handlebars.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. var __defProp = Object.defineProperty;
  8. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  9. var __getOwnPropNames = Object.getOwnPropertyNames;
  10. var __hasOwnProp = Object.prototype.hasOwnProperty;
  11. var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
  12. var __reExport = (target, module, desc) => {
  13. if (module && typeof module === "object" || typeof module === "function") {
  14. for (let key of __getOwnPropNames(module))
  15. if (!__hasOwnProp.call(target, key) && key !== "default")
  16. __defProp(target, key, { get: () => module[key], enumerable: !(desc = __getOwnPropDesc(module, key)) || desc.enumerable });
  17. }
  18. return target;
  19. };
  20. // src/fillers/monaco-editor-core.ts
  21. var monaco_editor_core_exports = {};
  22. __markAsModule(monaco_editor_core_exports);
  23. __reExport(monaco_editor_core_exports, monaco_editor_core_star);
  24. import * as monaco_editor_core_star from "../../editor/editor.api.js";
  25. // src/basic-languages/handlebars/handlebars.ts
  26. var EMPTY_ELEMENTS = [
  27. "area",
  28. "base",
  29. "br",
  30. "col",
  31. "embed",
  32. "hr",
  33. "img",
  34. "input",
  35. "keygen",
  36. "link",
  37. "menuitem",
  38. "meta",
  39. "param",
  40. "source",
  41. "track",
  42. "wbr"
  43. ];
  44. var conf = {
  45. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\$\^\&\*\(\)\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\s]+)/g,
  46. comments: {
  47. blockComment: ["{{!--", "--}}"]
  48. },
  49. brackets: [
  50. ["<!--", "-->"],
  51. ["<", ">"],
  52. ["{{", "}}"],
  53. ["{", "}"],
  54. ["(", ")"]
  55. ],
  56. autoClosingPairs: [
  57. { open: "{", close: "}" },
  58. { open: "[", close: "]" },
  59. { open: "(", close: ")" },
  60. { open: '"', close: '"' },
  61. { open: "'", close: "'" }
  62. ],
  63. surroundingPairs: [
  64. { open: "<", close: ">" },
  65. { open: '"', close: '"' },
  66. { open: "'", close: "'" }
  67. ],
  68. onEnterRules: [
  69. {
  70. beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join("|")}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, "i"),
  71. afterText: /^<\/(\w[\w\d]*)\s*>$/i,
  72. action: {
  73. indentAction: monaco_editor_core_exports.languages.IndentAction.IndentOutdent
  74. }
  75. },
  76. {
  77. beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join("|")}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, "i"),
  78. action: { indentAction: monaco_editor_core_exports.languages.IndentAction.Indent }
  79. }
  80. ]
  81. };
  82. var language = {
  83. defaultToken: "",
  84. tokenPostfix: "",
  85. tokenizer: {
  86. root: [
  87. [/\{\{!--/, "comment.block.start.handlebars", "@commentBlock"],
  88. [/\{\{!/, "comment.start.handlebars", "@comment"],
  89. [/\{\{/, { token: "@rematch", switchTo: "@handlebarsInSimpleState.root" }],
  90. [/<!DOCTYPE/, "metatag.html", "@doctype"],
  91. [/<!--/, "comment.html", "@commentHtml"],
  92. [/(<)(\w+)(\/>)/, ["delimiter.html", "tag.html", "delimiter.html"]],
  93. [/(<)(script)/, ["delimiter.html", { token: "tag.html", next: "@script" }]],
  94. [/(<)(style)/, ["delimiter.html", { token: "tag.html", next: "@style" }]],
  95. [/(<)([:\w]+)/, ["delimiter.html", { token: "tag.html", next: "@otherTag" }]],
  96. [/(<\/)(\w+)/, ["delimiter.html", { token: "tag.html", next: "@otherTag" }]],
  97. [/</, "delimiter.html"],
  98. [/\{/, "delimiter.html"],
  99. [/[^<{]+/]
  100. ],
  101. doctype: [
  102. [
  103. /\{\{/,
  104. {
  105. token: "@rematch",
  106. switchTo: "@handlebarsInSimpleState.comment"
  107. }
  108. ],
  109. [/[^>]+/, "metatag.content.html"],
  110. [/>/, "metatag.html", "@pop"]
  111. ],
  112. comment: [
  113. [/\}\}/, "comment.end.handlebars", "@pop"],
  114. [/./, "comment.content.handlebars"]
  115. ],
  116. commentBlock: [
  117. [/--\}\}/, "comment.block.end.handlebars", "@pop"],
  118. [/./, "comment.content.handlebars"]
  119. ],
  120. commentHtml: [
  121. [
  122. /\{\{/,
  123. {
  124. token: "@rematch",
  125. switchTo: "@handlebarsInSimpleState.comment"
  126. }
  127. ],
  128. [/-->/, "comment.html", "@pop"],
  129. [/[^-]+/, "comment.content.html"],
  130. [/./, "comment.content.html"]
  131. ],
  132. otherTag: [
  133. [
  134. /\{\{/,
  135. {
  136. token: "@rematch",
  137. switchTo: "@handlebarsInSimpleState.otherTag"
  138. }
  139. ],
  140. [/\/?>/, "delimiter.html", "@pop"],
  141. [/"([^"]*)"/, "attribute.value"],
  142. [/'([^']*)'/, "attribute.value"],
  143. [/[\w\-]+/, "attribute.name"],
  144. [/=/, "delimiter"],
  145. [/[ \t\r\n]+/]
  146. ],
  147. script: [
  148. [
  149. /\{\{/,
  150. {
  151. token: "@rematch",
  152. switchTo: "@handlebarsInSimpleState.script"
  153. }
  154. ],
  155. [/type/, "attribute.name", "@scriptAfterType"],
  156. [/"([^"]*)"/, "attribute.value"],
  157. [/'([^']*)'/, "attribute.value"],
  158. [/[\w\-]+/, "attribute.name"],
  159. [/=/, "delimiter"],
  160. [
  161. />/,
  162. {
  163. token: "delimiter.html",
  164. next: "@scriptEmbedded.text/javascript",
  165. nextEmbedded: "text/javascript"
  166. }
  167. ],
  168. [/[ \t\r\n]+/],
  169. [
  170. /(<\/)(script\s*)(>)/,
  171. ["delimiter.html", "tag.html", { token: "delimiter.html", next: "@pop" }]
  172. ]
  173. ],
  174. scriptAfterType: [
  175. [
  176. /\{\{/,
  177. {
  178. token: "@rematch",
  179. switchTo: "@handlebarsInSimpleState.scriptAfterType"
  180. }
  181. ],
  182. [/=/, "delimiter", "@scriptAfterTypeEquals"],
  183. [
  184. />/,
  185. {
  186. token: "delimiter.html",
  187. next: "@scriptEmbedded.text/javascript",
  188. nextEmbedded: "text/javascript"
  189. }
  190. ],
  191. [/[ \t\r\n]+/],
  192. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  193. ],
  194. scriptAfterTypeEquals: [
  195. [
  196. /\{\{/,
  197. {
  198. token: "@rematch",
  199. switchTo: "@handlebarsInSimpleState.scriptAfterTypeEquals"
  200. }
  201. ],
  202. [
  203. /"([^"]*)"/,
  204. {
  205. token: "attribute.value",
  206. switchTo: "@scriptWithCustomType.$1"
  207. }
  208. ],
  209. [
  210. /'([^']*)'/,
  211. {
  212. token: "attribute.value",
  213. switchTo: "@scriptWithCustomType.$1"
  214. }
  215. ],
  216. [
  217. />/,
  218. {
  219. token: "delimiter.html",
  220. next: "@scriptEmbedded.text/javascript",
  221. nextEmbedded: "text/javascript"
  222. }
  223. ],
  224. [/[ \t\r\n]+/],
  225. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  226. ],
  227. scriptWithCustomType: [
  228. [
  229. /\{\{/,
  230. {
  231. token: "@rematch",
  232. switchTo: "@handlebarsInSimpleState.scriptWithCustomType.$S2"
  233. }
  234. ],
  235. [
  236. />/,
  237. {
  238. token: "delimiter.html",
  239. next: "@scriptEmbedded.$S2",
  240. nextEmbedded: "$S2"
  241. }
  242. ],
  243. [/"([^"]*)"/, "attribute.value"],
  244. [/'([^']*)'/, "attribute.value"],
  245. [/[\w\-]+/, "attribute.name"],
  246. [/=/, "delimiter"],
  247. [/[ \t\r\n]+/],
  248. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  249. ],
  250. scriptEmbedded: [
  251. [
  252. /\{\{/,
  253. {
  254. token: "@rematch",
  255. switchTo: "@handlebarsInEmbeddedState.scriptEmbedded.$S2",
  256. nextEmbedded: "@pop"
  257. }
  258. ],
  259. [/<\/script/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }]
  260. ],
  261. style: [
  262. [
  263. /\{\{/,
  264. {
  265. token: "@rematch",
  266. switchTo: "@handlebarsInSimpleState.style"
  267. }
  268. ],
  269. [/type/, "attribute.name", "@styleAfterType"],
  270. [/"([^"]*)"/, "attribute.value"],
  271. [/'([^']*)'/, "attribute.value"],
  272. [/[\w\-]+/, "attribute.name"],
  273. [/=/, "delimiter"],
  274. [
  275. />/,
  276. {
  277. token: "delimiter.html",
  278. next: "@styleEmbedded.text/css",
  279. nextEmbedded: "text/css"
  280. }
  281. ],
  282. [/[ \t\r\n]+/],
  283. [
  284. /(<\/)(style\s*)(>)/,
  285. ["delimiter.html", "tag.html", { token: "delimiter.html", next: "@pop" }]
  286. ]
  287. ],
  288. styleAfterType: [
  289. [
  290. /\{\{/,
  291. {
  292. token: "@rematch",
  293. switchTo: "@handlebarsInSimpleState.styleAfterType"
  294. }
  295. ],
  296. [/=/, "delimiter", "@styleAfterTypeEquals"],
  297. [
  298. />/,
  299. {
  300. token: "delimiter.html",
  301. next: "@styleEmbedded.text/css",
  302. nextEmbedded: "text/css"
  303. }
  304. ],
  305. [/[ \t\r\n]+/],
  306. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  307. ],
  308. styleAfterTypeEquals: [
  309. [
  310. /\{\{/,
  311. {
  312. token: "@rematch",
  313. switchTo: "@handlebarsInSimpleState.styleAfterTypeEquals"
  314. }
  315. ],
  316. [
  317. /"([^"]*)"/,
  318. {
  319. token: "attribute.value",
  320. switchTo: "@styleWithCustomType.$1"
  321. }
  322. ],
  323. [
  324. /'([^']*)'/,
  325. {
  326. token: "attribute.value",
  327. switchTo: "@styleWithCustomType.$1"
  328. }
  329. ],
  330. [
  331. />/,
  332. {
  333. token: "delimiter.html",
  334. next: "@styleEmbedded.text/css",
  335. nextEmbedded: "text/css"
  336. }
  337. ],
  338. [/[ \t\r\n]+/],
  339. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  340. ],
  341. styleWithCustomType: [
  342. [
  343. /\{\{/,
  344. {
  345. token: "@rematch",
  346. switchTo: "@handlebarsInSimpleState.styleWithCustomType.$S2"
  347. }
  348. ],
  349. [
  350. />/,
  351. {
  352. token: "delimiter.html",
  353. next: "@styleEmbedded.$S2",
  354. nextEmbedded: "$S2"
  355. }
  356. ],
  357. [/"([^"]*)"/, "attribute.value"],
  358. [/'([^']*)'/, "attribute.value"],
  359. [/[\w\-]+/, "attribute.name"],
  360. [/=/, "delimiter"],
  361. [/[ \t\r\n]+/],
  362. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  363. ],
  364. styleEmbedded: [
  365. [
  366. /\{\{/,
  367. {
  368. token: "@rematch",
  369. switchTo: "@handlebarsInEmbeddedState.styleEmbedded.$S2",
  370. nextEmbedded: "@pop"
  371. }
  372. ],
  373. [/<\/style/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }]
  374. ],
  375. handlebarsInSimpleState: [
  376. [/\{\{\{?/, "delimiter.handlebars"],
  377. [/\}\}\}?/, { token: "delimiter.handlebars", switchTo: "@$S2.$S3" }],
  378. { include: "handlebarsRoot" }
  379. ],
  380. handlebarsInEmbeddedState: [
  381. [/\{\{\{?/, "delimiter.handlebars"],
  382. [
  383. /\}\}\}?/,
  384. {
  385. token: "delimiter.handlebars",
  386. switchTo: "@$S2.$S3",
  387. nextEmbedded: "$S3"
  388. }
  389. ],
  390. { include: "handlebarsRoot" }
  391. ],
  392. handlebarsRoot: [
  393. [/"[^"]*"/, "string.handlebars"],
  394. [/[#/][^\s}]+/, "keyword.helper.handlebars"],
  395. [/else\b/, "keyword.helper.handlebars"],
  396. [/[\s]+/],
  397. [/[^}]/, "variable.parameter.handlebars"]
  398. ]
  399. }
  400. };
  401. export {
  402. conf,
  403. language
  404. };