mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-01-21 00:13:58 +08:00
98cf0e425a
add another layer of matching by introducing support for second match group since javascript (at least in current browsers) still lacks lookbehind in regex so now supports /nomatch(markstart(text)markend)nomatch/ and still supports the /markstart(text)markend/ syntax all `nomatch` will be kept as is so kindof simulating lookbehinds
46 lines
803 B
JavaScript
46 lines
803 B
JavaScript
import { Mark } from 'tiptap'
|
|
import { toggleMark, markInputRule, markPasteRule } from 'tiptap-commands'
|
|
|
|
export default class Italic extends Mark {
|
|
|
|
get name() {
|
|
return 'italic'
|
|
}
|
|
|
|
get schema() {
|
|
return {
|
|
parseDOM: [
|
|
{ tag: 'i' },
|
|
{ tag: 'em' },
|
|
{ style: 'font-style=italic' },
|
|
],
|
|
toDOM: () => ['em', 0],
|
|
}
|
|
}
|
|
|
|
keys({ type }) {
|
|
return {
|
|
'Mod-i': toggleMark(type),
|
|
}
|
|
}
|
|
|
|
commands({ type }) {
|
|
return () => toggleMark(type)
|
|
}
|
|
|
|
inputRules({ type }) {
|
|
return [
|
|
markInputRule(/(?:^|[^_])(_([^_]+)_)$/, type),
|
|
markInputRule(/(?:^|[^*])(\*([^*]+)\*)$/, type),
|
|
]
|
|
}
|
|
|
|
pasteRules({ type }) {
|
|
return [
|
|
markPasteRule(/_([^_]+)_/g, type),
|
|
markPasteRule(/\*([^*]+)\*/g, type),
|
|
]
|
|
}
|
|
|
|
}
|