fix: remove duplicate HTML entity keys in utils
This commit is contained in:
parent
76436ac1a2
commit
3ee7b28d3d
@ -13,6 +13,7 @@ export function cn(...inputs: ClassValue[]) {
|
||||
export function decodeHtmlEntities(text: string): string {
|
||||
if (!text) return "";
|
||||
|
||||
// Objeto con entidades comunes de WordPress/HTML
|
||||
const entities: { [key: string]: string } = {
|
||||
'–': '–',
|
||||
'—': '—',
|
||||
@ -28,19 +29,18 @@ export function decodeHtmlEntities(text: string): string {
|
||||
'"': '"',
|
||||
''': "'",
|
||||
'&': '&',
|
||||
' ': ' ',
|
||||
'–': '–',
|
||||
'—': '—',
|
||||
' ': ' '
|
||||
};
|
||||
|
||||
let decoded = text;
|
||||
|
||||
// Aplicar reemplazos del mapa manual
|
||||
Object.keys(entities).forEach(entity => {
|
||||
decoded = decoded.split(entity).join(entities[entity]);
|
||||
});
|
||||
|
||||
// Remover cualquier otra entidad numérica residual (&#...;) que no esté en el mapa
|
||||
return decoded.replace(/&#\d+;/g, (match) => {
|
||||
const num = parseInt(match.replace(/\D/g, ''), 10);
|
||||
return String.fromCharCode(num);
|
||||
// Decodificador genérico para cualquier otra entidad numérica residual (&#...;)
|
||||
return decoded.replace(/&#(\d+);/g, (match, dec) => {
|
||||
return String.fromCharCode(parseInt(dec, 10));
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user