Skip to content

Fix range of mdast-util-to-markdown - #22

Merged
wooorm merged 1 commit into
syntax-tree:mainfrom
slorber:fix-to-markdown-range
Oct 30, 2026
Merged

wooorm merged 1 commit into
syntax-tree:mainfrom
slorber:fix-to-markdown-range

Conversation

@slorber

@slorber slorber commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

7a13d4a (released in 3.1.1) uses the unicode and afterNode fields on unsafe patterns, which were added in mdast-util-to-markdown@2.2.0. But package.json still allows mdast-util-to-markdown@^2.0.0.

Projects whose lockfile already has mdast-util-to-markdown@2.1.x keep it when they upgrade only mdast-util-directive, as Dependabot does. 2.1.x ignores both fields: it compiles [^\s\p{P}\p{S}] without the u flag, where \p is a literal p. So colons followed by punctuation get escaped, including in link URLs:

import {directiveToMarkdown} from 'mdast-util-directive'
import {toMarkdown} from 'mdast-util-to-markdown'

const tree = {
  type: 'paragraph',
  children: [
    {
      type: 'link',
      url: 'https://example.com',
      children: [{type: 'text', value: 'a'}]
    },
    {type: 'text', value: ' b:. c:)'}
  ]
}

console.log(toMarkdown(tree, {extensions: [directiveToMarkdown()]}))

With mdast-util-to-markdown@2.1.2:

[a](https\://example.com) b\:. c\:)

With mdast-util-to-markdown@2.2.0:

[a](https://example.com) b:. c:)

We ran into it in Docusaurus: meta/docusaurus#12804.

🤖 Generated with Claude Code

The `unicode` and `afterNode` fields on unsafe patterns,
used since 7a13d4a, were added in `mdast-util-to-markdown@2.2.0`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Oct 30, 2026
@wooorm
wooorm merged commit 4049f96 into syntax-tree:main Oct 30, 2026
5 checks passed
@github-actions

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label Oct 30, 2026
@github-actions github-actions Bot removed the 🤞 phase/open Post is being triaged manually label Oct 30, 2026
@wooorm

wooorm commented Oct 30, 2026

Copy link
Copy Markdown
Member

thanks, released in 3.2.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💪 phase/solved Post is done

Development

Successfully merging this pull request may close these issues.

2 participants