Commit 1aed42eb69e15b191c5464a58fe7efb06c51ce1c

Golmote 2014-12-14T18:42:43

Add Less language

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