MCPcopy
hub / github.com/webpack/webpack / decodeHtmlEntitiesWithMap

Function decodeHtmlEntitiesWithMap

lib/html/syntax.js:3738–3769  ·  view source on GitHub ↗
(str, isAttribute)

Source from the content-addressed store, hash-verified

3736 * @returns {{ text: string, map: number[] | undefined }} decoded text and offset map
3737 */
3738const decodeHtmlEntitiesWithMap = (str, isAttribute) => {
3739 /** @type {number[] | undefined} */
3740 let map;
3741 if (str.includes("&")) {
3742 CHARACTER_REFERENCE_REGEXP.lastIndex = 0;
3743 let text = "";
3744 let last = 0;
3745 /** @type {RegExpExecArray | null} */
3746 let m;
3747 while ((m = CHARACTER_REFERENCE_REGEXP.exec(str)) !== null) {
3748 const match = m[0];
3749 const decoded = decodeOneReference(
3750 match,
3751 str.charCodeAt(m.index + match.length),
3752 isAttribute
3753 );
3754 if (decoded === match) continue;
3755 if (map === undefined) map = [];
3756 for (let r = last; r < m.index; r++) map.push(r);
3757 text += str.slice(last, m.index);
3758 for (let i = 0; i < decoded.length; i++) map.push(m.index);
3759 text += decoded;
3760 last = m.index + match.length;
3761 }
3762 if (map !== undefined) {
3763 for (let r = last; r < str.length; r++) map.push(r);
3764 map.push(str.length);
3765 return { text: text + str.slice(last), map };
3766 }
3767 }
3768 return { text: str, map };
3769};
3770
3771// cspell:ignore advasoft altglyph altglyphdef altglyphitem animatecolor animatemotion animatetransform arcrole aswedit attributename attributetype basefrequency baseprofile bgsound calcmode clippathunits definitionurl diffuseconstant fedropshadow filterunits glyphref gradienttransform gradientunits hotjava hotmetal kernelmatrix kernelunitlength keypoints keysplines keytimes limitingconeangle malignmark markerheight markerwidth maskcontentunits maskunits metrius mglyph mtext numoctaves pathlength patterncontentunits patterntransform patternunits pointsatx pointsaty pointsatz preservealpha primitiveunits refx refy repeatcount repeatdur requiredextensions requiredfeatures selectedcontent silmaril softquad specularconstant specularexponent startoffset stddeviation stitchtiles surfacescale systemlanguage tablevalues targetx targety textlength viewbox viewtarget webtechs xchannelselector ychannelselector megamorphic attributeless rowspan imagesizes novalidate maxlength
3772

Callers 2

parseMethod · 0.85

Calls 4

decodeOneReferenceFunction · 0.85
execMethod · 0.80
sliceMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected