prism-qml.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. (function (Prism) {
  2. var jsString = /"(?:\\.|[^\\"\r\n])*"|'(?:\\.|[^\\'\r\n])*'/.source;
  3. var jsComment = /\/\/.*(?!.)|\/\*(?:[^*]|\*(?!\/))*\*\//.source;
  4. var jsExpr = /(?:[^\\()[\]{}"'/]|<string>|\/(?![*/])|<comment>|\(<expr>*\)|\[<expr>*\]|\{<expr>*\}|\\[\s\S])/
  5. .source.replace(/<string>/g, function () { return jsString; }).replace(/<comment>/g, function () { return jsComment; });
  6. // the pattern will blow up, so only a few iterations
  7. for (var i = 0; i < 2; i++) {
  8. jsExpr = jsExpr.replace(/<expr>/g, function () { return jsExpr; });
  9. }
  10. jsExpr = jsExpr.replace(/<expr>/g, '[^\\s\\S]');
  11. Prism.languages.qml = {
  12. 'comment': {
  13. pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
  14. greedy: true
  15. },
  16. 'javascript-function': {
  17. pattern: RegExp(/((?:^|;)[ \t]*)function\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*\(<js>*\)\s*\{<js>*\}/.source.replace(/<js>/g, function () { return jsExpr; }), 'm'),
  18. lookbehind: true,
  19. greedy: true,
  20. alias: 'language-javascript',
  21. inside: Prism.languages.javascript
  22. },
  23. 'class-name': {
  24. pattern: /((?:^|[:;])[ \t]*)(?!\d)\w+(?=[ \t]*\{|[ \t]+on\b)/m,
  25. lookbehind: true
  26. },
  27. 'property': [
  28. {
  29. pattern: /((?:^|[;{])[ \t]*)(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
  30. lookbehind: true
  31. },
  32. {
  33. pattern: /((?:^|[;{])[ \t]*)property[ \t]+(?!\d)\w+(?:\.\w+)*[ \t]+(?!\d)\w+(?:\.\w+)*(?=[ \t]*:)/m,
  34. lookbehind: true,
  35. inside: {
  36. 'keyword': /^property/,
  37. 'property': /\w+(?:\.\w+)*/
  38. }
  39. }
  40. ],
  41. 'javascript-expression': {
  42. pattern: RegExp(/(:[ \t]*)(?![\s;}[])(?:(?!$|[;}])<js>)+/.source.replace(/<js>/g, function () { return jsExpr; }), 'm'),
  43. lookbehind: true,
  44. greedy: true,
  45. alias: 'language-javascript',
  46. inside: Prism.languages.javascript
  47. },
  48. 'string': {
  49. pattern: /"(?:\\.|[^\\"\r\n])*"/,
  50. greedy: true
  51. },
  52. 'keyword': /\b(?:as|import|on)\b/,
  53. 'punctuation': /[{}[\]:;,]/
  54. };
  55. }(Prism));