JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix:tui md格式渲染
openJiuwen-bot8a0a43f9b83a
diff --git a/jiuwenclaw/cli/src/ui/rendering/text.ts b/jiuwenclaw/cli/src/ui/rendering/text.tsindex 815649e546..e72e1c9b07 100644--- a/jiuwenclaw/cli/src/ui/rendering/text.ts+++ b/jiuwenclaw/cli/src/ui/rendering/text.ts@@ -56,9 +56,17 @@ export function renderMarkdownLines(paddingX = 0,paddingY = 0,): string[] {- const markdown = new Markdown(text || "", paddingX, paddingY, markdownTheme);+ const processedText = preprocessTaskList(text);+ const markdown = new Markdown(processedText, paddingX, paddingY, markdownTheme);const lines = markdown.render(width);- return lines.length > 0 ? lines : [emptyLine(width)];+ const filtered = filterCodeBlockBorders(lines);+ return filtered.length > 0 ? filtered : [emptyLine(width)];+}++function preprocessTaskList(text: string): string {+ return text+ .replace(/^[-*]\s+\[x\]\s+/gm, (match) => match.replace("[x]", "☑").replace("[X]", "☑"))+ .replace(/^[-*]\s+\[\s\]\s+/gm, (match) => match.replace("[ ]", "☐"));}export function renderStyledMarkdownLines(@@ -68,9 +76,27 @@ export function renderStyledMarkdownLines(paddingX = 0,paddingY = 0,): string[] {- const markdown = new Markdown(text || "", paddingX, paddingY, markdownTheme, style);+ const processedText = preprocessTaskList(text);+ const markdown = new Markdown(processedText, paddingX, paddingY, markdownTheme, style);const lines = markdown.render(width);- return lines.length > 0 ? lines : [emptyLine(width)];+ const filtered = filterCodeBlockBorders(lines);+ return filtered.length > 0 ? filtered : [emptyLine(width)];+}++function filterCodeBlockBorders(lines: string[]): string[] {+ const result: string[] = [];+ for (const line of lines) {+ const stripped = line.replace(/\x1b\[[0-9;]*m/g, "");+ const trimmed = stripped.trim();+ if (trimmed === "```") continue;+ const langMatch = trimmed.match(/^```(\w+)\s*$/);+ if (langMatch) {+ result.push(langMatch[1]);+ continue;+ }+ result.push(line);+ }+ return result;}export function renderIndentedBlock(diff --git a/jiuwenclaw/cli/src/ui/theme.ts b/jiuwenclaw/cli/src/ui/theme.tsindex 7b730bc490..9ac327f131 100644--- a/jiuwenclaw/cli/src/ui/theme.ts+++ b/jiuwenclaw/cli/src/ui/theme.ts@@ -255,18 +255,52 @@ export const editorTheme: EditorTheme = {};export const markdownTheme: MarkdownTheme = {- heading: (value: string) => chalk.bold.hex(getThemeDefinition().markdownHeading)(value),- link: (value: string) => chalk.hex(getAccentHex())(value),- linkUrl: (value: string) => chalk.hex(getThemeDefinition().textDim)(value),- code: (value: string) => chalk.hex(getThemeDefinition().markdownCode)(value),+ heading: (value: string) => {+ if (value.startsWith("# ")) {+ const text = value.slice(2);+ return chalk.bold(text);+ } else if (value.startsWith("## ")) {+ const text = value.slice(3);+ return chalk.bold(text);+ } else if (value.startsWith("### ")) {+ const text = value.slice(4);+ return chalk.hex(getThemeDefinition().textPrimary)(text);+ } else if (value.startsWith("#### ")) {+ const text = value.slice(5);+ return chalk.hex(getThemeDefinition().textPrimary)(text);+ } else if (value.startsWith("##### ")) {+ const text = value.slice(6);+ return chalk.hex(getThemeDefinition().textPrimary)(text);+ } else if (value.startsWith("###### ")) {+ const text = value.slice(7);+ return chalk.hex(getThemeDefinition().textPrimary)(text);+ }+ return chalk.bold(value);+ },+ link: (value: string) => chalk.underline.hex(getAccentHex())(value),+ linkUrl: (value: string) => chalk.dim.hex(getThemeDefinition().textDim)(value),+ code: (value: string) => chalk.bgHex("333333").hex("#98c379")(value),codeBlock: (value: string) => chalk.hex(getThemeDefinition().markdownCodeBlock)(value),- codeBlockBorder: (value: string) => chalk.hex(getThemeDefinition().borderPanel)(value),- quote: (value: string) => chalk.italic.hex(getThemeDefinition().textDim)(value),- quoteBorder: (value: string) => chalk.hex(getThemeDefinition().borderPanel)(value),- hr: (value: string) => chalk.hex(getThemeDefinition().borderPanel)(value),- listBullet: (value: string) => chalk.hex(getAccentHex())(value),+ codeBlockBorder: (value: string) => chalk.dim.hex(getThemeDefinition().borderPanel)(value),+ quote: (value: string) => chalk.italic.hex("#abb2bf")(value),+ quoteBorder: (value: string) => chalk.hex("#61afef")(value),+ hr: (value: string) => chalk.hex(getAccentHex())(value),+ listBullet: (value: string) => {+ if (value === "- " || value.startsWith("- ")) {+ return chalk.hex(getAccentHex())("○ ");+ }+ return chalk.hex(getAccentHex())(value);+ },bold: (value: string) => chalk.bold(value),italic: (value: string) => chalk.italic(value),strikethrough: (value: string) => chalk.strikethrough(value),underline: (value: string) => chalk.underline(value),+ highlightCode: (code: string, lang?: string): string[] => {+ const lines = code.split("\n");+ const def = getThemeDefinition();+ return lines.map((line) => {+ return chalk.hex(def.markdownCodeBlock)(line);+ });+ },+ codeBlockIndent: " ",};