eleventy-plugin-syntaxhighl.../src/LiquidHighlightTag.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

const HighlightPairedShortcode = require("./HighlightPairedShortcode");
const Chroma = require("chroma-highlight");
const parseSyntaxArguments = require("./parseSyntaxArguments");
const getAttributes = require("./getAttributes");
class LiquidHighlightTag {
constructor(liquidEngine) {
this.liquidEngine = liquidEngine;
}
getObject(options = {}) {
let ret = function (highlighter) {
return {
parse: function (tagToken, remainTokens) {
2023-02-03 03:32:52 +01:00
this.args = tagToken.args;
this.tokens = [];
var stream =
highlighter.liquidEngine.parser.parseStream(remainTokens);
stream
.on("token", (token) => {
if (token.name === "endhighlight") {
stream.stop();
} else {
this.tokens.push(token);
}
})
.on("end", (x) => {
throw new Error(`tag ${tagToken.getText()} not closed`);
});
stream.start();
},
render: function (scope, hash) {
let tokens = this.tokens.map((token) => {
return token.raw || token.getText();
});
let tokenStr = tokens.join("").trim();
2023-02-03 03:32:52 +01:00
console.log(this.args);
return Promise.resolve(
2023-02-03 03:32:52 +01:00
HighlightPairedShortcode(tokenStr, this.args, options)
);
},
};
};
return ret(this);
}
}
module.exports = LiquidHighlightTag;