Skip to content

Commit

Permalink
Merge pull request #1964 from nextcloud/enh/update_mark_regexps
Browse files Browse the repository at this point in the history
Update mark input/paste rules to tiptap v2 regular expressions
  • Loading branch information
mejo- authored Nov 27, 2021
2 parents b984df8 + dc436d3 commit 74a721b
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 15 deletions.
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

0 comments on commit 74a721b

Please sign in to comment.