yogthos/Selmer

Quoted strings as tag arguments have their quotes escaped and preserved

Open

#235 geöffnet am 6. Juli 2020

Auf GitHub ansehen
 (11 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Clojure (86 Forks)batch import
enhancementhelp wanted

Repository-Metriken

Stars
 (670 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 39m) (4 gemergte PRs in 30 T)

Beschreibung

Is it possible to have a quoted string as an argument to a tag, without the surrounding quotes being preserved in the output?

Selmer, as expected, does treat the quoted string as a single argument, but passes the string to the tag function with its quotes, escaped, as part of the string.

Or perhaps there's another notation which allows a string with spaces to be treated as a single argument?

(use 'selmer.parser)

(add-tag! :foo
  (fn [args context-map]
    (str "foo " (first args))))

(render "{% foo \"quux quuz\" %}" {})
=>"foo \"quux quuz\""

Using render-file removes the need to escape the quotes in the template file, but still introduces them in the output:

file.txt:

{% foo "quux quuz" %}
(render-file "file.txt" {})
=>"foo \"quux quuz\""

The {% safe %} tag has no discernible effect:

file.txt:

{% safe %}{% foo "quux quuz" %}{% endsafe %}
(render-file "file.txt" {})
=>"foo \"quux quuz\""

Contributor Guide