Skip to content

Instantly share code, notes, and snippets.

@icai
Created January 28, 2014 16:11
Show Gist options
  • Save icai/8670686 to your computer and use it in GitHub Desktop.
Save icai/8670686 to your computer and use it in GitHub Desktop.
Expressjs Highlight style
/* code */
p code {
background: #efefef;
border: 1px solid #eaeaea;
font-family: monaco, monospace;
font-size: .75em;
padding: 2px 8px;
-webkit-border-radius: 3px;
}
pre {
color: #353535;
font-size: 14px;
line-height: 1.4;
margin: 20px 0;
padding: 20px;
background: white;
border: 1px solid #e7e7e7;
border-bottom: 1px solid #ddd;
-webkit-box-shadow: 0 1px 3px 0 #eee;
-webkit-border-radius: 3px;
}
pre code {
font-family: monaco, monospace;
font-size: .8em;
}
code .comment { color: #888 }
code .init { color: #2F6FAD }
code .string { color: #5890AD }
code .keyword { color: #8A6343 }
code .number { color: #2F6FAD }
/**
* Highlight the given `js`.
*/
function highlight(js) {
return js
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
.replace(/('.*?')/gm, '<span class="string">$1</span>')
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
.replace(/(\d+)/gm, '<span class="number">$1</span>')
.replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
.replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment