Nokogiri: strip certain html tags

Hi all!

For layout reasons many of my blog posts are wrapped up with a section tag.

Nokogiri unfortunately generates

<p><section></p>

Is there a way to strip certain html tags—either in config.rb or when calling <%= article.summary %>?

Thank you very much

I think you’re misusing a templating language. The solution is to generate proper html in the first place. Nokogiri shouldn’t generate output like that which makes me wonder what you’re actually running the text through. I don’t think it’s Nokogiri.

If you can provide the code, I can recommend some corrections.

Hi epochwolf!

Valid HTML5 code is used, yet I wrap section tags around the code to guarantee high flexibility of responsive layouts:

  • section = standard width
  • figure (i. e) = wider (if not placed within section; no negative margin is needed)
  • class="wide" = wider

Here is a code example:


<section>

<p>Valid HTML5 code</p>

</section>

<figure><img src="test.jpg" alt="Test"></figure>

<section class="wide">

<p>Valid HTML5 code</p>

</section>

Thanks for your help!

Could it be that you’re trying to render those blocks as Markdown? Most Markdown formatters will (foolishly) wrap paragraph tags around all HTML elements.

THX for your help!

Sorry, forgot to mention: I use redcarpet to render markdown.

Redcarpet can cope with section and article tags (unlike kramdown), and renders markdown correctly within these tags.

What is the name of the template file (including suffixes)?

The name is just layout.erb (within source --> layouts).