Files
tiptap/packages/tiptap-commands/src/commands/markInputRule.js
Erick Wilder 54550b2386 feat(package.json): Add lint yarn script + make it a precondition to build all packages.
fmt(tiptap-commands): Fix all ESLint violations with `--fix`

fmt(tiptap-commands): Ignore some ESLint rules on code copied from prosemirror.

fmt(tiptap): Apply ESLint autofix to `tiptap` package sources.

fmt(tiptap-extensions): Fix ESlint violations from `marks`

refactor(tiptap-extensions): Fix ESLint violations for `plugins/Suggestions.js`.

Some of the violations required a bit of restructuring of the code/logic

fmt(tiptap-utils): Fix ESLint violations.

feat(package.json): Add yarn script to lint source code before compiling the examples.
2018-10-13 17:20:03 +02:00

27 lines
790 B
JavaScript

import { InputRule } from 'prosemirror-inputrules'
export default function (regexp, markType, getAttrs) {
return new InputRule(regexp, (state, match, start, end) => {
const attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs
const { tr } = state
let markEnd = end
if (match[1]) {
const startSpaces = match[0].search(/\S/)
const textStart = start + match[0].indexOf(match[1])
const textEnd = textStart + match[1].length
if (textEnd < end) {
tr.delete(textEnd, end)
}
if (textStart > start) {
tr.delete(start + startSpaces, textStart)
}
markEnd = start + startSpaces + match[1].length
}
tr.addMark(start, markEnd, markType.create(attrs))
tr.removeStoredMark(markType) // Do not continue with mark.
return tr
})
}