Open vladimir-poghosyan opened 1 month ago
please provide a complete example that reproduces the issue (so it can be run from CLI). also outline your expectations.
When I render the following template (index.html):
@require(lang)
<!doctype html>
<html lang="@lang!h">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<script>
window.addEventListener("DOMContentLoaded", event => {
document.querySelectorAll("button[data-open-dialog]").forEach(button => {
const dialog = document.getElementById(button.dataset.openDialog)
if (!dialog)
return
button.addEventListener("click", event => dialog.show())
})
})
</script>
</head>
<body>
<dialog id="welcome_dialog"><span>Hello there<span></dialog>
<button data-open-dialog="welcome_dialog">Open welcome dialog</button>
</body>
</html>
with python3 -m wheezy.template.console -w index.html '{"lang": "hy"}' > ./rendered.html
command, I get an error in browser console: Uncaught SyntaxError: unexpected token: keyword 'if'
. Running the same command without -w
argument works as expected.
If JavaScript statements are properly terminated with semicolon, the code doesn't break. But it's also possible to leave them out.
I think WhitespaceExtension
must skip processing JavaScript code inside script
tags. Or maybe treat it differently, which I understand can be a complex matter.
When
WhitespaceExtension
is used with wheezy.template, which includes a JavaScript code insidescript
tag, the extension breaks JavaScript code in some cases. For example, JS code with only newline termination:Should the
script
tag be added to ignore rules ofWhitespacePreprocessor
?