diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-12-02 11:14:14 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-12-02 11:26:49 +0300 |
commit | 3c350b2d41ea352e9d5131ff1def87182402a6e2 (patch) | |
tree | 1e6bf7945a2f73ac8be426699a0e3a78f4324f2d /src | |
parent | ffdf26ff3dcf4295b6f296881226b08afa90235d (diff) |
Fix espacing and cover with tests (fixes #325)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/EditorFactory.js | 5 | ||||
-rw-r--r-- | src/tests/markdown.spec.js | 29 |
2 files changed, 29 insertions, 5 deletions
diff --git a/src/EditorFactory.js b/src/EditorFactory.js index 9b37cb5c1..de0b03e8b 100644 --- a/src/EditorFactory.js +++ b/src/EditorFactory.js @@ -134,8 +134,9 @@ const createMarkdownSerializer = (_nodes, _marks) => { { ...defaultMarkdownSerializer.marks, ...marks } ), serialize: function(content, options) { - return this.serializer.serialize(content, { ...options, tightLists: true }).split('\\[ \\]').join('[ ]') - .split('\\[x\\]').join('[x]') + return this.serializer.serialize(content, { ...options, tightLists: true }) + .split('\\[').join('[') + .split('\\]').join(']') }, } } diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js index 354665b8a..9c52f87b6 100644 --- a/src/tests/markdown.spec.js +++ b/src/tests/markdown.spec.js @@ -81,7 +81,32 @@ describe('Markdown though editor', () => { 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)') + expect(markdownThroughEditor('- [ [asd](sdf)')).toBe('* [ [asd](sdf)') + expect(markdownThroughEditor('- [ ] asd')).toBe('* [ ] asd') + expect(markdownThroughEditor('- [ ] foo\n- [x] bar')).toBe('* [ ] foo\n* [x] bar') + expect(markdownThroughEditor('- [x] foo\n' + + ' - [ ] bar\n' + + ' - [x] baz\n' + + '- [ ] bim')).toBe('* [x] foo\n' + + ' * [ ] bar\n' + + ' * [x] baz\n' + + '* [ ] bim') + expect(markdownThroughEditor('- [X] asd')).toBe('* [x] asd') + expect(markdownThroughEditor('- [\t] asd')).toBe('* [ ] asd') + expect(markdownThroughEditor('- [ ] asd')).toBe('* [ ] asd') + expect(markdownThroughEditor('- [X] asd')).toBe('* [x] asd') + expect(markdownThroughEditor('- [F] asd')).toBe('* [F] asd') + }) + + test('escaping', () => { + const test = '(Asdf [asdf asdf](asdf asdf) asdf asdf asdf asdf asdf asdf asdf asdf asdf)\n' + + '\n' + + '* [asdf asdf asdf/asdf](Asdf Asdf)\n' + + '* asdf asdf asdf [a--f asdf asdf](a--f Asdf Asdf)\n' + + '* [Asdf asdf asdf asdf asdf asdf](Asdf asdf)' + expect(markdownThroughEditor(test)).toBe(test) + expect(markdownThroughEditor('This is a [test] for escaping')).toBe('This is a [test] for escaping') + expect(markdownThroughEditor('This is a [test for escaping')).toBe('This is a [test for escaping') }) }) @@ -96,8 +121,6 @@ describe('Markdown serializer from html', () => { expect(markdownThroughEditorHtml('<img src="image" alt="description" />')).toBe('![description](image)') }) test('checkboxes', () => { - expect(markdownThroughEditor('- [ ] asd')).toBe('* [ ] asd') - expect(markdownThroughEditor('- [X] asd')).toBe('* [x] asd') expect(markdownThroughEditorHtml('<ul><li><input type="checkbox" checked /><label>foo</label></li></ul>')).toBe('* [x] foo') expect(markdownThroughEditorHtml('<ul><li><input type="checkbox" /><label>test</label></li></ul>')).toBe('* [ ] test') expect(markdownThroughEditorHtml('<ul><li><input type="checkbox" checked /><div><h2>Test</h2><p><strong>content</strong></p></div></li></ul>')).toBe('* [x] Test\n\n **content**') |