properties.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. CodeMirror.defineMode("properties", function() {
  2. return {
  3. token: function(stream, state) {
  4. var sol = stream.sol() || state.afterSection;
  5. var eol = stream.eol();
  6. state.afterSection = false;
  7. if (sol) {
  8. if (state.nextMultiline) {
  9. state.inMultiline = true;
  10. state.nextMultiline = false;
  11. } else {
  12. state.position = "def";
  13. }
  14. }
  15. if (eol && ! state.nextMultiline) {
  16. state.inMultiline = false;
  17. state.position = "def";
  18. }
  19. if (sol) {
  20. while(stream.eatSpace());
  21. }
  22. var ch = stream.next();
  23. if (sol && (ch === "#" || ch === "!" || ch === ";")) {
  24. state.position = "comment";
  25. stream.skipToEnd();
  26. return "comment";
  27. } else if (sol && ch === "[") {
  28. state.afterSection = true;
  29. stream.skipTo("]"); stream.eat("]");
  30. return "header";
  31. } else if (ch === "=" || ch === ":") {
  32. state.position = "quote";
  33. return null;
  34. } else if (ch === "\\" && state.position === "quote") {
  35. if (stream.next() !== "u") { // u = Unicode sequence \u1234
  36. // Multiline value
  37. state.nextMultiline = true;
  38. }
  39. }
  40. return state.position;
  41. },
  42. startState: function() {
  43. return {
  44. position : "def", // Current position, "def", "quote" or "comment"
  45. nextMultiline : false, // Is the next line multiline value
  46. inMultiline : false, // Is the current line a multiline value
  47. afterSection : false // Did we just open a section
  48. };
  49. }
  50. };
  51. });
  52. CodeMirror.defineMIME("text/x-properties", "properties");
  53. CodeMirror.defineMIME("text/x-ini", "properties");