Skip to content

Commit

Permalink
Merge pull request #3480 from nextcloud/backport/3330/stable25
Browse files Browse the repository at this point in the history
[stable25] Combined code block backport
  • Loading branch information
juliusknorr authored Nov 24, 2022
2 parents db27365 + 5f539a0 commit 64a168b
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 18 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.

4 changes: 2 additions & 2 deletions src/extensions/Markdown.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
/**
* @copyright Copyright (c) 2022 Max <[email protected]>
*
* @author Max <[email protected]>
*
* @license GNU AGPL version 3 or any later version
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/RichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Blockquote from '@tiptap/extension-blockquote'
import OrderedList from '@tiptap/extension-ordered-list'
import ListItem from '@tiptap/extension-list-item'
import Code from '@tiptap/extension-code'
import CodeBlock from '@tiptap/extension-code-block'
import CodeBlock from './../nodes/CodeBlock.js'
import HorizontalRule from '@tiptap/extension-horizontal-rule'
import Dropcursor from '@tiptap/extension-dropcursor'
import FrontMatter from './../nodes/FrontMatter.js'
Expand Down
26 changes: 26 additions & 0 deletions src/nodes/CodeBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
node.attrs.params = node.attrs.language
return defaultMarkdownSerializer.nodes.code_block(state, node, parent, index)
},

})

export default CodeBlock
2 changes: 2 additions & 0 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ describe('Markdown though editor', () => {
})
test('code block', () => {
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```')
})
test('markdown untouched', () => {
// Issue #2703
Expand Down

0 comments on commit 64a168b

Please sign in to comment.