diff --git a/.eleventy.js b/.eleventy.js index 5166009..e677d3d 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -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) { diff --git a/_src/eleventy-liquidjs-tag-highlight-plain.js b/_src/eleventy-liquidjs-tag-highlight-plain.js new file mode 100644 index 0000000..bd153c3 --- /dev/null +++ b/_src/eleventy-liquidjs-tag-highlight-plain.js @@ -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(); +}; \ No newline at end of file diff --git a/_src/eleventy-liquidjs-tag-highlight-prismjs.js b/_src/eleventy-liquidjs-tag-highlight-prismjs.js new file mode 100644 index 0000000..c0a128c --- /dev/null +++ b/_src/eleventy-liquidjs-tag-highlight-prismjs.js @@ -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(); +}; \ No newline at end of file diff --git a/_src/eleventy-liquidjs-tag-highlight.js b/_src/eleventy-liquidjs-tag-highlight.js deleted file mode 100644 index 4f91e8a..0000000 --- a/_src/eleventy-liquidjs-tag-highlight.js +++ /dev/null @@ -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(); - } -}; \ No newline at end of file