refactor: Improve automark.ts code readability and remove unnecessary spaces
This commit is contained in:
@@ -89,7 +89,7 @@ export function risuFormater(dat:string){
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
const line = lines[i][1]
|
let line = lines[i][1]
|
||||||
let isNumbered = false
|
let isNumbered = false
|
||||||
let endMarked = false
|
let endMarked = false
|
||||||
if(excludesDat.includes(line[0]) || (line[1] === '.' && ['1','2','3','4','5','6','7','8','9'].includes(line[0]))){
|
if(excludesDat.includes(line[0]) || (line[1] === '.' && ['1','2','3','4','5','6','7','8','9'].includes(line[0]))){
|
||||||
@@ -107,6 +107,10 @@ export function risuFormater(dat:string){
|
|||||||
let depth = 0
|
let depth = 0
|
||||||
let depthChunk:string[] = ['']
|
let depthChunk:string[] = ['']
|
||||||
let depthChunkType:string[] = ['']
|
let depthChunkType:string[] = ['']
|
||||||
|
|
||||||
|
//spaces for detection
|
||||||
|
line = ' ' + line + ' '
|
||||||
|
|
||||||
for(let j=0;j<line.length;j++){
|
for(let j=0;j<line.length;j++){
|
||||||
switch(line[j]){
|
switch(line[j]){
|
||||||
case '"':
|
case '"':
|
||||||
@@ -129,7 +133,7 @@ export function risuFormater(dat:string){
|
|||||||
case '‘':
|
case '‘':
|
||||||
case '’':{
|
case '’':{
|
||||||
if(depthChunkType[depth] === "'"){
|
if(depthChunkType[depth] === "'"){
|
||||||
if(line[j-1] === '' || (line[j-2] === 'i' && line[j-1] === 'n')){
|
if(line[j-1] === ' ' || line[j+1] !== ' ' || (line[j-2] === 'i' && line[j-1] === 'n')){
|
||||||
//this is not a quote
|
//this is not a quote
|
||||||
depthChunk[depth] += line[j]
|
depthChunk[depth] += line[j]
|
||||||
}
|
}
|
||||||
@@ -165,6 +169,13 @@ export function risuFormater(dat:string){
|
|||||||
result += depthChunk.pop()
|
result += depthChunk.pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(result.startsWith(' ')){
|
||||||
|
result = result.substring(1)
|
||||||
|
}
|
||||||
|
if(result.endsWith(' ')){
|
||||||
|
result = result.substring(0,result.length-1)
|
||||||
|
}
|
||||||
|
|
||||||
result += '\n'
|
result += '\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user