Skip to content

Commit

Permalink
Merge pull request #3321 from nextcloud/fix/markdownit_fence_trailing…
Browse files Browse the repository at this point in the history
…_newline

Remove trailing newline from code blocks
  • Loading branch information
mejo- authored Nov 2, 2022
2 parents ded6b61 + fe6962b commit 5b086d5
Show file tree
Hide file tree
Showing 11 changed files with 27 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.

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

0 comments on commit 5b086d5

Please sign in to comment.