Separate files for syntax highlighters

This commit is contained in:
Zach Leatherman 2018-01-27 23:50:07 -06:00
parent d7e2c4e525
commit dfe49017c8
4 changed files with 30 additions and 30 deletions

View File

@ -2,7 +2,7 @@ const { DateTime } = require("luxon");
const metadata = require("./_data/metadata.json");
const absoluteUrl = require("./_src/absoluteUrl");
const HtmlToAbsoluteUrls = require("./_src/HtmlToAbsoluteUrls");
const highlighters = require("./_src/eleventy-liquidjs-tag-highlight");
const syntaxHighlighter = require("./_src/eleventy-liquidjs-tag-highlight-prismjs");
function dateToISO(dateObj) {
return DateTime.fromJSDate(dateObj).toISO({ includeOffset: true, suppressMilliseconds: true });
@ -43,7 +43,7 @@ module.exports = function(eleventyConfig) {
}, true);
// compatibility with existing {% highlight js %} and others
eleventyConfig.addLiquidTag("highlight", highlighters.prismjs);
eleventyConfig.addLiquidTag("highlight", syntaxHighlighter);
// only content in the `posts/` directory
eleventyConfig.addCollection("posts", function(collection) {

View File

@ -0,0 +1,16 @@
const LiquidHighlight = require( "./LiquidHighlight" );
module.exports = function(liquidEngine) {
let highlight = new LiquidHighlight(liquidEngine);
highlight.addClassHook(function(language, line) {
if( language === "dir" ) {
// has trailing slash
if( line.match(/\/$/) !== null ) {
return "highlight-line-isdir";
}
}
});
return highlight.getObject();
};

View File

@ -0,0 +1,12 @@
const Prism = require('prismjs');
const LiquidHighlight = require( "./LiquidHighlight" );
module.exports = function(liquidEngine) {
let highlight = new LiquidHighlight(liquidEngine);
highlight.addHook(function(language, htmlStr, lines) {
return Prism.highlight(htmlStr, Prism.languages[ language ]);
});
return highlight.getObject();
};

View File

@ -1,28 +0,0 @@
const Prism = require('prismjs');
const LiquidHighlight = require( "./LiquidHighlight" );
module.exports = {
plain: function(liquidEngine) {
let highlight = new LiquidHighlight(liquidEngine);
highlight.addClassHook(function(language, line) {
if( language === "dir" ) {
// has trailing slash
if( line.match(/\/$/) !== null ) {
return "highlight-line-isdir";
}
}
});
return highlight.getObject();
},
prismjs: function(liquidEngine) {
let highlight = new LiquidHighlight(liquidEngine);
highlight.addHook(function(language, htmlStr, lines) {
return Prism.highlight(htmlStr, Prism.languages[ language ]);
});
return highlight.getObject();
}
};