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