quicktemplate icon indicating copy to clipboard operation
quicktemplate copied to clipboard

Disable HTML escaping

Open Ma124 opened this issue 5 years ago • 1 comments

I really like QTPL but I rarely use it for HTML generation but rather go code generation. So I often write code like this to avoid the automatic HTML escaping which is really inconvenient:

func writeunesc(iow io.Writer, s string) {
	qw := qt.AcquireWriter(iow)
	streamunesc(qw, s)
	qt.ReleaseWriter(qw)
}

func unesc(s string) string {
	qb := qt.AcquireByteBuffer()
	writeunesc(qb, s)
	qs := string(qb.B)
	qt.ReleaseByteBuffer(qb)
	return qs
}

func streamunesc(qw *qt.Writer, s string) {
	qw.N().S(s)
}

to use it like this:

{% func Foo(param *ParamType) %}
Some
{%= unesc(param.Text) %}
stuff
{% endfunc %}

So I wanted to ask if there is already a way to deal with this and if not how one could implement this maybe as some thing like {%r param.Text %}

Ma124 avatar Jul 17 '19 15:07 Ma124

You can already do it with {%s= params.Text %}.

However, I think it would be interesting to be able to disable escaping for a block of code.

pierrre avatar Sep 12 '23 09:09 pierrre