html.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.34.1(547870b6881302c5b4ff32173c16d06009e3588f)
  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/html/html.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. autoClosingPairs: [
  55. { open: "{", close: "}" },
  56. { open: "[", close: "]" },
  57. { open: "(", close: ")" },
  58. { open: '"', close: '"' },
  59. { open: "'", close: "'" }
  60. ],
  61. surroundingPairs: [
  62. { open: '"', close: '"' },
  63. { open: "'", close: "'" },
  64. { open: "{", close: "}" },
  65. { open: "[", close: "]" },
  66. { open: "(", close: ")" },
  67. { open: "<", close: ">" }
  68. ],
  69. onEnterRules: [
  70. {
  71. beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join("|")}))([_:\\w][_:\\w-.\\d]*)([^/>]*(?!/)>)[^<]*$`, "i"),
  72. afterText: /^<\/([_:\w][_:\w-.\d]*)\s*>$/i,
  73. action: {
  74. indentAction: monaco_editor_core_exports.languages.IndentAction.IndentOutdent
  75. }
  76. },
  77. {
  78. beforeText: new RegExp(`<(?!(?:${EMPTY_ELEMENTS.join("|")}))(\\w[\\w\\d]*)([^/>]*(?!/)>)[^<]*$`, "i"),
  79. action: { indentAction: monaco_editor_core_exports.languages.IndentAction.Indent }
  80. }
  81. ],
  82. folding: {
  83. markers: {
  84. start: new RegExp("^\\s*<!--\\s*#region\\b.*-->"),
  85. end: new RegExp("^\\s*<!--\\s*#endregion\\b.*-->")
  86. }
  87. }
  88. };
  89. var language = {
  90. defaultToken: "",
  91. tokenPostfix: ".html",
  92. ignoreCase: true,
  93. tokenizer: {
  94. root: [
  95. [/<!DOCTYPE/, "metatag", "@doctype"],
  96. [/<!--/, "comment", "@comment"],
  97. [/(<)((?:[\w\-]+:)?[\w\-]+)(\s*)(\/>)/, ["delimiter", "tag", "", "delimiter"]],
  98. [/(<)(script)/, ["delimiter", { token: "tag", next: "@script" }]],
  99. [/(<)(style)/, ["delimiter", { token: "tag", next: "@style" }]],
  100. [/(<)((?:[\w\-]+:)?[\w\-]+)/, ["delimiter", { token: "tag", next: "@otherTag" }]],
  101. [/(<\/)((?:[\w\-]+:)?[\w\-]+)/, ["delimiter", { token: "tag", next: "@otherTag" }]],
  102. [/</, "delimiter"],
  103. [/[^<]+/]
  104. ],
  105. doctype: [
  106. [/[^>]+/, "metatag.content"],
  107. [/>/, "metatag", "@pop"]
  108. ],
  109. comment: [
  110. [/-->/, "comment", "@pop"],
  111. [/[^-]+/, "comment.content"],
  112. [/./, "comment.content"]
  113. ],
  114. otherTag: [
  115. [/\/?>/, "delimiter", "@pop"],
  116. [/"([^"]*)"/, "attribute.value"],
  117. [/'([^']*)'/, "attribute.value"],
  118. [/[\w\-]+/, "attribute.name"],
  119. [/=/, "delimiter"],
  120. [/[ \t\r\n]+/]
  121. ],
  122. script: [
  123. [/type/, "attribute.name", "@scriptAfterType"],
  124. [/"([^"]*)"/, "attribute.value"],
  125. [/'([^']*)'/, "attribute.value"],
  126. [/[\w\-]+/, "attribute.name"],
  127. [/=/, "delimiter"],
  128. [
  129. />/,
  130. {
  131. token: "delimiter",
  132. next: "@scriptEmbedded",
  133. nextEmbedded: "text/javascript"
  134. }
  135. ],
  136. [/[ \t\r\n]+/],
  137. [/(<\/)(script\s*)(>)/, ["delimiter", "tag", { token: "delimiter", next: "@pop" }]]
  138. ],
  139. scriptAfterType: [
  140. [/=/, "delimiter", "@scriptAfterTypeEquals"],
  141. [
  142. />/,
  143. {
  144. token: "delimiter",
  145. next: "@scriptEmbedded",
  146. nextEmbedded: "text/javascript"
  147. }
  148. ],
  149. [/[ \t\r\n]+/],
  150. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  151. ],
  152. scriptAfterTypeEquals: [
  153. [
  154. /"module"/,
  155. {
  156. token: "attribute.value",
  157. switchTo: "@scriptWithCustomType.text/javascript"
  158. }
  159. ],
  160. [
  161. /'module'/,
  162. {
  163. token: "attribute.value",
  164. switchTo: "@scriptWithCustomType.text/javascript"
  165. }
  166. ],
  167. [
  168. /"([^"]*)"/,
  169. {
  170. token: "attribute.value",
  171. switchTo: "@scriptWithCustomType.$1"
  172. }
  173. ],
  174. [
  175. /'([^']*)'/,
  176. {
  177. token: "attribute.value",
  178. switchTo: "@scriptWithCustomType.$1"
  179. }
  180. ],
  181. [
  182. />/,
  183. {
  184. token: "delimiter",
  185. next: "@scriptEmbedded",
  186. nextEmbedded: "text/javascript"
  187. }
  188. ],
  189. [/[ \t\r\n]+/],
  190. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  191. ],
  192. scriptWithCustomType: [
  193. [
  194. />/,
  195. {
  196. token: "delimiter",
  197. next: "@scriptEmbedded.$S2",
  198. nextEmbedded: "$S2"
  199. }
  200. ],
  201. [/"([^"]*)"/, "attribute.value"],
  202. [/'([^']*)'/, "attribute.value"],
  203. [/[\w\-]+/, "attribute.name"],
  204. [/=/, "delimiter"],
  205. [/[ \t\r\n]+/],
  206. [/<\/script\s*>/, { token: "@rematch", next: "@pop" }]
  207. ],
  208. scriptEmbedded: [
  209. [/<\/script/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }],
  210. [/[^<]+/, ""]
  211. ],
  212. style: [
  213. [/type/, "attribute.name", "@styleAfterType"],
  214. [/"([^"]*)"/, "attribute.value"],
  215. [/'([^']*)'/, "attribute.value"],
  216. [/[\w\-]+/, "attribute.name"],
  217. [/=/, "delimiter"],
  218. [
  219. />/,
  220. {
  221. token: "delimiter",
  222. next: "@styleEmbedded",
  223. nextEmbedded: "text/css"
  224. }
  225. ],
  226. [/[ \t\r\n]+/],
  227. [/(<\/)(style\s*)(>)/, ["delimiter", "tag", { token: "delimiter", next: "@pop" }]]
  228. ],
  229. styleAfterType: [
  230. [/=/, "delimiter", "@styleAfterTypeEquals"],
  231. [
  232. />/,
  233. {
  234. token: "delimiter",
  235. next: "@styleEmbedded",
  236. nextEmbedded: "text/css"
  237. }
  238. ],
  239. [/[ \t\r\n]+/],
  240. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  241. ],
  242. styleAfterTypeEquals: [
  243. [
  244. /"([^"]*)"/,
  245. {
  246. token: "attribute.value",
  247. switchTo: "@styleWithCustomType.$1"
  248. }
  249. ],
  250. [
  251. /'([^']*)'/,
  252. {
  253. token: "attribute.value",
  254. switchTo: "@styleWithCustomType.$1"
  255. }
  256. ],
  257. [
  258. />/,
  259. {
  260. token: "delimiter",
  261. next: "@styleEmbedded",
  262. nextEmbedded: "text/css"
  263. }
  264. ],
  265. [/[ \t\r\n]+/],
  266. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  267. ],
  268. styleWithCustomType: [
  269. [
  270. />/,
  271. {
  272. token: "delimiter",
  273. next: "@styleEmbedded.$S2",
  274. nextEmbedded: "$S2"
  275. }
  276. ],
  277. [/"([^"]*)"/, "attribute.value"],
  278. [/'([^']*)'/, "attribute.value"],
  279. [/[\w\-]+/, "attribute.name"],
  280. [/=/, "delimiter"],
  281. [/[ \t\r\n]+/],
  282. [/<\/style\s*>/, { token: "@rematch", next: "@pop" }]
  283. ],
  284. styleEmbedded: [
  285. [/<\/style/, { token: "@rematch", next: "@pop", nextEmbedded: "@pop" }],
  286. [/[^<]+/, ""]
  287. ]
  288. }
  289. };
  290. export {
  291. conf,
  292. language
  293. };