From 38fc733b99ec27dca515d2dfb3d2d1acbe35607c Mon Sep 17 00:00:00 2001 From: shixy <18705837259@163.com> Date: Sat, 14 Mar 2026 16:13:02 +0800 Subject: [PATCH] fix(markdown-to-html): preserve inline code inside bold/emphasis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `extractText()` helper in `preprocessCjkEmphasis()` only handled `text` nodes and nodes with `children`. `inlineCode` AST nodes (which have a `value` but no `children`) fell through to the default empty- string return, silently dropping their content. For example `**算出 \`logits\`**` rendered as `算出 ` with the code span completely lost. Add an `inlineCode` branch that wraps the node value in backticks so the downstream `marked` pass can turn it into a proper `` element. Co-Authored-By: Claude Opus 4.6 --- .../vendor/baoyu-md/src/renderer.test.ts | 36 +++++++++++++++++++ .../scripts/vendor/baoyu-md/src/renderer.ts | 1 + 2 files changed, 37 insertions(+) create mode 100644 skills/baoyu-markdown-to-html/scripts/vendor/baoyu-md/src/renderer.test.ts diff --git a/skills/baoyu-markdown-to-html/scripts/vendor/baoyu-md/src/renderer.test.ts b/skills/baoyu-markdown-to-html/scripts/vendor/baoyu-md/src/renderer.test.ts new file mode 100644 index 0000000..57e7a08 --- /dev/null +++ b/skills/baoyu-markdown-to-html/scripts/vendor/baoyu-md/src/renderer.test.ts @@ -0,0 +1,36 @@ +import assert from "node:assert/strict"; +import test from "node:test"; + +import { initRenderer, renderMarkdown } from "./renderer.ts"; + +const render = (md: string) => { + const r = initRenderer(); + return renderMarkdown(md, r).html; +}; + +test("bold with inline code (no underscore)", () => { + const html = render("**算出 `logits`,算出 `loss`。**"); + assert.match(html, /]*>logits<\/code>/); + assert.match(html, /]*>loss<\/code>/); +}); + +test("bold with inline code (contains underscore)", () => { + const html = render("**变成 `input_ids`。**"); + assert.match(html, /]*>input_ids<\/code>/); +}); + +test("emphasis with inline code", () => { + const html = render("*查看 `hidden_states`*"); + assert.match(html, /]*>hidden_states<\/code>/); +}); + +test("plain inline code (regression)", () => { + const html = render("`lm_head`"); + assert.match(html, /]*>lm_head<\/code>/); +}); + +test("bold without code (regression)", () => { + const html = render("**纯粗体文本**"); + assert.match(html, /]*>纯粗体文本<\/strong>/); + assert.doesNotMatch(html, / { if (node.type === "text") return node.value; + if (node.type === "inlineCode") return `\`${node.value}\``; if (node.children) return node.children.map(extractText).join(""); return ""; };