Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove trailing newline from code blocks
Markdown-it serialized code blocks to `<pre><code>...\n</pre></code>`,
which leads to trailing newlines in the code blocks as rendered by
 Tiptap.

Let the Tiptap CodeBlock node remove the trailing newline in parseHTML
in order to avoid this.

There's another issue with trailing newlines that got added to code
blocks on purpose being removed by prosemirror-markdown, but that's not
affected by this change.

Fixes: #2344

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- authored and juliusknorr committed Nov 24, 2022
commit 0c7214a2ccec3d53ff481bd23278ab38f42856f9
12 changes: 12 additions & 0 deletions src/nodes/CodeBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ 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 (Github issue #2344)
getContent: (node, schema) => {
return schema.nodes.codeBlock.create(null, [schema.text(node.textContent.replace(/\n$/, ''))])
},
},
]
},

toMarkdown(state, node, parent, index) {
// prosemirror-markdown uses `params` instead of `language` attribute
Expand Down