Skip to content

Support keyword arguments for Liquid shortcodes. #1263

@dawaltconley

Description

@dawaltconley

Is your feature request related to a problem? Please describe.

Currently, a Nunjucks shortcode or custom tag like this...

{% test 'arg1', 'arg2', foo='bar', baz=5 %}

...will pass the following arguments to its function:

[ 'arg1', 'arg2', { __keywords: true, foo: 'bar', baz: 5 } ]

This makes a lot of sense to me and I'd like to see its behavior replicated in Liquid shortcodes.

Describe the solution you'd like

I wrote a parser for Liquid arguments, which (mostly) matches the moo lexer currently used for Liquid shortcodes, but also supports keyword arguments and mimics the above behavior.

I can submit this as a pull request, though I think it partially depends on #1058 and how 11ty handles async argument evaluations.

Describe alternatives you've considered

There are some slight differences between mine and the moo parser, which I think bring it closer to Liquid syntax but which could be (theoretically?) breaking:

  1. Whitespace / arg separators are /,?[ \t\n\r]+/ instead of /[, \t]+/. So arg1 ,arg2 or arg1,,,arg2 would be invalid.
  2. Numbers only allow one dot: /[0-9]+\.?[0-9]*/ instead of /[0-9]+\.*[0-9]*/
  3. Variables can only have periods separating valid variable names, i.e foo.bar.baz and not ..foobar.baz.

I could bring it exactly in line with the moo lexer if that's preferred. I assume it might be possible to do this with moo too, though I haven't used it before.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions