udxcms 1.0.9 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (428) hide show
  1. package/dist/api/common.d.ts +28 -28
  2. package/dist/api/h5/axios.d.ts +3 -3
  3. package/dist/api/h5/axios.js +12 -9
  4. package/dist/api/h5/common.d.ts +10 -10
  5. package/dist/api/index.d.ts +1 -1
  6. package/dist/api/index.js +8 -6
  7. package/dist/components/basicComponents/AdsBanner.vue +3 -3
  8. package/dist/components/basicComponents/AreaSelect.vue +9 -1
  9. package/dist/components/basicComponents/BaseMenu.vue +1 -0
  10. package/dist/components/businessComponents/Currency.vue +6 -4
  11. package/dist/components/businessComponents/CustomAnnounceModal.vue +2 -2
  12. package/dist/components/businessComponents/Footer.vue +1 -1
  13. package/dist/components/businessComponents/FooterPointx.vue +1 -1
  14. package/dist/components/businessComponents/Language.vue +8 -4
  15. package/dist/components/businessComponents/SiteLoading.vue +3 -3
  16. package/dist/components/cmsComponents/academy/CmsAcademyJoinComunity.vue +1 -1
  17. package/dist/components/cmsComponents/academy/CmsAcademySectionOne.vue +1 -1
  18. package/dist/components/cmsComponents/api/code.js +2 -4
  19. package/dist/components/cmsComponents/api/test.js +2 -4
  20. package/dist/components/cmsComponents/sdk/Logo.vue +1 -1
  21. package/dist/components/cmsComponents/sdk/lib/highlight/lib/core.js +2051 -1836
  22. package/dist/components/cmsComponents/sdk/lib/highlight/lib/index.js +3 -1
  23. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/1c.js +509 -424
  24. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/abnf.js +77 -65
  25. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/accesslog.js +89 -84
  26. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/actionscript.js +86 -80
  27. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/ada.js +166 -149
  28. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/angelscript.js +109 -90
  29. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/apache.js +72 -69
  30. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/applescript.js +150 -125
  31. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/arcade.js +150 -144
  32. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/arduino.js +518 -475
  33. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/armasm.js +120 -112
  34. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/asciidoc.js +268 -244
  35. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/aspectj.js +154 -144
  36. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/autohotkey.js +73 -70
  37. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/autoit.js +160 -146
  38. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/avrasm.js +70 -63
  39. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/awk.js +63 -61
  40. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/axapta.js +166 -160
  41. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/bash.js +142 -133
  42. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/basic.js +55 -52
  43. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/bnf.js +27 -25
  44. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/brainfuck.js +36 -30
  45. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/c-like.js +444 -407
  46. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/c.js +267 -247
  47. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/cal.js +91 -77
  48. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/capnproto.js +53 -48
  49. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/ceylon.js +73 -67
  50. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/clean.js +30 -25
  51. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/clojure-repl.js +15 -13
  52. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/clojure.js +145 -134
  53. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/cmake.js +54 -52
  54. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/coffeescript.js +322 -304
  55. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/coq.js +69 -65
  56. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/cos.js +127 -119
  57. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/cpp.js +415 -383
  58. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/crmsh.js +91 -88
  59. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/crystal.js +299 -293
  60. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/csharp.js +416 -407
  61. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/csp.js +25 -23
  62. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/css.js +559 -547
  63. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/d.js +244 -215
  64. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/dart.js +183 -168
  65. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/delphi.js +115 -112
  66. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/diff.js +73 -71
  67. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/django.js +64 -59
  68. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/dns.js +36 -33
  69. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/dockerfile.js +22 -20
  70. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/dos.js +58 -51
  71. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/dsconfig.js +57 -54
  72. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/dts.js +136 -125
  73. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/dust.js +33 -31
  74. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/ebnf.js +43 -37
  75. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/elixir.js +223 -218
  76. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/elm.js +115 -98
  77. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/erb.js +16 -14
  78. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/erlang-repl.js +60 -52
  79. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/erlang.js +180 -171
  80. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/excel.js +54 -51
  81. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/fix.js +29 -27
  82. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/flix.js +45 -39
  83. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/fortran.js +132 -123
  84. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/fsharp.js +71 -67
  85. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/gams.js +175 -164
  86. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/gauss.js +294 -271
  87. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/gcode.js +77 -74
  88. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/gherkin.js +38 -36
  89. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/glsl.js +118 -115
  90. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/gml.js +875 -871
  91. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/go.js +61 -56
  92. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/golo.js +24 -20
  93. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/gradle.js +35 -31
  94. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/groovy.js +140 -126
  95. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/haml.js +102 -96
  96. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/handlebars.js +273 -232
  97. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/haskell.js +158 -143
  98. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/haxe.js +144 -138
  99. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/hsp.js +52 -45
  100. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/htmlbars.js +292 -245
  101. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/http.js +92 -87
  102. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/hy.js +99 -89
  103. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/inform7.js +59 -57
  104. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/ini.js +128 -115
  105. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/irpf90.js +111 -105
  106. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/isbl.js +3198 -2973
  107. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/java.js +160 -146
  108. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/javascript.js +543 -513
  109. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/jboss-cli.js +53 -51
  110. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/json.js +53 -51
  111. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/julia-repl.js +24 -22
  112. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/julia.js +406 -387
  113. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/kotlin.js +258 -236
  114. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/lasso.js +168 -159
  115. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/latex.js +234 -216
  116. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/ldif.js +33 -32
  117. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/leaf.js +39 -37
  118. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/less.js +633 -587
  119. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/lisp.js +100 -94
  120. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/livecodeserver.js +174 -169
  121. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/livescript.js +337 -319
  122. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/llvm.js +124 -118
  123. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/lsl.js +9 -1
  124. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/lua.js +70 -64
  125. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/makefile.js +82 -79
  126. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/markdown.js +228 -218
  127. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/mathematica.js +6752 -6731
  128. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/matlab.js +89 -84
  129. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/maxima.js +408 -402
  130. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/mel.js +226 -223
  131. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/mercury.js +109 -99
  132. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/mipsasm.js +98 -95
  133. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/mizar.js +19 -16
  134. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/mojolicious.js +25 -24
  135. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/monkey.js +78 -69
  136. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/moonscript.js +129 -122
  137. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/n1ql.js +65 -59
  138. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/nginx.js +123 -119
  139. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/nim.js +68 -63
  140. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/nix.js +56 -51
  141. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/node-repl.js +26 -24
  142. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/nsis.js +110 -93
  143. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/objectivec.js +109 -103
  144. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/ocaml.js +71 -62
  145. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/openscad.js +71 -68
  146. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/oxygene.js +87 -76
  147. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/parser3.js +47 -37
  148. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/perl.js +468 -441
  149. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/pf.js +49 -43
  150. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/pgsql.js +594 -574
  151. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/php-template.js +42 -40
  152. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/php.js +185 -175
  153. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/plaintext.js +10 -8
  154. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/pony.js +79 -66
  155. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/powershell.js +317 -273
  156. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/processing.js +48 -46
  157. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/profile.js +35 -33
  158. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/prolog.js +93 -73
  159. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/properties.js +69 -64
  160. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/protobuf.js +35 -33
  161. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/puppet.js +132 -124
  162. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/purebasic.js +67 -61
  163. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/python-repl.js +26 -24
  164. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/python.js +406 -389
  165. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/q.js +27 -20
  166. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/qml.js +190 -176
  167. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/r.js +187 -171
  168. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/reasonml.js +296 -277
  169. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/rib.js +27 -24
  170. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/roboconf.js +69 -62
  171. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/routeros.js +150 -139
  172. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/rsl.js +39 -35
  173. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/ruby.js +339 -314
  174. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/ruleslanguage.js +67 -63
  175. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/rust.js +132 -126
  176. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/sas.js +124 -114
  177. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/scala.js +126 -115
  178. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/scheme.js +188 -168
  179. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/scilab.js +60 -56
  180. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/scss.js +518 -508
  181. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/shell.js +19 -17
  182. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/smali.js +125 -119
  183. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/smalltalk.js +52 -50
  184. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/sml.js +70 -63
  185. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/sqf.js +436 -426
  186. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/sql.js +662 -643
  187. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/sql_more.js +162 -155
  188. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/stan.js +536 -525
  189. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/stata.js +45 -40
  190. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/step21.js +56 -53
  191. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/stylus.js +580 -553
  192. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/subunit.js +43 -41
  193. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/swift.js +770 -679
  194. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/taggerscript.js +43 -38
  195. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/tap.js +44 -42
  196. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/tcl.js +82 -68
  197. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/thrift.js +38 -33
  198. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/tp.js +85 -80
  199. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/twig.js +63 -54
  200. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/typescript.js +625 -587
  201. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/vala.js +52 -48
  202. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/vbnet.js +178 -156
  203. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/vbscript-html.js +13 -11
  204. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/vbscript.js +71 -58
  205. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/verilog.js +120 -113
  206. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/vhdl.js +61 -53
  207. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/vim.js +111 -107
  208. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/x86asm.js +152 -138
  209. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/xl.js +83 -75
  210. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/xml.js +230 -209
  211. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/xquery.js +179 -161
  212. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/yaml.js +164 -154
  213. package/dist/components/cmsComponents/sdk/lib/highlight/lib/languages/zephir.js +125 -118
  214. package/dist/components/cmsComponents/wiki/Logo.vue +1 -1
  215. package/dist/components/cmsComponents/wiki/lib/highlight/lib/core.js +2051 -1836
  216. package/dist/components/cmsComponents/wiki/lib/highlight/lib/index.js +3 -1
  217. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/1c.js +509 -424
  218. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/abnf.js +77 -65
  219. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/accesslog.js +89 -84
  220. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/actionscript.js +86 -80
  221. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/ada.js +166 -149
  222. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/angelscript.js +109 -90
  223. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/apache.js +72 -69
  224. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/applescript.js +150 -125
  225. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/arcade.js +150 -144
  226. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/arduino.js +518 -475
  227. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/armasm.js +120 -112
  228. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/asciidoc.js +268 -244
  229. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/aspectj.js +154 -144
  230. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/autohotkey.js +73 -70
  231. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/autoit.js +160 -146
  232. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/avrasm.js +70 -63
  233. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/awk.js +63 -61
  234. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/axapta.js +166 -160
  235. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/bash.js +142 -133
  236. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/basic.js +55 -52
  237. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/bnf.js +27 -25
  238. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/brainfuck.js +36 -30
  239. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/c-like.js +444 -407
  240. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/c.js +267 -247
  241. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/cal.js +91 -77
  242. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/capnproto.js +53 -48
  243. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/ceylon.js +73 -67
  244. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/clean.js +30 -25
  245. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/clojure-repl.js +15 -13
  246. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/clojure.js +145 -134
  247. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/cmake.js +54 -52
  248. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/coffeescript.js +322 -304
  249. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/coq.js +69 -65
  250. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/cos.js +127 -119
  251. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/cpp.js +415 -383
  252. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/crmsh.js +91 -88
  253. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/crystal.js +299 -293
  254. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/csharp.js +416 -407
  255. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/csp.js +25 -23
  256. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/css.js +559 -547
  257. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/d.js +244 -215
  258. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/dart.js +183 -168
  259. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/delphi.js +115 -112
  260. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/diff.js +73 -71
  261. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/django.js +64 -59
  262. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/dns.js +36 -33
  263. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/dockerfile.js +22 -20
  264. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/dos.js +58 -51
  265. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/dsconfig.js +57 -54
  266. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/dts.js +136 -125
  267. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/dust.js +33 -31
  268. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/ebnf.js +43 -37
  269. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/elixir.js +223 -218
  270. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/elm.js +115 -98
  271. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/erb.js +16 -14
  272. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/erlang-repl.js +60 -52
  273. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/erlang.js +180 -171
  274. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/excel.js +54 -51
  275. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/fix.js +29 -27
  276. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/flix.js +45 -39
  277. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/fortran.js +132 -123
  278. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/fsharp.js +71 -67
  279. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/gams.js +175 -164
  280. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/gauss.js +294 -271
  281. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/gcode.js +77 -74
  282. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/gherkin.js +38 -36
  283. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/glsl.js +118 -115
  284. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/gml.js +875 -871
  285. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/go.js +61 -56
  286. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/golo.js +24 -20
  287. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/gradle.js +35 -31
  288. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/groovy.js +140 -126
  289. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/haml.js +102 -96
  290. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/handlebars.js +273 -232
  291. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/haskell.js +158 -143
  292. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/haxe.js +144 -138
  293. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/hsp.js +52 -45
  294. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/htmlbars.js +292 -245
  295. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/http.js +92 -87
  296. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/hy.js +99 -89
  297. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/inform7.js +59 -57
  298. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/ini.js +128 -115
  299. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/irpf90.js +111 -105
  300. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/isbl.js +3198 -2973
  301. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/java.js +160 -146
  302. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/javascript.js +543 -513
  303. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/jboss-cli.js +53 -51
  304. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/json.js +53 -51
  305. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/julia-repl.js +24 -22
  306. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/julia.js +406 -387
  307. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/kotlin.js +258 -236
  308. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/lasso.js +168 -159
  309. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/latex.js +234 -216
  310. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/ldif.js +33 -32
  311. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/leaf.js +39 -37
  312. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/less.js +633 -587
  313. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/lisp.js +100 -94
  314. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/livecodeserver.js +174 -169
  315. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/livescript.js +337 -319
  316. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/llvm.js +124 -118
  317. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/lsl.js +9 -1
  318. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/lua.js +70 -64
  319. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/makefile.js +82 -79
  320. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/markdown.js +228 -218
  321. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/mathematica.js +6752 -6731
  322. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/matlab.js +89 -84
  323. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/maxima.js +408 -402
  324. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/mel.js +226 -223
  325. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/mercury.js +109 -99
  326. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/mipsasm.js +98 -95
  327. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/mizar.js +19 -16
  328. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/mojolicious.js +25 -24
  329. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/monkey.js +78 -69
  330. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/moonscript.js +129 -122
  331. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/n1ql.js +65 -59
  332. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/nginx.js +123 -119
  333. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/nim.js +68 -63
  334. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/nix.js +56 -51
  335. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/node-repl.js +26 -24
  336. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/nsis.js +110 -93
  337. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/objectivec.js +109 -103
  338. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/ocaml.js +71 -62
  339. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/openscad.js +71 -68
  340. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/oxygene.js +87 -76
  341. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/parser3.js +47 -37
  342. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/perl.js +468 -441
  343. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/pf.js +49 -43
  344. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/pgsql.js +594 -574
  345. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/php-template.js +42 -40
  346. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/php.js +185 -175
  347. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/plaintext.js +10 -8
  348. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/pony.js +79 -66
  349. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/powershell.js +317 -273
  350. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/processing.js +48 -46
  351. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/profile.js +35 -33
  352. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/prolog.js +93 -73
  353. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/properties.js +69 -64
  354. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/protobuf.js +35 -33
  355. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/puppet.js +132 -124
  356. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/purebasic.js +67 -61
  357. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/python-repl.js +26 -24
  358. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/python.js +406 -389
  359. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/q.js +27 -20
  360. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/qml.js +190 -176
  361. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/r.js +187 -171
  362. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/reasonml.js +296 -277
  363. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/rib.js +27 -24
  364. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/roboconf.js +69 -62
  365. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/routeros.js +150 -139
  366. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/rsl.js +39 -35
  367. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/ruby.js +339 -314
  368. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/ruleslanguage.js +67 -63
  369. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/rust.js +132 -126
  370. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/sas.js +124 -114
  371. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/scala.js +126 -115
  372. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/scheme.js +188 -168
  373. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/scilab.js +60 -56
  374. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/scss.js +518 -508
  375. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/shell.js +19 -17
  376. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/smali.js +125 -119
  377. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/smalltalk.js +52 -50
  378. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/sml.js +70 -63
  379. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/sqf.js +436 -426
  380. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/sql.js +662 -643
  381. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/sql_more.js +162 -155
  382. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/stan.js +536 -525
  383. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/stata.js +45 -40
  384. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/step21.js +56 -53
  385. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/stylus.js +580 -553
  386. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/subunit.js +43 -41
  387. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/swift.js +770 -679
  388. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/taggerscript.js +43 -38
  389. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/tap.js +44 -42
  390. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/tcl.js +82 -68
  391. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/thrift.js +38 -33
  392. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/tp.js +85 -80
  393. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/twig.js +63 -54
  394. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/typescript.js +625 -587
  395. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/vala.js +52 -48
  396. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/vbnet.js +178 -156
  397. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/vbscript-html.js +13 -11
  398. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/vbscript.js +71 -58
  399. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/verilog.js +120 -113
  400. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/vhdl.js +61 -53
  401. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/vim.js +111 -107
  402. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/x86asm.js +152 -138
  403. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/xl.js +83 -75
  404. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/xml.js +230 -209
  405. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/xquery.js +179 -161
  406. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/yaml.js +164 -154
  407. package/dist/components/cmsComponents/wiki/lib/highlight/lib/languages/zephir.js +125 -118
  408. package/dist/components/h5Components/Language.vue +6 -4
  409. package/dist/components/h5Components/Top.vue +3 -3
  410. package/dist/components/h5Components/walletconnectBottom.vue +3 -3
  411. package/dist/components/index.js +115 -220
  412. package/dist/components/pageComponents/academy/academy_wallet.vue +3 -3
  413. package/dist/components/pageComponents/header/header_dtx2.vue +4 -4
  414. package/dist/components/pageComponents/header/header_lending.vue +2 -3
  415. package/dist/components/pageComponents/header/header_paragen.vue +2 -2
  416. package/dist/components/pageComponents/index/IndexBridge.vue +16 -4
  417. package/dist/components/pageComponents/index/IndexDemo.vue +1 -1
  418. package/dist/components/pageComponents/index/IndexDex.vue +1 -1
  419. package/dist/components/pageComponents/index/IndexMorse.vue +1 -1
  420. package/dist/components/pageComponents/index/IndexOrbits.vue +1 -1
  421. package/dist/components/pageComponents/index/IndexVortex.vue +1 -1
  422. package/dist/utils/connect.d.ts +1 -1
  423. package/dist/utils/connect.js +6 -4
  424. package/dist/utils/http.d.ts +2 -2
  425. package/dist/utils/http.js +12 -10
  426. package/dist/utils/index.d.ts +2 -0
  427. package/dist/utils/index.js +2 -1
  428. package/package.json +2 -2
@@ -3,54 +3,62 @@ function deepFreeze(obj) {
3
3
  obj.clear = obj.delete = obj.set = function () {
4
4
  throw new Error('map is read-only');
5
5
  };
6
- }
7
- else if (obj instanceof Set) {
6
+ } else if (obj instanceof Set) {
8
7
  obj.add = obj.clear = obj.delete = function () {
9
8
  throw new Error('set is read-only');
10
9
  };
11
10
  }
11
+
12
12
  // Freeze self
13
13
  Object.freeze(obj);
14
+
14
15
  Object.getOwnPropertyNames(obj).forEach(function (name) {
15
16
  var prop = obj[name];
17
+
16
18
  // Freeze prop if it is an object
17
19
  if (typeof prop == 'object' && !Object.isFrozen(prop)) {
18
20
  deepFreeze(prop);
19
21
  }
20
22
  });
23
+
21
24
  return obj;
22
25
  }
26
+
23
27
  var deepFreezeEs6 = deepFreeze;
24
28
  var _default = deepFreeze;
25
29
  deepFreezeEs6.default = _default;
30
+
26
31
  /** @implements CallbackResponse */
27
32
  class Response {
28
- /**
29
- * @param {CompiledMode} mode
30
- */
31
- constructor(mode) {
32
- // eslint-disable-next-line no-undefined
33
- if (mode.data === undefined)
34
- mode.data = {};
35
- this.data = mode.data;
36
- this.isMatchIgnored = false;
37
- }
38
- ignoreMatch() {
39
- this.isMatchIgnored = true;
40
- }
33
+ /**
34
+ * @param {CompiledMode} mode
35
+ */
36
+ constructor(mode) {
37
+ // eslint-disable-next-line no-undefined
38
+ if (mode.data === undefined) mode.data = {};
39
+
40
+ this.data = mode.data;
41
+ this.isMatchIgnored = false;
42
+ }
43
+
44
+ ignoreMatch() {
45
+ this.isMatchIgnored = true;
46
+ }
41
47
  }
48
+
42
49
  /**
43
50
  * @param {string} value
44
51
  * @returns {string}
45
52
  */
46
53
  function escapeHTML(value) {
47
- return value
48
- .replace(/&/g, '&')
49
- .replace(/</g, '&lt;')
50
- .replace(/>/g, '&gt;')
51
- .replace(/"/g, '&quot;')
52
- .replace(/'/g, '&#x27;');
54
+ return value
55
+ .replace(/&/g, '&amp;')
56
+ .replace(/</g, '&lt;')
57
+ .replace(/>/g, '&gt;')
58
+ .replace(/"/g, '&quot;')
59
+ .replace(/'/g, '&#x27;');
53
60
  }
61
+
54
62
  /**
55
63
  * performs a shallow merge of multiple objects into one
56
64
  *
@@ -60,18 +68,20 @@ function escapeHTML(value) {
60
68
  * @returns {T} a single new object
61
69
  */
62
70
  function inherit(original, ...objects) {
63
- /** @type Record<string,any> */
64
- const result = Object.create(null);
65
- for (const key in original) {
66
- result[key] = original[key];
67
- }
68
- objects.forEach(function (obj) {
69
- for (const key in obj) {
70
- result[key] = obj[key];
71
- }
72
- });
73
- return /** @type {T} */ (result);
71
+ /** @type Record<string,any> */
72
+ const result = Object.create(null);
73
+
74
+ for (const key in original) {
75
+ result[key] = original[key];
76
+ }
77
+ objects.forEach(function(obj) {
78
+ for (const key in obj) {
79
+ result[key] = obj[key];
80
+ }
81
+ });
82
+ return /** @type {T} */ (result);
74
83
  }
84
+
75
85
  /**
76
86
  * @typedef {object} Renderer
77
87
  * @property {(text: string) => void} addText
@@ -79,157 +89,176 @@ function inherit(original, ...objects) {
79
89
  * @property {(node: Node) => void} closeNode
80
90
  * @property {() => string} value
81
91
  */
92
+
82
93
  /** @typedef {{kind?: string, sublanguage?: boolean}} Node */
83
94
  /** @typedef {{walk: (r: Renderer) => void}} Tree */
84
95
  /** */
96
+
85
97
  const SPAN_CLOSE = '</span>';
98
+
86
99
  /**
87
100
  * Determines if a node needs to be wrapped in <span>
88
101
  *
89
102
  * @param {Node} node */
90
103
  const emitsWrappingTags = (node) => {
91
- return !!node.kind;
104
+ return !!node.kind;
92
105
  };
106
+
93
107
  /** @type {Renderer} */
94
108
  class HTMLRenderer {
95
- /**
96
- * Creates a new HTMLRenderer
97
- *
98
- * @param {Tree} parseTree - the parse tree (must support `walk` API)
99
- * @param {{classPrefix: string}} options
100
- */
101
- constructor(parseTree, options) {
102
- this.buffer = "";
103
- this.classPrefix = options.classPrefix;
104
- parseTree.walk(this);
105
- }
106
- /**
107
- * Adds texts to the output stream
108
- *
109
- * @param {string} text */
110
- addText(text) {
111
- this.buffer += escapeHTML(text);
112
- }
113
- /**
114
- * Adds a node open to the output stream (if needed)
115
- *
116
- * @param {Node} node */
117
- openNode(node) {
118
- if (!emitsWrappingTags(node))
119
- return;
120
- let className = node.kind;
121
- if (!node.sublanguage) {
122
- className = `${this.classPrefix}${className}`;
123
- }
124
- this.span(className);
125
- }
126
- /**
127
- * Adds a node close to the output stream (if needed)
128
- *
129
- * @param {Node} node */
130
- closeNode(node) {
131
- if (!emitsWrappingTags(node))
132
- return;
133
- this.buffer += SPAN_CLOSE;
134
- }
135
- /**
136
- * returns the accumulated buffer
137
- */
138
- value() {
139
- return this.buffer;
140
- }
141
- // helpers
142
- /**
143
- * Builds a span element
144
- *
145
- * @param {string} className */
146
- span(className) {
147
- this.buffer += `<span class="${className}">`;
109
+ /**
110
+ * Creates a new HTMLRenderer
111
+ *
112
+ * @param {Tree} parseTree - the parse tree (must support `walk` API)
113
+ * @param {{classPrefix: string}} options
114
+ */
115
+ constructor(parseTree, options) {
116
+ this.buffer = "";
117
+ this.classPrefix = options.classPrefix;
118
+ parseTree.walk(this);
119
+ }
120
+
121
+ /**
122
+ * Adds texts to the output stream
123
+ *
124
+ * @param {string} text */
125
+ addText(text) {
126
+ this.buffer += escapeHTML(text);
127
+ }
128
+
129
+ /**
130
+ * Adds a node open to the output stream (if needed)
131
+ *
132
+ * @param {Node} node */
133
+ openNode(node) {
134
+ if (!emitsWrappingTags(node)) return;
135
+
136
+ let className = node.kind;
137
+ if (!node.sublanguage) {
138
+ className = `${this.classPrefix}${className}`;
148
139
  }
140
+ this.span(className);
141
+ }
142
+
143
+ /**
144
+ * Adds a node close to the output stream (if needed)
145
+ *
146
+ * @param {Node} node */
147
+ closeNode(node) {
148
+ if (!emitsWrappingTags(node)) return;
149
+
150
+ this.buffer += SPAN_CLOSE;
151
+ }
152
+
153
+ /**
154
+ * returns the accumulated buffer
155
+ */
156
+ value() {
157
+ return this.buffer;
158
+ }
159
+
160
+ // helpers
161
+
162
+ /**
163
+ * Builds a span element
164
+ *
165
+ * @param {string} className */
166
+ span(className) {
167
+ this.buffer += `<span class="${className}">`;
168
+ }
149
169
  }
170
+
150
171
  /** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} | string} Node */
151
172
  /** @typedef {{kind?: string, sublanguage?: boolean, children: Node[]} } DataNode */
152
173
  /** */
174
+
153
175
  class TokenTree {
154
- constructor() {
155
- /** @type DataNode */
156
- this.rootNode = { children: [] };
157
- this.stack = [this.rootNode];
158
- }
159
- get top() {
160
- return this.stack[this.stack.length - 1];
161
- }
162
- get root() { return this.rootNode; }
163
- /** @param {Node} node */
164
- add(node) {
165
- this.top.children.push(node);
166
- }
167
- /** @param {string} kind */
168
- openNode(kind) {
169
- /** @type Node */
170
- const node = { kind, children: [] };
171
- this.add(node);
172
- this.stack.push(node);
173
- }
174
- closeNode() {
175
- if (this.stack.length > 1) {
176
- return this.stack.pop();
177
- }
178
- // eslint-disable-next-line no-undefined
179
- return undefined;
180
- }
181
- closeAllNodes() {
182
- while (this.closeNode())
183
- ;
184
- }
185
- toJSON() {
186
- return JSON.stringify(this.rootNode, null, 4);
187
- }
188
- /**
189
- * @typedef { import("./html_renderer").Renderer } Renderer
190
- * @param {Renderer} builder
191
- */
192
- walk(builder) {
193
- // this does not
194
- return this.constructor._walk(builder, this.rootNode);
195
- // this works
196
- // return TokenTree._walk(builder, this.rootNode);
197
- }
198
- /**
199
- * @param {Renderer} builder
200
- * @param {Node} node
201
- */
202
- static _walk(builder, node) {
203
- if (typeof node === "string") {
204
- builder.addText(node);
205
- }
206
- else if (node.children) {
207
- builder.openNode(node);
208
- node.children.forEach((child) => this._walk(builder, child));
209
- builder.closeNode(node);
210
- }
211
- return builder;
212
- }
213
- /**
214
- * @param {Node} node
215
- */
216
- static _collapse(node) {
217
- if (typeof node === "string")
218
- return;
219
- if (!node.children)
220
- return;
221
- if (node.children.every(el => typeof el === "string")) {
222
- // node.text = node.children.join("");
223
- // delete node.children;
224
- node.children = [node.children.join("")];
225
- }
226
- else {
227
- node.children.forEach((child) => {
228
- TokenTree._collapse(child);
229
- });
230
- }
176
+ constructor() {
177
+ /** @type DataNode */
178
+ this.rootNode = { children: [] };
179
+ this.stack = [this.rootNode];
180
+ }
181
+
182
+ get top() {
183
+ return this.stack[this.stack.length - 1];
184
+ }
185
+
186
+ get root() { return this.rootNode; }
187
+
188
+ /** @param {Node} node */
189
+ add(node) {
190
+ this.top.children.push(node);
191
+ }
192
+
193
+ /** @param {string} kind */
194
+ openNode(kind) {
195
+ /** @type Node */
196
+ const node = { kind, children: [] };
197
+ this.add(node);
198
+ this.stack.push(node);
199
+ }
200
+
201
+ closeNode() {
202
+ if (this.stack.length > 1) {
203
+ return this.stack.pop();
231
204
  }
205
+ // eslint-disable-next-line no-undefined
206
+ return undefined;
207
+ }
208
+
209
+ closeAllNodes() {
210
+ while (this.closeNode());
211
+ }
212
+
213
+ toJSON() {
214
+ return JSON.stringify(this.rootNode, null, 4);
215
+ }
216
+
217
+ /**
218
+ * @typedef { import("./html_renderer").Renderer } Renderer
219
+ * @param {Renderer} builder
220
+ */
221
+ walk(builder) {
222
+ // this does not
223
+ return this.constructor._walk(builder, this.rootNode);
224
+ // this works
225
+ // return TokenTree._walk(builder, this.rootNode);
226
+ }
227
+
228
+ /**
229
+ * @param {Renderer} builder
230
+ * @param {Node} node
231
+ */
232
+ static _walk(builder, node) {
233
+ if (typeof node === "string") {
234
+ builder.addText(node);
235
+ } else if (node.children) {
236
+ builder.openNode(node);
237
+ node.children.forEach((child) => this._walk(builder, child));
238
+ builder.closeNode(node);
239
+ }
240
+ return builder;
241
+ }
242
+
243
+ /**
244
+ * @param {Node} node
245
+ */
246
+ static _collapse(node) {
247
+ if (typeof node === "string") return;
248
+ if (!node.children) return;
249
+
250
+ if (node.children.every(el => typeof el === "string")) {
251
+ // node.text = node.children.join("");
252
+ // delete node.children;
253
+ node.children = [node.children.join("")];
254
+ } else {
255
+ node.children.forEach((child) => {
256
+ TokenTree._collapse(child);
257
+ });
258
+ }
259
+ }
232
260
  }
261
+
233
262
  /**
234
263
  Currently this is all private API, but this is the minimal API necessary
235
264
  that an Emitter must implement to fully support the parser.
@@ -246,83 +275,90 @@ class TokenTree {
246
275
  - toHTML()
247
276
 
248
277
  */
278
+
249
279
  /**
250
280
  * @implements {Emitter}
251
281
  */
252
282
  class TokenTreeEmitter extends TokenTree {
253
- /**
254
- * @param {*} options
255
- */
256
- constructor(options) {
257
- super();
258
- this.options = options;
259
- }
260
- /**
261
- * @param {string} text
262
- * @param {string} kind
263
- */
264
- addKeyword(text, kind) {
265
- if (text === "") {
266
- return;
267
- }
268
- this.openNode(kind);
269
- this.addText(text);
270
- this.closeNode();
271
- }
272
- /**
273
- * @param {string} text
274
- */
275
- addText(text) {
276
- if (text === "") {
277
- return;
278
- }
279
- this.add(text);
280
- }
281
- /**
282
- * @param {Emitter & {root: DataNode}} emitter
283
- * @param {string} name
284
- */
285
- addSublanguage(emitter, name) {
286
- /** @type DataNode */
287
- const node = emitter.root;
288
- node.kind = name;
289
- node.sublanguage = true;
290
- this.add(node);
291
- }
292
- toHTML() {
293
- const renderer = new HTMLRenderer(this, this.options);
294
- return renderer.value();
295
- }
296
- finalize() {
297
- return true;
298
- }
283
+ /**
284
+ * @param {*} options
285
+ */
286
+ constructor(options) {
287
+ super();
288
+ this.options = options;
289
+ }
290
+
291
+ /**
292
+ * @param {string} text
293
+ * @param {string} kind
294
+ */
295
+ addKeyword(text, kind) {
296
+ if (text === "") { return; }
297
+
298
+ this.openNode(kind);
299
+ this.addText(text);
300
+ this.closeNode();
301
+ }
302
+
303
+ /**
304
+ * @param {string} text
305
+ */
306
+ addText(text) {
307
+ if (text === "") { return; }
308
+
309
+ this.add(text);
310
+ }
311
+
312
+ /**
313
+ * @param {Emitter & {root: DataNode}} emitter
314
+ * @param {string} name
315
+ */
316
+ addSublanguage(emitter, name) {
317
+ /** @type DataNode */
318
+ const node = emitter.root;
319
+ node.kind = name;
320
+ node.sublanguage = true;
321
+ this.add(node);
322
+ }
323
+
324
+ toHTML() {
325
+ const renderer = new HTMLRenderer(this, this.options);
326
+ return renderer.value();
327
+ }
328
+
329
+ finalize() {
330
+ return true;
331
+ }
299
332
  }
333
+
300
334
  /**
301
335
  * @param {string} value
302
336
  * @returns {RegExp}
303
337
  * */
304
338
  function escape(value) {
305
- return new RegExp(value.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'), 'm');
339
+ return new RegExp(value.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'), 'm');
306
340
  }
341
+
307
342
  /**
308
343
  * @param {RegExp | string } re
309
344
  * @returns {string}
310
345
  */
311
346
  function source(re) {
312
- if (!re)
313
- return null;
314
- if (typeof re === "string")
315
- return re;
316
- return re.source;
347
+ if (!re) return null;
348
+ if (typeof re === "string") return re;
349
+
350
+ return re.source;
317
351
  }
352
+
318
353
  /**
319
354
  * @param {...(RegExp | string) } args
320
355
  * @returns {string}
321
356
  */
322
357
  function concat(...args) {
323
- const joined = args.map((x) => source(x)).join("");
324
- return joined;
358
+ const joined = args.map((x) => source(x)).join("");
359
+ return joined;
325
360
  }
361
+
326
362
  /**
327
363
  * Any of the passed expresssions may match
328
364
  *
@@ -331,25 +367,28 @@ function concat(...args) {
331
367
  * @returns {string}
332
368
  */
333
369
  function either(...args) {
334
- const joined = '(' + args.map((x) => source(x)).join("|") + ")";
335
- return joined;
370
+ const joined = '(' + args.map((x) => source(x)).join("|") + ")";
371
+ return joined;
336
372
  }
373
+
337
374
  /**
338
375
  * @param {RegExp} re
339
376
  * @returns {number}
340
377
  */
341
378
  function countMatchGroups(re) {
342
- return (new RegExp(re.toString() + '|')).exec('').length - 1;
379
+ return (new RegExp(re.toString() + '|')).exec('').length - 1;
343
380
  }
381
+
344
382
  /**
345
383
  * Does lexeme start with a regular expression match at the beginning
346
384
  * @param {RegExp} re
347
385
  * @param {string} lexeme
348
386
  */
349
387
  function startsWith(re, lexeme) {
350
- const match = re && re.exec(lexeme);
351
- return match && match.index === 0;
388
+ const match = re && re.exec(lexeme);
389
+ return match && match.index === 0;
352
390
  }
391
+
353
392
  // BACKREF_RE matches an open parenthesis or backreference. To avoid
354
393
  // an incorrect parse, it additionally matches the following:
355
394
  // - [...] elements, where the meaning of parentheses and escapes change
@@ -358,6 +397,7 @@ function startsWith(re, lexeme) {
358
397
  // - non-matching or lookahead parentheses, which do not capture. These
359
398
  // follow the '(' with a '?'.
360
399
  const BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
400
+
361
401
  // join logically computes regexps.join(separator), but fixes the
362
402
  // backreferences so they continue to match.
363
403
  // it also places each individual regular expression into it's own
@@ -369,34 +409,36 @@ const BACKREF_RE = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
369
409
  * @returns {string}
370
410
  */
371
411
  function join(regexps, separator = "|") {
372
- let numCaptures = 0;
373
- return regexps.map((regex) => {
374
- numCaptures += 1;
375
- const offset = numCaptures;
376
- let re = source(regex);
377
- let out = '';
378
- while (re.length > 0) {
379
- const match = BACKREF_RE.exec(re);
380
- if (!match) {
381
- out += re;
382
- break;
383
- }
384
- out += re.substring(0, match.index);
385
- re = re.substring(match.index + match[0].length);
386
- if (match[0][0] === '\\' && match[1]) {
387
- // Adjust the backreference.
388
- out += '\\' + String(Number(match[1]) + offset);
389
- }
390
- else {
391
- out += match[0];
392
- if (match[0] === '(') {
393
- numCaptures++;
394
- }
395
- }
396
- }
397
- return out;
398
- }).map(re => `(${re})`).join(separator);
412
+ let numCaptures = 0;
413
+
414
+ return regexps.map((regex) => {
415
+ numCaptures += 1;
416
+ const offset = numCaptures;
417
+ let re = source(regex);
418
+ let out = '';
419
+
420
+ while (re.length > 0) {
421
+ const match = BACKREF_RE.exec(re);
422
+ if (!match) {
423
+ out += re;
424
+ break;
425
+ }
426
+ out += re.substring(0, match.index);
427
+ re = re.substring(match.index + match[0].length);
428
+ if (match[0][0] === '\\' && match[1]) {
429
+ // Adjust the backreference.
430
+ out += '\\' + String(Number(match[1]) + offset);
431
+ } else {
432
+ out += match[0];
433
+ if (match[0] === '(') {
434
+ numCaptures++;
435
+ }
436
+ }
437
+ }
438
+ return out;
439
+ }).map(re => `(${re})`).join(separator);
399
440
  }
441
+
400
442
  // Common regexps
401
443
  const MATCH_NOTHING_RE = /\b\B/;
402
444
  const IDENT_RE = '[a-zA-Z]\\w*';
@@ -405,46 +447,51 @@ const NUMBER_RE = '\\b\\d+(\\.\\d+)?';
405
447
  const C_NUMBER_RE = '(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)'; // 0x..., 0..., decimal, float
406
448
  const BINARY_NUMBER_RE = '\\b(0b[01]+)'; // 0b...
407
449
  const RE_STARTERS_RE = '!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~';
450
+
408
451
  /**
409
452
  * @param { Partial<Mode> & {binary?: string | RegExp} } opts
410
453
  */
411
454
  const SHEBANG = (opts = {}) => {
412
- const beginShebang = /^#![ ]*\//;
413
- if (opts.binary) {
414
- opts.begin = concat(beginShebang, /.*\b/, opts.binary, /\b.*/);
415
- }
416
- return inherit({
417
- className: 'meta',
418
- begin: beginShebang,
419
- end: /$/,
420
- relevance: 0,
421
- /** @type {ModeCallback} */
422
- "on:begin": (m, resp) => {
423
- if (m.index !== 0)
424
- resp.ignoreMatch();
425
- }
426
- }, opts);
455
+ const beginShebang = /^#![ ]*\//;
456
+ if (opts.binary) {
457
+ opts.begin = concat(
458
+ beginShebang,
459
+ /.*\b/,
460
+ opts.binary,
461
+ /\b.*/);
462
+ }
463
+ return inherit({
464
+ className: 'meta',
465
+ begin: beginShebang,
466
+ end: /$/,
467
+ relevance: 0,
468
+ /** @type {ModeCallback} */
469
+ "on:begin": (m, resp) => {
470
+ if (m.index !== 0) resp.ignoreMatch();
471
+ }
472
+ }, opts);
427
473
  };
474
+
428
475
  // Common modes
429
476
  const BACKSLASH_ESCAPE = {
430
- begin: '\\\\[\\s\\S]', relevance: 0
477
+ begin: '\\\\[\\s\\S]', relevance: 0
431
478
  };
432
479
  const APOS_STRING_MODE = {
433
- className: 'string',
434
- begin: '\'',
435
- end: '\'',
436
- illegal: '\\n',
437
- contains: [BACKSLASH_ESCAPE]
480
+ className: 'string',
481
+ begin: '\'',
482
+ end: '\'',
483
+ illegal: '\\n',
484
+ contains: [BACKSLASH_ESCAPE]
438
485
  };
439
486
  const QUOTE_STRING_MODE = {
440
- className: 'string',
441
- begin: '"',
442
- end: '"',
443
- illegal: '\\n',
444
- contains: [BACKSLASH_ESCAPE]
487
+ className: 'string',
488
+ begin: '"',
489
+ end: '"',
490
+ illegal: '\\n',
491
+ contains: [BACKSLASH_ESCAPE]
445
492
  };
446
493
  const PHRASAL_WORDS_MODE = {
447
- begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
494
+ begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
448
495
  };
449
496
  /**
450
497
  * Creates a comment mode
@@ -454,91 +501,95 @@ const PHRASAL_WORDS_MODE = {
454
501
  * @param {Mode | {}} [modeOptions]
455
502
  * @returns {Partial<Mode>}
456
503
  */
457
- const COMMENT = function (begin, end, modeOptions = {}) {
458
- const mode = inherit({
459
- className: 'comment',
460
- begin,
461
- end,
462
- contains: []
463
- }, modeOptions);
464
- mode.contains.push(PHRASAL_WORDS_MODE);
465
- mode.contains.push({
466
- className: 'doctag',
467
- begin: '(?:TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):',
468
- relevance: 0
469
- });
470
- return mode;
504
+ const COMMENT = function(begin, end, modeOptions = {}) {
505
+ const mode = inherit(
506
+ {
507
+ className: 'comment',
508
+ begin,
509
+ end,
510
+ contains: []
511
+ },
512
+ modeOptions
513
+ );
514
+ mode.contains.push(PHRASAL_WORDS_MODE);
515
+ mode.contains.push({
516
+ className: 'doctag',
517
+ begin: '(?:TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):',
518
+ relevance: 0
519
+ });
520
+ return mode;
471
521
  };
472
522
  const C_LINE_COMMENT_MODE = COMMENT('//', '$');
473
523
  const C_BLOCK_COMMENT_MODE = COMMENT('/\\*', '\\*/');
474
524
  const HASH_COMMENT_MODE = COMMENT('#', '$');
475
525
  const NUMBER_MODE = {
476
- className: 'number',
477
- begin: NUMBER_RE,
478
- relevance: 0
526
+ className: 'number',
527
+ begin: NUMBER_RE,
528
+ relevance: 0
479
529
  };
480
530
  const C_NUMBER_MODE = {
481
- className: 'number',
482
- begin: C_NUMBER_RE,
483
- relevance: 0
531
+ className: 'number',
532
+ begin: C_NUMBER_RE,
533
+ relevance: 0
484
534
  };
485
535
  const BINARY_NUMBER_MODE = {
486
- className: 'number',
487
- begin: BINARY_NUMBER_RE,
488
- relevance: 0
536
+ className: 'number',
537
+ begin: BINARY_NUMBER_RE,
538
+ relevance: 0
489
539
  };
490
540
  const CSS_NUMBER_MODE = {
491
- className: 'number',
492
- begin: NUMBER_RE + '(' +
493
- '%|em|ex|ch|rem' +
494
- '|vw|vh|vmin|vmax' +
495
- '|cm|mm|in|pt|pc|px' +
496
- '|deg|grad|rad|turn' +
497
- '|s|ms' +
498
- '|Hz|kHz' +
499
- '|dpi|dpcm|dppx' +
500
- ')?',
501
- relevance: 0
541
+ className: 'number',
542
+ begin: NUMBER_RE + '(' +
543
+ '%|em|ex|ch|rem' +
544
+ '|vw|vh|vmin|vmax' +
545
+ '|cm|mm|in|pt|pc|px' +
546
+ '|deg|grad|rad|turn' +
547
+ '|s|ms' +
548
+ '|Hz|kHz' +
549
+ '|dpi|dpcm|dppx' +
550
+ ')?',
551
+ relevance: 0
502
552
  };
503
553
  const REGEXP_MODE = {
504
- // this outer rule makes sure we actually have a WHOLE regex and not simply
505
- // an expression such as:
506
- //
507
- // 3 / something
508
- //
509
- // (which will then blow up when regex's `illegal` sees the newline)
510
- begin: /(?=\/[^/\n]*\/)/,
511
- contains: [{
512
- className: 'regexp',
513
- begin: /\//,
514
- end: /\/[gimuy]*/,
515
- illegal: /\n/,
516
- contains: [
517
- BACKSLASH_ESCAPE,
518
- {
519
- begin: /\[/,
520
- end: /\]/,
521
- relevance: 0,
522
- contains: [BACKSLASH_ESCAPE]
523
- }
524
- ]
525
- }]
554
+ // this outer rule makes sure we actually have a WHOLE regex and not simply
555
+ // an expression such as:
556
+ //
557
+ // 3 / something
558
+ //
559
+ // (which will then blow up when regex's `illegal` sees the newline)
560
+ begin: /(?=\/[^/\n]*\/)/,
561
+ contains: [{
562
+ className: 'regexp',
563
+ begin: /\//,
564
+ end: /\/[gimuy]*/,
565
+ illegal: /\n/,
566
+ contains: [
567
+ BACKSLASH_ESCAPE,
568
+ {
569
+ begin: /\[/,
570
+ end: /\]/,
571
+ relevance: 0,
572
+ contains: [BACKSLASH_ESCAPE]
573
+ }
574
+ ]
575
+ }]
526
576
  };
527
577
  const TITLE_MODE = {
528
- className: 'title',
529
- begin: IDENT_RE,
530
- relevance: 0
578
+ className: 'title',
579
+ begin: IDENT_RE,
580
+ relevance: 0
531
581
  };
532
582
  const UNDERSCORE_TITLE_MODE = {
533
- className: 'title',
534
- begin: UNDERSCORE_IDENT_RE,
535
- relevance: 0
583
+ className: 'title',
584
+ begin: UNDERSCORE_IDENT_RE,
585
+ relevance: 0
536
586
  };
537
587
  const METHOD_GUARD = {
538
- // excludes method names from keyword processing
539
- begin: '\\.\\s*' + UNDERSCORE_IDENT_RE,
540
- relevance: 0
588
+ // excludes method names from keyword processing
589
+ begin: '\\.\\s*' + UNDERSCORE_IDENT_RE,
590
+ relevance: 0
541
591
  };
592
+
542
593
  /**
543
594
  * Adds end same as begin mechanics to a mode
544
595
  *
@@ -546,16 +597,17 @@ const METHOD_GUARD = {
546
597
  * group is what is used for comparison
547
598
  * @param {Partial<Mode>} mode
548
599
  */
549
- const END_SAME_AS_BEGIN = function (mode) {
550
- return Object.assign(mode, {
551
- /** @type {ModeCallback} */
552
- 'on:begin': (m, resp) => { resp.data._beginMatch = m[1]; },
553
- /** @type {ModeCallback} */
554
- 'on:end': (m, resp) => { if (resp.data._beginMatch !== m[1])
555
- resp.ignoreMatch(); }
600
+ const END_SAME_AS_BEGIN = function(mode) {
601
+ return Object.assign(mode,
602
+ {
603
+ /** @type {ModeCallback} */
604
+ 'on:begin': (m, resp) => { resp.data._beginMatch = m[1]; },
605
+ /** @type {ModeCallback} */
606
+ 'on:end': (m, resp) => { if (resp.data._beginMatch !== m[1]) resp.ignoreMatch(); }
556
607
  });
557
608
  };
558
- var MODES = /*#__PURE__*/ Object.freeze({
609
+
610
+ var MODES = /*#__PURE__*/Object.freeze({
559
611
  __proto__: null,
560
612
  MATCH_NOTHING_RE: MATCH_NOTHING_RE,
561
613
  IDENT_RE: IDENT_RE,
@@ -583,16 +635,21 @@ var MODES = /*#__PURE__*/ Object.freeze({
583
635
  METHOD_GUARD: METHOD_GUARD,
584
636
  END_SAME_AS_BEGIN: END_SAME_AS_BEGIN
585
637
  });
638
+
586
639
  // Grammar extensions / plugins
587
640
  // See: https://github.com/highlightjs/highlight.js/issues/2833
641
+
588
642
  // Grammar extensions allow "syntactic sugar" to be added to the grammar modes
589
643
  // without requiring any underlying changes to the compiler internals.
644
+
590
645
  // `compileMatch` being the perfect small example of now allowing a grammar
591
646
  // author to write `match` when they desire to match a single expression rather
592
647
  // than being forced to use `begin`. The extension then just moves `match` into
593
648
  // `begin` when it runs. Ie, no features have been added, but we've just made
594
649
  // the experience of writing (and reading grammars) a little bit nicer.
650
+
595
651
  // ------
652
+
596
653
  // TODO: We need negative look-behind support to do this properly
597
654
  /**
598
655
  * Skip a match if it has a preceding dot
@@ -604,80 +661,85 @@ var MODES = /*#__PURE__*/ Object.freeze({
604
661
  * @param {CallbackResponse} response
605
662
  */
606
663
  function skipIfhasPrecedingDot(match, response) {
607
- const before = match.input[match.index - 1];
608
- if (before === ".") {
609
- response.ignoreMatch();
610
- }
664
+ const before = match.input[match.index - 1];
665
+ if (before === ".") {
666
+ response.ignoreMatch();
667
+ }
611
668
  }
669
+
670
+
612
671
  /**
613
672
  * `beginKeywords` syntactic sugar
614
673
  * @type {CompilerExt}
615
674
  */
616
675
  function beginKeywords(mode, parent) {
617
- if (!parent)
618
- return;
619
- if (!mode.beginKeywords)
620
- return;
621
- // for languages with keywords that include non-word characters checking for
622
- // a word boundary is not sufficient, so instead we check for a word boundary
623
- // or whitespace - this does no harm in any case since our keyword engine
624
- // doesn't allow spaces in keywords anyways and we still check for the boundary
625
- // first
626
- mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')(?!\\.)(?=\\b|\\s)';
627
- mode.__beforeBegin = skipIfhasPrecedingDot;
628
- mode.keywords = mode.keywords || mode.beginKeywords;
629
- delete mode.beginKeywords;
630
- // prevents double relevance, the keywords themselves provide
631
- // relevance, the mode doesn't need to double it
632
- // eslint-disable-next-line no-undefined
633
- if (mode.relevance === undefined)
634
- mode.relevance = 0;
676
+ if (!parent) return;
677
+ if (!mode.beginKeywords) return;
678
+
679
+ // for languages with keywords that include non-word characters checking for
680
+ // a word boundary is not sufficient, so instead we check for a word boundary
681
+ // or whitespace - this does no harm in any case since our keyword engine
682
+ // doesn't allow spaces in keywords anyways and we still check for the boundary
683
+ // first
684
+ mode.begin = '\\b(' + mode.beginKeywords.split(' ').join('|') + ')(?!\\.)(?=\\b|\\s)';
685
+ mode.__beforeBegin = skipIfhasPrecedingDot;
686
+ mode.keywords = mode.keywords || mode.beginKeywords;
687
+ delete mode.beginKeywords;
688
+
689
+ // prevents double relevance, the keywords themselves provide
690
+ // relevance, the mode doesn't need to double it
691
+ // eslint-disable-next-line no-undefined
692
+ if (mode.relevance === undefined) mode.relevance = 0;
635
693
  }
694
+
636
695
  /**
637
696
  * Allow `illegal` to contain an array of illegal values
638
697
  * @type {CompilerExt}
639
698
  */
640
699
  function compileIllegal(mode, _parent) {
641
- if (!Array.isArray(mode.illegal))
642
- return;
643
- mode.illegal = either(...mode.illegal);
700
+ if (!Array.isArray(mode.illegal)) return;
701
+
702
+ mode.illegal = either(...mode.illegal);
644
703
  }
704
+
645
705
  /**
646
706
  * `match` to match a single expression for readability
647
707
  * @type {CompilerExt}
648
708
  */
649
709
  function compileMatch(mode, _parent) {
650
- if (!mode.match)
651
- return;
652
- if (mode.begin || mode.end)
653
- throw new Error("begin & end are not supported with match");
654
- mode.begin = mode.match;
655
- delete mode.match;
710
+ if (!mode.match) return;
711
+ if (mode.begin || mode.end) throw new Error("begin & end are not supported with match");
712
+
713
+ mode.begin = mode.match;
714
+ delete mode.match;
656
715
  }
716
+
657
717
  /**
658
718
  * provides the default 1 relevance to all modes
659
719
  * @type {CompilerExt}
660
720
  */
661
721
  function compileRelevance(mode, _parent) {
662
- // eslint-disable-next-line no-undefined
663
- if (mode.relevance === undefined)
664
- mode.relevance = 1;
722
+ // eslint-disable-next-line no-undefined
723
+ if (mode.relevance === undefined) mode.relevance = 1;
665
724
  }
725
+
666
726
  // keywords that should have no default relevance value
667
727
  const COMMON_KEYWORDS = [
668
- 'of',
669
- 'and',
670
- 'for',
671
- 'in',
672
- 'not',
673
- 'or',
674
- 'if',
675
- 'then',
676
- 'parent', // common variable name
677
- 'list', // common variable name
678
- 'value' // common variable name
728
+ 'of',
729
+ 'and',
730
+ 'for',
731
+ 'in',
732
+ 'not',
733
+ 'or',
734
+ 'if',
735
+ 'then',
736
+ 'parent', // common variable name
737
+ 'list', // common variable name
738
+ 'value' // common variable name
679
739
  ];
740
+
680
741
  const DEFAULT_KEYWORD_CLASSNAME = "keyword";
742
+
681
743
  /**
682
744
  * Given raw keywords from a language definition, compile them.
683
745
  *
@@ -685,42 +747,47 @@ const DEFAULT_KEYWORD_CLASSNAME = "keyword";
685
747
  * @param {boolean} caseInsensitive
686
748
  */
687
749
  function compileKeywords(rawKeywords, caseInsensitive, className = DEFAULT_KEYWORD_CLASSNAME) {
688
- /** @type KeywordDict */
689
- const compiledKeywords = {};
690
- // input can be a string of keywords, an array of keywords, or a object with
691
- // named keys representing className (which can then point to a string or array)
692
- if (typeof rawKeywords === 'string') {
693
- compileList(className, rawKeywords.split(" "));
694
- }
695
- else if (Array.isArray(rawKeywords)) {
696
- compileList(className, rawKeywords);
697
- }
698
- else {
699
- Object.keys(rawKeywords).forEach(function (className) {
700
- // collapse all our objects back into the parent object
701
- Object.assign(compiledKeywords, compileKeywords(rawKeywords[className], caseInsensitive, className));
702
- });
703
- }
704
- return compiledKeywords;
705
- // ---
706
- /**
707
- * Compiles an individual list of keywords
708
- *
709
- * Ex: "for if when while|5"
710
- *
711
- * @param {string} className
712
- * @param {Array<string>} keywordList
713
- */
714
- function compileList(className, keywordList) {
715
- if (caseInsensitive) {
716
- keywordList = keywordList.map(x => x.toLowerCase());
717
- }
718
- keywordList.forEach(function (keyword) {
719
- const pair = keyword.split('|');
720
- compiledKeywords[pair[0]] = [className, scoreForKeyword(pair[0], pair[1])];
721
- });
722
- }
750
+ /** @type KeywordDict */
751
+ const compiledKeywords = {};
752
+
753
+ // input can be a string of keywords, an array of keywords, or a object with
754
+ // named keys representing className (which can then point to a string or array)
755
+ if (typeof rawKeywords === 'string') {
756
+ compileList(className, rawKeywords.split(" "));
757
+ } else if (Array.isArray(rawKeywords)) {
758
+ compileList(className, rawKeywords);
759
+ } else {
760
+ Object.keys(rawKeywords).forEach(function(className) {
761
+ // collapse all our objects back into the parent object
762
+ Object.assign(
763
+ compiledKeywords,
764
+ compileKeywords(rawKeywords[className], caseInsensitive, className)
765
+ );
766
+ });
767
+ }
768
+ return compiledKeywords;
769
+
770
+ // ---
771
+
772
+ /**
773
+ * Compiles an individual list of keywords
774
+ *
775
+ * Ex: "for if when while|5"
776
+ *
777
+ * @param {string} className
778
+ * @param {Array<string>} keywordList
779
+ */
780
+ function compileList(className, keywordList) {
781
+ if (caseInsensitive) {
782
+ keywordList = keywordList.map(x => x.toLowerCase());
783
+ }
784
+ keywordList.forEach(function(keyword) {
785
+ const pair = keyword.split('|');
786
+ compiledKeywords[pair[0]] = [className, scoreForKeyword(pair[0], pair[1])];
787
+ });
788
+ }
723
789
  }
790
+
724
791
  /**
725
792
  * Returns the proper score for a given keyword
726
793
  *
@@ -730,21 +797,25 @@ function compileKeywords(rawKeywords, caseInsensitive, className = DEFAULT_KEYWO
730
797
  * @param {string} [providedScore]
731
798
  */
732
799
  function scoreForKeyword(keyword, providedScore) {
733
- // manual scores always win over common keywords
734
- // so you can force a score of 1 if you really insist
735
- if (providedScore) {
736
- return Number(providedScore);
737
- }
738
- return commonKeyword(keyword) ? 0 : 1;
800
+ // manual scores always win over common keywords
801
+ // so you can force a score of 1 if you really insist
802
+ if (providedScore) {
803
+ return Number(providedScore);
804
+ }
805
+
806
+ return commonKeyword(keyword) ? 0 : 1;
739
807
  }
808
+
740
809
  /**
741
810
  * Determines if a given keyword is common or not
742
811
  *
743
812
  * @param {string} keyword */
744
813
  function commonKeyword(keyword) {
745
- return COMMON_KEYWORDS.includes(keyword.toLowerCase());
814
+ return COMMON_KEYWORDS.includes(keyword.toLowerCase());
746
815
  }
816
+
747
817
  // compilation
818
+
748
819
  /**
749
820
  * Compiles a language definition result
750
821
  *
@@ -755,332 +826,368 @@ function commonKeyword(keyword) {
755
826
  * @returns {CompiledLanguage}
756
827
  */
757
828
  function compileLanguage(language, { plugins }) {
758
- /**
759
- * Builds a regex with the case sensativility of the current language
760
- *
761
- * @param {RegExp | string} value
762
- * @param {boolean} [global]
763
- */
764
- function langRe(value, global) {
765
- return new RegExp(source(value), 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : ''));
829
+ /**
830
+ * Builds a regex with the case sensativility of the current language
831
+ *
832
+ * @param {RegExp | string} value
833
+ * @param {boolean} [global]
834
+ */
835
+ function langRe(value, global) {
836
+ return new RegExp(
837
+ source(value),
838
+ 'm' + (language.case_insensitive ? 'i' : '') + (global ? 'g' : '')
839
+ );
840
+ }
841
+
842
+ /**
843
+ Stores multiple regular expressions and allows you to quickly search for
844
+ them all in a string simultaneously - returning the first match. It does
845
+ this by creating a huge (a|b|c) regex - each individual item wrapped with ()
846
+ and joined by `|` - using match groups to track position. When a match is
847
+ found checking which position in the array has content allows us to figure
848
+ out which of the original regexes / match groups triggered the match.
849
+
850
+ The match object itself (the result of `Regex.exec`) is returned but also
851
+ enhanced by merging in any meta-data that was registered with the regex.
852
+ This is how we keep track of which mode matched, and what type of rule
853
+ (`illegal`, `begin`, end, etc).
854
+ */
855
+ class MultiRegex {
856
+ constructor() {
857
+ this.matchIndexes = {};
858
+ // @ts-ignore
859
+ this.regexes = [];
860
+ this.matchAt = 1;
861
+ this.position = 0;
766
862
  }
767
- /**
768
- Stores multiple regular expressions and allows you to quickly search for
769
- them all in a string simultaneously - returning the first match. It does
770
- this by creating a huge (a|b|c) regex - each individual item wrapped with ()
771
- and joined by `|` - using match groups to track position. When a match is
772
- found checking which position in the array has content allows us to figure
773
- out which of the original regexes / match groups triggered the match.
774
-
775
- The match object itself (the result of `Regex.exec`) is returned but also
776
- enhanced by merging in any meta-data that was registered with the regex.
777
- This is how we keep track of which mode matched, and what type of rule
778
- (`illegal`, `begin`, end, etc).
779
- */
780
- class MultiRegex {
781
- constructor() {
782
- this.matchIndexes = {};
783
- // @ts-ignore
784
- this.regexes = [];
785
- this.matchAt = 1;
786
- this.position = 0;
787
- }
788
- // @ts-ignore
789
- addRule(re, opts) {
790
- opts.position = this.position++;
791
- // @ts-ignore
792
- this.matchIndexes[this.matchAt] = opts;
793
- this.regexes.push([opts, re]);
794
- this.matchAt += countMatchGroups(re) + 1;
795
- }
796
- compile() {
797
- if (this.regexes.length === 0) {
798
- // avoids the need to check length every time exec is called
799
- // @ts-ignore
800
- this.exec = () => null;
801
- }
802
- const terminators = this.regexes.map(el => el[1]);
803
- this.matcherRe = langRe(join(terminators), true);
804
- this.lastIndex = 0;
805
- }
806
- /** @param {string} s */
807
- exec(s) {
808
- this.matcherRe.lastIndex = this.lastIndex;
809
- const match = this.matcherRe.exec(s);
810
- if (!match) {
811
- return null;
812
- }
813
- // eslint-disable-next-line no-undefined
814
- const i = match.findIndex((el, i) => i > 0 && el !== undefined);
815
- // @ts-ignore
816
- const matchData = this.matchIndexes[i];
817
- // trim off any earlier non-relevant match groups (ie, the other regex
818
- // match groups that make up the multi-matcher)
819
- match.splice(0, i);
820
- return Object.assign(match, matchData);
821
- }
863
+
864
+ // @ts-ignore
865
+ addRule(re, opts) {
866
+ opts.position = this.position++;
867
+ // @ts-ignore
868
+ this.matchIndexes[this.matchAt] = opts;
869
+ this.regexes.push([opts, re]);
870
+ this.matchAt += countMatchGroups(re) + 1;
822
871
  }
823
- /*
824
- Created to solve the key deficiently with MultiRegex - there is no way to
825
- test for multiple matches at a single location. Why would we need to do
826
- that? In the future a more dynamic engine will allow certain matches to be
827
- ignored. An example: if we matched say the 3rd regex in a large group but
828
- decided to ignore it - we'd need to started testing again at the 4th
829
- regex... but MultiRegex itself gives us no real way to do that.
830
-
831
- So what this class creates MultiRegexs on the fly for whatever search
832
- position they are needed.
833
-
834
- NOTE: These additional MultiRegex objects are created dynamically. For most
835
- grammars most of the time we will never actually need anything more than the
836
- first MultiRegex - so this shouldn't have too much overhead.
837
-
838
- Say this is our search group, and we match regex3, but wish to ignore it.
839
-
840
- regex1 | regex2 | regex3 | regex4 | regex5 ' ie, startAt = 0
841
-
842
- What we need is a new MultiRegex that only includes the remaining
843
- possibilities:
844
-
845
- regex4 | regex5 ' ie, startAt = 3
846
-
847
- This class wraps all that complexity up in a simple API... `startAt` decides
848
- where in the array of expressions to start doing the matching. It
849
- auto-increments, so if a match is found at position 2, then startAt will be
850
- set to 3. If the end is reached startAt will return to 0.
851
-
852
- MOST of the time the parser will be setting startAt manually to 0.
853
- */
854
- class ResumableMultiRegex {
855
- constructor() {
856
- // @ts-ignore
857
- this.rules = [];
858
- // @ts-ignore
859
- this.multiRegexes = [];
860
- this.count = 0;
861
- this.lastIndex = 0;
862
- this.regexIndex = 0;
863
- }
864
- // @ts-ignore
865
- getMatcher(index) {
866
- if (this.multiRegexes[index])
867
- return this.multiRegexes[index];
868
- const matcher = new MultiRegex();
869
- this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
870
- matcher.compile();
871
- this.multiRegexes[index] = matcher;
872
- return matcher;
873
- }
874
- resumingScanAtSamePosition() {
875
- return this.regexIndex !== 0;
876
- }
877
- considerAll() {
878
- this.regexIndex = 0;
879
- }
872
+
873
+ compile() {
874
+ if (this.regexes.length === 0) {
875
+ // avoids the need to check length every time exec is called
880
876
  // @ts-ignore
881
- addRule(re, opts) {
882
- this.rules.push([re, opts]);
883
- if (opts.type === "begin")
884
- this.count++;
885
- }
886
- /** @param {string} s */
887
- exec(s) {
888
- const m = this.getMatcher(this.regexIndex);
889
- m.lastIndex = this.lastIndex;
890
- let result = m.exec(s);
891
- // The following is because we have no easy way to say "resume scanning at the
892
- // existing position but also skip the current rule ONLY". What happens is
893
- // all prior rules are also skipped which can result in matching the wrong
894
- // thing. Example of matching "booger":
895
- // our matcher is [string, "booger", number]
896
- //
897
- // ....booger....
898
- // if "booger" is ignored then we'd really need a regex to scan from the
899
- // SAME position for only: [string, number] but ignoring "booger" (if it
900
- // was the first match), a simple resume would scan ahead who knows how
901
- // far looking only for "number", ignoring potential string matches (or
902
- // future "booger" matches that might be valid.)
903
- // So what we do: We execute two matchers, one resuming at the same
904
- // position, but the second full matcher starting at the position after:
905
- // /--- resume first regex match here (for [number])
906
- // |/---- full match here for [string, "booger", number]
907
- // vv
908
- // ....booger....
909
- // Which ever results in a match first is then used. So this 3-4 step
910
- // process essentially allows us to say "match at this position, excluding
911
- // a prior rule that was ignored".
912
- //
913
- // 1. Match "booger" first, ignore. Also proves that [string] does non match.
914
- // 2. Resume matching for [number]
915
- // 3. Match at index + 1 for [string, "booger", number]
916
- // 4. If #2 and #3 result in matches, which came first?
917
- if (this.resumingScanAtSamePosition()) {
918
- if (result && result.index === this.lastIndex)
919
- ;
920
- else { // use the second matcher result
921
- const m2 = this.getMatcher(0);
922
- m2.lastIndex = this.lastIndex + 1;
923
- result = m2.exec(s);
924
- }
925
- }
926
- if (result) {
927
- this.regexIndex += result.position + 1;
928
- if (this.regexIndex === this.count) {
929
- // wrap-around to considering all matches again
930
- this.considerAll();
931
- }
932
- }
933
- return result;
934
- }
877
+ this.exec = () => null;
878
+ }
879
+ const terminators = this.regexes.map(el => el[1]);
880
+ this.matcherRe = langRe(join(terminators), true);
881
+ this.lastIndex = 0;
935
882
  }
936
- /**
937
- * Given a mode, builds a huge ResumableMultiRegex that can be used to walk
938
- * the content and find matches.
939
- *
940
- * @param {CompiledMode} mode
941
- * @returns {ResumableMultiRegex}
942
- */
943
- function buildModeRegex(mode) {
944
- const mm = new ResumableMultiRegex();
945
- mode.contains.forEach(term => mm.addRule(term.begin, { rule: term, type: "begin" }));
946
- if (mode.terminatorEnd) {
947
- mm.addRule(mode.terminatorEnd, { type: "end" });
948
- }
949
- if (mode.illegal) {
950
- mm.addRule(mode.illegal, { type: "illegal" });
951
- }
952
- return mm;
883
+
884
+ /** @param {string} s */
885
+ exec(s) {
886
+ this.matcherRe.lastIndex = this.lastIndex;
887
+ const match = this.matcherRe.exec(s);
888
+ if (!match) { return null; }
889
+
890
+ // eslint-disable-next-line no-undefined
891
+ const i = match.findIndex((el, i) => i > 0 && el !== undefined);
892
+ // @ts-ignore
893
+ const matchData = this.matchIndexes[i];
894
+ // trim off any earlier non-relevant match groups (ie, the other regex
895
+ // match groups that make up the multi-matcher)
896
+ match.splice(0, i);
897
+
898
+ return Object.assign(match, matchData);
953
899
  }
954
- /** skip vs abort vs ignore
955
- *
956
- * @skip - The mode is still entered and exited normally (and contains rules apply),
957
- * but all content is held and added to the parent buffer rather than being
958
- * output when the mode ends. Mostly used with `sublanguage` to build up
959
- * a single large buffer than can be parsed by sublanguage.
960
- *
961
- * - The mode begin ands ends normally.
962
- * - Content matched is added to the parent mode buffer.
963
- * - The parser cursor is moved forward normally.
964
- *
965
- * @abort - A hack placeholder until we have ignore. Aborts the mode (as if it
966
- * never matched) but DOES NOT continue to match subsequent `contains`
967
- * modes. Abort is bad/suboptimal because it can result in modes
968
- * farther down not getting applied because an earlier rule eats the
969
- * content but then aborts.
970
- *
971
- * - The mode does not begin.
972
- * - Content matched by `begin` is added to the mode buffer.
973
- * - The parser cursor is moved forward accordingly.
974
- *
975
- * @ignore - Ignores the mode (as if it never matched) and continues to match any
976
- * subsequent `contains` modes. Ignore isn't technically possible with
977
- * the current parser implementation.
978
- *
979
- * - The mode does not begin.
980
- * - Content matched by `begin` is ignored.
981
- * - The parser cursor is not moved forward.
982
- */
983
- /**
984
- * Compiles an individual mode
985
- *
986
- * This can raise an error if the mode contains certain detectable known logic
987
- * issues.
988
- * @param {Mode} mode
989
- * @param {CompiledMode | null} [parent]
990
- * @returns {CompiledMode | never}
991
- */
992
- function compileMode(mode, parent) {
993
- const cmode = /** @type CompiledMode */ (mode);
994
- if (mode.isCompiled)
995
- return cmode;
996
- [
997
- // do this early so compiler extensions generally don't have to worry about
998
- // the distinction between match/begin
999
- compileMatch
1000
- ].forEach(ext => ext(mode, parent));
1001
- language.compilerExtensions.forEach(ext => ext(mode, parent));
1002
- // __beforeBegin is considered private API, internal use only
1003
- mode.__beforeBegin = null;
1004
- [
1005
- beginKeywords,
1006
- // do this later so compiler extensions that come earlier have access to the
1007
- // raw array if they wanted to perhaps manipulate it, etc.
1008
- compileIllegal,
1009
- // default to 1 relevance if not specified
1010
- compileRelevance
1011
- ].forEach(ext => ext(mode, parent));
1012
- mode.isCompiled = true;
1013
- let keywordPattern = null;
1014
- if (typeof mode.keywords === "object") {
1015
- keywordPattern = mode.keywords.$pattern;
1016
- delete mode.keywords.$pattern;
1017
- }
1018
- if (mode.keywords) {
1019
- mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);
1020
- }
1021
- // both are not allowed
1022
- if (mode.lexemes && keywordPattern) {
1023
- throw new Error("ERR: Prefer `keywords.$pattern` to `mode.lexemes`, BOTH are not allowed. (see mode reference) ");
1024
- }
1025
- // `mode.lexemes` was the old standard before we added and now recommend
1026
- // using `keywords.$pattern` to pass the keyword pattern
1027
- keywordPattern = keywordPattern || mode.lexemes || /\w+/;
1028
- cmode.keywordPatternRe = langRe(keywordPattern, true);
1029
- if (parent) {
1030
- if (!mode.begin)
1031
- mode.begin = /\B|\b/;
1032
- cmode.beginRe = langRe(mode.begin);
1033
- if (mode.endSameAsBegin)
1034
- mode.end = mode.begin;
1035
- if (!mode.end && !mode.endsWithParent)
1036
- mode.end = /\B|\b/;
1037
- if (mode.end)
1038
- cmode.endRe = langRe(mode.end);
1039
- cmode.terminatorEnd = source(mode.end) || '';
1040
- if (mode.endsWithParent && parent.terminatorEnd) {
1041
- cmode.terminatorEnd += (mode.end ? '|' : '') + parent.terminatorEnd;
1042
- }
1043
- }
1044
- if (mode.illegal)
1045
- cmode.illegalRe = langRe(/** @type {RegExp | string} */ (mode.illegal));
1046
- if (!mode.contains)
1047
- mode.contains = [];
1048
- mode.contains = [].concat(...mode.contains.map(function (c) {
1049
- return expandOrCloneMode(c === 'self' ? mode : c);
1050
- }));
1051
- mode.contains.forEach(function (c) { compileMode(/** @type Mode */ (c), cmode); });
1052
- if (mode.starts) {
1053
- compileMode(mode.starts, parent);
1054
- }
1055
- cmode.matcher = buildModeRegex(cmode);
1056
- return cmode;
900
+ }
901
+
902
+ /*
903
+ Created to solve the key deficiently with MultiRegex - there is no way to
904
+ test for multiple matches at a single location. Why would we need to do
905
+ that? In the future a more dynamic engine will allow certain matches to be
906
+ ignored. An example: if we matched say the 3rd regex in a large group but
907
+ decided to ignore it - we'd need to started testing again at the 4th
908
+ regex... but MultiRegex itself gives us no real way to do that.
909
+
910
+ So what this class creates MultiRegexs on the fly for whatever search
911
+ position they are needed.
912
+
913
+ NOTE: These additional MultiRegex objects are created dynamically. For most
914
+ grammars most of the time we will never actually need anything more than the
915
+ first MultiRegex - so this shouldn't have too much overhead.
916
+
917
+ Say this is our search group, and we match regex3, but wish to ignore it.
918
+
919
+ regex1 | regex2 | regex3 | regex4 | regex5 ' ie, startAt = 0
920
+
921
+ What we need is a new MultiRegex that only includes the remaining
922
+ possibilities:
923
+
924
+ regex4 | regex5 ' ie, startAt = 3
925
+
926
+ This class wraps all that complexity up in a simple API... `startAt` decides
927
+ where in the array of expressions to start doing the matching. It
928
+ auto-increments, so if a match is found at position 2, then startAt will be
929
+ set to 3. If the end is reached startAt will return to 0.
930
+
931
+ MOST of the time the parser will be setting startAt manually to 0.
932
+ */
933
+ class ResumableMultiRegex {
934
+ constructor() {
935
+ // @ts-ignore
936
+ this.rules = [];
937
+ // @ts-ignore
938
+ this.multiRegexes = [];
939
+ this.count = 0;
940
+
941
+ this.lastIndex = 0;
942
+ this.regexIndex = 0;
1057
943
  }
1058
- if (!language.compilerExtensions)
1059
- language.compilerExtensions = [];
1060
- // self is not valid at the top-level
1061
- if (language.contains && language.contains.includes('self')) {
1062
- throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
944
+
945
+ // @ts-ignore
946
+ getMatcher(index) {
947
+ if (this.multiRegexes[index]) return this.multiRegexes[index];
948
+
949
+ const matcher = new MultiRegex();
950
+ this.rules.slice(index).forEach(([re, opts]) => matcher.addRule(re, opts));
951
+ matcher.compile();
952
+ this.multiRegexes[index] = matcher;
953
+ return matcher;
1063
954
  }
1064
- // we need a null object, which inherit will guarantee
1065
- language.classNameAliases = inherit(language.classNameAliases || {});
1066
- return compileMode(/** @type Mode */ (language));
1067
- }
1068
- /**
1069
- * Determines if a mode has a dependency on it's parent or not
1070
- *
1071
- * If a mode does have a parent dependency then often we need to clone it if
1072
- * it's used in multiple places so that each copy points to the correct parent,
1073
- * where-as modes without a parent can often safely be re-used at the bottom of
955
+
956
+ resumingScanAtSamePosition() {
957
+ return this.regexIndex !== 0;
958
+ }
959
+
960
+ considerAll() {
961
+ this.regexIndex = 0;
962
+ }
963
+
964
+ // @ts-ignore
965
+ addRule(re, opts) {
966
+ this.rules.push([re, opts]);
967
+ if (opts.type === "begin") this.count++;
968
+ }
969
+
970
+ /** @param {string} s */
971
+ exec(s) {
972
+ const m = this.getMatcher(this.regexIndex);
973
+ m.lastIndex = this.lastIndex;
974
+ let result = m.exec(s);
975
+
976
+ // The following is because we have no easy way to say "resume scanning at the
977
+ // existing position but also skip the current rule ONLY". What happens is
978
+ // all prior rules are also skipped which can result in matching the wrong
979
+ // thing. Example of matching "booger":
980
+
981
+ // our matcher is [string, "booger", number]
982
+ //
983
+ // ....booger....
984
+
985
+ // if "booger" is ignored then we'd really need a regex to scan from the
986
+ // SAME position for only: [string, number] but ignoring "booger" (if it
987
+ // was the first match), a simple resume would scan ahead who knows how
988
+ // far looking only for "number", ignoring potential string matches (or
989
+ // future "booger" matches that might be valid.)
990
+
991
+ // So what we do: We execute two matchers, one resuming at the same
992
+ // position, but the second full matcher starting at the position after:
993
+
994
+ // /--- resume first regex match here (for [number])
995
+ // |/---- full match here for [string, "booger", number]
996
+ // vv
997
+ // ....booger....
998
+
999
+ // Which ever results in a match first is then used. So this 3-4 step
1000
+ // process essentially allows us to say "match at this position, excluding
1001
+ // a prior rule that was ignored".
1002
+ //
1003
+ // 1. Match "booger" first, ignore. Also proves that [string] does non match.
1004
+ // 2. Resume matching for [number]
1005
+ // 3. Match at index + 1 for [string, "booger", number]
1006
+ // 4. If #2 and #3 result in matches, which came first?
1007
+ if (this.resumingScanAtSamePosition()) {
1008
+ if (result && result.index === this.lastIndex) ; else { // use the second matcher result
1009
+ const m2 = this.getMatcher(0);
1010
+ m2.lastIndex = this.lastIndex + 1;
1011
+ result = m2.exec(s);
1012
+ }
1013
+ }
1014
+
1015
+ if (result) {
1016
+ this.regexIndex += result.position + 1;
1017
+ if (this.regexIndex === this.count) {
1018
+ // wrap-around to considering all matches again
1019
+ this.considerAll();
1020
+ }
1021
+ }
1022
+
1023
+ return result;
1024
+ }
1025
+ }
1026
+
1027
+ /**
1028
+ * Given a mode, builds a huge ResumableMultiRegex that can be used to walk
1029
+ * the content and find matches.
1030
+ *
1031
+ * @param {CompiledMode} mode
1032
+ * @returns {ResumableMultiRegex}
1033
+ */
1034
+ function buildModeRegex(mode) {
1035
+ const mm = new ResumableMultiRegex();
1036
+
1037
+ mode.contains.forEach(term => mm.addRule(term.begin, { rule: term, type: "begin" }));
1038
+
1039
+ if (mode.terminatorEnd) {
1040
+ mm.addRule(mode.terminatorEnd, { type: "end" });
1041
+ }
1042
+ if (mode.illegal) {
1043
+ mm.addRule(mode.illegal, { type: "illegal" });
1044
+ }
1045
+
1046
+ return mm;
1047
+ }
1048
+
1049
+ /** skip vs abort vs ignore
1050
+ *
1051
+ * @skip - The mode is still entered and exited normally (and contains rules apply),
1052
+ * but all content is held and added to the parent buffer rather than being
1053
+ * output when the mode ends. Mostly used with `sublanguage` to build up
1054
+ * a single large buffer than can be parsed by sublanguage.
1055
+ *
1056
+ * - The mode begin ands ends normally.
1057
+ * - Content matched is added to the parent mode buffer.
1058
+ * - The parser cursor is moved forward normally.
1059
+ *
1060
+ * @abort - A hack placeholder until we have ignore. Aborts the mode (as if it
1061
+ * never matched) but DOES NOT continue to match subsequent `contains`
1062
+ * modes. Abort is bad/suboptimal because it can result in modes
1063
+ * farther down not getting applied because an earlier rule eats the
1064
+ * content but then aborts.
1065
+ *
1066
+ * - The mode does not begin.
1067
+ * - Content matched by `begin` is added to the mode buffer.
1068
+ * - The parser cursor is moved forward accordingly.
1069
+ *
1070
+ * @ignore - Ignores the mode (as if it never matched) and continues to match any
1071
+ * subsequent `contains` modes. Ignore isn't technically possible with
1072
+ * the current parser implementation.
1073
+ *
1074
+ * - The mode does not begin.
1075
+ * - Content matched by `begin` is ignored.
1076
+ * - The parser cursor is not moved forward.
1077
+ */
1078
+
1079
+ /**
1080
+ * Compiles an individual mode
1081
+ *
1082
+ * This can raise an error if the mode contains certain detectable known logic
1083
+ * issues.
1084
+ * @param {Mode} mode
1085
+ * @param {CompiledMode | null} [parent]
1086
+ * @returns {CompiledMode | never}
1087
+ */
1088
+ function compileMode(mode, parent) {
1089
+ const cmode = /** @type CompiledMode */ (mode);
1090
+ if (mode.isCompiled) return cmode;
1091
+
1092
+ [
1093
+ // do this early so compiler extensions generally don't have to worry about
1094
+ // the distinction between match/begin
1095
+ compileMatch
1096
+ ].forEach(ext => ext(mode, parent));
1097
+
1098
+ language.compilerExtensions.forEach(ext => ext(mode, parent));
1099
+
1100
+ // __beforeBegin is considered private API, internal use only
1101
+ mode.__beforeBegin = null;
1102
+
1103
+ [
1104
+ beginKeywords,
1105
+ // do this later so compiler extensions that come earlier have access to the
1106
+ // raw array if they wanted to perhaps manipulate it, etc.
1107
+ compileIllegal,
1108
+ // default to 1 relevance if not specified
1109
+ compileRelevance
1110
+ ].forEach(ext => ext(mode, parent));
1111
+
1112
+ mode.isCompiled = true;
1113
+
1114
+ let keywordPattern = null;
1115
+ if (typeof mode.keywords === "object") {
1116
+ keywordPattern = mode.keywords.$pattern;
1117
+ delete mode.keywords.$pattern;
1118
+ }
1119
+
1120
+ if (mode.keywords) {
1121
+ mode.keywords = compileKeywords(mode.keywords, language.case_insensitive);
1122
+ }
1123
+
1124
+ // both are not allowed
1125
+ if (mode.lexemes && keywordPattern) {
1126
+ throw new Error("ERR: Prefer `keywords.$pattern` to `mode.lexemes`, BOTH are not allowed. (see mode reference) ");
1127
+ }
1128
+
1129
+ // `mode.lexemes` was the old standard before we added and now recommend
1130
+ // using `keywords.$pattern` to pass the keyword pattern
1131
+ keywordPattern = keywordPattern || mode.lexemes || /\w+/;
1132
+ cmode.keywordPatternRe = langRe(keywordPattern, true);
1133
+
1134
+ if (parent) {
1135
+ if (!mode.begin) mode.begin = /\B|\b/;
1136
+ cmode.beginRe = langRe(mode.begin);
1137
+ if (mode.endSameAsBegin) mode.end = mode.begin;
1138
+ if (!mode.end && !mode.endsWithParent) mode.end = /\B|\b/;
1139
+ if (mode.end) cmode.endRe = langRe(mode.end);
1140
+ cmode.terminatorEnd = source(mode.end) || '';
1141
+ if (mode.endsWithParent && parent.terminatorEnd) {
1142
+ cmode.terminatorEnd += (mode.end ? '|' : '') + parent.terminatorEnd;
1143
+ }
1144
+ }
1145
+ if (mode.illegal) cmode.illegalRe = langRe(/** @type {RegExp | string} */ (mode.illegal));
1146
+ if (!mode.contains) mode.contains = [];
1147
+
1148
+ mode.contains = [].concat(...mode.contains.map(function(c) {
1149
+ return expandOrCloneMode(c === 'self' ? mode : c);
1150
+ }));
1151
+ mode.contains.forEach(function(c) { compileMode(/** @type Mode */ (c), cmode); });
1152
+
1153
+ if (mode.starts) {
1154
+ compileMode(mode.starts, parent);
1155
+ }
1156
+
1157
+ cmode.matcher = buildModeRegex(cmode);
1158
+ return cmode;
1159
+ }
1160
+
1161
+ if (!language.compilerExtensions) language.compilerExtensions = [];
1162
+
1163
+ // self is not valid at the top-level
1164
+ if (language.contains && language.contains.includes('self')) {
1165
+ throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
1166
+ }
1167
+
1168
+ // we need a null object, which inherit will guarantee
1169
+ language.classNameAliases = inherit(language.classNameAliases || {});
1170
+
1171
+ return compileMode(/** @type Mode */ (language));
1172
+ }
1173
+
1174
+ /**
1175
+ * Determines if a mode has a dependency on it's parent or not
1176
+ *
1177
+ * If a mode does have a parent dependency then often we need to clone it if
1178
+ * it's used in multiple places so that each copy points to the correct parent,
1179
+ * where-as modes without a parent can often safely be re-used at the bottom of
1074
1180
  * a mode chain.
1075
1181
  *
1076
1182
  * @param {Mode | null} mode
1077
1183
  * @returns {boolean} - is there a dependency on the parent?
1078
1184
  * */
1079
1185
  function dependencyOnParent(mode) {
1080
- if (!mode)
1081
- return false;
1082
- return mode.endsWithParent || dependencyOnParent(mode.starts);
1186
+ if (!mode) return false;
1187
+
1188
+ return mode.endsWithParent || dependencyOnParent(mode.starts);
1083
1189
  }
1190
+
1084
1191
  /**
1085
1192
  * Expands a mode or clones it if necessary
1086
1193
  *
@@ -1092,1211 +1199,1319 @@ function dependencyOnParent(mode) {
1092
1199
  * @returns {Mode | Mode[]}
1093
1200
  * */
1094
1201
  function expandOrCloneMode(mode) {
1095
- if (mode.variants && !mode.cachedVariants) {
1096
- mode.cachedVariants = mode.variants.map(function (variant) {
1097
- return inherit(mode, { variants: null }, variant);
1098
- });
1099
- }
1100
- // EXPAND
1101
- // if we have variants then essentially "replace" the mode with the variants
1102
- // this happens in compileMode, where this function is called from
1103
- if (mode.cachedVariants) {
1104
- return mode.cachedVariants;
1105
- }
1106
- // CLONE
1107
- // if we have dependencies on parents then we need a unique
1108
- // instance of ourselves, so we can be reused with many
1109
- // different parents without issue
1110
- if (dependencyOnParent(mode)) {
1111
- return inherit(mode, { starts: mode.starts ? inherit(mode.starts) : null });
1112
- }
1113
- if (Object.isFrozen(mode)) {
1114
- return inherit(mode);
1115
- }
1116
- // no special dependency issues, just return ourselves
1117
- return mode;
1202
+ if (mode.variants && !mode.cachedVariants) {
1203
+ mode.cachedVariants = mode.variants.map(function(variant) {
1204
+ return inherit(mode, { variants: null }, variant);
1205
+ });
1206
+ }
1207
+
1208
+ // EXPAND
1209
+ // if we have variants then essentially "replace" the mode with the variants
1210
+ // this happens in compileMode, where this function is called from
1211
+ if (mode.cachedVariants) {
1212
+ return mode.cachedVariants;
1213
+ }
1214
+
1215
+ // CLONE
1216
+ // if we have dependencies on parents then we need a unique
1217
+ // instance of ourselves, so we can be reused with many
1218
+ // different parents without issue
1219
+ if (dependencyOnParent(mode)) {
1220
+ return inherit(mode, { starts: mode.starts ? inherit(mode.starts) : null });
1221
+ }
1222
+
1223
+ if (Object.isFrozen(mode)) {
1224
+ return inherit(mode);
1225
+ }
1226
+
1227
+ // no special dependency issues, just return ourselves
1228
+ return mode;
1118
1229
  }
1230
+
1119
1231
  var version = "10.7.3";
1232
+
1120
1233
  // @ts-nocheck
1234
+
1121
1235
  function hasValueOrEmptyAttribute(value) {
1122
- return Boolean(value || value === "");
1236
+ return Boolean(value || value === "");
1123
1237
  }
1238
+
1124
1239
  function BuildVuePlugin(hljs) {
1125
- const Component = {
1126
- props: ["language", "code", "autodetect"],
1127
- data: function () {
1128
- return {
1129
- detectedLanguage: "",
1130
- unknownLanguage: false
1131
- };
1132
- },
1133
- computed: {
1134
- className() {
1135
- if (this.unknownLanguage)
1136
- return "";
1137
- return "hljs " + this.detectedLanguage;
1138
- },
1139
- highlighted() {
1140
- // no idea what language to use, return raw code
1141
- if (!this.autoDetect && !hljs.getLanguage(this.language)) {
1142
- console.warn(`The language "${this.language}" you specified could not be found.`);
1143
- this.unknownLanguage = true;
1144
- return escapeHTML(this.code);
1145
- }
1146
- let result = {};
1147
- if (this.autoDetect) {
1148
- result = hljs.highlightAuto(this.code);
1149
- this.detectedLanguage = result.language;
1150
- }
1151
- else {
1152
- result = hljs.highlight(this.language, this.code, this.ignoreIllegals);
1153
- this.detectedLanguage = this.language;
1154
- }
1155
- return result.value;
1156
- },
1157
- autoDetect() {
1158
- return !this.language || hasValueOrEmptyAttribute(this.autodetect);
1159
- },
1160
- ignoreIllegals() {
1161
- return true;
1162
- }
1163
- },
1164
- // this avoids needing to use a whole Vue compilation pipeline just
1165
- // to build Highlight.js
1166
- render(createElement) {
1167
- return createElement("pre", {}, [
1168
- createElement("code", {
1169
- class: this.className,
1170
- domProps: { innerHTML: this.highlighted }
1171
- })
1172
- ]);
1173
- }
1174
- // template: `<pre><code :class="className" v-html="highlighted"></code></pre>`
1175
- };
1176
- const VuePlugin = {
1177
- install(Vue) {
1178
- Vue.component('highlightjs', Component);
1240
+ const Component = {
1241
+ props: ["language", "code", "autodetect"],
1242
+ data: function() {
1243
+ return {
1244
+ detectedLanguage: "",
1245
+ unknownLanguage: false
1246
+ };
1247
+ },
1248
+ computed: {
1249
+ className() {
1250
+ if (this.unknownLanguage) return "";
1251
+
1252
+ return "hljs " + this.detectedLanguage;
1253
+ },
1254
+ highlighted() {
1255
+ // no idea what language to use, return raw code
1256
+ if (!this.autoDetect && !hljs.getLanguage(this.language)) {
1257
+ console.warn(`The language "${this.language}" you specified could not be found.`);
1258
+ this.unknownLanguage = true;
1259
+ return escapeHTML(this.code);
1179
1260
  }
1180
- };
1181
- return { Component, VuePlugin };
1261
+
1262
+ let result = {};
1263
+ if (this.autoDetect) {
1264
+ result = hljs.highlightAuto(this.code);
1265
+ this.detectedLanguage = result.language;
1266
+ } else {
1267
+ result = hljs.highlight(this.language, this.code, this.ignoreIllegals);
1268
+ this.detectedLanguage = this.language;
1269
+ }
1270
+ return result.value;
1271
+ },
1272
+ autoDetect() {
1273
+ return !this.language || hasValueOrEmptyAttribute(this.autodetect);
1274
+ },
1275
+ ignoreIllegals() {
1276
+ return true;
1277
+ }
1278
+ },
1279
+ // this avoids needing to use a whole Vue compilation pipeline just
1280
+ // to build Highlight.js
1281
+ render(createElement) {
1282
+ return createElement("pre", {}, [
1283
+ createElement("code", {
1284
+ class: this.className,
1285
+ domProps: { innerHTML: this.highlighted }
1286
+ })
1287
+ ]);
1288
+ }
1289
+ // template: `<pre><code :class="className" v-html="highlighted"></code></pre>`
1290
+ };
1291
+
1292
+ const VuePlugin = {
1293
+ install(Vue) {
1294
+ Vue.component('highlightjs', Component);
1295
+ }
1296
+ };
1297
+
1298
+ return { Component, VuePlugin };
1182
1299
  }
1300
+
1183
1301
  /* plugin itself */
1302
+
1184
1303
  /** @type {HLJSPlugin} */
1185
1304
  const mergeHTMLPlugin = {
1186
- "after:highlightElement": ({ el, result, text }) => {
1187
- const originalStream = nodeStream(el);
1188
- if (!originalStream.length)
1189
- return;
1190
- const resultNode = document.createElement('div');
1191
- resultNode.innerHTML = result.value;
1192
- result.value = mergeStreams(originalStream, nodeStream(resultNode), text);
1193
- }
1305
+ "after:highlightElement": ({ el, result, text }) => {
1306
+ const originalStream = nodeStream(el);
1307
+ if (!originalStream.length) return;
1308
+
1309
+ const resultNode = document.createElement('div');
1310
+ resultNode.innerHTML = result.value;
1311
+ result.value = mergeStreams(originalStream, nodeStream(resultNode), text);
1312
+ }
1194
1313
  };
1314
+
1195
1315
  /* Stream merging support functions */
1316
+
1196
1317
  /**
1197
1318
  * @typedef Event
1198
1319
  * @property {'start'|'stop'} event
1199
1320
  * @property {number} offset
1200
1321
  * @property {Node} node
1201
1322
  */
1323
+
1202
1324
  /**
1203
1325
  * @param {Node} node
1204
1326
  */
1205
1327
  function tag(node) {
1206
- return node.nodeName.toLowerCase();
1328
+ return node.nodeName.toLowerCase();
1207
1329
  }
1330
+
1208
1331
  /**
1209
1332
  * @param {Node} node
1210
1333
  */
1211
1334
  function nodeStream(node) {
1212
- /** @type Event[] */
1213
- const result = [];
1214
- (function _nodeStream(node, offset) {
1215
- for (let child = node.firstChild; child; child = child.nextSibling) {
1216
- if (child.nodeType === 3) {
1217
- offset += child.nodeValue.length;
1218
- }
1219
- else if (child.nodeType === 1) {
1220
- result.push({
1221
- event: 'start',
1222
- offset: offset,
1223
- node: child
1224
- });
1225
- offset = _nodeStream(child, offset);
1226
- // Prevent void elements from having an end tag that would actually
1227
- // double them in the output. There are more void elements in HTML
1228
- // but we list only those realistically expected in code display.
1229
- if (!tag(child).match(/br|hr|img|input/)) {
1230
- result.push({
1231
- event: 'stop',
1232
- offset: offset,
1233
- node: child
1234
- });
1235
- }
1236
- }
1237
- }
1238
- return offset;
1239
- })(node, 0);
1240
- return result;
1335
+ /** @type Event[] */
1336
+ const result = [];
1337
+ (function _nodeStream(node, offset) {
1338
+ for (let child = node.firstChild; child; child = child.nextSibling) {
1339
+ if (child.nodeType === 3) {
1340
+ offset += child.nodeValue.length;
1341
+ } else if (child.nodeType === 1) {
1342
+ result.push({
1343
+ event: 'start',
1344
+ offset: offset,
1345
+ node: child
1346
+ });
1347
+ offset = _nodeStream(child, offset);
1348
+ // Prevent void elements from having an end tag that would actually
1349
+ // double them in the output. There are more void elements in HTML
1350
+ // but we list only those realistically expected in code display.
1351
+ if (!tag(child).match(/br|hr|img|input/)) {
1352
+ result.push({
1353
+ event: 'stop',
1354
+ offset: offset,
1355
+ node: child
1356
+ });
1357
+ }
1358
+ }
1359
+ }
1360
+ return offset;
1361
+ })(node, 0);
1362
+ return result;
1241
1363
  }
1364
+
1242
1365
  /**
1243
1366
  * @param {any} original - the original stream
1244
1367
  * @param {any} highlighted - stream of the highlighted source
1245
1368
  * @param {string} value - the original source itself
1246
1369
  */
1247
1370
  function mergeStreams(original, highlighted, value) {
1248
- let processed = 0;
1249
- let result = '';
1250
- const nodeStack = [];
1251
- function selectStream() {
1252
- if (!original.length || !highlighted.length) {
1253
- return original.length ? original : highlighted;
1254
- }
1255
- if (original[0].offset !== highlighted[0].offset) {
1256
- return (original[0].offset < highlighted[0].offset) ? original : highlighted;
1257
- }
1258
- /*
1259
- To avoid starting the stream just before it should stop the order is
1260
- ensured that original always starts first and closes last:
1261
-
1262
- if (event1 == 'start' && event2 == 'start')
1263
- return original;
1264
- if (event1 == 'start' && event2 == 'stop')
1265
- return highlighted;
1266
- if (event1 == 'stop' && event2 == 'start')
1267
- return original;
1268
- if (event1 == 'stop' && event2 == 'stop')
1269
- return highlighted;
1270
-
1271
- ... which is collapsed to:
1272
- */
1273
- return highlighted[0].event === 'start' ? original : highlighted;
1274
- }
1275
- /**
1276
- * @param {Node} node
1277
- */
1278
- function open(node) {
1279
- /** @param {Attr} attr */
1280
- function attributeString(attr) {
1281
- return ' ' + attr.nodeName + '="' + escapeHTML(attr.value) + '"';
1282
- }
1283
- // @ts-ignore
1284
- result += '<' + tag(node) + [].map.call(node.attributes, attributeString).join('') + '>';
1285
- }
1286
- /**
1287
- * @param {Node} node
1288
- */
1289
- function close(node) {
1290
- result += '</' + tag(node) + '>';
1371
+ let processed = 0;
1372
+ let result = '';
1373
+ const nodeStack = [];
1374
+
1375
+ function selectStream() {
1376
+ if (!original.length || !highlighted.length) {
1377
+ return original.length ? original : highlighted;
1291
1378
  }
1292
- /**
1293
- * @param {Event} event
1294
- */
1295
- function render(event) {
1296
- (event.event === 'start' ? open : close)(event.node);
1379
+ if (original[0].offset !== highlighted[0].offset) {
1380
+ return (original[0].offset < highlighted[0].offset) ? original : highlighted;
1297
1381
  }
1298
- while (original.length || highlighted.length) {
1299
- let stream = selectStream();
1300
- result += escapeHTML(value.substring(processed, stream[0].offset));
1301
- processed = stream[0].offset;
1302
- if (stream === original) {
1303
- /*
1304
- On any opening or closing tag of the original markup we first close
1305
- the entire highlighted node stack, then render the original tag along
1306
- with all the following original tags at the same offset and then
1307
- reopen all the tags on the highlighted stack.
1308
- */
1309
- nodeStack.reverse().forEach(close);
1310
- do {
1311
- render(stream.splice(0, 1)[0]);
1312
- stream = selectStream();
1313
- } while (stream === original && stream.length && stream[0].offset === processed);
1314
- nodeStack.reverse().forEach(open);
1315
- }
1316
- else {
1317
- if (stream[0].event === 'start') {
1318
- nodeStack.push(stream[0].node);
1319
- }
1320
- else {
1321
- nodeStack.pop();
1322
- }
1323
- render(stream.splice(0, 1)[0]);
1324
- }
1325
- }
1326
- return result + escapeHTML(value.substr(processed));
1382
+
1383
+ /*
1384
+ To avoid starting the stream just before it should stop the order is
1385
+ ensured that original always starts first and closes last:
1386
+
1387
+ if (event1 == 'start' && event2 == 'start')
1388
+ return original;
1389
+ if (event1 == 'start' && event2 == 'stop')
1390
+ return highlighted;
1391
+ if (event1 == 'stop' && event2 == 'start')
1392
+ return original;
1393
+ if (event1 == 'stop' && event2 == 'stop')
1394
+ return highlighted;
1395
+
1396
+ ... which is collapsed to:
1397
+ */
1398
+ return highlighted[0].event === 'start' ? original : highlighted;
1399
+ }
1400
+
1401
+ /**
1402
+ * @param {Node} node
1403
+ */
1404
+ function open(node) {
1405
+ /** @param {Attr} attr */
1406
+ function attributeString(attr) {
1407
+ return ' ' + attr.nodeName + '="' + escapeHTML(attr.value) + '"';
1408
+ }
1409
+ // @ts-ignore
1410
+ result += '<' + tag(node) + [].map.call(node.attributes, attributeString).join('') + '>';
1411
+ }
1412
+
1413
+ /**
1414
+ * @param {Node} node
1415
+ */
1416
+ function close(node) {
1417
+ result += '</' + tag(node) + '>';
1418
+ }
1419
+
1420
+ /**
1421
+ * @param {Event} event
1422
+ */
1423
+ function render(event) {
1424
+ (event.event === 'start' ? open : close)(event.node);
1425
+ }
1426
+
1427
+ while (original.length || highlighted.length) {
1428
+ let stream = selectStream();
1429
+ result += escapeHTML(value.substring(processed, stream[0].offset));
1430
+ processed = stream[0].offset;
1431
+ if (stream === original) {
1432
+ /*
1433
+ On any opening or closing tag of the original markup we first close
1434
+ the entire highlighted node stack, then render the original tag along
1435
+ with all the following original tags at the same offset and then
1436
+ reopen all the tags on the highlighted stack.
1437
+ */
1438
+ nodeStack.reverse().forEach(close);
1439
+ do {
1440
+ render(stream.splice(0, 1)[0]);
1441
+ stream = selectStream();
1442
+ } while (stream === original && stream.length && stream[0].offset === processed);
1443
+ nodeStack.reverse().forEach(open);
1444
+ } else {
1445
+ if (stream[0].event === 'start') {
1446
+ nodeStack.push(stream[0].node);
1447
+ } else {
1448
+ nodeStack.pop();
1449
+ }
1450
+ render(stream.splice(0, 1)[0]);
1451
+ }
1452
+ }
1453
+ return result + escapeHTML(value.substr(processed));
1327
1454
  }
1455
+
1328
1456
  /*
1329
1457
 
1330
1458
  For the reasoning behind this please see:
1331
1459
  https://github.com/highlightjs/highlight.js/issues/2880#issuecomment-747275419
1332
1460
 
1333
1461
  */
1462
+
1334
1463
  /**
1335
1464
  * @type {Record<string, boolean>}
1336
1465
  */
1337
1466
  const seenDeprecations = {};
1467
+
1338
1468
  /**
1339
1469
  * @param {string} message
1340
1470
  */
1341
1471
  const error = (message) => {
1342
- console.error(message);
1472
+ console.error(message);
1343
1473
  };
1474
+
1344
1475
  /**
1345
1476
  * @param {string} message
1346
1477
  * @param {any} args
1347
1478
  */
1348
1479
  const warn = (message, ...args) => {
1349
- console.log(`WARN: ${message}`, ...args);
1480
+ console.log(`WARN: ${message}`, ...args);
1350
1481
  };
1482
+
1351
1483
  /**
1352
1484
  * @param {string} version
1353
1485
  * @param {string} message
1354
1486
  */
1355
1487
  const deprecated = (version, message) => {
1356
- if (seenDeprecations[`${version}/${message}`])
1357
- return;
1358
- console.log(`Deprecated as of ${version}. ${message}`);
1359
- seenDeprecations[`${version}/${message}`] = true;
1488
+ if (seenDeprecations[`${version}/${message}`]) return;
1489
+
1490
+ console.log(`Deprecated as of ${version}. ${message}`);
1491
+ seenDeprecations[`${version}/${message}`] = true;
1360
1492
  };
1493
+
1361
1494
  /*
1362
1495
  Syntax highlighting with language autodetection.
1363
1496
  https://highlightjs.org/
1364
1497
  */
1498
+
1365
1499
  const escape$1 = escapeHTML;
1366
1500
  const inherit$1 = inherit;
1367
1501
  const NO_MATCH = Symbol("nomatch");
1502
+
1368
1503
  /**
1369
1504
  * @param {any} hljs - object that is extended (legacy)
1370
1505
  * @returns {HLJSApi}
1371
1506
  */
1372
- const HLJS = function (hljs) {
1373
- // Global internal variables used within the highlight.js library.
1374
- /** @type {Record<string, Language>} */
1375
- const languages = Object.create(null);
1376
- /** @type {Record<string, string>} */
1377
- const aliases = Object.create(null);
1378
- /** @type {HLJSPlugin[]} */
1379
- const plugins = [];
1380
- // safe/production mode - swallows more errors, tries to keep running
1381
- // even if a single syntax or parse hits a fatal error
1382
- let SAFE_MODE = true;
1383
- const fixMarkupRe = /(^(<[^>]+>|\t|)+|\n)/gm;
1384
- const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?";
1385
- /** @type {Language} */
1386
- const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: 'Plain text', contains: [] };
1387
- // Global options used when within external APIs. This is modified when
1388
- // calling the `hljs.configure` function.
1389
- /** @type HLJSOptions */
1390
- let options = {
1391
- noHighlightRe: /^(no-?highlight)$/i,
1392
- languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
1393
- classPrefix: 'hljs-',
1394
- tabReplace: null,
1395
- useBR: false,
1396
- languages: null,
1397
- // beta configuration options, subject to change, welcome to discuss
1398
- // https://github.com/highlightjs/highlight.js/issues/1086
1399
- __emitter: TokenTreeEmitter
1400
- };
1401
- /* Utility functions */
1402
- /**
1403
- * Tests a language name to see if highlighting should be skipped
1404
- * @param {string} languageName
1405
- */
1406
- function shouldNotHighlight(languageName) {
1407
- return options.noHighlightRe.test(languageName);
1408
- }
1409
- /**
1410
- * @param {HighlightedHTMLElement} block - the HTML element to determine language for
1411
- */
1412
- function blockLanguage(block) {
1413
- let classes = block.className + ' ';
1414
- classes += block.parentNode ? block.parentNode.className : '';
1415
- // language-* takes precedence over non-prefixed class names.
1416
- const match = options.languageDetectRe.exec(classes);
1417
- if (match) {
1418
- const language = getLanguage(match[1]);
1419
- if (!language) {
1420
- warn(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
1421
- warn("Falling back to no-highlight mode for this block.", block);
1422
- }
1423
- return language ? match[1] : 'no-highlight';
1424
- }
1425
- return classes
1426
- .split(/\s+/)
1427
- .find((_class) => shouldNotHighlight(_class) || getLanguage(_class));
1428
- }
1429
- /**
1430
- * Core highlighting function.
1431
- *
1432
- * OLD API
1433
- * highlight(lang, code, ignoreIllegals, continuation)
1434
- *
1435
- * NEW API
1436
- * highlight(code, {lang, ignoreIllegals})
1437
- *
1438
- * @param {string} codeOrlanguageName - the language to use for highlighting
1439
- * @param {string | HighlightOptions} optionsOrCode - the code to highlight
1440
- * @param {boolean} [ignoreIllegals] - whether to ignore illegal matches, default is to bail
1441
- * @param {CompiledMode} [continuation] - current continuation mode, if any
1442
- *
1443
- * @returns {HighlightResult} Result - an object that represents the result
1444
- * @property {string} language - the language name
1445
- * @property {number} relevance - the relevance score
1446
- * @property {string} value - the highlighted HTML code
1447
- * @property {string} code - the original raw code
1448
- * @property {CompiledMode} top - top of the current mode stack
1449
- * @property {boolean} illegal - indicates whether any illegal matches were found
1450
- */
1451
- function highlight(codeOrlanguageName, optionsOrCode, ignoreIllegals, continuation) {
1452
- let code = "";
1453
- let languageName = "";
1454
- if (typeof optionsOrCode === "object") {
1455
- code = codeOrlanguageName;
1456
- ignoreIllegals = optionsOrCode.ignoreIllegals;
1457
- languageName = optionsOrCode.language;
1458
- // continuation not supported at all via the new API
1459
- // eslint-disable-next-line no-undefined
1460
- continuation = undefined;
1461
- }
1462
- else {
1463
- // old API
1464
- deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
1465
- deprecated("10.7.0", "Please use highlight(code, options) instead.\nhttps://github.com/highlightjs/highlight.js/issues/2277");
1466
- languageName = codeOrlanguageName;
1467
- code = optionsOrCode;
1468
- }
1469
- /** @type {BeforeHighlightContext} */
1470
- const context = {
1471
- code,
1472
- language: languageName
1473
- };
1474
- // the plugin can change the desired language or the code to be highlighted
1475
- // just be changing the object it was passed
1476
- fire("before:highlight", context);
1477
- // a before plugin can usurp the result completely by providing it's own
1478
- // in which case we don't even need to call highlight
1479
- const result = context.result
1480
- ? context.result
1481
- : _highlight(context.language, context.code, ignoreIllegals, continuation);
1482
- result.code = context.code;
1483
- // the plugin can change anything in result to suite it
1484
- fire("after:highlight", result);
1485
- return result;
1507
+ const HLJS = function(hljs) {
1508
+ // Global internal variables used within the highlight.js library.
1509
+ /** @type {Record<string, Language>} */
1510
+ const languages = Object.create(null);
1511
+ /** @type {Record<string, string>} */
1512
+ const aliases = Object.create(null);
1513
+ /** @type {HLJSPlugin[]} */
1514
+ const plugins = [];
1515
+
1516
+ // safe/production mode - swallows more errors, tries to keep running
1517
+ // even if a single syntax or parse hits a fatal error
1518
+ let SAFE_MODE = true;
1519
+ const fixMarkupRe = /(^(<[^>]+>|\t|)+|\n)/gm;
1520
+ const LANGUAGE_NOT_FOUND = "Could not find the language '{}', did you forget to load/include a language module?";
1521
+ /** @type {Language} */
1522
+ const PLAINTEXT_LANGUAGE = { disableAutodetect: true, name: 'Plain text', contains: [] };
1523
+
1524
+ // Global options used when within external APIs. This is modified when
1525
+ // calling the `hljs.configure` function.
1526
+ /** @type HLJSOptions */
1527
+ let options = {
1528
+ noHighlightRe: /^(no-?highlight)$/i,
1529
+ languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
1530
+ classPrefix: 'hljs-',
1531
+ tabReplace: null,
1532
+ useBR: false,
1533
+ languages: null,
1534
+ // beta configuration options, subject to change, welcome to discuss
1535
+ // https://github.com/highlightjs/highlight.js/issues/1086
1536
+ __emitter: TokenTreeEmitter
1537
+ };
1538
+
1539
+ /* Utility functions */
1540
+
1541
+ /**
1542
+ * Tests a language name to see if highlighting should be skipped
1543
+ * @param {string} languageName
1544
+ */
1545
+ function shouldNotHighlight(languageName) {
1546
+ return options.noHighlightRe.test(languageName);
1547
+ }
1548
+
1549
+ /**
1550
+ * @param {HighlightedHTMLElement} block - the HTML element to determine language for
1551
+ */
1552
+ function blockLanguage(block) {
1553
+ let classes = block.className + ' ';
1554
+
1555
+ classes += block.parentNode ? block.parentNode.className : '';
1556
+
1557
+ // language-* takes precedence over non-prefixed class names.
1558
+ const match = options.languageDetectRe.exec(classes);
1559
+ if (match) {
1560
+ const language = getLanguage(match[1]);
1561
+ if (!language) {
1562
+ warn(LANGUAGE_NOT_FOUND.replace("{}", match[1]));
1563
+ warn("Falling back to no-highlight mode for this block.", block);
1564
+ }
1565
+ return language ? match[1] : 'no-highlight';
1486
1566
  }
1487
- /**
1488
- * private highlight that's used internally and does not fire callbacks
1489
- *
1490
- * @param {string} languageName - the language to use for highlighting
1491
- * @param {string} codeToHighlight - the code to highlight
1492
- * @param {boolean?} [ignoreIllegals] - whether to ignore illegal matches, default is to bail
1493
- * @param {CompiledMode?} [continuation] - current continuation mode, if any
1494
- * @returns {HighlightResult} - result of the highlight operation
1495
- */
1496
- function _highlight(languageName, codeToHighlight, ignoreIllegals, continuation) {
1497
- /**
1498
- * Return keyword data if a match is a keyword
1499
- * @param {CompiledMode} mode - current mode
1500
- * @param {RegExpMatchArray} match - regexp match data
1501
- * @returns {KeywordData | false}
1502
- */
1503
- function keywordData(mode, match) {
1504
- const matchText = language.case_insensitive ? match[0].toLowerCase() : match[0];
1505
- return Object.prototype.hasOwnProperty.call(mode.keywords, matchText) && mode.keywords[matchText];
1506
- }
1507
- function processKeywords() {
1508
- if (!top.keywords) {
1509
- emitter.addText(modeBuffer);
1510
- return;
1511
- }
1512
- let lastIndex = 0;
1513
- top.keywordPatternRe.lastIndex = 0;
1514
- let match = top.keywordPatternRe.exec(modeBuffer);
1515
- let buf = "";
1516
- while (match) {
1517
- buf += modeBuffer.substring(lastIndex, match.index);
1518
- const data = keywordData(top, match);
1519
- if (data) {
1520
- const [kind, keywordRelevance] = data;
1521
- emitter.addText(buf);
1522
- buf = "";
1523
- relevance += keywordRelevance;
1524
- if (kind.startsWith("_")) {
1525
- // _ implied for relevance only, do not highlight
1526
- // by applying a class name
1527
- buf += match[0];
1528
- }
1529
- else {
1530
- const cssClass = language.classNameAliases[kind] || kind;
1531
- emitter.addKeyword(match[0], cssClass);
1532
- }
1533
- }
1534
- else {
1535
- buf += match[0];
1536
- }
1537
- lastIndex = top.keywordPatternRe.lastIndex;
1538
- match = top.keywordPatternRe.exec(modeBuffer);
1539
- }
1540
- buf += modeBuffer.substr(lastIndex);
1541
- emitter.addText(buf);
1542
- }
1543
- function processSubLanguage() {
1544
- if (modeBuffer === "")
1545
- return;
1546
- /** @type HighlightResult */
1547
- let result = null;
1548
- if (typeof top.subLanguage === 'string') {
1549
- if (!languages[top.subLanguage]) {
1550
- emitter.addText(modeBuffer);
1551
- return;
1552
- }
1553
- result = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);
1554
- continuations[top.subLanguage] = /** @type {CompiledMode} */ (result.top);
1555
- }
1556
- else {
1557
- result = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);
1558
- }
1559
- // Counting embedded language score towards the host language may be disabled
1560
- // with zeroing the containing mode relevance. Use case in point is Markdown that
1561
- // allows XML everywhere and makes every XML snippet to have a much larger Markdown
1562
- // score.
1563
- if (top.relevance > 0) {
1564
- relevance += result.relevance;
1565
- }
1566
- emitter.addSublanguage(result.emitter, result.language);
1567
- }
1568
- function processBuffer() {
1569
- if (top.subLanguage != null) {
1570
- processSubLanguage();
1571
- }
1572
- else {
1573
- processKeywords();
1574
- }
1575
- modeBuffer = '';
1576
- }
1577
- /**
1578
- * @param {Mode} mode - new mode to start
1579
- */
1580
- function startNewMode(mode) {
1581
- if (mode.className) {
1582
- emitter.openNode(language.classNameAliases[mode.className] || mode.className);
1583
- }
1584
- top = Object.create(mode, { parent: { value: top } });
1585
- return top;
1586
- }
1587
- /**
1588
- * @param {CompiledMode } mode - the mode to potentially end
1589
- * @param {RegExpMatchArray} match - the latest match
1590
- * @param {string} matchPlusRemainder - match plus remainder of content
1591
- * @returns {CompiledMode | void} - the next mode, or if void continue on in current mode
1592
- */
1593
- function endOfMode(mode, match, matchPlusRemainder) {
1594
- let matched = startsWith(mode.endRe, matchPlusRemainder);
1595
- if (matched) {
1596
- if (mode["on:end"]) {
1597
- const resp = new Response(mode);
1598
- mode["on:end"](match, resp);
1599
- if (resp.isMatchIgnored)
1600
- matched = false;
1601
- }
1602
- if (matched) {
1603
- while (mode.endsParent && mode.parent) {
1604
- mode = mode.parent;
1605
- }
1606
- return mode;
1607
- }
1608
- }
1609
- // even if on:end fires an `ignore` it's still possible
1610
- // that we might trigger the end node because of a parent mode
1611
- if (mode.endsWithParent) {
1612
- return endOfMode(mode.parent, match, matchPlusRemainder);
1613
- }
1614
- }
1615
- /**
1616
- * Handle matching but then ignoring a sequence of text
1617
- *
1618
- * @param {string} lexeme - string containing full match text
1619
- */
1620
- function doIgnore(lexeme) {
1621
- if (top.matcher.regexIndex === 0) {
1622
- // no more regexs to potentially match here, so we move the cursor forward one
1623
- // space
1624
- modeBuffer += lexeme[0];
1625
- return 1;
1626
- }
1627
- else {
1628
- // no need to move the cursor, we still have additional regexes to try and
1629
- // match at this very spot
1630
- resumeScanAtSamePosition = true;
1631
- return 0;
1632
- }
1633
- }
1634
- /**
1635
- * Handle the start of a new potential mode match
1636
- *
1637
- * @param {EnhancedMatch} match - the current match
1638
- * @returns {number} how far to advance the parse cursor
1639
- */
1640
- function doBeginMatch(match) {
1641
- const lexeme = match[0];
1642
- const newMode = match.rule;
1643
- const resp = new Response(newMode);
1644
- // first internal before callbacks, then the public ones
1645
- const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
1646
- for (const cb of beforeCallbacks) {
1647
- if (!cb)
1648
- continue;
1649
- cb(match, resp);
1650
- if (resp.isMatchIgnored)
1651
- return doIgnore(lexeme);
1652
- }
1653
- if (newMode && newMode.endSameAsBegin) {
1654
- newMode.endRe = escape(lexeme);
1655
- }
1656
- if (newMode.skip) {
1657
- modeBuffer += lexeme;
1658
- }
1659
- else {
1660
- if (newMode.excludeBegin) {
1661
- modeBuffer += lexeme;
1662
- }
1663
- processBuffer();
1664
- if (!newMode.returnBegin && !newMode.excludeBegin) {
1665
- modeBuffer = lexeme;
1666
- }
1667
- }
1668
- startNewMode(newMode);
1669
- // if (mode["after:begin"]) {
1670
- // let resp = new Response(mode);
1671
- // mode["after:begin"](match, resp);
1672
- // }
1673
- return newMode.returnBegin ? 0 : lexeme.length;
1674
- }
1675
- /**
1676
- * Handle the potential end of mode
1677
- *
1678
- * @param {RegExpMatchArray} match - the current match
1679
- */
1680
- function doEndMatch(match) {
1681
- const lexeme = match[0];
1682
- const matchPlusRemainder = codeToHighlight.substr(match.index);
1683
- const endMode = endOfMode(top, match, matchPlusRemainder);
1684
- if (!endMode) {
1685
- return NO_MATCH;
1686
- }
1687
- const origin = top;
1688
- if (origin.skip) {
1689
- modeBuffer += lexeme;
1690
- }
1691
- else {
1692
- if (!(origin.returnEnd || origin.excludeEnd)) {
1693
- modeBuffer += lexeme;
1694
- }
1695
- processBuffer();
1696
- if (origin.excludeEnd) {
1697
- modeBuffer = lexeme;
1698
- }
1699
- }
1700
- do {
1701
- if (top.className) {
1702
- emitter.closeNode();
1703
- }
1704
- if (!top.skip && !top.subLanguage) {
1705
- relevance += top.relevance;
1706
- }
1707
- top = top.parent;
1708
- } while (top !== endMode.parent);
1709
- if (endMode.starts) {
1710
- if (endMode.endSameAsBegin) {
1711
- endMode.starts.endRe = endMode.endRe;
1712
- }
1713
- startNewMode(endMode.starts);
1714
- }
1715
- return origin.returnEnd ? 0 : lexeme.length;
1716
- }
1717
- function processContinuations() {
1718
- const list = [];
1719
- for (let current = top; current !== language; current = current.parent) {
1720
- if (current.className) {
1721
- list.unshift(current.className);
1722
- }
1723
- }
1724
- list.forEach(item => emitter.openNode(item));
1725
- }
1726
- /** @type {{type?: MatchType, index?: number, rule?: Mode}}} */
1727
- let lastMatch = {};
1728
- /**
1729
- * Process an individual match
1730
- *
1731
- * @param {string} textBeforeMatch - text preceeding the match (since the last match)
1732
- * @param {EnhancedMatch} [match] - the match itself
1733
- */
1734
- function processLexeme(textBeforeMatch, match) {
1735
- const lexeme = match && match[0];
1736
- // add non-matched text to the current mode buffer
1737
- modeBuffer += textBeforeMatch;
1738
- if (lexeme == null) {
1739
- processBuffer();
1740
- return 0;
1741
- }
1742
- // we've found a 0 width match and we're stuck, so we need to advance
1743
- // this happens when we have badly behaved rules that have optional matchers to the degree that
1744
- // sometimes they can end up matching nothing at all
1745
- // Ref: https://github.com/highlightjs/highlight.js/issues/2140
1746
- if (lastMatch.type === "begin" && match.type === "end" && lastMatch.index === match.index && lexeme === "") {
1747
- // spit the "skipped" character that our regex choked on back into the output sequence
1748
- modeBuffer += codeToHighlight.slice(match.index, match.index + 1);
1749
- if (!SAFE_MODE) {
1750
- /** @type {AnnotatedError} */
1751
- const err = new Error('0 width match regex');
1752
- err.languageName = languageName;
1753
- err.badRule = lastMatch.rule;
1754
- throw err;
1755
- }
1756
- return 1;
1757
- }
1758
- lastMatch = match;
1759
- if (match.type === "begin") {
1760
- return doBeginMatch(match);
1761
- }
1762
- else if (match.type === "illegal" && !ignoreIllegals) {
1763
- // illegal match, we do not continue processing
1764
- /** @type {AnnotatedError} */
1765
- const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.className || '<unnamed>') + '"');
1766
- err.mode = top;
1767
- throw err;
1768
- }
1769
- else if (match.type === "end") {
1770
- const processed = doEndMatch(match);
1771
- if (processed !== NO_MATCH) {
1772
- return processed;
1773
- }
1774
- }
1775
- // edge case for when illegal matches $ (end of line) which is technically
1776
- // a 0 width match but not a begin/end match so it's not caught by the
1777
- // first handler (when ignoreIllegals is true)
1778
- if (match.type === "illegal" && lexeme === "") {
1779
- // advance so we aren't stuck in an infinite loop
1780
- return 1;
1781
- }
1782
- // infinite loops are BAD, this is a last ditch catch all. if we have a
1783
- // decent number of iterations yet our index (cursor position in our
1784
- // parsing) still 3x behind our index then something is very wrong
1785
- // so we bail
1786
- if (iterations > 100000 && iterations > match.index * 3) {
1787
- const err = new Error('potential infinite loop, way more iterations than matches');
1788
- throw err;
1789
- }
1790
- /*
1791
- Why might be find ourselves here? Only one occasion now. An end match that was
1792
- triggered but could not be completed. When might this happen? When an `endSameasBegin`
1793
- rule sets the end rule to a specific match. Since the overall mode termination rule that's
1794
- being used to scan the text isn't recompiled that means that any match that LOOKS like
1795
- the end (but is not, because it is not an exact match to the beginning) will
1796
- end up here. A definite end match, but when `doEndMatch` tries to "reapply"
1797
- the end rule and fails to match, we wind up here, and just silently ignore the end.
1798
-
1799
- This causes no real harm other than stopping a few times too many.
1800
- */
1801
- modeBuffer += lexeme;
1802
- return lexeme.length;
1803
- }
1804
- const language = getLanguage(languageName);
1805
- if (!language) {
1806
- error(LANGUAGE_NOT_FOUND.replace("{}", languageName));
1807
- throw new Error('Unknown language: "' + languageName + '"');
1808
- }
1809
- const md = compileLanguage(language, { plugins });
1810
- let result = '';
1811
- /** @type {CompiledMode} */
1812
- let top = continuation || md;
1813
- /** @type Record<string,CompiledMode> */
1814
- const continuations = {}; // keep continuations for sub-languages
1815
- const emitter = new options.__emitter(options);
1816
- processContinuations();
1817
- let modeBuffer = '';
1818
- let relevance = 0;
1819
- let index = 0;
1820
- let iterations = 0;
1821
- let resumeScanAtSamePosition = false;
1822
- try {
1823
- top.matcher.considerAll();
1824
- for (;;) {
1825
- iterations++;
1826
- if (resumeScanAtSamePosition) {
1827
- // only regexes not matched previously will now be
1828
- // considered for a potential match
1829
- resumeScanAtSamePosition = false;
1830
- }
1831
- else {
1832
- top.matcher.considerAll();
1833
- }
1834
- top.matcher.lastIndex = index;
1835
- const match = top.matcher.exec(codeToHighlight);
1836
- // console.log("match", match[0], match.rule && match.rule.begin)
1837
- if (!match)
1838
- break;
1839
- const beforeMatch = codeToHighlight.substring(index, match.index);
1840
- const processedCount = processLexeme(beforeMatch, match);
1841
- index = match.index + processedCount;
1842
- }
1843
- processLexeme(codeToHighlight.substr(index));
1844
- emitter.closeAllNodes();
1845
- emitter.finalize();
1846
- result = emitter.toHTML();
1847
- return {
1848
- // avoid possible breakage with v10 clients expecting
1849
- // this to always be an integer
1850
- relevance: Math.floor(relevance),
1851
- value: result,
1852
- language: languageName,
1853
- illegal: false,
1854
- emitter: emitter,
1855
- top: top
1856
- };
1857
- }
1858
- catch (err) {
1859
- if (err.message && err.message.includes('Illegal')) {
1860
- return {
1861
- illegal: true,
1862
- illegalBy: {
1863
- msg: err.message,
1864
- context: codeToHighlight.slice(index - 100, index + 100),
1865
- mode: err.mode
1866
- },
1867
- sofar: result,
1868
- relevance: 0,
1869
- value: escape$1(codeToHighlight),
1870
- emitter: emitter
1871
- };
1872
- }
1873
- else if (SAFE_MODE) {
1874
- return {
1875
- illegal: false,
1876
- relevance: 0,
1877
- value: escape$1(codeToHighlight),
1878
- emitter: emitter,
1879
- language: languageName,
1880
- top: top,
1881
- errorRaised: err
1882
- };
1883
- }
1884
- else {
1885
- throw err;
1886
- }
1887
- }
1567
+
1568
+ return classes
1569
+ .split(/\s+/)
1570
+ .find((_class) => shouldNotHighlight(_class) || getLanguage(_class));
1571
+ }
1572
+
1573
+ /**
1574
+ * Core highlighting function.
1575
+ *
1576
+ * OLD API
1577
+ * highlight(lang, code, ignoreIllegals, continuation)
1578
+ *
1579
+ * NEW API
1580
+ * highlight(code, {lang, ignoreIllegals})
1581
+ *
1582
+ * @param {string} codeOrlanguageName - the language to use for highlighting
1583
+ * @param {string | HighlightOptions} optionsOrCode - the code to highlight
1584
+ * @param {boolean} [ignoreIllegals] - whether to ignore illegal matches, default is to bail
1585
+ * @param {CompiledMode} [continuation] - current continuation mode, if any
1586
+ *
1587
+ * @returns {HighlightResult} Result - an object that represents the result
1588
+ * @property {string} language - the language name
1589
+ * @property {number} relevance - the relevance score
1590
+ * @property {string} value - the highlighted HTML code
1591
+ * @property {string} code - the original raw code
1592
+ * @property {CompiledMode} top - top of the current mode stack
1593
+ * @property {boolean} illegal - indicates whether any illegal matches were found
1594
+ */
1595
+ function highlight(codeOrlanguageName, optionsOrCode, ignoreIllegals, continuation) {
1596
+ let code = "";
1597
+ let languageName = "";
1598
+ if (typeof optionsOrCode === "object") {
1599
+ code = codeOrlanguageName;
1600
+ ignoreIllegals = optionsOrCode.ignoreIllegals;
1601
+ languageName = optionsOrCode.language;
1602
+ // continuation not supported at all via the new API
1603
+ // eslint-disable-next-line no-undefined
1604
+ continuation = undefined;
1605
+ } else {
1606
+ // old API
1607
+ deprecated("10.7.0", "highlight(lang, code, ...args) has been deprecated.");
1608
+ deprecated("10.7.0", "Please use highlight(code, options) instead.\nhttps://github.com/highlightjs/highlight.js/issues/2277");
1609
+ languageName = codeOrlanguageName;
1610
+ code = optionsOrCode;
1888
1611
  }
1612
+
1613
+ /** @type {BeforeHighlightContext} */
1614
+ const context = {
1615
+ code,
1616
+ language: languageName
1617
+ };
1618
+ // the plugin can change the desired language or the code to be highlighted
1619
+ // just be changing the object it was passed
1620
+ fire("before:highlight", context);
1621
+
1622
+ // a before plugin can usurp the result completely by providing it's own
1623
+ // in which case we don't even need to call highlight
1624
+ const result = context.result
1625
+ ? context.result
1626
+ : _highlight(context.language, context.code, ignoreIllegals, continuation);
1627
+
1628
+ result.code = context.code;
1629
+ // the plugin can change anything in result to suite it
1630
+ fire("after:highlight", result);
1631
+
1632
+ return result;
1633
+ }
1634
+
1635
+ /**
1636
+ * private highlight that's used internally and does not fire callbacks
1637
+ *
1638
+ * @param {string} languageName - the language to use for highlighting
1639
+ * @param {string} codeToHighlight - the code to highlight
1640
+ * @param {boolean?} [ignoreIllegals] - whether to ignore illegal matches, default is to bail
1641
+ * @param {CompiledMode?} [continuation] - current continuation mode, if any
1642
+ * @returns {HighlightResult} - result of the highlight operation
1643
+ */
1644
+ function _highlight(languageName, codeToHighlight, ignoreIllegals, continuation) {
1889
1645
  /**
1890
- * returns a valid highlight result, without actually doing any actual work,
1891
- * auto highlight starts with this and it's possible for small snippets that
1892
- * auto-detection may not find a better match
1893
- * @param {string} code
1894
- * @returns {HighlightResult}
1646
+ * Return keyword data if a match is a keyword
1647
+ * @param {CompiledMode} mode - current mode
1648
+ * @param {RegExpMatchArray} match - regexp match data
1649
+ * @returns {KeywordData | false}
1895
1650
  */
1896
- function justTextHighlightResult(code) {
1897
- const result = {
1898
- relevance: 0,
1899
- emitter: new options.__emitter(options),
1900
- value: escape$1(code),
1901
- illegal: false,
1902
- top: PLAINTEXT_LANGUAGE
1903
- };
1904
- result.emitter.addText(code);
1905
- return result;
1651
+ function keywordData(mode, match) {
1652
+ const matchText = language.case_insensitive ? match[0].toLowerCase() : match[0];
1653
+ return Object.prototype.hasOwnProperty.call(mode.keywords, matchText) && mode.keywords[matchText];
1906
1654
  }
1907
- /**
1908
- Highlighting with language detection. Accepts a string with the code to
1909
- highlight. Returns an object with the following properties:
1910
-
1911
- - language (detected language)
1912
- - relevance (int)
1913
- - value (an HTML string with highlighting markup)
1914
- - second_best (object with the same structure for second-best heuristically
1915
- detected language, may be absent)
1916
-
1917
- @param {string} code
1918
- @param {Array<string>} [languageSubset]
1919
- @returns {AutoHighlightResult}
1920
- */
1921
- function highlightAuto(code, languageSubset) {
1922
- languageSubset = languageSubset || options.languages || Object.keys(languages);
1923
- const plaintext = justTextHighlightResult(code);
1924
- const results = languageSubset.filter(getLanguage).filter(autoDetection).map(name => _highlight(name, code, false));
1925
- results.unshift(plaintext); // plaintext is always an option
1926
- const sorted = results.sort((a, b) => {
1927
- // sort base on relevance
1928
- if (a.relevance !== b.relevance)
1929
- return b.relevance - a.relevance;
1930
- // always award the tie to the base language
1931
- // ie if C++ and Arduino are tied, it's more likely to be C++
1932
- if (a.language && b.language) {
1933
- if (getLanguage(a.language).supersetOf === b.language) {
1934
- return 1;
1935
- }
1936
- else if (getLanguage(b.language).supersetOf === a.language) {
1937
- return -1;
1938
- }
1939
- }
1940
- // otherwise say they are equal, which has the effect of sorting on
1941
- // relevance while preserving the original ordering - which is how ties
1942
- // have historically been settled, ie the language that comes first always
1943
- // wins in the case of a tie
1944
- return 0;
1945
- });
1946
- const [best, secondBest] = sorted;
1947
- /** @type {AutoHighlightResult} */
1948
- const result = best;
1949
- result.second_best = secondBest;
1950
- return result;
1951
- }
1952
- /**
1953
- Post-processing of the highlighted markup:
1954
-
1955
- - replace TABs with something more useful
1956
- - replace real line-breaks with '<br>' for non-pre containers
1957
-
1958
- @param {string} html
1959
- @returns {string}
1960
- */
1961
- function fixMarkup(html) {
1962
- if (!(options.tabReplace || options.useBR)) {
1963
- return html;
1964
- }
1965
- return html.replace(fixMarkupRe, match => {
1966
- if (match === '\n') {
1967
- return options.useBR ? '<br>' : match;
1968
- }
1969
- else if (options.tabReplace) {
1970
- return match.replace(/\t/g, options.tabReplace);
1971
- }
1972
- return match;
1973
- });
1974
- }
1975
- /**
1976
- * Builds new class name for block given the language name
1977
- *
1978
- * @param {HTMLElement} element
1979
- * @param {string} [currentLang]
1980
- * @param {string} [resultLang]
1981
- */
1982
- function updateClassName(element, currentLang, resultLang) {
1983
- const language = currentLang ? aliases[currentLang] : resultLang;
1984
- element.classList.add("hljs");
1985
- if (language)
1986
- element.classList.add(language);
1655
+
1656
+ function processKeywords() {
1657
+ if (!top.keywords) {
1658
+ emitter.addText(modeBuffer);
1659
+ return;
1660
+ }
1661
+
1662
+ let lastIndex = 0;
1663
+ top.keywordPatternRe.lastIndex = 0;
1664
+ let match = top.keywordPatternRe.exec(modeBuffer);
1665
+ let buf = "";
1666
+
1667
+ while (match) {
1668
+ buf += modeBuffer.substring(lastIndex, match.index);
1669
+ const data = keywordData(top, match);
1670
+ if (data) {
1671
+ const [kind, keywordRelevance] = data;
1672
+ emitter.addText(buf);
1673
+ buf = "";
1674
+
1675
+ relevance += keywordRelevance;
1676
+ if (kind.startsWith("_")) {
1677
+ // _ implied for relevance only, do not highlight
1678
+ // by applying a class name
1679
+ buf += match[0];
1680
+ } else {
1681
+ const cssClass = language.classNameAliases[kind] || kind;
1682
+ emitter.addKeyword(match[0], cssClass);
1683
+ }
1684
+ } else {
1685
+ buf += match[0];
1686
+ }
1687
+ lastIndex = top.keywordPatternRe.lastIndex;
1688
+ match = top.keywordPatternRe.exec(modeBuffer);
1689
+ }
1690
+ buf += modeBuffer.substr(lastIndex);
1691
+ emitter.addText(buf);
1987
1692
  }
1988
- /** @type {HLJSPlugin} */
1989
- const brPlugin = {
1990
- "before:highlightElement": ({ el }) => {
1991
- if (options.useBR) {
1992
- el.innerHTML = el.innerHTML.replace(/\n/g, '').replace(/<br[ /]*>/g, '\n');
1993
- }
1994
- },
1995
- "after:highlightElement": ({ result }) => {
1996
- if (options.useBR) {
1997
- result.value = result.value.replace(/\n/g, "<br>");
1998
- }
1999
- }
2000
- };
2001
- const TAB_REPLACE_RE = /^(<[^>]+>|\t)+/gm;
2002
- /** @type {HLJSPlugin} */
2003
- const tabReplacePlugin = {
2004
- "after:highlightElement": ({ result }) => {
2005
- if (options.tabReplace) {
2006
- result.value = result.value.replace(TAB_REPLACE_RE, (m) => m.replace(/\t/g, options.tabReplace));
2007
- }
2008
- }
2009
- };
2010
- /**
2011
- * Applies highlighting to a DOM node containing code. Accepts a DOM node and
2012
- * two optional parameters for fixMarkup.
2013
- *
2014
- * @param {HighlightedHTMLElement} element - the HTML element to highlight
2015
- */
2016
- function highlightElement(element) {
2017
- /** @type HTMLElement */
2018
- let node = null;
2019
- const language = blockLanguage(element);
2020
- if (shouldNotHighlight(language))
2021
- return;
2022
- // support for v10 API
2023
- fire("before:highlightElement", { el: element, language: language });
2024
- node = element;
2025
- const text = node.textContent;
2026
- const result = language ? highlight(text, { language, ignoreIllegals: true }) : highlightAuto(text);
2027
- // support for v10 API
2028
- fire("after:highlightElement", { el: element, result, text });
2029
- element.innerHTML = result.value;
2030
- updateClassName(element, language, result.language);
2031
- element.result = {
2032
- language: result.language,
2033
- // TODO: remove with version 11.0
2034
- re: result.relevance,
2035
- relavance: result.relevance
2036
- };
2037
- if (result.second_best) {
2038
- element.second_best = {
2039
- language: result.second_best.language,
2040
- // TODO: remove with version 11.0
2041
- re: result.second_best.relevance,
2042
- relavance: result.second_best.relevance
2043
- };
2044
- }
1693
+
1694
+ function processSubLanguage() {
1695
+ if (modeBuffer === "") return;
1696
+ /** @type HighlightResult */
1697
+ let result = null;
1698
+
1699
+ if (typeof top.subLanguage === 'string') {
1700
+ if (!languages[top.subLanguage]) {
1701
+ emitter.addText(modeBuffer);
1702
+ return;
1703
+ }
1704
+ result = _highlight(top.subLanguage, modeBuffer, true, continuations[top.subLanguage]);
1705
+ continuations[top.subLanguage] = /** @type {CompiledMode} */ (result.top);
1706
+ } else {
1707
+ result = highlightAuto(modeBuffer, top.subLanguage.length ? top.subLanguage : null);
1708
+ }
1709
+
1710
+ // Counting embedded language score towards the host language may be disabled
1711
+ // with zeroing the containing mode relevance. Use case in point is Markdown that
1712
+ // allows XML everywhere and makes every XML snippet to have a much larger Markdown
1713
+ // score.
1714
+ if (top.relevance > 0) {
1715
+ relevance += result.relevance;
1716
+ }
1717
+ emitter.addSublanguage(result.emitter, result.language);
2045
1718
  }
2046
- /**
2047
- * Updates highlight.js global options with the passed options
2048
- *
2049
- * @param {Partial<HLJSOptions>} userOptions
2050
- */
2051
- function configure(userOptions) {
2052
- if (userOptions.useBR) {
2053
- deprecated("10.3.0", "'useBR' will be removed entirely in v11.0");
2054
- deprecated("10.3.0", "Please see https://github.com/highlightjs/highlight.js/issues/2559");
2055
- }
2056
- options = inherit$1(options, userOptions);
1719
+
1720
+ function processBuffer() {
1721
+ if (top.subLanguage != null) {
1722
+ processSubLanguage();
1723
+ } else {
1724
+ processKeywords();
1725
+ }
1726
+ modeBuffer = '';
2057
1727
  }
1728
+
2058
1729
  /**
2059
- * Highlights to all <pre><code> blocks on a page
2060
- *
2061
- * @type {Function & {called?: boolean}}
1730
+ * @param {Mode} mode - new mode to start
2062
1731
  */
2063
- // TODO: remove v12, deprecated
2064
- const initHighlighting = () => {
2065
- if (initHighlighting.called)
2066
- return;
2067
- initHighlighting.called = true;
2068
- deprecated("10.6.0", "initHighlighting() is deprecated. Use highlightAll() instead.");
2069
- const blocks = document.querySelectorAll('pre code');
2070
- blocks.forEach(highlightElement);
2071
- };
2072
- // Higlights all when DOMContentLoaded fires
2073
- // TODO: remove v12, deprecated
2074
- function initHighlightingOnLoad() {
2075
- deprecated("10.6.0", "initHighlightingOnLoad() is deprecated. Use highlightAll() instead.");
2076
- wantsHighlight = true;
1732
+ function startNewMode(mode) {
1733
+ if (mode.className) {
1734
+ emitter.openNode(language.classNameAliases[mode.className] || mode.className);
1735
+ }
1736
+ top = Object.create(mode, { parent: { value: top } });
1737
+ return top;
2077
1738
  }
2078
- let wantsHighlight = false;
1739
+
2079
1740
  /**
2080
- * auto-highlights all pre>code elements on the page
1741
+ * @param {CompiledMode } mode - the mode to potentially end
1742
+ * @param {RegExpMatchArray} match - the latest match
1743
+ * @param {string} matchPlusRemainder - match plus remainder of content
1744
+ * @returns {CompiledMode | void} - the next mode, or if void continue on in current mode
2081
1745
  */
2082
- function highlightAll() {
2083
- // if we are called too early in the loading process
2084
- if (document.readyState === "loading") {
2085
- wantsHighlight = true;
2086
- return;
1746
+ function endOfMode(mode, match, matchPlusRemainder) {
1747
+ let matched = startsWith(mode.endRe, matchPlusRemainder);
1748
+
1749
+ if (matched) {
1750
+ if (mode["on:end"]) {
1751
+ const resp = new Response(mode);
1752
+ mode["on:end"](match, resp);
1753
+ if (resp.isMatchIgnored) matched = false;
2087
1754
  }
2088
- const blocks = document.querySelectorAll('pre code');
2089
- blocks.forEach(highlightElement);
2090
- }
2091
- function boot() {
2092
- // if a highlight was requested before DOM was loaded, do now
2093
- if (wantsHighlight)
2094
- highlightAll();
2095
- }
2096
- // make sure we are in the browser environment
2097
- if (typeof window !== 'undefined' && window.addEventListener) {
2098
- window.addEventListener('DOMContentLoaded', boot, false);
1755
+
1756
+ if (matched) {
1757
+ while (mode.endsParent && mode.parent) {
1758
+ mode = mode.parent;
1759
+ }
1760
+ return mode;
1761
+ }
1762
+ }
1763
+ // even if on:end fires an `ignore` it's still possible
1764
+ // that we might trigger the end node because of a parent mode
1765
+ if (mode.endsWithParent) {
1766
+ return endOfMode(mode.parent, match, matchPlusRemainder);
1767
+ }
2099
1768
  }
1769
+
2100
1770
  /**
2101
- * Register a language grammar module
1771
+ * Handle matching but then ignoring a sequence of text
2102
1772
  *
2103
- * @param {string} languageName
2104
- * @param {LanguageFn} languageDefinition
1773
+ * @param {string} lexeme - string containing full match text
2105
1774
  */
2106
- function registerLanguage(languageName, languageDefinition) {
2107
- let lang = null;
2108
- try {
2109
- lang = languageDefinition(hljs);
2110
- }
2111
- catch (error$1) {
2112
- error("Language definition for '{}' could not be registered.".replace("{}", languageName));
2113
- // hard or soft error
2114
- if (!SAFE_MODE) {
2115
- throw error$1;
2116
- }
2117
- else {
2118
- error(error$1);
2119
- }
2120
- // languages that have serious errors are replaced with essentially a
2121
- // "plaintext" stand-in so that the code blocks will still get normal
2122
- // css classes applied to them - and one bad language won't break the
2123
- // entire highlighter
2124
- lang = PLAINTEXT_LANGUAGE;
2125
- }
2126
- // give it a temporary name if it doesn't have one in the meta-data
2127
- if (!lang.name)
2128
- lang.name = languageName;
2129
- languages[languageName] = lang;
2130
- lang.rawDefinition = languageDefinition.bind(null, hljs);
2131
- if (lang.aliases) {
2132
- registerAliases(lang.aliases, { languageName });
2133
- }
1775
+ function doIgnore(lexeme) {
1776
+ if (top.matcher.regexIndex === 0) {
1777
+ // no more regexs to potentially match here, so we move the cursor forward one
1778
+ // space
1779
+ modeBuffer += lexeme[0];
1780
+ return 1;
1781
+ } else {
1782
+ // no need to move the cursor, we still have additional regexes to try and
1783
+ // match at this very spot
1784
+ resumeScanAtSamePosition = true;
1785
+ return 0;
1786
+ }
2134
1787
  }
1788
+
2135
1789
  /**
2136
- * Remove a language grammar module
1790
+ * Handle the start of a new potential mode match
2137
1791
  *
2138
- * @param {string} languageName
1792
+ * @param {EnhancedMatch} match - the current match
1793
+ * @returns {number} how far to advance the parse cursor
2139
1794
  */
2140
- function unregisterLanguage(languageName) {
2141
- delete languages[languageName];
2142
- for (const alias of Object.keys(aliases)) {
2143
- if (aliases[alias] === languageName) {
2144
- delete aliases[alias];
2145
- }
2146
- }
1795
+ function doBeginMatch(match) {
1796
+ const lexeme = match[0];
1797
+ const newMode = match.rule;
1798
+
1799
+ const resp = new Response(newMode);
1800
+ // first internal before callbacks, then the public ones
1801
+ const beforeCallbacks = [newMode.__beforeBegin, newMode["on:begin"]];
1802
+ for (const cb of beforeCallbacks) {
1803
+ if (!cb) continue;
1804
+ cb(match, resp);
1805
+ if (resp.isMatchIgnored) return doIgnore(lexeme);
1806
+ }
1807
+
1808
+ if (newMode && newMode.endSameAsBegin) {
1809
+ newMode.endRe = escape(lexeme);
1810
+ }
1811
+
1812
+ if (newMode.skip) {
1813
+ modeBuffer += lexeme;
1814
+ } else {
1815
+ if (newMode.excludeBegin) {
1816
+ modeBuffer += lexeme;
1817
+ }
1818
+ processBuffer();
1819
+ if (!newMode.returnBegin && !newMode.excludeBegin) {
1820
+ modeBuffer = lexeme;
1821
+ }
1822
+ }
1823
+ startNewMode(newMode);
1824
+ // if (mode["after:begin"]) {
1825
+ // let resp = new Response(mode);
1826
+ // mode["after:begin"](match, resp);
1827
+ // }
1828
+ return newMode.returnBegin ? 0 : lexeme.length;
2147
1829
  }
1830
+
2148
1831
  /**
2149
- * @returns {string[]} List of language internal names
1832
+ * Handle the potential end of mode
1833
+ *
1834
+ * @param {RegExpMatchArray} match - the current match
2150
1835
  */
2151
- function listLanguages() {
2152
- return Object.keys(languages);
1836
+ function doEndMatch(match) {
1837
+ const lexeme = match[0];
1838
+ const matchPlusRemainder = codeToHighlight.substr(match.index);
1839
+
1840
+ const endMode = endOfMode(top, match, matchPlusRemainder);
1841
+ if (!endMode) { return NO_MATCH; }
1842
+
1843
+ const origin = top;
1844
+ if (origin.skip) {
1845
+ modeBuffer += lexeme;
1846
+ } else {
1847
+ if (!(origin.returnEnd || origin.excludeEnd)) {
1848
+ modeBuffer += lexeme;
1849
+ }
1850
+ processBuffer();
1851
+ if (origin.excludeEnd) {
1852
+ modeBuffer = lexeme;
1853
+ }
1854
+ }
1855
+ do {
1856
+ if (top.className) {
1857
+ emitter.closeNode();
1858
+ }
1859
+ if (!top.skip && !top.subLanguage) {
1860
+ relevance += top.relevance;
1861
+ }
1862
+ top = top.parent;
1863
+ } while (top !== endMode.parent);
1864
+ if (endMode.starts) {
1865
+ if (endMode.endSameAsBegin) {
1866
+ endMode.starts.endRe = endMode.endRe;
1867
+ }
1868
+ startNewMode(endMode.starts);
1869
+ }
1870
+ return origin.returnEnd ? 0 : lexeme.length;
2153
1871
  }
2154
- /**
2155
- intended usage: When one language truly requires another
2156
-
2157
- Unlike `getLanguage`, this will throw when the requested language
2158
- is not available.
2159
-
2160
- @param {string} name - name of the language to fetch/require
2161
- @returns {Language | never}
2162
- */
2163
- function requireLanguage(name) {
2164
- deprecated("10.4.0", "requireLanguage will be removed entirely in v11.");
2165
- deprecated("10.4.0", "Please see https://github.com/highlightjs/highlight.js/pull/2844");
2166
- const lang = getLanguage(name);
2167
- if (lang) {
2168
- return lang;
1872
+
1873
+ function processContinuations() {
1874
+ const list = [];
1875
+ for (let current = top; current !== language; current = current.parent) {
1876
+ if (current.className) {
1877
+ list.unshift(current.className);
2169
1878
  }
2170
- const err = new Error('The \'{}\' language is required, but not loaded.'.replace('{}', name));
2171
- throw err;
2172
- }
2173
- /**
2174
- * @param {string} name - name of the language to retrieve
2175
- * @returns {Language | undefined}
2176
- */
2177
- function getLanguage(name) {
2178
- name = (name || '').toLowerCase();
2179
- return languages[name] || languages[aliases[name]];
1879
+ }
1880
+ list.forEach(item => emitter.openNode(item));
2180
1881
  }
1882
+
1883
+ /** @type {{type?: MatchType, index?: number, rule?: Mode}}} */
1884
+ let lastMatch = {};
1885
+
2181
1886
  /**
1887
+ * Process an individual match
2182
1888
  *
2183
- * @param {string|string[]} aliasList - single alias or list of aliases
2184
- * @param {{languageName: string}} opts
2185
- */
2186
- function registerAliases(aliasList, { languageName }) {
2187
- if (typeof aliasList === 'string') {
2188
- aliasList = [aliasList];
2189
- }
2190
- aliasList.forEach(alias => { aliases[alias.toLowerCase()] = languageName; });
2191
- }
2192
- /**
2193
- * Determines if a given language has auto-detection enabled
2194
- * @param {string} name - name of the language
2195
- */
2196
- function autoDetection(name) {
2197
- const lang = getLanguage(name);
2198
- return lang && !lang.disableAutodetect;
2199
- }
2200
- /**
2201
- * Upgrades the old highlightBlock plugins to the new
2202
- * highlightElement API
2203
- * @param {HLJSPlugin} plugin
1889
+ * @param {string} textBeforeMatch - text preceeding the match (since the last match)
1890
+ * @param {EnhancedMatch} [match] - the match itself
2204
1891
  */
2205
- function upgradePluginAPI(plugin) {
2206
- // TODO: remove with v12
2207
- if (plugin["before:highlightBlock"] && !plugin["before:highlightElement"]) {
2208
- plugin["before:highlightElement"] = (data) => {
2209
- plugin["before:highlightBlock"](Object.assign({ block: data.el }, data));
2210
- };
2211
- }
2212
- if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) {
2213
- plugin["after:highlightElement"] = (data) => {
2214
- plugin["after:highlightBlock"](Object.assign({ block: data.el }, data));
2215
- };
1892
+ function processLexeme(textBeforeMatch, match) {
1893
+ const lexeme = match && match[0];
1894
+
1895
+ // add non-matched text to the current mode buffer
1896
+ modeBuffer += textBeforeMatch;
1897
+
1898
+ if (lexeme == null) {
1899
+ processBuffer();
1900
+ return 0;
1901
+ }
1902
+
1903
+ // we've found a 0 width match and we're stuck, so we need to advance
1904
+ // this happens when we have badly behaved rules that have optional matchers to the degree that
1905
+ // sometimes they can end up matching nothing at all
1906
+ // Ref: https://github.com/highlightjs/highlight.js/issues/2140
1907
+ if (lastMatch.type === "begin" && match.type === "end" && lastMatch.index === match.index && lexeme === "") {
1908
+ // spit the "skipped" character that our regex choked on back into the output sequence
1909
+ modeBuffer += codeToHighlight.slice(match.index, match.index + 1);
1910
+ if (!SAFE_MODE) {
1911
+ /** @type {AnnotatedError} */
1912
+ const err = new Error('0 width match regex');
1913
+ err.languageName = languageName;
1914
+ err.badRule = lastMatch.rule;
1915
+ throw err;
1916
+ }
1917
+ return 1;
1918
+ }
1919
+ lastMatch = match;
1920
+
1921
+ if (match.type === "begin") {
1922
+ return doBeginMatch(match);
1923
+ } else if (match.type === "illegal" && !ignoreIllegals) {
1924
+ // illegal match, we do not continue processing
1925
+ /** @type {AnnotatedError} */
1926
+ const err = new Error('Illegal lexeme "' + lexeme + '" for mode "' + (top.className || '<unnamed>') + '"');
1927
+ err.mode = top;
1928
+ throw err;
1929
+ } else if (match.type === "end") {
1930
+ const processed = doEndMatch(match);
1931
+ if (processed !== NO_MATCH) {
1932
+ return processed;
2216
1933
  }
1934
+ }
1935
+
1936
+ // edge case for when illegal matches $ (end of line) which is technically
1937
+ // a 0 width match but not a begin/end match so it's not caught by the
1938
+ // first handler (when ignoreIllegals is true)
1939
+ if (match.type === "illegal" && lexeme === "") {
1940
+ // advance so we aren't stuck in an infinite loop
1941
+ return 1;
1942
+ }
1943
+
1944
+ // infinite loops are BAD, this is a last ditch catch all. if we have a
1945
+ // decent number of iterations yet our index (cursor position in our
1946
+ // parsing) still 3x behind our index then something is very wrong
1947
+ // so we bail
1948
+ if (iterations > 100000 && iterations > match.index * 3) {
1949
+ const err = new Error('potential infinite loop, way more iterations than matches');
1950
+ throw err;
1951
+ }
1952
+
1953
+ /*
1954
+ Why might be find ourselves here? Only one occasion now. An end match that was
1955
+ triggered but could not be completed. When might this happen? When an `endSameasBegin`
1956
+ rule sets the end rule to a specific match. Since the overall mode termination rule that's
1957
+ being used to scan the text isn't recompiled that means that any match that LOOKS like
1958
+ the end (but is not, because it is not an exact match to the beginning) will
1959
+ end up here. A definite end match, but when `doEndMatch` tries to "reapply"
1960
+ the end rule and fails to match, we wind up here, and just silently ignore the end.
1961
+
1962
+ This causes no real harm other than stopping a few times too many.
1963
+ */
1964
+
1965
+ modeBuffer += lexeme;
1966
+ return lexeme.length;
2217
1967
  }
2218
- /**
2219
- * @param {HLJSPlugin} plugin
2220
- */
2221
- function addPlugin(plugin) {
2222
- upgradePluginAPI(plugin);
2223
- plugins.push(plugin);
1968
+
1969
+ const language = getLanguage(languageName);
1970
+ if (!language) {
1971
+ error(LANGUAGE_NOT_FOUND.replace("{}", languageName));
1972
+ throw new Error('Unknown language: "' + languageName + '"');
2224
1973
  }
2225
- /**
2226
- *
2227
- * @param {PluginEvent} event
2228
- * @param {any} args
2229
- */
2230
- function fire(event, args) {
2231
- const cb = event;
2232
- plugins.forEach(function (plugin) {
2233
- if (plugin[cb]) {
2234
- plugin[cb](args);
2235
- }
2236
- });
1974
+
1975
+ const md = compileLanguage(language, { plugins });
1976
+ let result = '';
1977
+ /** @type {CompiledMode} */
1978
+ let top = continuation || md;
1979
+ /** @type Record<string,CompiledMode> */
1980
+ const continuations = {}; // keep continuations for sub-languages
1981
+ const emitter = new options.__emitter(options);
1982
+ processContinuations();
1983
+ let modeBuffer = '';
1984
+ let relevance = 0;
1985
+ let index = 0;
1986
+ let iterations = 0;
1987
+ let resumeScanAtSamePosition = false;
1988
+
1989
+ try {
1990
+ top.matcher.considerAll();
1991
+
1992
+ for (;;) {
1993
+ iterations++;
1994
+ if (resumeScanAtSamePosition) {
1995
+ // only regexes not matched previously will now be
1996
+ // considered for a potential match
1997
+ resumeScanAtSamePosition = false;
1998
+ } else {
1999
+ top.matcher.considerAll();
2000
+ }
2001
+ top.matcher.lastIndex = index;
2002
+
2003
+ const match = top.matcher.exec(codeToHighlight);
2004
+ // console.log("match", match[0], match.rule && match.rule.begin)
2005
+
2006
+ if (!match) break;
2007
+
2008
+ const beforeMatch = codeToHighlight.substring(index, match.index);
2009
+ const processedCount = processLexeme(beforeMatch, match);
2010
+ index = match.index + processedCount;
2011
+ }
2012
+ processLexeme(codeToHighlight.substr(index));
2013
+ emitter.closeAllNodes();
2014
+ emitter.finalize();
2015
+ result = emitter.toHTML();
2016
+
2017
+ return {
2018
+ // avoid possible breakage with v10 clients expecting
2019
+ // this to always be an integer
2020
+ relevance: Math.floor(relevance),
2021
+ value: result,
2022
+ language: languageName,
2023
+ illegal: false,
2024
+ emitter: emitter,
2025
+ top: top
2026
+ };
2027
+ } catch (err) {
2028
+ if (err.message && err.message.includes('Illegal')) {
2029
+ return {
2030
+ illegal: true,
2031
+ illegalBy: {
2032
+ msg: err.message,
2033
+ context: codeToHighlight.slice(index - 100, index + 100),
2034
+ mode: err.mode
2035
+ },
2036
+ sofar: result,
2037
+ relevance: 0,
2038
+ value: escape$1(codeToHighlight),
2039
+ emitter: emitter
2040
+ };
2041
+ } else if (SAFE_MODE) {
2042
+ return {
2043
+ illegal: false,
2044
+ relevance: 0,
2045
+ value: escape$1(codeToHighlight),
2046
+ emitter: emitter,
2047
+ language: languageName,
2048
+ top: top,
2049
+ errorRaised: err
2050
+ };
2051
+ } else {
2052
+ throw err;
2053
+ }
2237
2054
  }
2238
- /**
2239
- Note: fixMarkup is deprecated and will be removed entirely in v11
2240
-
2241
- @param {string} arg
2055
+ }
2056
+
2057
+ /**
2058
+ * returns a valid highlight result, without actually doing any actual work,
2059
+ * auto highlight starts with this and it's possible for small snippets that
2060
+ * auto-detection may not find a better match
2061
+ * @param {string} code
2062
+ * @returns {HighlightResult}
2063
+ */
2064
+ function justTextHighlightResult(code) {
2065
+ const result = {
2066
+ relevance: 0,
2067
+ emitter: new options.__emitter(options),
2068
+ value: escape$1(code),
2069
+ illegal: false,
2070
+ top: PLAINTEXT_LANGUAGE
2071
+ };
2072
+ result.emitter.addText(code);
2073
+ return result;
2074
+ }
2075
+
2076
+ /**
2077
+ Highlighting with language detection. Accepts a string with the code to
2078
+ highlight. Returns an object with the following properties:
2079
+
2080
+ - language (detected language)
2081
+ - relevance (int)
2082
+ - value (an HTML string with highlighting markup)
2083
+ - second_best (object with the same structure for second-best heuristically
2084
+ detected language, may be absent)
2085
+
2086
+ @param {string} code
2087
+ @param {Array<string>} [languageSubset]
2088
+ @returns {AutoHighlightResult}
2089
+ */
2090
+ function highlightAuto(code, languageSubset) {
2091
+ languageSubset = languageSubset || options.languages || Object.keys(languages);
2092
+ const plaintext = justTextHighlightResult(code);
2093
+
2094
+ const results = languageSubset.filter(getLanguage).filter(autoDetection).map(name =>
2095
+ _highlight(name, code, false)
2096
+ );
2097
+ results.unshift(plaintext); // plaintext is always an option
2098
+
2099
+ const sorted = results.sort((a, b) => {
2100
+ // sort base on relevance
2101
+ if (a.relevance !== b.relevance) return b.relevance - a.relevance;
2102
+
2103
+ // always award the tie to the base language
2104
+ // ie if C++ and Arduino are tied, it's more likely to be C++
2105
+ if (a.language && b.language) {
2106
+ if (getLanguage(a.language).supersetOf === b.language) {
2107
+ return 1;
2108
+ } else if (getLanguage(b.language).supersetOf === a.language) {
2109
+ return -1;
2110
+ }
2111
+ }
2112
+
2113
+ // otherwise say they are equal, which has the effect of sorting on
2114
+ // relevance while preserving the original ordering - which is how ties
2115
+ // have historically been settled, ie the language that comes first always
2116
+ // wins in the case of a tie
2117
+ return 0;
2118
+ });
2119
+
2120
+ const [best, secondBest] = sorted;
2121
+
2122
+ /** @type {AutoHighlightResult} */
2123
+ const result = best;
2124
+ result.second_best = secondBest;
2125
+
2126
+ return result;
2127
+ }
2128
+
2129
+ /**
2130
+ Post-processing of the highlighted markup:
2131
+
2132
+ - replace TABs with something more useful
2133
+ - replace real line-breaks with '<br>' for non-pre containers
2134
+
2135
+ @param {string} html
2242
2136
  @returns {string}
2243
- */
2244
- function deprecateFixMarkup(arg) {
2245
- deprecated("10.2.0", "fixMarkup will be removed entirely in v11.0");
2246
- deprecated("10.2.0", "Please see https://github.com/highlightjs/highlight.js/issues/2534");
2247
- return fixMarkup(arg);
2137
+ */
2138
+ function fixMarkup(html) {
2139
+ if (!(options.tabReplace || options.useBR)) {
2140
+ return html;
2248
2141
  }
2249
- /**
2250
- *
2251
- * @param {HighlightedHTMLElement} el
2252
- */
2253
- function deprecateHighlightBlock(el) {
2254
- deprecated("10.7.0", "highlightBlock will be removed entirely in v12.0");
2255
- deprecated("10.7.0", "Please use highlightElement now.");
2256
- return highlightElement(el);
2142
+
2143
+ return html.replace(fixMarkupRe, match => {
2144
+ if (match === '\n') {
2145
+ return options.useBR ? '<br>' : match;
2146
+ } else if (options.tabReplace) {
2147
+ return match.replace(/\t/g, options.tabReplace);
2148
+ }
2149
+ return match;
2150
+ });
2151
+ }
2152
+
2153
+ /**
2154
+ * Builds new class name for block given the language name
2155
+ *
2156
+ * @param {HTMLElement} element
2157
+ * @param {string} [currentLang]
2158
+ * @param {string} [resultLang]
2159
+ */
2160
+ function updateClassName(element, currentLang, resultLang) {
2161
+ const language = currentLang ? aliases[currentLang] : resultLang;
2162
+
2163
+ element.classList.add("hljs");
2164
+ if (language) element.classList.add(language);
2165
+ }
2166
+
2167
+ /** @type {HLJSPlugin} */
2168
+ const brPlugin = {
2169
+ "before:highlightElement": ({ el }) => {
2170
+ if (options.useBR) {
2171
+ el.innerHTML = el.innerHTML.replace(/\n/g, '').replace(/<br[ /]*>/g, '\n');
2172
+ }
2173
+ },
2174
+ "after:highlightElement": ({ result }) => {
2175
+ if (options.useBR) {
2176
+ result.value = result.value.replace(/\n/g, "<br>");
2177
+ }
2178
+ }
2179
+ };
2180
+
2181
+ const TAB_REPLACE_RE = /^(<[^>]+>|\t)+/gm;
2182
+ /** @type {HLJSPlugin} */
2183
+ const tabReplacePlugin = {
2184
+ "after:highlightElement": ({ result }) => {
2185
+ if (options.tabReplace) {
2186
+ result.value = result.value.replace(TAB_REPLACE_RE, (m) =>
2187
+ m.replace(/\t/g, options.tabReplace)
2188
+ );
2189
+ }
2190
+ }
2191
+ };
2192
+
2193
+ /**
2194
+ * Applies highlighting to a DOM node containing code. Accepts a DOM node and
2195
+ * two optional parameters for fixMarkup.
2196
+ *
2197
+ * @param {HighlightedHTMLElement} element - the HTML element to highlight
2198
+ */
2199
+ function highlightElement(element) {
2200
+ /** @type HTMLElement */
2201
+ let node = null;
2202
+ const language = blockLanguage(element);
2203
+
2204
+ if (shouldNotHighlight(language)) return;
2205
+
2206
+ // support for v10 API
2207
+ fire("before:highlightElement",
2208
+ { el: element, language: language });
2209
+
2210
+ node = element;
2211
+ const text = node.textContent;
2212
+ const result = language ? highlight(text, { language, ignoreIllegals: true }) : highlightAuto(text);
2213
+
2214
+ // support for v10 API
2215
+ fire("after:highlightElement", { el: element, result, text });
2216
+
2217
+ element.innerHTML = result.value;
2218
+ updateClassName(element, language, result.language);
2219
+ element.result = {
2220
+ language: result.language,
2221
+ // TODO: remove with version 11.0
2222
+ re: result.relevance,
2223
+ relavance: result.relevance
2224
+ };
2225
+ if (result.second_best) {
2226
+ element.second_best = {
2227
+ language: result.second_best.language,
2228
+ // TODO: remove with version 11.0
2229
+ re: result.second_best.relevance,
2230
+ relavance: result.second_best.relevance
2231
+ };
2232
+ }
2233
+ }
2234
+
2235
+ /**
2236
+ * Updates highlight.js global options with the passed options
2237
+ *
2238
+ * @param {Partial<HLJSOptions>} userOptions
2239
+ */
2240
+ function configure(userOptions) {
2241
+ if (userOptions.useBR) {
2242
+ deprecated("10.3.0", "'useBR' will be removed entirely in v11.0");
2243
+ deprecated("10.3.0", "Please see https://github.com/highlightjs/highlight.js/issues/2559");
2244
+ }
2245
+ options = inherit$1(options, userOptions);
2246
+ }
2247
+
2248
+ /**
2249
+ * Highlights to all <pre><code> blocks on a page
2250
+ *
2251
+ * @type {Function & {called?: boolean}}
2252
+ */
2253
+ // TODO: remove v12, deprecated
2254
+ const initHighlighting = () => {
2255
+ if (initHighlighting.called) return;
2256
+ initHighlighting.called = true;
2257
+
2258
+ deprecated("10.6.0", "initHighlighting() is deprecated. Use highlightAll() instead.");
2259
+
2260
+ const blocks = document.querySelectorAll('pre code');
2261
+ blocks.forEach(highlightElement);
2262
+ };
2263
+
2264
+ // Higlights all when DOMContentLoaded fires
2265
+ // TODO: remove v12, deprecated
2266
+ function initHighlightingOnLoad() {
2267
+ deprecated("10.6.0", "initHighlightingOnLoad() is deprecated. Use highlightAll() instead.");
2268
+ wantsHighlight = true;
2269
+ }
2270
+
2271
+ let wantsHighlight = false;
2272
+
2273
+ /**
2274
+ * auto-highlights all pre>code elements on the page
2275
+ */
2276
+ function highlightAll() {
2277
+ // if we are called too early in the loading process
2278
+ if (document.readyState === "loading") {
2279
+ wantsHighlight = true;
2280
+ return;
2257
2281
  }
2258
- /* Interface definition */
2259
- Object.assign(hljs, {
2260
- highlight,
2261
- highlightAuto,
2262
- highlightAll,
2263
- fixMarkup: deprecateFixMarkup,
2264
- highlightElement,
2265
- // TODO: Remove with v12 API
2266
- highlightBlock: deprecateHighlightBlock,
2267
- configure,
2268
- initHighlighting,
2269
- initHighlightingOnLoad,
2270
- registerLanguage,
2271
- unregisterLanguage,
2272
- listLanguages,
2273
- getLanguage,
2274
- registerAliases,
2275
- requireLanguage,
2276
- autoDetection,
2277
- inherit: inherit$1,
2278
- addPlugin,
2279
- // plugins for frameworks
2280
- vuePlugin: BuildVuePlugin(hljs).VuePlugin
2282
+
2283
+ const blocks = document.querySelectorAll('pre code');
2284
+ blocks.forEach(highlightElement);
2285
+ }
2286
+
2287
+ function boot() {
2288
+ // if a highlight was requested before DOM was loaded, do now
2289
+ if (wantsHighlight) highlightAll();
2290
+ }
2291
+
2292
+ // make sure we are in the browser environment
2293
+ if (typeof window !== 'undefined' && window.addEventListener) {
2294
+ window.addEventListener('DOMContentLoaded', boot, false);
2295
+ }
2296
+
2297
+ /**
2298
+ * Register a language grammar module
2299
+ *
2300
+ * @param {string} languageName
2301
+ * @param {LanguageFn} languageDefinition
2302
+ */
2303
+ function registerLanguage(languageName, languageDefinition) {
2304
+ let lang = null;
2305
+ try {
2306
+ lang = languageDefinition(hljs);
2307
+ } catch (error$1) {
2308
+ error("Language definition for '{}' could not be registered.".replace("{}", languageName));
2309
+ // hard or soft error
2310
+ if (!SAFE_MODE) { throw error$1; } else { error(error$1); }
2311
+ // languages that have serious errors are replaced with essentially a
2312
+ // "plaintext" stand-in so that the code blocks will still get normal
2313
+ // css classes applied to them - and one bad language won't break the
2314
+ // entire highlighter
2315
+ lang = PLAINTEXT_LANGUAGE;
2316
+ }
2317
+ // give it a temporary name if it doesn't have one in the meta-data
2318
+ if (!lang.name) lang.name = languageName;
2319
+ languages[languageName] = lang;
2320
+ lang.rawDefinition = languageDefinition.bind(null, hljs);
2321
+
2322
+ if (lang.aliases) {
2323
+ registerAliases(lang.aliases, { languageName });
2324
+ }
2325
+ }
2326
+
2327
+ /**
2328
+ * Remove a language grammar module
2329
+ *
2330
+ * @param {string} languageName
2331
+ */
2332
+ function unregisterLanguage(languageName) {
2333
+ delete languages[languageName];
2334
+ for (const alias of Object.keys(aliases)) {
2335
+ if (aliases[alias] === languageName) {
2336
+ delete aliases[alias];
2337
+ }
2338
+ }
2339
+ }
2340
+
2341
+ /**
2342
+ * @returns {string[]} List of language internal names
2343
+ */
2344
+ function listLanguages() {
2345
+ return Object.keys(languages);
2346
+ }
2347
+
2348
+ /**
2349
+ intended usage: When one language truly requires another
2350
+
2351
+ Unlike `getLanguage`, this will throw when the requested language
2352
+ is not available.
2353
+
2354
+ @param {string} name - name of the language to fetch/require
2355
+ @returns {Language | never}
2356
+ */
2357
+ function requireLanguage(name) {
2358
+ deprecated("10.4.0", "requireLanguage will be removed entirely in v11.");
2359
+ deprecated("10.4.0", "Please see https://github.com/highlightjs/highlight.js/pull/2844");
2360
+
2361
+ const lang = getLanguage(name);
2362
+ if (lang) { return lang; }
2363
+
2364
+ const err = new Error('The \'{}\' language is required, but not loaded.'.replace('{}', name));
2365
+ throw err;
2366
+ }
2367
+
2368
+ /**
2369
+ * @param {string} name - name of the language to retrieve
2370
+ * @returns {Language | undefined}
2371
+ */
2372
+ function getLanguage(name) {
2373
+ name = (name || '').toLowerCase();
2374
+ return languages[name] || languages[aliases[name]];
2375
+ }
2376
+
2377
+ /**
2378
+ *
2379
+ * @param {string|string[]} aliasList - single alias or list of aliases
2380
+ * @param {{languageName: string}} opts
2381
+ */
2382
+ function registerAliases(aliasList, { languageName }) {
2383
+ if (typeof aliasList === 'string') {
2384
+ aliasList = [aliasList];
2385
+ }
2386
+ aliasList.forEach(alias => { aliases[alias.toLowerCase()] = languageName; });
2387
+ }
2388
+
2389
+ /**
2390
+ * Determines if a given language has auto-detection enabled
2391
+ * @param {string} name - name of the language
2392
+ */
2393
+ function autoDetection(name) {
2394
+ const lang = getLanguage(name);
2395
+ return lang && !lang.disableAutodetect;
2396
+ }
2397
+
2398
+ /**
2399
+ * Upgrades the old highlightBlock plugins to the new
2400
+ * highlightElement API
2401
+ * @param {HLJSPlugin} plugin
2402
+ */
2403
+ function upgradePluginAPI(plugin) {
2404
+ // TODO: remove with v12
2405
+ if (plugin["before:highlightBlock"] && !plugin["before:highlightElement"]) {
2406
+ plugin["before:highlightElement"] = (data) => {
2407
+ plugin["before:highlightBlock"](
2408
+ Object.assign({ block: data.el }, data)
2409
+ );
2410
+ };
2411
+ }
2412
+ if (plugin["after:highlightBlock"] && !plugin["after:highlightElement"]) {
2413
+ plugin["after:highlightElement"] = (data) => {
2414
+ plugin["after:highlightBlock"](
2415
+ Object.assign({ block: data.el }, data)
2416
+ );
2417
+ };
2418
+ }
2419
+ }
2420
+
2421
+ /**
2422
+ * @param {HLJSPlugin} plugin
2423
+ */
2424
+ function addPlugin(plugin) {
2425
+ upgradePluginAPI(plugin);
2426
+ plugins.push(plugin);
2427
+ }
2428
+
2429
+ /**
2430
+ *
2431
+ * @param {PluginEvent} event
2432
+ * @param {any} args
2433
+ */
2434
+ function fire(event, args) {
2435
+ const cb = event;
2436
+ plugins.forEach(function(plugin) {
2437
+ if (plugin[cb]) {
2438
+ plugin[cb](args);
2439
+ }
2281
2440
  });
2282
- hljs.debugMode = function () { SAFE_MODE = false; };
2283
- hljs.safeMode = function () { SAFE_MODE = true; };
2284
- hljs.versionString = version;
2285
- for (const key in MODES) {
2286
- // @ts-ignore
2287
- if (typeof MODES[key] === "object") {
2288
- // @ts-ignore
2289
- deepFreezeEs6(MODES[key]);
2290
- }
2441
+ }
2442
+
2443
+ /**
2444
+ Note: fixMarkup is deprecated and will be removed entirely in v11
2445
+
2446
+ @param {string} arg
2447
+ @returns {string}
2448
+ */
2449
+ function deprecateFixMarkup(arg) {
2450
+ deprecated("10.2.0", "fixMarkup will be removed entirely in v11.0");
2451
+ deprecated("10.2.0", "Please see https://github.com/highlightjs/highlight.js/issues/2534");
2452
+
2453
+ return fixMarkup(arg);
2454
+ }
2455
+
2456
+ /**
2457
+ *
2458
+ * @param {HighlightedHTMLElement} el
2459
+ */
2460
+ function deprecateHighlightBlock(el) {
2461
+ deprecated("10.7.0", "highlightBlock will be removed entirely in v12.0");
2462
+ deprecated("10.7.0", "Please use highlightElement now.");
2463
+
2464
+ return highlightElement(el);
2465
+ }
2466
+
2467
+ /* Interface definition */
2468
+ Object.assign(hljs, {
2469
+ highlight,
2470
+ highlightAuto,
2471
+ highlightAll,
2472
+ fixMarkup: deprecateFixMarkup,
2473
+ highlightElement,
2474
+ // TODO: Remove with v12 API
2475
+ highlightBlock: deprecateHighlightBlock,
2476
+ configure,
2477
+ initHighlighting,
2478
+ initHighlightingOnLoad,
2479
+ registerLanguage,
2480
+ unregisterLanguage,
2481
+ listLanguages,
2482
+ getLanguage,
2483
+ registerAliases,
2484
+ requireLanguage,
2485
+ autoDetection,
2486
+ inherit: inherit$1,
2487
+ addPlugin,
2488
+ // plugins for frameworks
2489
+ vuePlugin: BuildVuePlugin(hljs).VuePlugin
2490
+ });
2491
+
2492
+ hljs.debugMode = function() { SAFE_MODE = false; };
2493
+ hljs.safeMode = function() { SAFE_MODE = true; };
2494
+ hljs.versionString = version;
2495
+
2496
+ for (const key in MODES) {
2497
+ // @ts-ignore
2498
+ if (typeof MODES[key] === "object") {
2499
+ // @ts-ignore
2500
+ deepFreezeEs6(MODES[key]);
2291
2501
  }
2292
- // merge all the modes/regexs into our main object
2293
- Object.assign(hljs, MODES);
2294
- // built-in plugins, likely to be moved out of core in the future
2295
- hljs.addPlugin(brPlugin); // slated to be removed in v11
2296
- hljs.addPlugin(mergeHTMLPlugin);
2297
- hljs.addPlugin(tabReplacePlugin);
2298
- return hljs;
2502
+ }
2503
+
2504
+ // merge all the modes/regexs into our main object
2505
+ Object.assign(hljs, MODES);
2506
+
2507
+ // built-in plugins, likely to be moved out of core in the future
2508
+ hljs.addPlugin(brPlugin); // slated to be removed in v11
2509
+ hljs.addPlugin(mergeHTMLPlugin);
2510
+ hljs.addPlugin(tabReplacePlugin);
2511
+ return hljs;
2299
2512
  };
2513
+
2300
2514
  // export an "instance" of the highlighter
2301
2515
  var highlight = HLJS({});
2516
+
2302
2517
  module.exports = highlight;