Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable HTML escaping #57

Open
Ma124 opened this issue Jul 17, 2019 · 1 comment
Open

Disable HTML escaping #57

Ma124 opened this issue Jul 17, 2019 · 1 comment

Comments

@Ma124
Copy link

Ma124 commented Jul 17, 2019

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 %}

@pierrre
Copy link

pierrre commented Sep 12, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants