Skip to content

Commit 1d1c275

Browse files
committed
feat(generator): add internal link processing for Markdown to HTML conversion
- Introduced a method to process internal links in generated HTML, converting .md file references to .html while preserving anchors. - Enhanced the documentation generation process by ensuring that internal links are correctly formatted, improving navigation within the generated documentation.
1 parent 4d8bf27 commit 1d1c275

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/generator.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,27 @@ export class DocumentationGenerator {
178178
return match;
179179
});
180180

181+
// Processar links internos para converter .md para .html
182+
html = this.processInternalLinks(html);
183+
181184
return html;
182185
}
183186

187+
private processInternalLinks(html: string): string {
188+
// Regex para encontrar links internos que apontam para arquivos .md
189+
// Procura por href="./arquivo.md" ou href="arquivo.md" (links relativos)
190+
// Também trata aspas simples e links com âncoras (#section)
191+
return html.replace(/href=(["'])([^"']*\.md(?:#[^"']*)?)\1/g, (match, quote, href) => {
192+
// Verificar se é um link interno (não começa com http:// ou https://)
193+
if (!href.startsWith('http://') && !href.startsWith('https://') && !href.startsWith('mailto:')) {
194+
// Converter .md para .html, preservando âncoras se existirem
195+
const htmlHref = href.replace(/\.md(#.*)?$/, '.html$1');
196+
return `href=${quote}${htmlHref}${quote}`;
197+
}
198+
return match;
199+
});
200+
}
201+
184202
private async findMarkdownFiles(dir: string): Promise<string[]> {
185203
const files: string[] = [];
186204
const entries = await fs.readdir(dir, { withFileTypes: true });

0 commit comments

Comments
 (0)