tenta fix pdfservice.js
This commit is contained in:
1 parent
3a3c64f1b3
commit
e179fb33d7
1 file changed
+29
-10
@@ -284,19 +284,38 @@ export class PdfService {
|
|||||||
.replace(/&#(\d+);/g, (m, code) => String.fromCharCode(code));
|
.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 <b>, <strong>, <i>, <em>, <u>, <br>, <p>, <span style="text-indent:2em;">
|
||||||
|
// Remove atributos de <span> exceto text-indent
|
||||||
|
return html
|
||||||
|
// Remove spans que não são recuo
|
||||||
|
.replace(/<span\b((?!text-indent)[^>])*?>/gi, '')
|
||||||
|
// Remove atributos de <b>, <strong>, <i>, <em>, <u>, <p>
|
||||||
|
.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>(.*?)<\/span>/gi, '$1')
|
||||||
|
// Remove comentários HTML
|
||||||
|
.replace(/<!--[\s\S]*?-->/g, '');
|
||||||
|
}
|
||||||
|
|
||||||
// Processar variáveis do template e decodificar entidades HTML
|
// Processar variáveis do template e decodificar entidades HTML
|
||||||
// Mantém tags <b>, <strong>, <i>, <em>, <u>, <br>, <p>, <span style="text-indent:2em;">
|
// Mantém tags <b>, <strong>, <i>, <em>, <u>, <br>, <p>, <span style="text-indent:2em;">
|
||||||
const texto = decodeHtmlEntities(
|
const texto = decodeHtmlEntities(
|
||||||
this.processarTemplate(conteudo, escritorio)
|
stripUnsupportedTags(
|
||||||
.replace(/<br\s*\/?>/gi, '\n')
|
this.processarTemplate(conteudo, escritorio)
|
||||||
.replace(/<\/p>/gi, '\n\n')
|
.replace(/<br\s*\/?>/gi, '\n')
|
||||||
.replace(/<p[^>]*>/gi, '') // Remove apenas a tag de abertura <p>
|
.replace(/<\/p>/gi, '\n\n')
|
||||||
.replace(/<span[^>]*text-indent[^>]*>/gi, '§§INDENT§§') // Marca recuo de parágrafo
|
.replace(/<p[^>]*>/gi, '') // Remove apenas a tag de abertura <p>
|
||||||
.replace(/<\/span>/gi, '')
|
.replace(/<span[^>]*text-indent[^>]*>/gi, '§§INDENT§§') // Marca recuo de parágrafo
|
||||||
.replace(/\r\n/g, '\n')
|
.replace(/<\/span>/gi, '')
|
||||||
.replace(/\r/g, '\n')
|
.replace(/\r\n/g, '\n')
|
||||||
.replace(/\n{3,}/g, '\n\n')
|
.replace(/\r/g, '\n')
|
||||||
.trim()
|
.replace(/\n{3,}/g, '\n\n')
|
||||||
|
.trim()
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Quebra o texto em parágrafos (mantendo quebras de linha duplas como parágrafo)
|
// Quebra o texto em parágrafos (mantendo quebras de linha duplas como parágrafo)
|
||||||
|
|||||||
Reference in new issue
Block a user