Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4629457
feature: initial table support
max-nextcloud Mar 9, 2022
a62606c
refactor: render Markdown in table nodes
max-nextcloud Mar 10, 2022
759f8cb
fix: handling of various table formats
max-nextcloud Mar 14, 2022
c41a661
feature: add table button to create a table
max-nextcloud Mar 14, 2022
921080c
💄 (#114): add table css
Mar 14, 2022
39cf02c
fix: keep tables separate in markdown
max-nextcloud Mar 15, 2022
2443861
refactor: separate file for TableHeadRow
max-nextcloud Mar 15, 2022
15480e0
fix: use tableRole `row` for headerRow
max-nextcloud Mar 15, 2022
230dba7
fix: table layout to match prosemirror expectations
max-nextcloud Mar 16, 2022
df1deb6
fix: preserve td and th attributes
max-nextcloud Mar 16, 2022
7481eee
style: add border radius to table
max-nextcloud Mar 16, 2022
11ccb11
style: margin below a table to keep them separated
max-nextcloud Mar 16, 2022
fca037f
fix: make tab leave table on last cell.
max-nextcloud Mar 16, 2022
d626d24
enhance: move cursor down in table on enter
max-nextcloud Mar 17, 2022
932191e
ui: use table icon from material design
max-nextcloud Mar 17, 2022
5ea0628
feat: add and remove columns in tables
max-nextcloud Mar 21, 2022
3491ccb
ui: add actions for rows
max-nextcloud Mar 21, 2022
2e0440e
ui: translate table actions, new icons
max-nextcloud Mar 22, 2022
3bd2f3a
ui: reduce spacing in table headers
max-nextcloud Mar 22, 2022
0cd70c0
fix: disallow creating a table from within a table
max-nextcloud Mar 22, 2022
b1c27a4
ui: tweak tables
max-nextcloud Mar 22, 2022
9ebbe2e
make npm_package_name available
max-nextcloud Mar 23, 2022
08a9764
feature: button to remove table
max-nextcloud Mar 23, 2022
29d068e
ui: use primary-light color for hovered table row
max-nextcloud Mar 23, 2022
d7ae7e7
💄 (#114): add table css variables
Mar 30, 2022
52c36ba
build: compile js
max-nextcloud Mar 31, 2022
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
Prev Previous commit
Next Next commit
fix: keep tables separate in markdown
Also make sure that table rows are rendered on one line each.

Signed-off-by: Max <[email protected]>
  • Loading branch information
max-nextcloud committed Mar 31, 2022
commit 39cf02c6e67e1784e23b771bb92dcdfdf6c408ba
54 changes: 54 additions & 0 deletions cypress/fixtures/Table.md
Original file line number Diff line number Diff line change
@@ -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

76 changes: 76 additions & 0 deletions cypress/integration/Table.spec.js
Original file line number Diff line number Diff line change
@@ -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)
}
})
1 change: 1 addition & 0 deletions src/nodes/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default Table.extend({

toMarkdown(state, node) {
state.renderContent(node)
state.closeBlock(node)
},

})
1 change: 1 addition & 0 deletions src/nodes/TableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default TableRow.extend({
toMarkdown(state, node) {
state.write('|')
state.renderInline(node)
state.ensureNewLine()
},

parseHTML() {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/tables.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down