mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-02 12:39:50 +08:00
- 为 AI markdown 渲染补充 fenced code block 预处理 - 修正 opening/closing fence 缺少换行时的代码块解析失败 - 补充回归测试并更新 issue backlog 记录 Fixes #369
14 lines
667 B
TypeScript
14 lines
667 B
TypeScript
export const normalizeAiMarkdown = (content: string): string => {
|
|
let text = String(content || '').replace(/\r\n/g, '\n');
|
|
const knownFenceLanguages = [
|
|
'sql', 'mermaid', 'json', 'javascript', 'typescript', 'ts', 'js', 'tsx', 'jsx',
|
|
'bash', 'sh', 'shell', 'python', 'py', 'go', 'java', 'yaml', 'yml', 'html', 'css',
|
|
'xml', 'markdown', 'md', 'text', 'plaintext', 'vue', 'php', 'ruby', 'rust', 'toml',
|
|
'ini', 'diff',
|
|
];
|
|
const fencePattern = new RegExp(`(^|\\n)\`\`\`(${knownFenceLanguages.join('|')})([^\\n])`, 'gi');
|
|
text = text.replace(fencePattern, '$1```$2\n$3');
|
|
text = text.replace(/([^\n])```(?=\n|$)/g, '$1\n```');
|
|
return text;
|
|
};
|