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:
authorJulius Härtl <jus@bitgrid.net>2019-07-02 21:22:20 +0300
committerJulius Härtl <jus@bitgrid.net>2019-07-02 21:22:20 +0300
commit7a5063d10564bd2bb0142c532a845b963ca533fd (patch)
tree2f0af27e84e7510dd8c0f208b8ef9d9acef16b1d /src/EditorFactory.js
parente6a951fe693cee8655324fd0347a5cc1ef0c8806 (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.js16
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