LHTML+ lhtml-site

Code

A code block starts with code::[language] and ends with code::[-]:

Python, highlighted
LHTML
code::[python]
def bounce(height, loss=0.8):
    return height * loss
code::[-]
Result
HTML produced
<div class="code"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">bounce</span><span class="p">(</span><span class="n">height</span><span class="p">,</span> <span class="n">loss</span><span class="o">=</span><span class="mf">0.8</span><span class="p">):</span>
    <span class="k">return</span> <span class="n">height</span> <span class="o">*</span> <span class="n">loss</span>
</pre></div>

Its lines are never read as LHTML: a :: in the code cannot close the block, and **, < and > are shown as written.

C++, with :: and < >
LHTML
code::[c++]
std::vector<float> heights; // **not bold**
code::[-]
Result
HTML produced
<div class="code"><pre><span></span><span class="m">std::</span><span class="n">vector</span><span class="o">&lt;</span><span class="kt">float</span><span class="o">&gt;</span><span class="w"> </span><span class="n">heights</span><span class="p">;</span><span class="w"> </span><span class="c1">// **not bold**</span>
</pre></div>
  • Any language known to Pygments: python, c++, glsl, bash... The case does not matter.
  • code::[] is plain text. An unknown language is plain text too, with a warning that suggests a close name (pyhton: did you mean python?).
  • A code::[python] without its code::[-] is not a code block: LHTML warns, and reads the lines as LHTML.

The colors come from a stylesheet; the themes of lhtml-site include one. With LHTML alone, make it with Pygments and give it to the page:

pipx run --spec pygments pygmentize -S default -f html -a .code > code.css
lhtml page.l.html --css code.css -o page.html

For a word of code in a sentence, use inline code between backquotes.

Next: HTML, formulas and Jinja. All the rules: Syntax reference.

Built with lhtml-site, the docs theme. Part of ScholarTools.