scrivito_codemirror_editor 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. checksums.yaml +5 -5
  2. data/LICENSE +21 -165
  3. data/README.md +2 -2
  4. data/app/assets/javascripts/scrivito_codemirror_editor/codemirror_editor.js +29 -0
  5. data/lib/scrivito_codemirror_editor.rb +0 -2
  6. data/vendor/assets/javascripts/codemirror/addons/comment/comment.js +203 -0
  7. data/vendor/assets/javascripts/codemirror/addons/comment/continuecomment.js +85 -0
  8. data/vendor/assets/javascripts/codemirror/addons/dialog/dialog.js +157 -0
  9. data/vendor/assets/javascripts/codemirror/addons/display/autorefresh.js +47 -0
  10. data/vendor/assets/javascripts/codemirror/addons/display/fullscreen.js +41 -0
  11. data/vendor/assets/javascripts/codemirror/addons/display/panel.js +112 -0
  12. data/vendor/assets/javascripts/codemirror/addons/display/placeholder.js +62 -0
  13. data/vendor/assets/javascripts/codemirror/addons/display/rulers.js +51 -0
  14. data/vendor/assets/javascripts/codemirror/addons/edit/closebrackets.js +195 -0
  15. data/vendor/assets/javascripts/codemirror/addons/edit/closetag.js +169 -0
  16. data/vendor/assets/javascripts/codemirror/addons/edit/continuelist.js +51 -0
  17. data/vendor/assets/javascripts/codemirror/addons/edit/matchbrackets.js +120 -0
  18. data/vendor/assets/javascripts/codemirror/addons/edit/matchtags.js +66 -0
  19. data/vendor/assets/javascripts/codemirror/addons/edit/trailingspace.js +27 -0
  20. data/vendor/assets/javascripts/codemirror/addons/fold/brace-fold.js +105 -0
  21. data/vendor/assets/javascripts/codemirror/addons/fold/comment-fold.js +59 -0
  22. data/vendor/assets/javascripts/codemirror/addons/fold/foldcode.js +150 -0
  23. data/vendor/assets/javascripts/codemirror/addons/fold/foldgutter.js +146 -0
  24. data/vendor/assets/javascripts/codemirror/addons/fold/indent-fold.js +44 -0
  25. data/vendor/assets/javascripts/codemirror/addons/fold/markdown-fold.js +49 -0
  26. data/vendor/assets/javascripts/codemirror/addons/fold/xml-fold.js +182 -0
  27. data/vendor/assets/javascripts/codemirror/addons/hint/anyword-hint.js +41 -0
  28. data/vendor/assets/javascripts/codemirror/addons/hint/css-hint.js +60 -0
  29. data/vendor/assets/javascripts/codemirror/addons/hint/html-hint.js +348 -0
  30. data/vendor/assets/javascripts/codemirror/addons/hint/javascript-hint.js +146 -0
  31. data/vendor/assets/javascripts/codemirror/addons/hint/show-hint.js +437 -0
  32. data/vendor/assets/javascripts/codemirror/addons/hint/sql-hint.js +271 -0
  33. data/vendor/assets/javascripts/codemirror/addons/hint/xml-hint.js +110 -0
  34. data/vendor/assets/javascripts/codemirror/addons/lint/coffeescript-lint.js +41 -0
  35. data/vendor/assets/javascripts/codemirror/addons/lint/css-lint.js +35 -0
  36. data/vendor/assets/javascripts/codemirror/addons/lint/html-lint.js +46 -0
  37. data/vendor/assets/javascripts/codemirror/addons/lint/javascript-lint.js +136 -0
  38. data/vendor/assets/javascripts/codemirror/addons/lint/json-lint.js +31 -0
  39. data/vendor/assets/javascripts/codemirror/addons/lint/lint.js +239 -0
  40. data/vendor/assets/javascripts/codemirror/addons/lint/yaml-lint.js +28 -0
  41. data/vendor/assets/javascripts/codemirror/addons/merge/merge.js +773 -0
  42. data/vendor/assets/javascripts/codemirror/addons/mode/loadmode.js +64 -0
  43. data/vendor/assets/javascripts/codemirror/addons/mode/multiplex.js +123 -0
  44. data/vendor/assets/javascripts/codemirror/addons/mode/overlay.js +85 -0
  45. data/vendor/assets/javascripts/codemirror/addons/mode/simple.js +213 -0
  46. data/vendor/assets/javascripts/codemirror/addons/runmode/colorize.js +40 -0
  47. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode-standalone.js +157 -0
  48. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.js +72 -0
  49. data/vendor/assets/javascripts/codemirror/addons/runmode/runmode.node.js +179 -0
  50. data/vendor/assets/javascripts/codemirror/addons/scroll/annotatescrollbar.js +118 -0
  51. data/vendor/assets/javascripts/codemirror/addons/scroll/scrollpastend.js +48 -0
  52. data/vendor/assets/javascripts/codemirror/addons/scroll/simplescrollbars.js +152 -0
  53. data/vendor/assets/javascripts/codemirror/addons/search/jump-to-line.js +49 -0
  54. data/vendor/assets/javascripts/codemirror/addons/search/match-highlighter.js +146 -0
  55. data/vendor/assets/javascripts/codemirror/addons/search/matchesonscrollbar.js +97 -0
  56. data/vendor/assets/javascripts/codemirror/addons/search/search.js +249 -0
  57. data/vendor/assets/javascripts/codemirror/addons/search/searchcursor.js +189 -0
  58. data/vendor/assets/javascripts/codemirror/addons/selection/active-line.js +74 -0
  59. data/vendor/assets/javascripts/codemirror/addons/selection/mark-selection.js +118 -0
  60. data/vendor/assets/javascripts/codemirror/addons/selection/selection-pointer.js +98 -0
  61. data/vendor/assets/javascripts/codemirror/addons/tern/tern.js +701 -0
  62. data/vendor/assets/javascripts/codemirror/addons/tern/worker.js +44 -0
  63. data/vendor/assets/javascripts/codemirror/addons/wrap/hardwrap.js +144 -0
  64. data/vendor/assets/javascripts/codemirror/keymaps/emacs.js +412 -0
  65. data/vendor/assets/javascripts/codemirror/keymaps/sublime.js +580 -0
  66. data/vendor/assets/javascripts/codemirror/keymaps/vim.js +5065 -0
  67. data/vendor/assets/javascripts/codemirror/modes/apl.js +174 -0
  68. data/vendor/assets/javascripts/codemirror/modes/asciiarmor.js +73 -0
  69. data/vendor/assets/javascripts/codemirror/modes/asn.1.js +204 -0
  70. data/vendor/assets/javascripts/codemirror/modes/asterisk.js +196 -0
  71. data/vendor/assets/javascripts/codemirror/modes/brainfuck.js +85 -0
  72. data/vendor/assets/javascripts/codemirror/modes/clike.js +786 -0
  73. data/vendor/assets/javascripts/codemirror/modes/clojure.js +306 -0
  74. data/vendor/assets/javascripts/codemirror/modes/cmake.js +97 -0
  75. data/vendor/assets/javascripts/codemirror/modes/cobol.js +255 -0
  76. data/vendor/assets/javascripts/codemirror/modes/coffeescript.js +355 -0
  77. data/vendor/assets/javascripts/codemirror/modes/commonlisp.js +123 -0
  78. data/vendor/assets/javascripts/codemirror/modes/crystal.js +391 -0
  79. data/vendor/assets/javascripts/codemirror/modes/css.js +825 -0
  80. data/vendor/assets/javascripts/codemirror/modes/cypher.js +146 -0
  81. data/vendor/assets/javascripts/codemirror/modes/d.js +218 -0
  82. data/vendor/assets/javascripts/codemirror/modes/dart.js +157 -0
  83. data/vendor/assets/javascripts/codemirror/modes/diff.js +47 -0
  84. data/vendor/assets/javascripts/codemirror/modes/django.js +356 -0
  85. data/vendor/assets/javascripts/codemirror/modes/dockerfile.js +79 -0
  86. data/vendor/assets/javascripts/codemirror/modes/dtd.js +142 -0
  87. data/vendor/assets/javascripts/codemirror/modes/dylan.js +344 -0
  88. data/vendor/assets/javascripts/codemirror/modes/ebnf.js +195 -0
  89. data/vendor/assets/javascripts/codemirror/modes/ecl.js +206 -0
  90. data/vendor/assets/javascripts/codemirror/modes/eiffel.js +160 -0
  91. data/vendor/assets/javascripts/codemirror/modes/elm.js +205 -0
  92. data/vendor/assets/javascripts/codemirror/modes/erlang.js +618 -0
  93. data/vendor/assets/javascripts/codemirror/modes/factor.js +83 -0
  94. data/vendor/assets/javascripts/codemirror/modes/fcl.js +173 -0
  95. data/vendor/assets/javascripts/codemirror/modes/forth.js +180 -0
  96. data/vendor/assets/javascripts/codemirror/modes/fortran.js +188 -0
  97. data/vendor/assets/javascripts/codemirror/modes/gas.js +345 -0
  98. data/vendor/assets/javascripts/codemirror/modes/gfm.js +130 -0
  99. data/vendor/assets/javascripts/codemirror/modes/gherkin.js +178 -0
  100. data/vendor/assets/javascripts/codemirror/modes/go.js +185 -0
  101. data/vendor/assets/javascripts/codemirror/modes/groovy.js +230 -0
  102. data/vendor/assets/javascripts/codemirror/modes/haml.js +161 -0
  103. data/vendor/assets/javascripts/codemirror/modes/handlebars.js +62 -0
  104. data/vendor/assets/javascripts/codemirror/modes/haskell-literate.js +43 -0
  105. data/vendor/assets/javascripts/codemirror/modes/haskell.js +267 -0
  106. data/vendor/assets/javascripts/codemirror/modes/haxe.js +515 -0
  107. data/vendor/assets/javascripts/codemirror/modes/htmlembedded.js +28 -0
  108. data/vendor/assets/javascripts/codemirror/modes/htmlmixed.js +152 -0
  109. data/vendor/assets/javascripts/codemirror/modes/http.js +113 -0
  110. data/vendor/assets/javascripts/codemirror/modes/idl.js +290 -0
  111. data/vendor/assets/javascripts/codemirror/modes/jade.js +590 -0
  112. data/vendor/assets/javascripts/codemirror/modes/javascript.js +748 -0
  113. data/vendor/assets/javascripts/codemirror/modes/jinja2.js +142 -0
  114. data/vendor/assets/javascripts/codemirror/modes/jsx.js +147 -0
  115. data/vendor/assets/javascripts/codemirror/modes/julia.js +392 -0
  116. data/vendor/assets/javascripts/codemirror/modes/livescript.js +280 -0
  117. data/vendor/assets/javascripts/codemirror/modes/lua.js +159 -0
  118. data/vendor/assets/javascripts/codemirror/modes/markdown.js +797 -0
  119. data/vendor/assets/javascripts/codemirror/modes/mathematica.js +176 -0
  120. data/vendor/assets/javascripts/codemirror/modes/mbox.js +129 -0
  121. data/vendor/assets/javascripts/codemirror/modes/mirc.js +193 -0
  122. data/vendor/assets/javascripts/codemirror/modes/mllike.js +205 -0
  123. data/vendor/assets/javascripts/codemirror/modes/modelica.js +245 -0
  124. data/vendor/assets/javascripts/codemirror/modes/mscgen.js +169 -0
  125. data/vendor/assets/javascripts/codemirror/modes/mumps.js +148 -0
  126. data/vendor/assets/javascripts/codemirror/modes/nginx.js +178 -0
  127. data/vendor/assets/javascripts/codemirror/modes/nsis.js +95 -0
  128. data/vendor/assets/javascripts/codemirror/modes/ntriples.js +186 -0
  129. data/vendor/assets/javascripts/codemirror/modes/octave.js +135 -0
  130. data/vendor/assets/javascripts/codemirror/modes/oz.js +252 -0
  131. data/vendor/assets/javascripts/codemirror/modes/pascal.js +109 -0
  132. data/vendor/assets/javascripts/codemirror/modes/pegjs.js +114 -0
  133. data/vendor/assets/javascripts/codemirror/modes/perl.js +837 -0
  134. data/vendor/assets/javascripts/codemirror/modes/php.js +234 -0
  135. data/vendor/assets/javascripts/codemirror/modes/pig.js +178 -0
  136. data/vendor/assets/javascripts/codemirror/modes/powershell.js +396 -0
  137. data/vendor/assets/javascripts/codemirror/modes/properties.js +78 -0
  138. data/vendor/assets/javascripts/codemirror/modes/protobuf.js +68 -0
  139. data/vendor/assets/javascripts/codemirror/modes/puppet.js +220 -0
  140. data/vendor/assets/javascripts/codemirror/modes/python.js +340 -0
  141. data/vendor/assets/javascripts/codemirror/modes/q.js +139 -0
  142. data/vendor/assets/javascripts/codemirror/modes/r.js +164 -0
  143. data/vendor/assets/javascripts/codemirror/modes/rpm.js +109 -0
  144. data/vendor/assets/javascripts/codemirror/modes/rst.js +557 -0
  145. data/vendor/assets/javascripts/codemirror/modes/ruby.js +285 -0
  146. data/vendor/assets/javascripts/codemirror/modes/rust.js +71 -0
  147. data/vendor/assets/javascripts/codemirror/modes/sas.js +315 -0
  148. data/vendor/assets/javascripts/codemirror/modes/sass.js +414 -0
  149. data/vendor/assets/javascripts/codemirror/modes/scheme.js +249 -0
  150. data/vendor/assets/javascripts/codemirror/modes/shell.js +139 -0
  151. data/vendor/assets/javascripts/codemirror/modes/sieve.js +193 -0
  152. data/vendor/assets/javascripts/codemirror/modes/slim.js +575 -0
  153. data/vendor/assets/javascripts/codemirror/modes/smalltalk.js +168 -0
  154. data/vendor/assets/javascripts/codemirror/modes/smarty.js +225 -0
  155. data/vendor/assets/javascripts/codemirror/modes/solr.js +104 -0
  156. data/vendor/assets/javascripts/codemirror/modes/soy.js +199 -0
  157. data/vendor/assets/javascripts/codemirror/modes/sparql.js +180 -0
  158. data/vendor/assets/javascripts/codemirror/modes/spreadsheet.js +112 -0
  159. data/vendor/assets/javascripts/codemirror/modes/sql.js +413 -0
  160. data/vendor/assets/javascripts/codemirror/modes/stex.js +251 -0
  161. data/vendor/assets/javascripts/codemirror/modes/stylus.js +769 -0
  162. data/vendor/assets/javascripts/codemirror/modes/swift.js +202 -0
  163. data/vendor/assets/javascripts/codemirror/modes/tcl.js +139 -0
  164. data/vendor/assets/javascripts/codemirror/modes/textile.js +469 -0
  165. data/vendor/assets/javascripts/codemirror/modes/tiddlywiki.js +308 -0
  166. data/vendor/assets/javascripts/codemirror/modes/tiki.js +312 -0
  167. data/vendor/assets/javascripts/codemirror/modes/toml.js +88 -0
  168. data/vendor/assets/javascripts/codemirror/modes/tornado.js +68 -0
  169. data/vendor/assets/javascripts/codemirror/modes/troff.js +84 -0
  170. data/vendor/assets/javascripts/codemirror/modes/ttcn-cfg.js +214 -0
  171. data/vendor/assets/javascripts/codemirror/modes/ttcn.js +283 -0
  172. data/vendor/assets/javascripts/codemirror/modes/turtle.js +162 -0
  173. data/vendor/assets/javascripts/codemirror/modes/twig.js +141 -0
  174. data/vendor/assets/javascripts/codemirror/modes/vb.js +276 -0
  175. data/vendor/assets/javascripts/codemirror/modes/vbscript.js +350 -0
  176. data/vendor/assets/javascripts/codemirror/modes/velocity.js +201 -0
  177. data/vendor/assets/javascripts/codemirror/modes/verilog.js +537 -0
  178. data/vendor/assets/javascripts/codemirror/modes/vhdl.js +189 -0
  179. data/vendor/assets/javascripts/codemirror/modes/vue.js +69 -0
  180. data/vendor/assets/javascripts/codemirror/modes/webidl.js +195 -0
  181. data/vendor/assets/javascripts/codemirror/modes/xml.js +394 -0
  182. data/vendor/assets/javascripts/codemirror/modes/xquery.js +437 -0
  183. data/vendor/assets/javascripts/codemirror/modes/yacas.js +204 -0
  184. data/vendor/assets/javascripts/codemirror/modes/yaml-frontmatter.js +68 -0
  185. data/vendor/assets/javascripts/codemirror/modes/yaml.js +117 -0
  186. data/vendor/assets/javascripts/codemirror/modes/z80.js +116 -0
  187. data/vendor/assets/javascripts/codemirror.js +8922 -0
  188. data/vendor/assets/stylesheets/codemirror/addons/dialog/dialog.css +32 -0
  189. data/vendor/assets/stylesheets/codemirror/addons/display/fullscreen.css +6 -0
  190. data/vendor/assets/stylesheets/codemirror/addons/fold/foldgutter.css +20 -0
  191. data/vendor/assets/stylesheets/codemirror/addons/hint/show-hint.css +37 -0
  192. data/vendor/assets/stylesheets/codemirror/addons/lint/lint.css +73 -0
  193. data/vendor/assets/stylesheets/codemirror/addons/merge/merge.css +113 -0
  194. data/vendor/assets/stylesheets/codemirror/addons/scroll/simplescrollbars.css +66 -0
  195. data/vendor/assets/stylesheets/codemirror/addons/search/matchesonscrollbar.css +8 -0
  196. data/vendor/assets/stylesheets/codemirror/addons/tern/tern.css +87 -0
  197. data/vendor/assets/stylesheets/codemirror/modes/tiddlywiki.css +14 -0
  198. data/vendor/assets/stylesheets/codemirror/modes/tiki.css +26 -0
  199. data/vendor/assets/stylesheets/codemirror/themes/3024-day.css +41 -0
  200. data/vendor/assets/stylesheets/codemirror/themes/3024-night.css +39 -0
  201. data/vendor/assets/stylesheets/codemirror/themes/abcdef.css +32 -0
  202. data/vendor/assets/stylesheets/codemirror/themes/ambiance-mobile.css +5 -0
  203. data/vendor/assets/stylesheets/codemirror/themes/ambiance.css +74 -0
  204. data/vendor/assets/stylesheets/codemirror/themes/base16-dark.css +38 -0
  205. data/vendor/assets/stylesheets/codemirror/themes/base16-light.css +38 -0
  206. data/vendor/assets/stylesheets/codemirror/themes/bespin.css +34 -0
  207. data/vendor/assets/stylesheets/codemirror/themes/blackboard.css +32 -0
  208. data/vendor/assets/stylesheets/codemirror/themes/cobalt.css +25 -0
  209. data/vendor/assets/stylesheets/codemirror/themes/colorforth.css +33 -0
  210. data/vendor/assets/stylesheets/codemirror/themes/dracula.css +41 -0
  211. data/vendor/assets/stylesheets/codemirror/themes/eclipse.css +23 -0
  212. data/vendor/assets/stylesheets/codemirror/themes/elegant.css +13 -0
  213. data/vendor/assets/stylesheets/codemirror/themes/erlang-dark.css +34 -0
  214. data/vendor/assets/stylesheets/codemirror/themes/hopscotch.css +34 -0
  215. data/vendor/assets/stylesheets/codemirror/themes/icecoder.css +43 -0
  216. data/vendor/assets/stylesheets/codemirror/themes/isotope.css +34 -0
  217. data/vendor/assets/stylesheets/codemirror/themes/lesser-dark.css +47 -0
  218. data/vendor/assets/stylesheets/codemirror/themes/liquibyte.css +95 -0
  219. data/vendor/assets/stylesheets/codemirror/themes/material.css +53 -0
  220. data/vendor/assets/stylesheets/codemirror/themes/mbo.css +37 -0
  221. data/vendor/assets/stylesheets/codemirror/themes/mdn-like.css +46 -0
  222. data/vendor/assets/stylesheets/codemirror/themes/midnight.css +45 -0
  223. data/vendor/assets/stylesheets/codemirror/themes/monokai.css +36 -0
  224. data/vendor/assets/stylesheets/codemirror/themes/neat.css +12 -0
  225. data/vendor/assets/stylesheets/codemirror/themes/neo.css +43 -0
  226. data/vendor/assets/stylesheets/codemirror/themes/night.css +27 -0
  227. data/vendor/assets/stylesheets/codemirror/themes/paraiso-dark.css +38 -0
  228. data/vendor/assets/stylesheets/codemirror/themes/paraiso-light.css +38 -0
  229. data/vendor/assets/stylesheets/codemirror/themes/pastel-on-dark.css +53 -0
  230. data/vendor/assets/stylesheets/codemirror/themes/railscasts.css +34 -0
  231. data/vendor/assets/stylesheets/codemirror/themes/rubyblue.css +25 -0
  232. data/vendor/assets/stylesheets/codemirror/themes/seti.css +44 -0
  233. data/vendor/assets/stylesheets/codemirror/themes/solarized.css +169 -0
  234. data/vendor/assets/stylesheets/codemirror/themes/the-matrix.css +30 -0
  235. data/vendor/assets/stylesheets/codemirror/themes/tomorrow-night-bright.css +35 -0
  236. data/vendor/assets/stylesheets/codemirror/themes/tomorrow-night-eighties.css +38 -0
  237. data/vendor/assets/stylesheets/codemirror/themes/ttcn.css +64 -0
  238. data/vendor/assets/stylesheets/codemirror/themes/twilight.css +32 -0
  239. data/vendor/assets/stylesheets/codemirror/themes/vibrant-ink.css +34 -0
  240. data/vendor/assets/stylesheets/codemirror/themes/xq-dark.css +53 -0
  241. data/vendor/assets/stylesheets/codemirror/themes/xq-light.css +43 -0
  242. data/vendor/assets/stylesheets/codemirror/themes/yeti.css +44 -0
  243. data/vendor/assets/stylesheets/codemirror/themes/zenburn.css +37 -0
  244. data/vendor/assets/stylesheets/codemirror.css +347 -0
  245. metadata +244 -49
  246. data/app/assets/javascripts/scrivito_codemirror_editor/codemirror_editor.js.coffee +0 -23
@@ -0,0 +1,797 @@
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"), require("../xml/xml"), require("../meta"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror", "../xml/xml", "../meta"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
15
+
16
+ var htmlMode = CodeMirror.getMode(cmCfg, "text/html");
17
+ var htmlModeMissing = htmlMode.name == "null"
18
+
19
+ function getMode(name) {
20
+ if (CodeMirror.findModeByName) {
21
+ var found = CodeMirror.findModeByName(name);
22
+ if (found) name = found.mime || found.mimes[0];
23
+ }
24
+ var mode = CodeMirror.getMode(cmCfg, name);
25
+ return mode.name == "null" ? null : mode;
26
+ }
27
+
28
+ // Should characters that affect highlighting be highlighted separate?
29
+ // Does not include characters that will be output (such as `1.` and `-` for lists)
30
+ if (modeCfg.highlightFormatting === undefined)
31
+ modeCfg.highlightFormatting = false;
32
+
33
+ // Maximum number of nested blockquotes. Set to 0 for infinite nesting.
34
+ // Excess `>` will emit `error` token.
35
+ if (modeCfg.maxBlockquoteDepth === undefined)
36
+ modeCfg.maxBlockquoteDepth = 0;
37
+
38
+ // Should underscores in words open/close em/strong?
39
+ if (modeCfg.underscoresBreakWords === undefined)
40
+ modeCfg.underscoresBreakWords = true;
41
+
42
+ // Use `fencedCodeBlocks` to configure fenced code blocks. false to
43
+ // disable, string to specify a precise regexp that the fence should
44
+ // match, and true to allow three or more backticks or tildes (as
45
+ // per CommonMark).
46
+
47
+ // Turn on task lists? ("- [ ] " and "- [x] ")
48
+ if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
49
+
50
+ // Turn on strikethrough syntax
51
+ if (modeCfg.strikethrough === undefined)
52
+ modeCfg.strikethrough = false;
53
+
54
+ // Allow token types to be overridden by user-provided token types.
55
+ if (modeCfg.tokenTypeOverrides === undefined)
56
+ modeCfg.tokenTypeOverrides = {};
57
+
58
+ var tokenTypes = {
59
+ header: "header",
60
+ code: "comment",
61
+ quote: "quote",
62
+ list1: "variable-2",
63
+ list2: "variable-3",
64
+ list3: "keyword",
65
+ hr: "hr",
66
+ image: "tag",
67
+ formatting: "formatting",
68
+ linkInline: "link",
69
+ linkEmail: "link",
70
+ linkText: "link",
71
+ linkHref: "string",
72
+ em: "em",
73
+ strong: "strong",
74
+ strikethrough: "strikethrough"
75
+ };
76
+
77
+ for (var tokenType in tokenTypes) {
78
+ if (tokenTypes.hasOwnProperty(tokenType) && modeCfg.tokenTypeOverrides[tokenType]) {
79
+ tokenTypes[tokenType] = modeCfg.tokenTypeOverrides[tokenType];
80
+ }
81
+ }
82
+
83
+ var hrRE = /^([*\-_])(?:\s*\1){2,}\s*$/
84
+ , ulRE = /^[*\-+]\s+/
85
+ , olRE = /^[0-9]+([.)])\s+/
86
+ , taskListRE = /^\[(x| )\](?=\s)/ // Must follow ulRE or olRE
87
+ , atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
88
+ , setextHeaderRE = /^ *(?:\={1,}|-{1,})\s*$/
89
+ , textRE = /^[^#!\[\]*_\\<>` "'(~]+/
90
+ , fencedCodeRE = new RegExp("^(" + (modeCfg.fencedCodeBlocks === true ? "~~~+|```+" : modeCfg.fencedCodeBlocks) +
91
+ ")[ \\t]*([\\w+#\-]*)");
92
+
93
+ function switchInline(stream, state, f) {
94
+ state.f = state.inline = f;
95
+ return f(stream, state);
96
+ }
97
+
98
+ function switchBlock(stream, state, f) {
99
+ state.f = state.block = f;
100
+ return f(stream, state);
101
+ }
102
+
103
+ function lineIsEmpty(line) {
104
+ return !line || !/\S/.test(line.string)
105
+ }
106
+
107
+ // Blocks
108
+
109
+ function blankLine(state) {
110
+ // Reset linkTitle state
111
+ state.linkTitle = false;
112
+ // Reset EM state
113
+ state.em = false;
114
+ // Reset STRONG state
115
+ state.strong = false;
116
+ // Reset strikethrough state
117
+ state.strikethrough = false;
118
+ // Reset state.quote
119
+ state.quote = 0;
120
+ // Reset state.indentedCode
121
+ state.indentedCode = false;
122
+ if (htmlModeMissing && state.f == htmlBlock) {
123
+ state.f = inlineNormal;
124
+ state.block = blockNormal;
125
+ }
126
+ // Reset state.trailingSpace
127
+ state.trailingSpace = 0;
128
+ state.trailingSpaceNewLine = false;
129
+ // Mark this line as blank
130
+ state.prevLine = state.thisLine
131
+ state.thisLine = null
132
+ return null;
133
+ }
134
+
135
+ function blockNormal(stream, state) {
136
+
137
+ var sol = stream.sol();
138
+
139
+ var prevLineIsList = state.list !== false,
140
+ prevLineIsIndentedCode = state.indentedCode;
141
+
142
+ state.indentedCode = false;
143
+
144
+ if (prevLineIsList) {
145
+ if (state.indentationDiff >= 0) { // Continued list
146
+ if (state.indentationDiff < 4) { // Only adjust indentation if *not* a code block
147
+ state.indentation -= state.indentationDiff;
148
+ }
149
+ state.list = null;
150
+ } else if (state.indentation > 0) {
151
+ state.list = null;
152
+ } else { // No longer a list
153
+ state.list = false;
154
+ }
155
+ }
156
+
157
+ var match = null;
158
+ if (state.indentationDiff >= 4) {
159
+ stream.skipToEnd();
160
+ if (prevLineIsIndentedCode || lineIsEmpty(state.prevLine)) {
161
+ state.indentation -= 4;
162
+ state.indentedCode = true;
163
+ return tokenTypes.code;
164
+ } else {
165
+ return null;
166
+ }
167
+ } else if (stream.eatSpace()) {
168
+ return null;
169
+ } else if ((match = stream.match(atxHeaderRE)) && match[1].length <= 6) {
170
+ state.header = match[1].length;
171
+ if (modeCfg.highlightFormatting) state.formatting = "header";
172
+ state.f = state.inline;
173
+ return getType(state);
174
+ } else if (!lineIsEmpty(state.prevLine) && !state.quote && !prevLineIsList &&
175
+ !prevLineIsIndentedCode && (match = stream.match(setextHeaderRE))) {
176
+ state.header = match[0].charAt(0) == '=' ? 1 : 2;
177
+ if (modeCfg.highlightFormatting) state.formatting = "header";
178
+ state.f = state.inline;
179
+ return getType(state);
180
+ } else if (stream.eat('>')) {
181
+ state.quote = sol ? 1 : state.quote + 1;
182
+ if (modeCfg.highlightFormatting) state.formatting = "quote";
183
+ stream.eatSpace();
184
+ return getType(state);
185
+ } else if (stream.peek() === '[') {
186
+ return switchInline(stream, state, footnoteLink);
187
+ } else if (stream.match(hrRE, true)) {
188
+ state.hr = true;
189
+ return tokenTypes.hr;
190
+ } else if ((lineIsEmpty(state.prevLine) || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
191
+ var listType = null;
192
+ if (stream.match(ulRE, true)) {
193
+ listType = 'ul';
194
+ } else {
195
+ stream.match(olRE, true);
196
+ listType = 'ol';
197
+ }
198
+ state.indentation = stream.column() + stream.current().length;
199
+ state.list = true;
200
+
201
+ // While this list item's marker's indentation
202
+ // is less than the deepest list item's content's indentation,
203
+ // pop the deepest list item indentation off the stack.
204
+ while (state.listStack && stream.column() < state.listStack[state.listStack.length - 1]) {
205
+ state.listStack.pop();
206
+ }
207
+
208
+ // Add this list item's content's indentation to the stack
209
+ state.listStack.push(state.indentation);
210
+
211
+ if (modeCfg.taskLists && stream.match(taskListRE, false)) {
212
+ state.taskList = true;
213
+ }
214
+ state.f = state.inline;
215
+ if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
216
+ return getType(state);
217
+ } else if (modeCfg.fencedCodeBlocks && (match = stream.match(fencedCodeRE, true))) {
218
+ state.fencedChars = match[1]
219
+ // try switching mode
220
+ state.localMode = getMode(match[2]);
221
+ if (state.localMode) state.localState = CodeMirror.startState(state.localMode);
222
+ state.f = state.block = local;
223
+ if (modeCfg.highlightFormatting) state.formatting = "code-block";
224
+ state.code = -1
225
+ return getType(state);
226
+ }
227
+
228
+ return switchInline(stream, state, state.inline);
229
+ }
230
+
231
+ function htmlBlock(stream, state) {
232
+ var style = htmlMode.token(stream, state.htmlState);
233
+ if (!htmlModeMissing) {
234
+ var inner = CodeMirror.innerMode(htmlMode, state.htmlState)
235
+ if ((inner.mode.name == "xml" && inner.state.tagStart === null &&
236
+ (!inner.state.context && inner.state.tokenize.isInText)) ||
237
+ (state.md_inside && stream.current().indexOf(">") > -1)) {
238
+ state.f = inlineNormal;
239
+ state.block = blockNormal;
240
+ state.htmlState = null;
241
+ }
242
+ }
243
+ return style;
244
+ }
245
+
246
+ function local(stream, state) {
247
+ if (state.fencedChars && stream.match(state.fencedChars, false)) {
248
+ state.localMode = state.localState = null;
249
+ state.f = state.block = leavingLocal;
250
+ return null;
251
+ } else if (state.localMode) {
252
+ return state.localMode.token(stream, state.localState);
253
+ } else {
254
+ stream.skipToEnd();
255
+ return tokenTypes.code;
256
+ }
257
+ }
258
+
259
+ function leavingLocal(stream, state) {
260
+ stream.match(state.fencedChars);
261
+ state.block = blockNormal;
262
+ state.f = inlineNormal;
263
+ state.fencedChars = null;
264
+ if (modeCfg.highlightFormatting) state.formatting = "code-block";
265
+ state.code = 1
266
+ var returnType = getType(state);
267
+ state.code = 0
268
+ return returnType;
269
+ }
270
+
271
+ // Inline
272
+ function getType(state) {
273
+ var styles = [];
274
+
275
+ if (state.formatting) {
276
+ styles.push(tokenTypes.formatting);
277
+
278
+ if (typeof state.formatting === "string") state.formatting = [state.formatting];
279
+
280
+ for (var i = 0; i < state.formatting.length; i++) {
281
+ styles.push(tokenTypes.formatting + "-" + state.formatting[i]);
282
+
283
+ if (state.formatting[i] === "header") {
284
+ styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.header);
285
+ }
286
+
287
+ // Add `formatting-quote` and `formatting-quote-#` for blockquotes
288
+ // Add `error` instead if the maximum blockquote nesting depth is passed
289
+ if (state.formatting[i] === "quote") {
290
+ if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
291
+ styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.quote);
292
+ } else {
293
+ styles.push("error");
294
+ }
295
+ }
296
+ }
297
+ }
298
+
299
+ if (state.taskOpen) {
300
+ styles.push("meta");
301
+ return styles.length ? styles.join(' ') : null;
302
+ }
303
+ if (state.taskClosed) {
304
+ styles.push("property");
305
+ return styles.length ? styles.join(' ') : null;
306
+ }
307
+
308
+ if (state.linkHref) {
309
+ styles.push(tokenTypes.linkHref, "url");
310
+ } else { // Only apply inline styles to non-url text
311
+ if (state.strong) { styles.push(tokenTypes.strong); }
312
+ if (state.em) { styles.push(tokenTypes.em); }
313
+ if (state.strikethrough) { styles.push(tokenTypes.strikethrough); }
314
+ if (state.linkText) { styles.push(tokenTypes.linkText); }
315
+ if (state.code) { styles.push(tokenTypes.code); }
316
+ }
317
+
318
+ if (state.header) { styles.push(tokenTypes.header, tokenTypes.header + "-" + state.header); }
319
+
320
+ if (state.quote) {
321
+ styles.push(tokenTypes.quote);
322
+
323
+ // Add `quote-#` where the maximum for `#` is modeCfg.maxBlockquoteDepth
324
+ if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {
325
+ styles.push(tokenTypes.quote + "-" + state.quote);
326
+ } else {
327
+ styles.push(tokenTypes.quote + "-" + modeCfg.maxBlockquoteDepth);
328
+ }
329
+ }
330
+
331
+ if (state.list !== false) {
332
+ var listMod = (state.listStack.length - 1) % 3;
333
+ if (!listMod) {
334
+ styles.push(tokenTypes.list1);
335
+ } else if (listMod === 1) {
336
+ styles.push(tokenTypes.list2);
337
+ } else {
338
+ styles.push(tokenTypes.list3);
339
+ }
340
+ }
341
+
342
+ if (state.trailingSpaceNewLine) {
343
+ styles.push("trailing-space-new-line");
344
+ } else if (state.trailingSpace) {
345
+ styles.push("trailing-space-" + (state.trailingSpace % 2 ? "a" : "b"));
346
+ }
347
+
348
+ return styles.length ? styles.join(' ') : null;
349
+ }
350
+
351
+ function handleText(stream, state) {
352
+ if (stream.match(textRE, true)) {
353
+ return getType(state);
354
+ }
355
+ return undefined;
356
+ }
357
+
358
+ function inlineNormal(stream, state) {
359
+ var style = state.text(stream, state);
360
+ if (typeof style !== 'undefined')
361
+ return style;
362
+
363
+ if (state.list) { // List marker (*, +, -, 1., etc)
364
+ state.list = null;
365
+ return getType(state);
366
+ }
367
+
368
+ if (state.taskList) {
369
+ var taskOpen = stream.match(taskListRE, true)[1] !== "x";
370
+ if (taskOpen) state.taskOpen = true;
371
+ else state.taskClosed = true;
372
+ if (modeCfg.highlightFormatting) state.formatting = "task";
373
+ state.taskList = false;
374
+ return getType(state);
375
+ }
376
+
377
+ state.taskOpen = false;
378
+ state.taskClosed = false;
379
+
380
+ if (state.header && stream.match(/^#+$/, true)) {
381
+ if (modeCfg.highlightFormatting) state.formatting = "header";
382
+ return getType(state);
383
+ }
384
+
385
+ // Get sol() value now, before character is consumed
386
+ var sol = stream.sol();
387
+
388
+ var ch = stream.next();
389
+
390
+ // Matches link titles present on next line
391
+ if (state.linkTitle) {
392
+ state.linkTitle = false;
393
+ var matchCh = ch;
394
+ if (ch === '(') {
395
+ matchCh = ')';
396
+ }
397
+ matchCh = (matchCh+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
398
+ var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;
399
+ if (stream.match(new RegExp(regex), true)) {
400
+ return tokenTypes.linkHref;
401
+ }
402
+ }
403
+
404
+ // If this block is changed, it may need to be updated in GFM mode
405
+ if (ch === '`') {
406
+ var previousFormatting = state.formatting;
407
+ if (modeCfg.highlightFormatting) state.formatting = "code";
408
+ stream.eatWhile('`');
409
+ var count = stream.current().length
410
+ if (state.code == 0) {
411
+ state.code = count
412
+ return getType(state)
413
+ } else if (count == state.code) { // Must be exact
414
+ var t = getType(state)
415
+ state.code = 0
416
+ return t
417
+ } else {
418
+ state.formatting = previousFormatting
419
+ return getType(state)
420
+ }
421
+ } else if (state.code) {
422
+ return getType(state);
423
+ }
424
+
425
+ if (ch === '\\') {
426
+ stream.next();
427
+ if (modeCfg.highlightFormatting) {
428
+ var type = getType(state);
429
+ var formattingEscape = tokenTypes.formatting + "-escape";
430
+ return type ? type + " " + formattingEscape : formattingEscape;
431
+ }
432
+ }
433
+
434
+ if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
435
+ stream.match(/\[[^\]]*\]/);
436
+ state.inline = state.f = linkHref;
437
+ return tokenTypes.image;
438
+ }
439
+
440
+ if (ch === '[' && stream.match(/[^\]]*\](\(.*\)| ?\[.*?\])/, false)) {
441
+ state.linkText = true;
442
+ if (modeCfg.highlightFormatting) state.formatting = "link";
443
+ return getType(state);
444
+ }
445
+
446
+ if (ch === ']' && state.linkText && stream.match(/\(.*?\)| ?\[.*?\]/, false)) {
447
+ if (modeCfg.highlightFormatting) state.formatting = "link";
448
+ var type = getType(state);
449
+ state.linkText = false;
450
+ state.inline = state.f = linkHref;
451
+ return type;
452
+ }
453
+
454
+ if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) {
455
+ state.f = state.inline = linkInline;
456
+ if (modeCfg.highlightFormatting) state.formatting = "link";
457
+ var type = getType(state);
458
+ if (type){
459
+ type += " ";
460
+ } else {
461
+ type = "";
462
+ }
463
+ return type + tokenTypes.linkInline;
464
+ }
465
+
466
+ if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) {
467
+ state.f = state.inline = linkInline;
468
+ if (modeCfg.highlightFormatting) state.formatting = "link";
469
+ var type = getType(state);
470
+ if (type){
471
+ type += " ";
472
+ } else {
473
+ type = "";
474
+ }
475
+ return type + tokenTypes.linkEmail;
476
+ }
477
+
478
+ if (ch === '<' && stream.match(/^(!--|\w)/, false)) {
479
+ var end = stream.string.indexOf(">", stream.pos);
480
+ if (end != -1) {
481
+ var atts = stream.string.substring(stream.start, end);
482
+ if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) state.md_inside = true;
483
+ }
484
+ stream.backUp(1);
485
+ state.htmlState = CodeMirror.startState(htmlMode);
486
+ return switchBlock(stream, state, htmlBlock);
487
+ }
488
+
489
+ if (ch === '<' && stream.match(/^\/\w*?>/)) {
490
+ state.md_inside = false;
491
+ return "tag";
492
+ }
493
+
494
+ var ignoreUnderscore = false;
495
+ if (!modeCfg.underscoresBreakWords) {
496
+ if (ch === '_' && stream.peek() !== '_' && stream.match(/(\w)/, false)) {
497
+ var prevPos = stream.pos - 2;
498
+ if (prevPos >= 0) {
499
+ var prevCh = stream.string.charAt(prevPos);
500
+ if (prevCh !== '_' && prevCh.match(/(\w)/, false)) {
501
+ ignoreUnderscore = true;
502
+ }
503
+ }
504
+ }
505
+ }
506
+ if (ch === '*' || (ch === '_' && !ignoreUnderscore)) {
507
+ if (sol && stream.peek() === ' ') {
508
+ // Do nothing, surrounded by newline and space
509
+ } else if (state.strong === ch && stream.eat(ch)) { // Remove STRONG
510
+ if (modeCfg.highlightFormatting) state.formatting = "strong";
511
+ var t = getType(state);
512
+ state.strong = false;
513
+ return t;
514
+ } else if (!state.strong && stream.eat(ch)) { // Add STRONG
515
+ state.strong = ch;
516
+ if (modeCfg.highlightFormatting) state.formatting = "strong";
517
+ return getType(state);
518
+ } else if (state.em === ch) { // Remove EM
519
+ if (modeCfg.highlightFormatting) state.formatting = "em";
520
+ var t = getType(state);
521
+ state.em = false;
522
+ return t;
523
+ } else if (!state.em) { // Add EM
524
+ state.em = ch;
525
+ if (modeCfg.highlightFormatting) state.formatting = "em";
526
+ return getType(state);
527
+ }
528
+ } else if (ch === ' ') {
529
+ if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces
530
+ if (stream.peek() === ' ') { // Surrounded by spaces, ignore
531
+ return getType(state);
532
+ } else { // Not surrounded by spaces, back up pointer
533
+ stream.backUp(1);
534
+ }
535
+ }
536
+ }
537
+
538
+ if (modeCfg.strikethrough) {
539
+ if (ch === '~' && stream.eatWhile(ch)) {
540
+ if (state.strikethrough) {// Remove strikethrough
541
+ if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
542
+ var t = getType(state);
543
+ state.strikethrough = false;
544
+ return t;
545
+ } else if (stream.match(/^[^\s]/, false)) {// Add strikethrough
546
+ state.strikethrough = true;
547
+ if (modeCfg.highlightFormatting) state.formatting = "strikethrough";
548
+ return getType(state);
549
+ }
550
+ } else if (ch === ' ') {
551
+ if (stream.match(/^~~/, true)) { // Probably surrounded by space
552
+ if (stream.peek() === ' ') { // Surrounded by spaces, ignore
553
+ return getType(state);
554
+ } else { // Not surrounded by spaces, back up pointer
555
+ stream.backUp(2);
556
+ }
557
+ }
558
+ }
559
+ }
560
+
561
+ if (ch === ' ') {
562
+ if (stream.match(/ +$/, false)) {
563
+ state.trailingSpace++;
564
+ } else if (state.trailingSpace) {
565
+ state.trailingSpaceNewLine = true;
566
+ }
567
+ }
568
+
569
+ return getType(state);
570
+ }
571
+
572
+ function linkInline(stream, state) {
573
+ var ch = stream.next();
574
+
575
+ if (ch === ">") {
576
+ state.f = state.inline = inlineNormal;
577
+ if (modeCfg.highlightFormatting) state.formatting = "link";
578
+ var type = getType(state);
579
+ if (type){
580
+ type += " ";
581
+ } else {
582
+ type = "";
583
+ }
584
+ return type + tokenTypes.linkInline;
585
+ }
586
+
587
+ stream.match(/^[^>]+/, true);
588
+
589
+ return tokenTypes.linkInline;
590
+ }
591
+
592
+ function linkHref(stream, state) {
593
+ // Check if space, and return NULL if so (to avoid marking the space)
594
+ if(stream.eatSpace()){
595
+ return null;
596
+ }
597
+ var ch = stream.next();
598
+ if (ch === '(' || ch === '[') {
599
+ state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]", 0);
600
+ if (modeCfg.highlightFormatting) state.formatting = "link-string";
601
+ state.linkHref = true;
602
+ return getType(state);
603
+ }
604
+ return 'error';
605
+ }
606
+
607
+ var linkRE = {
608
+ ")": /^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/,
609
+ "]": /^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\\]]|\\.)*\])*?(?=\])/
610
+ }
611
+
612
+ function getLinkHrefInside(endChar) {
613
+ return function(stream, state) {
614
+ var ch = stream.next();
615
+
616
+ if (ch === endChar) {
617
+ state.f = state.inline = inlineNormal;
618
+ if (modeCfg.highlightFormatting) state.formatting = "link-string";
619
+ var returnState = getType(state);
620
+ state.linkHref = false;
621
+ return returnState;
622
+ }
623
+
624
+ stream.match(linkRE[endChar])
625
+ state.linkHref = true;
626
+ return getType(state);
627
+ };
628
+ }
629
+
630
+ function footnoteLink(stream, state) {
631
+ if (stream.match(/^([^\]\\]|\\.)*\]:/, false)) {
632
+ state.f = footnoteLinkInside;
633
+ stream.next(); // Consume [
634
+ if (modeCfg.highlightFormatting) state.formatting = "link";
635
+ state.linkText = true;
636
+ return getType(state);
637
+ }
638
+ return switchInline(stream, state, inlineNormal);
639
+ }
640
+
641
+ function footnoteLinkInside(stream, state) {
642
+ if (stream.match(/^\]:/, true)) {
643
+ state.f = state.inline = footnoteUrl;
644
+ if (modeCfg.highlightFormatting) state.formatting = "link";
645
+ var returnType = getType(state);
646
+ state.linkText = false;
647
+ return returnType;
648
+ }
649
+
650
+ stream.match(/^([^\]\\]|\\.)+/, true);
651
+
652
+ return tokenTypes.linkText;
653
+ }
654
+
655
+ function footnoteUrl(stream, state) {
656
+ // Check if space, and return NULL if so (to avoid marking the space)
657
+ if(stream.eatSpace()){
658
+ return null;
659
+ }
660
+ // Match URL
661
+ stream.match(/^[^\s]+/, true);
662
+ // Check for link title
663
+ if (stream.peek() === undefined) { // End of line, set flag to check next line
664
+ state.linkTitle = true;
665
+ } else { // More content on line, check if link title
666
+ stream.match(/^(?:\s+(?:"(?:[^"\\]|\\\\|\\.)+"|'(?:[^'\\]|\\\\|\\.)+'|\((?:[^)\\]|\\\\|\\.)+\)))?/, true);
667
+ }
668
+ state.f = state.inline = inlineNormal;
669
+ return tokenTypes.linkHref + " url";
670
+ }
671
+
672
+ var mode = {
673
+ startState: function() {
674
+ return {
675
+ f: blockNormal,
676
+
677
+ prevLine: null,
678
+ thisLine: null,
679
+
680
+ block: blockNormal,
681
+ htmlState: null,
682
+ indentation: 0,
683
+
684
+ inline: inlineNormal,
685
+ text: handleText,
686
+
687
+ formatting: false,
688
+ linkText: false,
689
+ linkHref: false,
690
+ linkTitle: false,
691
+ code: 0,
692
+ em: false,
693
+ strong: false,
694
+ header: 0,
695
+ hr: false,
696
+ taskList: false,
697
+ list: false,
698
+ listStack: [],
699
+ quote: 0,
700
+ trailingSpace: 0,
701
+ trailingSpaceNewLine: false,
702
+ strikethrough: false,
703
+ fencedChars: null
704
+ };
705
+ },
706
+
707
+ copyState: function(s) {
708
+ return {
709
+ f: s.f,
710
+
711
+ prevLine: s.prevLine,
712
+ thisLine: s.thisLine,
713
+
714
+ block: s.block,
715
+ htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),
716
+ indentation: s.indentation,
717
+
718
+ localMode: s.localMode,
719
+ localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,
720
+
721
+ inline: s.inline,
722
+ text: s.text,
723
+ formatting: false,
724
+ linkTitle: s.linkTitle,
725
+ code: s.code,
726
+ em: s.em,
727
+ strong: s.strong,
728
+ strikethrough: s.strikethrough,
729
+ header: s.header,
730
+ hr: s.hr,
731
+ taskList: s.taskList,
732
+ list: s.list,
733
+ listStack: s.listStack.slice(0),
734
+ quote: s.quote,
735
+ indentedCode: s.indentedCode,
736
+ trailingSpace: s.trailingSpace,
737
+ trailingSpaceNewLine: s.trailingSpaceNewLine,
738
+ md_inside: s.md_inside,
739
+ fencedChars: s.fencedChars
740
+ };
741
+ },
742
+
743
+ token: function(stream, state) {
744
+
745
+ // Reset state.formatting
746
+ state.formatting = false;
747
+
748
+ if (stream != state.thisLine) {
749
+ var forceBlankLine = state.header || state.hr;
750
+
751
+ // Reset state.header and state.hr
752
+ state.header = 0;
753
+ state.hr = false;
754
+
755
+ if (stream.match(/^\s*$/, true) || forceBlankLine) {
756
+ blankLine(state);
757
+ if (!forceBlankLine) return null
758
+ state.prevLine = null
759
+ }
760
+
761
+ state.prevLine = state.thisLine
762
+ state.thisLine = stream
763
+
764
+ // Reset state.taskList
765
+ state.taskList = false;
766
+
767
+ // Reset state.trailingSpace
768
+ state.trailingSpace = 0;
769
+ state.trailingSpaceNewLine = false;
770
+
771
+ state.f = state.block;
772
+ var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, ' ').length;
773
+ state.indentationDiff = Math.min(indentation - state.indentation, 4);
774
+ state.indentation = state.indentation + state.indentationDiff;
775
+ if (indentation > 0) return null;
776
+ }
777
+ return state.f(stream, state);
778
+ },
779
+
780
+ innerMode: function(state) {
781
+ if (state.block == htmlBlock) return {state: state.htmlState, mode: htmlMode};
782
+ if (state.localState) return {state: state.localState, mode: state.localMode};
783
+ return {state: state, mode: mode};
784
+ },
785
+
786
+ blankLine: blankLine,
787
+
788
+ getType: getType,
789
+
790
+ fold: "markdown"
791
+ };
792
+ return mode;
793
+ }, "xml");
794
+
795
+ CodeMirror.defineMIME("text/x-markdown", "markdown");
796
+
797
+ });