From 2476738a511d1aa6069020ee8d1355a88a0581b9 Mon Sep 17 00:00:00 2001 From: aleclarson Date: Mon, 3 Dec 2018 12:12:50 -0500 Subject: [PATCH] 0.2.0 --- .gitignore | 3 - .prettierrc | 7 - .travis.yml | 11 - package.json | 2 +- spec/__snapshots__/index.spec.js.snap | 2836 ------------------------- spec/index.spec.js | 429 ---- 6 files changed, 1 insertion(+), 3287 deletions(-) delete mode 100644 .gitignore delete mode 100644 .prettierrc delete mode 100644 .travis.yml delete mode 100644 spec/__snapshots__/index.spec.js.snap delete mode 100644 spec/index.spec.js diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 05e59d8..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/node_modules/ -/coverage/ -/shrinkwrap.yaml diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index aff3c2b..0000000 --- a/.prettierrc +++ /dev/null @@ -1,7 +0,0 @@ -{ - "bracketSpacing": true, - "jsxBracketSameLine": true, - "singleQuote": true, - "semi": false, - "trailingComma": "es5" -} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a98d077..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: node_js -node_js: - - '8' - - '10' - - 'node' -git: - depth: 1 - quiet: true -env: - - NODE_ENV=TEST -script: npm test && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage diff --git a/package.json b/package.json index 172dfc3..15eb398 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "markdown-ast", - "version": "0.1.9", + "version": "0.2.0", "description": "Markdown AST parser", "repository": "aleclarson/markdown-ast", "license": "MIT", diff --git a/spec/__snapshots__/index.spec.js.snap b/spec/__snapshots__/index.spec.js.snap deleted file mode 100644 index 323408e..0000000 --- a/spec/__snapshots__/index.spec.js.snap +++ /dev/null @@ -1,2836 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Bold must be closed with same style 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "Hello world", - "type": "text", - }, - Object { - "block": Array [], - "style": "**", - "type": "bold", - }, - ], - "style": "__", - "type": "bold", - }, -] -`; - -exports[`Bold star syntax 1`] = ` -Array [ - Object { - "text": "I ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "like", - "type": "text", - }, - ], - "style": "**", - "type": "bold", - }, - Object { - "text": " tiny libraries", - "type": "text", - }, -] -`; - -exports[`Bold underline syntax 1`] = ` -Array [ - Object { - "text": "I ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "like", - "type": "text", - }, - ], - "style": "__", - "type": "bold", - }, - Object { - "text": " tiny libraries", - "type": "text", - }, -] -`; - -exports[`Bold wrapped in italic 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "tiny", - "type": "text", - }, - ], - "style": "**", - "type": "bold", - }, - Object { - "text": " libraries", - "type": "text", - }, - ], - "style": "_", - "type": "italic", - }, -] -`; - -exports[`Bold wrapped in italic 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "tiny", - "type": "text", - }, - ], - "style": "**", - "type": "bold", - }, - Object { - "text": " libraries", - "type": "text", - }, - ], - "style": "*", - "type": "italic", - }, -] -`; - -exports[`Bold wrapped in italic 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "tiny", - "type": "text", - }, - ], - "style": "__", - "type": "bold", - }, - Object { - "text": " libraries", - "type": "text", - }, - ], - "style": "_", - "type": "italic", - }, -] -`; - -exports[`Borders alternate symbols 1`] = ` -Array [ - Object { - "text": "foo -", - "type": "text", - }, - Object { - "text": "***", - "type": "border", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": "bar", - "type": "text", - }, -] -`; - -exports[`Borders alternate symbols 2`] = ` -Array [ - Object { - "text": "foo -", - "type": "text", - }, - Object { - "text": "* * *", - "type": "border", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": "bar", - "type": "text", - }, -] -`; - -exports[`Borders alternate symbols 3`] = ` -Array [ - Object { - "text": "foo -", - "type": "text", - }, - Object { - "text": "___", - "type": "border", - }, - Object { - "text": " -bar", - "type": "text", - }, -] -`; - -exports[`Borders alternate symbols 4`] = ` -Array [ - Object { - "text": "foo -", - "type": "text", - }, - Object { - "text": "_ _ _", - "type": "border", - }, - Object { - "text": " -bar", - "type": "text", - }, -] -`; - -exports[`Borders inside a quote 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "---", - "type": "border", - }, - Object { - "text": " -bar", - "type": "text", - }, - ], - "type": "quote", - }, -] -`; - -exports[`Borders inside a quote 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "* * *", - "type": "border", - }, - Object { - "text": " -bar", - "type": "text", - }, - ], - "type": "quote", - }, -] -`; - -exports[`Borders using spaced-out dashes 1`] = ` -Array [ - Object { - "text": "foo -", - "type": "text", - }, - Object { - "text": "- - -", - "type": "border", - }, - Object { - "text": " -bar", - "type": "text", - }, -] -`; - -exports[`Borders using spaced-out dashes 2`] = ` -Array [ - Object { - "text": "foo -", - "type": "text", - }, - Object { - "text": "- - -", - "type": "border", - }, - Object { - "text": " -bar", - "type": "text", - }, -] -`; - -exports[`Borders using spaced-out dashes 3`] = ` -Array [ - Object { - "text": "foo -", - "type": "text", - }, - Object { - "text": "- - -", - "type": "border", - }, - Object { - "text": " -bar", - "type": "text", - }, -] -`; - -exports[`Borders using tight-packed dashes 1`] = ` -Array [ - Object { - "text": "foo", - "type": "text", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": "---", - "type": "border", - }, - Object { - "text": " -bar", - "type": "text", - }, -] -`; - -exports[`Borders using tight-packed dashes 2`] = ` -Array [ - Object { - "text": "foo", - "type": "text", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": "----", - "type": "border", - }, - Object { - "text": " -bar", - "type": "text", - }, -] -`; - -exports[`Breaks using double \\n 1`] = ` -Array [ - Object { - "text": "Something with", - "type": "text", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": "a line break", - "type": "text", - }, -] -`; - -exports[`Breaks using double \\r\\n 1`] = ` -Array [ - Object { - "text": "Something with - -a line break", - "type": "text", - }, -] -`; - -exports[`Breaks using double space + \\n 1`] = ` -Array [ - Object { - "text": "Something with", - "type": "text", - }, - Object { - "text": " -", - "type": "break", - }, - Object { - "text": "a line break", - "type": "text", - }, -] -`; - -exports[`Code blocks fenced empty 1`] = ` -Array [ - Object { - "code": "", - "indent": "", - "syntax": "", - "type": "codeBlock", - }, -] -`; - -exports[`Code blocks fenced with explicit syntax 1`] = ` -Array [ - Object { - "code": "var a = 1", - "indent": "", - "syntax": "js", - "type": "codeBlock", - }, -] -`; - -exports[`Code blocks fenced with triple backticks 1`] = ` -Array [ - Object { - "code": "var a = 1", - "indent": "", - "syntax": "", - "type": "codeBlock", - }, -] -`; - -exports[`Code blocks indented empty with text immediately after 1`] = ` -Array [ - Object { - "code": "", - "indent": " ", - "syntax": "", - "type": "codeBlock", - }, - Object { - "text": " -foo", - "type": "text", - }, -] -`; - -exports[`Code blocks indented must be first on its line 1`] = ` -Array [ - Object { - "text": "| var a = 1", - "type": "text", - }, -] -`; - -exports[`Code blocks indented with mixed tabs/spaces 1`] = ` -Array [ - Object { - "code": "foo -foo", - "indent": " ", - "syntax": "", - "type": "codeBlock", - }, -] -`; - -exports[`Code blocks indented with mixed tabs/spaces 2`] = ` -Array [ - Object { - "code": "foo -foo -foo", - "indent": " ", - "syntax": "", - "type": "codeBlock", - }, - Object { - "text": " -", - "type": "text", - }, -] -`; - -exports[`Code blocks indented with spaces 1`] = ` -Array [ - Object { - "code": "var a = 1 -var b = 2", - "indent": " ", - "syntax": "", - "type": "codeBlock", - }, -] -`; - -exports[`Code blocks indented with tabs 1`] = ` -Array [ - Object { - "code": "var a = 1 -var b = 2", - "indent": " ", - "syntax": "", - "type": "codeBlock", - }, -] -`; - -exports[`Code spans in between text nodes 1`] = ` -Array [ - Object { - "text": "Use ", - "type": "text", - }, - Object { - "code": "foo(bar, true)", - "type": "codeSpan", - }, - Object { - "text": " to win bigly.", - "type": "text", - }, -] -`; - -exports[`Code spans right after newline in multi-line list item 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "Use -", - "type": "text", - }, - Object { - "code": "foo(bar, true)", - "type": "codeSpan", - }, - Object { - "text": " to win bigly.", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Code spans right before newline in multi-line list item 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "Use ", - "type": "text", - }, - Object { - "code": "foo(bar, true)", - "type": "codeSpan", - }, - Object { - "text": " -to win bigly.", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Edge cases unclosed bold 1`] = ` -Array [ - Object { - "block": Array [], - "style": "**", - "type": "bold", - }, -] -`; - -exports[`Edge cases unclosed bold 2`] = ` -Array [ - Object { - "block": Array [], - "style": "__", - "type": "bold", - }, -] -`; - -exports[`Edge cases unclosed bold 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "style": "**", - "type": "bold", - }, -] -`; - -exports[`Edge cases unclosed bold 4`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "style": "__", - "type": "bold", - }, -] -`; - -exports[`Edge cases unclosed code block 1`] = ` -Array [ - Object { - "text": "\`\`\`", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed code block 2`] = ` -Array [ - Object { - "text": "\`\`\` -foo", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed code span 1`] = ` -Array [ - Object { - "text": "\`", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed code span 2`] = ` -Array [ - Object { - "text": "\`foo", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed image 1`] = ` -Array [ - Object { - "text": "![", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed image 2`] = ` -Array [ - Object { - "alt": "", - "ref": "", - "type": "image", - "url": "", - }, - Object { - "text": "(", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed image 3`] = ` -Array [ - Object { - "text": "![foo", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed image 4`] = ` -Array [ - Object { - "alt": "", - "ref": "", - "type": "image", - "url": "", - }, - Object { - "text": "(foo", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed italic 1`] = ` -Array [ - Object { - "block": Array [], - "style": "*", - "type": "italic", - }, -] -`; - -exports[`Edge cases unclosed italic 2`] = ` -Array [ - Object { - "block": Array [], - "style": "_", - "type": "italic", - }, -] -`; - -exports[`Edge cases unclosed italic 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "style": "*", - "type": "italic", - }, -] -`; - -exports[`Edge cases unclosed italic 4`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "style": "_", - "type": "italic", - }, -] -`; - -exports[`Edge cases unclosed link 1`] = ` -Array [ - Object { - "block": Array [], - "ref": "", - "type": "link", - "url": "", - }, -] -`; - -exports[`Edge cases unclosed link 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": "", - }, -] -`; - -exports[`Edge cases unclosed link 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": "", - }, - Object { - "text": "(", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed link 4`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": "", - }, - Object { - "text": "(#bar", - "type": "text", - }, -] -`; - -exports[`Edge cases unclosed strike-through 1`] = ` -Array [ - Object { - "block": Array [], - "style": "~~", - "type": "strike", - }, -] -`; - -exports[`Edge cases unclosed strike-through 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "style": "~~", - "type": "strike", - }, -] -`; - -exports[`Escaped characters escaped bold 1`] = ` -Array [ - Object { - "text": "\\\\_", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "style": "_", - "type": "italic", - }, -] -`; - -exports[`Escaped characters escaped escape 1`] = ` -Array [ - Object { - "text": "\\\\\\\\", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - Object { - "block": Array [], - "style": "_", - "type": "italic", - }, - ], - "style": "__", - "type": "bold", - }, -] -`; - -exports[`Escaped characters escaped title 1`] = ` -Array [ - Object { - "text": "\\\\# foo bar", - "type": "text", - }, -] -`; - -exports[`Images cannot be confused for a link definition 1`] = ` -Array [ - Object { - "alt": "foo", - "ref": "", - "type": "image", - "url": "", - }, - Object { - "text": ": bar", - "type": "text", - }, -] -`; - -exports[`Images escaped square brackets in the alt text 1`] = ` -Array [ - Object { - "alt": "hello \\\\[world\\\\]", - "ref": "", - "type": "image", - "url": "foo.png", - }, -] -`; - -exports[`Images inline url 1`] = ` -Array [ - Object { - "alt": "", - "ref": "", - "type": "image", - "url": "foo.png", - }, -] -`; - -exports[`Images inline url 2`] = ` -Array [ - Object { - "alt": "title", - "ref": "", - "type": "image", - "url": "foo.png", - }, -] -`; - -exports[`Images inside a link block 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "alt": "", - "ref": "", - "type": "image", - "url": "toc.png", - }, - ], - "ref": "", - "type": "link", - "url": "#toc", - }, -] -`; - -exports[`Images inside a link block 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "alt": "Foo Bar", - "ref": "", - "type": "image", - "url": "foo.png", - }, - ], - "ref": "", - "type": "link", - "url": "#foo", - }, -] -`; - -exports[`Images inside a link block 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "alt": "Example", - "ref": "", - "type": "image", - "url": "", - }, - ], - "ref": "", - "type": "link", - "url": "#example", - }, -] -`; - -exports[`Images link reference 1`] = ` -Array [ - Object { - "alt": "", - "ref": "foo", - "type": "image", - "url": "", - }, -] -`; - -exports[`Images link reference 2`] = ` -Array [ - Object { - "alt": "Foo Bar", - "ref": "", - "type": "image", - "url": "", - }, -] -`; - -exports[`Images markdown in the alt text 1`] = ` -Array [ - Object { - "alt": "# foo _bar_ ![baz", - "ref": "", - "type": "image", - "url": "", - }, - Object { - "text": "]", - "type": "text", - }, -] -`; - -exports[`Italic must be closed with same style 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "Hello world", - "type": "text", - }, - Object { - "block": Array [], - "style": "*", - "type": "italic", - }, - ], - "style": "_", - "type": "italic", - }, -] -`; - -exports[`Italic star syntax 1`] = ` -Array [ - Object { - "text": "I ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "like", - "type": "text", - }, - ], - "style": "*", - "type": "italic", - }, - Object { - "text": " tiny libraries", - "type": "text", - }, -] -`; - -exports[`Italic underline syntax 1`] = ` -Array [ - Object { - "text": "I ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "like", - "type": "text", - }, - ], - "style": "_", - "type": "italic", - }, - Object { - "text": " tiny libraries", - "type": "text", - }, -] -`; - -exports[`Italic wrapped in bold 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "tiny", - "type": "text", - }, - ], - "style": "*", - "type": "italic", - }, - Object { - "text": " libraries", - "type": "text", - }, - ], - "style": "__", - "type": "bold", - }, -] -`; - -exports[`Italic wrapped in bold 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "tiny", - "type": "text", - }, - ], - "style": "*", - "type": "italic", - }, - Object { - "text": " libraries", - "type": "text", - }, - ], - "style": "**", - "type": "bold", - }, -] -`; - -exports[`Italic wrapped in bold 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "tiny", - "type": "text", - }, - ], - "style": "_", - "type": "italic", - }, - Object { - "text": " libraries", - "type": "text", - }, - ], - "style": "__", - "type": "bold", - }, -] -`; - -exports[`Link definitions may contain markdown syntax 1`] = ` -Array [ - Object { - "key": "__proto__", - "type": "linkDef", - "url": "https://github.com/aleclarson/markdown-ast", - }, -] -`; - -exports[`Link definitions must come first on their line 1`] = ` -Array [ - Object { - "key": "foo", - "type": "linkDef", - "url": "https://github.com/aleclarson/markdown-ast", - }, -] -`; - -exports[`Links auto-close any nested blocks 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "unclosed ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "bold text", - "type": "text", - }, - ], - "style": "**", - "type": "bold", - }, - ], - "ref": "", - "type": "link", - "url": "#foo", - }, -] -`; - -exports[`Links auto-close any nested blocks 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "unclosed ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "italic text", - "type": "text", - }, - ], - "style": "_", - "type": "italic", - }, - ], - "ref": "", - "type": "link", - "url": "#foo", - }, -] -`; - -exports[`Links auto-close any nested blocks 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "unclosed ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "link", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": " text](#foo", - }, - ], - "ref": "", - "type": "link", - "url": "", - }, -] -`; - -exports[`Links auto-close any nested blocks 4`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "unclosed ", - "type": "text", - }, - Object { - "alt": "link text", - "ref": "", - "type": "image", - "url": "#foo", - }, - ], - "ref": "", - "type": "link", - "url": "", - }, -] -`; - -exports[`Links hash url 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "Example", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": "#example", - }, -] -`; - -exports[`Links inline url 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "Hello world", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": "https://github.com/aleclarson/markdown-ast", - }, -] -`; - -exports[`Links inside an

1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "this", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": "", - }, - ], - "rank": 1, - "type": "title", - }, -] -`; - -exports[`Links inside an

2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "this", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": "#foo", - }, - ], - "rank": 1, - "type": "title", - }, -] -`; - -exports[`Links inside an

3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "this", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": "https://github.com/aleclarson/markdown-ast", - }, - ], - "rank": 1, - "type": "title", - }, -] -`; - -exports[`Links link reference 1`] = ` -Array [ - Object { - "text": "Hello ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "GitHub", - "type": "text", - }, - ], - "ref": "", - "type": "link", - "url": "", - }, - Object { - "text": "!", - "type": "text", - }, -] -`; - -exports[`Links link reference 2`] = ` -Array [ - Object { - "text": "Hello ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "GitHub", - "type": "text", - }, - ], - "ref": "gh", - "type": "link", - "url": "", - }, - Object { - "text": "!", - "type": "text", - }, -] -`; - -exports[`Lists
    1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "Ordered", - "type": "text", - }, - ], - "bullet": "1.", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Lists", - "type": "text", - }, - ], - "bullet": "2.", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Numbers are ignored", - "type": "text", - }, - ], - "bullet": "4.", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists
      2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "Ordered", - "type": "text", - }, - ], - "bullet": "1)", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Lists", - "type": "text", - }, - ], - "bullet": "2)", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Numbers are ignored", - "type": "text", - }, - ], - "bullet": "4)", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists
        1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists
          2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "+", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "+", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists
            3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists
              with mixed bullet styles 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "+", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Three", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists indented
                1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "1.", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested one", - "type": "text", - }, - ], - "bullet": "1.", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested two", - "type": "text", - }, - ], - "bullet": "2.", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "2.", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists indented
                  2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "1)", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested one", - "type": "text", - }, - ], - "bullet": "1)", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested two", - "type": "text", - }, - ], - "bullet": "2)", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "2)", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists indented
                    3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "1.", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested one", - "type": "text", - }, - ], - "bullet": "1)", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested two", - "type": "text", - }, - ], - "bullet": "2)", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "2.", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists indented
                      4`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "1)", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested one", - "type": "text", - }, - ], - "bullet": "1.", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested two", - "type": "text", - }, - ], - "bullet": "2.", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "2)", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists indented
                        1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "+", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested one", - "type": "text", - }, - ], - "bullet": "*", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Nested two", - "type": "text", - }, - ], - "bullet": "*", - "indent": " ", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Lists spaced out
                          1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "One", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "block": Array [ - Object { - "text": "Two", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "block": Array [ - Object { - "text": "Three", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Multi-line list items closed by
                          1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo -bar", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": " baz", - "type": "text", - }, -] -`; - -exports[`Multi-line list items closed by next
                        • 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo -bar", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Multi-line list items indentation styles 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo -bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Multi-line list items indentation styles 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo -bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Multi-line list items indentation styles 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo -bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Multi-line list items indentation styles 4`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo -bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Multi-line list items mixed indentation 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "a1 -a2 -a3 -a4 -a5", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, -] -`; - -exports[`Multi-line list items with indented bullet 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": " ", - "type": "list", - }, -] -`; - -exports[`Multi-line list items with indented bullet 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": " ", - "type": "list", - }, -] -`; - -exports[`Multi-line list items with indented bullet 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": " ", - "type": "list", - }, -] -`; - -exports[`Multi-line list items with indented bullet 4`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": " ", - "type": "list", - }, -] -`; - -exports[`Multi-line list items with indented bullet 5`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": " ", - "type": "list", - }, -] -`; - -exports[`Multi-line list items with indented bullet 6`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "bullet": "*", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "bar -baz", - "type": "text", - }, - ], - "bullet": "*", - "indent": " ", - "type": "list", - }, -] -`; - -exports[`Quotes empty line 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "To be or not to be", - "type": "text", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": "That is the question", - "type": "text", - }, - ], - "type": "quote", - }, -] -`; - -exports[`Quotes multi-line 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "in -the -quote", - "type": "text", - }, - ], - "type": "quote", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": "and outside", - "type": "text", - }, -] -`; - -exports[`Quotes multi-line 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "in -the -quote", - "type": "text", - }, - ], - "type": "quote", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": "and outside", - "type": "text", - }, -] -`; - -exports[`Quotes nested 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "block": Array [ - Object { - "text": "To be or not to be -That is the question", - "type": "text", - }, - ], - "type": "quote", - }, - ], - "type": "quote", - }, -] -`; - -exports[`Quotes with bulleted list 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "block": Array [ - Object { - "text": "line 1", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "line 2", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "line 3", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - ], - "type": "quote", - }, - Object { - "text": " -", - "type": "text", - }, -] -`; - -exports[`Quotes with bulleted list 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "block": Array [ - Object { - "text": "line 1", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "line 2", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "line 3.1 -line 3.2", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - ], - "type": "quote", - }, - Object { - "text": " -", - "type": "text", - }, -] -`; - -exports[`Quotes with bulleted list 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "block": Array [ - Object { - "text": "line 1", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "line 2", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "line 3.1", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - ], - "type": "quote", - }, - Object { - "text": " - -", - "type": "break", - }, - Object { - "text": "after", - "type": "text", - }, -] -`; - -exports[`Quotes with text 1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "To be or not to be", - "type": "text", - }, - ], - "type": "quote", - }, -] -`; - -exports[`Strike-through using squiggles 1`] = ` -Array [ - Object { - "text": "I like ", - "type": "text", - }, - Object { - "block": Array [ - Object { - "text": "tiny", - "type": "text", - }, - ], - "style": "~~", - "type": "strike", - }, - Object { - "text": " libraries", - "type": "text", - }, -] -`; - -exports[`Titles

                          1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like tiny libraries", - "type": "text", - }, - ], - "rank": 1, - "type": "title", - }, -] -`; - -exports[`Titles

                          2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like tiny libraries", - "type": "text", - }, - ], - "rank": 1, - "type": "title", - }, -] -`; - -exports[`Titles

                          1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like tiny libraries", - "type": "text", - }, - ], - "rank": 2, - "type": "title", - }, -] -`; - -exports[`Titles

                          2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like tiny libraries", - "type": "text", - }, - ], - "rank": 2, - "type": "title", - }, -] -`; - -exports[`Titles

                          thru

                          1`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like tiny libraries", - "type": "text", - }, - ], - "rank": 3, - "type": "title", - }, -] -`; - -exports[`Titles

                          thru

                          2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like tiny libraries", - "type": "text", - }, - ], - "rank": 4, - "type": "title", - }, -] -`; - -exports[`Titles

                          thru

                          3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like tiny libraries", - "type": "text", - }, - ], - "rank": 5, - "type": "title", - }, -] -`; - -exports[`Titles

                          thru

                          4`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "I like tiny libraries", - "type": "text", - }, - ], - "rank": 6, - "type": "title", - }, -] -`; - -exports[`Titles empty title 1`] = ` -Array [ - Object { - "block": Array [], - "rank": 1, - "type": "title", - }, -] -`; - -exports[`Titles empty title 2`] = ` -Array [ - Object { - "block": Array [], - "rank": 2, - "type": "title", - }, -] -`; - -exports[`Titles empty title 3`] = ` -Array [ - Object { - "block": Array [], - "rank": 3, - "type": "title", - }, -] -`; - -exports[`Titles empty title 4`] = ` -Array [ - Object { - "block": Array [], - "rank": 4, - "type": "title", - }, -] -`; - -exports[`preserves EOF newline 1`] = ` -Array [ - Object { - "text": "foo -", - "type": "text", - }, -] -`; - -exports[`preserves EOF newline 2`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "a", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - Object { - "block": Array [ - Object { - "text": "b", - "type": "text", - }, - ], - "bullet": "-", - "indent": "", - "type": "list", - }, - Object { - "text": " -", - "type": "text", - }, -] -`; - -exports[`preserves EOF newline 3`] = ` -Array [ - Object { - "block": Array [ - Object { - "text": "foo", - "type": "text", - }, - ], - "rank": 1, - "type": "title", - }, - Object { - "text": " -", - "type": "text", - }, -] -`; - -exports[`preserves EOF newline 4`] = ` -Array [ - Object { - "code": "foo", - "indent": "", - "syntax": "", - "type": "codeBlock", - }, - Object { - "text": " -", - "type": "text", - }, -] -`; diff --git a/spec/index.spec.js b/spec/index.spec.js deleted file mode 100644 index c8e2e10..0000000 --- a/spec/index.spec.js +++ /dev/null @@ -1,429 +0,0 @@ -const md = require('..') - -test('preserves EOF newline', () => { - expect(md('foo\n')).toMatchSnapshot() - // List - expect(md('- a\n- b\n')).toMatchSnapshot() - // Title - expect(md('# foo\n')).toMatchSnapshot() - // Code block - expect(md('```\nfoo\n```\n')).toMatchSnapshot() -}) - -describe('Bold', () => { - test('star syntax', () => { - expect(md('I **like** tiny libraries')).toMatchSnapshot() - }) - - test('underline syntax', () => { - expect(md('I __like__ tiny libraries')).toMatchSnapshot() - }) - - test('wrapped in italic', () => { - expect(md('_I like **tiny** libraries_')).toMatchSnapshot() - expect(md('*I like **tiny** libraries*')).toMatchSnapshot() - expect(md('_I like __tiny__ libraries_')).toMatchSnapshot() - }) - - test('must be closed with same style', () => { - expect(md('__Hello world**')).toMatchSnapshot() - }) -}) - -describe('Italic', () => { - test('star syntax', () => { - expect(md('I *like* tiny libraries')).toMatchSnapshot() - }) - - test('underline syntax', () => { - expect(md('I _like_ tiny libraries')).toMatchSnapshot() - }) - - test('wrapped in bold', () => { - expect(md('__I like *tiny* libraries__')).toMatchSnapshot() - expect(md('**I like *tiny* libraries**')).toMatchSnapshot() - expect(md('__I like _tiny_ libraries__')).toMatchSnapshot() - }) - - test('must be closed with same style', () => { - expect(md('_Hello world*')).toMatchSnapshot() - }) -}) - -describe('Strike-through', () => { - test('using squiggles', () => { - expect(md('I like ~~tiny~~ libraries')).toMatchSnapshot() - }) -}) - -describe('Titles', () => { - test('

                          ', () => { - expect(md('# I like tiny libraries')).toMatchSnapshot() - expect(md('I like tiny libraries\n===')).toMatchSnapshot() - }) - - test('

                          ', () => { - expect(md('## I like tiny libraries')).toMatchSnapshot() - expect(md('I like tiny libraries\n---')).toMatchSnapshot() - }) - - test('

                          thru

                          ', () => { - expect(md('### I like tiny libraries')).toMatchSnapshot() - expect(md('#### I like tiny libraries')).toMatchSnapshot() - expect(md('##### I like tiny libraries')).toMatchSnapshot() - expect(md('###### I like tiny libraries')).toMatchSnapshot() - }) - - test('empty title', () => { - expect(md('#')).toMatchSnapshot() - expect(md('## ')).toMatchSnapshot() - expect(md('###\t')).toMatchSnapshot() - expect(md('#### \t \t')).toMatchSnapshot() - }) -}) - -describe('Links', () => { - test('inline url', () => { - let link = 'https://github.com/aleclarson/markdown-ast' - expect(md(`[Hello world](${link})`)).toMatchSnapshot() - }) - - test('hash url', () => { - expect(md('[Example](#example)')).toMatchSnapshot() - }) - - test('link reference', () => { - expect(md('Hello [GitHub]!')).toMatchSnapshot() - expect(md('Hello [GitHub][gh]!')).toMatchSnapshot() - }) - - test('inside an

                          ', () => { - let link = 'https://github.com/aleclarson/markdown-ast' - expect(md(`# I like [this]`)).toMatchSnapshot() - expect(md(`# I like [this](#foo)`)).toMatchSnapshot() - expect(md(`# I like [this](${link})`)).toMatchSnapshot() - }) - - test('auto-close any nested blocks', () => { - expect(md('[unclosed **bold text](#foo)')).toMatchSnapshot() - expect(md('[unclosed _italic text](#foo)')).toMatchSnapshot() - - // The nested link takes over by looking ahead for ")" - expect(md('[unclosed [link]( text](#foo)')).toMatchSnapshot() - - // The nested image takes over by looking ahead for "]" - expect(md('[unclosed ![link text](#foo)')).toMatchSnapshot() - }) -}) - -describe('Link definitions', () => { - let link = 'https://github.com/aleclarson/markdown-ast' - test('must come first on their line', () => { - expect(md(`[foo]: ${link}`)).toMatchSnapshot() - }) - test('may contain markdown syntax', () => { - expect(md(`[__proto__]: ${link}`)).toMatchSnapshot() - }) -}) - -describe('Images', () => { - test('inline url', () => { - expect(md('![](foo.png)')).toMatchSnapshot() - expect(md('![title](foo.png)')).toMatchSnapshot() - }) - - test('link reference', () => { - expect(md('![][foo]')).toMatchSnapshot() - expect(md('![Foo Bar]')).toMatchSnapshot() - }) - - test('inside a link block', () => { - expect(md('[![](toc.png)](#toc)')).toMatchSnapshot() - expect(md('[![Foo Bar](foo.png)](#foo)')).toMatchSnapshot() - expect(md('[![Example]](#example)')).toMatchSnapshot() - }) - - test('cannot be confused for a link definition', () => { - // The ": bar" part is interpreted as plain text. - expect(md('![foo]: bar')).toMatchSnapshot() - }) - - test('markdown in the alt text', () => { - expect(md('![# foo _bar_ ![baz]]')).toMatchSnapshot() - }) - - test('escaped square brackets in the alt text', () => { - expect(md('![hello \\[world\\]](foo.png)')).toMatchSnapshot() - }) -}) - -describe('Lists', () => { - test('
                            ', () => { - expect(md('- One\n- Two')).toMatchSnapshot() - expect(md('+ One\n+ Two')).toMatchSnapshot() - expect(md('* One\n* Two')).toMatchSnapshot() - }) - - test('
                              with mixed bullet styles', () => { - expect(md('+ One\n* Two\n- Three')).toMatchSnapshot() - }) - - test('indented
                                ', () => { - expect(md('+ One\n\t* Nested one\n\t* Nested two\n- Two')).toMatchSnapshot() - }) - - test('spaced out
                                  ', () => { - expect(md('* One\n\n* Two\n\n* Three')).toMatchSnapshot() - }) - - test('
                                    ', () => { - expect(md('1. Ordered\n2. Lists\n4. Numbers are ignored')).toMatchSnapshot() - expect(md('1) Ordered\n2) Lists\n4) Numbers are ignored')).toMatchSnapshot() - }) - - test('indented
                                      ', () => { - expect( - md('1. One\n\t1. Nested one\n\t2. Nested two\n2. Two') - ).toMatchSnapshot() - expect( - md('1) One\n\t1) Nested one\n\t2) Nested two\n2) Two') - ).toMatchSnapshot() - expect( - md('1. One\n\t1) Nested one\n\t2) Nested two\n2. Two') - ).toMatchSnapshot() - expect( - md('1) One\n\t1. Nested one\n\t2. Nested two\n2) Two') - ).toMatchSnapshot() - }) -}) - -describe('Multi-line list items', () => { - test('indentation styles', () => { - expect(md('* foo\nbar\nbaz')).toMatchSnapshot() - expect(md('* foo\n\tbar\n\tbaz')).toMatchSnapshot() - expect(md('* foo\n bar\n baz')).toMatchSnapshot() - expect(md('* foo\n bar\n baz')).toMatchSnapshot() - }) - - test('mixed indentation', () => { - expect(md('* a1\na2\n a3\n a4\n\ta5')).toMatchSnapshot() - }) - - test('with indented bullet', () => { - expect(md('* foo\n\t* bar\nbaz')).toMatchSnapshot() - expect(md('* foo\n\t* bar\n\tbaz')).toMatchSnapshot() - - expect(md('* foo\n * bar\nbaz')).toMatchSnapshot() - expect(md('* foo\n * bar\n baz')).toMatchSnapshot() - - expect(md('* foo\n * bar\nbaz')).toMatchSnapshot() - expect(md('* foo\n * bar\n baz')).toMatchSnapshot() - }) - - test('closed by next
                                    1. ', () => { - expect(md('* foo\nbar\n* baz')).toMatchSnapshot() - }) - - test('closed by
                                      ', () => { - expect(md('* foo\n bar\n\n baz')).toMatchSnapshot() - }) -}) - -describe('Code spans', () => { - test('in between text nodes', () => { - expect(md('Use `foo(bar, true)` to win bigly.')).toMatchSnapshot() - }) - - test('right before newline in multi-line list item', () => { - expect(md('- Use `foo(bar, true)`\nto win bigly.')).toMatchSnapshot() - }) - - test('right after newline in multi-line list item', () => { - expect(md('- Use\n`foo(bar, true)` to win bigly.')).toMatchSnapshot() - }) -}) - -describe('Code blocks', () => { - describe('fenced', () => { - test('with triple backticks', () => { - expect(md('```\nvar a = 1\n```')).toMatchSnapshot() - }) - - test('with explicit syntax', () => { - expect(md('```js\nvar a = 1\n```')).toMatchSnapshot() - }) - - test('empty', () => { - expect(md('```\n```')).toMatchSnapshot() - }) - }) - - describe('indented', () => { - test('with tabs', () => { - expect(md('\tvar a = 1\n\tvar b = 2')).toMatchSnapshot() - }) - - test('with spaces', () => { - expect(md(' var a = 1\n var b = 2')).toMatchSnapshot() - }) - - test('with mixed tabs/spaces', () => { - expect(md('\tfoo\n foo')).toMatchSnapshot() - - // With trailing newline: - expect(md(' foo\n\tfoo\n foo\n')).toMatchSnapshot() - }) - - test('must be first on its line', () => { - expect(md('| var a = 1')).toMatchSnapshot() - }) - - test('empty with text immediately after', () => { - expect(md(' \nfoo')).toMatchSnapshot() - }) - }) -}) - -describe('Quotes', () => { - test('with text', () => { - expect(md('> To be or not to be')).toMatchSnapshot() - }) - - test('nested', () => { - expect( - md('> > To be or not to be\n> That is the question') - ).toMatchSnapshot() - }) - - test('empty line', () => { - expect( - md('> To be or not to be\n>\n> That is the question') - ).toMatchSnapshot() - }) - - test('multi-line', () => { - // A double newline is required to exit the quote. - expect(md('> in\n> the\n> quote\n\nand outside')).toMatchSnapshot() - - // The repeated > brackets are optional. - expect(md('> in\nthe\nquote\n\nand outside')).toMatchSnapshot() - }) - - test('with bulleted list', () => { - expect(md('> - line 1\n> - line 2\n> - line 3\n')).toMatchSnapshot() - - // With an EOF newline: - expect( - md('> - line 1\n> - line 2\n> - line 3.1\nline 3.2\n') - ).toMatchSnapshot() - - // With a trailing break node: - expect( - md('> - line 1\n> - line 2\n> - line 3.1\n\nafter') - ).toMatchSnapshot() - }) -}) - -describe('Breaks', () => { - test('using double \\n', () => { - expect(md('Something with\n\na line break')).toMatchSnapshot() - }) - - test('using double \\r\\n', () => { - expect(md('Something with\r\n\r\na line break')).toMatchSnapshot() - }) - - test('using double space + \\n', () => { - expect(md('Something with \na line break')).toMatchSnapshot() - }) -}) - -describe('Borders', () => { - test('using tight-packed dashes', () => { - // Note the extra newline after "foo" - expect(md('foo\n\n---\nbar')).toMatchSnapshot() - expect(md('foo\n\n----\nbar')).toMatchSnapshot() - }) - - test('using spaced-out dashes', () => { - expect(md('foo\n- - -\nbar')).toMatchSnapshot() - expect(md('foo\n-\t-\t-\nbar')).toMatchSnapshot() - expect(md('foo\n- \t - \t -\nbar')).toMatchSnapshot() - }) - - test('alternate symbols', () => { - // Asterisks - expect(md('foo\n***\n\nbar')).toMatchSnapshot() - expect(md('foo\n* * *\n\nbar')).toMatchSnapshot() - - // Underscores - expect(md('foo\n___\nbar')).toMatchSnapshot() - expect(md('foo\n_ _ _\nbar')).toMatchSnapshot() - }) - - test('inside a quote', () => { - expect(md('> ---\nbar')).toMatchSnapshot() - expect(md('> * * *\nbar')).toMatchSnapshot() - }) -}) - -describe('Edge cases', () => { - test('unclosed italic', () => { - expect(md('*')).toMatchSnapshot() - expect(md('_')).toMatchSnapshot() - expect(md('*foo')).toMatchSnapshot() - expect(md('_foo')).toMatchSnapshot() - }) - - test('unclosed bold', () => { - expect(md('**')).toMatchSnapshot() - expect(md('__')).toMatchSnapshot() - expect(md('**foo')).toMatchSnapshot() - expect(md('__foo')).toMatchSnapshot() - }) - - test('unclosed strike-through', () => { - expect(md('~~')).toMatchSnapshot() - expect(md('~~foo')).toMatchSnapshot() - }) - - test('unclosed code span', () => { - // The backtick becomes plain text. - expect(md('`')).toMatchSnapshot() - expect(md('`foo')).toMatchSnapshot() - }) - - test('unclosed code block', () => { - // The fence becomes plain text. - expect(md('```')).toMatchSnapshot() - expect(md('```\nfoo')).toMatchSnapshot() - }) - - test('unclosed link', () => { - expect(md('[')).toMatchSnapshot() - expect(md('[foo')).toMatchSnapshot() - expect(md('[foo](')).toMatchSnapshot() - expect(md('[foo](#bar')).toMatchSnapshot() - }) - - test('unclosed image', () => { - expect(md('![')).toMatchSnapshot() - expect(md('![](')).toMatchSnapshot() - expect(md('![foo')).toMatchSnapshot() - expect(md('![](foo')).toMatchSnapshot() - }) -}) - -describe('Escaped characters', () => { - test('escaped title', () => { - expect(md('\\# foo bar')).toMatchSnapshot() - }) - - test('escaped bold', () => { - expect(md('\\__foo_')).toMatchSnapshot() - }) - - test('escaped escape', () => { - expect(md('\\\\__foo_')).toMatchSnapshot() - }) -})