Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyword arguments for Liquid shortcodes. #1733

Closed
wants to merge 2 commits into from

Conversation

dawaltconley
Copy link

Fixes #1263. This removes moo and switches the argument lexer/parser for Liquid shortcodes to liquid-args, to support keyword arguments with output mirroring Nunjucks kwargs.

This includes some breaking changes in how Liquid shortcodes handle the whitespace in between arguments. With liquid-args, whitespace can be any number of space, tab, newline, or carriage return characters ([ \t\n\r]), and will allow a comma at the beginning of the whitespace. That means that the following tags will parse correctly:

{% shortcode arg1, arg2, arg3 %}
{% shortcode arg1 arg2 arg3 %}
{% shortcode arg1,arg2,arg3 %}
{% shortcode arg1    arg2, 
    arg3 %}

But the following, which was previously supported, will break:

{% shortcode arg1,,arg2,,arg3 %}
{% shortcode arg1 , arg2 , arg3 %}
{% shortcode arg1 ,arg2 ,,arg3 %}

There are also some changes to how shortcodes parse numbers and dot-notation variable names. The previous moo parser would accept numbers like 10...78 and variable names like ..foobar.baz. These were passed to the Liquid engine, which would throw an error for invalid Liquid. The liquid-args parser rejects these before passing to the engine. This shouldn't cause breaking changes but could affect error handling in some cases.

Basically the same as #1269, but updated to the latest version of 11ty.

@mphstudios
Copy link

@zachleat has there been any thought about merging this change or perhaps additional work to make the args lexer a configurable template engine option?

@zachleat
Copy link
Member

zachleat commented Dec 6, 2022

Closing this one per the comment left over at #1263. #1263 (comment)

Again, I’m sorry this didn’t make it!

@zachleat zachleat closed this Dec 6, 2022
nex3 added a commit to nex3/eleventy that referenced this pull request Sep 15, 2024
This is an adaptation of 11ty#1733 to use the built-in Liquid argument
parser that was added in 11ty#2679.

Co-Authored-By: Dylan Awalt-Conley <web@dylan.ac>
nex3 added a commit to nex3/eleventy that referenced this pull request Sep 20, 2024
This is an adaptation of 11ty#1733 to use the built-in Liquid argument
parser that was added in 11ty#2679.

Co-Authored-By: Dylan Awalt-Conley <web@dylan.ac>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support keyword arguments for Liquid shortcodes.
3 participants