Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
  • Loading branch information
mejo- committed Dec 2, 2021
commit 1547c34a7e2e452b5f1b1d676bd0b18de2d3d40d
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions src/marks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down