Skip to content

Lossless Flavored Markdown

Lossless Flavored Markdown — MDX power without MDX’s opinions.

LFM turns many markdown authoring conventions (CommonMark, GFM, directives, Obsidian callouts, hex-code citations, Obsidian embeds, MDX components) into one AST for your framework’s components to render. It reads .mdx files too: their JSX components arrive as nodes naming the component file they import, and nothing in the file is executed. If you want CommonMark only, use remark-parse.

Live demo · Site · Changelog · Docs

Install

Install from JSR with an npm alias:

package.json
{
"dependencies": {
"@lossless-group/lfm": "npm:@jsr/lossless-group__lfm@^0.9.0"
}
}
.npmrc
@jsr:registry=https://npm.jsr.io

Newer pnpm versions can use "@lossless-group/lfm": "jsr:^0.9.0" instead, with no .npmrc line. GitHub Packages also carries a mirror, but it needs an auth token.

Quick start

import { parseMarkdown } from '@lossless-group/lfm';
const tree = await parseMarkdown(markdownContent);
// tree is an MDAST. Your renderer maps its nodes to components.

To add LFM to an existing unified pipeline, use the preset:

import { unified } from 'unified';
import remarkParse from 'remark-parse';
import { remarkLfm } from '@lossless-group/lfm';
const processor = unified().use(remarkParse).use(remarkLfm);
const tree = await processor.run(processor.parse(content));

Every plugin is also exported on its own, for example remarkLfmCallouts.

Use in the browser / from a CDN

@lossless-group/lfm/browser has the parser, the preset and every plugin, and nothing that needs Node, so a page with no build step (a Claude artifact, a CodePen) can import it from jsDelivr, which mirrors npm. Replace <version> with a published version.

<script type="module">
import { unified } from 'https://cdn.jsdelivr.net/npm/unified@11/+esm';
import remarkRehype from 'https://cdn.jsdelivr.net/npm/remark-rehype@11/+esm';
import rehypeStringify from 'https://cdn.jsdelivr.net/npm/rehype-stringify@10/+esm';
import { parseMarkdown } from 'https://cdn.jsdelivr.net/npm/@lossless-group/lfm@<version>/browser/+esm';
const tree = await parseMarkdown('A claim.[^a3f9b2]\n\n[^a3f9b2]: [A source](https://example.com)');
const hast = await unified().use(remarkRehype).run(tree);
const html = unified().use(rehypeStringify).stringify(hast);
const sources = tree.data.citations.ordered; // [{ index: 1, identifier: 'a3f9b2', title, url }]
</script>

Open Graph fetching is left out, since it caches to disk. The browser guide covers esm.sh and unpkg, rendering the sources list, and why the two steps stay separate.

What you can write

You want You write Setup Guide
Tables, task lists, strikethrough, autolinks GFM On by default
Callouts > [!warning] Title or :::callout{type="warning"} On by default
Private notes, left out of the page %%comment%%, inline or across blocks On by default Comments
Citations [^a1b2c3] On by default Citations
Heading anchors and a table of contents Any heading On by default Headings
An eyebrow and subheading on a heading $$ Eyebrow and && Subheading On by default Headings
Link previews :::link-preview or :::link-rollup On by default; fetching metadata needs ogFetch Link previews
Image carousels :::image-carousel On by default Image carousels
Mermaid diagrams A mermaid code fence Register the format; your site draws it with mermaid.js Code fences
Graphviz, PlantUML, Vega-Lite, YANG, JSON Schema, JSON Canvas A code fence named for the format Register the format Code fences
Colored code Any code fence Import /highlight in your code block component Highlighting
Wikilinks [[Page]] or [[folder/Page#Section|Display]] Supply a resolver or path config Wikilinks
Task metadata - [ ] @handle Title #Tag ~3d 2026-11-15 Set taskMetadata Tasks
A section of another document, shown here ![[Note#Heading]] on its own line Set crossReferenceEmbeds with a load function Cross-reference embeds
Components in .mdx files import X from './X.astro' and <X prop={[…]} /> Set mdx for .mdx files MDX
A citation of an agent skill, or a pack of them as cards :skill[slug] and :::skill-pack Suggested component: parsed already; your site keeps the registry and renders it Agent skills

A bare URL on its own line can also become an embed. The provider catalog ships now, but sites classify the URLs themselves until the plugin lands. See Link previews.

How it works

Authors keep writing in whatever syntax their tool prefers. A remark plugin matches the pattern (the trigger), and the parser emits one canonical node for your renderer.

flowchart LR
subgraph SYN["01 · Syntax — author"]
S1[":::callout{type=warning}"]
S2["&gt; [!warning] Title"]
S3["bare youtu.be/{id}"]
S4["[^a1b2c3]"]
S5["&lt;BarChart items={[…]} /&gt; in .mdx"]
S6["![[Note#Heading]]"]
end
subgraph TRG["02 · Trigger — LFM ships"]
T1["remark-lfm-callouts"]
T2["lfm-link-preview"]
T3["remark-lfm-citations"]
T4["remark-lfm-mdx"]
T5["lfm-cross-reference-embeds"]
end
subgraph CMP["03 · Component — your renderer"]
C1["one MDAST callout node"]
C2["one MDAST link-preview node"]
C3["one MDAST citation node"]
C4["one component node + its import"]
C5["one cross-reference-embed block + its source"]
end
S1 --> T1
S2 --> T1
S3 --> T2
S4 --> T3
S5 --> T4
S6 --> T5
T1 --> C1
T2 --> C2
T3 --> C3
T4 --> C4
T5 --> C5

A directive callout and an Obsidian callout produce the same node, so your <Callout> renders one shape whichever tool wrote the file. Supporting a new syntax means adding a plugin, with no renderer changes. This package owns the first two stages, and the components are yours.

MDX is one more trigger

An MDX component is LFM’s equivalent of a directive. Both put a component, with its props, at a place in the prose:

Directive (.md)MDX (.mdx)
::stat{value="5×" label="vs. peers"}
import Stat from '../components/Stat.astro';
<Stat value="5×" label="vs. peers" />
A leafDirective named stat. Your renderer finds the component by name in its own trigger map.A componentNode with triggerSyntax: 'mdx', its props, and import.resolved: 'src/components/Stat.astro' (for a file in src/content/). Your renderer renders that file; no lookup.

The difference is who says which component: a directive names it and the site decides; an MDX file imports it itself. Props keep their real types, so items={[{ value: 18000 }]} arrives as an array. They are read as data, never executed. Turn mdx on for .mdx files only, since MDX changes how < and { parse. See MDX.

Show a section of another document

Obsidian’s embed syntax works too. On a line of its own:

![[Google Maps#Google Maps API managing policies.]]
![[Tooling/Products/Google Maps#Google Maps API managing policies.|Google Maps]]

LFM loads the other document through a load function you supply (it never reads files itself), cuts out that section (its heading, up to the next heading at the same level), and puts it in place as one cross-reference-embed block. The block carries where it came from (title, url), so your renderer can show it as part of the page, with a small “From Google Maps” line and a link that opens the original:

const tree = await parseMarkdown(body, {
crossReferenceEmbeds: {
load: async ({ path }) => {
const note = await findNote(path);
return note ? { markdown: note.body, url: note.url } : null;
},
},
});

![[Note]] embeds a whole document, #A#B a section inside a section, and a missing document or section still arrives, empty, with a status saying why. Astro sites can copy the CrossReferenceContentEmbed component from astro-knots’ packages/lfm-astro. See Cross-reference embeds.

Options

const tree = await parseMarkdown(content, {
gfm: true, // default: true
directives: true, // default: true; also enables link previews and carousels
callouts: true, // default: true
citations: true, // default: true
headingIds: true, // default: true
headingBlocks: true, // default: true
comments: true, // default: true; leaves %%notes%% out of the page
// Opt-in, because each needs something from you:
// codeFences: { formats: [mermaid] },
// wikilinks: { resolver },
// taskMetadata: true,
// ogFetch: { enabled: true }, // makes network calls
// mdx: { filePath }, // .mdx files only; resolves component imports
// crossReferenceEmbeds: { load }, // ![[Note#Heading]]; makes parsing async
});

Imports

Import Contains
@lossless-group/lfm parseMarkdown, the remarkLfm preset, and every plugin
@lossless-group/lfm/browser The same, minus Open Graph fetching, with no Node imports. In the browser
@lossless-group/lfm/formats Code-fence handlers, including mermaid
@lossless-group/lfm/formats/yang The YANG handler
@lossless-group/lfm/formats/json-schema The JSON Schema handler
@lossless-group/lfm/formats/plantuml The PlantUML handler, which needs Node
@lossless-group/lfm/highlight highlightCode
@lossless-group/lfm/resolve-path createPathResolver
@lossless-group/lfm/types TypeScript types

Plugin names from before 0.5.0, such as remarkCallouts, still work as permanent aliases.

More

License

MIT