Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
Fix code blocks loosing the language hint on serialization
`prosemirror-markdown` uses `params` attribute for the language hint
whereas `tiptap` uses the `language` attribute.

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux authored and mejo- committed Oct 31, 2022
commit b33ea7546a92391e94bff36f3dce2866748834b1
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 @@ -28,7 +28,7 @@ import BulletList from './../nodes/BulletList.js'
import Callout from './../nodes/Callouts.js'
import CharacterCount from '@tiptap/extension-character-count'
import Code from '@tiptap/extension-code'
import CodeBlock from '@tiptap/extension-code-block'
import CodeBlock from './../nodes/CodeBlock.js'
import Document from '@tiptap/extension-document'
import Dropcursor from '@tiptap/extension-dropcursor'
import FrontMatter from './../nodes/FrontMatter.js'
Expand Down
14 changes: 14 additions & 0 deletions src/nodes/CodeBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import TiptapCodeBlock from '@tiptap/extension-code-block'
import { defaultMarkdownSerializer } from 'prosemirror-markdown'

const CodeBlock = TiptapCodeBlock.extend({

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 @@ -101,6 +101,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