(input: string)
| 155 | } |
| 156 | |
| 157 | function parseToSpansUncached(input: string): Span[] { |
| 158 | const parser = new Parser(); |
| 159 | const actions = parser.feed(input); |
| 160 | const spans: Span[] = []; |
| 161 | let currentHyperlink: string | undefined; |
| 162 | for (const action of actions) { |
| 163 | if (action.type === 'link') { |
| 164 | if (action.action.type === 'start') { |
| 165 | currentHyperlink = action.action.url; |
| 166 | } else { |
| 167 | currentHyperlink = undefined; |
| 168 | } |
| 169 | continue; |
| 170 | } |
| 171 | if (action.type === 'text') { |
| 172 | const text = action.graphemes.map(g => g.value).join(''); |
| 173 | if (!text) continue; |
| 174 | const props = textStyleToSpanProps(action.style); |
| 175 | if (currentHyperlink) { |
| 176 | props.hyperlink = currentHyperlink; |
| 177 | } |
| 178 | |
| 179 | // Try to merge with previous span if props match |
| 180 | const lastSpan = spans[spans.length - 1]; |
| 181 | if (lastSpan && propsEqual(lastSpan.props, props)) { |
| 182 | lastSpan.text += text; |
| 183 | } else { |
| 184 | spans.push({ |
| 185 | text, |
| 186 | props |
| 187 | }); |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | return spans; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Convert termio's TextStyle to SpanProps. |
no test coverage detected