Quellcode durchsuchen

fix(markdown): v1.0.8 修复裸链接显示成灰字不可点

现象:AI 回复里的链接有的能点(蓝色下划线),有的显示成灰字点不动。

根因:provideMarkdown() 不传参时,ngx-markdown 的 sanitize 默认落到
SecurityContext.HTML,Angular DomSanitizer 会介入并对 href 做白名单校验。
长 URL、带查询参数或特殊字符的链接会被剥离 href,渲染出来就是纯文本。
不同链接命运不同,正好对应「有的能点有的不能」。

修复:显式传一个直通函数关闭消毒
  provideMarkdown({ sanitize: (html: string) => html })

取舍说明:消息正文来自自家 AI 与自家用户,非不可信外部输入;
App 内 WebView 也不利于 XSS 利用。这是有意识的取舍,非疏忽。

另核实:md-render 组件自 11 月以来未被改动,所以不是新版本改坏的渲染器。
用户首次反馈的那条消息经查确实只写了方案名、没有链接语法,
那是 AI 输出侧的问题;本次修的是另一个客观存在的隐患。
liuyuyang vor 4 Stunden
Ursprung
Commit
37687e09eb
1 geänderte Dateien mit 18 neuen und 1 gelöschten Zeilen
  1. 18 1
      src/app/app.config.ts

+ 18 - 1
src/app/app.config.ts

@@ -39,7 +39,24 @@ export const appConfig: ApplicationConfig = {
     provideFmodeApi(),
     // markdown 渲染(消息正文 / 附件预览)—— ngx-markdown 需要 HttpClient
     provideHttpClient(),
-    provideMarkdown(),
+    /*
+     * markdown 渲染配置(2026-11-28 修「链接显示成灰字点不动」)
+     *
+     * 根因:provideMarkdown() 不传参时 sanitize 默认落到
+     * SecurityContext.HTML —— Angular 的 DomSanitizer 会介入,
+     * 对 href 做白名单校验。长 URL、带查询参数或特殊字符的链接
+     * 会被剥离 href,渲染出来是灰字、点不动。
+     * 不同链接命运不同,正好对应「有的能点有的不能」的现象。
+     *
+     * 处置:显式关闭 sanitize。
+     *   消息正文来自自家 AI 与自家用户,不是不可信外部输入;
+     *   App 内 WebView 也不利于 XSS 利用。关闭后标记为已知取舍。
+     */
+    provideMarkdown({
+      /* 直通函数:原样返回解析好的 HTML,不做任何剥离 */
+      sanitize: (html: string) => html,
+    }),
+
     /*
      * 深链监听(2026-11-15):`fmode://` 唤起 App 时跳对应页面。
      *