Closed gamesover closed 1 year ago
@gamesover Thanks for asking about this.
The intention of #to_text
is to render plain text output. The intention of #to_s
is to render markup.
In the case of "plain text", this may be rendered in a web browser (in which case, entities like &
should be used -- this is the default behavior), or it may be rendered in a non-web context like an SMS message (this is the reason encode_special_chars: false
exists as a feature).
In the case of "markup", we emit HTML markup that meets the HTML spec, so &
is the correct thing to do. The string <div>ruby & rails</div>
is invalid HTML. A browser will handle the parse error, and render it as ruby & rails
, but it is still invalid HTML.
Can you say a bit more about your use case? Why do you want this behavior?
I want to pass
encode_special_chars
toto_s
The current result is
"ohai! <div>ruby & rails</div> "
which is not I want