فهرست منبع

fix(note): 修复注释内嵌套模版内容不显示

模版参数解析时只取文本节点且后一个覆盖前一个,注释里的
{{sent}} 等嵌套模版被丢弃,气泡内容变成残缺文本。

- MdRender: 文本节点改为拼接;参数含嵌套模版时不下发该参数,
  内容以已渲染的 children 形式传给前端。
- Note.tsx: note ?? children 改为 note ? note : children,
  空串也能回落到 children。

html / markdown 格式下嵌套模版仍会丢外层结构,已留 TODO。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BbA1nkFVxFQnqF1Yb6TVki
visuddhinanda 1 هفته پیش
والد
کامیت
583159ad06
2فایلهای تغییر یافته به همراه23 افزوده شده و 4 حذف شده
  1. 15 2
      api-v13/app/Http/Api/MdRender.php
  2. 8 2
      dashboard-v6/src/components/template/Note.tsx

+ 15 - 2
api-v13/app/Http/Api/MdRender.php

@@ -287,12 +287,25 @@ class MdRender
                         }
                     }
                     if (empty($paramName)) {
+                        /**
+                         * 位置参数。多个文本节点要拼接,不能互相覆盖。
+                         * 如果参数里含有嵌套模版(元素节点),纯文本是残缺的,
+                         * 此时不设置该参数,交给渲染结果的子节点(children)显示。
+                         * TODO: html / markdown 格式下嵌套模版仍会丢失外层模版结构,
+                         * 因为 dfn 是按文档顺序遍历的,外层先于内层渲染。
+                         */
+                        $paramText = '';
+                        $hasNestedTpl = false;
                         foreach ($child->childNodes as $param_child) {
-                            // code...
                             if ($param_child->nodeType === 3) {
-                                $props["{$param_id}"] = $param_child->nodeValue;
+                                $paramText .= $param_child->nodeValue;
+                            } elseif ($param_child->nodeType === 1) {
+                                $hasNestedTpl = true;
                             }
                         }
+                        if (! $hasNestedTpl) {
+                            $props["{$param_id}"] = $paramText;
+                        }
                     }
                 }
                 $child = $child->nextSibling;

+ 8 - 2
dashboard-v6/src/components/template/Note.tsx

@@ -6,7 +6,11 @@ const { Link } = Typography;
 
 interface IWidgetNoteCtl {
   trigger?: string; //界面上显示的文字
-  note?: string; //note内容
+  /**
+   * note 内容。注释里含有嵌套模版时后端不下发这个字段,
+   * 内容以 children(已渲染的嵌套模版)的形式传进来。
+   */
+  note?: string;
   children?: React.ReactNode;
 }
 const NoteCtl = ({ trigger, note, children }: IWidgetNoteCtl) => {
@@ -14,7 +18,9 @@ const NoteCtl = ({ trigger, note, children }: IWidgetNoteCtl) => {
   return (
     <>
       <Popover
-        content={<div style={{ width: 500 }}>{note ?? children}</div>}
+        content={
+          <div style={{ width: 500 }}>{note ? note : children}</div>
+        }
         placement="bottom"
       >
         <Link>{show}</Link>