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