Skip to content

Commit

Permalink
refactor: non-root selector (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
LincZero committed Feb 16, 2023
1 parent c8ec57e commit 8be1826
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
11 changes: 5 additions & 6 deletions src/config/abReg.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/** @attention 修改正则要注意小括号的位置是否对应,不然还要去修改索引 */
export const ABReg = {
reg_header: /^\s*(-\s)*\[(.*)\]/, // /^\s*(>\s|-\s)*\[(.*?)\]/,需要小心会和callout语法冲突!!!
reg_header: /^(\s|>\s|-\s)*\[(.*)\]/,

reg_front: /^{\[.*?\]/,
reg_end: /^}./,
reg_list: /^\s*-\s(.*)/, //: /^\s*(>\s)*-\s(.*)$/
reg_list2: /^(\s*)-\s(.*)/,
reg_code: /^\s*(```|~~~)(.*)/, //: /^\s*(>\s|-\s)*(```|~~~)(.*)$/
reg_quote: /^\s*>\s(.*)/, // `- > ` 不匹配,要认为这种是列表
reg_heading: /^(\#+)\s(.*)/,
reg_list: /^((\s|>\s|-\s)*)-\s(.*)/, //: /^\s*(>\s)*-\s(.*)$/
reg_code: /^((\s|>\s|-\s)*)(```|~~~)(.*)/, //: /^\s*(>\s|-\s)*(```|~~~)(.*)$/
reg_quote: /^((\s|>\s|-\s)*)>\s(.*)/, // `- > ` 不匹配,要认为这种是列表
reg_heading: /^((\s|>\s|-\s)*)(\#+)\s(.*)/,
}
14 changes: 7 additions & 7 deletions src/manager/abMdSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ class ABMdSelector_code extends ABMdSelector{
if (i!=0) {
const header = list_text[i-1].match(ABReg.reg_header)
if (header){
code_flag = match_tmp[1]
prev_header = header[2]
code_flag = match_tmp[3]
prev_header = header[4]
prev_from = i-1
continue
}
Expand All @@ -222,7 +222,7 @@ class ABMdSelector_code extends ABMdSelector{
if (this.settings.select_code==ConfSelect.ifhead) continue
// 没有header 也选
prev_from = i
code_flag = match_tmp[1]
code_flag = match_tmp[3]
prev_header = ""
continue
}
Expand Down Expand Up @@ -331,8 +331,8 @@ class ABMdSelector_heading extends ABMdSelector{
if (i!=0) {
const header = list_text[i-1].match(ABReg.reg_header)
if (header){
prev_heading_level = match_tmp[1].length
prev_header = header[2]
prev_heading_level = match_tmp[3].length
prev_header = header[4]
prev_from = i-1
continue
}
Expand All @@ -341,14 +341,14 @@ class ABMdSelector_heading extends ABMdSelector{
if (this.settings.select_code==ConfSelect.ifhead) continue
// 没有header 也选
prev_from = i
prev_heading_level = match_tmp[1].length
prev_heading_level = match_tmp[3].length
prev_header = ""
continue
}
else { // 选择结束标志
const match_tmp = list_text[i].match(ABReg.reg_heading)
if (!match_tmp) continue
if (match_tmp[1].length >= prev_heading_level) continue // 【改】可选同级
if (match_tmp[3].length >= prev_heading_level) continue // 【改】可选同级
const from = this.map_line_ch[prev_from]
const to = this.map_line_ch[i]-1 // 不包括这一行
matchInfo.push({
Expand Down
2 changes: 1 addition & 1 deletion src/replace/baseProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const process_Xcode:ABProcessorSpecSimp = {
if (code_flag==""){ // 寻找开始标志
const match_tmp = list_content[i].match(ABReg.reg_code)
if(match_tmp){
code_flag = match_tmp[1]
code_flag = match_tmp[3]
line_start = i
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/replace/listProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ export class ListProcess{
let mul_mode:string = "" // 多行模式,para或list或title或空
for (let line of list_text) {
const match_heading = line.match(ABReg.reg_heading)
const match_list = line.match(ABReg.reg_list2)
const match_list = line.match(ABReg.reg_list)
if (match_heading){ // 1. 标题层级
removeTailBlank()
list_itemInfo.push({
content: match_heading[2],
content: match_heading[3],
level: match_heading[1].length-10
})
mul_mode = "title"
}
else if (match_list){ // 2. 列表层级
removeTailBlank()
list_itemInfo.push({
content: match_list[2],
content: match_list[3],
level: match_list[1].length+1//+10
})
mul_mode = "list"
Expand Down

0 comments on commit 8be1826

Please sign in to comment.