Repository navigation
Conversation
1. Root cause: remark-parse parses <br> as html nodes, Milkdown's htmlSchema.toDOM renders them as literal text via textContent 2. Fix: add remarkTransformBrToHardbreak plugin that converts <br> html nodes to mdast break nodes, rendered as <br> elements 3. Impact: <br> tags now display as line breaks in preview; other markdown syntax unaffected Log: fix br tag display as literal text in markdown preview Influence: 1. Test <br> tag renders as line break in markdown preview 2. Test <br/> and <br /> variants also render as line breaks 3. Verify standard markdown syntax (code, tables, headings) unaffected fix: md预览中将br标签转换为hardbreak节点 1. 根因:remark-parse将<br>解析为html节点,Milkdown的htmlSchema.toDOM 通过textContent将其渲染为字面文本而非换行 2. 方案:添加remarkTransformBrToHardbreak插件,将<br>的html节点 转换为mdast break节点,由hardbreakSchema渲染为<br>元素 3. 影响:<br>标签在预览中显示为换行;其余markdown语法不受影响 Log: 修复markdown预览中br标签显示为字面文本的问题 Influence: 1. 测试<br>标签在markdown预览中渲染为换行 2. 测试<br/>和<br />变体也渲染为换行 3. 验证标准markdown语法(代码、表格、标题)不受影响 PMS: BUG-378211
|
Sorry @pengfeixx, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 1 hour and 53 minutes by commenting |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideThe preview Markdown pipeline now transforms standalone Flow diagram for converting br HTML to preview hardbreaksflowchart LR
A[Markdown source] --> B[remark-parse]
B --> C{html node matches br variant}
C -->|yes| D[remarkTransformBrToHardbreak]
D --> E[mdast break node]
E --> F[Milkdown hardbreakSchema]
F --> G[Rendered line break]
C -->|no| H[Existing Markdown pipeline]
H --> I[Existing preview rendering]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Root Cause Analysis
remark-parse parses inline HTML tags like
<br>astype: "html"mdast nodes. In Milkdown's read-only preview mode,htmlSchema.toDOMrenders html nodes viaspan.textContent, which outputs the raw tag as literal text instead of a line break. The preview pipeline had no transformation step to convert<br>html nodes into proper break nodes.Fix Approach
Added a self-implemented remark plugin
remarkTransformBrToHardbreakthat walks the mdast tree and replaces html nodes matching/^<br\s*\/?>$/iwithtype: "break"nodes. Break nodes are rendered by Milkdown'shardbreakSchemaas<br>HTML elements, producing the expected line break. No third-party remark plugins were introduced. The fix is applied in bothmain.js(source) andmain.bundle.js(committed build artifact).Change Safety Assessment
Code Safety
.use()in boot chain, does not alter existing plugin ordering or behaviorBusiness Impact Scope
Only affects
<br>tag rendering in Markdown preview: previously displayed as literal text<br>, now displays as a line break.[[...]]wiki links remain as literal text (out of scope). Standard Markdown syntax (headings, code blocks, tables, bold, links) rendering is unaffected.Verification Suggestion
<br>tags and verify they render as line breaks in preview<br/>,<br />,<BR>variants all render as line breaks<br>text inside code blocks is not converted根因分析
remark-parse 将内联 HTML 标签(如
<br>)解析为type: "html"的 mdast 节点。在 Milkdown 只读预览模式下,htmlSchema.toDOM通过span.textContent渲染 html 节点,将原始标签作为字面文本输出而非换行。预览管线中缺少将<br>html 节点转换为 break 节点的转换步骤。修复方案
新增自实现的 remark 插件
remarkTransformBrToHardbreak,遍历 mdast 树,将匹配/^<br\s*\/?>$/i的 html 节点替换为type: "break"节点。break 节点由 Milkdown 的hardbreakSchema渲染为<br>HTML 元素,实现换行效果。未引入任何第三方 remark 插件。修复同时应用于main.js(源码)和main.bundle.js(已提交的构建产物)。改动安全评估
代码安全评估
.use()注册在 boot 链中,不改变已有插件的注册顺序或行为业务影响范围
仅影响 Markdown 预览中
<br>标签的渲染行为:之前显示为字面文本<br>,修复后显示为换行。[[...]]wiki 链接保持字面文本显示(不在修复范围)。标准 Markdown 语法(标题、代码块、表格、加粗、链接等)渲染行为不受影响。验证建议
<br>标签的 Markdown 文件,确认预览中显示为换行<br/>、<br />、<BR>等变体均正确渲染为换行<br>文本不被转换Summary by Sourcery
Convert standalone
<br>HTML nodes into Markdown hard breaks so previews display line breaks instead of literal tags.Bug Fixes:
<br>HTML tags as line breaks in the Markdown read-only preview, including common casing and spacing variants.Build:
<br>rendering fix.