Reference
Features
The features option on markdownToHtml, mdxToJs, markdownToJs, markdownToHast, and mdxToHast toggles which Markdown extensions the parser recognizes (see Entry points for those functions). By default, Sätteri enables gfm and frontmatter.
import { markdownToHtml } from "satteri";
markdownToHtml(source, {
features: {
gfm: true,
frontmatter: true,
math: false,
attributes: false,
directive: false,
superscript: false,
subscript: false,
wikilinks: false,
definitionList: false,
breaks: false,
smartPunctuation: false,
rawHtml: false,
},
});
gfm, math, and smartPunctuation each accept a boolean or a granular options object. Passing the object turns the feature on.
Link to this headingGFM
gfm?: boolean | {
footnotes?: boolean | FootnoteOptions
}
Default: true. Enables tables, footnotes, strikethrough, task lists, and GitHub-style autolinks.
Strikethrough accepts both single (~text~) and double (~~text~~) tildes. Unless subscript is enabled, in which case single tildes become subscript and only double tildes strike through.
Link to this headingCustomizing footnotes
The three strings in the footnotes section (the <h2> label, the backref aria-label, and the backref text) are configurable without a post-processing plugin:
markdownToHtml(source, {
features: {
gfm: {
footnotes: {
label: "Notes de bas de page",
backContent: "↑",
backLabel: "Retour à la référence {reference}",
},
},
},
});
backLabel and backContent each accept either a string template or a callback.
In a string template, the {reference} token expands to the footnote number on the first backref (e.g. 1) and to number-K on repeated backrefs (e.g. 1-2). Template mode also appends a <sup>K</sup> marker after backContent on reruns.
For full control, you can pass a callback to these options:
type FootnoteBackrefCallback = (referenceNumber: number, rerunIndex: number) => string;
markdownToHtml(source, {
features: {
gfm: {
footnotes: {
backLabel: (n, k) => (k > 1 ? `Retour ${n}-${k}` : `Retour ${n}`),
backContent: (_n, k) => (k === 1 ? "↑" : `↑${k}`),
},
},
},
});
Both arguments are 1-based. referenceNumber is the footnote number a reader sees; rerunIndex is 1 for the first backref to a given definition, 2 for the second, and so on. Callback mode skips the auto-<sup>K</sup>: the callback returns the final content for each backref.
Separately, a clobberPrefix can be specified (default: user-content-) that prefixes all footnote IDs:
markdownToHtml(source, {
features: {
gfm: {
footnotes: {
clobberPrefix: "custom-prefix-",
},
},
},
});
Link to this headingMath
Default: false.
math?: boolean | {
singleDollarTextMath?: boolean
}
Parses $$ ... $$ display math and $ ... $ inline math.
Set singleDollarTextMath: false to keep $$ ... $$ working while treating single dollars as literal text. Useful for prose with currency like "from $50 to $100":
markdownToHtml(source, {
features: { math: { singleDollarTextMath: false } },
});
Link to this headingFrontmatter
Default: true.
frontmatter?: boolean
Recognizes YAML (--- ... ---) and TOML (+++ ... +++) blocks at the top of a document.
The parsed block is returned alongside the rendered output:
const { html, frontmatter } = markdownToHtml(source);
if (frontmatter) {
console.log(frontmatter.kind); // "yaml" or "toml"
console.log(frontmatter.value); // raw string between the delimiters
}
Sätteri does not currently parse the TOML or YAML.
Link to this headingHeading attributes
Enabled by attributes. The older headingAttributes flag still enables heading attributes on their own, but it is deprecated.
Recognizes curly-brace attribute syntax on headings:
## My heading {#my-id .my-class}
The id and classes appear on the rendered heading, producing the following HTML:
<h2 id="my-id" class="my-class">My heading</h2>
# sets the id and . adds a class. You can also write arbitrary attributes as key=value, or a bare key for a valueless attribute (rendered as key=""):
### Note {#intro data-level=2 hidden}
<h3 id="intro" data-level="2" hidden="">Note</h3>
As in Pandoc, a block counts only if everything in it is an attribute: an id, a class, or a key that names one (letters, digits, -, _, :, . and @, as in data-x, x-on:click or @click). Anything else keeps the whole block as text, so other {...} syntax, such as {base|reading} ruby annotations, is left alone.
Wrap a value in " or ' quotes when it needs to contain spaces:
# Title {data-label="hello world"}
<h1 data-label="hello world">Title</h1>
Attributes keep the order they are written in, as in remark-directive. Explicit id= and class= merge with the #/. shorthands instead of producing duplicate attributes: each keeps the place it first appeared, the last id wins, and classes accumulate in source order:
## Heading {.intro #x class=lead id=main}
<h2 class="intro lead" id="main">Heading</h2>
Link to this headingIn MDX
MDX treats {...} as a JavaScript expression, which normally collides with the attribute syntax. Sätteri resolves this by only reading a trailing {...} as heading attributes when its contents aren't a valid expression — so {#id}, {.class} and {data-x=y} become attributes, while a real expression such as {title} is still evaluated:
# My heading {#my-id}
# Welcome {name}
A {...} that is valid JavaScript stays an expression even when it looks like attributes: {hidden}, {level=2} and {title="Home"} evaluate rather than apply — silently, and unlike in plain Markdown. Add a #/. shorthand to force attributes; {#id hidden} applies both.
Link to this headingAttributes
Default: false.
attributes?: boolean
Recognizes curly-brace attributes on more elements than headings, with the heading attribute syntax and merge rules. It also turns on heading attributes. Attributes on fenced code blocks follow the info string and go on the <code>:
```js {.highlight #example data-line=3}
console.log("hi");
```
<pre><code class="highlight language-js" id="example" data-line="3">console.log("hi");
</code></pre>
The language is written before the braces, so its class comes first, holding any attribute classes followed by language-js. Only a block that ends the info string counts; text before it stays in the code's meta.
Attributes on an inline element follow it with no space between: emphasis, strong, code spans, links, images and strikethrough. Blocks that follow one another merge:
**Note**{.warning} see [the guide](/guide){target=_blank} and `npm i`{.cmd}{#install}
<p><strong class="warning">Note</strong> see <a href="/guide" target="_blank">the guide</a> and <code class="cmd" id="install">npm i</code></p>
A block ending a paragraph's last line goes on the paragraph, or on the list item from the item's first line. A block on a line of its own goes on the block it's written after, at the level its > markers and indentation put it, as kramdown places a block IAL: written inside the blockquotes and list items around the paragraph, it goes on the paragraph (on its list item, in a tight list); written lazily outside some of them, it goes on the outermost it leaves, a list item giving its list. A paragraph holding only a block goes on the list, table or thematic break before it, and a block ending a table cell goes on the cell:
- Milk {.fresh}
- Eggs
{.groceries}
| Item {.name} |
| --- |
| Milk |
{.inventory}
<ul class="groceries">
<li class="fresh">Milk</li>
<li>Eggs</li>
</ul>
<table class="inventory">
<thead>
<tr>
<th class="name">Item</th>
</tr>
</thead>
<tbody>
<tr>
<td>Milk</td>
</tr>
</tbody>
</table>
In MDX, a {...} after an inline element or ending a paragraph is still a JavaScript expression.
Link to this headingDirectives
Default: false.
directive?: boolean
Enables container (:::name), leaf (::name), and text (:name) directives as defined by remark-directive. The parser produces directive nodes. Rendering them is up to a plugin; the default mdast→hast conversion drops them.
Link to this headingSuperscript / subscript
Default: false for both.
superscript?: boolean
subscript?: boolean
^text^ becomes <sup>text</sup> and ~text~ becomes <sub>text</sub>.
Subscript and GFM strikethrough share the ~ delimiter. Enabling subscript therefore disables GFM's single-tilde strikethrough (~text~ to <del>), only leaving double-tilde strikethrough (~~text~~) available.
Link to this headingWikilinks
Default: false.
wikilinks?: boolean
Recognizes [[Target]] and [[Target|Label]] as links.
Link to this headingDefinition lists
Default: false.
definitionList?: boolean
A term line followed by one or more definitions, each marked with a colon (:) or a tilde (~), becomes a definition list, following the pandoc / PHP Markdown Extra syntax:
Apple
: Pomaceous fruit.
: A tech company.
A term fits on one line, as in pandoc: after a paragraph of two or more lines, a marker line continues the paragraph instead of starting a definition.
A tight definition puts its content directly in the <dd>; a loose one — separated from its term by a blank line — wraps it in a <p>. The parser produces descriptionList, descriptionTerm, and descriptionDetails mdast nodes, each available to plugins.
Link to this headingLine breaks
Default: false.
breaks?: boolean
Turns every line ending inside a paragraph or heading into a hard break, as if each line ended with two spaces:
Roses are red
Violets are blue
renders as <p>Roses are red<br>\nViolets are blue</p>, and plugins see a break node between the two lines. Line endings in code, raw HTML, and image alt text stay as written.
Link to this headingSmart punctuation
Default: false.
smartPunctuation?: boolean | {
quotes?: boolean
dashes?: boolean
ellipses?: boolean
}
Pass true to enable all three categories at once, or an options object to turn on just the parts you want:
// Curly quotes only; leave -- and ... alone.
markdownToHtml(source, {
features: { smartPunctuation: { quotes: true, dashes: false, ellipses: false } },
});
Omitted keys in the options object default to true, so { dashes: false } enables quotes and ellipses but disables dashes.
Link to this headingRaw HTML
Default: false.
rawHtml?: boolean
By default, raw HTML embedded in Markdown is kept as opaque raw nodes and re-emitted verbatim. rawHtml: true reparses it into real HAST element, text, and comment nodes. The reparse runs during the mdast→hast conversion, so markdownToHast, markdownToHtml, and the plugin pipelines all reparse identically, and HAST plugins always see the reparsed elements.
The whole tree goes through the HTML parser, so a tag opened in one raw block and closed in another is resolved against the surrounding Markdown. Attributes are normalised into typed hast properties (class → className: ["…"], disabled → true, tabindex → a number, data-foo-bar → dataFooBar). In MDX, JSX elements and expressions are preserved in place while the raw HTML around them is still resolved. Positions are not preserved through the reparse.
import { markdownToHast } from "satteri";
const tree = markdownToHast(`<div class="note">\n\n**hi**\n\n</div>`, {
features: { rawHtml: true },
});
// <div> is now a real element wrapping the parsed <p><strong>hi</strong></p>