xmitter-11ty/_src/eleventy-liquidjs-tag-highlight-plain.js
Zach Leatherman 14655cb1c4 Fixes #3
2018-01-22 22:53:46 -06:00

32 lines
849 B
JavaScript

module.exports = function(liquidEngine) {
return {
parse: function(tagToken, remainTokens) {
this.language = tagToken.args;
this.tokens = [];
var stream = 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 highlight not closed");
});
stream.start();
},
render: function(scope, hash) {
var tokens = this.tokens.map(token => {
return token.raw.trim();
}).join('').trim();
return Promise.resolve(`<pre class="language-${this.language}"><code class="language-${this.language}">\n` + tokens + "\n</code></pre>");
}
}
};