import toMarkdown from 'discourse/lib/to-markdown';
QUnit.module("lib:to-markdown");
QUnit.test("converts styles between normal words", assert => {
const html = `Line with styles between words.`;
const markdown = `Line with ~~styles~~ **_between_** words.`;
assert.equal(toMarkdown(html), markdown);
});
QUnit.test("converts inline nested styles", assert => {
let html = `Italicised line with some random bold words.`;
let markdown = `_Italicised line with **some random** **bold** words._`;
assert.equal(toMarkdown(html), markdown);
html = `Italicised line
with some
random bold words.`;
markdown = `Italicised line\n with some\n random ~~bold~~ words.`;
assert.equal(toMarkdown(html), markdown);
});
QUnit.test("converts a link", assert => {
let html = `Discourse`;
let markdown = `[Discourse](https://discourse.org)`;
assert.equal(toMarkdown(html), markdown);
html = `Disc\n\n\nour\n\nse`;
markdown = `[Disc\nour\nse](https://discourse.org)`;
assert.equal(toMarkdown(html), markdown);
});
QUnit.test("put raw URL instead of converting the link", assert => {
let url = "https://discourse.org";
const html = () => `${url}`;
assert.equal(toMarkdown(html()), url);
url = "discourse.org/t/topic-slug/1";
assert.equal(toMarkdown(html()), url);
});
QUnit.test("skip empty link", assert => {
assert.equal(toMarkdown(``), "");
});
QUnit.test("converts heading tags", assert => {
const html = `
Lorem ipsum dolor sit amet, consectetur elit.
Ut minim veniam, laboris
Heading 1 | Head 2 |
---|---|
Lorem | ipsum |
dolor | sit amet |
Headi\n\nng 1 | Head 2 |
---|---|
Lorem | ipsum |
sit amet |
var helloWorld = () => {
alert(' hello \t\t world ');
return;
}
helloWorld();
consectetur.`;
let output = `Lorem ipsum dolor sit amet,\n\n\`\`\`\nvar helloWorld = () => {\n alert(' hello \t\t world ');\n return;\n}\nhelloWorld();\n\`\`\`\n\nconsectetur.`;
assert.equal(toMarkdown(html), output);
html = `Lorem ipsum dolor sit amet, var helloWorld = () => {
alert(' hello \t\t world ');
return;
}
helloWorld();
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);
});
QUnit.test("converts blockquote tag", assert => {
let html = "Lorem ipsum"; let output = "> Lorem ipsum"; assert.equal(toMarkdown(html), output); html = "
Lorem ipsum
"; output = "> Lorem ipsum\n\n> dolor sit amet"; assert.equal(toMarkdown(html), output); html = "dolor sit amet
\nLorem ipsum\n"; output = "> Lorem ipsum\n> > dolor\n> > > sit\n> > amet"; assert.equal(toMarkdown(html), output); }); QUnit.test("converts ol list tag", assert => { const html = `Testingdolor
sitamet