-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathRichText.js
More file actions
158 lines (153 loc) · 4.34 KB
/
RichText.js
File metadata and controls
158 lines (153 loc) · 4.34 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/**
* SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { t } from '@nextcloud/l10n'
import { Extension } from '@tiptap/core'
/* eslint-disable import/no-named-as-default */
import Blockquote from '@tiptap/extension-blockquote'
import Document from '@tiptap/extension-document'
import HorizontalRule from '@tiptap/extension-horizontal-rule'
import { ListItem } from '@tiptap/extension-list'
import Placeholder from '@tiptap/extension-placeholder'
import Text from '@tiptap/extension-text'
/* eslint-enable import/no-named-as-default */
import { CharacterCount, Dropcursor, Gapcursor } from '@tiptap/extensions'
import { common, createLowlight } from 'lowlight'
import MentionSuggestion from '../components/Suggestion/Mention/suggestions.js'
import Heading from '../nodes/Heading.js'
import EmojiSuggestion from './../components/Suggestion/Emoji/suggestions.js'
import LinkBubble from './../extensions/LinkBubble.js'
import LinkPicker from './../extensions/LinkPicker.js'
import Markdown from './../extensions/Markdown.js'
import Mention from './../extensions/Mention.js'
import Search from './../extensions/Search.ts'
import TextDirection from './../extensions/TextDirection.ts'
import Typography from './../extensions/Typography.ts'
import { Code, Italic, Link, Strike, Strong, Underline } from './../marks/index.js'
import BulletList from './../nodes/BulletList.js'
import Callouts from './../nodes/Callouts.js'
import CodeBlock from './../nodes/CodeBlock.js'
import Details from './../nodes/Details.js'
import EditableTable from './../nodes/EditableTable.js'
import FrontMatter from './../nodes/FrontMatter.js'
import HardBreak from './../nodes/HardBreak.js'
import Image from './../nodes/Image.js'
import ImageInline from './../nodes/ImageInline.js'
import { MathBlock, MathInline } from './../nodes/Mathematics.js'
import OrderedList from './../nodes/OrderedList.js'
import Paragraph from './../nodes/Paragraph.js'
import Preview from './../nodes/Preview.js'
import Table from './../nodes/Table.js'
import TaskItem from './../nodes/TaskItem.js'
import TaskList from './../nodes/TaskList.js'
import TrailingNode from './../nodes/TrailingNode.js'
import Emoji from './Emoji.js'
import KeepSyntax from './KeepSyntax.js'
import Keymap from './Keymap.js'
const lowlight = createLowlight(common)
lowlight.registerAlias('plaintext', 'mermaid')
export default Extension.create({
name: 'RichText',
addOptions() {
return {
connection: null,
editing: true,
extensions: [],
relativePath: null,
isEmbedded: false,
mentionSearch: undefined,
}
},
addExtensions() {
const defaultExtensions = [
Markdown,
Document,
Text,
Paragraph,
HardBreak,
Heading,
Strong,
Italic,
Strike,
Blockquote,
CharacterCount,
Code,
CodeBlock.configure({
lowlight,
defaultLanguage: 'plaintext',
}),
Details,
BulletList,
HorizontalRule,
OrderedList,
ListItem,
this.options.editing ? EditableTable : Table,
TaskList,
TaskItem,
Callouts,
Preview.configure({
isEmbedded: this.options.isEmbedded,
}),
Underline,
Image,
ImageInline,
Dropcursor.configure({
color: 'var(--color-primary-element)',
width: 2,
}),
Gapcursor,
KeepSyntax,
Keymap,
FrontMatter,
Mention.configure({
suggestion: MentionSuggestion({
connection: this.options.connection,
options: {
mentionSearch: this.options.mentionSearch,
},
}),
}),
Search,
Emoji.configure({
suggestion: EmojiSuggestion(),
}),
LinkPicker,
Link.configure({
openOnClick: true,
shouldAutoLink: (href) => /^https?:\/\//.test(href),
relativePath: this.options.relativePath,
}),
LinkBubble,
this.options.editing
? Placeholder.configure({
placeholder: t('text', "Start writing or type '/' to add…"),
})
: null,
TrailingNode,
TextDirection.configure({
types: [
'blockquote',
'callout',
'detailsSummary',
'heading',
'listItem',
'paragraph',
'tableCell',
'tableHeader',
'taskItem',
],
}),
Typography,
MathInline,
MathBlock,
]
const additionalExtensionNames = this.options.extensions.map((e) => e.name)
return [
...defaultExtensions.filter(
(e) => e && !additionalExtensionNames.includes(e.name),
),
...this.options.extensions,
]
},
})