Permalink
Browse files

Add support for specifying a language for code blocks.

For example, to force Handlebars+HTML highlighting:

```handlebars
{{blah}}
```
  • Loading branch information...
1 parent af3489e commit e61de7322c78480c892237d288b33b067d190300 @rgrove committed Mar 2, 2012
Showing with 11 additions and 4 deletions.
  1. +11 −4 lib/higgins.js
View
@@ -142,27 +142,34 @@ Higgins.prototype = {
// Code blocks.
this._html = this._html.replace(/^[^\S\n]*```[^\S\n]*(.+?)?$\s*^([\s\S]*?)\s*^[^\S\n]*```[^\S\n]*$/gm, function (match, type, content) {
- var className = 'code prettyprint';
+ var classes = ['code'];
// Escape and unindent the content.
content = util.escapeHTML(unindent(content));
switch (type) {
case 'nohighlight': // fallthru
case 'no-highlight':
- className = '';
+ case 'raw':
break;
case 'terminal':
- className = 'terminal';
+ classes.push('terminal');
// Make # and $ prompts non-selectable, for easier copy/paste.
content = content.replace(/^([#\$]\s*)/gm,
'<span class="noselect">$1</span>');
break;
+
+ default:
+ classes.push('prettyprint');
+
+ if (type) {
+ classes.push('lang-' + type);
+ }
}
- return '<pre class="' + className + '">' + content + '</pre>\n';
+ return '<pre class="' + classes.join(' ') + '">' + content + '</pre>\n';
});
// Inline code snippets.

0 comments on commit e61de73

Please sign in to comment.