diff --git a/src/components/MainEditor.vue b/src/components/MainEditor.vue
index d964d01..e8b35d1 100644
--- a/src/components/MainEditor.vue
+++ b/src/components/MainEditor.vue
@@ -221,14 +221,35 @@ const sanitize = (html) => {
// PlantUML 渲染核心逻辑
html = html.replace(/@startuml([\s\S]*?)@enduml/g, (_, umlCode) => {
+ // 参数 umlCode 不包含 @startuml 和 @enduml
+ const sourceCode = `@startuml${umlCode}@enduml`;
const lines = umlCode.split('\n');
- // 去除换行作用的首尾
- if (lines[0] == '
') {
- lines.shift();
+ if (lines.length == 0) {
+ return sourceCode;
}
- if (/
]*>/i.test(lines[lines.length - 1])) {
- lines.pop();
+ // 如果 @startuml 后接的不是
或者
的标签(前面有空行的情况) + // 如果都不是,则说明尾行不以 @enduml 开头,不作解析 + if (lastLine.length > 0) { + // 既不是换行符也不是
标签,不作解析 + if (!/
]*>$/i.test(lastLine)) { + return sourceCode; + } + // 存在一种情况,@enduml 前面带 > 符号,即 >@enduml。这种情况: + // 尾行是
标签,上一行是
,同样不作解析 + if (lines.length >= 2 && /]*>$/i.test(lines[lines.length - 2])) { + return sourceCode; + } + } + // 去除换行作用的首行(首行是在 @startuml 后的换行符) + lines.shift(); + // 去除换行作用的尾行(尾行是在 @enduml 前面的换行符) + lines.pop(); const removeLineBreak = /(.*?)(?=
|<\/p>)/i; const extractedLines = lines.map(line => {