Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/components/BilingualMarkdownRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ const BilingualMarkdownRenderer = forwardRef<BilingualMarkdownRendererHandle, Bi
'mt-1 pl-3 border-l-2 border-blue-400 dark:border-blue-500 text-gray-600 dark:text-text-tertiary text-sm leading-relaxed';

if (segments[i].hasInlineCode) {
const codeRegex = /<code>([\s\S]*?)<\/code>/g;
// 修改正则以支持带属性的 code 标签(如 <code class="...">)
const codeRegex = /<code(?:\s+[^>]*)?>([\s\S]*?)<\/code>/g;
let lastIndex = 0;
let match: RegExpExecArray | null;
while ((match = codeRegex.exec(translatedTexts[i])) !== null) {
Expand Down
12 changes: 10 additions & 2 deletions src/components/MarkdownRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,9 @@ const MarkdownRenderer: React.FC<MarkdownRendererProps> = memo(({
<del className="line-through text-gray-500 dark:text-text-tertiary">{children}</del>
),
code: ({ className, children, ...props }) => {
const isInline = !className;
// 检查 props 中是否有 'data-code-block' 标记(由 pre 组件添加)
const isCodeBlock = 'data-code-block' in props || !!className;
const isInline = !isCodeBlock;
const match = /language-(\w+)/.exec(className || '');
const language = match ? match[1] : '';

Expand All @@ -874,7 +876,13 @@ const MarkdownRenderer: React.FC<MarkdownRendererProps> = memo(({
</CodeBlock>
);
},
pre: ({ children }) => <>{children}</>,
pre: ({ children }) => {
// 给 code 子元素添加标记,表明它是代码块而不是行内代码
if (React.isValidElement(children) && children.type === 'code') {
return <>{React.cloneElement(children as React.ReactElement<any>, { 'data-code-block': true })}</>;
}
return <>{children}</>;
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
blockquote: ({ children }) => (
<blockquote className="border-l-4 border-black/[0.06] dark:border-white/[0.04] pl-4 py-1 my-2 text-gray-700 dark:text-text-tertiary italic bg-light-bg dark:bg-panel-dark/50 rounded-r">
{children}
Expand Down
11 changes: 11 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@

/* ========== Markdown Prose Component Styles ========== */
@layer components {
.prose pre {
overflow-x: auto;
white-space: pre;
word-wrap: normal;
word-break: normal;
}

.prose pre code {
display: block;
padding: 1rem;
Expand All @@ -199,6 +206,10 @@
line-height: 1.5rem;
tab-size: 2;
-moz-tab-size: 2;
white-space: pre;
word-wrap: normal;
word-break: normal;
overflow-x: auto;
}

.prose :not(pre) > code {
Expand Down
Loading