I’m using Nokogiri to handle the following problem:
I have a piece of HTML, and for certain text nodes, I need to insert
tags into the text of these nodes at a certain place.
What I am doing is finding the place where I want to insert the ,
let’s say index X of the text node’s text, and doing the following:
- Setting the node’s text to just what is before index X
- Adding the as a next sibling to the original node
- Adding another next sibling to the original node that is another text
node, whose contents are the rest of the text in the original node.
I can pass a string with “blah” to Node#add_next_sibling
I’m having trouble with creating a new text node and passing it to
Does anyone have an example of creating a new text node in
Is there a simpler way to do this than splitting up one text node
into 3 nodes?