mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:48:17 +08:00
Remove unwanted spaces between HTML tags and support Word documents
This commit is contained in:
@ -4,19 +4,21 @@ QUnit.module("lib:to-markdown");
|
||||
|
||||
QUnit.test("converts styles between normal words", assert => {
|
||||
const html = `Line with <s>styles</s> <b><i>between</i></b> words.`;
|
||||
const markdown = `Line with ~~styles~~ **_between_** words.`;
|
||||
const markdown = `Line with ~~styles~~ ***between*** words.`;
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
|
||||
assert.equal(toMarkdown("A <b>bold </b>word"), "A **bold** word");
|
||||
});
|
||||
|
||||
QUnit.test("converts inline nested styles", assert => {
|
||||
let html = `<em>Italicised line with <strong>some random</strong> <b>bold</b> words.</em>`;
|
||||
let markdown = `_Italicised line with **some random** **bold** words._`;
|
||||
let markdown = `*Italicised line with **some random** **bold** words.*`;
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
|
||||
html = `<i class="fa">Italicised line
|
||||
with <b title="strong">some
|
||||
with <b title="strong">some<br>
|
||||
random</b> <s>bold</s> words.</i>`;
|
||||
markdown = `<i>Italicised line\n with <b>some\n random</b> ~~bold~~ words.</i>`;
|
||||
markdown = `<i>Italicised line with <b>some\nrandom</b> ~~bold~~ words.</i>`;
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
});
|
||||
|
||||
@ -26,7 +28,7 @@ QUnit.test("converts a link", assert => {
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
|
||||
html = `<a href="https://discourse.org">Disc\n\n\nour\n\nse</a>`;
|
||||
markdown = `[Disc\nour\nse](https://discourse.org)`;
|
||||
markdown = `[Disc our se](https://discourse.org)`;
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
});
|
||||
|
||||
@ -82,7 +84,7 @@ QUnit.test("converts ul list tag", assert => {
|
||||
<li>Item 3</li>
|
||||
</ul>
|
||||
`;
|
||||
const markdown = `* Item 1\n* Item 2\n\n * Sub Item 1\n * Sub Item 2\n\n * Sub _Sub_ Item 1\n * Sub **Sub** Item 2\n\n* Item 3`;
|
||||
const markdown = `* Item 1\n* Item 2\n\n * Sub Item 1\n * Sub Item 2\n\n * Sub *Sub* Item 1\n * Sub **Sub** Item 2\n\n* Item 3`;
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
});
|
||||
|
||||
@ -101,10 +103,12 @@ QUnit.test("converts table tags", assert => {
|
||||
<thead> <tr><th>Heading 1</th><th>Head 2</th></tr> </thead>
|
||||
<tbody>
|
||||
<tr><td>Lorem</td><td>ipsum</td></tr>
|
||||
<tr><td><b>dolor</b></td> <td><i>sit amet</i></td></tr></tbody>
|
||||
<tr><td><b>dolor</b></td> <td><i>sit amet</i></td> </tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
`;
|
||||
const markdown = `Discourse Avenue\n\n**laboris**\n\n|Heading 1|Head 2|\n| --- | --- |\n|Lorem|ipsum|\n|**dolor**|_sit amet_|`;
|
||||
const markdown = `Discourse Avenue\n\n**laboris**\n\n|Heading 1|Head 2|\n| --- | --- |\n|Lorem|ipsum|\n|**dolor**|*sit amet*|`;
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
});
|
||||
|
||||
@ -164,11 +168,11 @@ QUnit.test("supporting html tags by keeping them", assert => {
|
||||
output = `[Lorem <del>ipsum dolor</del> sit](http://example.com).`;
|
||||
assert.equal(toMarkdown(html), output);
|
||||
|
||||
html = `Lorem <del>ipsum \n\n dolor</del> sit.`;
|
||||
html = `Lorem <del>ipsum dolor</del> sit.`;
|
||||
assert.equal(toMarkdown(html), html);
|
||||
|
||||
html = `Lorem <a href="http://example.com"><del>ipsum \n\n\n dolor</del> sit.</a>`;
|
||||
output = `Lorem [<del>ipsum \n dolor</del> sit.](http://example.com)`;
|
||||
output = `Lorem [<del>ipsum dolor</del> sit.](http://example.com)`;
|
||||
assert.equal(toMarkdown(html), output);
|
||||
});
|
||||
|
||||
@ -223,6 +227,6 @@ QUnit.test("converts ol list tag", assert => {
|
||||
<li>Item 3</li>
|
||||
</ol>
|
||||
`;
|
||||
const markdown = `Testing\n\n1. Item 1\n2. Item 2\n\n 100. Sub Item 1\n 101. Sub Item 2\n\n * Sub _Sub_ Item 1\n * Sub **Sub** Item 2\n\n3. Item 3`;
|
||||
const markdown = `Testing\n\n1. Item 1\n2. Item 2\n\n 100. Sub Item 1\n 101. Sub Item 2\n\n * Sub *Sub* Item 1\n * Sub **Sub** Item 2\n\n3. Item 3`;
|
||||
assert.equal(toMarkdown(html), markdown);
|
||||
});
|
||||
|
Reference in New Issue
Block a user