Search code examples
htmltritium

Injecting newline after specific word in text with tritium


I have a span node that needs a newline inserted after a certain word. Whenever I use tritium to get into the inner() or text() scope I can't figure out how to inject a break in a way that the browser will interpret as a new node and not text. I don't want to grab the first half as a var and put them in a new node, is there an easier way to do this?


Solution

  • This code should work: You might also want to wrap the

    $("xpath") {
      inner() {
         replace(/(regex)/, '<br /> $1') 
         # This will work also:
         # replace(/(regex)/, '<span class="mw-block">$1</span>'
      } 
    }