fix: auto add newlines for single-line mermaid code
This commit is contained in:
32
footer.php
32
footer.php
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user