@baishuyun/ai-design 2.1.6 → 2.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @baishuyun/ai-design
2
2
 
3
+ ## 2.1.7
4
+
5
+ ### Patch Changes
6
+
7
+ - 8cd43ba: MemoizedMarkdown renders GitHub Flavored Markdown (tables, strikethrough, task lists, autolinks) and turns inline `<br>` into line breaks; markdown tables in ai-office messages get readable column widths and scroll horizontally when wide.
8
+
3
9
  ## 2.1.6
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baishuyun/ai-design",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "AI 功能 UI 组件库 - 所有 AI 功能的 UI 表现唯一真相来源",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -58,6 +58,7 @@
58
58
  "react-markdown": "^10.1.0",
59
59
  "rehype-highlight": "^7.0.2",
60
60
  "remark-breaks": "^4.0.0",
61
+ "remark-gfm": "4.0.1",
61
62
  "tailwind-merge": "^3.4.0",
62
63
  "vaul": "^1.1.2",
63
64
  "zod": "^4.1.13",
@@ -8,6 +8,39 @@ import { CSSProperties, memo, useMemo } from 'react';
8
8
  import ReactMarkdown from 'react-markdown';
9
9
  import rehypeHighlight, { type Options as HighlightOptions } from 'rehype-highlight';
10
10
  import remarkBreaks from 'remark-breaks';
11
+ import remarkGfm from 'remark-gfm';
12
+
13
+ interface MdNode {
14
+ type: string;
15
+ value?: string;
16
+ children?: MdNode[];
17
+ }
18
+
19
+ /**
20
+ * 把行内 HTML 的 <br> 转为换行节点:表格单元格内无法换行,模型常写 <br>;
21
+ * 其余 HTML 仍不渲染(不引入 rehype-raw,避免注入)。
22
+ */
23
+ const remarkBreakTags = () => (tree: MdNode) => {
24
+ const walk = (node: MdNode) => {
25
+ node.children?.forEach((child, i) => {
26
+ if (child.type === 'html' && /^<br\s*\/?>$/i.test(child.value?.trim() ?? '')) {
27
+ node.children![i] = { type: 'break' };
28
+ } else {
29
+ walk(child);
30
+ }
31
+ });
32
+ };
33
+ walk(tree);
34
+ };
35
+
36
+ /** GFM(表格、删除线、任务列表、自动链接)与 <br> 换行;breaks 时额外把单个换行渲染为换行 */
37
+ const BASE_REMARK_PLUGINS = [remarkGfm, remarkBreakTags];
38
+ const BREAKS_REMARK_PLUGINS = [...BASE_REMARK_PLUGINS, remarkBreaks];
39
+
40
+ /** 表格排版:表头不换行;单元格最小宽度、顶部对齐,避免短列被长列挤成逐字竖排;超宽时横向滚动 */
41
+ const TABLE_CLS =
42
+ '[&_table]:block [&_table]:overflow-x-auto [&_th]:whitespace-nowrap [&_th]:text-left ' +
43
+ '[&_td]:min-w-[5em] [&_td]:align-top [&_th]:px-2 [&_td]:px-2 [&_th:first-child]:pl-0 [&_td:first-child]:pl-0';
11
44
 
12
45
  const highlightOptions = {
13
46
  languages: { javascript, typescript, css, json, xml },
@@ -22,7 +55,7 @@ const MemoizedMarkdownBlock = memo(({ content, breaks }: { content: string; brea
22
55
  return (
23
56
  <ReactMarkdown
24
57
  rehypePlugins={[[rehypeHighlight, highlightOptions]]}
25
- remarkPlugins={breaks ? [remarkBreaks] : undefined}
58
+ remarkPlugins={breaks ? BREAKS_REMARK_PLUGINS : BASE_REMARK_PLUGINS}
26
59
  >
27
60
  {content}
28
61
  </ReactMarkdown>
@@ -42,7 +75,7 @@ const Prose = memo(function Prose({
42
75
  const blocks = useMemo(() => parseMarkdownIntoBlocks(content), [content]);
43
76
 
44
77
  return (
45
- <article className="prose" style={style}>
78
+ <article className={`prose ${TABLE_CLS}`} style={style}>
46
79
  {blocks.map((block, index) => (
47
80
  <MemoizedMarkdownBlock breaks={breaks} content={block} key={`${id}-block_${index}`} />
48
81
  ))}