refactoring

This commit is contained in:
Philipp Kühn 2020-04-12 23:42:51 +02:00
parent 83ce601621
commit 56beb707ab
3 changed files with 34 additions and 127 deletions

View File

@ -48,11 +48,10 @@ export default class Bold extends Mark {
}
inputRules() {
return ['**', '__'].map(character => ([
// match start of line
markInputRule(
return ['**', '__'].map(character => {
return markInputRule(
VerEx()
.startOfLine()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
@ -62,31 +61,15 @@ export default class Bold extends Mark {
.endCapture()
.endOfLine(),
this.type,
),
// match before whitespace
markInputRule(
VerEx()
.whitespace()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine(),
this.type,
),
]))
.flat(1)
)
})
}
pasteRules() {
return ['**', '__'].map(character => ([
// match start of line
markPasteRule(
return ['**', '__'].map(character => {
return markPasteRule(
VerEx()
.startOfLine()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
@ -95,22 +78,8 @@ export default class Bold extends Mark {
.find(character)
.endCapture(),
this.type,
),
// match before whitespace
markPasteRule(
VerEx()
.whitespace()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture(),
this.type,
),
]))
.flat(1)
)
})
}
}

View File

@ -39,69 +39,38 @@ export default class Code extends Mark {
}
inputRules() {
return ['`'].map(character => ([
// match start of line
return [
markInputRule(
VerEx()
.startOfLine()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.find('`')
.beginCapture()
.somethingBut(character)
.somethingBut('`')
.endCapture()
.find(character)
.find('`')
.endCapture()
.endOfLine(),
this.type,
),
// match before whitespace
markInputRule(
VerEx()
.whitespace()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine(),
this.type,
),
]))
.flat(1)
)
]
}
pasteRules() {
return ['`'].map(character => ([
// match start of line
return [
markPasteRule(
VerEx()
.startOfLine()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.find('`')
.beginCapture()
.somethingBut(character)
.somethingBut('`')
.endCapture()
.find(character)
.find('`')
.endCapture(),
this.type,
),
// match before whitespace
markPasteRule(
VerEx()
.whitespace()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture(),
this.type,
),
]))
.flat(1)
)
]
}
}

View File

@ -40,11 +40,10 @@ export default class Italic extends Mark {
}
inputRules() {
return ['*', '_'].map(character => ([
// match start of line
markInputRule(
return ['*', '_'].map(character => {
return markInputRule(
VerEx()
.startOfLine()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
@ -54,31 +53,15 @@ export default class Italic extends Mark {
.endCapture()
.endOfLine(),
this.type,
),
// match before whitespace
markInputRule(
VerEx()
.whitespace()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine(),
this.type,
),
]))
.flat(1)
)
})
}
pasteRules() {
return ['*', '_'].map(character => ([
// match start of line
markPasteRule(
return ['*', '_'].map(character => {
return markPasteRule(
VerEx()
.startOfLine()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
@ -87,22 +70,8 @@ export default class Italic extends Mark {
.find(character)
.endCapture(),
this.type,
),
// match before whitespace
markPasteRule(
VerEx()
.whitespace()
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture(),
this.type,
),
]))
.flat(1)
)
})
}
}