Merge pull request #489 from vkbansal/stylus Initial definition for stylus
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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
diff --git a/components.js b/components.js
index 0ea2bde..81905d0 100644
--- a/components.js
+++ b/components.js
@@ -310,6 +310,10 @@ var components = {
"rest": {
"title": "reST (reStructuredText)",
"owner": "Golmote"
+ },
+ "stylus" : {
+ "title": "Stylus",
+ "owner": "vkbansal"
}
},
"plugins": {
diff --git a/components/prism-stylus.js b/components/prism-stylus.js
new file mode 100644
index 0000000..fd04d78
--- /dev/null
+++ b/components/prism-stylus.js
@@ -0,0 +1,61 @@
+Prism.languages.stylus = {
+ 'comment': {
+ pattern: /(^|[^\\])(\/\*[\w\W]*?\*\/|\/\/.*?(\r?\n|$))/g,
+ lookbehind: true
+ },
+ 'keyword': /(px|r?em|ex|ch|vw|vh|vmin|vmax|deg|grad|rad|turn|m?s|k?Hz|dpi|dppx|dpcm)\b|\b(is|defined|not|isnt|and|or|unless|for|in)\b/g,
+ 'atrule': /@[\w-]+(?=\s+\S+)/gi,
+ 'url': /url\((["']?).*?\1\)/gi,
+ 'variable': /^\s*([\w-]+)(?=\s*[+-\\]?=)/gm,
+ 'string': /("|')(\\\n|\\?.)*?\1/g,
+ 'important': /\B!important\b/gi,
+ 'hexcode': /#[\da-f]{3,6}/gi,
+ 'entity': /\\[\da-f]{1,8}/gi,
+ 'number': /\d+\.?\d*%?/g,
+ 'selector': [
+ {
+ pattern: /::?(after|before|first-letter|first-line|selection)/g,
+ alias: 'pseudo-element'
+ },{
+ pattern: /:(?:active|checked|disabled|empty|enabled|first-child|first-of-type|focus|hover|in-range|invalid|lang|last-child|last-of-type|link|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|only-of-type|only-child|optional|out-of-range|read-only|read-write|required|root|target|valid|visited)(?:\(.*\))?/g,
+ alias:'pseudo-class'
+ },{
+ pattern: /\[[\w-]+?\s*[*~$^|=]?(?:=\s*\S+)?\]/g,
+ inside: {
+ "attr-name":
+ {
+ pattern: /(\[)([\w-]+)(?=\s*[*~$^|=]{0,2})/g,
+ lookbehind: true
+ },
+ "punctuation": /\[|\]/g,
+ "operator": /[*~$^|=]/g,
+ "attr-value": {
+ pattern: /\S+/
+ },
+ },
+ alias: 'attr'
+ },
+ {
+ pattern: /\.[a-z-]+/i,
+ alias: 'class'
+ },
+ {
+ pattern: /#[a-z-]+/i,
+ alias: 'id'
+ },
+ {
+ pattern: /\b(html|head|title|base|link|meta|style|script|noscript|template|body|section|nav|article|aside|h[1-6]|header|footer|address|main|p|hr|pre|blockquote|ol|ul|li|dl|dt|dd|figure|figcaption|div|a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|dbo|span|br|wbr|ins|del|image|iframe|embed|object|param|video|audio|source|track|canvas|map|area|sv|math|table|caption|colgroup|col|tbody|thead|tfoot|tr|td|th|form|fieldset|legeng|label|input|button|select|datalist|optgroup|option|textarea|keygen|output|progress|meter|details|summary|menuitem|menu)\b/g,
+ alias: 'tag'
+ },
+ ],
+ 'property': [
+ /^\s*([a-z-]+)(?=\s+[\w\W]+|\s*:)(?!\s*\{|\r?\n)/mig,
+ {
+ pattern: /(\(\s*)([a-z-]+)(?=\s*:)/ig,
+ lookbehind: true
+ }
+ ],
+ 'function': /[-a-z0-9]+(?=\()/ig,
+ 'punctuation': /[\{\};:]/g,
+ 'operator': /[-+]{1,2}|!|<=?|>=?|={1,3}|&{1,2}|\|?\||\?|\*|\/|~|\^|%/g
+}
diff --git a/components/prism-stylus.min.js b/components/prism-stylus.min.js
new file mode 100644
index 0000000..ed5c27a
--- /dev/null
+++ b/components/prism-stylus.min.js
@@ -0,0 +1 @@
+Prism.languages.stylus={comment:{pattern:/(^|[^\\])(\/\*[\w\W]*?\*\/|\/\/.*?(\r?\n|$))/g,lookbehind:!0},keyword:/(px|r?em|ex|ch|vw|vh|vmin|vmax|deg|grad|rad|turn|m?s|k?Hz|dpi|dppx|dpcm)\b|\b(is|defined|not|isnt|and|or|unless|for|in)\b/g,atrule:/@[\w-]+(?=\s+\S+)/gi,url:/url\((["']?).*?\1\)/gi,variable:/^\s*([\w-]+)(?=\s*[+-\\]?=)/gm,string:/("|')(\\\n|\\?.)*?\1/g,important:/\B!important\b/gi,hexcode:/#[\da-f]{3,6}/gi,entity:/\\[\da-f]{1,8}/gi,number:/\d+\.?\d*%?/g,selector:[{pattern:/::?(after|before|first-letter|first-line|selection)/g,alias:"pseudo-element"},{pattern:/:(?:active|checked|disabled|empty|enabled|first-child|first-of-type|focus|hover|in-range|invalid|lang|last-child|last-of-type|link|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|only-of-type|only-child|optional|out-of-range|read-only|read-write|required|root|target|valid|visited)(?:\(.*\))?/g,alias:"pseudo-class"},{pattern:/\[[\w-]+?\s*[*~$^|=]?(?:=\s*\S+)?\]/g,inside:{"attr-name":{pattern:/(\[)([\w-]+)(?=\s*[*~$^|=]{0,2})/g,lookbehind:!0},punctuation:/\[|\]/g,operator:/[*~$^|=]/g,"attr-value":{pattern:/\S+/}},alias:"attr"},{pattern:/\.[a-z-]+/i,alias:"class"},{pattern:/#[a-z-]+/i,alias:"id"},{pattern:/\b(html|head|title|base|link|meta|style|script|noscript|template|body|section|nav|article|aside|h[1-6]|header|footer|address|main|p|hr|pre|blockquote|ol|ul|li|dl|dt|dd|figure|figcaption|div|a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|dbo|span|br|wbr|ins|del|image|iframe|embed|object|param|video|audio|source|track|canvas|map|area|sv|math|table|caption|colgroup|col|tbody|thead|tfoot|tr|td|th|form|fieldset|legeng|label|input|button|select|datalist|optgroup|option|textarea|keygen|output|progress|meter|details|summary|menuitem|menu)\b/g,alias:"tag"}],property:[/^\s*([a-z-]+)(?=\s+[\w\W]+|\s*:)(?!\s*\{|\r?\n)/gim,{pattern:/(\(\s*)([a-z-]+)(?=\s*:)/gi,lookbehind:!0}],"function":/[-a-z0-9]+(?=\()/gi,punctuation:/[\{\};:]/g,operator:/[-+]{1,2}|!|<=?|>=?|={1,3}|&{1,2}|\|?\||\?|\*|\/|~|\^|%/g};
\ No newline at end of file
diff --git a/examples/prism-stylus.html b/examples/prism-stylus.html
new file mode 100644
index 0000000..f910de0
--- /dev/null
+++ b/examples/prism-stylus.html
@@ -0,0 +1,89 @@
+<h1>Stylus</h1>
+<p>To use this language, use the class "language-stylus".</p>
+
+<h2>Full Example</h2>
+<pre><code>/*!
+ * Adds the given numbers together.
+ */
+/*
+ * Adds the given numbers together.
+ */
+// I'm a comment!
+body {
+ font: 12px Helvetica, Arial, sans-serif;
+}
+a.button {
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+}
+
+body
+ font: 12px Helvetica, Arial, sans-serif;
+
+a.button:after
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+
+body
+ font: 12px Helvetica, Arial, sans-serif
+
+a.link > button#test, input[type=button], a:after()
+ -webkit-border-radius: 5px
+ -moz-border-radius: 5px
+ border-radius: 5px
+
+font-size = 14px
+font = font-size "Lucida Grande", Arial
+
+body {
+ padding: 50px;
+ font: 14px/1.4 fonts;
+}
+
+border-radius()
+ -webkit-border-radius arguments
+ -moz-border-radius arguments
+ border-radius arguments
+
+body
+ font 12px Helvetica, Arial, sans-serif
+
+a.button
+ border-radius(5px)
+
+@media (max-width: 30em) {
+ body {
+ color: #fff;
+ }
+}
+
+@media (max-width: 500px)
+ .foo
+ color: #000
+
+ @media (min-width: 100px), (min-height: 200px)
+ .foo
+ color: #100
+
+sum(nums...)
+ sum = 0
+ sum += n for n in nums
+
+sum(1 2 3 4)
+// => 10</code></pre>
+
+<h2>Known failures</h2>
+<p>There are certain edge cases where Prism will fail.
+ There are always such cases in every regex-based syntax highlighter.
+ However, Prism dares to be open and honest about them.
+ If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
+</p>
+
+<h3>Incorrect highlighting when tags like literals are used inside a string</h3>
+<pre><code>add(a, b)
+ if a is a 'unit' and b is a 'unit'
+ a + b
+ else
+ (error 'a and b must be units!')</code></pre>