Permalink
Browse files

Use highlight.js as default code highlighter

  • Loading branch information...
arikon committed Oct 6, 2012
1 parent 45b840b commit 7b38cec5e71b50926c2bbf979f74c1c4893fed85
Showing with 33 additions and 8 deletions.
  1. +1 −1 lib/extensions/hl.js
  2. +29 −5 lib/extensions/hljs.js
  3. +3 −2 package.json
View
@@ -1 +1 @@
-module.exports = require('./ohl');
+module.exports = require('./hljs');
View
@@ -1,15 +1,39 @@
-var utils = require('../utils');
+var HL = require('highlight.js');
exports.astToBemjson = function(c, p) {
+
+ var lang = translateAlias(p),
+ res = p? HL.highlight(lang, c) : HL.highlightAuto(lang);
+
return {
block: 'b-code',
- cls: p,
- content: utils.htmlEscape(c)
+ lang: lang,
+ content: res.value
};
+
};
exports.astToHtml = function(c, p) {
- return '<pre><code class="'+ p + '">' +
- utils.htmlEscape(c) +
+
+ var lang = translateAlias(p),
+ res = p? HL.highlight(lang, c) : HL.highlightAuto(lang);
+
+ return '<pre><code class="b-code b-code_lang_'+ lang + '">' +
+ res.value +
'</code></pre>';
+
};
+
+function translateAlias(alias) {
+
+ var lang = alias;
+
+ switch (alias) {
+ case 'js':
+ lang = 'javascript';
+ break;
+ }
+
+ return lang;
+
+}
View
@@ -20,7 +20,8 @@
"ometajs": "2.1.x",
"ometa-highlighter": "~ 0.2.3",
"q": "0.7.x",
- "coa": "0.3.x"
+ "coa": "0.3.x",
+ "highlight.js": "~7.2.0"
},
"engines": {
"node": ">=0.4.0"
@@ -32,4 +33,4 @@
],
"devDependencies": {},
"optionalDependencies": {}
-}
+}

0 comments on commit 7b38cec

Please sign in to comment.