Skip to content

Commit

Permalink
upgrade rainbow for better syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Jul 30, 2012
1 parent 4c00042 commit 4360cbd
Show file tree
Hide file tree
Showing 5 changed files with 934 additions and 11 deletions.
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@
content.innerHTML = marked(trimmed)
</script>

<script src="javascripts/rainbow-custom.min.js"></script>
<script src="javascripts/rainbow.js"></script>
<script src="javascripts/generic.js"></script>
<script src="javascripts/javascript.js"></script>
<script type="text/javascript">

var codeBlocks = document.querySelectorAll('code')
Expand Down
59 changes: 59 additions & 0 deletions javascripts/generic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* Generic language patterns
*
* @author Craig Campbell
* @version 1.0.9
*/
Rainbow.extend([
{
'matches': {
1: {
'name': 'keyword.operator',
'pattern': /\=/g
},
2: {
'name': 'string',
'matches': {
'name': 'constant.character.escape',
'pattern': /\\('|"){1}/g
}
}
},
'pattern': /(\(|\s|\[|\=|:)(('|")([^\\\1]|\\.)*?(\3))/gm
},
{
'name': 'comment',
'pattern': /\/\*[\s\S]*?\*\/|(\/\/|\#)[\s\S]*?$/gm
},
{
'name': 'constant.numeric',
'pattern': /\b(\d+(\.\d+)?(e(\+|\-)?\d+)?(f|d)?|0x[\da-f]+)\b/gi
},
{
'matches': {
1: 'keyword'
},
'pattern': /\b(and|array|as|bool(ean)?|c(atch|har|lass|onst)|d(ef|elete|o(uble)?)|e(cho|lse(if)?|xit|xtends|xcept)|f(inally|loat|or(each)?|unction)|global|if|import|int(eger)?|long|new|object|or|pr(int|ivate|otected)|public|return|self|st(ring|ruct|atic)|switch|th(en|is|row)|try|(un)?signed|var|void|while)(?=\(|\b)/gi
},
{
'name': 'constant.language',
'pattern': /true|false|null/g
},
{
'name': 'keyword.operator',
'pattern': /\+|\!|\-|&(gt|lt|amp);|\||\*|\=/g
},
{
'matches': {
1: 'function.call'
},
'pattern': /(\w+?)(?=\()/g
},
{
'matches': {
1: 'storage.function',
2: 'entity.name.function'
},
'pattern': /(function)\s(.*?)(?=\()/g
}
]);
99 changes: 99 additions & 0 deletions javascripts/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* Javascript patterns
*
* @author Craig Campbell
* @version 1.0.6
*/
Rainbow.extend('javascript', [

/**
* matches $. or $(
*/
{
'name': 'selector',
'pattern': /(\s|^)\$(?=\.|\()/g
},
{
'name': 'support',
'pattern': /\b(window|document)\b/g
},
{
'matches': {
1: 'support.property'
},
'pattern': /\.(length|node(Name|Value))\b/g
},
{
'matches': {
1: 'support.function'
},
'pattern': /(setTimeout|setInterval)(?=\()/g

},
{
'matches': {
1: 'support.method'
},
'pattern': /\.(getAttribute|push|getElementById|getElementsByClassName|log|setTimeout|setInterval)(?=\()/g
},
{
'matches': {
1: 'support.tag.script',
2: [
{
'name': 'string',
'pattern': /('|")(.*?)(\1)/g
},
{
'name': 'entity.tag.script',
'pattern': /(\w+)/g
}
],
3: 'support.tag.script'
},
'pattern': /(&lt;\/?)(script.*?)(&gt;)/g
},

/**
* matches any escaped characters inside of a js regex pattern
*
* @see https://github.com/ccampbell/rainbow/issues/22
*
* this was causing single line comments to fail so it now makes sure
* the opening / is not directly followed by a *
*
* @todo check that there is valid regex in match group 1
*/
{
'name': 'string.regexp',
'matches': {
1: 'string.regexp.open',
2: {
'name': 'constant.regexp.escape',
'pattern': /\\(.){1}/g
},
3: 'string.regexp.close',
4: 'string.regexp.modifier'
},
'pattern': /(\/)(?!\*)(.+)(\/)([igm]{0,3})/g
},

/**
* matches runtime function declarations
*/
{
'matches': {
1: 'storage',
3: 'entity.function'
},
'pattern': /(var)?(\s|^)(.*)(?=\s?=\s?function\()/g
},

/**
* matches any function call in the style functionName: function()
*/
{
'name': 'entity.function',
'pattern': /(\w+)(?=:\s{0,}function)/g
}
]);
10 changes: 0 additions & 10 deletions javascripts/rainbow-custom.min.js

This file was deleted.

Loading

0 comments on commit 4360cbd

Please sign in to comment.