liquid.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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/liquid/liquid.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. brackets: [
  47. ["<!--", "-->"],
  48. ["<", ">"],
  49. ["{{", "}}"],
  50. ["{%", "%}"],
  51. ["{", "}"],
  52. ["(", ")"]
  53. ],
  54. autoClosingPairs: [
  55. { open: "{", close: "}" },
  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. builtinTags: [
  85. "if",
  86. "else",
  87. "elseif",
  88. "endif",
  89. "render",
  90. "assign",
  91. "capture",
  92. "endcapture",
  93. "case",
  94. "endcase",
  95. "comment",
  96. "endcomment",
  97. "cycle",
  98. "decrement",
  99. "for",
  100. "endfor",
  101. "include",
  102. "increment",
  103. "layout",
  104. "raw",
  105. "endraw",
  106. "render",
  107. "tablerow",
  108. "endtablerow",
  109. "unless",
  110. "endunless"
  111. ],
  112. builtinFilters: [
  113. "abs",
  114. "append",
  115. "at_least",
  116. "at_most",
  117. "capitalize",
  118. "ceil",
  119. "compact",
  120. "date",
  121. "default",
  122. "divided_by",
  123. "downcase",
  124. "escape",
  125. "escape_once",
  126. "first",
  127. "floor",
  128. "join",
  129. "json",
  130. "last",
  131. "lstrip",
  132. "map",
  133. "minus",
  134. "modulo",
  135. "newline_to_br",
  136. "plus",
  137. "prepend",
  138. "remove",
  139. "remove_first",
  140. "replace",
  141. "replace_first",
  142. "reverse",
  143. "round",
  144. "rstrip",
  145. "size",
  146. "slice",
  147. "sort",
  148. "sort_natural",
  149. "split",
  150. "strip",
  151. "strip_html",
  152. "strip_newlines",
  153. "times",
  154. "truncate",
  155. "truncatewords",
  156. "uniq",
  157. "upcase",
  158. "url_decode",
  159. "url_encode",
  160. "where"
  161. ],
  162. constants: ["true", "false"],
  163. operators: ["==", "!=", ">", "<", ">=", "<="],
  164. symbol: /[=><!]+/,
  165. identifier: /[a-zA-Z_][\w]*/,
  166. tokenizer: {
  167. root: [
  168. [/\{\%\s*comment\s*\%\}/, "comment.start.liquid", "@comment"],
  169. [/\{\{/, { token: "@rematch", switchTo: "@liquidState.root" }],
  170. [/\{\%/, { token: "@rematch", switchTo: "@liquidState.root" }],
  171. [/(<)([\w\-]+)(\/>)/, ["delimiter.html", "tag.html", "delimiter.html"]],
  172. [/(<)([:\w]+)/, ["delimiter.html", { token: "tag.html", next: "@otherTag" }]],
  173. [/(<\/)([\w\-]+)/, ["delimiter.html", { token: "tag.html", next: "@otherTag" }]],
  174. [/</, "delimiter.html"],
  175. [/\{/, "delimiter.html"],
  176. [/[^<{]+/]
  177. ],
  178. comment: [
  179. [/\{\%\s*endcomment\s*\%\}/, "comment.end.liquid", "@pop"],
  180. [/./, "comment.content.liquid"]
  181. ],
  182. otherTag: [
  183. [
  184. /\{\{/,
  185. {
  186. token: "@rematch",
  187. switchTo: "@liquidState.otherTag"
  188. }
  189. ],
  190. [
  191. /\{\%/,
  192. {
  193. token: "@rematch",
  194. switchTo: "@liquidState.otherTag"
  195. }
  196. ],
  197. [/\/?>/, "delimiter.html", "@pop"],
  198. [/"([^"]*)"/, "attribute.value"],
  199. [/'([^']*)'/, "attribute.value"],
  200. [/[\w\-]+/, "attribute.name"],
  201. [/=/, "delimiter"],
  202. [/[ \t\r\n]+/]
  203. ],
  204. liquidState: [
  205. [/\{\{/, "delimiter.output.liquid"],
  206. [/\}\}/, { token: "delimiter.output.liquid", switchTo: "@$S2.$S3" }],
  207. [/\{\%/, "delimiter.tag.liquid"],
  208. [/raw\s*\%\}/, "delimiter.tag.liquid", "@liquidRaw"],
  209. [/\%\}/, { token: "delimiter.tag.liquid", switchTo: "@$S2.$S3" }],
  210. { include: "liquidRoot" }
  211. ],
  212. liquidRaw: [
  213. [/^(?!\{\%\s*endraw\s*\%\}).+/],
  214. [/\{\%/, "delimiter.tag.liquid"],
  215. [/@identifier/],
  216. [/\%\}/, { token: "delimiter.tag.liquid", next: "@root" }]
  217. ],
  218. liquidRoot: [
  219. [/\d+(\.\d+)?/, "number.liquid"],
  220. [/"[^"]*"/, "string.liquid"],
  221. [/'[^']*'/, "string.liquid"],
  222. [/\s+/],
  223. [
  224. /@symbol/,
  225. {
  226. cases: {
  227. "@operators": "operator.liquid",
  228. "@default": ""
  229. }
  230. }
  231. ],
  232. [/\./],
  233. [
  234. /@identifier/,
  235. {
  236. cases: {
  237. "@constants": "keyword.liquid",
  238. "@builtinFilters": "predefined.liquid",
  239. "@builtinTags": "predefined.liquid",
  240. "@default": "variable.liquid"
  241. }
  242. }
  243. ],
  244. [/[^}|%]/, "variable.liquid"]
  245. ]
  246. }
  247. };
  248. export {
  249. conf,
  250. language
  251. };