Skip to content

Commit 0708dee

Browse files
committed
perf: 更好的 html 初次解析策略
1 parent 456bf81 commit 0708dee

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/core/parser/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,30 @@ const INLINE_SYNTAXES: InlineSyntax[] = [
100100
contentIndex: 1,
101101
getAttrs: (m) => ({ content: m[1] }),
102102
},
103+
// sub/sup 上下标
104+
{
105+
type: "sub",
106+
pattern: /<sub>(.+?)<\/sub>/g,
107+
prefix: "<sub>",
108+
suffix: "</sub>",
109+
contentIndex: 1,
110+
},
111+
{
112+
type: "sup",
113+
pattern: /<sup>(.+?)<\/sup>/g,
114+
prefix: "<sup>",
115+
suffix: "</sup>",
116+
contentIndex: 1,
117+
},
118+
// 通用行内 HTML 元素(排除已有专用 mark 的 sub/sup)
119+
{
120+
type: "html_inline",
121+
pattern: /<([a-zA-Z][a-zA-Z0-9]*)(\s(?:[^>"']|"[^"]*"|'[^']*')*)?>(.+?)<\/\1>/g,
122+
prefix: (m: RegExpExecArray) => `<${m[1]}${m[2] || ""}>`,
123+
suffix: (m: RegExpExecArray) => `</${m[1]}>`,
124+
contentIndex: 3,
125+
getAttrs: (m: RegExpExecArray) => ({ tag: m[1].toLowerCase(), htmlAttrs: (m[2] || "").trim() }),
126+
},
103127
];
104128

105129
/** 块级语法模式 */

0 commit comments

Comments
 (0)