Skip to content
Snippets Groups Projects
Verified Commit e132da91 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Allow lang selection for code highlighting

Metadata: lang="c"
You can only select lang for whole article for now
parent 56c5e709
No related branches found
No related tags found
No related merge requests found
var marked = require('marked'); var marked = require('marked');
var renderer = new marked.Renderer(); var renderer = new marked.Renderer();
var toURL = require('./transformer-urlizetags.js').toURL; var toURL = require('./transformer-urlizetags.js').toURL;
var highlightjs = require('highlight.js');
renderer.image = function(href, title, text) { renderer.image = function(href, title, text) {
if(process.argv[3] !== "final") { if(process.argv[3] !== "final") {
...@@ -38,9 +39,6 @@ marked.setOptions({ ...@@ -38,9 +39,6 @@ marked.setOptions({
sanitize: false, sanitize: false,
smartLists: true, smartLists: true,
smartypants: false, smartypants: false,
highlight: function (code) {
return require('highlight.js').highlightAuto(code).value;
}
}); });
module.exports = function() { module.exports = function() {
...@@ -48,7 +46,16 @@ module.exports = function() { ...@@ -48,7 +46,16 @@ module.exports = function() {
tr.fancyname = "transformer markdown"; tr.fancyname = "transformer markdown";
tr.forEachPage = function(article, cb) { tr.forEachPage = function(article, cb) {
article.origContent = article.content; article.origContent = article.content;
article.content = marked(article.content); article.content = marked(article.content, {
highlight: function (code) {
var h;
if(highlightjs.getLanguage(article.metadata.lang))
h = highlightjs.highlight(article.metadata.lang, code, true);
else
h = highlightjs.highlightAuto(code);
return h.value;
}
});
cb(); cb();
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment