Markdown Writing Extensions
Posts on this site are written in Pandoc Markdown and rendered by Pandoc for both the website and the PDF export. Everything beyond plain Pandoc is implemented as a Lua filter in pandoc/filters; each file starts with a description of the syntax it handles. pandoc/defaults.yaml lists them in order, and scripts/pandoc.js is the glue that makes Hexo call Pandoc. No Hexo tag plugins ({% ... %}) are used.
This page is the reference and the test page in one. Each example shows its source and then the result, and the result is rendered from that same source, so reading through the page checks how everything is styled. Notebook posts cannot be shown inside a Markdown page; they have a demo post of their own.
Link Cards
A URL in a paragraph of its own becomes a card. The title, description and icon are fetched in the browser. To set the title yourself, write a normal link with the card class.
https://github.com/duanyll/duanyll.com-hexo
[A custom title](https://example.com){.card}Callouts and Folds
Fenced divs named note, tip, warning or danger become callouts. A first paragraph that is entirely bold is the title.
::: note
A note without a title.
:::
::: tip
**Optional title**
Body. Lists, code blocks and math all work here:
- an item with `inline code`
- an item with $e^{i\pi} + 1 = 0$
:::
::: warning
**Warning**
Something to be careful about.
:::
::: danger
**Danger**
Something that breaks things.
:::A note without a title.
Body. Lists, code blocks and math all work here:
- an item with
inline code - an item with
Something to be careful about.
Something that breaks things.
fold (collapsed) and fold-open (expanded) become <details>, with the first paragraph as the summary. The two kinds can be combined as ::: {.fold .warning}.
::: fold
Summary line, click to open
Body of the fold.
:::
::: fold-open
This one starts open
Body of the fold.
:::
::: {.fold .warning}
A fold in a callout color
Body of the fold.
:::Summary line, click to open
Body of the fold.
This one starts open
Body of the fold.
A fold in a callout color
Body of the fold.
A blank line is required before the opening :::, and before the closing ::: when the body ends with a list or a quote (otherwise Prettier folds the fence into the last item). The build warns about any ::: that ends up as plain text.
Any other ::: name or [text]{.name} is passed through as a <div> or <span> with that class, so a new effect only needs CSS.
Figures and Galleries
An image with alt text, alone in a paragraph, becomes a figure with the alt text as its caption (Markdown and math are allowed in it). An image with empty alt text has no caption. Clicking an image opens a viewer that steps through the images of the post.
{width=60%}
{width=40%}

Wrap several images in a gallery div to lay them out in a row. A row that does not fit scrolls sideways.
::: gallery



:::

Wide Layouts
A block can be made wider than the text column with the layout classes from Distill. Put the class on an image, or wrap any other content (tables, code, galleries, TikZ) in a fenced div. The page is sidebar, text, then free space on the right, and the sidebar stays in the viewport while the text scrolls, so wide blocks grow to the right. Only l-screen crosses the sidebar, and the parts of the sidebar it touches fade out while it passes.
| Class | Effect |
|---|---|
l-body-outset |
Slightly wider than the text on both sides |
l-page |
Text column plus the free space on its right, up to 984px |
l-page-outset |
A little wider than l-page |
l-screen |
The whole viewport width, drawn as a tinted band |
l-screen-inset |
The whole viewport width with a margin on both sides |
l-gutter |
A side note in the free space on the right, next to the block after it |
On narrow windows the free space disappears: l-page falls back to the text width, a side note moves into the text, and on phones every wide block spans the screen.
A class on an image moves to its figure, and the caption stays in the text column:
{.l-body-outset}
Anything else is wrapped in a div:
::: l-body-outset
```python
def cosine_with_warmup(step: int, total: int, warmup: int, peak: float) -> float:
"""Linear warmup to the peak, then a cosine decay to zero. A slightly wider block fits a few more characters."""
if step < warmup:
return peak * step / warmup
return 0.5 * peak * (1 + math.cos(math.pi * (step - warmup) / (total - warmup)))
```
:::def cosine_with_warmup(step: int, total: int, warmup: int, peak: float) -> float:
"""Linear warmup to the peak, then a cosine decay to zero. A slightly wider block fits a few more characters."""
if step < warmup:
return peak * step / warmup
return 0.5 * peak * (1 + math.cos(math.pi * (step - warmup) / (total - warmup)))To caption something that is not an image, wrap it in a figure div; its last paragraph is the caption.
::: {.figure .l-page}
| Model | Parameters | Layers | Hidden size | Heads | Learning rate | Batch size | Top-1 | Top-5 | Training time |
| ----- | ---------- | ------ | ----------- | ----- | ------------- | ---------- | ----- | ----- | ------------- |
| Small | 22 M | 12 | 384 | 6 | 5e-4 | 1024 | 71.2% | 90.4% | 14 hours |
| Base | 86 M | 12 | 768 | 12 | 5e-4 | 1024 | 78.3% | 94.1% | 31 hours |
| Large | 307 M | 24 | 1024 | 16 | 3e-4 | 512 | 83.0% | 96.5% | 96 hours |
A table with many columns in `l-page`, captioned with a `figure` div.
:::| Model | Parameters | Layers | Hidden size | Heads | Learning rate | Batch size | Top-1 | Top-5 | Training time |
|---|---|---|---|---|---|---|---|---|---|
| Small | 22 M | 12 | 384 | 6 | 5e-4 | 1024 | 71.2% | 90.4% | 14 hours |
| Base | 86 M | 12 | 768 | 12 | 5e-4 | 1024 | 78.3% | 94.1% | 31 hours |
| Large | 307 M | 24 | 1024 | 16 | 3e-4 | 512 | 83.0% | 96.5% | 96 hours |
l-page, captioned with a figure div.A side note is written before the paragraph it belongs to:
::: l-gutter
A side note. A remark, a source or an aside goes here without interrupting the text.
:::
The paragraph next to the side note. The note is set in a smaller size and a lighter color, and its width follows the free space on the right. The text column keeps its width whether or not there is something beside it, and this paragraph is long enough to show how the first lines of the two align.A side note. A remark, a source or an aside goes here without interrupting the text.
The paragraph next to the side note. The note is set in a smaller size and a lighter color, and its width follows the free space on the right. The text column keeps its width whether or not there is something beside it, and this paragraph is long enough to show how the first lines of the two align.
Pandoc’s columns / column divs lay blocks out side by side and can take a layout class too. On phones the columns stack.
:::: {.columns .l-page-outset}
::: column

:::
::: column

:::
::::
The two full-width classes draw a tinted band across the viewport:
::: {.gallery .l-screen}





:::
A paragraph between the two bands. While a band passes the sidebar, the parts of the sidebar it touches fade out, and they come back once it has scrolled past.
::: {.figure .l-screen-inset}
| Model | Parameters | Layers | Hidden size | Heads | Learning rate | Batch size | Top-1 | Top-5 | Training time |
| ----- | ---------- | ------ | ----------- | ----- | ------------- | ---------- | ----- | ----- | ------------- |
| Small | 22 M | 12 | 384 | 6 | 5e-4 | 1024 | 71.2% | 90.4% | 14 hours |
| Base | 86 M | 12 | 768 | 12 | 5e-4 | 1024 | 78.3% | 94.1% | 31 hours |
The same table in `l-screen-inset`, which keeps a margin on both sides.
:::



A paragraph between the two bands. While a band passes the sidebar, the parts of the sidebar it touches fade out, and they come back once it has scrolled past.
| Model | Parameters | Layers | Hidden size | Heads | Learning rate | Batch size | Top-1 | Top-5 | Training time |
|---|---|---|---|---|---|---|---|---|---|
| Small | 22 M | 12 | 384 | 6 | 5e-4 | 1024 | 71.2% | 90.4% | 14 hours |
| Base | 86 M | 12 | 768 | 12 | 5e-4 | 1024 | 78.3% | 94.1% | 31 hours |
l-screen-inset, which keeps a margin on both sides.Math
Formulas are written in TeX and rendered to SVG at build time, so the page loads no math script. Display formulas are numbered, and \label with \eqref works within a post. _config.yml defines macros such as \R, \argmin and \d for the site; .vscode/settings.json repeats them for the preview of the Markdown All in One extension in VS Code.
Inline math such as $\eta_t \in \R$ sits in the line of text. The minimizer in $\eqref{eq:demo}$ is found by gradient descent.
$$
\theta^* = \argmin_{\theta \in \R^n} \int_0^1 \left\| v_\theta(x_t, t) - \dot{x}_t \right\|^2 \d t \label{eq:demo}
$$Inline math such as
A TeX command outside a formula is dropped by Pandoc. The usual cause is a missing $, so the build warns about it.
Links to Other Posts
A link to another Markdown file or notebook in this repository is converted to the address of the published page. The link has to begin with / (relative to the repository root) or ./ (relative to the current file). Written this way, links can also be followed inside VS Code.
[An old post](/source/_posts/oi/2018-10-16-Simulate-Anneal.md) and [the notebook demo](/source/_posts/tech/2026-12-3-Distill-Layout.ipynb#l-page).An old post and the notebook demo.
TikZ Graphics
TikZ pictures are written as raw LaTeX blocks. On the website they are rendered to SVG at build time by node-tikzjax (see pandoc/tikz2svg.js); in the PDF they are compiled by LaTeX itself. Packages and TikZ libraries go into header-includes in the front matter. Chinese labels are supported. In dark mode the colors of a picture are inverted.
---
header-includes: |
\usetikzlibrary{positioning, arrows.meta}
---```{=latex}
\begin{tikzpicture}[
node distance=14mm,
box/.style={draw, rounded corners=2pt, minimum width=20mm, minimum height=9mm},
]
\node[box] (md) {Markdown};
\node[box, right=of md] (pandoc) {Pandoc 过滤器};
\node[box, right=of pandoc] (html) {HTML};
\node[box, below=8mm of html] (pdf) {PDF};
\draw[-Stealth] (md) -- (pandoc);
\draw[-Stealth] (pandoc) -- node[above] {\footnotesize $f(x)$} (html);
\draw[-Stealth] (pandoc) |- (pdf);
\end{tikzpicture}
```On the website a picture is shown at its natural size, where 10pt text in TeX is 13.3px. When the column is narrower than the picture, it shrinks, but not below 75% of its natural size. Below that it scrolls sideways, which is what a large picture does on a phone. A %| min-scale: line at the top of the block changes the limit for one picture: 0.5 lets a simple picture with large text shrink to half size, 1 never shrinks it, and 0 always fits it to the column. The two pictures below are the same; on a narrow screen the first one scrolls and the second one shrinks.
```{=latex}
\begin{tikzpicture}[box/.style={draw, minimum width=22mm, minimum height=9mm}]
\foreach \i in {1, ..., 6} \node[box] (n\i) at (\i * 3.2, 0) {Step \i};
\foreach \i [evaluate=\i as \j using int(\i + 1)] in {1, ..., 5} \draw[-Stealth] (n\i) -- (n\j);
\end{tikzpicture}
```
```{=latex}
%| min-scale: 0.4
\begin{tikzpicture}[box/.style={draw, minimum width=22mm, minimum height=9mm}]
\foreach \i in {1, ..., 6} \node[box] (n\i) at (\i * 3.2, 0) {Step \i};
\foreach \i [evaluate=\i as \j using int(\i + 1)] in {1, ..., 5} \draw[-Stealth] (n\i) -- (n\j);
\end{tikzpicture}
```Notebook Posts
A post can also be a Jupyter notebook: source/_posts/tech/2026-12-3-Distill-Layout.ipynb instead of .md. Text goes into markdown cells, written exactly as in a .md post, and figures come from code cells. The build does not run any code. It reads the outputs saved in the notebook, so run the cells and save before building. pandoc/ipynb2md.js flattens the notebook into one Markdown document, which then goes through the same Pandoc filters as any other post. The demo post is such a notebook and shows every layout with several kinds of figures.
- The first cell holds the front matter (YAML between
---lines). Make it a raw cell so the editor does not render it. - Cells are joined with blank lines, so a fenced div such as
:::: {.columns .l-page}can open in one markdown cell and close in a later one, with code cells in between. - A code cell is replaced by its output, followed by its code folded behind a small “显示代码” button. A cell without output does not appear in the post.
- A Plotly figure stays interactive: the browser draws it when it scrolls into view, and the theme adapts fonts, background and colors to the page, including dark mode. An image output (matplotlib) becomes an ordinary image, and printed text becomes a code block.
Comments at the top of a code cell say how its figure is laid out:
#| caption: Validation loss of three runs.
#| layout: l-page
#| height: 360
runs = pd.read_csv(f"{DATA}/runs.csv")
fig = px.line(runs, x="step", y="loss", color="run")
fig.show()| Option | Meaning |
|---|---|
caption |
The figure caption; inline Markdown is allowed |
layout |
A layout class from the table above |
height |
Height of a Plotly figure in pixels; defaults to the figure’s own height, then to 420 |
code |
fold (the default for a cell with output), show (code block before the output), hide |
A TikZ picture goes into a code cell that starts with %%tikz. Running the cell previews the picture in the notebook. The preview comes from the same filter the site uses (python/blogfig/tikz.py calls Pandoc with tikz.lua), with the packages and libraries from header-includes in the notebook’s front matter; save the notebook after changing them. Options use the TeX comment mark, %| instead of #|. In VS Code, switch the cell’s language to LaTeX (bottom right corner of the cell) to get LaTeX highlighting and linting: the %%tikz line and the options are comments to LaTeX. The build renders the picture from the source in the cell, as it does for a {=latex} block in a .md post, and does not show the code unless %| code: says so. %| min-scale: works as described under TikZ Graphics.
%%tikz
%| caption: The structure of the model.
%| layout: l-page
\begin{tikzpicture}
\draw (0, 0) circle (1);
\end{tikzpicture}To write one, install uv and run uv sync, then pick the .venv at the repository root as the notebook kernel. Packages a notebook needs go into pyproject.toml, followed by uv lock. Start the notebook with
import blogfig
blogfig.setup()which gives every Plotly figure the site’s palette and layout (python/blogfig), so the preview in the editor matches the light-mode page, and registers %%tikz. Data files live in a directory next to the notebook with the same name; Hexo ignores everything in it. A notebook runs in its own directory, so paths are relative to it.
source/_posts/tech/
2026-12-3-Distill-Layout.ipynb
2026-12-3-Distill-Layout/
runs.csvuv run python -m blogfig.run post.ipynb runs a notebook from the command line and saves the outputs back into it. node pandoc/ipynb2md.js post.ipynb prints the flattened Markdown. A cell that was saved with an error, or with a caption but no figure, leaves a marked placeholder in the page that makes the CI build fail.
Plain Markdown
The rest is ordinary Pandoc Markdown. These examples are here to check the styles.
Text can be **bold**, _italic_, ~~struck out~~ or `inline code`, with subscripts in H~2~O, superscripts in x^2^, [links](https://pandoc.org) and footnotes[^demo]. 中文和 English 混排时,标点和字体也在这里检查。
[^demo]: The text of a footnote ends up at the bottom of the page.Text can be bold, italic, struck out or inline code, with subscripts in H2O, superscripts in x2, links and footnotes1. 中文和 English 混排时,标点和字体也在这里检查。
- A bullet list
- with a nested item
- and another one
- The second item
1. An ordered list
2. The second item
- [x] A finished task
- [ ] An open task
Term
: An entry of a definition list.- A bullet list
- with a nested item
- and another one
- The second item
- An ordered list
- The second item
- Term
- An entry of a definition list.
> A block quote.
>
> Its second paragraph.
| Left | Center | Right |
| :-------- | :----: | ----: |
| Alignment | is | kept |
| a | b | 1.00 |
: A table caption, written as a line that starts with a colon.A block quote.
Its second paragraph.
| Left | Center | Right |
|---|---|---|
| Alignment | is | kept |
| a | b | 1.00 |
Code blocks are highlighted by Pandoc. The label in the corner is the language as written in the post, and a long line scrolls.
```sh
yarn make-pdf source/_posts/your-post.md && echo "a long line that keeps going well past the width of the text column to show how a code block scrolls sideways"
```
```
A block without a language is not highlighted.
```yarn make-pdf source/_posts/your-post.md && echo "a long line that keeps going well past the width of the text column to show how a code block scrolls sideways"A block without a language is not highlighted.Examples in This Page
The examples above are written once. A markdown code block with the demo class is shown as code and then rendered (demo.lua). When the example contains a code block itself, the outer fence needs one more backtick than the inner one.
```{.markdown .demo}
::: tip
Shown as source, then as a callout.
:::
```The text of a footnote ends up at the bottom of the page.↩︎
