Escaped HTML in html files breaks

I have a bit of escaped HTML code in a <code><pre> block in my page template, but the result is strange.

For example:

<code><pre>
  &lt;h1&gt;Hello World&lt;/h1&gt;
</pre></code>

should not change at all in the rendered page, but results in:

<code><pre>
  &LTh1>Hello World&LT/h1>
</pre></code>

This actually still works in most browsers, but I should not have to rely on heuristics from ancient web for my website to work.

I tried double escaping, quoting, wrapping the code in {% raw %}, nothing works.
When I tried to render this directly with Tera, it worked as expected.