Permalink
Browse files

Refactor of `hl` extension

  • Loading branch information...
1 parent 3a24490 commit 2e5cca2f48b802609771246cbcba94c290fe0010 @arikon arikon committed Oct 11, 2012
View
@@ -1 +0,0 @@
-module.exports = require('./hljs');
@@ -0,0 +1,24 @@
+var U = require('./util');
+
+exports.astToBemjson = function(c, p) {
+
+ var lang = U.translateAlias(p);
+
+ return {
+ block: 'highlight',
+ mods: {'render': 'client'},
+ lang: lang,
+ content: c
+ };
+
+};
+
+exports.astToHtml = function(c, p) {
+
+ var lang = U.translateAlias(p);
+
+ return '<pre class="highlight highlight_render_client"><code class="highlight__code ' + lang + '">' +
+ c +
+ '</code></pre>';
+
+};
@@ -0,0 +1,26 @@
+var HL = require('highlight.js'),
+ U = require('./util');
+
+exports.astToBemjson = function(c, p) {
+
+ var lang = U.translateAlias(p),
+ res = p? HL.highlight(lang, c) : HL.highlightAuto(c);
+
+ return {
+ block: 'highlight',
+ lang: res.language,
+ content: res.value
+ };
+
+};
+
+exports.astToHtml = function(c, p) {
+
+ var lang = U.translateAlias(p),
+ res = p? HL.highlight(lang, c) : HL.highlightAuto(c);
+
+ return '<pre class="highlight"><code class="highlight__code ' + res.language + '">' +
+ res.value +
+ '</code></pre>';
+
+};
View
@@ -0,0 +1,25 @@
+var HL_RENDER_DEFAULT = 'server',
+ HL_RENDER = process.env.SHMAKOWIKI_EXT_HL_RENDER || HL_RENDER_DEFAULT;
+
+if (!~['server', 'client', 'no-render'].indexOf(HL_RENDER)) {
+ HL_RENDER = HL_RENDER_DEFAULT;
+}
+
+var ext = {};
+switch (HL_RENDER) {
+
+ case 'server':
+ ext = require('./hljs-server');
+ break;
+
+ case 'client':
+ ext = require('./hljs-client');
+ break;
+
+ case 'no-render':
+ ext = require('./no-render');
+ break;
+
+}
+
+module.exports = ext;
@@ -1,4 +1,4 @@
-var U = require('../utils');
+var U = require('../../utils');
exports.astToBemjson = function(c, p) {
View
@@ -0,0 +1,23 @@
+exports.translateAlias = function(alias) {
+
+ var lang = alias;
+
+ switch (alias) {
+
+ case 'js':
+ lang = 'javascript';
+ break;
+
+ case 'patch':
+ lang = 'diff';
+ break;
+
+ case 'md':
+ lang = 'markdown';
+ break;
+
+ }
+
+ return lang;
+
+};
View
@@ -1,49 +0,0 @@
-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: 'highlight',
- lang: res.language,
- content: res.value
- };
-
-};
-
-exports.astToHtml = function(c, p) {
-
- var lang = translateAlias(p),
- res = p? HL.highlight(lang, c) : HL.highlightAuto(lang);
-
- return '<pre class="highlight"><code class="highlight__code ' + res.language + '">' +
- res.value +
- '</code></pre>';
-
-};
-
-function translateAlias(alias) {
-
- var lang = alias;
-
- switch (alias) {
-
- case 'js':
- lang = 'javascript';
- break;
-
- case 'patch':
- lang = 'diff';
- break;
-
- case 'md':
- lang = 'markdown';
- break;
-
- }
-
- return lang;
-
-}

0 comments on commit 2e5cca2

Please sign in to comment.