Skip to content

fix(x-markdown): update marked to v18 to fix strikethrough parsing - #2023

Open
waterWang wants to merge 1 commit into
ant-design:mainfrom
waterWang:fix/update-marked-to-v18
Open

fix(x-markdown): update marked to v18 to fix strikethrough parsing#2023
waterWang wants to merge 1 commit into
ant-design:mainfrom
waterWang:fix/update-marked-to-v18

Conversation

@waterWang

@waterWang waterWang commented Aug 11, 2026

Copy link
Copy Markdown

Background

The tilde-syntax strikethrough (~123 foo bar (~123)~) was rendering as plain text in XMarkdown because the marked dependency had a known parsing bug fixed in later versions.

Fix

Update marked from ^15.0.12 to ^18.0.7. The issue reporter confirmed this works via package overrides.

Related

Closes #2000

Summary by CodeRabbit

  • 改进
    • 更新 Markdown 渲染组件所使用的解析依赖,提升兼容性与稳定性。

The tilde-syntax strikethrough (~123~) was rendering as plain text
because marked v15 had a known parsing bug. Update from ^15.0.12
to ^18.0.7 where the fix was released.

Closes ant-design#2000
@dosubot dosubot Bot added bug Something isn't working dependencies Pull requests that update a dependency file labels Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

本次变更将 x-markdownmarked 运行时依赖从 ^15.0.12 更新为 ^18.0.7

Changes

XMarkdown 依赖更新

Layer / File(s) Summary
更新 marked 版本
packages/x-markdown/package.json
marked 运行时依赖版本更新为 ^18.0.7

Estimated code review effort: 1(低)| ~5 分钟

Possibly related PRs

  • ant-design/x#1969:同样更新 packages/x-markdown/package.json 中的 marked 依赖,但目标版本为 16.x。

Suggested reviewers: kimteayon

Poem

我是兔子,蹦过版本号,
marked 已到十八。
破浪线,稳解析,
XMarkdown 轻轻笑。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题明确说明将 marked 更新至 v18,并指出修复删除线解析问题,准确概括了主要变更。
Linked Issues check ✅ Passed PR 将 marked 更新至 18.0.7,符合 issue #2000 关于修复 XMarkdown 删除线解析问题的要求。
Out of Scope Changes check ✅ Passed 变更仅更新 XMarkdown 的 marked 运行时依赖,未发现与 issue #2000 无关的代码变更。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/x-markdown/package.json`:
- Line 60: 不要仅升级 marked;在项目现有的 Markdown 解析入口增加自定义 tokenizer 或预处理逻辑,使输入 ~123 foo
bar (~123)~ 输出为 <del>123 foo bar (~123)</del>。补充覆盖该输入与期望 HTML
的回归测试,并保留其他删除线语法的现有解析行为。
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 64e3f089-5168-4648-8154-2c39b35d8606

📥 Commits

Reviewing files that changed from the base of the PR and between 25aad7b and 46a3863.

📒 Files selected for processing (1)
  • packages/x-markdown/package.json

"html-react-parser": "^5.2.13",
"katex": "^0.16.22",
"marked": "^15.0.12"
"marked": "^18.0.7"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

repo_root="$(git rev-parse --show-toplevel)"
test_file="$repo_root/packages/x-markdown/src/XMarkdown/__tests__/Parser.test.ts"

rg -n '123 foo bar \(~123\)|<del>123 foo bar' "$test_file"

cd "$repo_root"
if [ -f pnpm-lock.yaml ]; then
  pnpm --dir packages/x-markdown test
elif [ -f yarn.lock ]; then
  yarn --cwd packages/x-markdown test
else
  npm --prefix packages/x-markdown test
fi

Repository: ant-design/x

Length of output: 150


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- package manifest ---'
sed -n '1,120p' packages/x-markdown/package.json

printf '%s\n' '--- parser test structure and target references ---'
ast-grep outline packages/x-markdown/src/XMarkdown/__tests__/Parser.test.ts
rg -n -C 3 'strikethrough|tilde|del|newline|custom|tag|123 foo bar' \
  packages/x-markdown/src/XMarkdown/__tests__/Parser.test.ts || true

printf '%s\n' '--- dependency declarations and lock entries ---'
rg -n -C 2 '"marked"|marked@|marked:' \
  packages/x-markdown/package.json package.json pnpm-lock.yaml yarn.lock package-lock.json 2>/dev/null || true

printf '%s\n' '--- repository status and available package scripts ---'
git status --short
node -e 'const p=require("./packages/x-markdown/package.json"); console.log(JSON.stringify(p.scripts,null,2))'

Repository: ant-design/x

Length of output: 8896


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- tracked lockfiles ---'
git ls-files | rg '(^|/)(pnpm-lock\.yaml|yarn\.lock|package-lock\.json|bun\.lockb?)$' || true

printf '%s\n' '--- parser implementation and marked usage ---'
rg -n -C 5 'from .*(marked|Parser)|marked\(|parse\(|markedConfig|protectCustomTagNewlines|paragraphTag' \
  packages/x-markdown/src/XMarkdown packages/x-markdown/src 2>/dev/null | head -n 260

printf '%s\n' '--- complete parser test file ---'
cat -n packages/x-markdown/src/XMarkdown/__tests__/Parser.test.ts

printf '%s\n' '--- package workspace context ---'
sed -n '1,180p' package.json

Repository: ant-design/x

Length of output: 38548


🌐 Web query:

marked 18.0.0 release breaking change trailing blank lines 18.0.7 tilde interrupt regex fix

💡 Result:

In the marked library, version 18.0.0 introduced a breaking change that trims trailing blank lines from block tokens [1][2][3]. Additionally, version 18.0.7 included a fix to avoid O(n^2) backtracking in the HTML block close and tilde interrupt regexes [4][5], addressing potential ReDoS (Regular Expression Denial of Service) vulnerabilities [6][5].

Citations:


🌐 Web query:

marked 18.0.7 parse "~123 foo bar (~123)~" output

💡 Result:

In marked version 18.0.7, the syntax ~123 is treated as standard text unless specifically configured otherwise, as marked does not implement strikethrough (typically denoted by ~~text~~) or other tilde-based formatting by default without extensions or specific configurations [1][2]. Regarding your specific input ~123 foo bar (~123)~, marked 18.0.7 will parse this as plain text wrapped in paragraph tags, resulting in output similar to <p>~123 foo bar (~123)~</p>. It is worth noting that version 18.0.7 included specific bug fixes related to tilde characters, specifically: - Avoidance of O(n^2) backtracking in tilde interrupt regexes [3][4]. - Preservation of code spans adjacent to tildes [3][4]. These updates ensure that the parser handles tildes more efficiently and correctly in contexts where they might interact with other markdown elements, but they do not change the default behavior of treating single tildes as literal characters [3][4].

Citations:


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- local dependency availability ---'
node -e 'try { console.log(require.resolve("marked")); } catch (e) { console.log("marked is not installed"); }'

printf '%s\n' '--- marked package metadata from the registry ---'
curl -fsSL https://registry.npmjs.org/marked/18.0.7 |
  node -e '
    let s = "";
    process.stdin.on("data", d => s += d);
    process.stdin.on("end", () => {
      const p = JSON.parse(s);
      console.log(JSON.stringify({
        version: p.version,
        engines: p.engines,
        exports: p.exports,
        dist: p.dist && { tarball: p.dist.tarball, integrity: p.dist.integrity }
      }, null, 2));
    });
  '

printf '%s\n' '--- marked 18.0.7 strikethrough rule source ---'
curl -fsSL https://unpkg.com/marked@18.0.7/lib/marked.esm.js |
  rg -n -C 3 'tilde|del|~~|gfm' | head -n 120

Repository: ant-design/x

Length of output: 37196


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

node - <<'JS'
const versions = ['15.0.12', '18.0.7'];

for (const version of versions) {
  const source = await (await fetch(`https://unpkg.com/marked@${version}/lib/marked.esm.js`)).text();
  const module = await import(`data:text/javascript,${encodeURIComponent(source)}`);
  const marked = module.marked ?? module.default;

  const input = '~123 foo bar (~123)~';
  const result = marked(input);
  console.log(JSON.stringify({ version, input, result }));

  if (version === '18.0.7' && !result.includes('<del>123 foo bar (~123)</del>')) {
    process.exitCode = 1;
  }
}
JS

Repository: ant-design/x

Length of output: 518


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

printf '%s\n' '--- tilde and strikethrough handling in the package ---'
rg -n -C 4 'strikethrough|strike|tilde|~~|~123|markedConfig|Tokenizer|del\(' \
  packages/x-markdown packages 2>/dev/null | head -n 260

printf '%s\n' '--- Parser constructor and configuration ---'
sed -n '1,130p' packages/x-markdown/src/XMarkdown/core/Parser.ts

printf '%s\n' '--- Parser preprocessing and parse path ---'
sed -n '250,375p' packages/x-markdown/src/XMarkdown/core/Parser.ts

Repository: ant-design/x

Length of output: 29747


不要仅升级 marked,请修复目标输入的解析行为。

marked@18.0.7~123 foo bar (~123)~ 的输出为 <p>~123 foo bar (<del>123)</del></p>\n。如果必须输出 <del>123 foo bar (~123)</del>,请增加自定义 tokenizer 或预处理逻辑,并添加回归测试。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/x-markdown/package.json` at line 60, 不要仅升级 marked;在项目现有的 Markdown
解析入口增加自定义 tokenizer 或预处理逻辑,使输入 ~123 foo bar (~123)~ 输出为 <del>123 foo bar
(~123)</del>。补充覆盖该输入与期望 HTML 的回归测试,并保留其他删除线语法的现有解析行为。

@nrps9909 nrps9909 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exact head 46a386328c2dbda4f5b92b98e34ca54afa93d4 is not the current PR head, so this review command should not have reached submission.

@nrps9909 nrps9909 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction to my immediately preceding review: the reviewed and current exact head is 46a386328c2dbda4f5b92cf3e7a551c2bb33fd54; the shorter SHA in that review body was a transcription error. The CHANGES_REQUESTED state is intentional for the following verified reasons:

  1. This PR changes only packages/x-markdown/package.json; the root package-lock.json still records the workspace dependency as marked: ^15.0.12 and locks packages/x-markdown/node_modules/marked to 15.0.12. Please regenerate and commit the lockfile so clean installs reproduce the change.
  2. marked@18.0.7 declares Node >=20, while .github/workflows/markdown-benchmark.yml still runs Node 18. Published package metadata confirms 15.0.12 requires Node >=18, but 16.4.2, 17.0.1, and 18.0.7 all require Node >=20. This bump therefore silently drops Node 18 consumers unless the project makes and documents that support change.
  3. Please add a regression for the issue’s exact input ~123 foo bar (~123). I reproduced Marked 15 emitting a partial <del> for that string and Marked 18 leaving it entirely as text. The PR body currently shows an extra trailing ~, which is a different parse case.

Please either retain Node 18 compatibility with a targeted parsing fix, or make Node >=20 an explicit project-level decision and update CI/support metadata consistently, along with the lockfile and exact regression.

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

Labels

bug Something isn't working dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XMarkdown: update marked to fix parsing bugs wrt strike-through

3 participants