/**
* Markdown cleanup utility for leftover markdown syntax after Asciidoc rendering
*/
export function cleanupMarkdown(html: string): string {
let cleaned = html
// Clean up markdown image syntax: 
cleaned = cleaned.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_match, alt, url) => {
const altText = alt || ''
return ``
})
// Clean up markdown link syntax: [text](url)
cleaned = cleaned.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, text, url) => {
// Check if it's already an HTML link
if (cleaned.includes(`href="${url}"`)) {
return _match
}
return `${text} `
})
// Clean up markdown table syntax
cleaned = cleanupMarkdownTables(cleaned)
return cleaned
}
function cleanupMarkdownTables(html: string): string {
// Simple markdown table detection and conversion
const tableRegex = /(\|.*\|[\r\n]+\|[\s\-\|]*[\r\n]+(\|.*\|[\r\n]+)*)/g
return html.replace(tableRegex, (match) => {
const lines = match.trim().split('\n').filter(line => line.trim())
if (lines.length < 2) return match
const headerRow = lines[0]
const separatorRow = lines[1]
const dataRows = lines.slice(2)
// Check if it's actually a table (has separator row with dashes)
if (!separatorRow.includes('-')) return match
const headers = headerRow.split('|').map(cell => cell.trim()).filter(cell => cell)
const rows = dataRows.map(row =>
row.split('|').map(cell => cell.trim()).filter(cell => cell)
)
let tableHtml = '
| ${header} | \n` }) tableHtml += '
|---|