import { parse_md_to_html } from './makoto'; import { test_assert_equal, total_tests, failed_tests, passed_tests } from './endosulfan'; /* 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 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
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-" 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 - Superscripts are supported! "^1^" become "1". Use these for footnotes too, I'm not implementing those. - Underlined headers are not supported, just use a header and a horizontal rule - Nested blockquotes won't work - The first row of a table will be assumed to be the header row, and don't bother with a row of dashes after it. - Also, the pipe ("|") in tables is mandatory at the end of the row, otherwise weird things will happen. - Bold, italic, and other elements are not supported in tables - */ /* List of warning types - */ //tests test_assert_equal(parse_md_to_html("a\n\n\nb"), "

a

\n

b

", "new line test 1"); test_assert_equal(parse_md_to_html("a\n\n\nb\n"), "

a

\n

b

", "new line test 2"); test_assert_equal(parse_md_to_html("a\n\n\nb\n\n"), "

a

\n

b

", "new line test 3"); test_assert_equal(parse_md_to_html("# testing\n## Heading#\n# Chee see\nlorem ipsum"), "

testing

\n

Heading#

\n

Chee see

\n

lorem ipsum

", "heading test 1"); test_assert_equal(parse_md_to_html("in the sam#e way# bricks don't\n# Yay\n#a# b"), "

in the sam#e way# bricks don't

\n

Yay

\n

#a# b

", "heading test 2"); test_assert_equal(parse_md_to_html("# "), "

<script>a<bc</script>

", "sanitize test"); test_assert_equal(parse_md_to_html("# tet offensive\n"), "

tet offensive

", "heading test 3"); test_assert_equal(parse_md_to_html("**test abc** *a*\n## **ch*ch**"), "

test abc a

\n

ch*ch

", "bold italic test 1"); test_assert_equal(parse_md_to_html("****a*"), "

a*

", "bold italic test 2"); test_assert_equal(parse_md_to_html("**burger** *b*ca*\n**with no fries**"), "

burger bca*

\n

with no fries

", "bold italic test 3"); test_assert_equal(parse_md_to_html("---\n--\n----\n--a-\n---"), "
\n

--

\n
\n

--a-

\n
", "horizontal rule test"); test_assert_equal(parse_md_to_html("\\*\\*cheese\\*\\*\n*\\*cheese\\*\\*"), "

**cheese**

\n

*cheese*

", "backslash test"); test_assert_equal(parse_md_to_html("asdf![alt text](/images/ming-dynasty.png)\n![(burger!)](https://burger.com/burger.png)"), "

asdf\"alt

\n\"(burger!)\"", "image test"); test_assert_equal(parse_md_to_html("asdf![alt text(/images/ming-dynasty.png)\n![burgeerr](wee.pong\n)"), "

asdf![alt text(/images/ming-dynasty.png)

\n

![burgeerr](wee.pong

\n

)

", "invalid image test"); test_assert_equal(parse_md_to_html("Yo quiero [cheeseburger](https://wendys.org/burger).\n[Con cheerios.](/cheerios)"), "

Yo quiero cheeseburger.

\n

Con cheerios.

", "link test 1"); test_assert_equal(parse_md_to_html("[a](b)\n[fake link](oops"), "

a

\n

[fake link](oops

", "link test 2"); test_assert_equal(parse_md_to_html("`e\n\\`testing `console.log('*koala*');`"), "

`e

\n

`testing console.log('*koala*');

", "code snippet test"); test_assert_equal(parse_md_to_html("```\nif time == 420:\n weed()\n```"), "
\nif time == 420:
\n    weed()
\n
", "code block test 1"); test_assert_equal(parse_md_to_html("## testing\n```markdown\n# title\n i like **cheeseburgers** and `code`\n```\n```"), "

testing

\n
\n# title
\n  i like **cheeseburgers** and `code`
\n
\n

`

", "code block test 2"); test_assert_equal(parse_md_to_html("> ```\n> if\n> b\n> a\n> ```"), "
\n
\nif
\n b
\na
\n
\n
", "code block test 2") test_assert_equal(parse_md_to_html("test\n> test\n> ## TEST\n> **beach**\n> `wee`\n> # dd"), "

test

\n
\n

test

\n

TEST

\n

beach

\n

wee

\n

dd

\n
", "block quote test 1"); test_assert_equal(parse_md_to_html("> ```\n> alert('e')\n> ```"), "
\n
\nalert('e')
\n
\n
", "block quote test 2"); test_assert_equal(parse_md_to_html("> a\n\n> b"), "
\n

a

\n
\n
\n

b

\n
", "block quote test 3"); test_assert_equal(parse_md_to_html("> - burger\n> -winter melons\n> abcdefg\n> - fries\n- p**i**zza\na"), "
\n\n

-winter melons

\n

abcdefg

\n\n
\n\n

a

", "unordered lists test"); test_assert_equal(parse_md_to_html("1. a\n2. b\n3. c\n5. should *fail*\n> 1. d\n> 2. e\n3. should fail too"), "
    \n
  1. a
  2. \n
  3. b
  4. \n
  5. c
  6. \n
\n

5. should fail

\n
\n
    \n
  1. d
  2. \n
  3. e
  4. \n
\n
\n

3. should fail too

", "ordered lists test 1") test_assert_equal(parse_md_to_html("1. uno\n2. dos\n3. tres\n4. cuatro\n5. cinco\n6. seis\n7. siete\n8. ocho\n9. nueve\n10. diez\n11. once"), "
    \n
  1. uno
  2. \n
  3. dos
  4. \n
  5. tres
  6. \n
  7. cuatro
  8. \n
  9. cinco
  10. \n
  11. seis
  12. \n
  13. siete
  14. \n
  15. ocho
  16. \n
  17. nueve
  18. \n
  19. diez
  20. \n
  21. once
  22. \n
", "ordered lists test 2"); test_assert_equal(parse_md_to_html("a ^ace^ base\n```js\n^sup^\n```\ne=mc^2\n^ea^"), "

a ace base

\n
\n^sup^
\n
\n

e=mc^2

\n

ea

", "superscript test"); //I don't care about table edgecases. test_assert_equal(parse_md_to_html("|a|b|c|\n|d|e|f|\n# a"), "\n\n\n\n\n\n\n\n\n\n\n
abc
def
\n

a

", "basic table test"); console.log(`Total Passed: \x1B[32m${passed_tests}/${total_tests}\x1B[m\nTotal Failed: \x1B[31m${failed_tests}/${total_tests}\x1B[m`);