FIX: trim no-break space in to-markdown (#11130)

No-break spaces were the reason for double spaces when pasting text to the composer.

https://meta.discourse.org/t/extra-spaces-added-to-markdown-with-rich-text-pasted/112769
This commit is contained in:
Krzysztof Kotlarek 2020-11-06 09:36:36 +11:00 committed by GitHub
parent 1b52cdedb1
commit 9bfce1a8dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -654,6 +654,7 @@ function trimUnwanted(html) {
const body = html.match(/<body[^>]*>([\s\S]*?)<\/body>/);
html = body ? body[1] : html;
html = html.replace(/\r|\n|&nbsp;/g, " ");
html = html.replace(/\u00A0/g, " "); // trim no-break space
let match;
while ((match = html.match(/<[^\s>]+[^>]*>\s{2,}<[^\s>]+[^>]*>/))) {

View File

@ -21,6 +21,11 @@ module("Unit | Utility | to-markdown", function () {
random</b> <s>bold</s> words.</i>`;
markdown = `<i>Italicised line with <b>some\nrandom</b> ~~bold~~ words.</i>`;
assert.equal(toMarkdown(html), markdown);
// eslint-disable-next-line no-irregular-whitespace
html = `<span>this is<span> </span></span><strong>bold</strong><span><span> </span>statement</span>`;
markdown = `this is **bold** statement`;
assert.equal(toMarkdown(html), markdown);
});
test("converts a link", function (assert) {