Skip to content

Commit

Permalink
feat: support reg with arg, support mdit with title #83
Browse files Browse the repository at this point in the history
  • Loading branch information
LincZero committed Dec 24, 2024
1 parent 0886784 commit 8470577
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/ABConverter/ABAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export function autoABAlias (header:string, selectorName:string, content:string)
for (const item of ABAlias_json) {
header = header.replace(item.regex, item.replacement)
}
for (const item of ABAlias_json_withSub) { // 特别组,被替换为带子串表示的结果
header = header.replace(item.regex, (match, ...groups) => {
return item.replacement.replace(/\$(\d+)/g, (_, number) => groups[number - 1]); // 根据捕获组替换
});
}
for (const item of ABAlias_json_end) { // 保证ABAlias_json内容被扩展后,该部分的替换规则仍处于最后
header = header.replace(item.regex, item.replacement)
}
Expand All @@ -91,12 +96,17 @@ interface ABAlias_json_item {
replacement: string
}

// 允许带参数的部分 (这部分的遍历会更耗时间。为了性能考虑,单独拿出来)
const ABAlias_json_withSub: ABAlias_json_item[] = [
{ regex: /\|::: 140lne\|(info|note|warn|warning|error)\s?(.*?)\|/, replacement: "|add([!$1] $2)|quote|" },
]

// mdit块
const ABAlias_json_mdit: ABAlias_json_item[] = [
{regex: "|::: 140lne|info|", replacement: "|add([!info])|quote|"},
{regex: "|::: 140lne|note|", replacement: "|add([!note])|quote|"},
{regex: /\|::: 140lne\|(warn|warning)\|/, replacement: "|add([!warning])|quote|"},
{regex: "|::: 140lne|error|", replacement: "|add([!error])|quote|"},
// {regex: "|::: 140lne|info|", replacement: "|add([!info])|quote|"},
// {regex: "|::: 140lne|note|", replacement: "|add([!note])|quote|"},
// {regex: /\|::: 140lne\|(warn|warning)\|/, replacement: "|add([!warning])|quote|"},
// {regex: "|::: 140lne|error|", replacement: "|add([!error])|quote|"},
{regex: /\|::: 140lne\|(2?tabs?|?)\|/, replacement: "|mditTabs|"},
{regex: "|::: 140lne|demo|", replacement: "|mditDemo|"},
{regex: "|::: 140lne|abDemo|", replacement: "|mditABDemo|"},
Expand Down

0 comments on commit 8470577

Please sign in to comment.