import { Parser } from './src/parser'; import * as fs from 'fs'; import * as path from 'path'; /** * Test that parses both markdown and asciidoc test documents * and generates an HTML report showing the parsing results */ describe('Parser Test Report', () => { const parser = new Parser({ linkBaseURL: 'https://example.com', wikilinkUrl: '/events?d={dtag}', hashtagUrl: '/notes?t={topic}', }); test('Generate HTML test report for markdown and asciidoc documents', async () => { // Read test documents const markdownContent = fs.readFileSync( path.join(__dirname, 'markdown_testdoc.md'), 'utf-8' ); const asciidocContent = fs.readFileSync( path.join(__dirname, 'asciidoc_testdoc.adoc'), 'utf-8' ); // Parse both documents const markdownResult = await parser.process(markdownContent); const asciidocResult = await parser.process(asciidocContent); // Generate HTML report const htmlReport = generateHTMLReport({ markdown: { original: markdownContent, result: markdownResult, }, asciidoc: { original: asciidocContent, result: asciidocResult, }, }); // Write HTML report to file const reportPath = path.join(__dirname, 'test-report.html'); fs.writeFileSync(reportPath, htmlReport, 'utf-8'); console.log(`\n✅ Test report generated: ${reportPath}`); console.log(` Open this file in your browser to view the results.\n`); // Basic assertions to ensure parsing worked expect(markdownResult.content).toBeTruthy(); expect(asciidocResult.content).toBeTruthy(); expect(markdownResult.content.length).toBeGreaterThan(0); expect(asciidocResult.content.length).toBeGreaterThan(0); }); }); interface TestData { original: string; result: any; } interface ReportData { markdown: TestData; asciidoc: TestData; } function generateHTMLReport(data: ReportData): string { const { markdown, asciidoc } = data; return ` GC Parser Test Report

GC Parser Test Report

Generated: ${new Date().toLocaleString()}

Markdown Document Test ✓ Parsed

${markdown.result.nostrLinks.length}
Nostr Links
${markdown.result.wikilinks.length}
Wikilinks
${markdown.result.hashtags.length}
Hashtags
${markdown.result.links.length}
Links
${markdown.result.media.length}
Media URLs
${markdown.result.hasLaTeX ? 'Yes' : 'No'}
Has LaTeX
${markdown.result.hasMusicalNotation ? 'Yes' : 'No'}
Has Music

Frontmatter

${markdown.result.frontmatter ? ` ` : '

No frontmatter found

'}

Original Markdown Content

${escapeHtml(markdown.original)}

Rendered HTML Output

${markdown.result.content}
View Raw HTML
${escapeHtml(markdown.result.content)}

Extracted Metadata

${markdown.result.nostrLinks.length > 0 ? `

Nostr Links (${markdown.result.nostrLinks.length})

${markdown.result.nostrLinks.map(link => `
${escapeHtml(link.type)}: ${escapeHtml(link.bech32)} ${link.text ? ` - ${escapeHtml(link.text)}` : ''}
`).join('')} ` : ''} ${markdown.result.wikilinks.length > 0 ? `

Wikilinks (${markdown.result.wikilinks.length})

${markdown.result.wikilinks.map(wl => `
${escapeHtml(wl.original)} → dtag: ${escapeHtml(wl.dtag)} ${wl.display ? ` (display: ${escapeHtml(wl.display)})` : ''}
`).join('')} ` : ''} ${markdown.result.hashtags.length > 0 ? `

Hashtags (${markdown.result.hashtags.length})

${markdown.result.hashtags.map(tag => `
#${escapeHtml(tag)}
`).join('')} ` : ''} ${markdown.result.links.length > 0 ? `

Links (${markdown.result.links.length})

${markdown.result.links.map(link => `
${escapeHtml(link.text || link.url)} ${link.isExternal ? 'External' : ''}
`).join('')} ` : ''} ${markdown.result.media.length > 0 ? `

Media URLs (${markdown.result.media.length})

${markdown.result.media.map(url => ` `).join('')} ` : ''} ${markdown.result.tableOfContents ? `

Table of Contents

${markdown.result.tableOfContents}
` : ''}

AsciiDoc Document Test ✓ Parsed

${asciidoc.result.nostrLinks.length}
Nostr Links
${asciidoc.result.wikilinks.length}
Wikilinks
${asciidoc.result.hashtags.length}
Hashtags
${asciidoc.result.links.length}
Links
${asciidoc.result.media.length}
Media URLs
${asciidoc.result.hasLaTeX ? 'Yes' : 'No'}
Has LaTeX
${asciidoc.result.hasMusicalNotation ? 'Yes' : 'No'}
Has Music

Frontmatter

${asciidoc.result.frontmatter ? ` ` : '

No frontmatter found

'}

Original AsciiDoc Content

${escapeHtml(asciidoc.original)}

Rendered HTML Output

${asciidoc.result.content}
View Raw HTML
${escapeHtml(asciidoc.result.content)}

Extracted Metadata

${asciidoc.result.nostrLinks.length > 0 ? `

Nostr Links (${asciidoc.result.nostrLinks.length})

${asciidoc.result.nostrLinks.map(link => `
${escapeHtml(link.type)}: ${escapeHtml(link.bech32)} ${link.text ? ` - ${escapeHtml(link.text)}` : ''}
`).join('')} ` : ''} ${asciidoc.result.wikilinks.length > 0 ? `

Wikilinks (${asciidoc.result.wikilinks.length})

${asciidoc.result.wikilinks.map(wl => `
${escapeHtml(wl.original)} → dtag: ${escapeHtml(wl.dtag)} ${wl.display ? ` (display: ${escapeHtml(wl.display)})` : ''}
`).join('')} ` : ''} ${asciidoc.result.hashtags.length > 0 ? `

Hashtags (${asciidoc.result.hashtags.length})

${asciidoc.result.hashtags.map(tag => `
#${escapeHtml(tag)}
`).join('')} ` : ''} ${asciidoc.result.links.length > 0 ? `

Links (${asciidoc.result.links.length})

${asciidoc.result.links.map(link => `
${escapeHtml(link.text || link.url)} ${link.isExternal ? 'External' : ''}
`).join('')} ` : ''} ${asciidoc.result.media.length > 0 ? `

Media URLs (${asciidoc.result.media.length})

${asciidoc.result.media.map(url => ` `).join('')} ` : ''} ${asciidoc.result.tableOfContents ? `

Table of Contents

${asciidoc.result.tableOfContents}
` : ''}
`; } function escapeHtml(text: string): string { const map: Record = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''', }; return text.replace(/[&<>"']/g, (m) => map[m]); }