Compare commits
2 Commits
main
...
release/v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
847b16ebdb | ||
|
|
b8fb046dbb |
@ -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",
|
||||||
|
|||||||
@ -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 => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user