Skip to content

Html decode

Athan Clark requested to merge html-decode-in-backends-20210815 into master

This MR fixes #140 (closed). The issue is the following: backends should be responsible for decoding Html-encoded strings (i.e. &lt; is html-encoded <), rather than all templates having their text decoded by default. This behavior is exhibited when you try to import a template that has an html-encoded html tag (&lt;div&gt; as <div>) - if we decode it by default, and use the static backend to render (for instance, with disembodied), then we'll have incorrectly formatted html (and worse yet, html elements where we were intending to have text!).

It's pretty convoluted, but you can see the issue if you do the following:

foo.html:

<div>&lt;foo&gt;</div>
renderStatic $(embedHtml "foo.html")

The expected output should be identical to foo.html, but unfortunately it comes out as <div><foo></div>.

Solution

This MR solves this issue by creating a new function in core/Shpadoinkle/Core.hs - htmlDecode :: JSString -> JSM JSString, which actually does the html decoding. Furthermore, it uses this function in the ParDiff and Snabbdom backends, but refrains from doing so in the static backend. Also, this MR removes the previously existing html decoding routines in template/Shpadoinkle/Template/TH.hs.

Merge request reports