@jarenjs/md 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +520 -0
- package/dist/types/ast.d.ts +181 -0
- package/dist/types/bake.d.ts +61 -0
- package/dist/types/compiler.d.ts +141 -0
- package/dist/types/component/index.d.ts +101 -0
- package/dist/types/directives.d.ts +126 -0
- package/dist/types/entities.d.ts +40 -0
- package/dist/types/footnotes.d.ts +83 -0
- package/dist/types/frontmatter.d.ts +67 -0
- package/dist/types/html.d.ts +72 -0
- package/dist/types/index.d.ts +30 -0
- package/dist/types/loader.d.ts +84 -0
- package/dist/types/mdx.d.ts +45 -0
- package/dist/types/parser.d.ts +116 -0
- package/dist/types/plugins/highlight.d.ts +64 -0
- package/dist/types/plugins/index.d.ts +64 -0
- package/dist/types/plugins/mermaid.d.ts +12 -0
- package/dist/types/scanner.d.ts +240 -0
- package/dist/types/to-html.d.ts +104 -0
- package/dist/types/to-md.d.ts +23 -0
- package/dist/types/to-vnode.d.ts +161 -0
- package/dist/types/utils.d.ts +63 -0
- package/docs/LOADER.md +92 -0
- package/docs/MD-FORMAT.md +502 -0
- package/docs/PLUGINS.md +277 -0
- package/package.json +80 -0
- package/schemas/jaren-md-ast.schema.json +296 -0
- package/src/ast.js +346 -0
- package/src/bake.js +104 -0
- package/src/compiler.js +167 -0
- package/src/component/index.js +191 -0
- package/src/directives.js +371 -0
- package/src/entities.js +107 -0
- package/src/footnotes.js +180 -0
- package/src/frontmatter.js +947 -0
- package/src/html.js +281 -0
- package/src/index.js +76 -0
- package/src/loader.js +0 -0
- package/src/mdx.js +219 -0
- package/src/parser.js +1685 -0
- package/src/plugins/highlight.js +325 -0
- package/src/plugins/index.js +75 -0
- package/src/plugins/mermaid.js +14 -0
- package/src/scanner.js +832 -0
- package/src/to-html.js +425 -0
- package/src/to-md.js +396 -0
- package/src/to-vnode.js +766 -0
- package/src/utils.js +107 -0
- package/styles/md.css +238 -0
package/src/entities.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file The HTML5 named character references, as CommonMark requires
|
|
4
|
+
* them (its "entity and numeric character references" section defers to
|
|
5
|
+
* the WHATWG HTML standard's table, all 2125 of them — a
|
|
6
|
+
* pragmatic subset is a dialect, not CommonMark).
|
|
7
|
+
*
|
|
8
|
+
* GENERATED by `scripts/generate-md-entities.js`; do not edit by hand.
|
|
9
|
+
*
|
|
10
|
+
* The table is packed as one string and split on first use rather than
|
|
11
|
+
* written as 2125 object properties: the packed form is a
|
|
12
|
+
* quarter of the source bytes and one allocation, and a document with no
|
|
13
|
+
* entity in it never pays for the Map at all.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** `name:codepoint[+codepoint]` (hex), comma separated. */
|
|
17
|
+
const PACKED = "AElig:c6,AMP:26,Aacute:c1,Abreve:102,Acirc:c2,Acy:410,Afr:1d504,Agrave:c0,Alpha:391,Amacr:100,And:2a53,Aogon:104,Aopf:1d538,ApplyFunction:2061,Aring:c5,Ascr:1d49c,Assign:2254,Atilde:c3,Auml:c4,Backslash:2216,Barv:2ae7,Barwed:2306,Bcy:411,Because:2235,Bernoullis:212c,Beta:392,Bfr:1d505,Bopf:1d539,Breve:2d8,Bscr:212c,Bumpeq:224e,CHcy:427,COPY:a9,Cacute:106,Cap:22d2,CapitalDifferentialD:2145,Cayleys:212d,Ccaron:10c,Ccedil:c7,Ccirc:108,Cconint:2230,Cdot:10a,Cedilla:b8,CenterDot:b7,Cfr:212d,Chi:3a7,CircleDot:2299,CircleMinus:2296,CirclePlus:2295,CircleTimes:2297,ClockwiseContourIntegral:2232,CloseCurlyDoubleQuote:201d,CloseCurlyQuote:2019,Colon:2237,Colone:2a74,Congruent:2261,Conint:222f,ContourIntegral:222e,Copf:2102,Coproduct:2210,CounterClockwiseContourIntegral:2233,Cross:2a2f,Cscr:1d49e,Cup:22d3,CupCap:224d,DD:2145,DDotrahd:2911,DJcy:402,DScy:405,DZcy:40f,Dagger:2021,Darr:21a1,Dashv:2ae4,Dcaron:10e,Dcy:414,Del:2207,Delta:394,Dfr:1d507,DiacriticalAcute:b4,DiacriticalDot:2d9,DiacriticalDoubleAcute:2dd,DiacriticalGrave:60,DiacriticalTilde:2dc,Diamond:22c4,DifferentialD:2146,Dopf:1d53b,Dot:a8,DotDot:20dc,DotEqual:2250,DoubleContourIntegral:222f,DoubleDot:a8,DoubleDownArrow:21d3,DoubleLeftArrow:21d0,DoubleLeftRightArrow:21d4,DoubleLeftTee:2ae4,DoubleLongLeftArrow:27f8,DoubleLongLeftRightArrow:27fa,DoubleLongRightArrow:27f9,DoubleRightArrow:21d2,DoubleRightTee:22a8,DoubleUpArrow:21d1,DoubleUpDownArrow:21d5,DoubleVerticalBar:2225,DownArrow:2193,DownArrowBar:2913,DownArrowUpArrow:21f5,DownBreve:311,DownLeftRightVector:2950,DownLeftTeeVector:295e,DownLeftVector:21bd,DownLeftVectorBar:2956,DownRightTeeVector:295f,DownRightVector:21c1,DownRightVectorBar:2957,DownTee:22a4,DownTeeArrow:21a7,Downarrow:21d3,Dscr:1d49f,Dstrok:110,ENG:14a,ETH:d0,Eacute:c9,Ecaron:11a,Ecirc:ca,Ecy:42d,Edot:116,Efr:1d508,Egrave:c8,Element:2208,Emacr:112,EmptySmallSquare:25fb,EmptyVerySmallSquare:25ab,Eogon:118,Eopf:1d53c,Epsilon:395,Equal:2a75,EqualTilde:2242,Equilibrium:21cc,Escr:2130,Esim:2a73,Eta:397,Euml:cb,Exists:2203,ExponentialE:2147,Fcy:424,Ffr:1d509,FilledSmallSquare:25fc,FilledVerySmallSquare:25aa,Fopf:1d53d,ForAll:2200,Fouriertrf:2131,Fscr:2131,GJcy:403,GT:3e,Gamma:393,Gammad:3dc,Gbreve:11e,Gcedil:122,Gcirc:11c,Gcy:413,Gdot:120,Gfr:1d50a,Gg:22d9,Gopf:1d53e,GreaterEqual:2265,GreaterEqualLess:22db,GreaterFullEqual:2267,GreaterGreater:2aa2,GreaterLess:2277,GreaterSlantEqual:2a7e,GreaterTilde:2273,Gscr:1d4a2,Gt:226b,HARDcy:42a,Hacek:2c7,Hat:5e,Hcirc:124,Hfr:210c,HilbertSpace:210b,Hopf:210d,HorizontalLine:2500,Hscr:210b,Hstrok:126,HumpDownHump:224e,HumpEqual:224f,IEcy:415,IJlig:132,IOcy:401,Iacute:cd,Icirc:ce,Icy:418,Idot:130,Ifr:2111,Igrave:cc,Im:2111,Imacr:12a,ImaginaryI:2148,Implies:21d2,Int:222c,Integral:222b,Intersection:22c2,InvisibleComma:2063,InvisibleTimes:2062,Iogon:12e,Iopf:1d540,Iota:399,Iscr:2110,Itilde:128,Iukcy:406,Iuml:cf,Jcirc:134,Jcy:419,Jfr:1d50d,Jopf:1d541,Jscr:1d4a5,Jsercy:408,Jukcy:404,KHcy:425,KJcy:40c,Kappa:39a,Kcedil:136,Kcy:41a,Kfr:1d50e,Kopf:1d542,Kscr:1d4a6,LJcy:409,LT:3c,Lacute:139,Lambda:39b,Lang:27ea,Laplacetrf:2112,Larr:219e,Lcaron:13d,Lcedil:13b,Lcy:41b,LeftAngleBracket:27e8,LeftArrow:2190,LeftArrowBar:21e4,LeftArrowRightArrow:21c6,LeftCeiling:2308,LeftDoubleBracket:27e6,LeftDownTeeVector:2961,LeftDownVector:21c3,LeftDownVectorBar:2959,LeftFloor:230a,LeftRightArrow:2194,LeftRightVector:294e,LeftTee:22a3,LeftTeeArrow:21a4,LeftTeeVector:295a,LeftTriangle:22b2,LeftTriangleBar:29cf,LeftTriangleEqual:22b4,LeftUpDownVector:2951,LeftUpTeeVector:2960,LeftUpVector:21bf,LeftUpVectorBar:2958,LeftVector:21bc,LeftVectorBar:2952,Leftarrow:21d0,Leftrightarrow:21d4,LessEqualGreater:22da,LessFullEqual:2266,LessGreater:2276,LessLess:2aa1,LessSlantEqual:2a7d,LessTilde:2272,Lfr:1d50f,Ll:22d8,Lleftarrow:21da,Lmidot:13f,LongLeftArrow:27f5,LongLeftRightArrow:27f7,LongRightArrow:27f6,Longleftarrow:27f8,Longleftrightarrow:27fa,Longrightarrow:27f9,Lopf:1d543,LowerLeftArrow:2199,LowerRightArrow:2198,Lscr:2112,Lsh:21b0,Lstrok:141,Lt:226a,Map:2905,Mcy:41c,MediumSpace:205f,Mellintrf:2133,Mfr:1d510,MinusPlus:2213,Mopf:1d544,Mscr:2133,Mu:39c,NJcy:40a,Nacute:143,Ncaron:147,Ncedil:145,Ncy:41d,NegativeMediumSpace:200b,NegativeThickSpace:200b,NegativeThinSpace:200b,NegativeVeryThinSpace:200b,NestedGreaterGreater:226b,NestedLessLess:226a,NewLine:a,Nfr:1d511,NoBreak:2060,NonBreakingSpace:a0,Nopf:2115,Not:2aec,NotCongruent:2262,NotCupCap:226d,NotDoubleVerticalBar:2226,NotElement:2209,NotEqual:2260,NotEqualTilde:2242+338,NotExists:2204,NotGreater:226f,NotGreaterEqual:2271,NotGreaterFullEqual:2267+338,NotGreaterGreater:226b+338,NotGreaterLess:2279,NotGreaterSlantEqual:2a7e+338,NotGreaterTilde:2275,NotHumpDownHump:224e+338,NotHumpEqual:224f+338,NotLeftTriangle:22ea,NotLeftTriangleBar:29cf+338,NotLeftTriangleEqual:22ec,NotLess:226e,NotLessEqual:2270,NotLessGreater:2278,NotLessLess:226a+338,NotLessSlantEqual:2a7d+338,NotLessTilde:2274,NotNestedGreaterGreater:2aa2+338,NotNestedLessLess:2aa1+338,NotPrecedes:2280,NotPrecedesEqual:2aaf+338,NotPrecedesSlantEqual:22e0,NotReverseElement:220c,NotRightTriangle:22eb,NotRightTriangleBar:29d0+338,NotRightTriangleEqual:22ed,NotSquareSubset:228f+338,NotSquareSubsetEqual:22e2,NotSquareSuperset:2290+338,NotSquareSupersetEqual:22e3,NotSubset:2282+20d2,NotSubsetEqual:2288,NotSucceeds:2281,NotSucceedsEqual:2ab0+338,NotSucceedsSlantEqual:22e1,NotSucceedsTilde:227f+338,NotSuperset:2283+20d2,NotSupersetEqual:2289,NotTilde:2241,NotTildeEqual:2244,NotTildeFullEqual:2247,NotTildeTilde:2249,NotVerticalBar:2224,Nscr:1d4a9,Ntilde:d1,Nu:39d,OElig:152,Oacute:d3,Ocirc:d4,Ocy:41e,Odblac:150,Ofr:1d512,Ograve:d2,Omacr:14c,Omega:3a9,Omicron:39f,Oopf:1d546,OpenCurlyDoubleQuote:201c,OpenCurlyQuote:2018,Or:2a54,Oscr:1d4aa,Oslash:d8,Otilde:d5,Otimes:2a37,Ouml:d6,OverBar:203e,OverBrace:23de,OverBracket:23b4,OverParenthesis:23dc,PartialD:2202,Pcy:41f,Pfr:1d513,Phi:3a6,Pi:3a0,PlusMinus:b1,Poincareplane:210c,Popf:2119,Pr:2abb,Precedes:227a,PrecedesEqual:2aaf,PrecedesSlantEqual:227c,PrecedesTilde:227e,Prime:2033,Product:220f,Proportion:2237,Proportional:221d,Pscr:1d4ab,Psi:3a8,QUOT:22,Qfr:1d514,Qopf:211a,Qscr:1d4ac,RBarr:2910,REG:ae,Racute:154,Rang:27eb,Rarr:21a0,Rarrtl:2916,Rcaron:158,Rcedil:156,Rcy:420,Re:211c,ReverseElement:220b,ReverseEquilibrium:21cb,ReverseUpEquilibrium:296f,Rfr:211c,Rho:3a1,RightAngleBracket:27e9,RightArrow:2192,RightArrowBar:21e5,RightArrowLeftArrow:21c4,RightCeiling:2309,RightDoubleBracket:27e7,RightDownTeeVector:295d,RightDownVector:21c2,RightDownVectorBar:2955,RightFloor:230b,RightTee:22a2,RightTeeArrow:21a6,RightTeeVector:295b,RightTriangle:22b3,RightTriangleBar:29d0,RightTriangleEqual:22b5,RightUpDownVector:294f,RightUpTeeVector:295c,RightUpVector:21be,RightUpVectorBar:2954,RightVector:21c0,RightVectorBar:2953,Rightarrow:21d2,Ropf:211d,RoundImplies:2970,Rrightarrow:21db,Rscr:211b,Rsh:21b1,RuleDelayed:29f4,SHCHcy:429,SHcy:428,SOFTcy:42c,Sacute:15a,Sc:2abc,Scaron:160,Scedil:15e,Scirc:15c,Scy:421,Sfr:1d516,ShortDownArrow:2193,ShortLeftArrow:2190,ShortRightArrow:2192,ShortUpArrow:2191,Sigma:3a3,SmallCircle:2218,Sopf:1d54a,Sqrt:221a,Square:25a1,SquareIntersection:2293,SquareSubset:228f,SquareSubsetEqual:2291,SquareSuperset:2290,SquareSupersetEqual:2292,SquareUnion:2294,Sscr:1d4ae,Star:22c6,Sub:22d0,Subset:22d0,SubsetEqual:2286,Succeeds:227b,SucceedsEqual:2ab0,SucceedsSlantEqual:227d,SucceedsTilde:227f,SuchThat:220b,Sum:2211,Sup:22d1,Superset:2283,SupersetEqual:2287,Supset:22d1,THORN:de,TRADE:2122,TSHcy:40b,TScy:426,Tab:9,Tau:3a4,Tcaron:164,Tcedil:162,Tcy:422,Tfr:1d517,Therefore:2234,Theta:398,ThickSpace:205f+200a,ThinSpace:2009,Tilde:223c,TildeEqual:2243,TildeFullEqual:2245,TildeTilde:2248,Topf:1d54b,TripleDot:20db,Tscr:1d4af,Tstrok:166,Uacute:da,Uarr:219f,Uarrocir:2949,Ubrcy:40e,Ubreve:16c,Ucirc:db,Ucy:423,Udblac:170,Ufr:1d518,Ugrave:d9,Umacr:16a,UnderBar:5f,UnderBrace:23df,UnderBracket:23b5,UnderParenthesis:23dd,Union:22c3,UnionPlus:228e,Uogon:172,Uopf:1d54c,UpArrow:2191,UpArrowBar:2912,UpArrowDownArrow:21c5,UpDownArrow:2195,UpEquilibrium:296e,UpTee:22a5,UpTeeArrow:21a5,Uparrow:21d1,Updownarrow:21d5,UpperLeftArrow:2196,UpperRightArrow:2197,Upsi:3d2,Upsilon:3a5,Uring:16e,Uscr:1d4b0,Utilde:168,Uuml:dc,VDash:22ab,Vbar:2aeb,Vcy:412,Vdash:22a9,Vdashl:2ae6,Vee:22c1,Verbar:2016,Vert:2016,VerticalBar:2223,VerticalLine:7c,VerticalSeparator:2758,VerticalTilde:2240,VeryThinSpace:200a,Vfr:1d519,Vopf:1d54d,Vscr:1d4b1,Vvdash:22aa,Wcirc:174,Wedge:22c0,Wfr:1d51a,Wopf:1d54e,Wscr:1d4b2,Xfr:1d51b,Xi:39e,Xopf:1d54f,Xscr:1d4b3,YAcy:42f,YIcy:407,YUcy:42e,Yacute:dd,Ycirc:176,Ycy:42b,Yfr:1d51c,Yopf:1d550,Yscr:1d4b4,Yuml:178,ZHcy:416,Zacute:179,Zcaron:17d,Zcy:417,Zdot:17b,ZeroWidthSpace:200b,Zeta:396,Zfr:2128,Zopf:2124,Zscr:1d4b5,aacute:e1,abreve:103,ac:223e,acE:223e+333,acd:223f,acirc:e2,acute:b4,acy:430,aelig:e6,af:2061,afr:1d51e,agrave:e0,alefsym:2135,aleph:2135,alpha:3b1,amacr:101,amalg:2a3f,amp:26,and:2227,andand:2a55,andd:2a5c,andslope:2a58,andv:2a5a,ang:2220,ange:29a4,angle:2220,angmsd:2221,angmsdaa:29a8,angmsdab:29a9,angmsdac:29aa,angmsdad:29ab,angmsdae:29ac,angmsdaf:29ad,angmsdag:29ae,angmsdah:29af,angrt:221f,angrtvb:22be,angrtvbd:299d,angsph:2222,angst:c5,angzarr:237c,aogon:105,aopf:1d552,ap:2248,apE:2a70,apacir:2a6f,ape:224a,apid:224b,apos:27,approx:2248,approxeq:224a,aring:e5,ascr:1d4b6,ast:2a,asymp:2248,asympeq:224d,atilde:e3,auml:e4,awconint:2233,awint:2a11,bNot:2aed,backcong:224c,backepsilon:3f6,backprime:2035,backsim:223d,backsimeq:22cd,barvee:22bd,barwed:2305,barwedge:2305,bbrk:23b5,bbrktbrk:23b6,bcong:224c,bcy:431,bdquo:201e,becaus:2235,because:2235,bemptyv:29b0,bepsi:3f6,bernou:212c,beta:3b2,beth:2136,between:226c,bfr:1d51f,bigcap:22c2,bigcirc:25ef,bigcup:22c3,bigodot:2a00,bigoplus:2a01,bigotimes:2a02,bigsqcup:2a06,bigstar:2605,bigtriangledown:25bd,bigtriangleup:25b3,biguplus:2a04,bigvee:22c1,bigwedge:22c0,bkarow:290d,blacklozenge:29eb,blacksquare:25aa,blacktriangle:25b4,blacktriangledown:25be,blacktriangleleft:25c2,blacktriangleright:25b8,blank:2423,blk12:2592,blk14:2591,blk34:2593,block:2588,bne:3d+20e5,bnequiv:2261+20e5,bnot:2310,bopf:1d553,bot:22a5,bottom:22a5,bowtie:22c8,boxDL:2557,boxDR:2554,boxDl:2556,boxDr:2553,boxH:2550,boxHD:2566,boxHU:2569,boxHd:2564,boxHu:2567,boxUL:255d,boxUR:255a,boxUl:255c,boxUr:2559,boxV:2551,boxVH:256c,boxVL:2563,boxVR:2560,boxVh:256b,boxVl:2562,boxVr:255f,boxbox:29c9,boxdL:2555,boxdR:2552,boxdl:2510,boxdr:250c,boxh:2500,boxhD:2565,boxhU:2568,boxhd:252c,boxhu:2534,boxminus:229f,boxplus:229e,boxtimes:22a0,boxuL:255b,boxuR:2558,boxul:2518,boxur:2514,boxv:2502,boxvH:256a,boxvL:2561,boxvR:255e,boxvh:253c,boxvl:2524,boxvr:251c,bprime:2035,breve:2d8,brvbar:a6,bscr:1d4b7,bsemi:204f,bsim:223d,bsime:22cd,bsol:5c,bsolb:29c5,bsolhsub:27c8,bull:2022,bullet:2022,bump:224e,bumpE:2aae,bumpe:224f,bumpeq:224f,cacute:107,cap:2229,capand:2a44,capbrcup:2a49,capcap:2a4b,capcup:2a47,capdot:2a40,caps:2229+fe00,caret:2041,caron:2c7,ccaps:2a4d,ccaron:10d,ccedil:e7,ccirc:109,ccups:2a4c,ccupssm:2a50,cdot:10b,cedil:b8,cemptyv:29b2,cent:a2,centerdot:b7,cfr:1d520,chcy:447,check:2713,checkmark:2713,chi:3c7,cir:25cb,cirE:29c3,circ:2c6,circeq:2257,circlearrowleft:21ba,circlearrowright:21bb,circledR:ae,circledS:24c8,circledast:229b,circledcirc:229a,circleddash:229d,cire:2257,cirfnint:2a10,cirmid:2aef,cirscir:29c2,clubs:2663,clubsuit:2663,colon:3a,colone:2254,coloneq:2254,comma:2c,commat:40,comp:2201,compfn:2218,complement:2201,complexes:2102,cong:2245,congdot:2a6d,conint:222e,copf:1d554,coprod:2210,copy:a9,copysr:2117,crarr:21b5,cross:2717,cscr:1d4b8,csub:2acf,csube:2ad1,csup:2ad0,csupe:2ad2,ctdot:22ef,cudarrl:2938,cudarrr:2935,cuepr:22de,cuesc:22df,cularr:21b6,cularrp:293d,cup:222a,cupbrcap:2a48,cupcap:2a46,cupcup:2a4a,cupdot:228d,cupor:2a45,cups:222a+fe00,curarr:21b7,curarrm:293c,curlyeqprec:22de,curlyeqsucc:22df,curlyvee:22ce,curlywedge:22cf,curren:a4,curvearrowleft:21b6,curvearrowright:21b7,cuvee:22ce,cuwed:22cf,cwconint:2232,cwint:2231,cylcty:232d,dArr:21d3,dHar:2965,dagger:2020,daleth:2138,darr:2193,dash:2010,dashv:22a3,dbkarow:290f,dblac:2dd,dcaron:10f,dcy:434,dd:2146,ddagger:2021,ddarr:21ca,ddotseq:2a77,deg:b0,delta:3b4,demptyv:29b1,dfisht:297f,dfr:1d521,dharl:21c3,dharr:21c2,diam:22c4,diamond:22c4,diamondsuit:2666,diams:2666,die:a8,digamma:3dd,disin:22f2,div:f7,divide:f7,divideontimes:22c7,divonx:22c7,djcy:452,dlcorn:231e,dlcrop:230d,dollar:24,dopf:1d555,dot:2d9,doteq:2250,doteqdot:2251,dotminus:2238,dotplus:2214,dotsquare:22a1,doublebarwedge:2306,downarrow:2193,downdownarrows:21ca,downharpoonleft:21c3,downharpoonright:21c2,drbkarow:2910,drcorn:231f,drcrop:230c,dscr:1d4b9,dscy:455,dsol:29f6,dstrok:111,dtdot:22f1,dtri:25bf,dtrif:25be,duarr:21f5,duhar:296f,dwangle:29a6,dzcy:45f,dzigrarr:27ff,eDDot:2a77,eDot:2251,eacute:e9,easter:2a6e,ecaron:11b,ecir:2256,ecirc:ea,ecolon:2255,ecy:44d,edot:117,ee:2147,efDot:2252,efr:1d522,eg:2a9a,egrave:e8,egs:2a96,egsdot:2a98,el:2a99,elinters:23e7,ell:2113,els:2a95,elsdot:2a97,emacr:113,empty:2205,emptyset:2205,emptyv:2205,emsp:2003,emsp13:2004,emsp14:2005,eng:14b,ensp:2002,eogon:119,eopf:1d556,epar:22d5,eparsl:29e3,eplus:2a71,epsi:3b5,epsilon:3b5,epsiv:3f5,eqcirc:2256,eqcolon:2255,eqsim:2242,eqslantgtr:2a96,eqslantless:2a95,equals:3d,equest:225f,equiv:2261,equivDD:2a78,eqvparsl:29e5,erDot:2253,erarr:2971,escr:212f,esdot:2250,esim:2242,eta:3b7,eth:f0,euml:eb,euro:20ac,excl:21,exist:2203,expectation:2130,exponentiale:2147,fallingdotseq:2252,fcy:444,female:2640,ffilig:fb03,fflig:fb00,ffllig:fb04,ffr:1d523,filig:fb01,fjlig:66+6a,flat:266d,fllig:fb02,fltns:25b1,fnof:192,fopf:1d557,forall:2200,fork:22d4,forkv:2ad9,fpartint:2a0d,frac12:bd,frac13:2153,frac14:bc,frac15:2155,frac16:2159,frac18:215b,frac23:2154,frac25:2156,frac34:be,frac35:2157,frac38:215c,frac45:2158,frac56:215a,frac58:215d,frac78:215e,frasl:2044,frown:2322,fscr:1d4bb,gE:2267,gEl:2a8c,gacute:1f5,gamma:3b3,gammad:3dd,gap:2a86,gbreve:11f,gcirc:11d,gcy:433,gdot:121,ge:2265,gel:22db,geq:2265,geqq:2267,geqslant:2a7e,ges:2a7e,gescc:2aa9,gesdot:2a80,gesdoto:2a82,gesdotol:2a84,gesl:22db+fe00,gesles:2a94,gfr:1d524,gg:226b,ggg:22d9,gimel:2137,gjcy:453,gl:2277,glE:2a92,gla:2aa5,glj:2aa4,gnE:2269,gnap:2a8a,gnapprox:2a8a,gne:2a88,gneq:2a88,gneqq:2269,gnsim:22e7,gopf:1d558,grave:60,gscr:210a,gsim:2273,gsime:2a8e,gsiml:2a90,gt:3e,gtcc:2aa7,gtcir:2a7a,gtdot:22d7,gtlPar:2995,gtquest:2a7c,gtrapprox:2a86,gtrarr:2978,gtrdot:22d7,gtreqless:22db,gtreqqless:2a8c,gtrless:2277,gtrsim:2273,gvertneqq:2269+fe00,gvnE:2269+fe00,hArr:21d4,hairsp:200a,half:bd,hamilt:210b,hardcy:44a,harr:2194,harrcir:2948,harrw:21ad,hbar:210f,hcirc:125,hearts:2665,heartsuit:2665,hellip:2026,hercon:22b9,hfr:1d525,hksearow:2925,hkswarow:2926,hoarr:21ff,homtht:223b,hookleftarrow:21a9,hookrightarrow:21aa,hopf:1d559,horbar:2015,hscr:1d4bd,hslash:210f,hstrok:127,hybull:2043,hyphen:2010,iacute:ed,ic:2063,icirc:ee,icy:438,iecy:435,iexcl:a1,iff:21d4,ifr:1d526,igrave:ec,ii:2148,iiiint:2a0c,iiint:222d,iinfin:29dc,iiota:2129,ijlig:133,imacr:12b,image:2111,imagline:2110,imagpart:2111,imath:131,imof:22b7,imped:1b5,in:2208,incare:2105,infin:221e,infintie:29dd,inodot:131,int:222b,intcal:22ba,integers:2124,intercal:22ba,intlarhk:2a17,intprod:2a3c,iocy:451,iogon:12f,iopf:1d55a,iota:3b9,iprod:2a3c,iquest:bf,iscr:1d4be,isin:2208,isinE:22f9,isindot:22f5,isins:22f4,isinsv:22f3,isinv:2208,it:2062,itilde:129,iukcy:456,iuml:ef,jcirc:135,jcy:439,jfr:1d527,jmath:237,jopf:1d55b,jscr:1d4bf,jsercy:458,jukcy:454,kappa:3ba,kappav:3f0,kcedil:137,kcy:43a,kfr:1d528,kgreen:138,khcy:445,kjcy:45c,kopf:1d55c,kscr:1d4c0,lAarr:21da,lArr:21d0,lAtail:291b,lBarr:290e,lE:2266,lEg:2a8b,lHar:2962,lacute:13a,laemptyv:29b4,lagran:2112,lambda:3bb,lang:27e8,langd:2991,langle:27e8,lap:2a85,laquo:ab,larr:2190,larrb:21e4,larrbfs:291f,larrfs:291d,larrhk:21a9,larrlp:21ab,larrpl:2939,larrsim:2973,larrtl:21a2,lat:2aab,latail:2919,late:2aad,lates:2aad+fe00,lbarr:290c,lbbrk:2772,lbrace:7b,lbrack:5b,lbrke:298b,lbrksld:298f,lbrkslu:298d,lcaron:13e,lcedil:13c,lceil:2308,lcub:7b,lcy:43b,ldca:2936,ldquo:201c,ldquor:201e,ldrdhar:2967,ldrushar:294b,ldsh:21b2,le:2264,leftarrow:2190,leftarrowtail:21a2,leftharpoondown:21bd,leftharpoonup:21bc,leftleftarrows:21c7,leftrightarrow:2194,leftrightarrows:21c6,leftrightharpoons:21cb,leftrightsquigarrow:21ad,leftthreetimes:22cb,leg:22da,leq:2264,leqq:2266,leqslant:2a7d,les:2a7d,lescc:2aa8,lesdot:2a7f,lesdoto:2a81,lesdotor:2a83,lesg:22da+fe00,lesges:2a93,lessapprox:2a85,lessdot:22d6,lesseqgtr:22da,lesseqqgtr:2a8b,lessgtr:2276,lesssim:2272,lfisht:297c,lfloor:230a,lfr:1d529,lg:2276,lgE:2a91,lhard:21bd,lharu:21bc,lharul:296a,lhblk:2584,ljcy:459,ll:226a,llarr:21c7,llcorner:231e,llhard:296b,lltri:25fa,lmidot:140,lmoust:23b0,lmoustache:23b0,lnE:2268,lnap:2a89,lnapprox:2a89,lne:2a87,lneq:2a87,lneqq:2268,lnsim:22e6,loang:27ec,loarr:21fd,lobrk:27e6,longleftarrow:27f5,longleftrightarrow:27f7,longmapsto:27fc,longrightarrow:27f6,looparrowleft:21ab,looparrowright:21ac,lopar:2985,lopf:1d55d,loplus:2a2d,lotimes:2a34,lowast:2217,lowbar:5f,loz:25ca,lozenge:25ca,lozf:29eb,lpar:28,lparlt:2993,lrarr:21c6,lrcorner:231f,lrhar:21cb,lrhard:296d,lrm:200e,lrtri:22bf,lsaquo:2039,lscr:1d4c1,lsh:21b0,lsim:2272,lsime:2a8d,lsimg:2a8f,lsqb:5b,lsquo:2018,lsquor:201a,lstrok:142,lt:3c,ltcc:2aa6,ltcir:2a79,ltdot:22d6,lthree:22cb,ltimes:22c9,ltlarr:2976,ltquest:2a7b,ltrPar:2996,ltri:25c3,ltrie:22b4,ltrif:25c2,lurdshar:294a,luruhar:2966,lvertneqq:2268+fe00,lvnE:2268+fe00,mDDot:223a,macr:af,male:2642,malt:2720,maltese:2720,map:21a6,mapsto:21a6,mapstodown:21a7,mapstoleft:21a4,mapstoup:21a5,marker:25ae,mcomma:2a29,mcy:43c,mdash:2014,measuredangle:2221,mfr:1d52a,mho:2127,micro:b5,mid:2223,midast:2a,midcir:2af0,middot:b7,minus:2212,minusb:229f,minusd:2238,minusdu:2a2a,mlcp:2adb,mldr:2026,mnplus:2213,models:22a7,mopf:1d55e,mp:2213,mscr:1d4c2,mstpos:223e,mu:3bc,multimap:22b8,mumap:22b8,nGg:22d9+338,nGt:226b+20d2,nGtv:226b+338,nLeftarrow:21cd,nLeftrightarrow:21ce,nLl:22d8+338,nLt:226a+20d2,nLtv:226a+338,nRightarrow:21cf,nVDash:22af,nVdash:22ae,nabla:2207,nacute:144,nang:2220+20d2,nap:2249,napE:2a70+338,napid:224b+338,napos:149,napprox:2249,natur:266e,natural:266e,naturals:2115,nbsp:a0,nbump:224e+338,nbumpe:224f+338,ncap:2a43,ncaron:148,ncedil:146,ncong:2247,ncongdot:2a6d+338,ncup:2a42,ncy:43d,ndash:2013,ne:2260,neArr:21d7,nearhk:2924,nearr:2197,nearrow:2197,nedot:2250+338,nequiv:2262,nesear:2928,nesim:2242+338,nexist:2204,nexists:2204,nfr:1d52b,ngE:2267+338,nge:2271,ngeq:2271,ngeqq:2267+338,ngeqslant:2a7e+338,nges:2a7e+338,ngsim:2275,ngt:226f,ngtr:226f,nhArr:21ce,nharr:21ae,nhpar:2af2,ni:220b,nis:22fc,nisd:22fa,niv:220b,njcy:45a,nlArr:21cd,nlE:2266+338,nlarr:219a,nldr:2025,nle:2270,nleftarrow:219a,nleftrightarrow:21ae,nleq:2270,nleqq:2266+338,nleqslant:2a7d+338,nles:2a7d+338,nless:226e,nlsim:2274,nlt:226e,nltri:22ea,nltrie:22ec,nmid:2224,nopf:1d55f,not:ac,notin:2209,notinE:22f9+338,notindot:22f5+338,notinva:2209,notinvb:22f7,notinvc:22f6,notni:220c,notniva:220c,notnivb:22fe,notnivc:22fd,npar:2226,nparallel:2226,nparsl:2afd+20e5,npart:2202+338,npolint:2a14,npr:2280,nprcue:22e0,npre:2aaf+338,nprec:2280,npreceq:2aaf+338,nrArr:21cf,nrarr:219b,nrarrc:2933+338,nrarrw:219d+338,nrightarrow:219b,nrtri:22eb,nrtrie:22ed,nsc:2281,nsccue:22e1,nsce:2ab0+338,nscr:1d4c3,nshortmid:2224,nshortparallel:2226,nsim:2241,nsime:2244,nsimeq:2244,nsmid:2224,nspar:2226,nsqsube:22e2,nsqsupe:22e3,nsub:2284,nsubE:2ac5+338,nsube:2288,nsubset:2282+20d2,nsubseteq:2288,nsubseteqq:2ac5+338,nsucc:2281,nsucceq:2ab0+338,nsup:2285,nsupE:2ac6+338,nsupe:2289,nsupset:2283+20d2,nsupseteq:2289,nsupseteqq:2ac6+338,ntgl:2279,ntilde:f1,ntlg:2278,ntriangleleft:22ea,ntrianglelefteq:22ec,ntriangleright:22eb,ntrianglerighteq:22ed,nu:3bd,num:23,numero:2116,numsp:2007,nvDash:22ad,nvHarr:2904,nvap:224d+20d2,nvdash:22ac,nvge:2265+20d2,nvgt:3e+20d2,nvinfin:29de,nvlArr:2902,nvle:2264+20d2,nvlt:3c+20d2,nvltrie:22b4+20d2,nvrArr:2903,nvrtrie:22b5+20d2,nvsim:223c+20d2,nwArr:21d6,nwarhk:2923,nwarr:2196,nwarrow:2196,nwnear:2927,oS:24c8,oacute:f3,oast:229b,ocir:229a,ocirc:f4,ocy:43e,odash:229d,odblac:151,odiv:2a38,odot:2299,odsold:29bc,oelig:153,ofcir:29bf,ofr:1d52c,ogon:2db,ograve:f2,ogt:29c1,ohbar:29b5,ohm:3a9,oint:222e,olarr:21ba,olcir:29be,olcross:29bb,oline:203e,olt:29c0,omacr:14d,omega:3c9,omicron:3bf,omid:29b6,ominus:2296,oopf:1d560,opar:29b7,operp:29b9,oplus:2295,or:2228,orarr:21bb,ord:2a5d,order:2134,orderof:2134,ordf:aa,ordm:ba,origof:22b6,oror:2a56,orslope:2a57,orv:2a5b,oscr:2134,oslash:f8,osol:2298,otilde:f5,otimes:2297,otimesas:2a36,ouml:f6,ovbar:233d,par:2225,para:b6,parallel:2225,parsim:2af3,parsl:2afd,part:2202,pcy:43f,percnt:25,period:2e,permil:2030,perp:22a5,pertenk:2031,pfr:1d52d,phi:3c6,phiv:3d5,phmmat:2133,phone:260e,pi:3c0,pitchfork:22d4,piv:3d6,planck:210f,planckh:210e,plankv:210f,plus:2b,plusacir:2a23,plusb:229e,pluscir:2a22,plusdo:2214,plusdu:2a25,pluse:2a72,plusmn:b1,plussim:2a26,plustwo:2a27,pm:b1,pointint:2a15,popf:1d561,pound:a3,pr:227a,prE:2ab3,prap:2ab7,prcue:227c,pre:2aaf,prec:227a,precapprox:2ab7,preccurlyeq:227c,preceq:2aaf,precnapprox:2ab9,precneqq:2ab5,precnsim:22e8,precsim:227e,prime:2032,primes:2119,prnE:2ab5,prnap:2ab9,prnsim:22e8,prod:220f,profalar:232e,profline:2312,profsurf:2313,prop:221d,propto:221d,prsim:227e,prurel:22b0,pscr:1d4c5,psi:3c8,puncsp:2008,qfr:1d52e,qint:2a0c,qopf:1d562,qprime:2057,qscr:1d4c6,quaternions:210d,quatint:2a16,quest:3f,questeq:225f,quot:22,rAarr:21db,rArr:21d2,rAtail:291c,rBarr:290f,rHar:2964,race:223d+331,racute:155,radic:221a,raemptyv:29b3,rang:27e9,rangd:2992,range:29a5,rangle:27e9,raquo:bb,rarr:2192,rarrap:2975,rarrb:21e5,rarrbfs:2920,rarrc:2933,rarrfs:291e,rarrhk:21aa,rarrlp:21ac,rarrpl:2945,rarrsim:2974,rarrtl:21a3,rarrw:219d,ratail:291a,ratio:2236,rationals:211a,rbarr:290d,rbbrk:2773,rbrace:7d,rbrack:5d,rbrke:298c,rbrksld:298e,rbrkslu:2990,rcaron:159,rcedil:157,rceil:2309,rcub:7d,rcy:440,rdca:2937,rdldhar:2969,rdquo:201d,rdquor:201d,rdsh:21b3,real:211c,realine:211b,realpart:211c,reals:211d,rect:25ad,reg:ae,rfisht:297d,rfloor:230b,rfr:1d52f,rhard:21c1,rharu:21c0,rharul:296c,rho:3c1,rhov:3f1,rightarrow:2192,rightarrowtail:21a3,rightharpoondown:21c1,rightharpoonup:21c0,rightleftarrows:21c4,rightleftharpoons:21cc,rightrightarrows:21c9,rightsquigarrow:219d,rightthreetimes:22cc,ring:2da,risingdotseq:2253,rlarr:21c4,rlhar:21cc,rlm:200f,rmoust:23b1,rmoustache:23b1,rnmid:2aee,roang:27ed,roarr:21fe,robrk:27e7,ropar:2986,ropf:1d563,roplus:2a2e,rotimes:2a35,rpar:29,rpargt:2994,rppolint:2a12,rrarr:21c9,rsaquo:203a,rscr:1d4c7,rsh:21b1,rsqb:5d,rsquo:2019,rsquor:2019,rthree:22cc,rtimes:22ca,rtri:25b9,rtrie:22b5,rtrif:25b8,rtriltri:29ce,ruluhar:2968,rx:211e,sacute:15b,sbquo:201a,sc:227b,scE:2ab4,scap:2ab8,scaron:161,sccue:227d,sce:2ab0,scedil:15f,scirc:15d,scnE:2ab6,scnap:2aba,scnsim:22e9,scpolint:2a13,scsim:227f,scy:441,sdot:22c5,sdotb:22a1,sdote:2a66,seArr:21d8,searhk:2925,searr:2198,searrow:2198,sect:a7,semi:3b,seswar:2929,setminus:2216,setmn:2216,sext:2736,sfr:1d530,sfrown:2322,sharp:266f,shchcy:449,shcy:448,shortmid:2223,shortparallel:2225,shy:ad,sigma:3c3,sigmaf:3c2,sigmav:3c2,sim:223c,simdot:2a6a,sime:2243,simeq:2243,simg:2a9e,simgE:2aa0,siml:2a9d,simlE:2a9f,simne:2246,simplus:2a24,simrarr:2972,slarr:2190,smallsetminus:2216,smashp:2a33,smeparsl:29e4,smid:2223,smile:2323,smt:2aaa,smte:2aac,smtes:2aac+fe00,softcy:44c,sol:2f,solb:29c4,solbar:233f,sopf:1d564,spades:2660,spadesuit:2660,spar:2225,sqcap:2293,sqcaps:2293+fe00,sqcup:2294,sqcups:2294+fe00,sqsub:228f,sqsube:2291,sqsubset:228f,sqsubseteq:2291,sqsup:2290,sqsupe:2292,sqsupset:2290,sqsupseteq:2292,squ:25a1,square:25a1,squarf:25aa,squf:25aa,srarr:2192,sscr:1d4c8,ssetmn:2216,ssmile:2323,sstarf:22c6,star:2606,starf:2605,straightepsilon:3f5,straightphi:3d5,strns:af,sub:2282,subE:2ac5,subdot:2abd,sube:2286,subedot:2ac3,submult:2ac1,subnE:2acb,subne:228a,subplus:2abf,subrarr:2979,subset:2282,subseteq:2286,subseteqq:2ac5,subsetneq:228a,subsetneqq:2acb,subsim:2ac7,subsub:2ad5,subsup:2ad3,succ:227b,succapprox:2ab8,succcurlyeq:227d,succeq:2ab0,succnapprox:2aba,succneqq:2ab6,succnsim:22e9,succsim:227f,sum:2211,sung:266a,sup:2283,sup1:b9,sup2:b2,sup3:b3,supE:2ac6,supdot:2abe,supdsub:2ad8,supe:2287,supedot:2ac4,suphsol:27c9,suphsub:2ad7,suplarr:297b,supmult:2ac2,supnE:2acc,supne:228b,supplus:2ac0,supset:2283,supseteq:2287,supseteqq:2ac6,supsetneq:228b,supsetneqq:2acc,supsim:2ac8,supsub:2ad4,supsup:2ad6,swArr:21d9,swarhk:2926,swarr:2199,swarrow:2199,swnwar:292a,szlig:df,target:2316,tau:3c4,tbrk:23b4,tcaron:165,tcedil:163,tcy:442,tdot:20db,telrec:2315,tfr:1d531,there4:2234,therefore:2234,theta:3b8,thetasym:3d1,thetav:3d1,thickapprox:2248,thicksim:223c,thinsp:2009,thkap:2248,thksim:223c,thorn:fe,tilde:2dc,times:d7,timesb:22a0,timesbar:2a31,timesd:2a30,tint:222d,toea:2928,top:22a4,topbot:2336,topcir:2af1,topf:1d565,topfork:2ada,tosa:2929,tprime:2034,trade:2122,triangle:25b5,triangledown:25bf,triangleleft:25c3,trianglelefteq:22b4,triangleq:225c,triangleright:25b9,trianglerighteq:22b5,tridot:25ec,trie:225c,triminus:2a3a,triplus:2a39,trisb:29cd,tritime:2a3b,trpezium:23e2,tscr:1d4c9,tscy:446,tshcy:45b,tstrok:167,twixt:226c,twoheadleftarrow:219e,twoheadrightarrow:21a0,uArr:21d1,uHar:2963,uacute:fa,uarr:2191,ubrcy:45e,ubreve:16d,ucirc:fb,ucy:443,udarr:21c5,udblac:171,udhar:296e,ufisht:297e,ufr:1d532,ugrave:f9,uharl:21bf,uharr:21be,uhblk:2580,ulcorn:231c,ulcorner:231c,ulcrop:230f,ultri:25f8,umacr:16b,uml:a8,uogon:173,uopf:1d566,uparrow:2191,updownarrow:2195,upharpoonleft:21bf,upharpoonright:21be,uplus:228e,upsi:3c5,upsih:3d2,upsilon:3c5,upuparrows:21c8,urcorn:231d,urcorner:231d,urcrop:230e,uring:16f,urtri:25f9,uscr:1d4ca,utdot:22f0,utilde:169,utri:25b5,utrif:25b4,uuarr:21c8,uuml:fc,uwangle:29a7,vArr:21d5,vBar:2ae8,vBarv:2ae9,vDash:22a8,vangrt:299c,varepsilon:3f5,varkappa:3f0,varnothing:2205,varphi:3d5,varpi:3d6,varpropto:221d,varr:2195,varrho:3f1,varsigma:3c2,varsubsetneq:228a+fe00,varsubsetneqq:2acb+fe00,varsupsetneq:228b+fe00,varsupsetneqq:2acc+fe00,vartheta:3d1,vartriangleleft:22b2,vartriangleright:22b3,vcy:432,vdash:22a2,vee:2228,veebar:22bb,veeeq:225a,vellip:22ee,verbar:7c,vert:7c,vfr:1d533,vltri:22b2,vnsub:2282+20d2,vnsup:2283+20d2,vopf:1d567,vprop:221d,vrtri:22b3,vscr:1d4cb,vsubnE:2acb+fe00,vsubne:228a+fe00,vsupnE:2acc+fe00,vsupne:228b+fe00,vzigzag:299a,wcirc:175,wedbar:2a5f,wedge:2227,wedgeq:2259,weierp:2118,wfr:1d534,wopf:1d568,wp:2118,wr:2240,wreath:2240,wscr:1d4cc,xcap:22c2,xcirc:25ef,xcup:22c3,xdtri:25bd,xfr:1d535,xhArr:27fa,xharr:27f7,xi:3be,xlArr:27f8,xlarr:27f5,xmap:27fc,xnis:22fb,xodot:2a00,xopf:1d569,xoplus:2a01,xotime:2a02,xrArr:27f9,xrarr:27f6,xscr:1d4cd,xsqcup:2a06,xuplus:2a04,xutri:25b3,xvee:22c1,xwedge:22c0,yacute:fd,yacy:44f,ycirc:177,ycy:44b,yen:a5,yfr:1d536,yicy:457,yopf:1d56a,yscr:1d4ce,yucy:44e,yuml:ff,zacute:17a,zcaron:17e,zcy:437,zdot:17c,zeetrf:2128,zeta:3b6,zfr:1d537,zhcy:436,zigrarr:21dd,zopf:1d56b,zscr:1d4cf,zwj:200d,zwnj:200c";
|
|
18
|
+
|
|
19
|
+
/** @type {Map<string, string>|null} */
|
|
20
|
+
let table = null;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The named character reference table, built on first use.
|
|
24
|
+
* @returns {Map<string, string>}
|
|
25
|
+
*/
|
|
26
|
+
export function namedEntities() {
|
|
27
|
+
if (table === null) {
|
|
28
|
+
table = new Map();
|
|
29
|
+
for (const entry of PACKED.split(',')) {
|
|
30
|
+
const at = entry.indexOf(':');
|
|
31
|
+
table.set(entry.slice(0, at), String.fromCodePoint(
|
|
32
|
+
...entry.slice(at + 1).split('+').map((hex) => parseInt(hex, 16))));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return table;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A character reference: named, decimal or hexadecimal. */
|
|
39
|
+
const RE_ENTITY = /^&(?:#[xX][0-9a-fA-F]{1,6};|#[0-9]{1,7};|[a-zA-Z][a-zA-Z0-9]{1,31};)/;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Decode one character reference at `pos` (`&...;`). Returns null when it
|
|
43
|
+
* is not a valid reference — an `&` that starts nothing is ordinary text,
|
|
44
|
+
* which is why this reports rather than throws.
|
|
45
|
+
* @param {string} src
|
|
46
|
+
* @param {number} pos
|
|
47
|
+
* @returns {{ value: string, end: number } | null}
|
|
48
|
+
*/
|
|
49
|
+
export function scanEntity(src, pos) {
|
|
50
|
+
const m = RE_ENTITY.exec(pos === 0 ? src : src.slice(pos));
|
|
51
|
+
if (m === null) return null;
|
|
52
|
+
const body = m[0].slice(1, -1);
|
|
53
|
+
if (body.charCodeAt(0) === 0x23 /* # */) {
|
|
54
|
+
const cp = body.charCodeAt(1) === 0x78 || body.charCodeAt(1) === 0x58
|
|
55
|
+
? parseInt(body.slice(2), 16)
|
|
56
|
+
: parseInt(body.slice(1), 10);
|
|
57
|
+
// U+0000 and out-of-range code points are the replacement character,
|
|
58
|
+
// never a thrown error: a document may contain anything
|
|
59
|
+
if (!Number.isFinite(cp) || cp === 0 || cp > 0x10FFFF)
|
|
60
|
+
return { value: '\uFFFD', end: pos + m[0].length };
|
|
61
|
+
return { value: String.fromCodePoint(cp), end: pos + m[0].length };
|
|
62
|
+
}
|
|
63
|
+
const named = namedEntities().get(body);
|
|
64
|
+
return named === undefined ? null : { value: named, end: pos + m[0].length };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Resolve backslash escapes and character references in a run of text.
|
|
69
|
+
*
|
|
70
|
+
* CommonMark processes both in the three places that are NOT inline
|
|
71
|
+
* content — link destinations, link titles and fence info strings — so
|
|
72
|
+
* they share this one pass rather than each re-deriving it.
|
|
73
|
+
* @param {string} text
|
|
74
|
+
* @returns {string}
|
|
75
|
+
*/
|
|
76
|
+
export function decodeReferences(text) {
|
|
77
|
+
if (text.indexOf('\\') === -1 && text.indexOf('&') === -1) return text;
|
|
78
|
+
let out = '';
|
|
79
|
+
let i = 0;
|
|
80
|
+
while (i < text.length) {
|
|
81
|
+
const code = text.charCodeAt(i);
|
|
82
|
+
if (code === 0x5C /* \\ */ && i + 1 < text.length && isEscapable(text.charCodeAt(i + 1))) {
|
|
83
|
+
out += text[i + 1];
|
|
84
|
+
i += 2;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (code === 0x26 /* & */) {
|
|
88
|
+
const entity = scanEntity(text, i);
|
|
89
|
+
if (entity !== null) {
|
|
90
|
+
out += entity.value;
|
|
91
|
+
i = entity.end;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
out += text[i];
|
|
96
|
+
i++;
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** ASCII punctuation — the only characters a backslash may escape. */
|
|
102
|
+
const ESCAPABLE = new Uint8Array(128);
|
|
103
|
+
for (const ch of '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~') ESCAPABLE[ch.charCodeAt(0)] = 1;
|
|
104
|
+
|
|
105
|
+
function isEscapable(code) {
|
|
106
|
+
return code < 128 && ESCAPABLE[code] === 1;
|
|
107
|
+
}
|
package/src/footnotes.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
/**
|
|
3
|
+
* @file GFM footnotes: which definitions a document actually cites, in
|
|
4
|
+
* which order, and what to call them.
|
|
5
|
+
*
|
|
6
|
+
* Definitions stay where the author wrote them (the AST is the
|
|
7
|
+
* document, not the rendering), so both emitters need the same answer to
|
|
8
|
+
* the same three questions before they emit anything: which definitions
|
|
9
|
+
* are cited, what number each one gets, and which identifiers the
|
|
10
|
+
* reference and its back-references carry. That answer lives here once —
|
|
11
|
+
* two emitters minting ids from two implementations is exactly how a
|
|
12
|
+
* back-reference ends up pointing at nothing.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { walkAst } from './ast.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @typedef {import('./ast.js').MdNode} MdNode
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {{ defs: MdNode[],
|
|
22
|
+
* numbers: Map<string, number>,
|
|
23
|
+
* counts: Map<string, number>,
|
|
24
|
+
* refs: WeakMap<MdNode, { number: number, occurrence: number }> }} Footnotes
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The default identifier prefix for footnotes — GitHub's own.
|
|
29
|
+
*
|
|
30
|
+
* Unlike a heading id (MD-FORMAT.md §4.5), which defaults to no prefix
|
|
31
|
+
* because CommonMark asserts a bare heading and the primary consumer is
|
|
32
|
+
* a document the host wrote, a footnote id is emitted by the DEFAULT
|
|
33
|
+
* rendering of a feature whose whole point is a link between two places
|
|
34
|
+
* on one page. No spec example asserts a bare `fn-1`, so the safe
|
|
35
|
+
* default costs nothing and a host page keeps its own `#fn-1` for
|
|
36
|
+
* itself. `slugPrefix`, when given, replaces it.
|
|
37
|
+
*/
|
|
38
|
+
export const FOOTNOTE_PREFIX = 'user-content-';
|
|
39
|
+
|
|
40
|
+
/** The back-reference glyph GitHub uses. */
|
|
41
|
+
export const BACKREF_MARK = '↩';
|
|
42
|
+
|
|
43
|
+
/** @type {WeakMap<MdNode[], Footnotes|null>} */
|
|
44
|
+
const collectMemo = new WeakMap();
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Collect a document's cited footnotes.
|
|
48
|
+
*
|
|
49
|
+
* Returns `null` when the AST holds no `footnoteDefinition` at all — the
|
|
50
|
+
* overwhelmingly common case, and the one that must cost nothing: the
|
|
51
|
+
* emitters compare that `null` to decide whether anything about footnote
|
|
52
|
+
* rendering can differ between two emissions.
|
|
53
|
+
*
|
|
54
|
+
* The result is memoized on the AST array, so re-rendering one document
|
|
55
|
+
* reuses it (and with it the vnode emitter's per-node memo); a
|
|
56
|
+
* transformed document is a different array and correctly gets fresh
|
|
57
|
+
* numbering.
|
|
58
|
+
*
|
|
59
|
+
* @param {MdNode[]} ast
|
|
60
|
+
* @returns {Footnotes|null}
|
|
61
|
+
*/
|
|
62
|
+
export function collectFootnotes(ast) {
|
|
63
|
+
const cached = collectMemo.get(ast);
|
|
64
|
+
if (cached !== undefined) return cached;
|
|
65
|
+
const result = collect(ast);
|
|
66
|
+
collectMemo.set(ast, result);
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Node types whose `children` are INLINE content. A footnote definition
|
|
72
|
+
* is a block, so it can never be inside one — and skipping them turns
|
|
73
|
+
* the discovery scan from a walk of every node in the document into a
|
|
74
|
+
* walk of its block skeleton. That matters because this scan runs on
|
|
75
|
+
* EVERY emission, including the overwhelming majority of documents that
|
|
76
|
+
* have no footnotes at all: profiled at ~6% of a 100 kB projection
|
|
77
|
+
* before this, which is a cost the feature has no right to impose on
|
|
78
|
+
* documents that do not use it.
|
|
79
|
+
*/
|
|
80
|
+
const INLINE_PARENTS = new Set(['paragraph', 'heading', 'tableCell']);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Find every footnote definition in a block tree, without descending
|
|
84
|
+
* into inline content.
|
|
85
|
+
* @param {MdNode[]} nodes @param {Map<string, MdNode>} byId
|
|
86
|
+
*/
|
|
87
|
+
function findDefinitions(nodes, byId) {
|
|
88
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
89
|
+
const node = nodes[i];
|
|
90
|
+
if (node.type === 'footnoteDefinition' && !byId.has(node.identifier)) {
|
|
91
|
+
byId.set(node.identifier, node);
|
|
92
|
+
}
|
|
93
|
+
const children = node.children;
|
|
94
|
+
if (Array.isArray(children) && !INLINE_PARENTS.has(node.type)) {
|
|
95
|
+
findDefinitions(children, byId);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @param {MdNode[]} ast
|
|
102
|
+
* @returns {Footnotes|null}
|
|
103
|
+
*/
|
|
104
|
+
function collect(ast) {
|
|
105
|
+
/** @type {Map<string, MdNode>} */
|
|
106
|
+
const byId = new Map();
|
|
107
|
+
findDefinitions(ast, byId);
|
|
108
|
+
if (byId.size === 0) return null;
|
|
109
|
+
|
|
110
|
+
/** @type {Footnotes} */
|
|
111
|
+
const found = {
|
|
112
|
+
defs: [],
|
|
113
|
+
numbers: new Map(),
|
|
114
|
+
counts: new Map(),
|
|
115
|
+
refs: new WeakMap(),
|
|
116
|
+
};
|
|
117
|
+
/** Definitions whose own content still has to be scanned. */
|
|
118
|
+
const pending = [];
|
|
119
|
+
|
|
120
|
+
/** @param {MdNode[]} root */
|
|
121
|
+
const scan = (root) => walkAst(root, (node) => {
|
|
122
|
+
// A definition is not rendered where it stands, so a reference
|
|
123
|
+
// inside one only counts once something cites the definition — which
|
|
124
|
+
// is what the queue below decides.
|
|
125
|
+
if (node.type === 'footnoteDefinition') return false;
|
|
126
|
+
if (node.type !== 'footnoteReference') return undefined;
|
|
127
|
+
const def = byId.get(node.identifier);
|
|
128
|
+
if (def === undefined) return undefined;
|
|
129
|
+
let number = found.numbers.get(node.identifier);
|
|
130
|
+
if (number === undefined) {
|
|
131
|
+
number = found.numbers.size + 1;
|
|
132
|
+
found.numbers.set(node.identifier, number);
|
|
133
|
+
found.defs.push(def);
|
|
134
|
+
pending.push(def);
|
|
135
|
+
}
|
|
136
|
+
const occurrence = (found.counts.get(node.identifier) ?? 0) + 1;
|
|
137
|
+
found.counts.set(node.identifier, occurrence);
|
|
138
|
+
if (!found.refs.has(node)) found.refs.set(node, { number, occurrence });
|
|
139
|
+
return undefined;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
scan(ast);
|
|
143
|
+
// A footnote may cite another. The queue grows as they are reached and
|
|
144
|
+
// a definition enters it at most once, so a cycle — even a footnote
|
|
145
|
+
// citing itself — terminates instead of unrolling.
|
|
146
|
+
for (let i = 0; i < pending.length; i++) scan(pending[i].children);
|
|
147
|
+
return found;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The `id` of a rendered footnote (the `<li>` in the section).
|
|
152
|
+
* @param {string} prefix @param {number} number
|
|
153
|
+
* @returns {string}
|
|
154
|
+
*/
|
|
155
|
+
export function footnoteId(prefix, number) {
|
|
156
|
+
return prefix + 'fn-' + number;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* The `id` of one citation. A footnote cited more than once needs one
|
|
161
|
+
* landing place per citation, or every back-reference would return the
|
|
162
|
+
* reader to the first.
|
|
163
|
+
* @param {string} prefix @param {number} number @param {number} occurrence
|
|
164
|
+
* @returns {string}
|
|
165
|
+
*/
|
|
166
|
+
export function footnoteRefId(prefix, number, occurrence) {
|
|
167
|
+
return prefix + 'fnref-' + number + (occurrence > 1 ? '-' + occurrence : '');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The accessible name of a back-reference: `↩` alone names nothing, and
|
|
172
|
+
* a footnote with several of them needs them told apart.
|
|
173
|
+
* @param {number} number @param {number} occurrence
|
|
174
|
+
* @returns {string}
|
|
175
|
+
*/
|
|
176
|
+
export function backrefLabel(number, occurrence) {
|
|
177
|
+
return occurrence > 1
|
|
178
|
+
? 'Back to reference ' + number + ', occurrence ' + occurrence
|
|
179
|
+
: 'Back to reference ' + number;
|
|
180
|
+
}
|