block quotes
and unordered lists draft
This commit is contained in:
31
index.ts
31
index.ts
@@ -3,8 +3,25 @@ import { test_assert_equal, total_tests, failed_tests, passed_tests } from './en
|
||||
|
||||
/*
|
||||
Quirks
|
||||
- Only one newline between text is needed for a new paragraph, not two.
|
||||
- Headings are given automatically generated ids ('header-0', 'header-1' etc) so url anchors (https://example.com/blog#header-1) are possible
|
||||
- Will only put newlines after headings, paragraphs, and horizontal rules, all others will not be in final output (exception is it will not put a newline on the last line, and also it will leave in newlines in code blocks)
|
||||
- Will only put newlines after headings, paragraphs, and horizontal rules, all others will not be in final output (exception is it will not put a newline on the last line, and also newlines in code blocks are preserved)
|
||||
- Spaces at the beginning of the line are normally cut off with html, so this parser will replace spaces with the html entity for spaces ( ) at the beginning of the line in code blocks
|
||||
- Lines in code blocks will be split with <br>s
|
||||
- The three backticks indicating a beginning or end of a code MUST be on their own line
|
||||
Invalid:
|
||||
```burger```
|
||||
Valid:
|
||||
```
|
||||
burger
|
||||
```
|
||||
- If a language for the code block is provided, the parser will add a css class "code-<language name>" to the resulting code block div (which btw has class code-block)
|
||||
- All elements should be able to be used in block quotes (ok, not really a quirk). In code blocks, the code in the code block must also start with "> " of course
|
||||
-
|
||||
*/
|
||||
|
||||
/*
|
||||
List of warning types
|
||||
-
|
||||
*/
|
||||
|
||||
@@ -42,8 +59,16 @@ test_assert_equal(parse_md_to_html("[a](b)\n[fake link](oops"), "<p><a href=\"b\
|
||||
|
||||
test_assert_equal(parse_md_to_html("`e\n\\`testing `console.log('*koala*');`"), "<p>`e</p>\n<p>`testing <code>console.log('*koala*');</code></p>", "code snippet test");
|
||||
|
||||
test_assert_equal(parse_md_to_html("## testing\n```markdown\n# title\n i like **cheeseburgers** and `code`\n```\n```"), "<h2 id=\"header-0\">testing</h2>\n<div class=\"code-block code-markdown\">\n# title\n i like **cheeseburgers** and `code`\n</div>\n<p><code></code>`</p>", "code block test");
|
||||
test_assert_equal(parse_md_to_html("```\nif time == 420:\n weed()\n```"), "<div class=\"code-block\">\nif time == 420:<br>\n weed()<br>\n</div>", "code block test 1");
|
||||
|
||||
//todo: blockquotes, ordered lists, unordered lists, table, code block
|
||||
test_assert_equal(parse_md_to_html("## testing\n```markdown\n# title\n i like **cheeseburgers** and `code`\n```\n```"), "<h2 id=\"header-0\">testing</h2>\n<div class=\"code-block code-markdown\">\n# title<br>\n i like **cheeseburgers** and `code`<br>\n</div>\n<p><code></code>`</p>", "code block test 2");
|
||||
|
||||
test_assert_equal(parse_md_to_html("test\n> test\n> ## TEST\n> **beach**\n> `wee`\n> # dd"), "<p>test</p>\n<blockquote>\n<p>test</p>\n<h2 id=\"header-0\">TEST</h2>\n<p><b>beach</b></p>\n<p><code>wee</code></p>\n<h1 id=\"header-1\">dd</h1>\n</blockquote>", "block quote test 1");
|
||||
|
||||
test_assert_equal(parse_md_to_html("> ```\n> alert('e')\n> ```"), "<blockquote>\n<div class=\"code-block\">\nalert('e')<br>\n</div>\n</blockquote>", "block quote test 2");
|
||||
|
||||
//todo: ordered lists, unordered lists, tables
|
||||
|
||||
console.log(parse_md_to_html("- burger\n- fries\n- pizza"));
|
||||
|
||||
console.log(`Total Passed: \x1B[32m${passed_tests}/${total_tests}\x1B[m\nTotal Failed: \x1B[31m${failed_tests}/${total_tests}\x1B[m`);
|
||||
|
||||
Reference in New Issue
Block a user