(html: string, name: string)
| 155 | } |
| 156 | |
| 157 | function extractMetaContent(html: string, name: string): string | undefined { |
| 158 | const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') |
| 159 | const patterns = [ |
| 160 | new RegExp( |
| 161 | `<meta\\b(?=[^>]*(?:name|property)=["']${escapedName}["'])(?=[^>]*content=["']([^"']*)["'])[^>]*>`, |
| 162 | 'i', |
| 163 | ), |
| 164 | new RegExp( |
| 165 | `<meta\\b(?=[^>]*content=["']([^"']*)["'])(?=[^>]*(?:name|property)=["']${escapedName}["'])[^>]*>`, |
| 166 | 'i', |
| 167 | ), |
| 168 | ] |
| 169 | |
| 170 | for (const pattern of patterns) { |
| 171 | const match = html.match(pattern) |
| 172 | if (match?.[1]) return normalizeText(decodeHtmlEntities(match[1])) |
| 173 | } |
| 174 | return undefined |
| 175 | } |
| 176 | |
| 177 | function extractHtml(html: string): { |
| 178 | title?: string |
no test coverage detected