FIX: remove whitespaces around inline HTML tags next to text. (#10803)

This commit is contained in:
Vinoth Kannan 2020-10-02 10:56:40 +05:30 committed by GitHub
parent 495c79da1a
commit d0d61e4118
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -25,7 +25,16 @@ export class Tag {
} }
if (this.inline) { if (this.inline) {
text = " " + text + " "; const prev = this.element.prev;
const next = this.element.next;
if (prev && prev.name !== "#text") {
text = " " + text;
}
if (next && next.name !== "#text") {
text = text + " ";
}
} }
return text; return text;

View File

@ -8,6 +8,7 @@ QUnit.test("converts styles between normal words", (assert) => {
assert.equal(toMarkdown(html), markdown); assert.equal(toMarkdown(html), markdown);
assert.equal(toMarkdown("A <b>bold </b>word"), "A **bold** word"); assert.equal(toMarkdown("A <b>bold </b>word"), "A **bold** word");
assert.equal(toMarkdown("A <b>bold</b>, word"), "A **bold**, word");
}); });
QUnit.test("converts inline nested styles", (assert) => { QUnit.test("converts inline nested styles", (assert) => {
@ -239,7 +240,7 @@ helloWorld();</code></pre>
return; return;
} }
helloWorld();</code>consectetur.`; helloWorld();</code>consectetur.`;
output = `Lorem ipsum dolor sit amet, \`var helloWorld = () => {\n alert(' hello \t\t world ');\n return;\n}\nhelloWorld();\` consectetur.`; output = `Lorem ipsum dolor sit amet, \`var helloWorld = () => {\n alert(' hello \t\t world ');\n return;\n}\nhelloWorld();\`consectetur.`;
assert.equal(toMarkdown(html), output); assert.equal(toMarkdown(html), output);
}); });