ruricolist / spinneret

Common Lisp HTML5 generator
MIT License
369 stars 26 forks source link

Attribute quoting not working in some cases #95

Open fiddlerwoaroof opened 4 months ago

fiddlerwoaroof commented 4 months ago

*always-quote* is ignored for some sorts of tags. This causes issues with other tools (such as prettier) that don't like attribute values with slashes.

FORMAT-ST-SNIPS> (let ((spinneret:*always-quote* t))
                   (spinneret:with-html (:link :href "/foo")))
<link href=/foo>
fiddlerwoaroof commented 4 months ago

Actually, I just realized this is a macro issue: the LET binding isn't active while the with-html macro is being expanded. So, as implemented, *always-quote*, has to be set with SETF before any invocation of with-html

ruricolist commented 4 months ago

I looked into reporting this as a bug on Prettier, but it's been a known bug since 2020: https://github.com/angular/angular/issues/36932.

In principle I'd be willing to change the handling of attribute values for better parser compatibility, but I'm hesitant to do it for just one parser.

fiddlerwoaroof commented 4 months ago

I wonder if there's a way to make always-quote work with a LET binding. I didn't quite follow the macroexpansion, but it's a bit surprising to me that this variable affects macroexpansion rather than being used by the generated code: is there a performance concern?

As far as prettier goes: I understand not wanting to adjust the behavior for a single parse but prettier is the de facto standard tool for reformatting HTML and other languages found in frontend codebases. If there's a single tool to target, I think prettier would be it.

ruricolist commented 4 months ago

I've change the default behavior to always quote attributes with slashes. I'm leaving this issue open for the moment to think about how and if always-quote should have a run-time effect.