replace extensions

This commit is contained in:
Philipp Kühn
2020-09-08 23:44:45 +02:00
parent 678b6444d2
commit 26ecc20a50
16 changed files with 590 additions and 491 deletions

View File

@@ -1,5 +1,4 @@
import { Mark, CommandSpec, markInputRule, markPasteRule } from '@tiptap/core'
import { MarkSpec } from 'prosemirror-model'
import { Mark, markInputRule, markPasteRule } from '@tiptap/core'
import VerEx from 'verbal-expressions'
declare module '@tiptap/core/src/Editor' {
@@ -8,75 +7,62 @@ declare module '@tiptap/core/src/Editor' {
}
}
export default class Bold extends Mark {
name = 'bold'
schema(): MarkSpec {
return {
parseDOM: [
{
tag: 'strong',
},
{
tag: 'b',
getAttrs: node => (node as HTMLElement).style.fontWeight !== 'normal' && null,
},
{
style: 'font-weight',
getAttrs: value => /^(bold(er)?|[5-9]\d{2,})$/.test(value as string) && null,
},
],
toDOM: () => ['strong', 0],
}
}
commands(): CommandSpec {
return {
bold: next => () => {
this.editor.toggleMark(this.name)
next()
export default new Mark()
.name('bold')
.schema(() => ({
parseDOM: [
{
tag: 'strong',
},
}
}
{
tag: 'b',
getAttrs: node => (node as HTMLElement).style.fontWeight !== 'normal' && null,
},
{
style: 'font-weight',
getAttrs: value => /^(bold(er)?|[5-9]\d{2,})$/.test(value as string) && null,
},
],
toDOM: () => ['strong', 0],
}))
.commands(({ editor, name }) => ({
bold: next => () => {
editor.toggleMark(name)
next()
},
}))
.keys(({ editor }) => ({
'Mod-b': () => editor.bold()
}))
// .inputRules(({ type }) => {
// return ['**', '__'].map(character => {
// const regex = VerEx()
// .add('(?:^|\\s)')
// .beginCapture()
// .find(character)
// .beginCapture()
// .somethingBut(character)
// .endCapture()
// .find(character)
// .endCapture()
// .endOfLine()
keys() {
return {
'Mod-b': () => this.editor.bold()
}
}
// return markInputRule(regex, type)
// })
// })
// .pasteRules(({ type }) => {
// return ['**', '__'].map(character => {
// const regex = VerEx()
// .add('(?:^|\\s)')
// .beginCapture()
// .find(character)
// .beginCapture()
// .somethingBut(character)
// .endCapture()
// .find(character)
// .endCapture()
inputRules() {
return ['**', '__'].map(character => {
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
.endOfLine()
return markInputRule(regex, this.type)
})
}
pasteRules() {
return ['**', '__'].map(character => {
const regex = VerEx()
.add('(?:^|\\s)')
.beginCapture()
.find(character)
.beginCapture()
.somethingBut(character)
.endCapture()
.find(character)
.endCapture()
return markPasteRule(regex, this.type)
})
}
}
// return markPasteRule(regex, type)
// })
// })
.create()