vue.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://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. ],
  36. style: [
  37. ["lang", /^stylus$/i, "stylus"],
  38. ["lang", /^sass$/i, "sass"],
  39. ["type", /^(text\/)?(x-)?styl(us)?$/i, "stylus"],
  40. ["type", /^text\/sass/i, "sass"]
  41. ],
  42. template: [
  43. ["lang", /^vue-template$/i, "vue"],
  44. ["lang", /^pug$/i, "pug"],
  45. ["lang", /^handlebars$/i, "handlebars"],
  46. ["type", /^(text\/)?(x-)?pug$/i, "pug"],
  47. ["type", /^text\/x-handlebars-template$/i, "handlebars"],
  48. [null, null, "vue-template"]
  49. ]
  50. };
  51. CodeMirror.defineMode("vue-template", function (config, parserConfig) {
  52. var mustacheOverlay = {
  53. token: function (stream) {
  54. if (stream.match(/^\{\{.*?\}\}/)) return "meta mustache";
  55. while (stream.next() && !stream.match("{{", false)) {}
  56. return null;
  57. }
  58. };
  59. return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), mustacheOverlay);
  60. });
  61. CodeMirror.defineMode("vue", function (config) {
  62. return CodeMirror.getMode(config, {name: "htmlmixed", tags: tagLanguages});
  63. }, "htmlmixed", "xml", "javascript", "coffeescript", "css", "sass", "stylus", "pug", "handlebars");
  64. CodeMirror.defineMIME("script/x-vue", "vue");
  65. CodeMirror.defineMIME("text/x-vue", "vue");
  66. });