MCPcopy Create free account
hub / github.com/markdown-it/markdown-it / replaceEntityPattern

Function replaceEntityPattern

lib/common/utils.mjs:78–97  ·  view source on GitHub ↗
(match, name)

Source from the content-addressed store, hash-verified

76const DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i
77
78function replaceEntityPattern (match, name) {
79 if (name.charCodeAt(0) === 0x23/* # */ && DIGITAL_ENTITY_TEST_RE.test(name)) {
80 const code = name[1].toLowerCase() === 'x'
81 ? parseInt(name.slice(2), 16)
82 : parseInt(name.slice(1), 10)
83
84 if (isValidEntityCode(code)) {
85 return fromCodePoint(code)
86 }
87
88 return match
89 }
90
91 const decoded = decodeHTML(match)
92 if (decoded !== match) {
93 return decoded
94 }
95
96 return match
97}
98
99function unescapeMd (str) {
100 if (str.indexOf('\\') < 0) { return str }

Callers 1

unescapeAllFunction · 0.85

Calls 2

isValidEntityCodeFunction · 0.85
fromCodePointFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…