summaryrefslogtreecommitdiffstats
path: root/packages/gitbook-markdown/lib/page.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gitbook-markdown/lib/page.js')
-rw-r--r--packages/gitbook-markdown/lib/page.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/packages/gitbook-markdown/lib/page.js b/packages/gitbook-markdown/lib/page.js
new file mode 100644
index 0000000..1adfcf8
--- /dev/null
+++ b/packages/gitbook-markdown/lib/page.js
@@ -0,0 +1,36 @@
+var Q = require('q');
+var _ = require('lodash');
+var kramed = require('kramed');
+var hljs = require('highlight.js');
+
+var lnormalize = require('./utils/lang').normalize;
+
+function parsePage(src) {
+ var options = _.extend({}, kramed.defaults, {
+ // Synchronous highlighting with highlight.js
+ highlight: function (code, lang) {
+ if(!lang) return code;
+
+ // Normalize lang
+ lang = lnormalize(lang);
+
+ try {
+ return hljs.highlight(lang, code).value;
+ } catch(e) { }
+
+ return code;
+ }
+ });
+
+ return {
+ sections: [
+ {
+ type: "normal",
+ content: kramed(src, options)
+ }
+ ]
+ };
+}
+
+// Exports
+module.exports = parsePage;