htmlembedded.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/LICENSE
  3. ;(function (mod) {
  4. if (typeof exports == 'object' && typeof module == 'object')
  5. // CommonJS
  6. mod(require('../../lib/codemirror'), require('../htmlmixed/htmlmixed'), require('../../addon/mode/multiplex'))
  7. else if (typeof define == 'function' && define.amd)
  8. // AMD
  9. define(['../../lib/codemirror', '../htmlmixed/htmlmixed', '../../addon/mode/multiplex'], mod)
  10. // Plain browser env
  11. else mod(CodeMirror)
  12. })(function (CodeMirror) {
  13. 'use strict'
  14. CodeMirror.defineMode(
  15. 'htmlembedded',
  16. function (config, parserConfig) {
  17. var closeComment = parserConfig.closeComment || '--%>'
  18. return CodeMirror.multiplexingMode(
  19. CodeMirror.getMode(config, 'htmlmixed'),
  20. {
  21. open: parserConfig.openComment || '<%--',
  22. close: closeComment,
  23. delimStyle: 'comment',
  24. mode: {
  25. token: function (stream) {
  26. stream.skipTo(closeComment) || stream.skipToEnd()
  27. return 'comment'
  28. },
  29. },
  30. },
  31. {
  32. open: parserConfig.open || parserConfig.scriptStartRegex || '<%',
  33. close: parserConfig.close || parserConfig.scriptEndRegex || '%>',
  34. mode: CodeMirror.getMode(config, parserConfig.scriptingModeSpec),
  35. }
  36. )
  37. },
  38. 'htmlmixed'
  39. )
  40. CodeMirror.defineMIME('application/x-ejs', { name: 'htmlembedded', scriptingModeSpec: 'javascript' })
  41. CodeMirror.defineMIME('application/x-aspx', { name: 'htmlembedded', scriptingModeSpec: 'text/x-csharp' })
  42. CodeMirror.defineMIME('application/x-jsp', { name: 'htmlembedded', scriptingModeSpec: 'text/x-java' })
  43. CodeMirror.defineMIME('application/x-erb', { name: 'htmlembedded', scriptingModeSpec: 'ruby' })
  44. })