diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-07-09 11:53:26 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-07-10 14:06:26 +0300 |
commit | e16deb0f52780621d2cfb589562db5ea19581ba2 (patch) | |
tree | e0e0b4b028018e8bcf76c62687fec217379381ca /src | |
parent | a5cf029eb50bde6fb4b3df7db20dc88ca0912da7 (diff) |
Keep checkboxes as plain text
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/EditorFactory.js | 14 | ||||
-rw-r--r-- | src/tests/markdown.spec.js | 5 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/EditorFactory.js b/src/EditorFactory.js index ec9a8835e..e0cbd3206 100644 --- a/src/EditorFactory.js +++ b/src/EditorFactory.js @@ -120,10 +120,16 @@ const createMarkdownSerializer = (_nodes, _marks) => { ...items, [name]: toMarkdown }), {}) - return new MarkdownSerializer( - { ...defaultMarkdownSerializer.nodes, ...nodes }, - { ...defaultMarkdownSerializer.marks, ...marks } - ) + return { + serializer: new MarkdownSerializer( + { ...defaultMarkdownSerializer.nodes, ...nodes }, + { ...defaultMarkdownSerializer.marks, ...marks } + ), + serialize: function(content, options) { + return this.serializer.serialize(content, options).split('\\[ \\]').join('[ ]') + .split('\\[x\\]').join('[x]') + } + } } const serializePlainText = (tiptap) => { diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js index cf011929b..83ed81c5d 100644 --- a/src/tests/markdown.spec.js +++ b/src/tests/markdown.spec.js @@ -78,6 +78,11 @@ describe('Markdown though editor', () => { test('special characters', () => { expect(markdownThroughEditor('"\';&.-#><')).toBe('"\';&.-#><') }) + test('checkboxes', () => { + expect(markdownThroughEditor('- [ ] [asd](sdf)')).toBe('* [ ] [asd](sdf)') + expect(markdownThroughEditor('- [x] [asd](sdf)')).toBe('* [x] [asd](sdf)') + expect(markdownThroughEditor('- [ [asd](sdf)')).toBe('* \\[ [asd](sdf)') + }) }) describe('Markdown serializer from html', () => { |