vue.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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') {
  6. // CommonJS
  7. mod(
  8. require('../../lib/codemirror'),
  9. require('../../addon/mode/overlay'),
  10. require('../xml/xml'),
  11. require('../javascript/javascript'),
  12. require('../coffeescript/coffeescript'),
  13. require('../css/css'),
  14. require('../sass/sass'),
  15. require('../stylus/stylus'),
  16. require('../pug/pug'),
  17. require('../handlebars/handlebars')
  18. )
  19. } else if (typeof define === 'function' && define.amd) {
  20. // AMD
  21. define([
  22. '../../lib/codemirror',
  23. '../../addon/mode/overlay',
  24. '../xml/xml',
  25. '../javascript/javascript',
  26. '../coffeescript/coffeescript',
  27. '../css/css',
  28. '../sass/sass',
  29. '../stylus/stylus',
  30. '../pug/pug',
  31. '../handlebars/handlebars',
  32. ], mod)
  33. } else {
  34. // Plain browser env
  35. mod(CodeMirror)
  36. }
  37. })(function (CodeMirror) {
  38. var tagLanguages = {
  39. script: [
  40. ['lang', /coffee(script)?/, 'coffeescript'],
  41. ['type', /^(?:text|application)\/(?:x-)?coffee(?:script)?$/, 'coffeescript'],
  42. ['lang', /^babel$/, 'javascript'],
  43. ['type', /^text\/babel$/, 'javascript'],
  44. ['type', /^text\/ecmascript-\d+$/, 'javascript'],
  45. ],
  46. style: [
  47. ['lang', /^stylus$/i, 'stylus'],
  48. ['lang', /^sass$/i, 'sass'],
  49. ['lang', /^less$/i, 'text/x-less'],
  50. ['lang', /^scss$/i, 'text/x-scss'],
  51. ['type', /^(text\/)?(x-)?styl(us)?$/i, 'stylus'],
  52. ['type', /^text\/sass/i, 'sass'],
  53. ['type', /^(text\/)?(x-)?scss$/i, 'text/x-scss'],
  54. ['type', /^(text\/)?(x-)?less$/i, 'text/x-less'],
  55. ],
  56. template: [
  57. ['lang', /^vue-template$/i, 'vue'],
  58. ['lang', /^pug$/i, 'pug'],
  59. ['lang', /^handlebars$/i, 'handlebars'],
  60. ['type', /^(text\/)?(x-)?pug$/i, 'pug'],
  61. ['type', /^text\/x-handlebars-template$/i, 'handlebars'],
  62. [null, null, 'vue-template'],
  63. ],
  64. }
  65. CodeMirror.defineMode('vue-template', function (config, parserConfig) {
  66. var mustacheOverlay = {
  67. token: function (stream) {
  68. if (stream.match(/^\{\{.*?\}\}/)) return 'meta mustache'
  69. while (stream.next() && !stream.match('{{', false)) {}
  70. return null
  71. },
  72. }
  73. return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || 'text/html'), mustacheOverlay)
  74. })
  75. CodeMirror.defineMode(
  76. 'vue',
  77. function (config) {
  78. return CodeMirror.getMode(config, { name: 'htmlmixed', tags: tagLanguages })
  79. },
  80. 'htmlmixed',
  81. 'xml',
  82. 'javascript',
  83. 'coffeescript',
  84. 'css',
  85. 'sass',
  86. 'stylus',
  87. 'pug',
  88. 'handlebars'
  89. )
  90. CodeMirror.defineMIME('script/x-vue', 'vue')
  91. CodeMirror.defineMIME('text/x-vue', 'vue')
  92. })