Escape non HTML tags in plain text (convert plain text to HTML)
问题 Using Rails, I need to get a plain text and show it as HTML, but I don't want to use <pre> tag, as it changes the format. 回答1: I needed to subclass HTML::WhiteListSanitizer to escape non whitelisted tags (by changing process_node ), monkey patch HTML::Node to don't downcase tags' names and monkey patch HTML::Text to apply <wbr /> word splitting: class Text2HTML def self.convert text text = simple_format text text = auto_link text, :all, :target => '_blank' text = NonHTMLEscaper.sanitize text