~xigoi/xidoc

0a71cb4eb96ef60fd3de254efbb5732518bcc691 — Adam Blažek 2 months ago a2ac83a
Description list
3 files changed, 27 insertions(+), 7 deletions(-)

M docs/commands.html
M docs/commands.xd
M src/xidocpkg/commands/default.nim
M docs/commands.html => docs/commands.html +5 -3
@@ 155,10 155,12 @@ font-family:var(--sans-serif);}code[class*=language-],pre[class*=language-]{font
<tr><td><pre class="language-xidoc"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">link-image</span> xidoc logo<span class="token punctuation">;</span> logo.svg<span class="token punctuation">;</span> https://xidoc.nim.town/<span class="token punctuation">]</span></code></pre></td><td><div><a href="https://xidoc.nim.town/"><img src="logo.svg" alt="xidoc logo" /></a></div></td></tr></table></section>
<section id="list" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">list</span> *items<span class="token punctuation">]</span></code></h4>Creates an unordered list of <code>items</code>.
<table><tr><th>Example</th><th>Output</th></tr>
<tr><td><pre class="language-xidoc"><code class="language-xidoc">Supported targets: <span class="token punctuation">[</span><span class="token tag">list</span> HTML<span class="token punctuation">;</span> <span class="token punctuation">[</span><span class="token tag">LaTeX</span><span class="token punctuation">]</span><span class="token punctuation">;</span> Gemtext<span class="token punctuation">]</span></code></pre></td><td><div>Supported targets: <ul><li>HTML</li><li><span class="xd-latex">L<sup>a</sup>T<sub>e</sub>X</span></li><li>Gemtext</li></ul></div></td></tr></table></section>
<section id="ordered-list" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">ordered-list</span> *items<span class="token punctuation">]</span></code></h4>Creates an ordered list of <code>items</code>.
<tr><td><pre class="language-xidoc"><code class="language-xidoc">Supported targets: <span class="token punctuation">[</span><span class="token tag">list</span> HTML<span class="token punctuation">;</span> <span class="token punctuation">[</span><span class="token tag">LaTeX</span><span class="token punctuation">]</span><span class="token punctuation">;</span> Gemtext<span class="token punctuation">]</span></code></pre></td><td><div>Supported targets: <ul><li>HTML</li><li><span class="xd-latex">L<sup>a</sup>T<sub>e</sub>X</span></li><li>Gemtext</li></ul></div></td></tr></table>
<section id="ordered-list" class="command"><h5 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">ordered-list</span> *items<span class="token punctuation">]</span></code></h5>Creates an ordered list of <code>items</code>.
<table><tr><th>Example</th><th>Output</th></tr>
<tr><td><pre class="language-xidoc"><code class="language-xidoc">TOP 5 LIST OF SMALLEST POSITIVE INTEGERS: <span class="token punctuation">[</span><span class="token tag">ordered-list</span> 1<span class="token punctuation">;</span> 2<span class="token punctuation">;</span> 3<span class="token punctuation">;</span> 4<span class="token punctuation">;</span> 5<span class="token punctuation">]</span></code></pre></td><td><div>TOP 5 LIST OF SMALLEST POSITIVE INTEGERS: <ol><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ol></div></td></tr></table></section>
<section id="description-list" class="command"><h5 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">description-list</span> *(key description)<span class="token punctuation">]</span></code></h5>Creates a description list associating <code>key</code>s with <code>description</code>s.
<dl><dt>Dog</dt><dd>Cute and loyal</dd><dt>Cat</dt><dd>Cute and entitled</dd></dl></section></section>
<section id="p" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">p</span> text<span class="token punctuation">]</span></code></h4>Creates a paragraph with the given <code>text</code>.</section>
<section id="section" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">section</span> ?title<span class="token punctuation">;</span> text<span class="token punctuation">]</span></code></h4>Creates a section with the given <code>title</code> and <code>text</code> (or without a title if not given). If it's inside another section, it will be a subsection. If it's inside a subsection, it will be a subsubsection. In HTML, this nesting can continue further.
<table><tr><th>Example</th><th>Output</th></tr>


@@ 274,7 276,7 @@ font-family:var(--sans-serif);}code[class*=language-],pre[class*=language-]{font
<tr><td><pre class="language-xidoc"><code class="language-xidoc">Within the Git repository of xidoc, the command reference is located at <span class="token punctuation">[</span><span class="token tag">ms</span> <span class="token punctuation">[</span><span class="token tag">get-doc-path-relative-to-containing</span> .git<span class="token punctuation">]</span><span class="token punctuation">]</span>.</code></pre></td><td><div>Within the Git repository of xidoc, the command reference is located at <code>docs/commands.xd</code>.</div></td></tr></table></section>
<section id="list-dirs" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">list-dirs</span> pattern<span class="token punctuation">]</span></code></h4>Lists all directories that match the glob <code>pattern</code>, relative to the current file.
<table><tr><th>Example</th><th>Output</th></tr>
<tr><td><pre class="language-xidoc"><code class="language-xidoc">The subdirectories of the <span class="token punctuation">[</span><span class="token tag">ms</span> src<span class="token punctuation">]</span> directory of xidoc are: <span class="token punctuation">[</span><span class="token tag">join</span> ,<span class="token punctuation">[</span><span class="token tag">space</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token punctuation">[</span><span class="token tag">list-dirs</span> ../src/*<span class="token punctuation">]</span><span class="token punctuation">]</span>.</code></pre></td><td><div>The subdirectories of the <code>src</code> directory of xidoc are: ../src/janet, ../src/katex, ../src/pkgs, ../src/prism, ../src/quickjs, ../src/xidocpkg.</div></td></tr></table></section>
<tr><td><pre class="language-xidoc"><code class="language-xidoc">The subdirectories of the <span class="token punctuation">[</span><span class="token tag">ms</span> src<span class="token punctuation">]</span> directory of xidoc are: <span class="token punctuation">[</span><span class="token tag">join</span> ,<span class="token punctuation">[</span><span class="token tag">space</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token punctuation">[</span><span class="token tag">list-dirs</span> ../src/*<span class="token punctuation">]</span><span class="token punctuation">]</span>.</code></pre></td><td><div>The subdirectories of the <code>src</code> directory of xidoc are: ../src/janet, ../src/katex, ../src/prism, ../src/quickjs, ../src/xidocpkg.</div></td></tr></table></section>
<section id="list-files" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">list-files</span> pattern<span class="token punctuation">]</span></code></h4>Lists all files that match the glob <code>pattern</code>, relative to the current file.
<table><tr><th>Example</th><th>Output</th></tr>
<tr><td><pre class="language-xidoc"><code class="language-xidoc">The xidoc sources of this documentation are: <span class="token punctuation">[</span><span class="token tag">join</span> ,<span class="token punctuation">[</span><span class="token tag">space</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token punctuation">[</span><span class="token tag">list-files</span> *.xd<span class="token punctuation">]</span><span class="token punctuation">]</span>.</code></pre></td><td><div>The xidoc sources of this documentation are: commands.xd, head.xd, index.xd, manual.xd, playground.xd, todo.xd.</div></td></tr></table></section></section>

M docs/commands.xd => docs/commands.xd +8 -4
@@ 224,10 224,14 @@ const factorial = (n) => {
    [cmd list; *items;
      Creates an unordered list of [param items].
      [ex Supported targets: [list HTML; [LaTeX]; Gemtext]]
    ]
    [cmd ordered-list; *items;
      Creates an ordered list of [param items].
      [ex TOP 5 LIST OF SMALLEST POSITIVE INTEGERS: [ordered-list 1; 2; 3; 4; 5]]
      [cmd ordered-list; *items;
        Creates an ordered list of [param items].
        [ex TOP 5 LIST OF SMALLEST POSITIVE INTEGERS: [ordered-list 1; 2; 3; 4; 5]]
      ]
      [cmd description-list; *(key description);
        Creates a description list associating [param key]s with [param description]s.
        [description-list Dog; Cute and loyal; Cat; Cute and entitled]
      ]
    ]
    [cmd p; text;
      Creates a paragraph with the given [param text].

M src/xidocpkg/commands/default.nim => src/xidocpkg/commands/default.nim +14 -0
@@ 223,6 223,20 @@ commands defaultCommands:
  proc defGlobalCmd(name: !String, paramList: ?String, body: Raw): Markup {.command: "def-global".} =
    def(global = true)

  proc descriptionListCmd(args: *Markup): Markup {.command: "description-list", safe.} =
    if args.len mod 2 != 0:
      xidocError "Arguments to description-list must come in pairs"
    var defs: seq[array[2, string]]
    for i in 0..<(args.len div 2):
      defs.add [args[2*i], args[2*i + 1]]
    case doc.target
    of tHtml:
      htg.dl(defs.mapIt(htg.dt(it[0]) & htg.dd(it[1])).join)
    of tLatex:
      env("description", defs.mapIt("\\item[$1] $2" % it).join)
    of tGemtext:
      "\n$1\n" % defs.mapIt("* $1: $2" % it).join("\n")

  theoremLikeCommand(dfnCmd, "dfn", pDefinition, "$1", "$1")

  proc drawCmd(width: ?String, height: ?String, desc: Raw): Markup {.command: "draw".} =