administrate-field-simple_mde_markdown 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (419) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +72 -0
  3. data/.circleci/setup-rubygems.sh +3 -0
  4. data/.gitignore +11 -0
  5. data/.rspec +3 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +8 -0
  8. data/Gemfile.lock +196 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +44 -0
  11. data/Rakefile +8 -0
  12. data/administrate-field-simple_mde_markdown.gemspec +31 -0
  13. data/app/assets/javascripts/administrate-field-simple_mde_markdown/application.js +6 -0
  14. data/app/assets/stylesheets/administrate-field-simple_mde_markdown/application.css +3 -0
  15. data/app/views/fields/simple_mde_markdown/_form.html.erb +6 -0
  16. data/app/views/fields/simple_mde_markdown/_index.html.erb +1 -0
  17. data/app/views/fields/simple_mde_markdown/_show.html.erb +1 -0
  18. data/lib/administrate/field/simple_mde_markdown.rb +31 -0
  19. data/node_modules/.bin/marked +1 -0
  20. data/node_modules/codemirror-spell-checker/.eslintrc +23 -0
  21. data/node_modules/codemirror-spell-checker/.npmignore +2 -0
  22. data/node_modules/codemirror-spell-checker/.travis.yml +18 -0
  23. data/node_modules/codemirror-spell-checker/CONTRIBUTING 2.md +10 -0
  24. data/node_modules/codemirror-spell-checker/CONTRIBUTING.md +10 -0
  25. data/node_modules/codemirror-spell-checker/LICENSE +22 -0
  26. data/node_modules/codemirror-spell-checker/README.md +50 -0
  27. data/node_modules/codemirror-spell-checker/bower.json +27 -0
  28. data/node_modules/codemirror-spell-checker/debug/.spell-checker 2.css.icloud +0 -0
  29. data/node_modules/codemirror-spell-checker/debug/spell-checker.css +9 -0
  30. data/node_modules/codemirror-spell-checker/debug/spell-checker.debug.js +2844 -0
  31. data/node_modules/codemirror-spell-checker/debug/spell-checker.js +2841 -0
  32. data/node_modules/codemirror-spell-checker/dist/.spell-checker.min 2.css.icloud +0 -0
  33. data/node_modules/codemirror-spell-checker/dist/en_US.aff +201 -0
  34. data/node_modules/codemirror-spell-checker/dist/en_US.dic +62120 -0
  35. data/node_modules/codemirror-spell-checker/dist/spell-checker.min 2.js +7 -0
  36. data/node_modules/codemirror-spell-checker/dist/spell-checker.min.css +7 -0
  37. data/node_modules/codemirror-spell-checker/dist/spell-checker.min.js +7 -0
  38. data/node_modules/codemirror-spell-checker/gulpfile.js +94 -0
  39. data/node_modules/codemirror-spell-checker/package.json +75 -0
  40. data/node_modules/codemirror-spell-checker/src/css/spell-checker.css +3 -0
  41. data/node_modules/codemirror-spell-checker/src/data/en_US.aff +201 -0
  42. data/node_modules/codemirror-spell-checker/src/data/en_US.dic +62120 -0
  43. data/node_modules/codemirror-spell-checker/src/js/spell-checker.js +119 -0
  44. data/node_modules/codemirror/.package 2.json.icloud +0 -0
  45. data/node_modules/codemirror/AUTHORS +773 -0
  46. data/node_modules/codemirror/CHANGELOG.md +1486 -0
  47. data/node_modules/codemirror/CONTRIBUTING.md +92 -0
  48. data/node_modules/codemirror/LICENSE +21 -0
  49. data/node_modules/codemirror/README.md +49 -0
  50. data/node_modules/codemirror/addon/comment/comment.js +209 -0
  51. data/node_modules/codemirror/addon/comment/continuecomment.js +78 -0
  52. data/node_modules/codemirror/addon/dialog/dialog.css +32 -0
  53. data/node_modules/codemirror/addon/dialog/dialog.js +161 -0
  54. data/node_modules/codemirror/addon/display/autorefresh.js +47 -0
  55. data/node_modules/codemirror/addon/display/fullscreen.css +6 -0
  56. data/node_modules/codemirror/addon/display/fullscreen.js +41 -0
  57. data/node_modules/codemirror/addon/display/panel.js +127 -0
  58. data/node_modules/codemirror/addon/display/placeholder.js +63 -0
  59. data/node_modules/codemirror/addon/display/rulers.js +51 -0
  60. data/node_modules/codemirror/addon/edit/closebrackets.js +187 -0
  61. data/node_modules/codemirror/addon/edit/closetag.js +175 -0
  62. data/node_modules/codemirror/addon/edit/continuelist.js +89 -0
  63. data/node_modules/codemirror/addon/edit/matchbrackets.js +145 -0
  64. data/node_modules/codemirror/addon/edit/matchtags.js +66 -0
  65. data/node_modules/codemirror/addon/edit/trailingspace.js +27 -0
  66. data/node_modules/codemirror/addon/fold/brace-fold.js +105 -0
  67. data/node_modules/codemirror/addon/fold/comment-fold.js +59 -0
  68. data/node_modules/codemirror/addon/fold/foldcode.js +152 -0
  69. data/node_modules/codemirror/addon/fold/foldgutter.css +20 -0
  70. data/node_modules/codemirror/addon/fold/foldgutter.js +146 -0
  71. data/node_modules/codemirror/addon/fold/indent-fold.js +48 -0
  72. data/node_modules/codemirror/addon/fold/markdown-fold.js +49 -0
  73. data/node_modules/codemirror/addon/fold/xml-fold.js +184 -0
  74. data/node_modules/codemirror/addon/hint/anyword-hint.js +41 -0
  75. data/node_modules/codemirror/addon/hint/css-hint.js +60 -0
  76. data/node_modules/codemirror/addon/hint/html-hint.js +348 -0
  77. data/node_modules/codemirror/addon/hint/javascript-hint.js +157 -0
  78. data/node_modules/codemirror/addon/hint/show-hint.css +36 -0
  79. data/node_modules/codemirror/addon/hint/show-hint.js +434 -0
  80. data/node_modules/codemirror/addon/hint/sql-hint.js +299 -0
  81. data/node_modules/codemirror/addon/hint/xml-hint.js +110 -0
  82. data/node_modules/codemirror/addon/lint/coffeescript-lint.js +47 -0
  83. data/node_modules/codemirror/addon/lint/css-lint.js +40 -0
  84. data/node_modules/codemirror/addon/lint/html-lint.js +53 -0
  85. data/node_modules/codemirror/addon/lint/javascript-lint.js +63 -0
  86. data/node_modules/codemirror/addon/lint/json-lint.js +40 -0
  87. data/node_modules/codemirror/addon/lint/lint.css +73 -0
  88. data/node_modules/codemirror/addon/lint/lint.js +252 -0
  89. data/node_modules/codemirror/addon/lint/yaml-lint.js +41 -0
  90. data/node_modules/codemirror/addon/merge/merge.css +119 -0
  91. data/node_modules/codemirror/addon/merge/merge.js +1002 -0
  92. data/node_modules/codemirror/addon/mode/loadmode.js +64 -0
  93. data/node_modules/codemirror/addon/mode/multiplex.js +131 -0
  94. data/node_modules/codemirror/addon/mode/multiplex_test.js +33 -0
  95. data/node_modules/codemirror/addon/mode/overlay.js +90 -0
  96. data/node_modules/codemirror/addon/mode/simple.js +216 -0
  97. data/node_modules/codemirror/addon/runmode/colorize.js +40 -0
  98. data/node_modules/codemirror/addon/runmode/runmode-standalone.js +158 -0
  99. data/node_modules/codemirror/addon/runmode/runmode.js +72 -0
  100. data/node_modules/codemirror/addon/runmode/runmode.node.js +197 -0
  101. data/node_modules/codemirror/addon/scroll/annotatescrollbar.js +122 -0
  102. data/node_modules/codemirror/addon/scroll/scrollpastend.js +48 -0
  103. data/node_modules/codemirror/addon/scroll/simplescrollbars.css +66 -0
  104. data/node_modules/codemirror/addon/scroll/simplescrollbars.js +152 -0
  105. data/node_modules/codemirror/addon/search/jump-to-line.js +50 -0
  106. data/node_modules/codemirror/addon/search/match-highlighter.js +165 -0
  107. data/node_modules/codemirror/addon/search/matchesonscrollbar.css +8 -0
  108. data/node_modules/codemirror/addon/search/matchesonscrollbar.js +97 -0
  109. data/node_modules/codemirror/addon/search/search.js +258 -0
  110. data/node_modules/codemirror/addon/search/searchcursor.js +293 -0
  111. data/node_modules/codemirror/addon/selection/active-line.js +72 -0
  112. data/node_modules/codemirror/addon/selection/mark-selection.js +119 -0
  113. data/node_modules/codemirror/addon/selection/selection-pointer.js +98 -0
  114. data/node_modules/codemirror/addon/tern/tern.css +87 -0
  115. data/node_modules/codemirror/addon/tern/tern.js +718 -0
  116. data/node_modules/codemirror/addon/tern/worker.js +44 -0
  117. data/node_modules/codemirror/addon/wrap/hardwrap.js +145 -0
  118. data/node_modules/codemirror/bin/source-highlight +48 -0
  119. data/node_modules/codemirror/keymap/emacs.js +417 -0
  120. data/node_modules/codemirror/keymap/sublime.js +691 -0
  121. data/node_modules/codemirror/keymap/vim.js +5467 -0
  122. data/node_modules/codemirror/lib/codemirror.css +346 -0
  123. data/node_modules/codemirror/lib/codemirror.js +9698 -0
  124. data/node_modules/codemirror/mode/apl/apl.js +174 -0
  125. data/node_modules/codemirror/mode/asciiarmor/asciiarmor.js +74 -0
  126. data/node_modules/codemirror/mode/asn.1/asn.1.js +204 -0
  127. data/node_modules/codemirror/mode/asterisk/asterisk.js +196 -0
  128. data/node_modules/codemirror/mode/brainfuck/brainfuck.js +85 -0
  129. data/node_modules/codemirror/mode/clike/clike.js +879 -0
  130. data/node_modules/codemirror/mode/clojure/clojure.js +292 -0
  131. data/node_modules/codemirror/mode/cmake/cmake.js +97 -0
  132. data/node_modules/codemirror/mode/cobol/cobol.js +255 -0
  133. data/node_modules/codemirror/mode/coffeescript/coffeescript.js +359 -0
  134. data/node_modules/codemirror/mode/commonlisp/commonlisp.js +124 -0
  135. data/node_modules/codemirror/mode/crystal/crystal.js +433 -0
  136. data/node_modules/codemirror/mode/css/css.js +832 -0
  137. data/node_modules/codemirror/mode/cypher/cypher.js +150 -0
  138. data/node_modules/codemirror/mode/d/d.js +223 -0
  139. data/node_modules/codemirror/mode/dart/dart.js +157 -0
  140. data/node_modules/codemirror/mode/diff/diff.js +47 -0
  141. data/node_modules/codemirror/mode/django/django.js +356 -0
  142. data/node_modules/codemirror/mode/dockerfile/dockerfile.js +211 -0
  143. data/node_modules/codemirror/mode/dtd/dtd.js +142 -0
  144. data/node_modules/codemirror/mode/dylan/dylan.js +352 -0
  145. data/node_modules/codemirror/mode/ebnf/ebnf.js +195 -0
  146. data/node_modules/codemirror/mode/ecl/ecl.js +206 -0
  147. data/node_modules/codemirror/mode/eiffel/eiffel.js +160 -0
  148. data/node_modules/codemirror/mode/elm/elm.js +205 -0
  149. data/node_modules/codemirror/mode/erlang/erlang.js +619 -0
  150. data/node_modules/codemirror/mode/factor/factor.js +85 -0
  151. data/node_modules/codemirror/mode/fcl/fcl.js +173 -0
  152. data/node_modules/codemirror/mode/forth/forth.js +180 -0
  153. data/node_modules/codemirror/mode/fortran/fortran.js +188 -0
  154. data/node_modules/codemirror/mode/gas/gas.js +345 -0
  155. data/node_modules/codemirror/mode/gfm/gfm.js +129 -0
  156. data/node_modules/codemirror/mode/gherkin/gherkin.js +178 -0
  157. data/node_modules/codemirror/mode/go/go.js +187 -0
  158. data/node_modules/codemirror/mode/groovy/groovy.js +230 -0
  159. data/node_modules/codemirror/mode/haml/haml.js +161 -0
  160. data/node_modules/codemirror/mode/handlebars/handlebars.js +66 -0
  161. data/node_modules/codemirror/mode/haskell-literate/haskell-literate.js +43 -0
  162. data/node_modules/codemirror/mode/haskell/haskell.js +268 -0
  163. data/node_modules/codemirror/mode/haxe/haxe.js +515 -0
  164. data/node_modules/codemirror/mode/htmlembedded/htmlembedded.js +37 -0
  165. data/node_modules/codemirror/mode/htmlmixed/htmlmixed.js +152 -0
  166. data/node_modules/codemirror/mode/http/http.js +113 -0
  167. data/node_modules/codemirror/mode/idl/idl.js +290 -0
  168. data/node_modules/codemirror/mode/javascript/javascript.js +899 -0
  169. data/node_modules/codemirror/mode/jinja2/jinja2.js +144 -0
  170. data/node_modules/codemirror/mode/jsx/jsx.js +148 -0
  171. data/node_modules/codemirror/mode/julia/julia.js +433 -0
  172. data/node_modules/codemirror/mode/livescript/livescript.js +280 -0
  173. data/node_modules/codemirror/mode/lua/lua.js +159 -0
  174. data/node_modules/codemirror/mode/markdown/markdown.js +884 -0
  175. data/node_modules/codemirror/mode/mathematica/mathematica.js +176 -0
  176. data/node_modules/codemirror/mode/mbox/mbox.js +129 -0
  177. data/node_modules/codemirror/mode/meta.js +217 -0
  178. data/node_modules/codemirror/mode/mirc/mirc.js +193 -0
  179. data/node_modules/codemirror/mode/mllike/mllike.js +359 -0
  180. data/node_modules/codemirror/mode/modelica/modelica.js +245 -0
  181. data/node_modules/codemirror/mode/mscgen/mscgen.js +175 -0
  182. data/node_modules/codemirror/mode/mumps/mumps.js +148 -0
  183. data/node_modules/codemirror/mode/nginx/nginx.js +178 -0
  184. data/node_modules/codemirror/mode/nsis/nsis.js +95 -0
  185. data/node_modules/codemirror/mode/ntriples/ntriples.js +195 -0
  186. data/node_modules/codemirror/mode/octave/octave.js +139 -0
  187. data/node_modules/codemirror/mode/oz/oz.js +252 -0
  188. data/node_modules/codemirror/mode/pascal/pascal.js +121 -0
  189. data/node_modules/codemirror/mode/pegjs/pegjs.js +114 -0
  190. data/node_modules/codemirror/mode/perl/perl.js +837 -0
  191. data/node_modules/codemirror/mode/php/php.js +234 -0
  192. data/node_modules/codemirror/mode/pig/pig.js +178 -0
  193. data/node_modules/codemirror/mode/powershell/powershell.js +398 -0
  194. data/node_modules/codemirror/mode/properties/properties 2.js +78 -0
  195. data/node_modules/codemirror/mode/properties/properties.js +78 -0
  196. data/node_modules/codemirror/mode/protobuf/protobuf.js +69 -0
  197. data/node_modules/codemirror/mode/pug/pug.js +591 -0
  198. data/node_modules/codemirror/mode/puppet/puppet.js +220 -0
  199. data/node_modules/codemirror/mode/python/python.js +409 -0
  200. data/node_modules/codemirror/mode/q/q.js +139 -0
  201. data/node_modules/codemirror/mode/r/r.js +190 -0
  202. data/node_modules/codemirror/mode/rpm/changes/index.html +66 -0
  203. data/node_modules/codemirror/mode/rpm/rpm.js +109 -0
  204. data/node_modules/codemirror/mode/rst/rst.js +557 -0
  205. data/node_modules/codemirror/mode/ruby/ruby.js +296 -0
  206. data/node_modules/codemirror/mode/rust/rust.js +72 -0
  207. data/node_modules/codemirror/mode/sas/sas.js +303 -0
  208. data/node_modules/codemirror/mode/sass/sass.js +454 -0
  209. data/node_modules/codemirror/mode/scheme/scheme.js +265 -0
  210. data/node_modules/codemirror/mode/shell/shell.js +152 -0
  211. data/node_modules/codemirror/mode/sieve/sieve.js +193 -0
  212. data/node_modules/codemirror/mode/slim/slim.js +575 -0
  213. data/node_modules/codemirror/mode/smalltalk/smalltalk.js +168 -0
  214. data/node_modules/codemirror/mode/smarty/smarty.js +225 -0
  215. data/node_modules/codemirror/mode/solr/solr.js +104 -0
  216. data/node_modules/codemirror/mode/soy/soy 2.js +359 -0
  217. data/node_modules/codemirror/mode/soy/soy.js +235 -0
  218. data/node_modules/codemirror/mode/sparql/sparql.js +180 -0
  219. data/node_modules/codemirror/mode/spreadsheet/spreadsheet.js +112 -0
  220. data/node_modules/codemirror/mode/sql/sql.js +499 -0
  221. data/node_modules/codemirror/mode/stex/stex.js +264 -0
  222. data/node_modules/codemirror/mode/stylus/stylus.js +771 -0
  223. data/node_modules/codemirror/mode/swift/swift.js +219 -0
  224. data/node_modules/codemirror/mode/tcl/tcl.js +139 -0
  225. data/node_modules/codemirror/mode/textile/textile.js +469 -0
  226. data/node_modules/codemirror/mode/tiddlywiki/tiddlywiki.css +14 -0
  227. data/node_modules/codemirror/mode/tiddlywiki/tiddlywiki.js +308 -0
  228. data/node_modules/codemirror/mode/tiki/tiki.css +26 -0
  229. data/node_modules/codemirror/mode/tiki/tiki.js +312 -0
  230. data/node_modules/codemirror/mode/toml/toml.js +88 -0
  231. data/node_modules/codemirror/mode/tornado/tornado.js +68 -0
  232. data/node_modules/codemirror/mode/troff/troff.js +84 -0
  233. data/node_modules/codemirror/mode/ttcn-cfg/ttcn-cfg.js +214 -0
  234. data/node_modules/codemirror/mode/ttcn/ttcn.js +283 -0
  235. data/node_modules/codemirror/mode/turtle/turtle.js +162 -0
  236. data/node_modules/codemirror/mode/twig/twig.js +141 -0
  237. data/node_modules/codemirror/mode/vb/vb.js +275 -0
  238. data/node_modules/codemirror/mode/vbscript/vbscript.js +350 -0
  239. data/node_modules/codemirror/mode/velocity/velocity.js +201 -0
  240. data/node_modules/codemirror/mode/verilog/verilog.js +675 -0
  241. data/node_modules/codemirror/mode/vhdl/vhdl.js +189 -0
  242. data/node_modules/codemirror/mode/vue/vue.js +77 -0
  243. data/node_modules/codemirror/mode/webidl/webidl.js +195 -0
  244. data/node_modules/codemirror/mode/xml/xml.js +402 -0
  245. data/node_modules/codemirror/mode/xquery/xquery.js +448 -0
  246. data/node_modules/codemirror/mode/yacas/yacas.js +204 -0
  247. data/node_modules/codemirror/mode/yaml-frontmatter/yaml-frontmatter.js +68 -0
  248. data/node_modules/codemirror/mode/yaml/yaml.js +120 -0
  249. data/node_modules/codemirror/mode/z80/z80.js +116 -0
  250. data/node_modules/codemirror/package.json +2395 -0
  251. data/node_modules/codemirror/rollup.config.js +20 -0
  252. data/node_modules/codemirror/src/codemirror.js +3 -0
  253. data/node_modules/codemirror/src/display/Display.js +106 -0
  254. data/node_modules/codemirror/src/display/focus.js +47 -0
  255. data/node_modules/codemirror/src/display/gutters.js +34 -0
  256. data/node_modules/codemirror/src/display/highlight_worker.js +55 -0
  257. data/node_modules/codemirror/src/display/line_numbers.js +48 -0
  258. data/node_modules/codemirror/src/display/mode_state.js +22 -0
  259. data/node_modules/codemirror/src/display/operations.js +205 -0
  260. data/node_modules/codemirror/src/display/scroll_events.js +115 -0
  261. data/node_modules/codemirror/src/display/scrollbars.js +193 -0
  262. data/node_modules/codemirror/src/display/scrolling.js +184 -0
  263. data/node_modules/codemirror/src/display/selection.js +158 -0
  264. data/node_modules/codemirror/src/display/update_display.js +260 -0
  265. data/node_modules/codemirror/src/display/update_line.js +188 -0
  266. data/node_modules/codemirror/src/display/update_lines.js +64 -0
  267. data/node_modules/codemirror/src/display/view_tracking.js +153 -0
  268. data/node_modules/codemirror/src/edit/CodeMirror.js +215 -0
  269. data/node_modules/codemirror/src/edit/commands.js +178 -0
  270. data/node_modules/codemirror/src/edit/deleteNearSelection.js +30 -0
  271. data/node_modules/codemirror/src/edit/drop_events.js +119 -0
  272. data/node_modules/codemirror/src/edit/fromTextArea.js +61 -0
  273. data/node_modules/codemirror/src/edit/global_events.js +42 -0
  274. data/node_modules/codemirror/src/edit/key_events.js +159 -0
  275. data/node_modules/codemirror/src/edit/legacy.js +62 -0
  276. data/node_modules/codemirror/src/edit/main.js +69 -0
  277. data/node_modules/codemirror/src/edit/methods.js +544 -0
  278. data/node_modules/codemirror/src/edit/mouse_events.js +407 -0
  279. data/node_modules/codemirror/src/edit/options.js +193 -0
  280. data/node_modules/codemirror/src/edit/utils.js +7 -0
  281. data/node_modules/codemirror/src/input/ContentEditableInput.js +527 -0
  282. data/node_modules/codemirror/src/input/TextareaInput.js +355 -0
  283. data/node_modules/codemirror/src/input/indent.js +71 -0
  284. data/node_modules/codemirror/src/input/input.js +135 -0
  285. data/node_modules/codemirror/src/input/keymap.js +148 -0
  286. data/node_modules/codemirror/src/input/keynames.js +17 -0
  287. data/node_modules/codemirror/src/input/movement.js +110 -0
  288. data/node_modules/codemirror/src/line/highlight.js +284 -0
  289. data/node_modules/codemirror/src/line/line_data.js +339 -0
  290. data/node_modules/codemirror/src/line/pos.js +40 -0
  291. data/node_modules/codemirror/src/line/saw_special_spans.js +10 -0
  292. data/node_modules/codemirror/src/line/spans.js +382 -0
  293. data/node_modules/codemirror/src/line/utils_line.js +85 -0
  294. data/node_modules/codemirror/src/measurement/position_measurement.js +699 -0
  295. data/node_modules/codemirror/src/measurement/widgets.js +26 -0
  296. data/node_modules/codemirror/src/model/Doc.js +432 -0
  297. data/node_modules/codemirror/src/model/change_measurement.js +61 -0
  298. data/node_modules/codemirror/src/model/changes.js +333 -0
  299. data/node_modules/codemirror/src/model/chunk.js +167 -0
  300. data/node_modules/codemirror/src/model/document_data.js +111 -0
  301. data/node_modules/codemirror/src/model/history.js +228 -0
  302. data/node_modules/codemirror/src/model/line_widget.js +78 -0
  303. data/node_modules/codemirror/src/model/mark_text.js +292 -0
  304. data/node_modules/codemirror/src/model/selection.js +84 -0
  305. data/node_modules/codemirror/src/model/selection_updates.js +208 -0
  306. data/node_modules/codemirror/src/modes.js +96 -0
  307. data/node_modules/codemirror/src/util/StringStream.js +90 -0
  308. data/node_modules/codemirror/src/util/bidi.js +214 -0
  309. data/node_modules/codemirror/src/util/browser.js +33 -0
  310. data/node_modules/codemirror/src/util/dom.js +97 -0
  311. data/node_modules/codemirror/src/util/event.js +103 -0
  312. data/node_modules/codemirror/src/util/feature_detection.js +84 -0
  313. data/node_modules/codemirror/src/util/misc.js +150 -0
  314. data/node_modules/codemirror/src/util/operation_group.js +72 -0
  315. data/node_modules/codemirror/theme/3024-day.css +41 -0
  316. data/node_modules/codemirror/theme/3024-night.css +39 -0
  317. data/node_modules/codemirror/theme/abcdef.css +32 -0
  318. data/node_modules/codemirror/theme/ambiance-mobile.css +5 -0
  319. data/node_modules/codemirror/theme/ambiance.css +74 -0
  320. data/node_modules/codemirror/theme/base16-dark.css +38 -0
  321. data/node_modules/codemirror/theme/base16-light.css +38 -0
  322. data/node_modules/codemirror/theme/bespin.css +34 -0
  323. data/node_modules/codemirror/theme/blackboard.css +32 -0
  324. data/node_modules/codemirror/theme/cobalt.css +25 -0
  325. data/node_modules/codemirror/theme/colorforth.css +33 -0
  326. data/node_modules/codemirror/theme/darcula.css +46 -0
  327. data/node_modules/codemirror/theme/dracula.css +40 -0
  328. data/node_modules/codemirror/theme/duotone-dark.css +35 -0
  329. data/node_modules/codemirror/theme/duotone-light.css +36 -0
  330. data/node_modules/codemirror/theme/eclipse.css +23 -0
  331. data/node_modules/codemirror/theme/elegant.css +13 -0
  332. data/node_modules/codemirror/theme/erlang-dark.css +34 -0
  333. data/node_modules/codemirror/theme/gruvbox-dark.css +37 -0
  334. data/node_modules/codemirror/theme/hopscotch.css +34 -0
  335. data/node_modules/codemirror/theme/icecoder.css +43 -0
  336. data/node_modules/codemirror/theme/idea.css +42 -0
  337. data/node_modules/codemirror/theme/isotope.css +34 -0
  338. data/node_modules/codemirror/theme/lesser-dark.css +47 -0
  339. data/node_modules/codemirror/theme/liquibyte.css +95 -0
  340. data/node_modules/codemirror/theme/lucario.css +37 -0
  341. data/node_modules/codemirror/theme/material.css +53 -0
  342. data/node_modules/codemirror/theme/mbo.css +37 -0
  343. data/node_modules/codemirror/theme/mdn-like.css +46 -0
  344. data/node_modules/codemirror/theme/midnight.css +43 -0
  345. data/node_modules/codemirror/theme/monokai.css +41 -0
  346. data/node_modules/codemirror/theme/neat.css +12 -0
  347. data/node_modules/codemirror/theme/neo.css +43 -0
  348. data/node_modules/codemirror/theme/night.css +27 -0
  349. data/node_modules/codemirror/theme/oceanic-next.css +44 -0
  350. data/node_modules/codemirror/theme/panda-syntax.css +85 -0
  351. data/node_modules/codemirror/theme/paraiso-dark.css +38 -0
  352. data/node_modules/codemirror/theme/paraiso-light.css +38 -0
  353. data/node_modules/codemirror/theme/pastel-on-dark.css +52 -0
  354. data/node_modules/codemirror/theme/railscasts.css +34 -0
  355. data/node_modules/codemirror/theme/rubyblue.css +25 -0
  356. data/node_modules/codemirror/theme/seti.css +44 -0
  357. data/node_modules/codemirror/theme/shadowfox.css +52 -0
  358. data/node_modules/codemirror/theme/solarized.css +168 -0
  359. data/node_modules/codemirror/theme/ssms.css +16 -0
  360. data/node_modules/codemirror/theme/the-matrix.css +30 -0
  361. data/node_modules/codemirror/theme/tomorrow-night-bright.css +35 -0
  362. data/node_modules/codemirror/theme/tomorrow-night-eighties.css +38 -0
  363. data/node_modules/codemirror/theme/ttcn.css +64 -0
  364. data/node_modules/codemirror/theme/twilight.css +32 -0
  365. data/node_modules/codemirror/theme/vibrant-ink.css +34 -0
  366. data/node_modules/codemirror/theme/xq-dark.css +53 -0
  367. data/node_modules/codemirror/theme/xq-light.css +43 -0
  368. data/node_modules/codemirror/theme/yeti.css +44 -0
  369. data/node_modules/codemirror/theme/zenburn.css +37 -0
  370. data/node_modules/marked/.editorconfig +16 -0
  371. data/node_modules/marked/.eslintignore +1 -0
  372. data/node_modules/marked/.eslintrc.json +28 -0
  373. data/node_modules/marked/.package 2.json.icloud +0 -0
  374. data/node_modules/marked/.travis.yml +47 -0
  375. data/node_modules/marked/Makefile +15 -0
  376. data/node_modules/marked/Makefile 2 +15 -0
  377. data/node_modules/marked/README 2.md +75 -0
  378. data/node_modules/marked/README.md +75 -0
  379. data/node_modules/marked/bin/marked +199 -0
  380. data/node_modules/marked/bower.json +23 -0
  381. data/node_modules/marked/component.json +10 -0
  382. data/node_modules/marked/index.js +1 -0
  383. data/node_modules/marked/jasmine.json +11 -0
  384. data/node_modules/marked/lib/marked 2.js +1604 -0
  385. data/node_modules/marked/lib/marked.js +1604 -0
  386. data/node_modules/marked/man/marked.1 +91 -0
  387. data/node_modules/marked/man/marked.1.txt +96 -0
  388. data/node_modules/marked/marked.min.js +6 -0
  389. data/node_modules/marked/package.json +95 -0
  390. data/node_modules/simplemde/.eslintrc +23 -0
  391. data/node_modules/simplemde/.npmignore +9 -0
  392. data/node_modules/simplemde/.travis.yml +18 -0
  393. data/node_modules/simplemde/CONTRIBUTING 2.md +10 -0
  394. data/node_modules/simplemde/CONTRIBUTING.md +10 -0
  395. data/node_modules/simplemde/LICENSE +22 -0
  396. data/node_modules/simplemde/README.md +331 -0
  397. data/node_modules/simplemde/bower.json +23 -0
  398. data/node_modules/simplemde/debug/.simplemde 2.css.icloud +0 -0
  399. data/node_modules/simplemde/debug/simplemde.css +676 -0
  400. data/node_modules/simplemde/debug/simplemde.debug.js +17023 -0
  401. data/node_modules/simplemde/debug/simplemde.js +17019 -0
  402. data/node_modules/simplemde/dist/simplemde.min.css +7 -0
  403. data/node_modules/simplemde/dist/simplemde.min.js +15 -0
  404. data/node_modules/simplemde/gulpfile.js +96 -0
  405. data/node_modules/simplemde/package.json +73 -0
  406. data/node_modules/simplemde/src/css/simplemde.css +328 -0
  407. data/node_modules/simplemde/src/js/codemirror/tablist 2.js +44 -0
  408. data/node_modules/simplemde/src/js/codemirror/tablist.js +44 -0
  409. data/node_modules/simplemde/src/js/simplemde.js +2028 -0
  410. data/node_modules/typo-js/README.md +45 -0
  411. data/node_modules/typo-js/dictionaries/en_US/.en_US 2.dic.icloud +0 -0
  412. data/node_modules/typo-js/dictionaries/en_US/README.md +7 -0
  413. data/node_modules/typo-js/dictionaries/en_US/en_US.aff +201 -0
  414. data/node_modules/typo-js/dictionaries/en_US/en_US.dic +62120 -0
  415. data/node_modules/typo-js/package.json +56 -0
  416. data/node_modules/typo-js/typo.js +931 -0
  417. data/package-lock.json +40 -0
  418. data/package.json +7 -0
  419. metadata +557 -0
@@ -0,0 +1,148 @@
1
+ import { flipCtrlCmd, mac, presto } from "../util/browser.js"
2
+ import { map } from "../util/misc.js"
3
+
4
+ import { keyNames } from "./keynames.js"
5
+
6
+ export let keyMap = {}
7
+
8
+ keyMap.basic = {
9
+ "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
10
+ "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
11
+ "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
12
+ "Tab": "defaultTab", "Shift-Tab": "indentAuto",
13
+ "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
14
+ "Esc": "singleSelection"
15
+ }
16
+ // Note that the save and find-related commands aren't defined by
17
+ // default. User code or addons can define them. Unknown commands
18
+ // are simply ignored.
19
+ keyMap.pcDefault = {
20
+ "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
21
+ "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
22
+ "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
23
+ "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
24
+ "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
25
+ "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
26
+ "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
27
+ "fallthrough": "basic"
28
+ }
29
+ // Very basic readline/emacs-style bindings, which are standard on Mac.
30
+ keyMap.emacsy = {
31
+ "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
32
+ "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
33
+ "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
34
+ "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
35
+ "Ctrl-O": "openLine"
36
+ }
37
+ keyMap.macDefault = {
38
+ "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
39
+ "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
40
+ "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
41
+ "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
42
+ "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
43
+ "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
44
+ "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
45
+ "fallthrough": ["basic", "emacsy"]
46
+ }
47
+ keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault
48
+
49
+ // KEYMAP DISPATCH
50
+
51
+ function normalizeKeyName(name) {
52
+ let parts = name.split(/-(?!$)/)
53
+ name = parts[parts.length - 1]
54
+ let alt, ctrl, shift, cmd
55
+ for (let i = 0; i < parts.length - 1; i++) {
56
+ let mod = parts[i]
57
+ if (/^(cmd|meta|m)$/i.test(mod)) cmd = true
58
+ else if (/^a(lt)?$/i.test(mod)) alt = true
59
+ else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true
60
+ else if (/^s(hift)?$/i.test(mod)) shift = true
61
+ else throw new Error("Unrecognized modifier name: " + mod)
62
+ }
63
+ if (alt) name = "Alt-" + name
64
+ if (ctrl) name = "Ctrl-" + name
65
+ if (cmd) name = "Cmd-" + name
66
+ if (shift) name = "Shift-" + name
67
+ return name
68
+ }
69
+
70
+ // This is a kludge to keep keymaps mostly working as raw objects
71
+ // (backwards compatibility) while at the same time support features
72
+ // like normalization and multi-stroke key bindings. It compiles a
73
+ // new normalized keymap, and then updates the old object to reflect
74
+ // this.
75
+ export function normalizeKeyMap(keymap) {
76
+ let copy = {}
77
+ for (let keyname in keymap) if (keymap.hasOwnProperty(keyname)) {
78
+ let value = keymap[keyname]
79
+ if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) continue
80
+ if (value == "...") { delete keymap[keyname]; continue }
81
+
82
+ let keys = map(keyname.split(" "), normalizeKeyName)
83
+ for (let i = 0; i < keys.length; i++) {
84
+ let val, name
85
+ if (i == keys.length - 1) {
86
+ name = keys.join(" ")
87
+ val = value
88
+ } else {
89
+ name = keys.slice(0, i + 1).join(" ")
90
+ val = "..."
91
+ }
92
+ let prev = copy[name]
93
+ if (!prev) copy[name] = val
94
+ else if (prev != val) throw new Error("Inconsistent bindings for " + name)
95
+ }
96
+ delete keymap[keyname]
97
+ }
98
+ for (let prop in copy) keymap[prop] = copy[prop]
99
+ return keymap
100
+ }
101
+
102
+ export function lookupKey(key, map, handle, context) {
103
+ map = getKeyMap(map)
104
+ let found = map.call ? map.call(key, context) : map[key]
105
+ if (found === false) return "nothing"
106
+ if (found === "...") return "multi"
107
+ if (found != null && handle(found)) return "handled"
108
+
109
+ if (map.fallthrough) {
110
+ if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
111
+ return lookupKey(key, map.fallthrough, handle, context)
112
+ for (let i = 0; i < map.fallthrough.length; i++) {
113
+ let result = lookupKey(key, map.fallthrough[i], handle, context)
114
+ if (result) return result
115
+ }
116
+ }
117
+ }
118
+
119
+ // Modifier key presses don't count as 'real' key presses for the
120
+ // purpose of keymap fallthrough.
121
+ export function isModifierKey(value) {
122
+ let name = typeof value == "string" ? value : keyNames[value.keyCode]
123
+ return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
124
+ }
125
+
126
+ export function addModifierNames(name, event, noShift) {
127
+ let base = name
128
+ if (event.altKey && base != "Alt") name = "Alt-" + name
129
+ if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") name = "Ctrl-" + name
130
+ if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") name = "Cmd-" + name
131
+ if (!noShift && event.shiftKey && base != "Shift") name = "Shift-" + name
132
+ return name
133
+ }
134
+
135
+ // Look up the name of a key as indicated by an event object.
136
+ export function keyName(event, noShift) {
137
+ if (presto && event.keyCode == 34 && event["char"]) return false
138
+ let name = keyNames[event.keyCode]
139
+ if (name == null || event.altGraphKey) return false
140
+ // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
141
+ // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
142
+ if (event.keyCode == 3 && event.code) name = event.code
143
+ return addModifierNames(name, event, noShift)
144
+ }
145
+
146
+ export function getKeyMap(val) {
147
+ return typeof val == "string" ? keyMap[val] : val
148
+ }
@@ -0,0 +1,17 @@
1
+ export let keyNames = {
2
+ 3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
3
+ 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
4
+ 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
5
+ 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
6
+ 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete", 145: "ScrollLock",
7
+ 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
8
+ 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
9
+ 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
10
+ }
11
+
12
+ // Number keys
13
+ for (let i = 0; i < 10; i++) keyNames[i + 48] = keyNames[i + 96] = String(i)
14
+ // Alphabetic keys
15
+ for (let i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i)
16
+ // Function keys
17
+ for (let i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i
@@ -0,0 +1,110 @@
1
+ import { Pos } from "../line/pos.js"
2
+ import { prepareMeasureForLine, measureCharPrepared, wrappedLineExtentChar } from "../measurement/position_measurement.js"
3
+ import { getBidiPartAt, getOrder } from "../util/bidi.js"
4
+ import { findFirst, lst, skipExtendingChars } from "../util/misc.js"
5
+
6
+ function moveCharLogically(line, ch, dir) {
7
+ let target = skipExtendingChars(line.text, ch + dir, dir)
8
+ return target < 0 || target > line.text.length ? null : target
9
+ }
10
+
11
+ export function moveLogically(line, start, dir) {
12
+ let ch = moveCharLogically(line, start.ch, dir)
13
+ return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
14
+ }
15
+
16
+ export function endOfLine(visually, cm, lineObj, lineNo, dir) {
17
+ if (visually) {
18
+ let order = getOrder(lineObj, cm.doc.direction)
19
+ if (order) {
20
+ let part = dir < 0 ? lst(order) : order[0]
21
+ let moveInStorageOrder = (dir < 0) == (part.level == 1)
22
+ let sticky = moveInStorageOrder ? "after" : "before"
23
+ let ch
24
+ // With a wrapped rtl chunk (possibly spanning multiple bidi parts),
25
+ // it could be that the last bidi part is not on the last visual line,
26
+ // since visual lines contain content order-consecutive chunks.
27
+ // Thus, in rtl, we are looking for the first (content-order) character
28
+ // in the rtl chunk that is on the last line (that is, the same line
29
+ // as the last (content-order) character).
30
+ if (part.level > 0 || cm.doc.direction == "rtl") {
31
+ let prep = prepareMeasureForLine(cm, lineObj)
32
+ ch = dir < 0 ? lineObj.text.length - 1 : 0
33
+ let targetTop = measureCharPrepared(cm, prep, ch).top
34
+ ch = findFirst(ch => measureCharPrepared(cm, prep, ch).top == targetTop, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch)
35
+ if (sticky == "before") ch = moveCharLogically(lineObj, ch, 1)
36
+ } else ch = dir < 0 ? part.to : part.from
37
+ return new Pos(lineNo, ch, sticky)
38
+ }
39
+ }
40
+ return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after")
41
+ }
42
+
43
+ export function moveVisually(cm, line, start, dir) {
44
+ let bidi = getOrder(line, cm.doc.direction)
45
+ if (!bidi) return moveLogically(line, start, dir)
46
+ if (start.ch >= line.text.length) {
47
+ start.ch = line.text.length
48
+ start.sticky = "before"
49
+ } else if (start.ch <= 0) {
50
+ start.ch = 0
51
+ start.sticky = "after"
52
+ }
53
+ let partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos]
54
+ if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
55
+ // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
56
+ // nothing interesting happens.
57
+ return moveLogically(line, start, dir)
58
+ }
59
+
60
+ let mv = (pos, dir) => moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir)
61
+ let prep
62
+ let getWrappedLineExtent = ch => {
63
+ if (!cm.options.lineWrapping) return {begin: 0, end: line.text.length}
64
+ prep = prep || prepareMeasureForLine(cm, line)
65
+ return wrappedLineExtentChar(cm, line, prep, ch)
66
+ }
67
+ let wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch)
68
+
69
+ if (cm.doc.direction == "rtl" || part.level == 1) {
70
+ let moveInStorageOrder = (part.level == 1) == (dir < 0)
71
+ let ch = mv(start, moveInStorageOrder ? 1 : -1)
72
+ if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
73
+ // Case 2: We move within an rtl part or in an rtl editor on the same visual line
74
+ let sticky = moveInStorageOrder ? "before" : "after"
75
+ return new Pos(start.line, ch, sticky)
76
+ }
77
+ }
78
+
79
+ // Case 3: Could not move within this bidi part in this visual line, so leave
80
+ // the current bidi part
81
+
82
+ let searchInVisualLine = (partPos, dir, wrappedLineExtent) => {
83
+ let getRes = (ch, moveInStorageOrder) => moveInStorageOrder
84
+ ? new Pos(start.line, mv(ch, 1), "before")
85
+ : new Pos(start.line, ch, "after")
86
+
87
+ for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
88
+ let part = bidi[partPos]
89
+ let moveInStorageOrder = (dir > 0) == (part.level != 1)
90
+ let ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1)
91
+ if (part.from <= ch && ch < part.to) return getRes(ch, moveInStorageOrder)
92
+ ch = moveInStorageOrder ? part.from : mv(part.to, -1)
93
+ if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) return getRes(ch, moveInStorageOrder)
94
+ }
95
+ }
96
+
97
+ // Case 3a: Look for other bidi parts on the same visual line
98
+ let res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent)
99
+ if (res) return res
100
+
101
+ // Case 3b: Look for other bidi parts on the next visual line
102
+ let nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1)
103
+ if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
104
+ res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh))
105
+ if (res) return res
106
+ }
107
+
108
+ // Case 4: Nowhere to move
109
+ return null
110
+ }
@@ -0,0 +1,284 @@
1
+ import { countColumn } from "../util/misc.js"
2
+ import { copyState, innerMode, startState } from "../modes.js"
3
+ import StringStream from "../util/StringStream.js"
4
+
5
+ import { getLine, lineNo } from "./utils_line.js"
6
+ import { clipPos } from "./pos.js"
7
+
8
+ class SavedContext {
9
+ constructor(state, lookAhead) {
10
+ this.state = state
11
+ this.lookAhead = lookAhead
12
+ }
13
+ }
14
+
15
+ class Context {
16
+ constructor(doc, state, line, lookAhead) {
17
+ this.state = state
18
+ this.doc = doc
19
+ this.line = line
20
+ this.maxLookAhead = lookAhead || 0
21
+ this.baseTokens = null
22
+ this.baseTokenPos = 1
23
+ }
24
+
25
+ lookAhead(n) {
26
+ let line = this.doc.getLine(this.line + n)
27
+ if (line != null && n > this.maxLookAhead) this.maxLookAhead = n
28
+ return line
29
+ }
30
+
31
+ baseToken(n) {
32
+ if (!this.baseTokens) return null
33
+ while (this.baseTokens[this.baseTokenPos] <= n)
34
+ this.baseTokenPos += 2
35
+ let type = this.baseTokens[this.baseTokenPos + 1]
36
+ return {type: type && type.replace(/( |^)overlay .*/, ""),
37
+ size: this.baseTokens[this.baseTokenPos] - n}
38
+ }
39
+
40
+ nextLine() {
41
+ this.line++
42
+ if (this.maxLookAhead > 0) this.maxLookAhead--
43
+ }
44
+
45
+ static fromSaved(doc, saved, line) {
46
+ if (saved instanceof SavedContext)
47
+ return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead)
48
+ else
49
+ return new Context(doc, copyState(doc.mode, saved), line)
50
+ }
51
+
52
+ save(copy) {
53
+ let state = copy !== false ? copyState(this.doc.mode, this.state) : this.state
54
+ return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state
55
+ }
56
+ }
57
+
58
+
59
+ // Compute a style array (an array starting with a mode generation
60
+ // -- for invalidation -- followed by pairs of end positions and
61
+ // style strings), which is used to highlight the tokens on the
62
+ // line.
63
+ export function highlightLine(cm, line, context, forceToEnd) {
64
+ // A styles array always starts with a number identifying the
65
+ // mode/overlays that it is based on (for easy invalidation).
66
+ let st = [cm.state.modeGen], lineClasses = {}
67
+ // Compute the base array of styles
68
+ runMode(cm, line.text, cm.doc.mode, context, (end, style) => st.push(end, style),
69
+ lineClasses, forceToEnd)
70
+ let state = context.state
71
+
72
+ // Run overlays, adjust style array.
73
+ for (let o = 0; o < cm.state.overlays.length; ++o) {
74
+ context.baseTokens = st
75
+ let overlay = cm.state.overlays[o], i = 1, at = 0
76
+ context.state = true
77
+ runMode(cm, line.text, overlay.mode, context, (end, style) => {
78
+ let start = i
79
+ // Ensure there's a token end at the current position, and that i points at it
80
+ while (at < end) {
81
+ let i_end = st[i]
82
+ if (i_end > end)
83
+ st.splice(i, 1, end, st[i+1], i_end)
84
+ i += 2
85
+ at = Math.min(end, i_end)
86
+ }
87
+ if (!style) return
88
+ if (overlay.opaque) {
89
+ st.splice(start, i - start, end, "overlay " + style)
90
+ i = start + 2
91
+ } else {
92
+ for (; start < i; start += 2) {
93
+ let cur = st[start+1]
94
+ st[start+1] = (cur ? cur + " " : "") + "overlay " + style
95
+ }
96
+ }
97
+ }, lineClasses)
98
+ context.state = state
99
+ context.baseTokens = null
100
+ context.baseTokenPos = 1
101
+ }
102
+
103
+ return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
104
+ }
105
+
106
+ export function getLineStyles(cm, line, updateFrontier) {
107
+ if (!line.styles || line.styles[0] != cm.state.modeGen) {
108
+ let context = getContextBefore(cm, lineNo(line))
109
+ let resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state)
110
+ let result = highlightLine(cm, line, context)
111
+ if (resetState) context.state = resetState
112
+ line.stateAfter = context.save(!resetState)
113
+ line.styles = result.styles
114
+ if (result.classes) line.styleClasses = result.classes
115
+ else if (line.styleClasses) line.styleClasses = null
116
+ if (updateFrontier === cm.doc.highlightFrontier)
117
+ cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier)
118
+ }
119
+ return line.styles
120
+ }
121
+
122
+ export function getContextBefore(cm, n, precise) {
123
+ let doc = cm.doc, display = cm.display
124
+ if (!doc.mode.startState) return new Context(doc, true, n)
125
+ let start = findStartLine(cm, n, precise)
126
+ let saved = start > doc.first && getLine(doc, start - 1).stateAfter
127
+ let context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start)
128
+
129
+ doc.iter(start, n, line => {
130
+ processLine(cm, line.text, context)
131
+ let pos = context.line
132
+ line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null
133
+ context.nextLine()
134
+ })
135
+ if (precise) doc.modeFrontier = context.line
136
+ return context
137
+ }
138
+
139
+ // Lightweight form of highlight -- proceed over this line and
140
+ // update state, but don't save a style array. Used for lines that
141
+ // aren't currently visible.
142
+ export function processLine(cm, text, context, startAt) {
143
+ let mode = cm.doc.mode
144
+ let stream = new StringStream(text, cm.options.tabSize, context)
145
+ stream.start = stream.pos = startAt || 0
146
+ if (text == "") callBlankLine(mode, context.state)
147
+ while (!stream.eol()) {
148
+ readToken(mode, stream, context.state)
149
+ stream.start = stream.pos
150
+ }
151
+ }
152
+
153
+ function callBlankLine(mode, state) {
154
+ if (mode.blankLine) return mode.blankLine(state)
155
+ if (!mode.innerMode) return
156
+ let inner = innerMode(mode, state)
157
+ if (inner.mode.blankLine) return inner.mode.blankLine(inner.state)
158
+ }
159
+
160
+ function readToken(mode, stream, state, inner) {
161
+ for (let i = 0; i < 10; i++) {
162
+ if (inner) inner[0] = innerMode(mode, state).mode
163
+ let style = mode.token(stream, state)
164
+ if (stream.pos > stream.start) return style
165
+ }
166
+ throw new Error("Mode " + mode.name + " failed to advance stream.")
167
+ }
168
+
169
+ class Token {
170
+ constructor(stream, type, state) {
171
+ this.start = stream.start; this.end = stream.pos
172
+ this.string = stream.current()
173
+ this.type = type || null
174
+ this.state = state
175
+ }
176
+ }
177
+
178
+ // Utility for getTokenAt and getLineTokens
179
+ export function takeToken(cm, pos, precise, asArray) {
180
+ let doc = cm.doc, mode = doc.mode, style
181
+ pos = clipPos(doc, pos)
182
+ let line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise)
183
+ let stream = new StringStream(line.text, cm.options.tabSize, context), tokens
184
+ if (asArray) tokens = []
185
+ while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
186
+ stream.start = stream.pos
187
+ style = readToken(mode, stream, context.state)
188
+ if (asArray) tokens.push(new Token(stream, style, copyState(doc.mode, context.state)))
189
+ }
190
+ return asArray ? tokens : new Token(stream, style, context.state)
191
+ }
192
+
193
+ function extractLineClasses(type, output) {
194
+ if (type) for (;;) {
195
+ let lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/)
196
+ if (!lineClass) break
197
+ type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length)
198
+ let prop = lineClass[1] ? "bgClass" : "textClass"
199
+ if (output[prop] == null)
200
+ output[prop] = lineClass[2]
201
+ else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
202
+ output[prop] += " " + lineClass[2]
203
+ }
204
+ return type
205
+ }
206
+
207
+ // Run the given mode's parser over a line, calling f for each token.
208
+ function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
209
+ let flattenSpans = mode.flattenSpans
210
+ if (flattenSpans == null) flattenSpans = cm.options.flattenSpans
211
+ let curStart = 0, curStyle = null
212
+ let stream = new StringStream(text, cm.options.tabSize, context), style
213
+ let inner = cm.options.addModeClass && [null]
214
+ if (text == "") extractLineClasses(callBlankLine(mode, context.state), lineClasses)
215
+ while (!stream.eol()) {
216
+ if (stream.pos > cm.options.maxHighlightLength) {
217
+ flattenSpans = false
218
+ if (forceToEnd) processLine(cm, text, context, stream.pos)
219
+ stream.pos = text.length
220
+ style = null
221
+ } else {
222
+ style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses)
223
+ }
224
+ if (inner) {
225
+ let mName = inner[0].name
226
+ if (mName) style = "m-" + (style ? mName + " " + style : mName)
227
+ }
228
+ if (!flattenSpans || curStyle != style) {
229
+ while (curStart < stream.start) {
230
+ curStart = Math.min(stream.start, curStart + 5000)
231
+ f(curStart, curStyle)
232
+ }
233
+ curStyle = style
234
+ }
235
+ stream.start = stream.pos
236
+ }
237
+ while (curStart < stream.pos) {
238
+ // Webkit seems to refuse to render text nodes longer than 57444
239
+ // characters, and returns inaccurate measurements in nodes
240
+ // starting around 5000 chars.
241
+ let pos = Math.min(stream.pos, curStart + 5000)
242
+ f(pos, curStyle)
243
+ curStart = pos
244
+ }
245
+ }
246
+
247
+ // Finds the line to start with when starting a parse. Tries to
248
+ // find a line with a stateAfter, so that it can start with a
249
+ // valid state. If that fails, it returns the line with the
250
+ // smallest indentation, which tends to need the least context to
251
+ // parse correctly.
252
+ function findStartLine(cm, n, precise) {
253
+ let minindent, minline, doc = cm.doc
254
+ let lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100)
255
+ for (let search = n; search > lim; --search) {
256
+ if (search <= doc.first) return doc.first
257
+ let line = getLine(doc, search - 1), after = line.stateAfter
258
+ if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier))
259
+ return search
260
+ let indented = countColumn(line.text, null, cm.options.tabSize)
261
+ if (minline == null || minindent > indented) {
262
+ minline = search - 1
263
+ minindent = indented
264
+ }
265
+ }
266
+ return minline
267
+ }
268
+
269
+ export function retreatFrontier(doc, n) {
270
+ doc.modeFrontier = Math.min(doc.modeFrontier, n)
271
+ if (doc.highlightFrontier < n - 10) return
272
+ let start = doc.first
273
+ for (let line = n - 1; line > start; line--) {
274
+ let saved = getLine(doc, line).stateAfter
275
+ // change is on 3
276
+ // state on line 1 looked ahead 2 -- so saw 3
277
+ // test 1 + 2 < 3 should cover this
278
+ if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
279
+ start = line + 1
280
+ break
281
+ }
282
+ }
283
+ doc.highlightFrontier = Math.min(doc.highlightFrontier, start)
284
+ }