| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- class BlockTests extends BaseTest {
- /** @type {Markdown} */
- parser;
- md(markdown) {
- return normalizeWhitespace(this.parser.toHTML(markdown));
- }
-
- setUp() {
- this.parser = Markdown.completeParser;
- }
-
- test_paragraphs() {
- let markdown = "Lorem ipsum\n\nDolor sit amet";
- let expected = "<p>Lorem ipsum</p> <p>Dolor sit amet</p>";
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_paragraph_lineGrouping() {
- let markdown = "Lorem ipsum\ndolor sit amet";
- let expected = "Lorem ipsum dolor sit amet";
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_header_underlineH1() {
- let markdown = "Header 1\n===\n\nLorem ipsum";
- let expected = "<h1>Header 1</h1> <p>Lorem ipsum</p>";
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_header_underlineH2() {
- let markdown = "Header 2\n---\n\nLorem ipsum";
- let expected = "<h2>Header 2</h2> <p>Lorem ipsum</p>";
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_header_hash() {
- let markdown = "# Header 1\n## Header 2\n### Header 3\n#### Header 4\n##### Header 5\n###### Header 6\n";
- let expected = '<h1>Header 1</h1> <h2>Header 2</h2> <h3>Header 3</h3> <h4>Header 4</h4> <h5>Header 5</h5> <h6>Header 6</h6>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_header_hash_trailing() {
- let markdown = "# Header 1 #\n## Header 2 ##\n### Header 3 ######";
- let expected = '<h1>Header 1</h1> <h2>Header 2</h2> <h3>Header 3</h3>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_unorderedList() {
- let markdown = "* Lorem\n* Ipsum\n* Dolor";
- let expected = '<ul> <li>Lorem</li> <li>Ipsum</li> <li>Dolor</li> </ul>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_unorderedList_nested() {
- let markdown = "* Lorem\n + Ipsum\n* Dolor";
- let expected = '<ul> <li>Lorem<ul> <li>Ipsum</li> </ul> </li> <li>Dolor</li> </ul>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_unorderedList_hitch() {
- // This incomplete bulleted list locked up the browser at one
- // point, not forever but a REALLY long time
- this.profile(1.0, () => {
- let markdown = "Testing\n\n* ";
- let expected = '<p>Testing</p> <ul> <li></li> </ul>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- });
- }
-
- test_orderedList() {
- let markdown = "1. Lorem\n1. Ipsum\n5. Dolor";
- let expected = '<ol> <li>Lorem</li> <li>Ipsum</li> <li>Dolor</li> </ol>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_orderedList_numbering() {
- let markdown = "4. Lorem\n1. Ipsum\n9. Dolor";
- let expected = '<ol start="4"> <li>Lorem</li> <li>Ipsum</li> <li>Dolor</li> </ol>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_orderedList_nested1() {
- let markdown = "1. Lorem\n 1. Ipsum\n1. Dolor";
- let expected = '<ol> <li>Lorem<ol> <li>Ipsum</li> </ol> </li> <li>Dolor</li> </ol>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_orderedList_nested2() {
- let markdown = "1. Lorem\n 1. Ipsum\n 1. Dolor\n 1. Sit\n1. Amet";
- let expected = '<ol> <li>Lorem<ol> <li>Ipsum<ol> <li>Dolor</li> </ol> </li> <li>Sit</li> </ol> </li> <li>Amet</li> </ol>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_blockquote() {
- let markdown = '> Lorem ipsum dolor';
- let expected = '<blockquote>Lorem ipsum dolor</blockquote>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_blockquote_paragraphs() {
- let markdown = '> Lorem ipsum dolor\n>\n>Sit amet';
- let expected = '<blockquote> <p>Lorem ipsum dolor</p> <p>Sit amet</p> </blockquote>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_blockquote_list() {
- let markdown = '> 1. Lorem\n> 2. Ipsum';
- let expected = '<blockquote> <ol> <li>Lorem</li> <li>Ipsum</li> </ol> </blockquote>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_codeBlock_indented() {
- let markdown = "Code\n\n function foo() {\n return 'bar';\n }\n\nend";
- let expected = "<p>Code</p>\n\n<pre><code>function foo() {\n return 'bar';\n}</code></pre>\n\n<p>end</p>";
- let actual = this.parser.toHTML(markdown).trim(); // don't normalize whitespace
- this.assertEqual(actual.replace(/ /g, '⎵'), expected.replace(/ /g, '⎵'));
- }
-
- test_codeBlock_fenced() {
- let markdown = "Code\n\n```\nfunction foo() {\n return 'bar';\n}\n```\n\nend";
- let expected = "<p>Code</p>\n\n<pre><code>function foo() {\n return 'bar';\n}</code></pre>\n\n<p>end</p>";
- let actual = this.parser.toHTML(markdown).trim(); // don't normalize whitespace
- this.assertEqual(actual.replace(/ /g, '⎵'), expected.replace(/ /g, '⎵'));
- }
-
- test_codeBlock_fenced_language() {
- let markdown = "Code\n\n```javascript\nfunction foo() {\n return 'bar';\n}\n```\n\nend";
- let expected = "<p>Code</p>\n\n<pre><code class=\"language-javascript\">function foo() {\n return 'bar';\n}</code></pre>\n\n<p>end</p>";
- let actual = this.parser.toHTML(markdown).trim(); // don't normalize whitespace
- this.assertEqual(actual.replace(/ /g, '⎵'), expected.replace(/ /g, '⎵'));
- }
-
- test_horizontalRule() {
- let markdown = "Before\n\n---\n\n- - -\n\n***\n\n* * * * * * *\n\nafter";
- let expected = "<p>Before</p> <hr> <hr> <hr> <hr> <p>after</p>";
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_table_unfenced() {
- let markdown = "Column A | Column B | Column C\n--- | --- | ---\n1 | 2 | 3\n4 | 5 | 6";
- let expected = "<table> <thead> <tr> <th>Column A</th> <th>Column B</th> <th>Column C</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> </tbody> </table>";
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_table_fenced() {
- let markdown = "| Column A | Column B | Column C |\n| --- | --- | --- |\n| 1 | 2 | 3\n4 | 5 | 6 |";
- let expected = "<table> <thead> <tr> <th>Column A</th> <th>Column B</th> <th>Column C</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> </tr> <tr> <td>4</td> <td>5</td> <td>6</td> </tr> </tbody> </table>";
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_table_alignment() {
- let markdown = 'Column A | Column B | Column C\n' +
- ':--- | :---: | ---:\n' +
- '1 | 2 | 3\n' +
- '4 | 5 | 6';
- let expected = '<table> ' +
- '<thead> ' +
- '<tr> ' +
- '<th style="text-align: left;">Column A</th> ' +
- '<th style="text-align: center;">Column B</th> ' +
- '<th style="text-align: right;">Column C</th> ' +
- '</tr> ' +
- '</thead> ' +
- '<tbody> ' +
- '<tr> ' +
- '<td style="text-align: left;">1</td> ' +
- '<td style="text-align: center;">2</td> ' +
- '<td style="text-align: right;">3</td> ' +
- '</tr> ' +
- '<tr> ' +
- '<td style="text-align: left;">4</td> ' +
- '<td style="text-align: center;">5</td> ' +
- '<td style="text-align: right;">6</td> ' +
- '</tr> ' +
- '</tbody> ' +
- '</table>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_table_holes() {
- let markdown = 'Column A||Column C\n' +
- '---|---|---\n' +
- '|1|2||\n' +
- '|4||6|\n' +
- '||8|9|';
- let expected = '<table> ' +
- '<thead> ' +
- '<tr> ' +
- '<th>Column A</th> ' +
- '<th></th> ' +
- '<th>Column C</th> ' +
- '</tr> ' +
- '</thead> ' +
- '<tbody> ' +
- '<tr> ' +
- '<td>1</td> ' +
- '<td>2</td> ' +
- '<td></td> ' +
- '</tr> ' +
- '<tr> ' +
- '<td>4</td> ' +
- '<td></td> ' +
- '<td>6</td> ' +
- '</tr> ' +
- '<tr> ' +
- '<td></td> ' +
- '<td>8</td> ' +
- '<td>9</td> ' +
- '</tr> ' +
- '</tbody> ' +
- '</table>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_definitionList() {
- let markdown = 'term\n' +
- ': definition\n' +
- 'another' +
- ' term\n' +
- ': def 1\n' +
- ' broken on next line\n' +
- ': def 2';
- let expected = '<dl> ' +
- '<dt>term</dt> ' +
- '<dd>definition</dd> ' +
- '<dt>another term</dt> ' +
- '<dd>def 1 broken on next line</dd> ' +
- '<dd>def 2</dd> ' +
- '</dl>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_footnotes() {
- let markdown = 'Lorem ipsum[^1] dolor[^abc] sit[^1] amet\n\n[^1]: A footnote\n[^abc]: Another footnote';
- let expected = '<p>Lorem ipsum<sup class="footnote" id="footnoteref_1"><a href="#footnote_1">1</a></sup> ' +
- 'dolor<sup class="footnote" id="footnoteref_2"><a href="#footnote_2">2</a></sup> ' +
- 'sit<sup class="footnote" id="footnoteref_3"><a href="#footnote_1">1</a></sup> amet</p> ' +
- '<div class="footnotes">' +
- '<ol>' +
- '<li value="1" id="footnote_1">A footnote <a href="#footnoteref_1" class="footnote-backref">↩︎</a> <a href="#footnoteref_3" class="footnote-backref">↩︎</a></li> ' +
- '<li value="2" id="footnote_2">Another footnote <a href="#footnoteref_2" class="footnote-backref">↩︎</a></li> ' +
- '</ol>' +
- '</div>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
-
- test_abbreviations() {
- let markdown = 'Lorem ipsum HTML dolor HTML sit\n' +
- '\n' +
- '*[HTML]: Hypertext Markup Language';
- let expected = '<p>Lorem ipsum <abbr title="Hypertext Markup Language">HTML</abbr> dolor <abbr title="Hypertext Markup Language">HTML</abbr> sit</p>';
- let actual = this.md(markdown);
- this.assertEqual(actual, expected);
- }
- }
|