123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636 |
- (function() {
- var mode = CodeMirror.getMode({tabSize: 4}, "markdown");
- function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
- MT("plainText",
- "foo");
- // Code blocks using 4 spaces (regardless of CodeMirror.tabSize value)
- MT("codeBlocksUsing4Spaces",
- " [comment foo]");
- // Code blocks using 4 spaces with internal indentation
- MT("codeBlocksUsing4SpacesIndentation",
- " [comment bar]",
- " [comment hello]",
- " [comment world]",
- " [comment foo]",
- "bar");
- // Code blocks using 4 spaces with internal indentation
- MT("codeBlocksUsing4SpacesIndentation",
- " foo",
- " [comment bar]",
- " [comment hello]",
- " [comment world]");
- // Code blocks using 1 tab (regardless of CodeMirror.indentWithTabs value)
- MT("codeBlocksUsing1Tab",
- "\t[comment foo]");
- // Inline code using backticks
- MT("inlineCodeUsingBackticks",
- "foo [comment `bar`]");
- // Block code using single backtick (shouldn't work)
- MT("blockCodeSingleBacktick",
- "[comment `]",
- "foo",
- "[comment `]");
- // Unclosed backticks
- // Instead of simply marking as CODE, it would be nice to have an
- // incomplete flag for CODE, that is styled slightly different.
- MT("unclosedBackticks",
- "foo [comment `bar]");
- // Per documentation: "To include a literal backtick character within a
- // code span, you can use multiple backticks as the opening and closing
- // delimiters"
- MT("doubleBackticks",
- "[comment ``foo ` bar``]");
- // Tests based on Dingus
- // http://daringfireball.net/projects/markdown/dingus
- //
- // Multiple backticks within an inline code block
- MT("consecutiveBackticks",
- "[comment `foo```bar`]");
- // Multiple backticks within an inline code block with a second code block
- MT("consecutiveBackticks",
- "[comment `foo```bar`] hello [comment `world`]");
- // Unclosed with several different groups of backticks
- MT("unclosedBackticks",
- "[comment ``foo ``` bar` hello]");
- // Closed with several different groups of backticks
- MT("closedBackticks",
- "[comment ``foo ``` bar` hello``] world");
- // atx headers
- // http://daringfireball.net/projects/markdown/syntax#header
- MT("atxH1",
- "[header # foo]");
- MT("atxH2",
- "[header ## foo]");
- MT("atxH3",
- "[header ### foo]");
- MT("atxH4",
- "[header #### foo]");
- MT("atxH5",
- "[header ##### foo]");
- MT("atxH6",
- "[header ###### foo]");
- // H6 - 7x '#' should still be H6, per Dingus
- // http://daringfireball.net/projects/markdown/dingus
- MT("atxH6NotH7",
- "[header ####### foo]");
- // Setext headers - H1, H2
- // Per documentation, "Any number of underlining =’s or -’s will work."
- // http://daringfireball.net/projects/markdown/syntax#header
- // Ideally, the text would be marked as `header` as well, but this is
- // not really feasible at the moment. So, instead, we're testing against
- // what works today, to avoid any regressions.
- //
- // Check if single underlining = works
- MT("setextH1",
- "foo",
- "[header =]");
- // Check if 3+ ='s work
- MT("setextH1",
- "foo",
- "[header ===]");
- // Check if single underlining - works
- MT("setextH2",
- "foo",
- "[header -]");
- // Check if 3+ -'s work
- MT("setextH2",
- "foo",
- "[header ---]");
- // Single-line blockquote with trailing space
- MT("blockquoteSpace",
- "[atom > foo]");
- // Single-line blockquote
- MT("blockquoteNoSpace",
- "[atom >foo]");
- // No blank line before blockquote
- MT("blockquoteNoBlankLine",
- "foo",
- "[atom > bar]");
- // Nested blockquote
- MT("blockquoteSpace",
- "[atom > foo]",
- "[number > > foo]",
- "[atom > > > foo]");
- // Single-line blockquote followed by normal paragraph
- MT("blockquoteThenParagraph",
- "[atom >foo]",
- "",
- "bar");
- // Multi-line blockquote (lazy mode)
- MT("multiBlockquoteLazy",
- "[atom >foo]",
- "[atom bar]");
- // Multi-line blockquote followed by normal paragraph (lazy mode)
- MT("multiBlockquoteLazyThenParagraph",
- "[atom >foo]",
- "[atom bar]",
- "",
- "hello");
- // Multi-line blockquote (non-lazy mode)
- MT("multiBlockquote",
- "[atom >foo]",
- "[atom >bar]");
- // Multi-line blockquote followed by normal paragraph (non-lazy mode)
- MT("multiBlockquoteThenParagraph",
- "[atom >foo]",
- "[atom >bar]",
- "",
- "hello");
- // Check list types
- MT("listAsterisk",
- "foo",
- "bar",
- "",
- "[variable-2 * foo]",
- "[variable-2 * bar]");
- MT("listPlus",
- "foo",
- "bar",
- "",
- "[variable-2 + foo]",
- "[variable-2 + bar]");
- MT("listDash",
- "foo",
- "bar",
- "",
- "[variable-2 - foo]",
- "[variable-2 - bar]");
- MT("listNumber",
- "foo",
- "bar",
- "",
- "[variable-2 1. foo]",
- "[variable-2 2. bar]");
- // Lists require a preceding blank line (per Dingus)
- MT("listBogus",
- "foo",
- "1. bar",
- "2. hello");
- // Formatting in lists (*)
- MT("listAsteriskFormatting",
- "[variable-2 * ][variable-2&em *foo*][variable-2 bar]",
- "[variable-2 * ][variable-2&strong **foo**][variable-2 bar]",
- "[variable-2 * ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",
- "[variable-2 * ][variable-2&comment `foo`][variable-2 bar]");
- // Formatting in lists (+)
- MT("listPlusFormatting",
- "[variable-2 + ][variable-2&em *foo*][variable-2 bar]",
- "[variable-2 + ][variable-2&strong **foo**][variable-2 bar]",
- "[variable-2 + ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",
- "[variable-2 + ][variable-2&comment `foo`][variable-2 bar]");
- // Formatting in lists (-)
- MT("listDashFormatting",
- "[variable-2 - ][variable-2&em *foo*][variable-2 bar]",
- "[variable-2 - ][variable-2&strong **foo**][variable-2 bar]",
- "[variable-2 - ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",
- "[variable-2 - ][variable-2&comment `foo`][variable-2 bar]");
- // Formatting in lists (1.)
- MT("listNumberFormatting",
- "[variable-2 1. ][variable-2&em *foo*][variable-2 bar]",
- "[variable-2 2. ][variable-2&strong **foo**][variable-2 bar]",
- "[variable-2 3. ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",
- "[variable-2 4. ][variable-2&comment `foo`][variable-2 bar]");
- // Paragraph lists
- MT("listParagraph",
- "[variable-2 * foo]",
- "",
- "[variable-2 * bar]");
- // Multi-paragraph lists
- //
- // 4 spaces
- MT("listMultiParagraph",
- "[variable-2 * foo]",
- "",
- "[variable-2 * bar]",
- "",
- " [variable-2 hello]");
- // 4 spaces, extra blank lines (should still be list, per Dingus)
- MT("listMultiParagraphExtra",
- "[variable-2 * foo]",
- "",
- "[variable-2 * bar]",
- "",
- "",
- " [variable-2 hello]");
- // 4 spaces, plus 1 space (should still be list, per Dingus)
- MT("listMultiParagraphExtraSpace",
- "[variable-2 * foo]",
- "",
- "[variable-2 * bar]",
- "",
- " [variable-2 hello]",
- "",
- " [variable-2 world]");
- // 1 tab
- MT("listTab",
- "[variable-2 * foo]",
- "",
- "[variable-2 * bar]",
- "",
- "\t[variable-2 hello]");
- // No indent
- MT("listNoIndent",
- "[variable-2 * foo]",
- "",
- "[variable-2 * bar]",
- "",
- "hello");
- // Blockquote
- MT("blockquote",
- "[variable-2 * foo]",
- "",
- "[variable-2 * bar]",
- "",
- " [variable-2&atom > hello]");
- // Code block
- MT("blockquoteCode",
- "[variable-2 * foo]",
- "",
- "[variable-2 * bar]",
- "",
- " [comment > hello]",
- "",
- " [variable-2 world]");
- // Code block followed by text
- MT("blockquoteCodeText",
- "[variable-2 * foo]",
- "",
- " [variable-2 bar]",
- "",
- " [comment hello]",
- "",
- " [variable-2 world]");
- // Nested list
- MT("listAsteriskNested",
- "[variable-2 * foo]",
- "",
- " [variable-3 * bar]");
- MT("listPlusNested",
- "[variable-2 + foo]",
- "",
- " [variable-3 + bar]");
- MT("listDashNested",
- "[variable-2 - foo]",
- "",
- " [variable-3 - bar]");
- MT("listNumberNested",
- "[variable-2 1. foo]",
- "",
- " [variable-3 2. bar]");
- MT("listMixed",
- "[variable-2 * foo]",
- "",
- " [variable-3 + bar]",
- "",
- " [keyword - hello]",
- "",
- " [variable-2 1. world]");
- MT("listBlockquote",
- "[variable-2 * foo]",
- "",
- " [variable-3 + bar]",
- "",
- " [atom&variable-3 > hello]");
- MT("listCode",
- "[variable-2 * foo]",
- "",
- " [variable-3 + bar]",
- "",
- " [comment hello]");
- // Code with internal indentation
- MT("listCodeIndentation",
- "[variable-2 * foo]",
- "",
- " [comment bar]",
- " [comment hello]",
- " [comment world]",
- " [comment foo]",
- " [variable-2 bar]");
- // List nesting edge cases
- MT("listNested",
- "[variable-2 * foo]",
- "",
- " [variable-3 * bar]",
- "",
- " [variable-2 hello]"
- );
- MT("listNested",
- "[variable-2 * foo]",
- "",
- " [variable-3 * bar]",
- "",
- " [variable-3 * foo]"
- );
- // Code followed by text
- MT("listCodeText",
- "[variable-2 * foo]",
- "",
- " [comment bar]",
- "",
- "hello");
- // Following tests directly from official Markdown documentation
- // http://daringfireball.net/projects/markdown/syntax#hr
- MT("hrSpace",
- "[hr * * *]");
- MT("hr",
- "[hr ***]");
- MT("hrLong",
- "[hr *****]");
- MT("hrSpaceDash",
- "[hr - - -]");
- MT("hrDashLong",
- "[hr ---------------------------------------]");
- // Inline link with title
- MT("linkTitle",
- "[link [[foo]]][string (http://example.com/ \"bar\")] hello");
- // Inline link without title
- MT("linkNoTitle",
- "[link [[foo]]][string (http://example.com/)] bar");
- // Inline link with image
- MT("linkImage",
- "[link [[][tag ![[foo]]][string (http://example.com/)][link ]]][string (http://example.com/)] bar");
- // Inline link with Em
- MT("linkEm",
- "[link [[][link&em *foo*][link ]]][string (http://example.com/)] bar");
- // Inline link with Strong
- MT("linkStrong",
- "[link [[][link&strong **foo**][link ]]][string (http://example.com/)] bar");
- // Inline link with EmStrong
- MT("linkEmStrong",
- "[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string (http://example.com/)] bar");
- // Image with title
- MT("imageTitle",
- "[tag ![[foo]]][string (http://example.com/ \"bar\")] hello");
- // Image without title
- MT("imageNoTitle",
- "[tag ![[foo]]][string (http://example.com/)] bar");
- // Image with asterisks
- MT("imageAsterisks",
- "[tag ![[*foo*]]][string (http://example.com/)] bar");
- // Not a link. Should be normal text due to square brackets being used
- // regularly in text, especially in quoted material, and no space is allowed
- // between square brackets and parentheses (per Dingus).
- MT("notALink",
- "[[foo]] (bar)");
- // Reference-style links
- MT("linkReference",
- "[link [[foo]]][string [[bar]]] hello");
- // Reference-style links with Em
- MT("linkReferenceEm",
- "[link [[][link&em *foo*][link ]]][string [[bar]]] hello");
- // Reference-style links with Strong
- MT("linkReferenceStrong",
- "[link [[][link&strong **foo**][link ]]][string [[bar]]] hello");
- // Reference-style links with EmStrong
- MT("linkReferenceEmStrong",
- "[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string [[bar]]] hello");
- // Reference-style links with optional space separator (per docuentation)
- // "You can optionally use a space to separate the sets of brackets"
- MT("linkReferenceSpace",
- "[link [[foo]]] [string [[bar]]] hello");
- // Should only allow a single space ("...use *a* space...")
- MT("linkReferenceDoubleSpace",
- "[[foo]] [[bar]] hello");
- // Reference-style links with implicit link name
- MT("linkImplicit",
- "[link [[foo]]][string [[]]] hello");
- // @todo It would be nice if, at some point, the document was actually
- // checked to see if the referenced link exists
- // Link label, for reference-style links (taken from documentation)
- MT("labelNoTitle",
- "[link [[foo]]:] [string http://example.com/]");
- MT("labelIndented",
- " [link [[foo]]:] [string http://example.com/]");
- MT("labelSpaceTitle",
- "[link [[foo bar]]:] [string http://example.com/ \"hello\"]");
- MT("labelDoubleTitle",
- "[link [[foo bar]]:] [string http://example.com/ \"hello\"] \"world\"");
- MT("labelTitleDoubleQuotes",
- "[link [[foo]]:] [string http://example.com/ \"bar\"]");
- MT("labelTitleSingleQuotes",
- "[link [[foo]]:] [string http://example.com/ 'bar']");
- MT("labelTitleParenthese",
- "[link [[foo]]:] [string http://example.com/ (bar)]");
- MT("labelTitleInvalid",
- "[link [[foo]]:] [string http://example.com/] bar");
- MT("labelLinkAngleBrackets",
- "[link [[foo]]:] [string <http://example.com/> \"bar\"]");
- MT("labelTitleNextDoubleQuotes",
- "[link [[foo]]:] [string http://example.com/]",
- "[string \"bar\"] hello");
- MT("labelTitleNextSingleQuotes",
- "[link [[foo]]:] [string http://example.com/]",
- "[string 'bar'] hello");
- MT("labelTitleNextParenthese",
- "[link [[foo]]:] [string http://example.com/]",
- "[string (bar)] hello");
- MT("labelTitleNextMixed",
- "[link [[foo]]:] [string http://example.com/]",
- "(bar\" hello");
- MT("linkWeb",
- "[link <http://example.com/>] foo");
- MT("linkEmail",
- "[link <user@example.com>] foo");
- MT("emAsterisk",
- "[em *foo*] bar");
- MT("emUnderscore",
- "[em _foo_] bar");
- MT("emInWordAsterisk",
- "foo[em *bar*]hello");
- MT("emInWordUnderscore",
- "foo[em _bar_]hello");
- // Per documentation: "...surround an * or _ with spaces, it’ll be
- // treated as a literal asterisk or underscore."
- MT("emEscapedBySpaceIn",
- "foo [em _bar _ hello_] world");
- MT("emEscapedBySpaceOut",
- "foo _ bar[em _hello_]world");
- // Unclosed emphasis characters
- // Instead of simply marking as EM / STRONG, it would be nice to have an
- // incomplete flag for EM and STRONG, that is styled slightly different.
- MT("emIncompleteAsterisk",
- "foo [em *bar]");
- MT("emIncompleteUnderscore",
- "foo [em _bar]");
- MT("strongAsterisk",
- "[strong **foo**] bar");
- MT("strongUnderscore",
- "[strong __foo__] bar");
- MT("emStrongAsterisk",
- "[em *foo][em&strong **bar*][strong hello**] world");
- MT("emStrongUnderscore",
- "[em _foo][em&strong __bar_][strong hello__] world");
- // "...same character must be used to open and close an emphasis span.""
- MT("emStrongMixed",
- "[em _foo][em&strong **bar*hello__ world]");
- MT("emStrongMixed",
- "[em *foo][em&strong __bar_hello** world]");
- // These characters should be escaped:
- // \ backslash
- // ` backtick
- // * asterisk
- // _ underscore
- // {} curly braces
- // [] square brackets
- // () parentheses
- // # hash mark
- // + plus sign
- // - minus sign (hyphen)
- // . dot
- // ! exclamation mark
- MT("escapeBacktick",
- "foo \\`bar\\`");
- MT("doubleEscapeBacktick",
- "foo \\\\[comment `bar\\\\`]");
- MT("escapeAsterisk",
- "foo \\*bar\\*");
- MT("doubleEscapeAsterisk",
- "foo \\\\[em *bar\\\\*]");
- MT("escapeUnderscore",
- "foo \\_bar\\_");
- MT("doubleEscapeUnderscore",
- "foo \\\\[em _bar\\\\_]");
- MT("escapeHash",
- "\\# foo");
- MT("doubleEscapeHash",
- "\\\\# foo");
- // Tests to make sure GFM-specific things aren't getting through
- MT("taskList",
- "[variable-2 * [ ]] bar]");
- MT("fencedCodeBlocks",
- "[comment ```]",
- "foo",
- "[comment ```]");
- })();
|