* Parse one line of ariaSnapshot output. * * Format examples: * - heading "Test" [level=1] * - link "Link A": * - /url: /a * - textbox "Name" * - paragraph: Some text * - combobox "Role":
(line: string)
| 116 | * - combobox "Role": |
| 117 | */ |
| 118 | function parseLine(line: string): ParsedNode | null { |
| 119 | // Match: (indent)(- )(role)( "name")?( [props])?(: inline)? |
| 120 | const match = line.match(/^(\s*)-\s+(\w+)(?:\s+"([^"]*)")?(?:\s+(\[.*?\]))?\s*(?::\s*(.*))?$/); |
| 121 | if (!match) { |
| 122 | // Skip metadata lines like "- /url: /a" |
| 123 | return null; |
| 124 | } |
| 125 | return { |
| 126 | indent: match[1].length, |
| 127 | role: match[2], |
| 128 | name: match[3] ?? null, |
| 129 | props: match[4] || '', |
| 130 | children: match[5]?.trim() || '', |
| 131 | rawLine: line, |
| 132 | }; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Take an accessibility snapshot and build the ref map. |