47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { clsx, type ClassValue } from "clsx"
|
||
import { twMerge } from "tailwind-merge"
|
||
|
||
export function cn(...inputs: ClassValue[]) {
|
||
return twMerge(clsx(inputs))
|
||
}
|
||
|
||
/**
|
||
* Decodifica entidades HTML comunes que vienen de WordPress (ej: … -> ...)
|
||
* @param text Texto con entidades HTML
|
||
* @returns Texto decodificado
|
||
*/
|
||
export function decodeHtmlEntities(text: string): string {
|
||
if (!text) return "";
|
||
|
||
// Objeto con entidades comunes de WordPress/HTML
|
||
const entities: { [key: string]: string } = {
|
||
'–': '–',
|
||
'—': '—',
|
||
'‘': "‘",
|
||
'’': "'",
|
||
'“': '"',
|
||
'”': '"',
|
||
'…': '...',
|
||
' ': ' ',
|
||
'&': '&',
|
||
'<': '<',
|
||
'>': '>',
|
||
'"': '"',
|
||
''': "'",
|
||
'&': '&',
|
||
' ': ' '
|
||
};
|
||
|
||
let decoded = text;
|
||
|
||
// Aplicar reemplazos del mapa manual
|
||
Object.keys(entities).forEach(entity => {
|
||
decoded = decoded.split(entity).join(entities[entity]);
|
||
});
|
||
|
||
// Decodificador genérico para cualquier otra entidad numérica residual (&#...;)
|
||
return decoded.replace(/&#(\d+);/g, (match, dec) => {
|
||
return String.fromCharCode(parseInt(dec, 10));
|
||
});
|
||
}
|