nl_tokens: Split a text node into an ordered list of siblings : - text node to the left of the match - the element replacing the match - text node to the right of the match
pl_tokens: function splitTextNode ( textnode , regexp , replacement ) { let text = textnode . nodeValue , <mask> = text . search ( regexp ) , match = text . match ( regexp ) , captured = [ ] , cursor ; if ( index < 0 || ! match . length ) { return [ textnode ] ; } if ( index > 0 ) { // capture left text node captured . push ( document . createTextNode ( text . substr ( 0 , index ) ) ) ; } // capture the replacement of the matched string captured . push ( parent . create ( match [ 0 ] . replace ( regexp , replacement ) ) ) ; cursor = index + match [ 0 ] . length ; if ( cursor < text . length ) { // capture right text node captured . push ( document . createTextNode ( text . substr ( cursor ) ) ) ; } return captured ; }