sanic-org / html5tagger

Create HTML documents from Python
The Unlicense
29 stars 4 forks source link

Adding script shouldn't escape && #6

Closed ahopkins closed 1 year ago

ahopkins commented 1 year ago

Current work around:

builder.script(HTML("... && ..."))

When adding script, we shouldn't escape entities as it messes with the rendered Javascript.

Tronic commented 1 year ago

You need to use _script for inline scripts. This is mentioned in README.

Autodetecting this, doing the right thing if .script or .style are used would be nice but also difficult to do. Adding a logic for checking this when content is being added to an element would degrade performance. Adding script and style methods would not affect performance, but then behave unexpectedly if not immediately followed by function call. In particular this construct would not add any script tag:

with doc.script:
    doc("javascript code")
Tronic commented 1 year ago

Perhaps if script and style were properties that either provided a proxy object or modified the main Builder object to use different escaping for that tag's content... A bit convoluted no matter which way it is done.

ahopkins commented 1 year ago

Ahh, makes sense. Without looking at anything, the proxy approach sounds right. Using _script is unfortunately not intuitive when it otherwise does seem to work without the underscore.