Let's say I have the following HTML:
<ul><li>Bullet 1.</li> <li>Bullet 2.</li> <li>Bullet 3.</li> <li>Bullet 4.</li> <li>Bullet 5.</li></ul>
What I want to do with this replaces any periods, question marks or exclamation marks with myself and the ending star that is inside the HTML node and then converted back to HTML. Thus, the result will be:
<ul><li>Bullet 1.*</li> <li>Bullet 2.*</li> <li>Bullet 3.*</li> <li>Bullet 4.*</li> <li>Bullet 5.*</li></ul>
I understand this a bit on IRB, but I canβt understand. here I have the code:
html = "<ul><li>Bullet 1.</li> <li>Bullet 2.</li> <li>Bullet 3.</li> <li>Bullet 4.</li> <li>Bullet 5.</li></ul>" doc = Nokogiri::HTML::DocumentFragment.parse(html) doc.search("*").map { |n| n.inner_text.gsub(/(?<=[.!?])(?!\*)/, "#{$1}*") }
The returned array is parsed correctly, but I'm just not sure how to convert it to HTML. Is there any other way that I can use to change inner_text as such?
source share