-
Notifications
You must be signed in to change notification settings - Fork 120
Expand file tree
/
Copy pathCodeBlock.js
More file actions
31 lines (26 loc) · 825 Bytes
/
CodeBlock.js
File metadata and controls
31 lines (26 loc) · 825 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
import TiptapCodeBlock from '@tiptap/extension-code-block'
import { defaultMarkdownSerializer } from 'prosemirror-markdown'
const CodeBlock = TiptapCodeBlock.extend({
parseHTML() {
return [
{
tag: 'pre',
preserveWhitespace: 'full',
// Remove trailing newline from code blocks (#2344)
getContent: (node, schema) => {
const textContent = node.textContent.replace(/\n$/, '')
const inner = textContent
? [schema.text(textContent)]
: []
return schema.nodes.codeBlock.create(null, inner)
},
},
]
},
toMarkdown(state, node, parent, index) {
// prosemirror-markdown uses `params` instead of `language` attribute
node.attrs.params = node.attrs.language
return defaultMarkdownSerializer.nodes.code_block(state, node, parent, index)
},
})
export default CodeBlock