Helper: Add specific class to all HTML items

Hi!

unfortunately, I am not familiar enough with helpers, but trying to achieve the following:

A class should to be added to all items of a set of HTML elements—say within the main article element. Exception when a class full-width is one of the classes the element already has.

This should be rendered:

<h1 class="article__item">Heading</h1>

<p class="article__item other-class">P1</p>

<p class="article__item">P2</p>

<p class="full-width other-class">P3</p>

<ul class="article__item">
<li>a</li>
<li>b</li>
</ul>

, either from markdown

# heading

P1
{:.other-class}

P2

P3
{:.full-width .other-class}

- a
- b

or HTML

<h1>Heading</h1>

<p class="other-class">P1</p>

<p>P2</p>

<p class="full-width other-class">P3</p>

<ul>
<li>a</li>
<li>b</li>
</ul>

Your help is very much appreciated. Thanks a lot.

This is my clumsy by working solution:

- doc = Nokogiri::HTML(yield)
- doc.search('p, ul, other-element').add_class('my-class').each do |p|
= doc