test.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. ;(function () {
  4. var mode = CodeMirror.getMode({ tabSize: 4 }, 'textile')
  5. function MT(name) {
  6. test.mode(name, mode, Array.prototype.slice.call(arguments, 1))
  7. }
  8. MT('simpleParagraphs', 'Some text.', '', 'Some more text.')
  9. /*
  10. * Phrase Modifiers
  11. */
  12. MT('em', 'foo [em _bar_]')
  13. MT('emBoogus', 'code_mirror')
  14. MT('strong', 'foo [strong *bar*]')
  15. MT('strongBogus', '3 * 3 = 9')
  16. MT('italic', 'foo [em __bar__]')
  17. MT('italicBogus', 'code__mirror')
  18. MT('bold', 'foo [strong **bar**]')
  19. MT('boldBogus', '3 ** 3 = 27')
  20. MT('simpleLink', '[link "CodeMirror":https://codemirror.net]')
  21. MT('referenceLink', '[link "CodeMirror":code_mirror]', 'Normal Text.', '[link [[code_mirror]]https://codemirror.net]')
  22. MT('footCite', 'foo bar[qualifier [[1]]]')
  23. MT('footCiteBogus', 'foo bar[[1a2]]')
  24. MT('special-characters', 'Registered [tag (r)], ' + 'Trademark [tag (tm)], and ' + 'Copyright [tag (c)] 2008')
  25. MT('cite', 'A book is [keyword ??The Count of Monte Cristo??] by Dumas.')
  26. MT('additionAndDeletion', 'The news networks declared [negative -Al Gore-] ' + '[positive +George W. Bush+] the winner in Florida.')
  27. MT('subAndSup', 'f(x, n) = log [builtin ~4~] x [builtin ^n^]')
  28. MT('spanAndCode', 'A [quote %span element%] and [atom @code element@]')
  29. MT('spanBogus', 'Percentage 25% is not a span.')
  30. MT('citeBogus', 'Question? is not a citation.')
  31. MT('codeBogus', 'user@example.com')
  32. MT('subBogus', '~username')
  33. MT('supBogus', 'foo ^ bar')
  34. MT('deletionBogus', '3 - 3 = 0')
  35. MT('additionBogus', '3 + 3 = 6')
  36. MT('image', 'An image: [string !http://www.example.com/image.png!]')
  37. MT('imageWithAltText', 'An image: [string !http://www.example.com/image.png (Alt Text)!]')
  38. MT('imageWithUrl', 'An image: [string !http://www.example.com/image.png!:http://www.example.com/]')
  39. /*
  40. * Headers
  41. */
  42. MT('h1', '[header&header-1 h1. foo]')
  43. MT('h2', '[header&header-2 h2. foo]')
  44. MT('h3', '[header&header-3 h3. foo]')
  45. MT('h4', '[header&header-4 h4. foo]')
  46. MT('h5', '[header&header-5 h5. foo]')
  47. MT('h6', '[header&header-6 h6. foo]')
  48. MT('h7Bogus', 'h7. foo')
  49. MT('multipleHeaders', '[header&header-1 h1. Heading 1]', '', 'Some text.', '', '[header&header-2 h2. Heading 2]', '', 'More text.')
  50. MT('h1inline', '[header&header-1 h1. foo ][header&header-1&em _bar_][header&header-1 baz]')
  51. /*
  52. * Lists
  53. */
  54. MT('ul', 'foo', 'bar', '', '[variable-2 * foo]', '[variable-2 * bar]')
  55. MT('ulNoBlank', 'foo', 'bar', '[variable-2 * foo]', '[variable-2 * bar]')
  56. MT('ol', 'foo', 'bar', '', '[variable-2 # foo]', '[variable-2 # bar]')
  57. MT('olNoBlank', 'foo', 'bar', '[variable-2 # foo]', '[variable-2 # bar]')
  58. MT(
  59. 'ulFormatting',
  60. '[variable-2 * ][variable-2&em _foo_][variable-2 bar]',
  61. '[variable-2 * ][variable-2&strong *][variable-2&em&strong _foo_]' + '[variable-2&strong *][variable-2 bar]',
  62. '[variable-2 * ][variable-2&strong *foo*][variable-2 bar]'
  63. )
  64. MT(
  65. 'olFormatting',
  66. '[variable-2 # ][variable-2&em _foo_][variable-2 bar]',
  67. '[variable-2 # ][variable-2&strong *][variable-2&em&strong _foo_]' + '[variable-2&strong *][variable-2 bar]',
  68. '[variable-2 # ][variable-2&strong *foo*][variable-2 bar]'
  69. )
  70. MT('ulNested', '[variable-2 * foo]', '[variable-3 ** bar]', '[keyword *** bar]', '[variable-2 **** bar]', '[variable-3 ** bar]')
  71. MT('olNested', '[variable-2 # foo]', '[variable-3 ## bar]', '[keyword ### bar]', '[variable-2 #### bar]', '[variable-3 ## bar]')
  72. MT('ulNestedWithOl', '[variable-2 * foo]', '[variable-3 ## bar]', '[keyword *** bar]', '[variable-2 #### bar]', '[variable-3 ** bar]')
  73. MT('olNestedWithUl', '[variable-2 # foo]', '[variable-3 ** bar]', '[keyword ### bar]', '[variable-2 **** bar]', '[variable-3 ## bar]')
  74. MT('definitionList', '[number - coffee := Hot ][number&em _and_][number black]', '', 'Normal text.')
  75. MT('definitionListSpan', '[number - coffee :=]', '', '[number Hot ][number&em _and_][number black =:]', '', 'Normal text.')
  76. MT('boo', '[number - dog := woof woof]', '[number - cat := meow meow]', '[number - whale :=]', '[number Whale noises.]', '', '[number Also, ][number&em _splashing_][number . =:]')
  77. /*
  78. * Attributes
  79. */
  80. MT('divWithAttribute', '[punctuation div][punctuation&attribute (#my-id)][punctuation . foo bar]')
  81. MT('divWithAttributeAnd2emRightPadding', '[punctuation div][punctuation&attribute (#my-id)((][punctuation . foo bar]')
  82. MT('divWithClassAndId', '[punctuation div][punctuation&attribute (my-class#my-id)][punctuation . foo bar]')
  83. MT('paragraphWithCss', 'p[attribute {color:red;}]. foo bar')
  84. MT('paragraphNestedStyles', 'p. [strong *foo ][strong&em _bar_][strong *]')
  85. MT('paragraphWithLanguage', 'p[attribute [[fr]]]. Parlez-vous français?')
  86. MT('paragraphLeftAlign', 'p[attribute <]. Left')
  87. MT('paragraphRightAlign', 'p[attribute >]. Right')
  88. MT('paragraphRightAlign', 'p[attribute =]. Center')
  89. MT('paragraphJustified', 'p[attribute <>]. Justified')
  90. MT('paragraphWithLeftIndent1em', 'p[attribute (]. Left')
  91. MT('paragraphWithRightIndent1em', 'p[attribute )]. Right')
  92. MT('paragraphWithLeftIndent2em', 'p[attribute ((]. Left')
  93. MT('paragraphWithRightIndent2em', 'p[attribute ))]. Right')
  94. MT('paragraphWithLeftIndent3emRightIndent2em', 'p[attribute ((())]. Right')
  95. MT('divFormatting', '[punctuation div. ][punctuation&strong *foo ]' + '[punctuation&strong&em _bar_][punctuation&strong *]')
  96. MT('phraseModifierAttributes', 'p[attribute (my-class)]. This is a paragraph that has a class and' + ' this [em _][em&attribute (#special-phrase)][em emphasized phrase_]' + ' has an id.')
  97. MT('linkWithClass', '[link "(my-class). This is a link with class":http://redcloth.org]')
  98. /*
  99. * Layouts
  100. */
  101. MT('paragraphLayouts', 'p. This is one paragraph.', '', 'p. This is another.')
  102. MT('div', '[punctuation div. foo bar]')
  103. MT('pre', '[operator pre. Text]')
  104. MT('bq.', '[bracket bq. foo bar]', '', 'Normal text.')
  105. MT('footnote', '[variable fn123. foo ][variable&strong *bar*]')
  106. /*
  107. * Spanning Layouts
  108. */
  109. MT('bq..ThenParagraph', '[bracket bq.. foo bar]', '', '[bracket More quote.]', 'p. Normal Text')
  110. MT('bq..ThenH1', '[bracket bq.. foo bar]', '', '[bracket More quote.]', '[header&header-1 h1. Header Text]')
  111. MT('bc..ThenParagraph', '[atom bc.. # Some ruby code]', '[atom obj = {foo: :bar}]', '[atom puts obj]', '', '[atom obj[[:love]] = "*love*"]', '[atom puts obj.love.upcase]', '', 'p. Normal text.')
  112. MT('fn1..ThenParagraph', '[variable fn1.. foo bar]', '', '[variable More.]', 'p. Normal Text')
  113. MT('pre..ThenParagraph', '[operator pre.. foo bar]', '', '[operator More.]', 'p. Normal Text')
  114. /*
  115. * Tables
  116. */
  117. MT('table', '[variable-3&operator |_. name |_. age|]', '[variable-3 |][variable-3&strong *Walter*][variable-3 | 5 |]', '[variable-3 |Florence| 6 |]', '', 'p. Normal text.')
  118. MT(
  119. 'tableWithAttributes',
  120. '[variable-3&operator |_. name |_. age|]',
  121. '[variable-3 |][variable-3&attribute /2.][variable-3 Jim |]',
  122. '[variable-3 |][variable-3&attribute \\2{color: red}.][variable-3 Sam |]'
  123. )
  124. /*
  125. * HTML
  126. */
  127. MT(
  128. 'html',
  129. '[comment <div id="wrapper">]',
  130. '[comment <section id="introduction">]',
  131. '',
  132. '[header&header-1 h1. Welcome]',
  133. '',
  134. '[variable-2 * Item one]',
  135. '[variable-2 * Item two]',
  136. '',
  137. '[comment <a href="http://example.com">Example</a>]',
  138. '',
  139. '[comment </section>]',
  140. '[comment </div>]'
  141. )
  142. MT('inlineHtml', 'I can use HTML directly in my [comment <span class="youbetcha">Textile</span>].')
  143. /*
  144. * No-Textile
  145. */
  146. MT('notextile', '[string-2 notextile. *No* formatting]')
  147. MT('notextileInline', 'Use [string-2 ==*asterisks*==] for [strong *strong*] text.')
  148. MT('notextileWithPre', '[operator pre. *No* formatting]')
  149. MT('notextileWithSpanningPre', '[operator pre.. *No* formatting]', '', '[operator *No* formatting]')
  150. /* Only toggling phrases between non-word chars. */
  151. MT('phrase-in-word', 'foo_bar_baz')
  152. MT('phrase-non-word', '[negative -x-] aaa-bbb ccc-ddd [negative -eee-] fff [negative -ggg-]')
  153. MT('phrase-lone-dash', 'foo - bar - baz')
  154. })()