vue.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. (function (mod) {
  4. "use strict";
  5. if (typeof exports === "object" && typeof module === "object") {// CommonJS
  6. mod(require("../../lib/codemirror"),
  7. require("../../addon/mode/overlay"),
  8. require("../xml/xml"),
  9. require("../javascript/javascript"),
  10. require("../coffeescript/coffeescript"),
  11. require("../css/css"),
  12. require("../sass/sass"),
  13. require("../stylus/stylus"),
  14. require("../pug/pug"),
  15. require("../handlebars/handlebars"));
  16. } else if (typeof define === "function" && define.amd) { // AMD
  17. define(["../../lib/codemirror",
  18. "../../addon/mode/overlay",
  19. "../xml/xml",
  20. "../javascript/javascript",
  21. "../coffeescript/coffeescript",
  22. "../css/css",
  23. "../sass/sass",
  24. "../stylus/stylus",
  25. "../pug/pug",
  26. "../handlebars/handlebars"], mod);
  27. } else { // Plain browser env
  28. mod(CodeMirror);
  29. }
  30. })(function (CodeMirror) {
  31. var tagLanguages = {
  32. script: [
  33. ["lang", /coffee(script)?/, "coffeescript"],
  34. ["type", /^(?:text|application)\/(?:x-)?coffee(?:script)?$/, "coffeescript"],
  35. ["lang", /^babel$/, "javascript"],
  36. ["type", /^text\/babel$/, "javascript"],
  37. ["type", /^text\/ecmascript-\d+$/, "javascript"]
  38. ],
  39. style: [
  40. ["lang", /^stylus$/i, "stylus"],
  41. ["lang", /^sass$/i, "sass"],
  42. ["lang", /^less$/i, "text/x-less"],
  43. ["lang", /^scss$/i, "text/x-scss"],
  44. ["type", /^(text\/)?(x-)?styl(us)?$/i, "stylus"],
  45. ["type", /^text\/sass/i, "sass"],
  46. ["type", /^(text\/)?(x-)?scss$/i, "text/x-scss"],
  47. ["type", /^(text\/)?(x-)?less$/i, "text/x-less"]
  48. ],
  49. template: [
  50. ["lang", /^vue-template$/i, "vue"],
  51. ["lang", /^pug$/i, "pug"],
  52. ["lang", /^handlebars$/i, "handlebars"],
  53. ["type", /^(text\/)?(x-)?pug$/i, "pug"],
  54. ["type", /^text\/x-handlebars-template$/i, "handlebars"],
  55. [null, null, "vue-template"]
  56. ]
  57. };
  58. CodeMirror.defineMode("vue-template", function (config, parserConfig) {
  59. var mustacheOverlay = {
  60. token: function (stream) {
  61. if (stream.match(/^\{\{.*?\}\}/)) return "meta mustache";
  62. while (stream.next() && !stream.match("{{", false)) {}
  63. return null;
  64. }
  65. };
  66. return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), mustacheOverlay);
  67. });
  68. CodeMirror.defineMode("vue", function (config) {
  69. return CodeMirror.getMode(config, {name: "htmlmixed", tags: tagLanguages});
  70. }, "htmlmixed", "xml", "javascript", "coffeescript", "css", "sass", "stylus", "pug", "handlebars");
  71. CodeMirror.defineMIME("script/x-vue", "vue");
  72. CodeMirror.defineMIME("text/x-vue", "vue");
  73. });