Skip to content

Commit

Permalink
Merge pull request #3780 from nextcloud/backport/3766/stable25
Browse files Browse the repository at this point in the history
[stable25] fix: empty code blocks
  • Loading branch information
max-nextcloud authored Feb 8, 2023
2 parents 0ba87db + 1991120 commit 3c443b2
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 17 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.

9 changes: 7 additions & 2 deletions src/nodes/CodeBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ 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)
// Remove trailing newline from code blocks (#2344)
getContent: (node, schema) => {
return schema.nodes.codeBlock.create(null, [schema.text(node.textContent.replace(/\n$/, ''))])
const textContent = node.textContent.replace(/\n$/, '')
const inner = textContent
? [schema.text(textContent)]
: []
return schema.nodes.codeBlock.create(null, inner)
},
},
]
Expand Down
2 changes: 2 additions & 0 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ describe('Markdown though editor', () => {
expect(markdownThroughEditor('```\n<?php echo "Hello World";\n```')).toBe('```\n<?php echo "Hello World";\n```')
// Issue #3328
expect(markdownThroughEditor('```python\nprint("Hello World")\n```')).toBe('```python\nprint("Hello World")\n```')
// Issue #3739
expect(markdownThroughEditor('```\n```')).toBe('```\n```')
})
test('markdown untouched', () => {
// Issue #2703
Expand Down

0 comments on commit 3c443b2

Please sign in to comment.