( html: string, target: PatchTarget, attr: string, )
| 289 | } |
| 290 | |
| 291 | export function readAttributeByTarget( |
| 292 | html: string, |
| 293 | target: PatchTarget, |
| 294 | attr: string, |
| 295 | ): string | undefined { |
| 296 | const match = findTagByTarget(html, target); |
| 297 | if (!match) return undefined; |
| 298 | |
| 299 | const fullAttr = attr.startsWith("data-") ? attr : `data-${attr}`; |
| 300 | const valueMatch = new RegExp(`\\b${fullAttr}=(["'])([^"']*)\\1`).exec(match.tag); |
| 301 | return valueMatch?.[2] != null ? unescapeHtmlAttribute(valueMatch[2]) : undefined; |
| 302 | } |
| 303 | |
| 304 | export function readTagSnippetByTarget(html: string, target: PatchTarget): string | undefined { |
| 305 | const match = findTagByTarget(html, target); |
no test coverage detected