Separate files for syntax highlighters
This commit is contained in:
parent
d7e2c4e525
commit
dfe49017c8
@ -2,7 +2,7 @@ const { DateTime } = require("luxon");
|
|||||||
const metadata = require("./_data/metadata.json");
|
const metadata = require("./_data/metadata.json");
|
||||||
const absoluteUrl = require("./_src/absoluteUrl");
|
const absoluteUrl = require("./_src/absoluteUrl");
|
||||||
const HtmlToAbsoluteUrls = require("./_src/HtmlToAbsoluteUrls");
|
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) {
|
function dateToISO(dateObj) {
|
||||||
return DateTime.fromJSDate(dateObj).toISO({ includeOffset: true, suppressMilliseconds: true });
|
return DateTime.fromJSDate(dateObj).toISO({ includeOffset: true, suppressMilliseconds: true });
|
||||||
@ -43,7 +43,7 @@ module.exports = function(eleventyConfig) {
|
|||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// compatibility with existing {% highlight js %} and others
|
// compatibility with existing {% highlight js %} and others
|
||||||
eleventyConfig.addLiquidTag("highlight", highlighters.prismjs);
|
eleventyConfig.addLiquidTag("highlight", syntaxHighlighter);
|
||||||
|
|
||||||
// only content in the `posts/` directory
|
// only content in the `posts/` directory
|
||||||
eleventyConfig.addCollection("posts", function(collection) {
|
eleventyConfig.addCollection("posts", function(collection) {
|
||||||
|
16
_src/eleventy-liquidjs-tag-highlight-plain.js
Normal file
16
_src/eleventy-liquidjs-tag-highlight-plain.js
Normal 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();
|
||||||
|
};
|
12
_src/eleventy-liquidjs-tag-highlight-prismjs.js
Normal file
12
_src/eleventy-liquidjs-tag-highlight-prismjs.js
Normal 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();
|
||||||
|
};
|
@ -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();
|
|
||||||
}
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user