Skip to content

Commit

Permalink
Updates RenderPlugin to use built-in Liquid parser #2679
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jul 21, 2024
1 parent e99b157 commit 93d0536
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/Plugins/RenderPlugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from "graceful-fs";
import { Merge, TemplatePath, isPlainObject } from "@11ty/eleventy-utils";
import { Tokenizer, evalToken } from "liquidjs";

// TODO add a first-class Markdown component to expose this using Markdown-only syntax (will need to be synchronous for markdown-it)

Expand Down Expand Up @@ -151,7 +152,18 @@ function eleventyRenderPlugin(eleventyConfig, options = {}) {
return {
parse: function (tagToken, remainTokens) {
this.name = tagToken.name;
this.args = tagToken.args;

if (eleventyConfig.liquid.parameterParsing === "builtin") {
let tokenizer = new Tokenizer(tagToken.args);
this.orderedArgs = [];
while (!tokenizer.end()) {
this.orderedArgs.push(tokenizer.readValue());
}
// note that Liquid does have a Hash class for name-based argument parsing but offers no easy to support both modes in one class
} else {
this.legacyArgs = tagToken.args;
}

this.tokens = [];

var stream = liquidEngine.parser
Expand All @@ -178,12 +190,18 @@ function eleventyRenderPlugin(eleventyConfig, options = {}) {
normalizedContext.eleventy = ctx.get(["eleventy"]);
}

let rawArgs = Liquid.parseArguments(null, this.args);
let argArray = [];
let contextScope = ctx.getAll();
for (let arg of rawArgs) {
let b = yield liquidEngine.evalValue(arg, contextScope);
argArray.push(b);
if (this.legacyArgs) {
let rawArgs = Liquid.parseArguments(null, this.legacyArgs);
for (let arg of rawArgs) {
let b = yield liquidEngine.evalValue(arg, ctx);
argArray.push(b);
}
} else if (this.orderedArgs) {
for (let arg of this.orderedArgs) {
let b = yield evalToken(arg, ctx);
argArray.push(b);
}
}

// plaintext paired shortcode content
Expand Down

0 comments on commit 93d0536

Please sign in to comment.