~xigoi/xidoc

84703e7f7733a4bdbd5b11f3fbca1a8368b5e7cc — Adam Blažek 2 months ago bf9e0de
[lines]
4 files changed, 21 insertions(+), 0 deletions(-)

M docs/commands.html
M docs/commands.xd
M src/xidocpkg/commands/default.nim
M tests/test_documents.nim
M docs/commands.html => docs/commands.html +3 -0
@@ 150,6 150,9 @@ font-family:var(--sans-serif);}code[class*=language-],pre[class*=language-]{font
  <span class="token keyword">return</span> result<span class="token punctuation">;</span>
<span class="token punctuation">}</span></code></pre></div></td></tr></table></section>
<section id="figure" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">figure</span> content<span class="token punctuation">;</span> ?caption<span class="token punctuation">]</span></code></h4>Creates a figure with the given <code>content</code> and an optional <code>caption</code>.</section>
<section id="lines" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">lines</span> *lines<span class="token punctuation">]</span></code></h4>Inserts physical newlines between <code>lines</code>.
<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">lines</span> Roses are red<span class="token punctuation">;</span> Violets are blue<span class="token punctuation">;</span> Java is bad<span class="token punctuation">;</span> JavaScript too<span class="token punctuation">]</span></code></pre></td><td><div>Roses are red<br />Violets are blue<br />Java is bad<br />JavaScript too</div></td></tr></table></section>
<section id="link-image" class="command"><h4 class="xd-section-heading"><code class="language-xidoc"><span class="token punctuation">[</span><span class="token tag">link-image</span> alt<span class="token punctuation">;</span> url<span class="token punctuation">;</span> ?link<span class="token punctuation">]</span></code></h4>Inserts an image loaded at viewing time from the given <code>url</code>. A substitute <code>alt</code> text must be given in case the image can't be displayed. If a <code>link</code> is provided, the image will be a link to the given URL.
<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">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>

M docs/commands.xd => docs/commands.xd +4 -0
@@ 217,6 217,10 @@ const factorial = (n) => {
    [cmd figure; content[;] ?caption;
      Creates a figure with the given [param content] and an optional [param caption].
    ]
    [cmd lines; *lines;
      Inserts physical newlines between [param lines].
      [ex [lines Roses are red; Violets are blue; Java is bad; JavaScript too]]
    ]
    [cmd link-image; alt[;] url[;] ?link;
      Inserts an image loaded at viewing time from the given [param url]. A substitute [param alt] text must be given in case the image can't be displayed. If a [param link] is provided, the image will be a link to the given URL.
      [ex [link-image xidoc logo; logo.svg; https://xidoc.nim.town/]]

M src/xidocpkg/commands/default.nim => src/xidocpkg/commands/default.nim +8 -0
@@ 454,6 454,14 @@ commands defaultCommands:

  theoremLikeCommand(lemmaCmd, "lemma", pLemma, "$1", "$1")

  proc linesCmd(lns: *Markup): Markup {.command: "lines", safe.} =
    const seps = [
      tHtml: htg.br(),
      tLatex: "\\\\",
      tGemtext: "\n"
    ]
    lns.join(seps[doc.target])

  proc linkCmd(name: ?Markup, url: !String): Markup {.command: "link", safe.} =
    case doc.target
    of tHtml:

M tests/test_documents.nim => tests/test_documents.nim +6 -0
@@ 139,6 139,12 @@ suite "\"Block formatting\" commands":
    "[figure IMAGE]".shouldRenderAs("<figure>IMAGE</figure>")
    "[figure IMAGE; CAPTION]".shouldRenderAs("<figure>IMAGE<figcaption>CAPTION</figcaption></figure>")

  test "[lines]":
    "[lines Roses are red; Violets are blue; Java is bad; JavaScript too]"
    .shouldRenderAs("Roses are red<br />Violets are blue<br />Java is bad<br />JavaScript too")
    "[lines one line]".shouldRenderAs("one line")
    "[lines]".shouldRenderAs("")

  test "[link-image]":
    "[link-image xidoc logo; logo.svg]".shouldRenderAs("<img src=\"logo.svg\" alt=\"xidoc logo\" />")
    "[link-image xidoc logo; logo.svg; https://xidoc.nim.town/]".shouldRenderAs("<a href=\"https://xidoc.nim.town/\"><img src=\"logo.svg\" alt=\"xidoc logo\" /></a>")