fix: auto add newlines for single-line mermaid code

This commit is contained in:
2026-01-23 21:47:30 +08:00
parent 715d6b81a9
commit 27a3afbf94

View File

@@ -315,6 +315,38 @@
// 如果代码看起来像是一行前100个字符中换行符很少尝试智能添加换行
let first100 = code.substring(0, 100);
let newlineCount = (first100.match(/\n/g) || []).length;
console.log('Newline count in first 100 chars:', newlineCount);
if (newlineCount < 2) {
console.log('Code appears to be on one line, attempting to add newlines...');
// 在 Mermaid 语法关键位置添加换行
code = code
.replace(/-->/g, '\n -->')
.replace(/\|([^|]+)\|/g, '|$1|\n ')
.replace(/\{([^}]+)\}/g, '{\n $1\n }')
.trim();
console.log('After adding newlines, first 200 chars:', code.substring(0, 200));
}
// 立即渲染这个图表 // 立即渲染这个图表
try { try {