Add Less language
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
diff --git a/components.js b/components.js
index 3c928fe..118b762 100644
--- a/components.js
+++ b/components.js
@@ -210,6 +210,11 @@ var components = {
"matlab": {
"title": "MATLAB",
"owner": "Golmote"
+ },
+ "less": {
+ "title": "Less",
+ "require": "css",
+ "owner": "Golmote"
}
},
"plugins": {
diff --git a/components/prism-less.js b/components/prism-less.js
new file mode 100644
index 0000000..7953b39
--- /dev/null
+++ b/components/prism-less.js
@@ -0,0 +1,64 @@
+/* FIXME :
+ :extend() is not handled specifically : its highlighting is buggy.
+ Mixin usage must be inside a ruleset to be highlighted.
+ At-rules (e.g. import) containing interpolations are buggy.
+ Detached rulesets are highlighted as at-rules.
+ A comment before a mixin usage prevents the latter to be properly highlighted.
+ */
+
+Prism.languages.less = Prism.languages.extend('css', {
+ 'comment': [
+ /\/\*[\w\W]*?\*\//g,
+ {
+ pattern: /(^|[^\\])\/\/.+/g,
+ lookbehind: true
+ }
+ ],
+ 'atrule': {
+ pattern: /@[\w-]+?(?:\([^{}]+\)|[^(){};])*?(?=\s*\{)/gi,
+ inside: {
+ 'punctuation': /[:()]/g
+ }
+ },
+ // selectors and mixins are considered the same
+ 'selector': {
+ //pattern: /(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|[^{};@])*?(?:\([^)]*\))?(?=\s*\{)/g,
+ pattern: /(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\([^{}]*\)|[^{};@])*?(?=\s*\{)/g,
+ inside: {
+ // mixin parameters
+ 'variable': /@+[\w-]+/
+ }
+ },
+
+ 'property': /(\b|\B)(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/ig,
+ 'punctuation': /[{}();:,]/g,
+ 'operator': /[+\-*\/]/
+});
+
+// Invert function and punctuation positions
+Prism.languages.insertBefore('less', 'punctuation', {
+ 'function': Prism.languages.less.function
+});
+
+Prism.languages.insertBefore('less', 'property', {
+ 'variable': [
+ // declaration
+ {
+ pattern: /@[\w-]+\s*:/,
+ inside: {
+ "punctuation": /:/
+ }
+ },
+
+ // usage
+ /@@?[\w-]+/
+ ]
+});
+
+Prism.languages.insertBefore('less', 'property', {
+ 'mixin-usage': {
+ pattern: /([{;]\s*)[.#](?!\d)[\w-]+.*?(?=[(;])/,
+ lookbehind: true,
+ alias: 'function'
+ }
+});
\ No newline at end of file
diff --git a/components/prism-less.min.js b/components/prism-less.min.js
new file mode 100644
index 0000000..8f4d240
--- /dev/null
+++ b/components/prism-less.min.js
@@ -0,0 +1 @@
+Prism.languages.less=Prism.languages.extend("css",{comment:[/\/\*[\w\W]*?\*\//g,{pattern:/(^|[^\\])\/\/.+/g,lookbehind:!0}],atrule:{pattern:/@[\w-]+?(?:\([^{}]+\)|[^(){};])*?(?=\s*\{)/gi,inside:{punctuation:/[:()]/g}},selector:{pattern:/(?:@\{[\w-]+\}|[^{};\s@])(?:@\{[\w-]+\}|\([^{}]*\)|[^{};@])*?(?=\s*\{)/g,inside:{variable:/@+[\w-]+/}},property:/(\b|\B)(?:@\{[\w-]+\}|[\w-])+(?:\+_?)?(?=\s*:)/gi,punctuation:/[{}();:,]/g,operator:/[+\-*\/]/}),Prism.languages.insertBefore("less","punctuation",{"function":Prism.languages.less.function}),Prism.languages.insertBefore("less","property",{variable:[{pattern:/@[\w-]+\s*:/,inside:{punctuation:/:/}},/@@?[\w-]+/]}),Prism.languages.insertBefore("less","property",{"mixin-usage":{pattern:/([{;]\s*)[.#](?!\d)[\w-]+.*?(?=[(;])/,lookbehind:!0,alias:"function"}});
\ No newline at end of file