test.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/LICENSE
  3. (function() {
  4. var mode = CodeMirror.getMode({tabSize: 4}, 'textile');
  5. function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  6. MT('simpleParagraphs',
  7. 'Some text.',
  8. '',
  9. 'Some more text.');
  10. /*
  11. * Phrase Modifiers
  12. */
  13. MT('em',
  14. 'foo [em _bar_]');
  15. MT('emBoogus',
  16. 'code_mirror');
  17. MT('strong',
  18. 'foo [strong *bar*]');
  19. MT('strongBogus',
  20. '3 * 3 = 9');
  21. MT('italic',
  22. 'foo [em __bar__]');
  23. MT('italicBogus',
  24. 'code__mirror');
  25. MT('bold',
  26. 'foo [strong **bar**]');
  27. MT('boldBogus',
  28. '3 ** 3 = 27');
  29. MT('simpleLink',
  30. '[link "CodeMirror":http://codemirror.net]');
  31. MT('referenceLink',
  32. '[link "CodeMirror":code_mirror]',
  33. 'Normal Text.',
  34. '[link [[code_mirror]]http://codemirror.net]');
  35. MT('footCite',
  36. 'foo bar[qualifier [[1]]]');
  37. MT('footCiteBogus',
  38. 'foo bar[[1a2]]');
  39. MT('special-characters',
  40. 'Registered [tag (r)], ' +
  41. 'Trademark [tag (tm)], and ' +
  42. 'Copyright [tag (c)] 2008');
  43. MT('cite',
  44. "A book is [keyword ??The Count of Monte Cristo??] by Dumas.");
  45. MT('additionAndDeletion',
  46. 'The news networks declared [negative -Al Gore-] ' +
  47. '[positive +George W. Bush+] the winner in Florida.');
  48. MT('subAndSup',
  49. 'f(x, n) = log [builtin ~4~] x [builtin ^n^]');
  50. MT('spanAndCode',
  51. 'A [quote %span element%] and [atom @code element@]');
  52. MT('spanBogus',
  53. 'Percentage 25% is not a span.');
  54. MT('citeBogus',
  55. 'Question? is not a citation.');
  56. MT('codeBogus',
  57. 'user@example.com');
  58. MT('subBogus',
  59. '~username');
  60. MT('supBogus',
  61. 'foo ^ bar');
  62. MT('deletionBogus',
  63. '3 - 3 = 0');
  64. MT('additionBogus',
  65. '3 + 3 = 6');
  66. MT('image',
  67. 'An image: [string !http://www.example.com/image.png!]');
  68. MT('imageWithAltText',
  69. 'An image: [string !http://www.example.com/image.png (Alt Text)!]');
  70. MT('imageWithUrl',
  71. 'An image: [string !http://www.example.com/image.png!:http://www.example.com/]');
  72. /*
  73. * Headers
  74. */
  75. MT('h1',
  76. '[header&header-1 h1. foo]');
  77. MT('h2',
  78. '[header&header-2 h2. foo]');
  79. MT('h3',
  80. '[header&header-3 h3. foo]');
  81. MT('h4',
  82. '[header&header-4 h4. foo]');
  83. MT('h5',
  84. '[header&header-5 h5. foo]');
  85. MT('h6',
  86. '[header&header-6 h6. foo]');
  87. MT('h7Bogus',
  88. 'h7. foo');
  89. MT('multipleHeaders',
  90. '[header&header-1 h1. Heading 1]',
  91. '',
  92. 'Some text.',
  93. '',
  94. '[header&header-2 h2. Heading 2]',
  95. '',
  96. 'More text.');
  97. MT('h1inline',
  98. '[header&header-1 h1. foo ][header&header-1&em _bar_][header&header-1 baz]');
  99. /*
  100. * Lists
  101. */
  102. MT('ul',
  103. 'foo',
  104. 'bar',
  105. '',
  106. '[variable-2 * foo]',
  107. '[variable-2 * bar]');
  108. MT('ulNoBlank',
  109. 'foo',
  110. 'bar',
  111. '[variable-2 * foo]',
  112. '[variable-2 * bar]');
  113. MT('ol',
  114. 'foo',
  115. 'bar',
  116. '',
  117. '[variable-2 # foo]',
  118. '[variable-2 # bar]');
  119. MT('olNoBlank',
  120. 'foo',
  121. 'bar',
  122. '[variable-2 # foo]',
  123. '[variable-2 # bar]');
  124. MT('ulFormatting',
  125. '[variable-2 * ][variable-2&em _foo_][variable-2 bar]',
  126. '[variable-2 * ][variable-2&strong *][variable-2&em&strong _foo_]' +
  127. '[variable-2&strong *][variable-2 bar]',
  128. '[variable-2 * ][variable-2&strong *foo*][variable-2 bar]');
  129. MT('olFormatting',
  130. '[variable-2 # ][variable-2&em _foo_][variable-2 bar]',
  131. '[variable-2 # ][variable-2&strong *][variable-2&em&strong _foo_]' +
  132. '[variable-2&strong *][variable-2 bar]',
  133. '[variable-2 # ][variable-2&strong *foo*][variable-2 bar]');
  134. MT('ulNested',
  135. '[variable-2 * foo]',
  136. '[variable-3 ** bar]',
  137. '[keyword *** bar]',
  138. '[variable-2 **** bar]',
  139. '[variable-3 ** bar]');
  140. MT('olNested',
  141. '[variable-2 # foo]',
  142. '[variable-3 ## bar]',
  143. '[keyword ### bar]',
  144. '[variable-2 #### bar]',
  145. '[variable-3 ## bar]');
  146. MT('ulNestedWithOl',
  147. '[variable-2 * foo]',
  148. '[variable-3 ## bar]',
  149. '[keyword *** bar]',
  150. '[variable-2 #### bar]',
  151. '[variable-3 ** bar]');
  152. MT('olNestedWithUl',
  153. '[variable-2 # foo]',
  154. '[variable-3 ** bar]',
  155. '[keyword ### bar]',
  156. '[variable-2 **** bar]',
  157. '[variable-3 ## bar]');
  158. MT('definitionList',
  159. '[number - coffee := Hot ][number&em _and_][number black]',
  160. '',
  161. 'Normal text.');
  162. MT('definitionListSpan',
  163. '[number - coffee :=]',
  164. '',
  165. '[number Hot ][number&em _and_][number black =:]',
  166. '',
  167. 'Normal text.');
  168. MT('boo',
  169. '[number - dog := woof woof]',
  170. '[number - cat := meow meow]',
  171. '[number - whale :=]',
  172. '[number Whale noises.]',
  173. '',
  174. '[number Also, ][number&em _splashing_][number . =:]');
  175. /*
  176. * Attributes
  177. */
  178. MT('divWithAttribute',
  179. '[punctuation div][punctuation&attribute (#my-id)][punctuation . foo bar]');
  180. MT('divWithAttributeAnd2emRightPadding',
  181. '[punctuation div][punctuation&attribute (#my-id)((][punctuation . foo bar]');
  182. MT('divWithClassAndId',
  183. '[punctuation div][punctuation&attribute (my-class#my-id)][punctuation . foo bar]');
  184. MT('paragraphWithCss',
  185. 'p[attribute {color:red;}]. foo bar');
  186. MT('paragraphNestedStyles',
  187. 'p. [strong *foo ][strong&em _bar_][strong *]');
  188. MT('paragraphWithLanguage',
  189. 'p[attribute [[fr]]]. Parlez-vous français?');
  190. MT('paragraphLeftAlign',
  191. 'p[attribute <]. Left');
  192. MT('paragraphRightAlign',
  193. 'p[attribute >]. Right');
  194. MT('paragraphRightAlign',
  195. 'p[attribute =]. Center');
  196. MT('paragraphJustified',
  197. 'p[attribute <>]. Justified');
  198. MT('paragraphWithLeftIndent1em',
  199. 'p[attribute (]. Left');
  200. MT('paragraphWithRightIndent1em',
  201. 'p[attribute )]. Right');
  202. MT('paragraphWithLeftIndent2em',
  203. 'p[attribute ((]. Left');
  204. MT('paragraphWithRightIndent2em',
  205. 'p[attribute ))]. Right');
  206. MT('paragraphWithLeftIndent3emRightIndent2em',
  207. 'p[attribute ((())]. Right');
  208. MT('divFormatting',
  209. '[punctuation div. ][punctuation&strong *foo ]' +
  210. '[punctuation&strong&em _bar_][punctuation&strong *]');
  211. MT('phraseModifierAttributes',
  212. 'p[attribute (my-class)]. This is a paragraph that has a class and' +
  213. ' this [em _][em&attribute (#special-phrase)][em emphasized phrase_]' +
  214. ' has an id.');
  215. MT('linkWithClass',
  216. '[link "(my-class). This is a link with class":http://redcloth.org]');
  217. /*
  218. * Layouts
  219. */
  220. MT('paragraphLayouts',
  221. 'p. This is one paragraph.',
  222. '',
  223. 'p. This is another.');
  224. MT('div',
  225. '[punctuation div. foo bar]');
  226. MT('pre',
  227. '[operator pre. Text]');
  228. MT('bq.',
  229. '[bracket bq. foo bar]',
  230. '',
  231. 'Normal text.');
  232. MT('footnote',
  233. '[variable fn123. foo ][variable&strong *bar*]');
  234. /*
  235. * Spanning Layouts
  236. */
  237. MT('bq..ThenParagraph',
  238. '[bracket bq.. foo bar]',
  239. '',
  240. '[bracket More quote.]',
  241. 'p. Normal Text');
  242. MT('bq..ThenH1',
  243. '[bracket bq.. foo bar]',
  244. '',
  245. '[bracket More quote.]',
  246. '[header&header-1 h1. Header Text]');
  247. MT('bc..ThenParagraph',
  248. '[atom bc.. # Some ruby code]',
  249. '[atom obj = {foo: :bar}]',
  250. '[atom puts obj]',
  251. '',
  252. '[atom obj[[:love]] = "*love*"]',
  253. '[atom puts obj.love.upcase]',
  254. '',
  255. 'p. Normal text.');
  256. MT('fn1..ThenParagraph',
  257. '[variable fn1.. foo bar]',
  258. '',
  259. '[variable More.]',
  260. 'p. Normal Text');
  261. MT('pre..ThenParagraph',
  262. '[operator pre.. foo bar]',
  263. '',
  264. '[operator More.]',
  265. 'p. Normal Text');
  266. /*
  267. * Tables
  268. */
  269. MT('table',
  270. '[variable-3&operator |_. name |_. age|]',
  271. '[variable-3 |][variable-3&strong *Walter*][variable-3 | 5 |]',
  272. '[variable-3 |Florence| 6 |]',
  273. '',
  274. 'p. Normal text.');
  275. MT('tableWithAttributes',
  276. '[variable-3&operator |_. name |_. age|]',
  277. '[variable-3 |][variable-3&attribute /2.][variable-3 Jim |]',
  278. '[variable-3 |][variable-3&attribute \\2{color: red}.][variable-3 Sam |]');
  279. /*
  280. * HTML
  281. */
  282. MT('html',
  283. '[comment <div id="wrapper">]',
  284. '[comment <section id="introduction">]',
  285. '',
  286. '[header&header-1 h1. Welcome]',
  287. '',
  288. '[variable-2 * Item one]',
  289. '[variable-2 * Item two]',
  290. '',
  291. '[comment <a href="http://example.com">Example</a>]',
  292. '',
  293. '[comment </section>]',
  294. '[comment </div>]');
  295. MT('inlineHtml',
  296. 'I can use HTML directly in my [comment <span class="youbetcha">Textile</span>].');
  297. /*
  298. * No-Textile
  299. */
  300. MT('notextile',
  301. '[string-2 notextile. *No* formatting]');
  302. MT('notextileInline',
  303. 'Use [string-2 ==*asterisks*==] for [strong *strong*] text.');
  304. MT('notextileWithPre',
  305. '[operator pre. *No* formatting]');
  306. MT('notextileWithSpanningPre',
  307. '[operator pre.. *No* formatting]',
  308. '',
  309. '[operator *No* formatting]');
  310. /* Only toggling phrases between non-word chars. */
  311. MT('phrase-in-word',
  312. 'foo_bar_baz');
  313. MT('phrase-non-word',
  314. '[negative -x-] aaa-bbb ccc-ddd [negative -eee-] fff [negative -ggg-]');
  315. MT('phrase-lone-dash',
  316. 'foo - bar - baz');
  317. })();