LHTML+ lhtml-site

Classes and ids

A class names a kind of element: a note, a warning, a button. An id names one element of the page, for a link to it or for a script. In LHTML both go in parentheses right after the :: of an element (or the = of a heading), written as in CSS: . before a class, # before an id.

::(.note)              a class
::(.note .warning)     two classes
::(.note.warning)      the same, glued
::(#tip)               an id
::(.note #tip)         a class and an id

The look of a class lives in a stylesheet. The examples of this page carry their own <style>: it is HTML, so LHTML keeps it as it is. In lhtml-site, the stylesheet has a place of its own (below).

A note, then a warning

One class, then two
LHTML
<style>
.note { border-left: 4px solid #2f6fdb; background: #eef4ff; padding: 6px 12px; margin: 6px 0; }
.warning { border-color: #d97706; background: #fff7e6; }
</style>
::(.note)
A note: the class gives it its look.
::
::(.note .warning)
A warning: a note, with a second class that changes its colors.
::
Result
HTML produced
<style>
.note { border-left: 4px solid #2f6fdb; background: #eef4ff; padding: 6px 12px; margin: 6px 0; }
.warning { border-color: #d97706; background: #fff7e6; }
</style>
<div class="note">
A note: the class gives it its look.
</div>
<div class="note warning">
A warning: a note, with a second class that changes its colors.
</div>

Two classes add up: .warning only says what changes from .note.

On a heading

A centered heading, and a section with an id
LHTML
<style> .centered { text-align: center; color: #b4232c; } </style>
=(.centered) Bouncing spheres
==(#method) The method
Result
HTML produced
<style> .centered { text-align: center; color: #b4232c; } </style>
<h1 class="centered">Bouncing spheres</h1>

<h2 id="method">The method</h2>

The group of a heading comes right after its =, before the space.

A link to a part of the page
LHTML
link::#exercise[Go to the exercise]

==(#exercise) Exercise
Compute the time of the first bounce.
Result
HTML produced
<a href="#exercise">Go to the exercise</a>

<h2 id="exercise">Exercise</h2>

Compute the time of the first bounce.

The id names the place, and link::#exercise[...] goes there. An id is unique in its page. In lhtml-site every heading already gets an id from its text; write one by hand for a short anchor that stays the same when the heading changes.

In a sentence: a span

Keyboard keys
LHTML
<style>
.key { font: 13px ui-monospace, monospace; border: 1px solid #bbb; border-bottom-width: 3px;
       border-radius: 4px; padding: 0 4px; }
</style>
Press span::(.key)Ctrl:: + span::(.key)S:: to save.
Result
HTML produced
<style>
.key { font: 13px ui-monospace, monospace; border: 1px solid #bbb; border-bottom-width: 3px;
       border-radius: 4px; padding: 0 4px; }
</style>
Press <span class="key">Ctrl</span> + <span class="key">S</span> to save.

The group comes after the URL:

A button, a round image
LHTML
<style>
.button { display: inline-block; background: #2f6fdb; color: #fff; padding: 6px 14px;
          border-radius: 6px; text-decoration: none; }
.round { border-radius: 50%; object-fit: cover; }
</style>
link::https://example.org(.button)[Next chapter →]

img::../../assets/img/slide-title.jpg(.round)[width:110px; height:110px;]
Result
HTML produced
<style>
.button { display: inline-block; background: #2f6fdb; color: #fff; padding: 6px 14px;
          border-radius: 6px; text-decoration: none; }
.round { border-radius: 50%; object-fit: cover; }
</style>
<a class="button" href="https://example.org">Next chapter →</a>

<img class="round" style="width:110px; height:110px;" src="../../assets/img/slide-title.jpg" alt="../../assets/img/slide-title.jpg">

Class, style and attributes together

The three groups follow each other in this order: (...) the classes and the id, [...] the style, {...} the other attributes.

All three
LHTML
<style> .card { border: 1px solid #ddd; border-radius: 8px; padding: 8px 12px; } </style>
::(.card #week-1)[max-width:320px;]{data-week="1"}
**Week 1**: splines and keyframes
::
Result
HTML produced
<style> .card { border: 1px solid #ddd; border-radius: 8px; padding: 8px 12px; } </style>
<div class="card" id="week-1" style="max-width:320px;" data-week="1">
<strong>Week 1</strong>: splines and keyframes
</div>

A class for what several elements share, a style for a one-off adjustment, attributes for the rest (title, target, data-...).

Which elements take a group

Element Example
A block, div:: or :: ::(.note) ... ::
A span span::(.key)Ctrl::
A heading ==(#method) The method
A link link::page.html(.button)[Next]
An image, a video img::photo.jpg(.round), videoplay::clip.mp4(.wide)
A macro note::(.important) ... ::: its class and this one add up

The other HTML elements take their class in HTML, as usual: <p class="lead">, <ul class="checklist">, <table class="results">. The name before :: is a built-in tag (div, span, link, img, video, videoplay) or one of your macros: p:: or article:: stay text. A list item * takes no group: for a styled list, put it in a block (::(.checklist) ... ::) and style .checklist li in the stylesheet.

In lhtml-site: where the CSS goes

Two places, from the most shared to the most local:

  • A macro, in configure.yaml: its class and its CSS together, written into the site for every page. note:: then replaces ::(.note) (Your own tags: macros).

    design:
      macros:
        note:
          class: note
          css: '.note { border-left: 4px solid #2f6fdb; background: #eef4ff; padding: 6px 12px; }'
    
  • The page itself: a <style> at its top, or a <link rel="stylesheet" href="...">. It is HTML, like in the examples above.

With LHTML alone, a macro has no CSS (the lhtml command rejects the css field): the CSS goes in a stylesheet given with --css style.css, or in a <style> of the page.

Next: Links and images. All the rules: Syntax reference.

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