diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-07-02 21:22:20 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-07-02 21:22:20 +0300 |
commit | 7a5063d10564bd2bb0142c532a845b963ca533fd (patch) | |
tree | 2f0af27e84e7510dd8c0f208b8ef9d9acef16b1d /src/EditorFactory.js | |
parent | e6a951fe693cee8655324fd0347a5cc1ef0c8806 (diff) |
Use text node to serialize plain text
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'src/EditorFactory.js')
-rw-r--r-- | src/EditorFactory.js | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/EditorFactory.js b/src/EditorFactory.js index 3a991f01b..ec9a8835e 100644 --- a/src/EditorFactory.js +++ b/src/EditorFactory.js @@ -101,6 +101,9 @@ const createEditor = ({ content, onUpdate, extensions, enableRichEditing, langua const markdownit = MarkdownIt('commonmark', { html: false, breaks: false }) .enable('strikethrough') +const SerializeException = (message) => { + this.message = message +} const createMarkdownSerializer = (_nodes, _marks) => { const nodes = Object .entries(_nodes) @@ -124,9 +127,16 @@ const createMarkdownSerializer = (_nodes, _marks) => { } const serializePlainText = (tiptap) => { - const tmp = document.createElement('div') - tmp.innerHTML = tiptap.getHTML() - return tmp.textContent || tmp.innerText || '' + const doc = tiptap.getJSON() + + if (doc.content.length !== 1 || doc.content[0].content.length !== 1) { + throw new SerializeException('Failed to serialize document to plain text') + } + const codeBlock = doc.content[0].content[0] + if (codeBlock.type !== 'text') { + throw new SerializeException('Failed to serialize document to plain text') + } + return codeBlock.text } export default createEditor |