From 3abdf6b1001f79a15cf924310cc4fdd90aeec6de Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 14 May 2019 10:37:16 +0100 Subject: [PATCH] also serialize to text and method to tell us if we need html for model --- src/editor/html_serialize.js | 14 ------------ src/editor/serialize.js | 43 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 14 deletions(-) delete mode 100644 src/editor/html_serialize.js create mode 100644 src/editor/serialize.js diff --git a/src/editor/html_serialize.js b/src/editor/html_serialize.js deleted file mode 100644 index bd8842b01f..0000000000 --- a/src/editor/html_serialize.js +++ /dev/null @@ -1,14 +0,0 @@ -export function htmlSerialize(model) { - return model.parts.reduce((html, part) => { - switch (part.type) { - case "newline": - return html + "
"; - case "plain": - case "pill-candidate": - return html + part.text; - case "room-pill": - case "user-pill": - return html + `${part.text}`; - } - }, ""); -} diff --git a/src/editor/serialize.js b/src/editor/serialize.js new file mode 100644 index 0000000000..57cc79b375 --- /dev/null +++ b/src/editor/serialize.js @@ -0,0 +1,43 @@ +export function htmlSerialize(model) { + return model.parts.reduce((html, part) => { + switch (part.type) { + case "newline": + return html + "
"; + case "plain": + case "pill-candidate": + return html + part.text; + case "room-pill": + case "user-pill": + return html + `${part.text}`; + } + }, ""); +} + +export function textSerialize(model) { + return model.parts.reduce((text, part) => { + switch (part.type) { + case "newline": + return text + "\n"; + case "plain": + case "pill-candidate": + return text + part.text; + case "room-pill": + case "user-pill": + return text + `${part.resourceId}`; + } + }, ""); +} + +export function requiresHtml(model) { + return model.parts.some(part => { + switch (part.type) { + case "newline": + case "plain": + case "pill-candidate": + return false; + case "room-pill": + case "user-pill": + return true; + } + }); +}