Ruby on rails 删除由标记创建的html

Ruby on rails 删除由标记创建的html,ruby-on-rails,ruby,markdown,Ruby On Rails,Ruby,Markdown,我正在使用Ruby(和Rails)和Markdown将文章中文本字段的内容转换为HTML 例如: # Heading. Some text. 创造 <h1>Heading.</h1> <p>Some text.</p> (并将显示为“Heading.Some Text.”在浏览器中,而不是“#Heading.Some Text”)在摘要中,您可以使用Sanitize获取呈现的HTML并从中删除所有标记 html = '<b><

我正在使用Ruby(和Rails)和Markdown将文章中文本字段的内容转换为HTML

例如:

# Heading.
Some text.
创造

<h1>Heading.</h1>
<p>Some text.</p>

(并将显示为“Heading.Some Text.”在浏览器中,而不是“#Heading.Some Text”)

在摘要中,您可以使用Sanitize获取呈现的HTML并从中删除所有标记

html = '<b><a href="http://foo.com/">foo</a></b><img src="http://foo.com/bar.jpg">'

Sanitize.clean(html) # => 'foo'
html=''
Sanitize.clean(html)#=>“foo”

html = '<b><a href="http://foo.com/">foo</a></b><img src="http://foo.com/bar.jpg">'

Sanitize.clean(html) # => 'foo'