Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cypress/fixtures/Table.md54
-rw-r--r--cypress/integration/Table.spec.js76
-rw-r--r--src/nodes/Table.js1
-rw-r--r--src/nodes/TableRow.js1
-rw-r--r--src/tests/tables.spec.js2
5 files changed, 133 insertions, 1 deletions
diff --git a/cypress/fixtures/Table.md b/cypress/fixtures/Table.md
new file mode 100644
index 000000000..634544249
--- /dev/null
+++ b/cypress/fixtures/Table.md
@@ -0,0 +1,54 @@
+## Preserve Tables
+
+This is a table
+
+| Header | other Header |
+|--------|--------------|
+| Cell | other cell |
+| Cell | other cell |
+
+---
+
+This is a table
+
+| Header | other Header |
+|--------|--------------|
+| Cell | other cell |
+| Cell | other cell |
+
+## Create a table
+
+insertTable
+
+---
+
+| | | |
+|--|--|--|
+| | | |
+| | | |
+
+did insertTable
+
+## Create second tables
+
+| | | |
+|--|--|--|
+| | | |
+| | | |
+
+insertTable
+
+---
+
+| | | |
+|--|--|--|
+| | | |
+| | | |
+
+| | | |
+|--|--|--|
+| | | |
+| | | |
+
+did insertTable
+
diff --git a/cypress/integration/Table.spec.js b/cypress/integration/Table.spec.js
new file mode 100644
index 000000000..a04601123
--- /dev/null
+++ b/cypress/integration/Table.spec.js
@@ -0,0 +1,76 @@
+import Table from './../../src/nodes/Table'
+import TableBody from './../../src/nodes/TableBody'
+import TableCell from './../../src/nodes/TableCell'
+import TableHead from './../../src/nodes/TableHead'
+import TableHeader from './../../src/nodes/TableHeader'
+import TableRow from './../../src/nodes/TableRow'
+import Markdown from './../../src/extensions/Markdown'
+import markdownit from './../../src/markdownit'
+import { createMarkdownSerializer } from './../../src/extensions/Markdown';
+import { findChildren, findChildrenByType } from 'prosemirror-utils'
+import createEditor from './../../src/tests/createEditor'
+import testData from '../fixtures/Table.md'
+
+describe('ListItem extension integrated in the editor', () => {
+
+ const editor = createEditor({
+ content: '',
+ extensions: [
+ Markdown,
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+ ],
+ })
+
+ for (const spec of testData.split(/#+\s+/)){
+ const [description, ...rest] = spec.split(/\n/)
+ const [input, output] = rest.join('\n').split(/\n\n---\n\n/)
+ if (!description) {
+ continue
+ }
+ it(description, () => {
+ expect(spec).to.include('\n')
+ expect(input).to.be.ok
+ expect(output).to.be.ok
+ loadMarkdown(input)
+ runCommands()
+ expectMarkdown(output.replace(/\n*$/, ''))
+ })
+ }
+
+ function loadMarkdown(markdown) {
+ editor.commands.setContent(markdownit.render(markdown))
+ }
+
+ function runCommands() {
+ let found
+ while (found = findCommand()) {
+ const name = found.node.text
+ editor.commands.setTextSelection(found.pos)
+ editor.commands[name]()
+ const updated = findCommand()
+ editor.commands.setTextSelection(updated.pos)
+ editor.commands.insertContent('did ')
+ }
+ }
+
+ function findCommand() {
+ const doc = editor.state.doc
+ return findChildren(doc, child => {
+ return child.isText && editor.commands.hasOwnProperty(child.text)
+ })[0]
+ }
+
+ function expectMarkdown(markdown) {
+ expect(getMarkdown().replace(/\n$/, '')).to.equal(markdown)
+ }
+
+ function getMarkdown() {
+ const serializer = createMarkdownSerializer(editor.schema)
+ return serializer.serialize(editor.state.doc)
+ }
+})
diff --git a/src/nodes/Table.js b/src/nodes/Table.js
index d2f55614b..ac667eee0 100644
--- a/src/nodes/Table.js
+++ b/src/nodes/Table.js
@@ -105,6 +105,7 @@ export default Table.extend({
toMarkdown(state, node) {
state.renderContent(node)
+ state.closeBlock(node)
},
})
diff --git a/src/nodes/TableRow.js b/src/nodes/TableRow.js
index 3beb7cf06..61e0b982a 100644
--- a/src/nodes/TableRow.js
+++ b/src/nodes/TableRow.js
@@ -9,6 +9,7 @@ export default TableRow.extend({
toMarkdown(state, node) {
state.write('|')
state.renderInline(node)
+ state.ensureNewLine()
},
parseHTML() {
diff --git a/src/tests/tables.spec.js b/src/tests/tables.spec.js
index 7e0bdce33..3ff44f1c8 100644
--- a/src/tests/tables.spec.js
+++ b/src/tests/tables.spec.js
@@ -17,7 +17,7 @@ describe('Table', () => {
test('serialize from editor', () => {
const tiptap = editorWithContent(markdownit.render(input))
const serializer = createMarkdownSerializer(tiptap.schema)
- expect(serializer.serialize(tiptap.state.doc)).toBe(input.replace(/\n$/, ''))
+ expect(serializer.serialize(tiptap.state.doc)).toBe(input)
})
test('handle html table with other structure', () => {