x-lang

← Index

x/tool/highlight

x-lang source and REPL transcripts as HTML, in Rouge token classes.

The tokens are (Syntax x)’s and the markup Syntax’s HTML renderer’s; the Highlight class adds the transcript lines and the container.

Class Highlight

x-lang source and REPL transcripts as HTML, in Rouge’s token classes, from the spans of (Syntax x).

Emits Rouge/Pygments token classes, so an existing Rouge stylesheet renders the output. The keywords are lib/x/constructs.x’s, read by x/tool/syntax.

source and transcript WRITE their result, like x/tool/fmt’s printers.

(Highlight spans text)

Write span markup for source text, WITHOUT the surrounding container.

Parameters:

Returns: ANY — nil (output via display)

Examples:

(Highlight spans "(f 1)") => <span class="p">(</span><span class="n">f</span> <span class="m">1</span><span class="p">)</span>

(Highlight source text)

Write x-lang source as a complete Rouge-style code block.

Parameters:

Returns: ANY — nil (output via display)

Examples:

(Highlight source "42") => <div class="highlight"><pre class="highlight"><code><span class="m">42</span></code></pre></div>

(Highlight transcript text)

Write a REPL transcript – “> expr” prompts and “expr => result” lines – as a complete code block.

Parameters:

Returns: ANY — nil (output via display)

Examples:

(Highlight transcript "x => 3") => <div class="highlight"><pre class="highlight"><code><span class="n">x</span><span class="o"> =&gt; </span><span class="m">3</span></code></pre></div>

(Highlight escape text)

HTML-escape &, < and > in text.

Parameters:

Returns: STRING — Escaped text

Examples:

(Highlight escape "a<b & c>d") => "a&lt;b &amp; c&gt;d"