MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / decodeHtmlEntities

Function decodeHtmlEntities

sdk/src/tools/read-url.ts:74–100  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

72}
73
74function decodeHtmlEntities(text: string): string {
75 const namedEntities: Record<string, string> = {
76 amp: '&',
77 apos: "'",
78 copy: '(c)',
79 hellip: '...',
80 gt: '>',
81 lt: '<',
82 mdash: '-',
83 middot: '*',
84 nbsp: ' ',
85 ndash: '-',
86 quot: '"',
87 rsquo: "'",
88 }
89
90 return text.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z]+);/g, (entity, body) => {
91 if (body[0] === '#') {
92 const isHex = body[1]?.toLowerCase() === 'x'
93 const value = Number.parseInt(body.slice(isHex ? 2 : 1), isHex ? 16 : 10)
94 return Number.isFinite(value) && value >= 0 && value <= 0x10ffff
95 ? String.fromCodePoint(value)
96 : entity
97 }
98 return namedEntities[body] ?? entity
99 })
100}
101
102function normalizeText(text: string): string {
103 return text

Callers 5

extractFirstMatchFunction · 0.85
extractMetaContentFunction · 0.85
extractHtmlFunction · 0.85
getValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected