mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
1b52cdedb1
commit
9bfce1a8dd
@ -654,6 +654,7 @@ function trimUnwanted(html) {
|
|||||||
const body = html.match(/<body[^>]*>([\s\S]*?)<\/body>/);
|
const body = html.match(/<body[^>]*>([\s\S]*?)<\/body>/);
|
||||||
html = body ? body[1] : html;
|
html = body ? body[1] : html;
|
||||||
html = html.replace(/\r|\n| /g, " ");
|
html = html.replace(/\r|\n| /g, " ");
|
||||||
|
html = html.replace(/\u00A0/g, " "); // trim no-break space
|
||||||
|
|
||||||
let match;
|
let match;
|
||||||
while ((match = html.match(/<[^\s>]+[^>]*>\s{2,}<[^\s>]+[^>]*>/))) {
|
while ((match = html.match(/<[^\s>]+[^>]*>\s{2,}<[^\s>]+[^>]*>/))) {
|
||||||
|
@ -21,6 +21,11 @@ module("Unit | Utility | to-markdown", function () {
|
|||||||
random</b> <s>bold</s> words.</i>`;
|
random</b> <s>bold</s> words.</i>`;
|
||||||
markdown = `<i>Italicised line with <b>some\nrandom</b> ~~bold~~ words.</i>`;
|
markdown = `<i>Italicised line with <b>some\nrandom</b> ~~bold~~ words.</i>`;
|
||||||
assert.equal(toMarkdown(html), markdown);
|
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) {
|
test("converts a link", function (assert) {
|
||||||
|
Loading…
Reference in New Issue
Block a user