(null);
@@ -75,15 +95,11 @@ function MarkdownUnorderedList({ children }: { children?: ReactNode }) {
const depth = useContext(ListDepthContext);
return (
-
- 0 ? 'pl-4' : 'pl-0'
- }`}
- >
- {children}
-
-
+ {/* 用真正的列表标记(`list-disc`)而不是手写 `'- '` 文本:手写前缀既没有悬挂缩进
+ (换行后的第二行会顶回最左边),也不算列表语义(读屏读成普通文本)。 */}
+
);
}
@@ -98,14 +114,12 @@ function MarkdownOrderedList({
const depth = useContext(ListDepthContext);
return (
-
-
- {children}
-
-
+
+ {children}
+
);
}
@@ -145,7 +159,6 @@ function StreamingMarkdownParagraph({ children }: { children?: ReactNode }) {
}
function MarkdownListItem({ children }: { children?: ReactNode }) {
- const listKind = useContext(ListKindContext);
let paragraphIndex = 0;
const childrenWithParagraphContext = Children.map(
children,
@@ -168,7 +181,6 @@ function MarkdownListItem({ children }: { children?: ReactNode }) {
);
return (
- {listKind === 'unordered' ? '- ' : null}
{childrenWithParagraphContext}
);
@@ -179,22 +191,50 @@ const markdownComponents: Components = {
a: ({ children }) => children,
img: ({ alt }) => (alt?.trim() ? `图片:${alt}` : '图片已省略'),
h1: ({ children }) => (
- {children}
+
+ {children}
+
),
h2: ({ children }) => (
- {children}
+
+ {children}
+
),
h3: ({ children }) => (
- {children}
+
+ {children}
+
),
h4: ({ children }) => (
- {children}
+
+ {children}
+
),
h5: ({ children }) => (
- {children}
+
+ {children}
+
),
h6: ({ children }) => (
-
+
{children}
),
@@ -209,15 +249,18 @@ const markdownComponents: Components = {
),
pre: ({ children }) => (
- {children}
+
+ {children}
+
),
- code: ({ className, children, node: _node, ...props }) => {
- const isBlock =
- Boolean(className?.includes('language-')) ||
- String(children).includes('\n');
+ code: function MarkdownCode({ className, children, node: _node, ...props }) {
+ const isBlock = useContext(CodeBlockContext);
return isBlock ? (
-
+
{children}
) : (
@@ -231,7 +274,10 @@ const markdownComponents: Components = {
},
table: ({ children }) => (