From e179fb33d77e3941a7f6b3d97af2109338b10c9d Mon Sep 17 00:00:00 2001 From: Rodrigo Martins Date: Mon, 21 Apr 2025 19:48:27 -0300 Subject: [PATCH] tenta fix pdfservice.js --- src/server/services/PdfService.ts | 39 +++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 10 deletions(-) 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)