smalldocs.markdown
class Attrs
Attrs(id: str = '', classes: list[str] = <factory>, kv: dict[str, str] = <factory>)Pandoc attributes: {#id .class key=value}.
| Parameter | Type | Default | Description |
|---|---|---|---|
id |
str | '' |
The identifier, without the # |
classes |
list[str] | <factory> |
The classes, without the dots |
kv |
dict[str, str] | <factory> |
The other key and value pairs |
Attrs.html
Attrs.html() -> strWrite the attributes as HTML.
| Parameter | Type | Default | Description |
|---|---|---|---|
| returns | str | The attributes as they go in an HTML tag, with a leading space, or empty |
parse_attrs
parse_attrs(text: str) -> AttrsParse Pandoc attributes; a bare word with no # or . is a class, as in ::: warning.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | What is between the braces, or a bare word such as callout-note |
| returns | Attrs | The identifier, classes and pairs |
split_front_matter
split_front_matter(text: str) -> tuple[dict, str]Take the YAML front matter off the top of a page.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | The whole source of a page |
| returns | tuple[dict, str] | The YAML front matter as a dict (empty when there is none), and the rest |
pandoc_id
pandoc_id(text: str) -> strMake a heading’s identifier by Pandoc’s rules: lower case, punctuation gone, spaces to hyphens, from the first letter.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | The plain text of a heading |
| returns | str | Its identifier, as Pandoc makes it |
plain
plain(tokens: list[Token] | None) -> strThe plain text of an inline run: text and code, without links’ targets or footnotes.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
list[Token] | None | required | The children of an inline token |
| returns | str | The text without its formatting |
is_fence_line
is_fence_line(line: str) -> str | NoneSay whether a line opens or closes a fenced div, and give what follows the colons.
| Parameter | Type | Default | Description |
|---|---|---|---|
line |
str | required | One line of source |
| returns | str | None | The text after the colons, or None when the line is no div fence |
fenced_div
fenced_div(state: StateBlock, start: int, end: int, silent: bool) -> boolParse ::: {.class} … ::: into div tokens; a fence with no attributes closes the innermost div.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateBlock | required | The block parser’s state |
start |
int | required | The line to try |
end |
int | required | The line after the last one |
silent |
bool | required | Only say whether a div starts here |
| returns | bool | Whether a div starts here |
heading_attrs
heading_attrs(state: StateCore) -> NoneTake {#id .class} off the end of each heading, before inline parsing, and keep it on the heading.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
links_with_spaces
links_with_spaces(state: StateCore) -> NoneLet a link’s target hold spaces, as Pandoc does: [x](a b.qmd) is read as [x](<a b.qmd>).
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
quote_attr_values
quote_attr_values(state: StateCore) -> NoneQuote bare attribute values such as width=50%, which Pandoc reads and the attrs plugin does not.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
matching_close
matching_close(toks: list[Token], i: int) -> intFind the closing token of the block that opens at i.
| Parameter | Type | Default | Description |
|---|---|---|---|
toks |
list[Token] | required | The token list |
i |
int | required | The index of an opening token |
| returns | int | The index of the token that closes it |
raw
raw(content: str) -> TokenMake a token of raw HTML.
| Parameter | Type | Default | Description |
|---|---|---|---|
content |
str | required | HTML |
| returns | Token | A token that renders the HTML as it is |
class Rules
Rules(md: MarkdownIt)The core rules that run after inline parsing; each reads and writes env.
| Parameter | Type | Default | Description |
|---|---|---|---|
md |
MarkdownIt | required | The parser they belong to |
Rules.ids
Rules.ids(state: StateCore) -> NoneGive every heading an identifier, as Pandoc does, unique on the page; note its text for the table of contents.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
Rules.title
Rules.title(state: StateCore) -> NoneWhen the page has no title, a level-one heading at the very top becomes it, as in Quarto.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
Rules.callouts
Rules.callouts(state: StateCore) -> NoneTurn ::: {.callout-note} divs into Quarto’s callout markup, with a title from title= or a first heading.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
Rules.tabsets
Rules.tabsets(state: StateCore) -> NoneTurn ::: {.panel-tabset} divs into Bootstrap tabs, one tab for each heading at the first level found.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
Rules.figures
Rules.figures(state: StateCore) -> NoneAn image alone in its paragraph, with alt text, becomes a figure with a caption, as Pandoc’s implicit figures.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
Rules.sections
Rules.sections(state: StateCore) -> NoneWrap each top-level heading and what follows in <section>, as Pandoc’s section divs.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
Rules.typography
Rules.typography(state: StateCore) -> NoneDashes and ellipses as Pandoc’s smart makes them: ---, -- and ....
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
Rules.search_text
Rules.search_text(state: StateCore) -> NoneNote the text under each heading, for the search index.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
StateCore | required | The core parser’s state |
heading_open
heading_open(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRender a heading as Quarto does: the id is on the section; the heading has anchored and data-anchor-id.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The opening tag of the heading |
div_open
div_open(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRender a fenced div with its attributes; .cell and other Quarto classes pass through.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The opening tag of the div |
div_close
div_close(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strClose a fenced div.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The closing tag |
paragraph_open
paragraph_open(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strOpen a paragraph, or the figure that wraps a lone image.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The opening tag of the paragraph, or of the figure |
paragraph_close
paragraph_close(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strClose a paragraph, or the figure with its caption.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The closing tag of the paragraph, or the caption and the end of the figure |
image
image(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRender an image with Bootstrap’s img-fluid, and its source rewritten for the page.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The <img> tag |
link_open
link_open(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRewrite a link for the page: .qmd, .md and .ipynb to .html, and links from the root to relative ones.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The opening tag of the link |
link_close
link_close(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strClose a link.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The closing tag |
code_inline
code_inline(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRender inline code; a documented name in backticks, outside a link, links to its reference entry.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The <code> element, linked when it names a documented symbol |
table_open
table_open(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRender a table with Bootstrap’s classes, as Quarto does.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The opening tag of the table |
fence
fence(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRender a fenced code block: raw {=html}, mermaid, or highlighted code with a copy button.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The HTML of the block, or nothing |
code_block_html
code_block_html(body: str, lang: str, a: Attrs, env: dict, extra: str = '') -> strHighlight a code block with Pygments, in Quarto’s markup with a copy button.
| Parameter | Type | Default | Description |
|---|---|---|---|
body |
str | required | The code |
lang |
str | required | Its language, or empty |
a |
Attrs | required | Its attributes: filename=, classes, an id |
env |
dict | required | The render environment, which counts the blocks |
extra |
str | '' |
More classes on the outer div, such as cell-code |
| returns | str | The HTML of the block |
code_block
code_block(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRender an indented code block like a fence with no language.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The HTML of the block |
math_renderer
math_renderer(content: str, opts: dict) -> strWrite maths as Pandoc does for KaTeX or MathJax: \(...\) inline and \[...\] for display.
| Parameter | Type | Default | Description |
|---|---|---|---|
content |
str | required | The TeX |
opts |
dict | required | display_mode: whether it is display maths |
| returns | str | The TeX between the delimiters that KaTeX’s auto-render finds |
math_inline
math_inline(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRender inline maths.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The maths, in a span |
math_block
math_block(tokens: Sequence[Token], idx: int, options: OptionsDict, env: dict) -> strRender display maths.
| Parameter | Type | Default | Description |
|---|---|---|---|
tokens |
Sequence[Token] | required | The tokens of the page |
idx |
int | required | The index of the token to render |
options |
OptionsDict | required | The parser’s options |
env |
dict | required | The render environment |
| returns | str | The maths, in a paragraph |
make_parser
make_parser(extensions: str = '') -> MarkdownItMake a markdown-it parser that reads Pandoc’s Markdown as far as Quarto sites use it.
| Parameter | Type | Default | Description |
|---|---|---|---|
extensions |
str | '' |
Pandoc’s reader with extensions, such as markdown-tex_math_dollars-smart |
| returns | MarkdownIt | The parser, with every rule in place |
render
render(text: str, env: dict, extensions: str = '') -> strRender a page’s Markdown to HTML, filling env with what the layout needs.
| Parameter | Type | Default | Description |
|---|---|---|---|
text |
str | required | Markdown, without its front matter |
env |
dict | required | In: title, link, symbols, code_copy, number_sections. Out: headings, search, math, … |
extensions |
str | '' |
Pandoc’s reader with extensions, from from: in the config |
| returns | str | The HTML of the body |