Skip to content

Commit 6505ac1

Browse files
os-billclaude
andauthored
fix(docs): pin the fumadocs-core peek omission that encodes markdown as entities (#281)
`fumadocs-core`'s `defaultStringifier` wraps every mdast-util-to-markdown serializer handler through `modHandler` and does not carry the handler's `peek` onto the wrapper. `containerPhrasing` uses `Handle.peek` to read the next sibling's first character without side effects; with it missing, the lookahead invokes that sibling's full handler and leaves `attentionEncodeSurroundingInfo` set from node N+1 for the loop to apply to node N. The result reached readers: 67 HTML numeric character references in `/llms-full.txt` and in each of the 79 per-page `/llms.mdx` bodies — files whose entire audience will not run them through an HTML parser — and 4 of 661 markdown link targets delivered malformed. Two of those also hid from the absolute-URL rewrite in `llms-full.txt/route.ts`, whose pattern needs a literal closing parenthesis, so they were served relative. Route A as decided on the card: pin the upstream one-liner through `pnpm.patchedDependencies` and fix the producer, so both consumers are repaired together and no consumer file is touched. Measured at base `50aacb9`: references 67 to 0 in both outputs, malformed targets 4 to 0 of 661, absolute site targets 560 to 562, page membership and order byte-identical. The patch applies on a wiped `--frozen-lockfile` install, and both failure modes were demonstrated: a perturbed anchor makes install exit 1, and removing the pin puts the defect back at exactly the baseline figures. The defect is present in 16.15.8 as well as the installed 16.8.12, so upgrading is not a fix. The pin is keyed to 16.8.12 and will not apply to any other version, which makes #239 a regeneration task. Fixes #197 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ChPQM8jamxLUfUAxwFpJ8S
1 parent d725081 commit 6505ac1

3 files changed

Lines changed: 103 additions & 9 deletions

File tree

‎package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
"better-sqlite3",
2727
"esbuild",
2828
"sharp"
29-
]
29+
],
30+
"patchedDependencies": {
31+
"fumadocs-core@16.8.12": "patches/fumadocs-core@16.8.12.patch"
32+
}
3033
}
3134
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Carry `Handle.peek` onto the wrapped serializer handlers in `defaultStringifier`.
2+
#
3+
# WHY THIS PIN EXISTS
4+
# -------------------
5+
# `page.data.getText('processed')` -- what `apps/docs/lib/source.ts` serves from
6+
# `/llms-full.txt` and from all 79 per-page `/llms.mdx` bodies -- emitted HTML
7+
# numeric character references into files that are not HTML, and two of them broke
8+
# the markdown link they sat in. Measured on `main` at 50aacb9, before this patch:
9+
# 67 numeric character references (58 encoding an asterisk, 5 a backtick, 4 a
10+
# closing parenthesis) and 4 of 661 link targets malformed, in each of the two
11+
# outputs. Two of those broken targets also made themselves invisible to the
12+
# absolute-URL rewrite in `app/llms-full.txt/route.ts`, whose `SITE_LINK` pattern
13+
# needs a literal closing parenthesis, so they were served relative in a file whose
14+
# whole purpose is to be read somewhere else.
15+
#
16+
# THE DEFECT
17+
# ----------
18+
# `defaultStringifier` (`dist/mdx-plugins/stringifier.js`) wraps every
19+
# `mdast-util-to-markdown` serializer handler through `modHandler`, and the wrapper
20+
# does not carry the handler's `peek` property. `containerPhrasing` uses
21+
# `Handle.peek` to read the NEXT sibling's first character cheaply and WITHOUT side
22+
# effects; with `peek` missing it invokes that sibling's full handler instead, and
23+
# the lookahead leaves `state.attentionEncodeSurroundingInfo` set from node N+1.
24+
# The loop then applies those flags to node N -- which is why an emphasis run's
25+
# opening marker is encoded while its closing partner is left alone.
26+
#
27+
# The fix is to copy `.peek` from the handler onto the wrapper. It is upstream's
28+
# bug, not this repo's, and this patch is byte-for-byte what upstream would ship.
29+
#
30+
# UPSTREAM STATE THIS TRACKS
31+
# --------------------------
32+
# Measured 2026-09-08 by unpacking the published tarballs: the defect is present in
33+
# 16.8.12 (installed here), 16.15.1, 16.15.2 and 16.15.8 (`latest` on that date).
34+
# The anchor line is byte-identical in all four. "Upgrade" is not a fix.
35+
#
36+
# Not reported upstream from this repository -- this session's GitHub access is
37+
# scoped to `objectstack-ai/*` and cannot open an issue on `fuma-nama/fumadocs`. A
38+
# ready-to-post upstream report is filed as a comment on
39+
# https://github.com/objectstack-ai/objectos/issues/197 and the maintainer routes
40+
# the filing.
41+
#
42+
# WHEN THIS FILE CAN BE DELETED
43+
# -----------------------------
44+
# When an installed `fumadocs-core` carries the fix itself: `grep peek
45+
# node_modules/fumadocs-core/dist/mdx-plugins/stringifier.js` finds something.
46+
# Delete this file, remove `pnpm.patchedDependencies` from the root `package.json`,
47+
# re-run `pnpm install`, and rebuild `apps/docs` -- the reference count must stay 0.
48+
#
49+
# ON A VERSION BUMP, THIS PATCH IS EXPECTED TO FAIL LOUDLY
50+
# --------------------------------------------------------
51+
# It is pinned to 16.8.12 by the key in `package.json`, so any other version simply
52+
# does not receive it and the defect returns silently -- which is why the counts
53+
# above are worth re-measuring on any bump. Beyond that, 16.15.x reformats an
54+
# `if` in the same function two hunks up, so a patch generated here does not
55+
# necessarily line up there. A Dependabot bump of this package therefore cannot be
56+
# merged on green: regenerate the patch against the new version in the same PR
57+
# (`pnpm patch fumadocs-core@<new>`), or drop it if upstream has landed the fix.
58+
#
59+
diff --git a/dist/mdx-plugins/stringifier.js b/dist/mdx-plugins/stringifier.js
60+
index cf19eea9336acb66414cf3e2e75f2b1aa2bfd138..636346eec49cd0760d84f874c2a352bd78a804fd 100644
61+
--- a/dist/mdx-plugins/stringifier.js
62+
+++ b/dist/mdx-plugins/stringifier.js
63+
@@ -66,7 +66,22 @@ function defaultStringifier(config = {}) {
64+
}
65+
const customToMarkdown = { handlers: { _custom(node, _, state, info) {
66+
const handlers = state.handlers;
67+
- for (const k in handlers) handlers[k] = modHandler(handlers[k], node.ctx);
68+
+ for (const k in handlers) {
69+
+ const handler = handlers[k];
70+
+ const wrapped = modHandler(handler, node.ctx);
71+
+
72+
+ // `Handle.peek` is how `mdast-util-to-markdown`'s `containerPhrasing`
73+
+ // reads the NEXT sibling's first character cheaply and without side
74+
+ // effects. A wrapper that does not carry it makes that lookahead invoke
75+
+ // the sibling's FULL handler instead, which leaves
76+
+ // `state.attentionEncodeSurroundingInfo` set from node N+1 and applies it
77+
+ // to node N — encoding markdown punctuation as numeric character
78+
+ // references in plain-text output. See the header of
79+
+ // `patches/fumadocs-core@16.8.12.patch` in this repository.
80+
+ if (handler.peek) wrapped.peek = handler.peek;
81+
+
82+
+ handlers[k] = wrapped;
83+
+ }
84+
return state.handle(node.root, void 0, state, info);
85+
} } };
86+
return function(root, ctx) {

‎pnpm-lock.yaml‎

Lines changed: 13 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)