(content: string)
| 15 | * Normalize void HTML tags for MDX compilation (e.g. `<img>` → `<img />`). |
| 16 | */ |
| 17 | export function sanitizeHtmlForMdx (content: string): string { |
| 18 | let result = content |
| 19 | |
| 20 | for (const tag of VOID_HTML_ELEMENTS) { |
| 21 | result = result.replace(new RegExp(`</${tag}\\s*>`, 'gi'), '') |
| 22 | } |
| 23 | |
| 24 | for (const tag of VOID_HTML_ELEMENTS) { |
| 25 | result = result.replace( |
| 26 | new RegExp(`<${tag}(\\s[^>]*?)?(?<!/)>`, 'gi'), |
| 27 | (_match, attrs: string | undefined) => `<${tag}${attrs ?? ''} />` |
| 28 | ) |
| 29 | } |
| 30 | |
| 31 | return result |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Build a regex/replace function that turns the monorepo's relative markdown |
no outgoing calls
no test coverage detected
searching dependent graphs…