Compare commits

...

2 Commits

Author SHA1 Message Date
Frankie Huang
847b16ebdb release v2.0.0 2025-05-06 23:58:42 +08:00
Frankie Huang
b8fb046dbb fix: 修复 plantuml 语法解析误区 2025-05-06 23:53:16 +08:00
2 changed files with 27 additions and 6 deletions

View File

@ -1,7 +1,7 @@
{ {
"$schema": "https://schema.tauri.app/config/2", "$schema": "https://schema.tauri.app/config/2",
"productName": "markdown-editor", "productName": "markdown-editor",
"version": "1.2.0", "version": "2.0.0",
"identifier": "com.markdown-editor.app", "identifier": "com.markdown-editor.app",
"build": { "build": {
"beforeDevCommand": "npm run dev", "beforeDevCommand": "npm run dev",

View File

@ -221,14 +221,35 @@ const sanitize = (html) => {
// PlantUML // PlantUML
html = html.replace(/@startuml([\s\S]*?)@enduml/g, (_, umlCode) => { html = html.replace(/@startuml([\s\S]*?)@enduml/g, (_, umlCode) => {
// umlCode @startuml @enduml
const sourceCode = `@startuml${umlCode}@enduml`;
const lines = umlCode.split('\n'); const lines = umlCode.split('\n');
// if (lines.length == 0) {
if (lines[0] == '<br>') { return sourceCode;
}
// @startuml <br> </p>
if (lines[0] !== '<br>' && lines[0] !== '</p>') {
return sourceCode;
}
const lastLine = lines[lines.length - 1];
// @enduml \n
// <p data-line="7">
// @enduml
if (lastLine.length > 0) {
// <p data-line="7">
if (!/<p\s+[^>]*>$/i.test(lastLine)) {
return sourceCode;
}
// @enduml > >@enduml
// <p data-line="7"> <blockquote data-line="7">
if (lines.length >= 2 && /<blockquote\s+[^>]*>$/i.test(lines[lines.length - 2])) {
return sourceCode;
}
}
// @startuml
lines.shift(); lines.shift();
} // @enduml
if (/<p\s+[^>]*>/i.test(lines[lines.length - 1])) {
lines.pop(); lines.pop();
}
const removeLineBreak = /(.*?)(?=<br>|<\/p>)/i; const removeLineBreak = /(.*?)(?=<br>|<\/p>)/i;
const extractedLines = lines.map(line => { const extractedLines = lines.map(line => {