-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathCode.ts
More file actions
44 lines (37 loc) · 990 Bytes
/
Code.ts
File metadata and controls
44 lines (37 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { markInputRule, markPasteRule } from '@tiptap/core'
import TipTapCode from '@tiptap/extension-code'
/**
* Regular expressions to match inline code blocks enclosed in backticks.
* Reverts upstream PR https://github.com/ueberdosis/tiptap/pull/5916 which
* introduced isuee https://github.com/nextcloud/text/issues/5483.
*/
export const inputRegex = /(?<!`)`([^`]+)`(?!`)/
/**
* Matches inline code while pasting.
*/
export const pasteRegex = /(?<!`)`([^`]+)`(?!`)/g
const Code = TipTapCode.extend({
// List all enabled marks except 'code' and 'link' (issue #4900)
excludes: 'em strike strong underline',
addInputRules() {
return [
markInputRule({
find: inputRegex,
type: this.type,
}),
]
},
addPasteRules() {
return [
markPasteRule({
find: pasteRegex,
type: this.type,
}),
]
},
})
export default Code