tiptap/packages/tiptap-extensions/src/marks/Italic.js
Marius Tolzmann 98cf0e425a fix markInputRules for italics mark
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
2019-05-07 23:08:06 +02:00

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),
]
}
}