rolldown icon indicating copy to clipboard operation
rolldown copied to clipboard

doc: backslashes in code blocks rendered as URL-encoded sequences on docs site

Open hyfdev-agent opened this issue 8 months ago • 2 comments

Description

Backslashes inside fenced code blocks in packages/rolldown/src/options/docs/*.md files are rendered as URL-encoded sequences (%5C) on rolldown.rs.

Example: rolldown.rs/reference/InputOptions.external

The regex example:

// Source (.md file)
external: /^[^./](?!:\\)/,

// Rendered on site
external: /^[^./](?!:%5C%5C)/,

%5B = [, %5C = \, %5D = ] — the characters are being URL-encoded instead of rendered literally.

Originally reported by @bddjr in https://github.com/rolldown/rolldown/pull/8780#issuecomment-2983429547.

Root Cause

The docs flow is:

  1. external.md contains correct markdown with fenced code blocks
  2. {@include ./docs/external.md} injects the content into a JSDoc comment in input-options.ts
  3. TypeDoc's comment parser processes the injected content as JSDoc markdown, including the contents of fenced code blocks — backslashes get treated as escape sequences
  4. extract-options-plugin.ts extracts the (already mangled) content
  5. VitePress renders the mangled output

The issue is that TypeDoc's {@include} does not preserve code block boundaries when processing escape sequences in its block lexer (see blockLexer.ts — it handles \{, \}, \@, \/, \` as escape pairs).

Why codeSplitting docs are not affected: The regex [\\/] in output-code-splitting-example.md survives because \/ is a recognized escape pair that resolves to / — which happens to be correct. But \\ followed by ] does not match any escape pair, so it goes through a different path and gets URL-encoded.

Possible Fixes

  1. Best: bypass TypeDoc for doc content — extract-options-plugin.ts already knows which property maps to which docs/*.md file. Instead of extracting the content from TypeDoc's processed output, read the original .md file directly and splice it in. This avoids the TypeDoc parser entirely.

  2. Upstream: fix TypeDoc — {@include} should skip escape processing inside fenced code blocks. Correct but depends on TypeDoc team.

  3. Workaround: post-process URL decoding — Add section.replace(/%5B/g, "[").replace(/%5C/g, "\\").replace(/%5D/g, "]") in extract-options-plugin.ts. Quick but fragile.

Affected Pages

Any docs/*.md file with backslashes in code blocks that is {@include}'d into a JSDoc comment. Currently:

  • external.md — regex with \\

hyfdev-agent avatar Mar 19 '26 08:03 hyfdev-agent

经过 #8786 修改后,现在的正则表达式是这样:

// before render
external: /^[^./](?!:[/\\])/,

// after render
external: /^[^./](?!:%5B/%5C%5C%5D)/,

所以可能是 [^./](?!:[/\\]) 被程序识别成markdown链接,导致渲染结果错误。

bddjr avatar Mar 19 '26 08:03 bddjr

Upstream fix landed in [email protected] (typedoc2md/typedoc-plugin-markdown#863)

kyu-rong avatar Jun 04 '26 11:06 kyu-rong