Skip to content

Releases

mdastic@0.6.0

Choose a tag to compare

@remorses remorses released this 19 Nov 16:25

mdastic now matches what a fresh npm i remark remark-gfm remark-mdx remark-stringify installs today.

  1. stringify matches mdast-util-to-markdown 2.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'
  2. Custom unsafe patterns support beforeNode, afterNode and unicode.
  3. GFM tables match mdast-util-gfm-table 2.0.1. Rows keep their own cell count instead of being padded.
  4. GFM autolink literals match mdast-util-gfm-autolink-literal 2.1.0. Emails after punctuation like / link, mailto: and xmpp: 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'
  5. Task list checks match mdast-util-gfm-task-list-item 2.0.1. Checks after definitions, empty checked items and bulletOrdered: ")" now serialize correctly.
  6. Multi-line JSX attribute expressions are indented like mdast-util-mdx-jsx 3.2.1.

mdastic@0.5.1

Choose a tag to compare

@remorses remorses released this 03 Nov 14:19
  1. Unclosed <!-- comments with htmlComments follow 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

Choose a tag to compare

@remorses remorses released this 03 Nov 14:06
  1. visit takes one visitor per node type, so several transforms share one walk:

    visit(tree, {
      heading: (node) => { node.depth },
      code: (node) => { node.lang },
    })
  2. JSX helpers in mdastic/mdx. isJsx(node, 'Card'), getAttribute, setAttribute, removeAttribute, and expression(source), which builds an attribute value with data.estree. isParent(node) from mdastic narrows to nodes with children.

    if (isJsx(node, 'Card')) {
      setAttribute(node, 'target', '_blank')
      setAttribute(node, 'title', expression('<Markdown inline children="**hi**" />'))
    }
  3. New mdx({ htmlComments: true }) option. Parses <!-- comments --> as html nodes in flow and inline, instead of returning an MDX error. Off by default, so parsing still matches remark-mdx.

  4. Single-line JSX after unravel stringifies 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

Choose a tag to compare

@remorses remorses released this 02 Nov 20:04
  1. New createProcessor({ syntax, transforms, stringify }). One syntax list for parse and stringify, plus (tree) => void transforms that run after every parse.
  2. createStreamParser({ transforms }). Block-local transforms run once on each settled block and on the live tail; every result equals createProcessor(...).parse(text).
  3. New unravel(tree) in mdastic/mdx. Unwraps paragraphs of only JSX and expressions into flow nodes, like @mdx-js/mdx's remark-mark-and-unravel.
  4. visit accepts [SKIP, index], like unist-util-visit: skip the node's children and continue at index.
  5. Types assign to @types/mdast. MdxjsEsm is now only in RootContent, not FlowContent, matching mdast-util-mdxjs-esm, so mdastic trees are assignable to mdast trees.

mdastic@0.3.4

Choose a tag to compare

@remorses remorses released this 02 Nov 17:50
  1. MDX errors now match remark's VFileMessage fully. MdxParseError has the same url as micromark, and errors from mdast-util-mdx-jsx and non-esm errors have a range place, so name and String(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'
  2. 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).

  3. 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.

  4. Tree-shakable. package.json sets "sideEffects": false, so bundles that do not call parse or stringify drop mdastic and acorn.

mdastic@0.3.3

Choose a tag to compare

@remorses remorses released this 30 Oct 18:22
  1. Fixed container end positions for nested block quotes, list items, and other blocks to match remark.
  2. Fixed MDX flow lines in containers, including paragraph interruption and JSX list item spread.
  3. Fixed fenced code endings and tables in nested containers to match remark across line endings and container boundaries.
  4. Fixed escaping at the end of link destinations to match remark.

Thanks @rgodha24 for #44, #45 and #46!

mdastic@0.3.2

Choose a tag to compare

@remorses remorses released this 29 Oct 10:16
  1. 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> is p > strong > "o"
    • ><_/\n>>> is a block quote with <_/> and >
    • > <a b\n>>> reports remark's "Expected a closing tag" error
  2. Fixed lists inside footnote definitions. The definition indent ends list items like a container prefix, so spread and item ends match remark when a blank line or a new container follows ([^1]:-\n\n -).
  3. 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>* * *).
  4. 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.

Thanks @rgodha24 for #41 and #42!

mdastic@0.3.1

Choose a tag to compare

@remorses remorses released this 28 Oct 14:33
  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 (![<a {...b}/>](x))
    • 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
  2. 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:-)
  3. 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.
  4. Fixed list and task list details:
    • list spread when 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] a or 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
  5. Fixed split tabs in containers: leftover tab columns stay data in code spans, inline math and MDX expression continuation lines, like remark.
  6. Fixed MDX differences from remark:
    • quoted JSX attribute values decode character references like parse-entities (&#128; is €, &copye; is ©e;)
    • flow tags or expressions on a container's paragraph continuation line that reach a lazy line now return remark's unexpected-lazy error (> 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
  7. 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.

Thanks @rgodha24 for #19 to #40 and #43!

mdastic@0.3.0

Choose a tag to compare

@remorses remorses released this 27 Oct 18:20
  1. New createStreamParser() for streaming markdown and MDX, like an LLM response. Pass the whole text so far on every chunk; each result equals parse(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 parse on 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.

  2. 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
  3. 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 / export line right after a definition stays paragraph text
    • an unclosed frontmatter fence starts no block quotes, lists or footnotes
    • end-tag-mismatch errors name micromark tokens like remark (atxHeading, gfmFootnoteDefinition, strikethrough, tableData)
  4. Fixed markdown parse differences from remark:

    • image alt text no longer keeps escapes or character references from GFM literal autolinks (![http://a\.b](/x.png) gives alt http://a.b)
    • unmatched backtick runs inside link and image labels stay text as a whole (![ab```)
    • 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- -)
  5. 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

Choose a tag to compare

@remorses remorses released this 26 Oct 19:33
  1. 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. Without math(), dollar signs remain ordinary text.

Thanks @rgodha24 for #10!