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.

78 lines
2.1 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"));
  6. else if (typeof define == "function" && define.amd) // AMD
  7. define(["../../lib/codemirror"], mod);
  8. else // Plain browser env
  9. mod(CodeMirror);
  10. })(function(CodeMirror) {
  11. "use strict";
  12. CodeMirror.defineMode("properties", function() {
  13. return {
  14. token: function(stream, state) {
  15. var sol = stream.sol() || state.afterSection;
  16. var eol = stream.eol();
  17. state.afterSection = false;
  18. if (sol) {
  19. if (state.nextMultiline) {
  20. state.inMultiline = true;
  21. state.nextMultiline = false;
  22. } else {
  23. state.position = "def";
  24. }
  25. }
  26. if (eol && ! state.nextMultiline) {
  27. state.inMultiline = false;
  28. state.position = "def";
  29. }
  30. if (sol) {
  31. while(stream.eatSpace()) {}
  32. }
  33. var ch = stream.next();
  34. if (sol && (ch === "#" || ch === "!" || ch === ";")) {
  35. state.position = "comment";
  36. stream.skipToEnd();
  37. return "comment";
  38. } else if (sol && ch === "[") {
  39. state.afterSection = true;
  40. stream.skipTo("]"); stream.eat("]");
  41. return "header";
  42. } else if (ch === "=" || ch === ":") {
  43. state.position = "quote";
  44. return null;
  45. } else if (ch === "\\" && state.position === "quote") {
  46. if (stream.eol()) { // end of line?
  47. // Multiline value
  48. state.nextMultiline = true;
  49. }
  50. }
  51. return state.position;
  52. },
  53. startState: function() {
  54. return {
  55. position : "def", // Current position, "def", "quote" or "comment"
  56. nextMultiline : false, // Is the next line multiline value
  57. inMultiline : false, // Is the current line a multiline value
  58. afterSection : false // Did we just open a section
  59. };
  60. }
  61. };
  62. });
  63. CodeMirror.defineMIME("text/x-properties", "properties");
  64. CodeMirror.defineMIME("text/x-ini", "properties");
  65. });