HTML, formulas and Jinja
LHTML converts a few symbols and leaves everything else as it is. That is what makes it easy to mix with the rest of the web.
HTML
Any HTML is kept: a table, a form, an <iframe>, an SVG.
== Results
<table border="1" cellpadding="4">
<tr><th>Method</th><th>Error</th></tr>
<tr><td>**Ours**</td><td>0.8%</td></tr>
<tr><td>Baseline</td><td>2.1%</td></tr>
</table>HTML produced
<h2>Results</h2>
<table border="1" cellpadding="4">
<tr><th>Method</th><th>Error</th></tr>
<tr><td><strong>Ours</strong></td><td>0.8%</td></tr>
<tr><td>Baseline</td><td>2.1%</td></tr>
</table>LHTML symbols still work inside the HTML: **Ours** is bold in its cell. The tags themselves and
their attributes are never changed. Neither are <script>, <style> and comments <!-- -->:
a ** or a ::before in them stays as written.
Formulas
\(...\) (in a line) and \[...\] (on its own) are kept as written, for KaTeX or MathJax. The
themes of lhtml-site render them with KaTeX, at build time when possible.
The position of a falling sphere is \(z(t) = z_0 - \frac{1}{2} g t^2\), so it hits the ground at
\[ t^\star = \sqrt{\frac{2 z_0}{g}} \]HTML produced
The position of a falling sphere is \(z(t) = z_0 - \frac{1}{2} g t^2\), so it hits the ground at
\[ t^\star = \sqrt{\frac{2 z_0}{g}} \]LHTML symbols are not read inside a formula: __ and ** stay as written. A $ is plain text,
as in a price: write \(...\), not $...$.
Jinja
{{ ... }} and {% ... %} are kept too, so a Jinja template can be written in LHTML. With
LHTML alone, convert first, then render the result with Jinja2:
jinja2.Template(lhtml.run(text)).render(...) (see
Using LHTML with Jinja2).
In lhtml-site, every page is a Jinja template, rendered before LHTML: variables, loops, Jinja macros and includes.
{% set students = ['Ada', 'Alan', 'Grace'] %}
{%- for name in students %}
* {{ name }}
{%- endfor %}
Jinja runs first and writes three * lines; LHTML then makes them one list:
<ul> <li> Ada </li> <li> Alan </li> <li> Grace </li> </ul>
The - of {%- removes the line break before the tag: without it, each {% for %} line leaves a
blank line between the items, and each item becomes a list of its own.
In lhtml-site: what every page receives
| Variable | Value |
|---|---|
pathToRoot |
the relative path to the root of the site (../../), for links that work at any depth |
page |
the settings of the page: its title, its front matter (page.layout, page.description...) |
pageID |
the page's number in the site, from 0 |
the keys of keywords: |
your own values, from configure.yaml |
A link to the home page from any page: link::{{ pathToRoot }}index.html[Home].
Next: Your own tags: macros. All the rules: Syntax reference.