Blocks and styles
The :: system is the heart of LHTML. It writes a block (div) or a span, with its classes, its
style and its attributes, in one line. A block with a style:
div::[color:#b4232c; font-size:120%;]
This text is big and red.
::HTML produced
<div style="color:#b4232c; font-size:120%;">
This text is big and red.
</div>div:: opens the block, [...] gives its CSS, and a bare :: closes it. The general form is:
tagName::(.classes #id)[css style]{html attributes} content ::
Every group is optional. Without a name, the element is a div. A bare :: closes the last
element opened.
The name is one of LHTML: div and span; link, img, video and videoplay for the
links and images; code for the
code blocks; ::nl for a space. Or
it is one of your macros. Any other element is written in HTML.
Without a name: a div
The name can be omitted: ::[...] is a div.
::[padding:10px 14px; background:#eef6ee; border-radius:8px;]
A green box, its style in one line.
::HTML produced
<div style="padding:10px 14px; background:#eef6ee; border-radius:8px;">
A green box, its style in one line.
</div>Inline: on one line
An element can close on the line where it opens: end its content with ::. A span closed this
way stays inside its sentence (a div closed this way is still a block, on a line of its own in
the page):
The result is span::[color:#0b7a75; font-weight:bold;] correct :: in all cases.HTML produced
The result is <span style="color:#0b7a75; font-weight:bold;"> correct </span> in all cases.The closing :: counts only when it stands apart from the content:
- The recommended form: a space before the closing
::, as inspan::(.key) S ::. After it may come a space, the end of the line, or punctuation:span::(.key) S ::,is closed. - One word glued to the groups closes too, when a space or the end of the line follows the
:::span::(.key)Ctrl:: + ...is closed. With punctuation right after, it is not:span::(.key)S::,is never closed, and LHTML warns. - A
::glued to a word after a space is text: inspan::(.key) S:: ..., the span is never closed.
The spaces around the content stay inside the span: span::(.key) S :: gives
<span class="key"> S </span>. On colored text they do not show; on a span with a background or a
border they do. For a tight span, glue a single word: span::(.key)Ctrl::.
span::[background:#ffe9a8;] spaced :: and span::[background:#ffe9a8;]tight:: and span::[background:#ffe9a8;] before a comma ::, done.HTML produced
<span style="background:#ffe9a8;"> spaced </span> and <span style="background:#ffe9a8;">tight</span> and <span style="background:#ffe9a8;"> before a comma </span>, done.Classes, id and attributes
::(.note #first)[background:#fff7e6; padding:6px 12px; border-radius:6px;]{title="The title attribute: a tooltip"}
Hover over this box: its title attribute shows.
::HTML produced
<div class="note" id="first" style="background:#fff7e6; padding:6px 12px; border-radius:6px;" title="The title attribute: a tooltip">
Hover over this box: its title attribute shows.
</div>(...): classes with., an id with#, as in CSS; Classes and ids shows what they are for, on every kind of element.[...]: the CSS of thestyleattribute.{...}: any other HTML attributes.
Blocks inside blocks
Each :: closes the last element still open. Open the outer block, then the inner ones, and close
them in the reverse order:
::[display:flex; gap:12px;]
::[flex:1; background:#f6f6f6; padding:8px;]
Left column,
on two lines
::
::[flex:1; background:#f6f6f6; padding:8px;] Right column ::
::HTML produced
<div style="display:flex; gap:12px;">
<div style="flex:1; background:#f6f6f6; padding:8px;">
Left column,
on two lines
</div>
<div style="flex:1; background:#f6f6f6; padding:8px;"> Right column </div>
</div>When it is not a tag
A tag is read only when it stands apart: glued to the word before it, :: is text. Code written in
a sentence stays as it is:
In C++, std::vector is a container; in Python, a[::2] takes every other item.HTML produced
In C++, std::vector is a container; in Python, a[::2] takes every other item.- A name that is neither a tag of LHTML nor a macro does not make a tag:
p:: text ::stays text, and its::closes nothing. - Nothing is a tag inside inline code:
`div::`is shown as written.
Warnings
An element never closed, or a :: that closes nothing, gives a warning, from the lhtml command
and from lhtml-site. For a file notes.l.html whose line 2 opens a div:: that nothing closes:
notes.l.html:2:1: warning: div:: is never closed (near 'div::[color:gray;]')
It reads file:line:column: level: message: the file, the line and the column where the problem
starts (here line 2, column 1), its level, then what is wrong, with the text it is about. A
warning does not stop the conversion: the page is written, and here the div runs to its end.
Your own tags: macros
When the same style comes back on every page, declare it once as a tag of your own, note:::
see Your own tags: macros.
Next: Classes and ids. All the rules: Syntax reference.