The golang.org/x/net/html package contains two functions similar to the ones in the html package for escaping and unescaping HTML entities:
func EscapeString(string) string
func UnescapeString(string) string
unfortunately these require loading entire documents into memory and converting them to a string before attempting to escape them.
It would be nice if there were also an implementation of the Transformer (and SpanningTransformer) interface from golang.org/x/text/transform that could perform escaping / unescaping on long byte streams without requiring buffering the entire stream into memory.
This could either be two functions which return transformers:
// Escaper returns a transformer that escapes special characters.
// See EscapeString for more information.
func Escaper() transform.SpanningTransformer
// Unescaper returns a transformer that unescapes special characters.
// See UnescapeString for more information.
func Unescaper() transform.SpanningTransformer
or a Transformer type which contains all the various helper methods (String, Bytes, etc.) that transformer based packages in the text tree have.
/cc @mpvl
The
golang.org/x/net/htmlpackage contains two functions similar to the ones in thehtmlpackage for escaping and unescaping HTML entities:unfortunately these require loading entire documents into memory and converting them to a string before attempting to escape them.
It would be nice if there were also an implementation of the
Transformer(andSpanningTransformer) interface fromgolang.org/x/text/transformthat could perform escaping / unescaping on long byte streams without requiring buffering the entire stream into memory.This could either be two functions which return transformers:
or a
Transformertype which contains all the various helper methods (String, Bytes, etc.) that transformer based packages in the text tree have./cc @mpvl