You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was working with parsing HTML data, and I ran into an issue. When something like <![CDATA[ .... ]]>
came up, the default html.Parse() method will parse that as an html comment. Calling html.Render() yields: <!--[CDATA[ .... ]]-->
creating a comment that isn't useful.
String manipulation can be used to get around this, but I know that under the hood the html.Tokenizer has the method: func (z *Tokenizer) AllowCDATA(allowCDATA bool)
which sets the tokenizer to process this properly.
Proposed Solution
I propose that the user be allowed to set the html.Tokenizer used by the html.Parse()/html.ParseWithOptions() methods. Under the hood, ParseWithOptions() creates a new html.Tokenizer based on the io.Reader passed to it. If the user was also allowed to pass the Tokenizer used by the parser, the user could then set those options as appropriate/necessary, avoiding the above problem.
This could be solved by adding an html.ParseOption. Namely:
Proposal Details
Issue
I was working with parsing HTML data, and I ran into an issue. When something like
<![CDATA[ .... ]]>
came up, the default html.Parse() method will parse that as an html comment. Calling html.Render() yields:
<!--[CDATA[ .... ]]-->
creating a comment that isn't useful.
String manipulation can be used to get around this, but I know that under the hood the html.Tokenizer has the method:
func (z *Tokenizer) AllowCDATA(allowCDATA bool)
which sets the tokenizer to process this properly.
Proposed Solution
I propose that the user be allowed to set the html.Tokenizer used by the html.Parse()/html.ParseWithOptions() methods. Under the hood, ParseWithOptions() creates a new html.Tokenizer based on the io.Reader passed to it. If the user was also allowed to pass the Tokenizer used by the parser, the user could then set those options as appropriate/necessary, avoiding the above problem.
This could be solved by adding an html.ParseOption. Namely:
and this would be called like:
The name of the method can be changed as well to whatever makes more sense.
The text was updated successfully, but these errors were encountered: