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);
assert.equal(toMarkdown("A bold word"), "A **bold** word");
});
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 with some\nrandom ~~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 our se](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 = `
Sub Item 2
Lorem ipsum dolor sit amet, consectetur elit.
Ut minim veniam, laboris
Heading 1 | Head 2 |
---|---|
Lorem | ipsum |
dolor | sit amet |
Heading 1 | Head 2 |
---|---|
ipsum |
Headi ng 1 | Head 2 |
---|---|
Lorem | ipsum |
sit amet |
Heading 1 |
---|
Lorem |
sit amet |
Lorem | 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