Repository navigation
Releases
mdastic@0.6.0
mdastic now matches what a fresh npm i remark remark-gfm remark-mdx remark-stringify installs today.
stringifymatchesmdast-util-to-markdown2.2.3. Fewer escapes (intraword_stays as is), emphasis and strong pick*or_so every run parses back the same, tight lists keep blank lines where needed, and link text that looks like a definition gets an empty title.stringify(parse('snake_case and x86_64')) // 'snake_case and x86_64\n', was 'snake\\_case and x86\\_64\n'
- Custom
unsafepatterns supportbeforeNode,afterNodeandunicode. - GFM tables match
mdast-util-gfm-table2.0.1. Rows keep their own cell count instead of being padded. - GFM autolink literals match
mdast-util-gfm-autolink-literal2.1.0. Emails after punctuation like/link,mailto:andxmpp:addresses link with their scheme, and hosts that start with punctuation no longer link.parse('mailto:a@b.co', { syntax: [gfm()] }) // link 'mailto:a@b.co'
- Task list checks match
mdast-util-gfm-task-list-item2.0.1. Checks after definitions, empty checked items andbulletOrdered: ")"now serialize correctly. - Multi-line JSX attribute expressions are indented like
mdast-util-mdx-jsx3.2.1.
mdastic@0.5.1
- Unclosed
<!--comments withhtmlCommentsfollow CommonMark. A comment that starts a block and never closes now runs to the end of its container, like a browser hides the rest of the page, instead of returning an MDX error.
mdastic@0.5.0
-
visittakes one visitor per node type, so several transforms share one walk:visit(tree, { heading: (node) => { node.depth }, code: (node) => { node.lang }, })
-
JSX helpers in
mdastic/mdx.isJsx(node, 'Card'),getAttribute,setAttribute,removeAttribute, andexpression(source), which builds an attribute value withdata.estree.isParent(node)frommdasticnarrows to nodes withchildren.if (isJsx(node, 'Card')) { setAttribute(node, 'target', '_blank') setAttribute(node, 'title', expression('<Markdown inline children="**hi**" />')) }
-
New
mdx({ htmlComments: true })option. Parses<!-- comments -->ashtmlnodes in flow and inline, instead of returning an MDX error. Off by default, so parsing still matches remark-mdx. -
Single-line JSX after
unravelstringifies on one line.<Note>Use `x` here.</Note>is written back as written, and parses to the same tree. remark writes each child as its own paragraph, which changes the tree. This is a deliberate difference from remark.
mdastic@0.4.0
- New
createProcessor({ syntax, transforms, stringify }). One syntax list forparseandstringify, plus(tree) => voidtransforms that run after every parse. createStreamParser({ transforms }). Block-local transforms run once on each settled block and on the live tail; every result equalscreateProcessor(...).parse(text).- New
unravel(tree)inmdastic/mdx. Unwraps paragraphs of only JSX and expressions into flow nodes, like@mdx-js/mdx's remark-mark-and-unravel. visitaccepts[SKIP, index], like unist-util-visit: skip the node's children and continue atindex.- Types assign to
@types/mdast.MdxjsEsmis now only inRootContent, notFlowContent, matching mdast-util-mdxjs-esm, so mdastic trees are assignable to mdast trees.
mdastic@0.3.4
-
MDX errors now match remark's VFileMessage fully.
MdxParseErrorhas the sameurlas micromark, and errors from mdast-util-mdx-jsx andnon-esmerrors have a rangeplace, sonameandString(error)match remark:const error = parse('<a></a/>', { syntax: [mdx()] }) String(error) // '1:7-1:8: Unexpected self-closing slash `/` in closing tag, expected the end of the tag'
-
Fixed MDX error order for closing tags. An attribute or self-closing slash in a closing tag is reported after a missing opening tag and after later micromark errors, like remark (
a </a b> c). -
Fixed error ranges at container ends. An unclosed code fence inside an open JSX tag in a list or footnote now reports remark's container end.
-
Tree-shakable.
package.jsonsets"sideEffects": false, so bundles that do not callparseorstringifydrop mdastic and acorn.
mdastic@0.3.3
- Fixed container end positions for nested block quotes, list items, and other blocks to match remark.
- Fixed MDX flow lines in containers, including paragraph interruption and JSX list item spread.
- Fixed fenced code endings and tables in nested containers to match remark across line endings and container boundaries.
- Fixed escaping at the end of link destinations to match remark.
mdastic@0.3.2
- Fixed multi-line MDX tags in containers. A JSX tag that spans lines now follows every tag and expression on its line, inside the container's own view, like remark. These inputs parsed as errors before:
<p><strong \n>o</strong></p>isp > strong > "o"><_/\n>>>is a block quote with<_/>and>> <a b\n>>>reports remark's "Expected a closing tag" error
- Fixed lists inside footnote definitions. The definition indent ends list items like a container prefix, so
spreadand item ends match remark when a blank line or a new container follows ([^1]:-\n\n -). - Fixed nested block quotes closed by a new container. They end at the enclosing prefix for footnote definitions too (
>>a\n>[^1]: b), and not for thematic breaks that look like list markers (>>a\n>* * *). - Fixed MDX end-of-file errors at container boundaries. When a new container closes an unfinished JSX tag or expression, mdastic reports the same error and place as remark.
mdastic@0.3.1
- Fixed link and image label parsing to match remark:
- JSX tags with spread attributes inside a label no longer fail with an acorn error (
) - references inside a label resolve before the outer label is rejected, and each inner label takes its own resource or reference (
![[a][]([)](/z)with[a]defined) - defined footnote calls inside a label take no resource (
[x [^a](])](/z)) - emphasis and strikethrough inside labels resolve in micromark's order
- JSX tags with spread attributes inside a label no longer fail with an acorn error (
- Fixed tables and lazy lines in containers (block quotes, list items, footnote definitions):
- tables are tracked through nested containers, so a lazy line after a table never joins it or opens a new table
- a lazy line declined by a nested quote closes all containers
- blank lines and footnote labels are never table head rows
- a table head row ends the link definitions before it (
[a]: u\nb|c\n-|-), so references to them resolve - HTML block starts win over GFM table head rows (
<!-- c -->\n:-)
- Fixed paragraph interruption in containers: after a paragraph or indented code in a quote, list item or footnote, a marker that cannot interrupt (
*alone,2.) stays paragraph text and keeps taking lazy lines. HTML blocks in containers no longer take lazy lines. - Fixed list and task list details:
- list
spreadwhen quoted lists close and around footnote definitions, and quoted list item positions [x]is a task checkbox only in an item's first content, not after* \n [x] aor a blank line after definitions- unclosed fenced code or HTML in a list item keeps remark's trailing blank lines when a footnote definition or
- --follows
- list
- Fixed split tabs in containers: leftover tab columns stay data in code spans, inline math and MDX expression continuation lines, like remark.
- Fixed MDX differences from remark:
- quoted JSX attribute values decode character references like
parse-entities(€is€,©e;is©e;) - flow tags or expressions on a container's paragraph continuation line that reach a lazy line now return remark's
unexpected-lazyerror (> a\n{\n}b) - JSX errors are reported in micromark's token exit order, and an unclosed expression at the end of a block quote reports the same place as remark
- footnotes inside footnotes inside JSX flow tags take the outer indent
- quoted JSX attribute values decode character references like
- Fixed quadratic parse time for unclosed
{lines in block quotes, long runs of link definitions, and[/![[]()bracket floods. These inputs now parse in linear time.
mdastic@0.3.0
-
New
createStreamParser()for streaming markdown and MDX, like an LLM response. Pass the whole text so far on every chunk; each result equalsparse(text):import { createStreamParser } from 'mdastic' import { mdx } from 'mdastic/mdx' import { gfm } from 'mdastic/gfm' const parser = createStreamParser({ syntax: [mdx(), gfm()] }) let text = '' for await (const chunk of response) { text += chunk const tree = parser.parse(text) if (tree instanceof Error) continue // incomplete MDX, keep the last good tree render(tree) }
Top-level blocks that can no longer change are cached and returned as the same objects on every call, so a renderer can memoize them. Only the text after the last safe cut is parsed again. Streaming in 32-character chunks is 2.7x to 10x faster than calling
parseon every chunk. Do not mutate returned trees: cached blocks are shared. Documents with link or footnote definitions or MDX imports are parsed in full on each call. -
Fixed footnote definition parsing to match remark, which treats them as containers like block quotes and list items:
- footnote labels are recognized before tables and link definitions (
[a]: b\n[^c]: d,[^b]: c\n|-|) - lazy lines after a footnote can start any list (
[^a]: b\n2) x) - paragraph interruption carries through footnote labels, footnotes directly inside footnotes take the outer indent
- definitions on lines with leftover tab columns, indented code in a container after a definition, and HTML after a definition now parse like remark
- footnote labels are recognized before tables and link definitions (
-
Fixed MDX parse differences from remark:
- link and footnote definitions take any indentation in MDX (
[e]: f), since MDX has no indented code - an
import/exportline right after a definition stays paragraph text - an unclosed frontmatter fence starts no block quotes, lists or footnotes
end-tag-mismatcherrors name micromark tokens like remark (atxHeading,gfmFootnoteDefinition,strikethrough,tableData)
- link and footnote definitions take any indentation in MDX (
-
Fixed markdown parse differences from remark:
- image alt text no longer keeps escapes or character references from GFM literal autolinks (
gives althttp://a.b) - unmatched backtick runs inside link and image labels stay text as a whole (
![a``)
- lazy lines inside quoted list items keep their indentation in code spans and inline math
- only the first list item after a paragraph inherits its interruption rules (
0\n- a\n- -)
- image alt text no longer keeps escapes or character references from GFM literal autolinks (
-
Fixed cubic MDX parse time for
{/}lines inside block quotes. A 1.2 MB docs page that never finished now parses in under 200 ms.
Thanks @rgodha24 for #11, #12, #13, #14, #15, #16, #17 and #18!
mdastic@0.2.0
-
New opt-in math syntax. Parse and serialize
$x$inline math and$$blocks with the same nodes, positions and markdown as remark-math:import { parse, stringify } from 'mdastic' import { math } from 'mdastic/math' const syntax = [math()] const tree = parse('Energy: $E = mc^2$', { syntax }) if (tree instanceof Error) throw tree const markdown = stringify(tree, { syntax })
Use
math({ singleDollarTextMath: false })to require at least two dollars for inline math. Withoutmath(), dollar signs remain ordinary text.