diff options
author | Jonas Meurer <jonas@freesources.org> | 2021-11-25 21:04:10 +0300 |
---|---|---|
committer | Jonas Meurer <jonas@freesources.org> | 2021-12-02 14:41:10 +0300 |
commit | 1547c34a7e2e452b5f1b1d676bd0b18de2d3d40d (patch) | |
tree | 43ed210ad01ebb7e7f366f0afbc835d4a286a884 /src | |
parent | c458a706cbdc186456ae897d30e67f2ce4247add (diff) |
Update mark input/paste rules to tiptap v2 regular expressions
The most important change is that a mark is added only if you are at
the beginning of a block or there is a space before it.
This especially fixes accidently formatting parts of a string as italic
when it contains two underscores (often true in URLs or emoji names).
This change can be reverted when we migrated to tiptap v2, but it's
a low hanging fix for an annoying bug, and the tiptap v2 migration might
take a bit longer.
See Philipp Kuehns comment at https://discuss.prosemirror.net/t/4230/3.
Signed-off-by: Jonas Meurer <jonas@freesources.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/marks/index.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/marks/index.js b/src/marks/index.js index a3de1a486..0275bae57 100644 --- a/src/marks/index.js +++ b/src/marks/index.js @@ -23,6 +23,7 @@ import { Bold, Italic as TipTapItalic, Strike as TipTapStrike, Link as TipTapLink } from 'tiptap-extensions' import { Plugin } from 'tiptap' import { getMarkAttrs } from 'tiptap-utils' +import { markInputRule, markPasteRule } from 'tiptap-commands' import { domHref, parseHref } from './../helpers/links' import { markdownit } from './../EditorFactory' @@ -37,6 +38,22 @@ class Strong extends Bold { return 'strong' } + // TODO: remove once we upgraded to tiptap v2 + inputRules({ type }) { + return [ + markInputRule(/(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))$/, type), + markInputRule(/(?:^|\s)((?:__)((?:[^__]+))(?:__))$/, type), + ] + } + + // TODO: remove once we upgraded to tiptap v2 + pasteRules({ type }) { + return [ + markPasteRule(/(?:^|\s)((?:\*\*)((?:[^*]+))(?:\*\*))/g, type), + markPasteRule(/(?:^|\s)((?:__)((?:[^__]+))(?:__))/g, type), + ] + } + } class Italic extends TipTapItalic { @@ -45,6 +62,22 @@ class Italic extends TipTapItalic { return 'em' } + // TODO: remove once we upgraded to tiptap v2 + inputRules({ type }) { + return [ + markInputRule(/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))$/, type), + markInputRule(/(?:^|\s)((?:_)((?:[^_]+))(?:_))$/, type), + ] + } + + // TODO: remove once we upgraded to tiptap v2 + pasteRules({ type }) { + return [ + markPasteRule(/(?:^|\s)((?:\*)((?:[^*]+))(?:\*))/g, type), + markPasteRule(/(?:^|\s)((?:_)((?:[^_]+))(?:_))/g, type), + ] + } + } class Strike extends TipTapStrike { @@ -76,6 +109,20 @@ class Strike extends TipTapStrike { } } + // TODO: remove once we upgraded to tiptap v2 + inputRules({ type }) { + return [ + markInputRule(/(?:^|\s)((?:~~)((?:[^~]+))(?:~~))$/, type), + ] + } + + // TODO: remove once we upgraded to tiptap v2 + pasteRules({ type }) { + return [ + markPasteRule(/(?:^|\s)((?:~~)((?:[^~]+))(?:~~))/g, type), + ] + } + } class Link extends TipTapLink { |