| @@ 131-186 (lines=56) @@ | ||
| 128 | }); |
|
| 129 | matchLocation = matches.shift(); |
|
| 130 | out: |
|
| 131 | while (true) { |
|
| 132 | if (blockElementsMap[curNode.nodeName] || shortEndedElementsMap[curNode.nodeName] || isContentEditableFalse(curNode)) { |
|
| 133 | atIndex++; |
|
| 134 | } |
|
| 135 | if (curNode.nodeType === 3) { |
|
| 136 | if (!endNode && curNode.length + atIndex >= matchLocation.end) { |
|
| 137 | endNode = curNode; |
|
| 138 | endNodeIndex = matchLocation.end - atIndex; |
|
| 139 | } else if (startNode) { |
|
| 140 | innerNodes.push(curNode); |
|
| 141 | } |
|
| 142 | if (!startNode && curNode.length + atIndex > matchLocation.start) { |
|
| 143 | startNode = curNode; |
|
| 144 | startNodeIndex = matchLocation.start - atIndex; |
|
| 145 | } |
|
| 146 | atIndex += curNode.length; |
|
| 147 | } |
|
| 148 | if (startNode && endNode) { |
|
| 149 | curNode = replaceFn({ |
|
| 150 | startNode: startNode, |
|
| 151 | startNodeIndex: startNodeIndex, |
|
| 152 | endNode: endNode, |
|
| 153 | endNodeIndex: endNodeIndex, |
|
| 154 | innerNodes: innerNodes, |
|
| 155 | match: matchLocation.text, |
|
| 156 | matchIndex: matchIndex |
|
| 157 | }); |
|
| 158 | atIndex -= endNode.length - endNodeIndex; |
|
| 159 | startNode = null; |
|
| 160 | endNode = null; |
|
| 161 | innerNodes = []; |
|
| 162 | matchLocation = matches.shift(); |
|
| 163 | matchIndex++; |
|
| 164 | if (!matchLocation) { |
|
| 165 | break; |
|
| 166 | } |
|
| 167 | } else if ((!hiddenTextElementsMap[curNode.nodeName] || blockElementsMap[curNode.nodeName]) && curNode.firstChild) { |
|
| 168 | if (!isContentEditableFalse(curNode)) { |
|
| 169 | curNode = curNode.firstChild; |
|
| 170 | continue; |
|
| 171 | } |
|
| 172 | } else if (curNode.nextSibling) { |
|
| 173 | curNode = curNode.nextSibling; |
|
| 174 | continue; |
|
| 175 | } |
|
| 176 | while (true) { |
|
| 177 | if (curNode.nextSibling) { |
|
| 178 | curNode = curNode.nextSibling; |
|
| 179 | break; |
|
| 180 | } else if (curNode.parentNode !== node) { |
|
| 181 | curNode = curNode.parentNode; |
|
| 182 | } else { |
|
| 183 | break out; |
|
| 184 | } |
|
| 185 | } |
|
| 186 | } |
|
| 187 | } |
|
| 188 | function genReplacer(callback) { |
|
| 189 | function makeReplacementNode(fill, matchIndex) { |
|
| @@ 84-139 (lines=56) @@ | ||
| 81 | function stepThroughMatches(node, matches, replaceFn) { |
|
| 82 | var startNode, endNode, startNodeIndex, endNodeIndex, innerNodes = [], atIndex = 0, curNode = node, matchLocation = matches.shift(), matchIndex = 0; |
|
| 83 | out: |
|
| 84 | while (true) { |
|
| 85 | if (blockElementsMap[curNode.nodeName] || shortEndedElementsMap[curNode.nodeName] || isContentEditableFalse(curNode)) { |
|
| 86 | atIndex++; |
|
| 87 | } |
|
| 88 | if (curNode.nodeType === 3) { |
|
| 89 | if (!endNode && curNode.length + atIndex >= matchLocation[1]) { |
|
| 90 | endNode = curNode; |
|
| 91 | endNodeIndex = matchLocation[1] - atIndex; |
|
| 92 | } else if (startNode) { |
|
| 93 | innerNodes.push(curNode); |
|
| 94 | } |
|
| 95 | if (!startNode && curNode.length + atIndex > matchLocation[0]) { |
|
| 96 | startNode = curNode; |
|
| 97 | startNodeIndex = matchLocation[0] - atIndex; |
|
| 98 | } |
|
| 99 | atIndex += curNode.length; |
|
| 100 | } |
|
| 101 | if (startNode && endNode) { |
|
| 102 | curNode = replaceFn({ |
|
| 103 | startNode: startNode, |
|
| 104 | startNodeIndex: startNodeIndex, |
|
| 105 | endNode: endNode, |
|
| 106 | endNodeIndex: endNodeIndex, |
|
| 107 | innerNodes: innerNodes, |
|
| 108 | match: matchLocation[2], |
|
| 109 | matchIndex: matchIndex |
|
| 110 | }); |
|
| 111 | atIndex -= endNode.length - endNodeIndex; |
|
| 112 | startNode = null; |
|
| 113 | endNode = null; |
|
| 114 | innerNodes = []; |
|
| 115 | matchLocation = matches.shift(); |
|
| 116 | matchIndex++; |
|
| 117 | if (!matchLocation) { |
|
| 118 | break; |
|
| 119 | } |
|
| 120 | } else if ((!hiddenTextElementsMap[curNode.nodeName] || blockElementsMap[curNode.nodeName]) && curNode.firstChild) { |
|
| 121 | if (!isContentEditableFalse(curNode)) { |
|
| 122 | curNode = curNode.firstChild; |
|
| 123 | continue; |
|
| 124 | } |
|
| 125 | } else if (curNode.nextSibling) { |
|
| 126 | curNode = curNode.nextSibling; |
|
| 127 | continue; |
|
| 128 | } |
|
| 129 | while (true) { |
|
| 130 | if (curNode.nextSibling) { |
|
| 131 | curNode = curNode.nextSibling; |
|
| 132 | break; |
|
| 133 | } else if (curNode.parentNode !== node) { |
|
| 134 | curNode = curNode.parentNode; |
|
| 135 | } else { |
|
| 136 | break out; |
|
| 137 | } |
|
| 138 | } |
|
| 139 | } |
|
| 140 | } |
|
| 141 | function genReplacer(nodeName) { |
|
| 142 | var makeReplacementNode; |
|