You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

7 months ago
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: https://codemirror.net/5/LICENSE
  3. (function (mod) {
  4. if (typeof exports == "object" && typeof module == "object") // CommonJS
  5. mod(require("../../lib/codemirror"), require("../haskell/haskell"))
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror", "../haskell/haskell"], mod)
  8. else // Plain browser env
  9. mod(CodeMirror)
  10. })(function (CodeMirror) {
  11. "use strict"
  12. CodeMirror.defineMode("haskell-literate", function (config, parserConfig) {
  13. var baseMode = CodeMirror.getMode(config, (parserConfig && parserConfig.base) || "haskell")
  14. return {
  15. startState: function () {
  16. return {
  17. inCode: false,
  18. baseState: CodeMirror.startState(baseMode)
  19. }
  20. },
  21. token: function (stream, state) {
  22. if (stream.sol()) {
  23. if (state.inCode = stream.eat(">"))
  24. return "meta"
  25. }
  26. if (state.inCode) {
  27. return baseMode.token(stream, state.baseState)
  28. } else {
  29. stream.skipToEnd()
  30. return "comment"
  31. }
  32. },
  33. innerMode: function (state) {
  34. return state.inCode ? {state: state.baseState, mode: baseMode} : null
  35. }
  36. }
  37. }, "haskell")
  38. CodeMirror.defineMIME("text/x-literate-haskell", "haskell-literate")
  39. });