diff --git a/src/server/services/PdfService.ts b/src/server/services/PdfService.ts index f4648df..370ff99 100644 --- a/src/server/services/PdfService.ts +++ b/src/server/services/PdfService.ts @@ -284,19 +284,38 @@ export class PdfService { .replace(/&#(\d+);/g, (m, code) => String.fromCharCode(code)); } + // Função para remover todas as tags HTML, exceto as de formatação suportadas + function stripUnsupportedTags(html: string): string { + // Remove todas as tags, exceto , , , , ,
,

, + // Remove atributos de exceto text-indent + return html + // Remove spans que não são recuo + .replace(/])*?>/gi, '') + // Remove atributos de , , , , ,

+ .replace(/<(b|strong|i|em|u|p)[^>]*>/gi, '<$1>') + // Remove todas as outras tags e atributos + .replace(/<(?!\/?(b|strong|i|em|u|br|p|span)[ >])[^>]+>/gi, '') + // Remove spans sem text-indent + .replace(/(.*?)<\/span>/gi, '$1') + // Remove comentários HTML + .replace(//g, ''); + } + // Processar variáveis do template e decodificar entidades HTML // Mantém tags , , , , ,
,

, const texto = decodeHtmlEntities( - this.processarTemplate(conteudo, escritorio) - .replace(//gi, '\n') - .replace(/<\/p>/gi, '\n\n') - .replace(/]*>/gi, '') // Remove apenas a tag de abertura

- .replace(/]*text-indent[^>]*>/gi, '§§INDENT§§') // Marca recuo de parágrafo - .replace(/<\/span>/gi, '') - .replace(/\r\n/g, '\n') - .replace(/\r/g, '\n') - .replace(/\n{3,}/g, '\n\n') - .trim() + stripUnsupportedTags( + this.processarTemplate(conteudo, escritorio) + .replace(//gi, '\n') + .replace(/<\/p>/gi, '\n\n') + .replace(/]*>/gi, '') // Remove apenas a tag de abertura

+ .replace(/]*text-indent[^>]*>/gi, '§§INDENT§§') // Marca recuo de parágrafo + .replace(/<\/span>/gi, '') + .replace(/\r\n/g, '\n') + .replace(/\r/g, '\n') + .replace(/\n{3,}/g, '\n\n') + .trim() + ) ); // Quebra o texto em parágrafos (mantendo quebras de linha duplas como parágrafo)