vue.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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("../jade/jade"),
  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. "../jade/jade",
  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", /^jade$/i, "jade"],
  45. ["lang", /^handlebars$/i, "handlebars"],
  46. ["type", /^(text\/)?(x-)?jade$/i, "jade"],
  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", "jade", "handlebars");
  64. CodeMirror.defineMIME("script/x-vue", "vue");
  65. });