Path: blob/master/web-gui/buildyourownbotnet/assets/js/codemirror/mode/markdown/test.js
1294 views
(function() {1var mode = CodeMirror.getMode({tabSize: 4}, "markdown");2function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }3var modeHighlightFormatting = CodeMirror.getMode({tabSize: 4}, {name: "markdown", highlightFormatting: true});4function FT(name) { test.mode(name, modeHighlightFormatting, Array.prototype.slice.call(arguments, 1)); }56FT("formatting_emAsterisk",7"[em&formatting&formatting-em *][em foo][em&formatting&formatting-em *]");89FT("formatting_emUnderscore",10"[em&formatting&formatting-em _][em foo][em&formatting&formatting-em _]");1112FT("formatting_strongAsterisk",13"[strong&formatting&formatting-strong **][strong foo][strong&formatting&formatting-strong **]");1415FT("formatting_strongUnderscore",16"[strong&formatting&formatting-strong __][strong foo][strong&formatting&formatting-strong __]");1718FT("formatting_codeBackticks",19"[comment&formatting&formatting-code `][comment foo][comment&formatting&formatting-code `]");2021FT("formatting_doubleBackticks",22"[comment&formatting&formatting-code ``][comment foo ` bar][comment&formatting&formatting-code ``]");2324FT("formatting_atxHeader",25"[header&header1&formatting&formatting-header&formatting-header1 #][header&header1 foo # bar ][header&header1&formatting&formatting-header&formatting-header1 #]");2627FT("formatting_setextHeader",28"foo",29"[header&header1&formatting&formatting-header&formatting-header1 =]");3031FT("formatting_blockquote",32"[quote"e-1&formatting&formatting-quote&formatting-quote-1 > ][quote"e-1 foo]");3334FT("formatting_list",35"[variable-2&formatting&formatting-list&formatting-list-ul - ][variable-2 foo]");36FT("formatting_list",37"[variable-2&formatting&formatting-list&formatting-list-ol 1. ][variable-2 foo]");3839FT("formatting_link",40"[link&formatting&formatting-link [][link foo][link&formatting&formatting-link ]]][string&formatting&formatting-link-string (][string http://example.com/][string&formatting&formatting-link-string )]");4142FT("formatting_linkReference",43"[link&formatting&formatting-link [][link foo][link&formatting&formatting-link ]]][string&formatting&formatting-link-string [][string bar][string&formatting&formatting-link-string ]]]",44"[link&formatting&formatting-link [][link bar][link&formatting&formatting-link ]]:] [string http://example.com/]");4546FT("formatting_linkWeb",47"[link&formatting&formatting-link <][link http://example.com/][link&formatting&formatting-link >]");4849FT("formatting_linkEmail",50"[link&formatting&formatting-link <][link [email protected]][link&formatting&formatting-link >]");5152FT("formatting_escape",53"[formatting&formatting-escape \\]*");5455MT("plainText",56"foo");5758// Don't style single trailing space59MT("trailingSpace1",60"foo ");6162// Two or more trailing spaces should be styled with line break character63MT("trailingSpace2",64"foo[trailing-space-a ][trailing-space-new-line ]");6566MT("trailingSpace3",67"foo[trailing-space-a ][trailing-space-b ][trailing-space-new-line ]");6869MT("trailingSpace4",70"foo[trailing-space-a ][trailing-space-b ][trailing-space-a ][trailing-space-new-line ]");7172// Code blocks using 4 spaces (regardless of CodeMirror.tabSize value)73MT("codeBlocksUsing4Spaces",74" [comment foo]");7576// Code blocks using 4 spaces with internal indentation77MT("codeBlocksUsing4SpacesIndentation",78" [comment bar]",79" [comment hello]",80" [comment world]",81" [comment foo]",82"bar");8384// Code blocks using 4 spaces with internal indentation85MT("codeBlocksUsing4SpacesIndentation",86" foo",87" [comment bar]",88" [comment hello]",89" [comment world]");9091// Code blocks using 1 tab (regardless of CodeMirror.indentWithTabs value)92MT("codeBlocksUsing1Tab",93"\t[comment foo]");9495// Inline code using backticks96MT("inlineCodeUsingBackticks",97"foo [comment `bar`]");9899// Block code using single backtick (shouldn't work)100MT("blockCodeSingleBacktick",101"[comment `]",102"foo",103"[comment `]");104105// Unclosed backticks106// Instead of simply marking as CODE, it would be nice to have an107// incomplete flag for CODE, that is styled slightly different.108MT("unclosedBackticks",109"foo [comment `bar]");110111// Per documentation: "To include a literal backtick character within a112// code span, you can use multiple backticks as the opening and closing113// delimiters"114MT("doubleBackticks",115"[comment ``foo ` bar``]");116117// Tests based on Dingus118// http://daringfireball.net/projects/markdown/dingus119//120// Multiple backticks within an inline code block121MT("consecutiveBackticks",122"[comment `foo```bar`]");123124// Multiple backticks within an inline code block with a second code block125MT("consecutiveBackticks",126"[comment `foo```bar`] hello [comment `world`]");127128// Unclosed with several different groups of backticks129MT("unclosedBackticks",130"[comment ``foo ``` bar` hello]");131132// Closed with several different groups of backticks133MT("closedBackticks",134"[comment ``foo ``` bar` hello``] world");135136// atx headers137// http://daringfireball.net/projects/markdown/syntax#header138139MT("atxH1",140"[header&header1 # foo]");141142MT("atxH2",143"[header&header2 ## foo]");144145MT("atxH3",146"[header&header3 ### foo]");147148MT("atxH4",149"[header&header4 #### foo]");150151MT("atxH5",152"[header&header5 ##### foo]");153154MT("atxH6",155"[header&header6 ###### foo]");156157// H6 - 7x '#' should still be H6, per Dingus158// http://daringfireball.net/projects/markdown/dingus159MT("atxH6NotH7",160"[header&header6 ####### foo]");161162// Inline styles should be parsed inside headers163MT("atxH1inline",164"[header&header1 # foo ][header&header1&em *bar*]");165166// Setext headers - H1, H2167// Per documentation, "Any number of underlining =’s or -’s will work."168// http://daringfireball.net/projects/markdown/syntax#header169// Ideally, the text would be marked as `header` as well, but this is170// not really feasible at the moment. So, instead, we're testing against171// what works today, to avoid any regressions.172//173// Check if single underlining = works174MT("setextH1",175"foo",176"[header&header1 =]");177178// Check if 3+ ='s work179MT("setextH1",180"foo",181"[header&header1 ===]");182183// Check if single underlining - works184MT("setextH2",185"foo",186"[header&header2 -]");187188// Check if 3+ -'s work189MT("setextH2",190"foo",191"[header&header2 ---]");192193// Single-line blockquote with trailing space194MT("blockquoteSpace",195"[quote"e-1 > foo]");196197// Single-line blockquote198MT("blockquoteNoSpace",199"[quote"e-1 >foo]");200201// No blank line before blockquote202MT("blockquoteNoBlankLine",203"foo",204"[quote"e-1 > bar]");205206// Nested blockquote207MT("blockquoteSpace",208"[quote"e-1 > foo]",209"[quote"e-1 >][quote"e-2 > foo]",210"[quote"e-1 >][quote"e-2 >][quote"e-3 > foo]");211212// Single-line blockquote followed by normal paragraph213MT("blockquoteThenParagraph",214"[quote"e-1 >foo]",215"",216"bar");217218// Multi-line blockquote (lazy mode)219MT("multiBlockquoteLazy",220"[quote"e-1 >foo]",221"[quote"e-1 bar]");222223// Multi-line blockquote followed by normal paragraph (lazy mode)224MT("multiBlockquoteLazyThenParagraph",225"[quote"e-1 >foo]",226"[quote"e-1 bar]",227"",228"hello");229230// Multi-line blockquote (non-lazy mode)231MT("multiBlockquote",232"[quote"e-1 >foo]",233"[quote"e-1 >bar]");234235// Multi-line blockquote followed by normal paragraph (non-lazy mode)236MT("multiBlockquoteThenParagraph",237"[quote"e-1 >foo]",238"[quote"e-1 >bar]",239"",240"hello");241242// Check list types243244MT("listAsterisk",245"foo",246"bar",247"",248"[variable-2 * foo]",249"[variable-2 * bar]");250251MT("listPlus",252"foo",253"bar",254"",255"[variable-2 + foo]",256"[variable-2 + bar]");257258MT("listDash",259"foo",260"bar",261"",262"[variable-2 - foo]",263"[variable-2 - bar]");264265MT("listNumber",266"foo",267"bar",268"",269"[variable-2 1. foo]",270"[variable-2 2. bar]");271272// Lists require a preceding blank line (per Dingus)273MT("listBogus",274"foo",275"1. bar",276"2. hello");277278// List after header279MT("listAfterHeader",280"[header&header1 # foo]",281"[variable-2 - bar]");282283// Formatting in lists (*)284MT("listAsteriskFormatting",285"[variable-2 * ][variable-2&em *foo*][variable-2 bar]",286"[variable-2 * ][variable-2&strong **foo**][variable-2 bar]",287"[variable-2 * ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",288"[variable-2 * ][variable-2&comment `foo`][variable-2 bar]");289290// Formatting in lists (+)291MT("listPlusFormatting",292"[variable-2 + ][variable-2&em *foo*][variable-2 bar]",293"[variable-2 + ][variable-2&strong **foo**][variable-2 bar]",294"[variable-2 + ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",295"[variable-2 + ][variable-2&comment `foo`][variable-2 bar]");296297// Formatting in lists (-)298MT("listDashFormatting",299"[variable-2 - ][variable-2&em *foo*][variable-2 bar]",300"[variable-2 - ][variable-2&strong **foo**][variable-2 bar]",301"[variable-2 - ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",302"[variable-2 - ][variable-2&comment `foo`][variable-2 bar]");303304// Formatting in lists (1.)305MT("listNumberFormatting",306"[variable-2 1. ][variable-2&em *foo*][variable-2 bar]",307"[variable-2 2. ][variable-2&strong **foo**][variable-2 bar]",308"[variable-2 3. ][variable-2&strong **][variable-2&em&strong *foo**][variable-2&em *][variable-2 bar]",309"[variable-2 4. ][variable-2&comment `foo`][variable-2 bar]");310311// Paragraph lists312MT("listParagraph",313"[variable-2 * foo]",314"",315"[variable-2 * bar]");316317// Multi-paragraph lists318//319// 4 spaces320MT("listMultiParagraph",321"[variable-2 * foo]",322"",323"[variable-2 * bar]",324"",325" [variable-2 hello]");326327// 4 spaces, extra blank lines (should still be list, per Dingus)328MT("listMultiParagraphExtra",329"[variable-2 * foo]",330"",331"[variable-2 * bar]",332"",333"",334" [variable-2 hello]");335336// 4 spaces, plus 1 space (should still be list, per Dingus)337MT("listMultiParagraphExtraSpace",338"[variable-2 * foo]",339"",340"[variable-2 * bar]",341"",342" [variable-2 hello]",343"",344" [variable-2 world]");345346// 1 tab347MT("listTab",348"[variable-2 * foo]",349"",350"[variable-2 * bar]",351"",352"\t[variable-2 hello]");353354// No indent355MT("listNoIndent",356"[variable-2 * foo]",357"",358"[variable-2 * bar]",359"",360"hello");361362// Blockquote363MT("blockquote",364"[variable-2 * foo]",365"",366"[variable-2 * bar]",367"",368" [variable-2"e"e-1 > hello]");369370// Code block371MT("blockquoteCode",372"[variable-2 * foo]",373"",374"[variable-2 * bar]",375"",376" [comment > hello]",377"",378" [variable-2 world]");379380// Code block followed by text381MT("blockquoteCodeText",382"[variable-2 * foo]",383"",384" [variable-2 bar]",385"",386" [comment hello]",387"",388" [variable-2 world]");389390// Nested list391392MT("listAsteriskNested",393"[variable-2 * foo]",394"",395" [variable-3 * bar]");396397MT("listPlusNested",398"[variable-2 + foo]",399"",400" [variable-3 + bar]");401402MT("listDashNested",403"[variable-2 - foo]",404"",405" [variable-3 - bar]");406407MT("listNumberNested",408"[variable-2 1. foo]",409"",410" [variable-3 2. bar]");411412MT("listMixed",413"[variable-2 * foo]",414"",415" [variable-3 + bar]",416"",417" [keyword - hello]",418"",419" [variable-2 1. world]");420421MT("listBlockquote",422"[variable-2 * foo]",423"",424" [variable-3 + bar]",425"",426" [quote"e-1&variable-3 > hello]");427428MT("listCode",429"[variable-2 * foo]",430"",431" [variable-3 + bar]",432"",433" [comment hello]");434435// Code with internal indentation436MT("listCodeIndentation",437"[variable-2 * foo]",438"",439" [comment bar]",440" [comment hello]",441" [comment world]",442" [comment foo]",443" [variable-2 bar]");444445// List nesting edge cases446MT("listNested",447"[variable-2 * foo]",448"",449" [variable-3 * bar]",450"",451" [variable-2 hello]"452);453MT("listNested",454"[variable-2 * foo]",455"",456" [variable-3 * bar]",457"",458" [variable-3 * foo]"459);460461// Code followed by text462MT("listCodeText",463"[variable-2 * foo]",464"",465" [comment bar]",466"",467"hello");468469// Following tests directly from official Markdown documentation470// http://daringfireball.net/projects/markdown/syntax#hr471472MT("hrSpace",473"[hr * * *]");474475MT("hr",476"[hr ***]");477478MT("hrLong",479"[hr *****]");480481MT("hrSpaceDash",482"[hr - - -]");483484MT("hrDashLong",485"[hr ---------------------------------------]");486487// Inline link with title488MT("linkTitle",489"[link [[foo]]][string (http://example.com/ \"bar\")] hello");490491// Inline link without title492MT("linkNoTitle",493"[link [[foo]]][string (http://example.com/)] bar");494495// Inline link with image496MT("linkImage",497"[link [[][tag ![[foo]]][string (http://example.com/)][link ]]][string (http://example.com/)] bar");498499// Inline link with Em500MT("linkEm",501"[link [[][link&em *foo*][link ]]][string (http://example.com/)] bar");502503// Inline link with Strong504MT("linkStrong",505"[link [[][link&strong **foo**][link ]]][string (http://example.com/)] bar");506507// Inline link with EmStrong508MT("linkEmStrong",509"[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string (http://example.com/)] bar");510511// Image with title512MT("imageTitle",513"[tag ![[foo]]][string (http://example.com/ \"bar\")] hello");514515// Image without title516MT("imageNoTitle",517"[tag ![[foo]]][string (http://example.com/)] bar");518519// Image with asterisks520MT("imageAsterisks",521"[tag ![[*foo*]]][string (http://example.com/)] bar");522523// Not a link. Should be normal text due to square brackets being used524// regularly in text, especially in quoted material, and no space is allowed525// between square brackets and parentheses (per Dingus).526MT("notALink",527"[[foo]] (bar)");528529// Reference-style links530MT("linkReference",531"[link [[foo]]][string [[bar]]] hello");532533// Reference-style links with Em534MT("linkReferenceEm",535"[link [[][link&em *foo*][link ]]][string [[bar]]] hello");536537// Reference-style links with Strong538MT("linkReferenceStrong",539"[link [[][link&strong **foo**][link ]]][string [[bar]]] hello");540541// Reference-style links with EmStrong542MT("linkReferenceEmStrong",543"[link [[][link&strong **][link&em&strong *foo**][link&em *][link ]]][string [[bar]]] hello");544545// Reference-style links with optional space separator (per docuentation)546// "You can optionally use a space to separate the sets of brackets"547MT("linkReferenceSpace",548"[link [[foo]]] [string [[bar]]] hello");549550// Should only allow a single space ("...use *a* space...")551MT("linkReferenceDoubleSpace",552"[[foo]] [[bar]] hello");553554// Reference-style links with implicit link name555MT("linkImplicit",556"[link [[foo]]][string [[]]] hello");557558// @todo It would be nice if, at some point, the document was actually559// checked to see if the referenced link exists560561// Link label, for reference-style links (taken from documentation)562563MT("labelNoTitle",564"[link [[foo]]:] [string http://example.com/]");565566MT("labelIndented",567" [link [[foo]]:] [string http://example.com/]");568569MT("labelSpaceTitle",570"[link [[foo bar]]:] [string http://example.com/ \"hello\"]");571572MT("labelDoubleTitle",573"[link [[foo bar]]:] [string http://example.com/ \"hello\"] \"world\"");574575MT("labelTitleDoubleQuotes",576"[link [[foo]]:] [string http://example.com/ \"bar\"]");577578MT("labelTitleSingleQuotes",579"[link [[foo]]:] [string http://example.com/ 'bar']");580581MT("labelTitleParenthese",582"[link [[foo]]:] [string http://example.com/ (bar)]");583584MT("labelTitleInvalid",585"[link [[foo]]:] [string http://example.com/] bar");586587MT("labelLinkAngleBrackets",588"[link [[foo]]:] [string <http://example.com/> \"bar\"]");589590MT("labelTitleNextDoubleQuotes",591"[link [[foo]]:] [string http://example.com/]",592"[string \"bar\"] hello");593594MT("labelTitleNextSingleQuotes",595"[link [[foo]]:] [string http://example.com/]",596"[string 'bar'] hello");597598MT("labelTitleNextParenthese",599"[link [[foo]]:] [string http://example.com/]",600"[string (bar)] hello");601602MT("labelTitleNextMixed",603"[link [[foo]]:] [string http://example.com/]",604"(bar\" hello");605606MT("linkWeb",607"[link <http://example.com/>] foo");608609MT("linkWebDouble",610"[link <http://example.com/>] foo [link <http://example.com/>]");611612MT("linkEmail",613"[link <[email protected]>] foo");614615MT("linkEmailDouble",616"[link <[email protected]>] foo [link <[email protected]>]");617618MT("emAsterisk",619"[em *foo*] bar");620621MT("emUnderscore",622"[em _foo_] bar");623624MT("emInWordAsterisk",625"foo[em *bar*]hello");626627MT("emInWordUnderscore",628"foo[em _bar_]hello");629630// Per documentation: "...surround an * or _ with spaces, it’ll be631// treated as a literal asterisk or underscore."632633MT("emEscapedBySpaceIn",634"foo [em _bar _ hello_] world");635636MT("emEscapedBySpaceOut",637"foo _ bar[em _hello_]world");638639MT("emEscapedByNewline",640"foo",641"_ bar[em _hello_]world");642643// Unclosed emphasis characters644// Instead of simply marking as EM / STRONG, it would be nice to have an645// incomplete flag for EM and STRONG, that is styled slightly different.646MT("emIncompleteAsterisk",647"foo [em *bar]");648649MT("emIncompleteUnderscore",650"foo [em _bar]");651652MT("strongAsterisk",653"[strong **foo**] bar");654655MT("strongUnderscore",656"[strong __foo__] bar");657658MT("emStrongAsterisk",659"[em *foo][em&strong **bar*][strong hello**] world");660661MT("emStrongUnderscore",662"[em _foo][em&strong __bar_][strong hello__] world");663664// "...same character must be used to open and close an emphasis span.""665MT("emStrongMixed",666"[em _foo][em&strong **bar*hello__ world]");667668MT("emStrongMixed",669"[em *foo][em&strong __bar_hello** world]");670671// These characters should be escaped:672// \ backslash673// ` backtick674// * asterisk675// _ underscore676// {} curly braces677// [] square brackets678// () parentheses679// # hash mark680// + plus sign681// - minus sign (hyphen)682// . dot683// ! exclamation mark684685MT("escapeBacktick",686"foo \\`bar\\`");687688MT("doubleEscapeBacktick",689"foo \\\\[comment `bar\\\\`]");690691MT("escapeAsterisk",692"foo \\*bar\\*");693694MT("doubleEscapeAsterisk",695"foo \\\\[em *bar\\\\*]");696697MT("escapeUnderscore",698"foo \\_bar\\_");699700MT("doubleEscapeUnderscore",701"foo \\\\[em _bar\\\\_]");702703MT("escapeHash",704"\\# foo");705706MT("doubleEscapeHash",707"\\\\# foo");708709MT("escapeNewline",710"\\",711"[em *foo*]");712713714// Tests to make sure GFM-specific things aren't getting through715716MT("taskList",717"[variable-2 * [ ]] bar]");718719MT("fencedCodeBlocks",720"[comment ```]",721"foo",722"[comment ```]");723})();724725726