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) {
|
|
|
|
console.log(">>LIQIUD");
|
|
|
|
console.log(tagToken.args);
|
|
|
|
console.log("<<LIQIUD");
|
2023-02-02 15:36:15 +01:00
|
|
|
let split = tagToken.args.split(" ");
|
|
|
|
|
|
|
|
this.language = split.shift();
|
|
|
|
this.highlightLines = split.join(" ");
|
|
|
|
|
|
|
|
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 00:46:44 +01:00
|
|
|
return Promise.resolve(
|
|
|
|
HighlightPairedShortcode(
|
|
|
|
tokenStr,
|
|
|
|
this.language,
|
|
|
|
this.highlightLines,
|
|
|
|
options
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
2023-02-02 15:36:15 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
return ret(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = LiquidHighlightTag;
|