From bdc451d66beb6944dc4fbbfa19aef14fef457858 Mon Sep 17 00:00:00 2001 From: Justin Sleep Date: Wed, 3 Jun 2020 16:36:48 -0500 Subject: [PATCH] Remove escape backslashes in non-Markdown messages --- src/Markdown.js | 8 -------- src/editor/serialize.ts | 4 ++++ test/editor/serialize-test.js | 12 ++++++++++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Markdown.js b/src/Markdown.js index fb1f8bf0ea..d312b7c5bd 100644 --- a/src/Markdown.js +++ b/src/Markdown.js @@ -175,14 +175,6 @@ export default class Markdown { const renderer = new commonmark.HtmlRenderer({safe: false}); const real_paragraph = renderer.paragraph; - // The default `out` function only sends the input through an XML - // escaping function, which causes messages to be entity encoded, - // which we don't want in this case. - renderer.out = function(s) { - // The `lit` function adds a string literal to the output buffer. - this.lit(s); - }; - renderer.paragraph = function(node, entering) { // as with toHTML, only append lines to paragraphs if there are // multiple paragraphs diff --git a/src/editor/serialize.ts b/src/editor/serialize.ts index 4d0b8cd03a..85d2bb8e8f 100644 --- a/src/editor/serialize.ts +++ b/src/editor/serialize.ts @@ -42,6 +42,10 @@ export function htmlSerializeIfNeeded(model: EditorModel, {forceHTML = false} = if (!parser.isPlainText() || forceHTML) { return parser.toHTML(); } + // ensure removal of escape backslashes in non-Markdown messages + if (md.indexOf("\\") > -1) { + return parser.toPlaintext(); + } } export function textSerialize(model: EditorModel) { diff --git a/test/editor/serialize-test.js b/test/editor/serialize-test.js index bd26ae91bb..f0d577ea21 100644 --- a/test/editor/serialize-test.js +++ b/test/editor/serialize-test.js @@ -61,4 +61,16 @@ describe('editor/serialize', function() { const html = htmlSerializeIfNeeded(model, {}); expect(html).toBe("Displayname]"); }); + it('escaped markdown should not retain backslashes', function() { + const pc = createPartCreator(); + const model = new EditorModel([pc.plain('\\*hello\\* world')]); + const html = htmlSerializeIfNeeded(model, {}); + expect(html).toBe('*hello* world'); + }); + it('escaped markdown should convert HTML entities', function() { + const pc = createPartCreator(); + const model = new EditorModel([pc.plain('\\*hello\\* world < hey world!')]); + const html = htmlSerializeIfNeeded(model, {}); + expect(html).toBe('*hello* world < hey world!'); + }); });