Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Oct 21, 2013
0 parents commit ce1ed94
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
tmp
*.sublime-*
22 changes: 22 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2010-2013 Alexis Sellier

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# hiless [![NPM version](https://badge.fury.io/js/hiless.png)](http://badge.fury.io/js/hiless)

> LESS Syntax Highlighter

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style.


## Author

**Alexis Sellier**

+ [github/cloudhead](https://github.com/cloudhead)


## License
Copyright (c) 2010-2013 Alexis Sellier
Licensed under the MIT license.
90 changes: 90 additions & 0 deletions hiless.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**!
* hiless - LESS Syntax Highlighter
* Copyright (c) 2010 Alexis Sellier

This comment has been minimized.

Copy link
@zlatanvasovic

zlatanvasovic Jan 4, 2014

2010 or 2013?

This comment has been minimized.

Copy link
@jonschlinkert

jonschlinkert Jan 4, 2014

Author Contributor

That's correct. It was published in 2010 by @cloudhead. The code was just moved to its own repo.

This comment has been minimized.

Copy link
@zlatanvasovic

zlatanvasovic Jan 4, 2014

ok :)

*/

(function () {

// All elements which match this will be syntax highlighted.
var selector = 'code';

if (!Object.keys || ![].forEach) {
return
}


/**
* Syntax definition
* The key becomes the class name of the <span> around the matched block of code.
*/
var syntax = {
'string' : /("(?:(?!")[^\\]|\\.)*"|'(?:(?!')[^\\]|\\.)*')/g,
'comment' : /(\/\*(?:[^*]|\*+[^\/*])*\*+\/|\/\/[^\n]*)/mg,
'keyword' : /\b(when)\b/g,
'color' : /(#[a-fA-F0-9]{8}|#[a-fA-F0-9]{6}|#[a-fA-F0-9]{3})(\b|$)/mg, //(?=[^\{\}]*[\};])
'nth' : /(\([n0-9+-]+\))(?=[^\{\}]*\{)/g,
'number' : /\b((?:-?\d*\.?\d+)(?:px|%|em|pc|ex|in|deg|s|ms|pt|cm|mm)?)/g,
'class' : /([\.:]([\w-]+|@\{[\w-]+\}))(?=[^\{\};]*\{)/mg,
'variable' : /(@@?-?[-a-z_0-9]+\s*)/g,
'attribute': /(\*?-?[-a-z_0-9]+\s*)(?=:[^\{\};]*[\};])/mg,
'selector' : /(\[[a-z]+)/g,
'id' : /(#[\w-]+)(?=[^\{\}]*\{)/mg,
'mixin' : /([#\.][\w-]+)(?=[^;\{\}]*[;\}])/g,
'element' : /\b([a-z]+[0-9]?)\b(?=[^\{\}\);]*\{)/mg,
'special' : /(! *important)\b/g,
};


var nodes = document.querySelectorAll(selector);
var table = {};

for (var i = 0, children; i < nodes.length; i++) {
children = nodes[i].childNodes;

for (var j = 0, str; j < children.length; j++) {
code = children[j];

if (code.length >= 0) { // It's a text node
// Don't highlight command-line snippets
if (!/^\$/.test(code.nodeValue.trim()) && !/^var /.test(code.nodeValue.trim())) {
Object.keys(syntax).forEach(function (s) {
code.nodeValue = code.nodeValue.replace(syntax[s], function (_, m) {
return '\u00ab' + encode(s) + '\u00b7' + encode(m) + '\u00b7' + encode(s) + '\u00bb';
});
});
}
}
}
}
for (var i = 0; i < nodes.length; i++) {
nodes[i].innerHTML = nodes[i].innerHTML.replace(/\u00ab(.+?)\u00b7(.+?)\u00b7\1\u00bb/g, function (_, name, value) {
value = value.replace(/\u00ab.+?\u00b7/g, '').replace(/\u00b7.+?\u00bb/g, '');
return '<span class="' + decode(name) + '">' + decode(value) + '</span>';
});
}

// Encode ASCII characters to, and from Braille
function encode(str, encoded) {
table[encoded = str.split('').map(function (s) {
if (s.charCodeAt(0) > 127) {
return s;
}
return String.fromCharCode(s.charCodeAt(0) + 0x2800);
}).join('')] = str;
return encoded;
}

function decode(str) {
if (str in table) {
return table[str];
} else {
return str.trim().split('').map(function (s) {
if (s.charCodeAt(0) - 0x2800 > 127) {
return s;
}
return String.fromCharCode(s.charCodeAt(0) - 0x2800);
}).join('');
}
}

})();
37 changes: 37 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "hiless",
"description": "The LESS syntax highlighter.",
"version": "0.1.0",
"homepage": "https://github.com/less/hiless",
"author": {
"name": "Alexis Sellier",
"url": "https://github.com/cloudhead"
},
"contributors": [
{
"name": "Jon Schlinkert",
"url": "https://github.com/jonschlinkert"
}
],
"repository": {
"type": "git",
"url": "https://github.com/less/hiless.git"
},
"bugs": {
"url": "https://github.com/less/hiless/issues"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/less/hiless/blob/master/LICENSE-MIT"
}
],
"keywords": [
"less",
"css",
"less.js",
"highlighter",
"syntax highlighter",
"code highlighter"
]
}

0 comments on commit ce1ed94

Please sign in to comment.