handlebars.js 11 KB

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