Reputation: 560
I am using Ruby (and Rails) with Markdown to convert the content of a text field into HTML in a post.
So for example:
# Heading.
Some text.
creates
<h1>Heading.</h1>
<p>Some text.</p>
This is good for my Article page, but when I want to display the same content in a teaser, I do not want to show the formatting given by markdown (OR the symbols used in the field to do the formatting...)
Essentially I'd like to strip the all the HTML after it's been created by Markdown... but Im not sure if that's the right approach and I can use parse the markdown as nothing...
So that the returned html is simply:
Heading.
Some Text.
(And will display as "Heading. Some Text." in the browser, not "# Heading. Some Text")
Upvotes: 2
Views: 723
Reputation: 40277
In your teaser, you could use Sanitize to take the rendered HTML and remove all tags from it
html = '<b><a href="http://foo.com/">foo</a></b><img src="http://foo.com/bar.jpg">'
Sanitize.clean(html) # => 'foo'
https://github.com/rgrove/sanitize/
Upvotes: 4