chore(deps): replace cli-highlight (#4468)

This commit is contained in:
Armin Ronacher
2026-05-13 12:19:45 +02:00
committed by GitHub
parent 2829146dde
commit e0b5d27af2
8 changed files with 281 additions and 149 deletions
+51
View File
@@ -0,0 +1,51 @@
export interface DecodedHtmlEntity {
text: string;
length: number;
}
function decodeCodePoint(codePoint: number): string | undefined {
if (!Number.isInteger(codePoint) || codePoint < 0 || codePoint > 0x10ffff) {
return undefined;
}
return String.fromCodePoint(codePoint);
}
export function decodeHtmlEntity(entity: string): string | undefined {
switch (entity) {
case "amp":
return "&";
case "lt":
return "<";
case "gt":
return ">";
case "quot":
return '"';
case "apos":
return "'";
}
if (entity.startsWith("#x") || entity.startsWith("#X")) {
return decodeCodePoint(Number.parseInt(entity.slice(2), 16));
}
if (entity.startsWith("#")) {
return decodeCodePoint(Number.parseInt(entity.slice(1), 10));
}
return undefined;
}
export function decodeHtmlEntityAt(html: string, index: number): DecodedHtmlEntity | undefined {
const semicolonIndex = html.indexOf(";", index + 1);
if (semicolonIndex === -1 || semicolonIndex - index > 16) {
return undefined;
}
const entity = html.slice(index + 1, semicolonIndex);
const decoded = decodeHtmlEntity(entity);
if (decoded === undefined) {
return undefined;
}
return { text: decoded, length: semicolonIndex - index + 1 };
}