Template().render produces extra newlines around the rendered text
CookiePLMonster opened this issue · comments
The following example, when ran in Brython 3.12.3, produces additional newlines around the HTML element that includes {variables}
when Template().render()
is used.
Example:
<script type="text/python">
from browser.template import Template
Template('template-test').render(name="extra spaces")
</script>
<p id="template-test">This generated text has <b>{name}</b>!!!</p>
Produces
This generated text has extra spaces !!!
Inspecting HTML after rendering reveals that this happens due to the additional newlines being inserted, that are rendered as spaces:
<p id="template-test">
This generated text has
<b>
extra spaces
</b>
!!!
</p>
Is this behaviour intended? If so, is there a way to work it around? In my "real" use case, this causes the <sup>
elements to be separated by spaces:
The commit referenced above should fix the issue, but it might introduce other ones that I don't see at the moment.
If you don't find any can you close the issue ?
Thanks
If you don't find any can you close the issue ?
My "production" use of templates isn't too heavy, I currently only generate footnotes with templates like this:
<template id="footnote-template">
<li id="fn:{id}" role="doc-endnote">
<p>{note}<a b-code="for n in range(num):" href="#fnref:{id}:{n}" class="reversefootnote" role="doc-backlink"> ↩<sup b-code="if n != 0:">{n+1}</sup></a></p>
</li>
</template>
<template id="footnote-sup">
<sup id="fnref:{id}:{num}" role="doc-noteref"><a href="#fn:{id}" class="footnote" rel="footnote">{notenum}</a></sup>
</template>
and a "hack" to instantiate and render new elements cloned from HTML5 templates described HERE. In those usages, the issue is fixed:
@PierreQuentel If you think this is enough to consider the issue fixed, we can close this ticket 🙂 Thank you for a quick fix!