Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable26] Fix/2708 pasting tables #4314

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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-editors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-editors.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.

6 changes: 4 additions & 2 deletions src/components/PlainTextReader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
</template>

<script>
/* eslint-disable import/no-named-as-default */
import CodeBlock from '@tiptap/extension-code-block'
import escapeHtml from 'escape-html'
import BaseReader from './BaseReader.vue'
import { PlainText } from './../extensions/index.js'
import escapeHtml from 'escape-html'

export default {
name: 'PlainTextReader',
Expand All @@ -37,7 +39,7 @@ export default {
renderHtml(content) {
return '<pre>' + escapeHtml(content) + '</pre>'
},
extensions: () => [PlainText],
extensions: () => [PlainText, CodeBlock],
},

props: {
Expand Down
2 changes: 0 additions & 2 deletions src/extensions/PlainText.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import { Extension } from '@tiptap/core'

/* eslint-disable import/no-named-as-default */
import CodeBlock from '@tiptap/extension-code-block'
import Text from '@tiptap/extension-text'
import PlainTextDocument from './../nodes/PlainTextDocument.js'

Expand All @@ -34,7 +33,6 @@ export default Extension.create({
return [
PlainTextDocument,
Text,
CodeBlock,
]
},

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/Table/TableHeadRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default TableRow.extend({

parseHTML() {
return [
{ tag: 'tr', priority: 70 },
{ tag: 'tr:first-of-type', priority: 80 },
]
},
})
2 changes: 1 addition & 1 deletion src/nodes/Table/TableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default TableRow.extend({

parseHTML() {
return [
{ tag: 'tr', priority: 80 },
{ tag: 'tr', priority: 70 },
]
},
})
15 changes: 15 additions & 0 deletions src/tests/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,18 @@ export function markdownThroughEditorHtml(html) {
const serializer = createMarkdownSerializer(tiptap.schema)
return serializer.serialize(tiptap.state.doc)
}

/**
* Paste HTML into the Editor and return the serialized markdown
*
* @param {string} html
* @returns {string}
*/
export function markdownFromPaste(html) {
const tiptap = createEditor({
enableRichEditing: true
})
tiptap.commands.insertContent(html)
const serializer = createMarkdownSerializer(tiptap.schema)
return serializer.serialize(tiptap.state.doc)
}
15 changes: 14 additions & 1 deletion src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import spec from "./fixtures/spec"
import markdownit from './../markdownit'
import { typesAvailable } from './../markdownit/callouts'
import { markdownThroughEditor, markdownThroughEditorHtml } from "./helpers";
import {
markdownThroughEditor,
markdownThroughEditorHtml,
markdownFromPaste
} from './helpers.js'
import { createMarkdownSerializer } from "../extensions/Markdown";
import createEditor from "../EditorFactory";

Expand Down Expand Up @@ -195,11 +199,20 @@ describe('Markdown serializer from html', () => {
)).toBe(`::: warn\n!warning!\n\n:::`)
})

test('table', () => {
expect(markdownThroughEditorHtml('<table><tbody><tr><th>greetings</th></tr><tr><td>hello</td></tr></tbody></table>')).toBe('| greetings |\n|-----------|\n| hello |\n')
})

test('table cell escaping', () => {
// while '|' has no special meaning in commonmark is has to be escaped for GFM tables
expect(markdownThroughEditorHtml('<table><tr><th>greetings</th></tr><tr><td>hello | hallo</td></tr></table>')).toBe('| greetings |\n|-----------|\n| hello \\| hallo |\n')
})

test('table pastes (#2708)', () => {
// while '|' has no special meaning in commonmark is has to be escaped for GFM tables
expect(markdownFromPaste('<table><tbody><tr><th>greetings</th></tr><tr><td>hello</td></tr></tbody></table>')).toBe('| greetings |\n|-----------|\n| hello |\n')
})

test('front matter', () => {
expect(markdownThroughEditorHtml('<pre id="frontmatter"><code>some: value</code></pre><h1>Heading</h1>')).toBe('---\nsome: value\n---\n\n# Heading')
// Test --- within front matter is allowed
Expand Down