(codes: CharacterDiff[])
| 147 | // after: abc[123]def |
| 148 | // The "before" codes will have two consecutive "equal" spans due to the addition. |
| 149 | export function simplifyCodes(codes: CharacterDiff[]): CharacterDiff[] { |
| 150 | const newCodes = []; |
| 151 | for (let i = 0; i < codes.length; i++) { |
| 152 | const code = codes[i]; |
| 153 | if (i == 0) { |
| 154 | newCodes.push(code); |
| 155 | continue; |
| 156 | } |
| 157 | |
| 158 | const lastIndex = newCodes.length - 1; |
| 159 | const lastCodeClass = newCodes[lastIndex][0]; |
| 160 | if (lastCodeClass == code[0]) { |
| 161 | newCodes[lastIndex][2] = code[2]; // extend last run. |
| 162 | } else { |
| 163 | newCodes.push(code); |
| 164 | } |
| 165 | } |
| 166 | return newCodes; |
| 167 | } |
| 168 | |
| 169 | // codes are (span class, start, end) triples. |
| 170 | // This wraps html[start..end] in appropriate <span>..</span>s. |
no outgoing calls
no test coverage detected