~xigoi/xidoc

4cd34f6644d3b4ca4a1a7be077ec45f32432fa69 — Adam Blažek 2 months ago 0e50d65
[empty-favicon]
3 files changed, 14 insertions(+), 5 deletions(-)

M docs/commands.html
M docs/commands.xd
M src/xidocpkg/commands/default.nim
M docs/commands.html => docs/commands.html +4 -3
@@ 303,17 303,18 @@ font-family:var(--sans-serif);}code[class*=language-],pre[class*=language-]{font
  let root2 = (-b - Math.sqrt(discriminant)) / (2 * a);
  root1 + ", " + root2
}</span><span class="token punctuation">]</span><span class="token punctuation">;</span> a<span class="token punctuation">;</span>3 <span class="token punctuation">;</span> b<span class="token punctuation">;</span>-18 <span class="token punctuation">;</span> c<span class="token punctuation">;</span>24<span class="token punctuation">]</span>.</code></pre></td><td><div>The roots of the polynomial <xd-inline-math><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>3</mn><msup><mi>x</mi><mn>2</mn></msup><mo>−</mo><mn>18</mn><mi>x</mi><mo>+</mo><mn>24</mn></mrow><annotation encoding="application/x-tex">3x^2 - 18x + 24</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.897438em;vertical-align:-0.08333em;"></span><span class="mord">3</span><span class="mord"><span class="mord mathnormal">x</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="height:0.8141079999999999em;"><span style="top:-3.063em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.72777em;vertical-align:-0.08333em;"></span><span class="mord">18</span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span><span class="mbin">+</span><span class="mspace" style="margin-right:0.2222222222222222em;"></span></span><span class="base"><span class="strut" style="height:0.64444em;vertical-align:0em;"></span><span class="mord">24</span></span></span></span></xd-inline-math> are 4, 2.</div></td></tr></table></section></section>
<section><h3 class="xd-section-heading">HTML-specific</h3><section id="html-add-attrs" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">html-add-attrs</span> attrs<span class="token punctuation">;</span> cmd<span class="token punctuation">]</span></code></h4>If the target is HTML, adds the given <code>attributes</code> to the tag produced by <code>cmd</code>. Supports the <code>.foo</code> and <code>#foo</code> syntax for specifying classes and IDs.
<section><h3 class="xd-section-heading">HTML-specific</h3><section id="html-add-attrs" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">html-add-attrs</span> attrs<span class="token punctuation">;</span> cmd<span class="token punctuation">]</span></code></h4>Adds the given <code>attributes</code> to the tag produced by <code>cmd</code>. Supports the <code>.foo</code> and <code>#foo</code> syntax for specifying classes and IDs.
<table><tr><th>Example</th><th>Output</th></tr>
<tr><td><pre class="language-xidoc"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">html-add-attrs</span> style="color:pink"<span class="token punctuation">;</span> <span class="token punctuation">[</span><span class="token tag">bf</span> Real men don't fear colors.<span class="token punctuation">]</span><span class="token punctuation">]</span></code></pre></td><td><div><b style="color:pink">Real men don't fear colors.</b></div></td></tr></table></section>
<section id="js-module" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">js-module</span> code<span class="token punctuation">]</span></code></h4>If the target is HTML, adds the given JavaScript code to the page as a JavaScript module. If you don't need to use any xidoc commands inside the code, it's recommended to use <a href="#js-module-raw"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">js-module-raw</span><span class="token punctuation">]</span></code></a>.
<section id="js-module" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">js-module</span> code<span class="token punctuation">]</span></code></h4>Adds the given JavaScript code to the page as a JavaScript module. If you don't need to use any xidoc commands inside the code, it's recommended to use <a href="#js-module-raw"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">js-module-raw</span><span class="token punctuation">]</span></code></a>.
<section id="js-module-raw" class="command"><h5 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">js-module-raw</span> <span class="token string">code</span><span class="token punctuation">]</span></code></h5>Works as a combination of <a href="#js-module"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">js-module</span><span class="token punctuation">]</span></code></a> and <a href="#raw"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">raw</span><span class="token punctuation">]</span></code></a>.
<table><tr><th>Example</th><th>Output</th></tr>
<tr><td><pre class="language-xidoc"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">&lt;span></span> #change-me<span class="token punctuation">;</span> I will be changed<span class="token punctuation">]</span> <span class="token punctuation">[</span><span class="token tag">js-module-raw</span> <span class="token string">document.getElementById("change-me").innerText = "I was changed"</span><span class="token punctuation">]</span></code></pre></td><td><div><span id="change-me">I will be changed</span> </div></td></tr></table></section></section>
<section id="link-stylesheet" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">link-stylesheet</span> url<span class="token punctuation">]</span></code></h4>Links the CSS stylesheet at the given <code>url</code> to be loaded at viewing time.</section>
<section id="style" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">style</span> stylesheet<span class="token punctuation">]</span></code></h4>Styles an HTML document using xidoc's custom syntax for CSS.
<table><tr><th>Example</th><th>Output</th></tr>
<tr><td><pre class="language-xidoc"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">style</span> <span class="token punctuation">[</span><span class="token tag">rule</span> .golden-frame<span class="token punctuation">;</span> <span class="token punctuation">[</span><span class="token tag">:</span> border<span class="token punctuation">;</span> 3px solid gold<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token tag">&lt;div></span> .golden-frame<span class="token punctuation">;</span> This text is a work of art!<span class="token punctuation">]</span></code></pre></td><td><div><div class="golden-frame">This text is a work of art!</div></div></td></tr></table></section></section>
<tr><td><pre class="language-xidoc"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">style</span> <span class="token punctuation">[</span><span class="token tag">rule</span> .golden-frame<span class="token punctuation">;</span> <span class="token punctuation">[</span><span class="token tag">:</span> border<span class="token punctuation">;</span> 3px solid gold<span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token tag">&lt;div></span> .golden-frame<span class="token punctuation">;</span> This text is a work of art!<span class="token punctuation">]</span></code></pre></td><td><div><div class="golden-frame">This text is a work of art!</div></div></td></tr></table></section>
<section id="empty-favicon" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">empty-favicon</span><span class="token punctuation">]</span></code></h4>Specifies the favicon of the webpage to be empty. This prevents unnecessary requests to <code>favicon.ico</code>.</section></section>
<section><h3 class="xd-section-heading">Other top-level commands</h3><section id="draw" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">draw</span> ?width<span class="token punctuation">;</span> ?height<span class="token punctuation">;</span> description<span class="token punctuation">]</span></code></h4><span style="color:red">[Experimental]</span> Draws a vector image with the given dimensions based on the <code>description</code>. The <code>description</code> format won't be documented until it's stabilized.
<table><tr><th>Example</th><th>Output</th></tr>
<tr><td><pre class="language-xidoc"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">draw</span> 80<span class="token punctuation">;</span> 80<span class="token punctuation">;</span>

M docs/commands.xd => docs/commands.xd +5 -2
@@ 490,11 490,11 @@ const factorial = (n) => {

  [section HTML-specific;
    [cmd html-add-attrs; attrs[;] cmd;
      If the target is HTML, adds the given [param attributes] to the tag produced by [param cmd]. Supports the [ms .foo] and [ms #foo] syntax for specifying classes and IDs.
      Adds the given [param attributes] to the tag produced by [param cmd]. Supports the [ms .foo] and [ms #foo] syntax for specifying classes and IDs.
      [if-html [ex [html-add-attrs style="color:pink"; [bf Real men don't fear colors.]]]]
    ]
    [cmd js-module; code;
      If the target is HTML, adds the given JavaScript code to the page as a JavaScript module. If you don't need to use any xidoc commands inside the code, it's recommended to use [cmd-ref js-module-raw].
      Adds the given JavaScript code to the page as a JavaScript module. If you don't need to use any xidoc commands inside the code, it's recommended to use [cmd-ref js-module-raw].
      [cmd js-module-raw; code;
        Works as a combination of [cmd-ref js-module] and [cmd-ref raw].
        [if-html [ex [<span> #change-me; I will be changed] [js-module-raw document.getElementById("change-me").innerText = "I was changed"]]]


@@ 507,6 507,9 @@ const factorial = (n) => {
      Styles an HTML document using xidoc's custom syntax for CSS.
      [if-html [ex [style [rule .golden-frame; [: border; 3px solid gold]]][<div> .golden-frame; This text is a work of art!]]]
    ]
    [cmd-nilad empty-favicon;
      Specifies the favicon of the webpage to be empty. This prevents unnecessary requests to [ms favicon.ico].
    ]
  ]

  [section Other top-level commands;

M src/xidocpkg/commands/default.nim => src/xidocpkg/commands/default.nim +5 -0
@@ 235,6 235,11 @@ commands defaultCommands:
    of tGemtext:
      xidocError "Drawing is currently not implemented in the Gemtext backend"

  proc emptyFaviconCmd(): Markup {.command: "empty-favicon", safe.} =
    if doc.target == tHtml:
      doc.addToHead.incl htg.link(rel = "icon", href = "data:,")
    ""

  theoremLikeCommand(exampleCmd, "example", pExample, "$1", "$1")

  theoremLikeCommand(exerciseCmd, "exercise", pExercise, "$1", "$1")