| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186 |
- /*!
- * Statum - client-side state library (markdown module).
- *
- * The CommonMark 0.31.2 engine (escape-first: raw source HTML is always
- * neutralised — see the security note above the engine) plus the
- * `stm-markdown` and `stm-h-demotion` bindings and the programmatic
- * `statum.markdown` API. The engine itself has no DOM references; only the
- * bindings touch elements.
- *
- * Load order: THIRD - requires statum-core.js (`window.statum._bridge`);
- * the `stm-markdown` handler orders itself after statum-document.js's
- * `stm-html`. (The attribute registry lives in statum-document.js; if that
- * module is absent, core queues the registration until it loads.) Like core:
- * an IIFE, no dependencies, no build step, plain script tag.
- */
- (function () {
- 'use strict';
- if (!window.statum || !window.statum._bridge) {
- console.error('[statum] statum-markdown.js requires statum-core.js');
- return;
- }
- var bridge = window.statum._bridge;
- var evalExpr = bridge.evalExpr;
- // ---------------------------------------------------------------------------
- // Markdown rendering (CommonMark 0.31.2)
- // ---------------------------------------------------------------------------
- //
- // A two-pass CommonMark engine: block structure first (paragraphs, ATX and
- // setext headings, thematic breaks, indented and fenced code blocks, block
- // quotes with lazy continuation, lists with tight/loose rendering and link
- // reference definitions), then inline parsing inside the leaf blocks
- // (delimiter-run emphasis, links and images, code spans, autolinks,
- // backslash escapes, entity references, hard/soft line breaks).
- //
- // SECURITY: the markdown source is untrusted text. Raw HTML is never passed
- // through — inline HTML and HTML-block-looking constructs render as escaped
- // text, which intentionally diverges from the CommonMark HTML output for
- // those examples. Link and image destinations are scheme-filtered by
- // safeMarkdownUrl() and everything is escaped before it reaches the output.
- function safeMarkdownUrl(url) {
- var u = url.trim();
- var m = u.match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);
- if (!m) return u;
- var scheme = m[1].toLowerCase();
- if (scheme === 'http' || scheme === 'https' || scheme === 'mailto' || scheme === 'ftp') return u;
- return '#';
- }
- /**
- * Packed HTML5 named-entity table (WHATWG `entities.json`, 2125 entries).
- * Each record is "name cp[,cp...]" on one line; multi-codepoint entities
- * carry comma-separated codepoints. Line breaks are escaped so the whole
- * table stays one string literal. Parsed lazily into a name -> text map the
- * first time an entity reference is looked up.
- */
- var MD_ENTITIES_PACKED = ''
- + "AElig 198\nAMP 38\nAacute 193\nAbreve 258\nAcirc 194\nAcy 1040\nAfr 120068\nAgrave 192\n"
- + "Alpha 913\nAmacr 256\nAnd 10835\nAogon 260\nAopf 120120\nApplyFunction 8289\nAring 197\n"
- + "Ascr 119964\nAssign 8788\nAtilde 195\nAuml 196\nBackslash 8726\nBarv 10983\nBarwed 8966\n"
- + "Bcy 1041\nBecause 8757\nBernoullis 8492\nBeta 914\nBfr 120069\nBopf 120121\nBreve 728\n"
- + "Bscr 8492\nBumpeq 8782\nCHcy 1063\nCOPY 169\nCacute 262\nCap 8914\n"
- + "CapitalDifferentialD 8517\nCayleys 8493\nCcaron 268\nCcedil 199\nCcirc 264\nCconint 8752\n"
- + "Cdot 266\nCedilla 184\nCenterDot 183\nCfr 8493\nChi 935\nCircleDot 8857\n"
- + "CircleMinus 8854\nCirclePlus 8853\nCircleTimes 8855\nClockwiseContourIntegral 8754\n"
- + "CloseCurlyDoubleQuote 8221\nCloseCurlyQuote 8217\nColon 8759\nColone 10868\n"
- + "Congruent 8801\nConint 8751\nContourIntegral 8750\nCopf 8450\nCoproduct 8720\n"
- + "CounterClockwiseContourIntegral 8755\nCross 10799\nCscr 119966\nCup 8915\nCupCap 8781\n"
- + "DD 8517\nDDotrahd 10513\nDJcy 1026\nDScy 1029\nDZcy 1039\nDagger 8225\nDarr 8609\n"
- + "Dashv 10980\nDcaron 270\nDcy 1044\nDel 8711\nDelta 916\nDfr 120071\nDiacriticalAcute 180\n"
- + "DiacriticalDot 729\nDiacriticalDoubleAcute 733\nDiacriticalGrave 96\n"
- + "DiacriticalTilde 732\nDiamond 8900\nDifferentialD 8518\nDopf 120123\nDot 168\n"
- + "DotDot 8412\nDotEqual 8784\nDoubleContourIntegral 8751\nDoubleDot 168\n"
- + "DoubleDownArrow 8659\nDoubleLeftArrow 8656\nDoubleLeftRightArrow 8660\n"
- + "DoubleLeftTee 10980\nDoubleLongLeftArrow 10232\nDoubleLongLeftRightArrow 10234\n"
- + "DoubleLongRightArrow 10233\nDoubleRightArrow 8658\nDoubleRightTee 8872\n"
- + "DoubleUpArrow 8657\nDoubleUpDownArrow 8661\nDoubleVerticalBar 8741\nDownArrow 8595\n"
- + "DownArrowBar 10515\nDownArrowUpArrow 8693\nDownBreve 785\nDownLeftRightVector 10576\n"
- + "DownLeftTeeVector 10590\nDownLeftVector 8637\nDownLeftVectorBar 10582\n"
- + "DownRightTeeVector 10591\nDownRightVector 8641\nDownRightVectorBar 10583\nDownTee 8868\n"
- + "DownTeeArrow 8615\nDownarrow 8659\nDscr 119967\nDstrok 272\nENG 330\nETH 208\nEacute 201\n"
- + "Ecaron 282\nEcirc 202\nEcy 1069\nEdot 278\nEfr 120072\nEgrave 200\nElement 8712\n"
- + "Emacr 274\nEmptySmallSquare 9723\nEmptyVerySmallSquare 9643\nEogon 280\nEopf 120124\n"
- + "Epsilon 917\nEqual 10869\nEqualTilde 8770\nEquilibrium 8652\nEscr 8496\nEsim 10867\n"
- + "Eta 919\nEuml 203\nExists 8707\nExponentialE 8519\nFcy 1060\nFfr 120073\n"
- + "FilledSmallSquare 9724\nFilledVerySmallSquare 9642\nFopf 120125\nForAll 8704\n"
- + "Fouriertrf 8497\nFscr 8497\nGJcy 1027\nGT 62\nGamma 915\nGammad 988\nGbreve 286\n"
- + "Gcedil 290\nGcirc 284\nGcy 1043\nGdot 288\nGfr 120074\nGg 8921\nGopf 120126\n"
- + "GreaterEqual 8805\nGreaterEqualLess 8923\nGreaterFullEqual 8807\nGreaterGreater 10914\n"
- + "GreaterLess 8823\nGreaterSlantEqual 10878\nGreaterTilde 8819\nGscr 119970\nGt 8811\n"
- + "HARDcy 1066\nHacek 711\nHat 94\nHcirc 292\nHfr 8460\nHilbertSpace 8459\nHopf 8461\n"
- + "HorizontalLine 9472\nHscr 8459\nHstrok 294\nHumpDownHump 8782\nHumpEqual 8783\nIEcy 1045\n"
- + "IJlig 306\nIOcy 1025\nIacute 205\nIcirc 206\nIcy 1048\nIdot 304\nIfr 8465\nIgrave 204\n"
- + "Im 8465\nImacr 298\nImaginaryI 8520\nImplies 8658\nInt 8748\nIntegral 8747\n"
- + "Intersection 8898\nInvisibleComma 8291\nInvisibleTimes 8290\nIogon 302\nIopf 120128\n"
- + "Iota 921\nIscr 8464\nItilde 296\nIukcy 1030\nIuml 207\nJcirc 308\nJcy 1049\nJfr 120077\n"
- + "Jopf 120129\nJscr 119973\nJsercy 1032\nJukcy 1028\nKHcy 1061\nKJcy 1036\nKappa 922\n"
- + "Kcedil 310\nKcy 1050\nKfr 120078\nKopf 120130\nKscr 119974\nLJcy 1033\nLT 60\nLacute 313\n"
- + "Lambda 923\nLang 10218\nLaplacetrf 8466\nLarr 8606\nLcaron 317\nLcedil 315\nLcy 1051\n"
- + "LeftAngleBracket 10216\nLeftArrow 8592\nLeftArrowBar 8676\nLeftArrowRightArrow 8646\n"
- + "LeftCeiling 8968\nLeftDoubleBracket 10214\nLeftDownTeeVector 10593\nLeftDownVector 8643\n"
- + "LeftDownVectorBar 10585\nLeftFloor 8970\nLeftRightArrow 8596\nLeftRightVector 10574\n"
- + "LeftTee 8867\nLeftTeeArrow 8612\nLeftTeeVector 10586\nLeftTriangle 8882\n"
- + "LeftTriangleBar 10703\nLeftTriangleEqual 8884\nLeftUpDownVector 10577\n"
- + "LeftUpTeeVector 10592\nLeftUpVector 8639\nLeftUpVectorBar 10584\nLeftVector 8636\n"
- + "LeftVectorBar 10578\nLeftarrow 8656\nLeftrightarrow 8660\nLessEqualGreater 8922\n"
- + "LessFullEqual 8806\nLessGreater 8822\nLessLess 10913\nLessSlantEqual 10877\n"
- + "LessTilde 8818\nLfr 120079\nLl 8920\nLleftarrow 8666\nLmidot 319\nLongLeftArrow 10229\n"
- + "LongLeftRightArrow 10231\nLongRightArrow 10230\nLongleftarrow 10232\n"
- + "Longleftrightarrow 10234\nLongrightarrow 10233\nLopf 120131\nLowerLeftArrow 8601\n"
- + "LowerRightArrow 8600\nLscr 8466\nLsh 8624\nLstrok 321\nLt 8810\nMap 10501\nMcy 1052\n"
- + "MediumSpace 8287\nMellintrf 8499\nMfr 120080\nMinusPlus 8723\nMopf 120132\nMscr 8499\n"
- + "Mu 924\nNJcy 1034\nNacute 323\nNcaron 327\nNcedil 325\nNcy 1053\n"
- + "NegativeMediumSpace 8203\nNegativeThickSpace 8203\nNegativeThinSpace 8203\n"
- + "NegativeVeryThinSpace 8203\nNestedGreaterGreater 8811\nNestedLessLess 8810\nNewLine 10\n"
- + "Nfr 120081\nNoBreak 8288\nNonBreakingSpace 160\nNopf 8469\nNot 10988\nNotCongruent 8802\n"
- + "NotCupCap 8813\nNotDoubleVerticalBar 8742\nNotElement 8713\nNotEqual 8800\n"
- + "NotEqualTilde 8770,824\nNotExists 8708\nNotGreater 8815\nNotGreaterEqual 8817\n"
- + "NotGreaterFullEqual 8807,824\nNotGreaterGreater 8811,824\nNotGreaterLess 8825\n"
- + "NotGreaterSlantEqual 10878,824\nNotGreaterTilde 8821\nNotHumpDownHump 8782,824\n"
- + "NotHumpEqual 8783,824\nNotLeftTriangle 8938\nNotLeftTriangleBar 10703,824\n"
- + "NotLeftTriangleEqual 8940\nNotLess 8814\nNotLessEqual 8816\nNotLessGreater 8824\n"
- + "NotLessLess 8810,824\nNotLessSlantEqual 10877,824\nNotLessTilde 8820\n"
- + "NotNestedGreaterGreater 10914,824\nNotNestedLessLess 10913,824\nNotPrecedes 8832\n"
- + "NotPrecedesEqual 10927,824\nNotPrecedesSlantEqual 8928\nNotReverseElement 8716\n"
- + "NotRightTriangle 8939\nNotRightTriangleBar 10704,824\nNotRightTriangleEqual 8941\n"
- + "NotSquareSubset 8847,824\nNotSquareSubsetEqual 8930\nNotSquareSuperset 8848,824\n"
- + "NotSquareSupersetEqual 8931\nNotSubset 8834,8402\nNotSubsetEqual 8840\nNotSucceeds 8833\n"
- + "NotSucceedsEqual 10928,824\nNotSucceedsSlantEqual 8929\nNotSucceedsTilde 8831,824\n"
- + "NotSuperset 8835,8402\nNotSupersetEqual 8841\nNotTilde 8769\nNotTildeEqual 8772\n"
- + "NotTildeFullEqual 8775\nNotTildeTilde 8777\nNotVerticalBar 8740\nNscr 119977\nNtilde 209\n"
- + "Nu 925\nOElig 338\nOacute 211\nOcirc 212\nOcy 1054\nOdblac 336\nOfr 120082\nOgrave 210\n"
- + "Omacr 332\nOmega 937\nOmicron 927\nOopf 120134\nOpenCurlyDoubleQuote 8220\n"
- + "OpenCurlyQuote 8216\nOr 10836\nOscr 119978\nOslash 216\nOtilde 213\nOtimes 10807\n"
- + "Ouml 214\nOverBar 8254\nOverBrace 9182\nOverBracket 9140\nOverParenthesis 9180\n"
- + "PartialD 8706\nPcy 1055\nPfr 120083\nPhi 934\nPi 928\nPlusMinus 177\nPoincareplane 8460\n"
- + "Popf 8473\nPr 10939\nPrecedes 8826\nPrecedesEqual 10927\nPrecedesSlantEqual 8828\n"
- + "PrecedesTilde 8830\nPrime 8243\nProduct 8719\nProportion 8759\nProportional 8733\n"
- + "Pscr 119979\nPsi 936\nQUOT 34\nQfr 120084\nQopf 8474\nQscr 119980\nRBarr 10512\nREG 174\n"
- + "Racute 340\nRang 10219\nRarr 8608\nRarrtl 10518\nRcaron 344\nRcedil 342\nRcy 1056\n"
- + "Re 8476\nReverseElement 8715\nReverseEquilibrium 8651\nReverseUpEquilibrium 10607\n"
- + "Rfr 8476\nRho 929\nRightAngleBracket 10217\nRightArrow 8594\nRightArrowBar 8677\n"
- + "RightArrowLeftArrow 8644\nRightCeiling 8969\nRightDoubleBracket 10215\n"
- + "RightDownTeeVector 10589\nRightDownVector 8642\nRightDownVectorBar 10581\n"
- + "RightFloor 8971\nRightTee 8866\nRightTeeArrow 8614\nRightTeeVector 10587\n"
- + "RightTriangle 8883\nRightTriangleBar 10704\nRightTriangleEqual 8885\n"
- + "RightUpDownVector 10575\nRightUpTeeVector 10588\nRightUpVector 8638\n"
- + "RightUpVectorBar 10580\nRightVector 8640\nRightVectorBar 10579\nRightarrow 8658\n"
- + "Ropf 8477\nRoundImplies 10608\nRrightarrow 8667\nRscr 8475\nRsh 8625\nRuleDelayed 10740\n"
- + "SHCHcy 1065\nSHcy 1064\nSOFTcy 1068\nSacute 346\nSc 10940\nScaron 352\nScedil 350\n"
- + "Scirc 348\nScy 1057\nSfr 120086\nShortDownArrow 8595\nShortLeftArrow 8592\n"
- + "ShortRightArrow 8594\nShortUpArrow 8593\nSigma 931\nSmallCircle 8728\nSopf 120138\n"
- + "Sqrt 8730\nSquare 9633\nSquareIntersection 8851\nSquareSubset 8847\n"
- + "SquareSubsetEqual 8849\nSquareSuperset 8848\nSquareSupersetEqual 8850\nSquareUnion 8852\n"
- + "Sscr 119982\nStar 8902\nSub 8912\nSubset 8912\nSubsetEqual 8838\nSucceeds 8827\n"
- + "SucceedsEqual 10928\nSucceedsSlantEqual 8829\nSucceedsTilde 8831\nSuchThat 8715\n"
- + "Sum 8721\nSup 8913\nSuperset 8835\nSupersetEqual 8839\nSupset 8913\nTHORN 222\n"
- + "TRADE 8482\nTSHcy 1035\nTScy 1062\nTab 9\nTau 932\nTcaron 356\nTcedil 354\nTcy 1058\n"
- + "Tfr 120087\nTherefore 8756\nTheta 920\nThickSpace 8287,8202\nThinSpace 8201\nTilde 8764\n"
- + "TildeEqual 8771\nTildeFullEqual 8773\nTildeTilde 8776\nTopf 120139\nTripleDot 8411\n"
- + "Tscr 119983\nTstrok 358\nUacute 218\nUarr 8607\nUarrocir 10569\nUbrcy 1038\nUbreve 364\n"
- + "Ucirc 219\nUcy 1059\nUdblac 368\nUfr 120088\nUgrave 217\nUmacr 362\nUnderBar 95\n"
- + "UnderBrace 9183\nUnderBracket 9141\nUnderParenthesis 9181\nUnion 8899\nUnionPlus 8846\n"
- + "Uogon 370\nUopf 120140\nUpArrow 8593\nUpArrowBar 10514\nUpArrowDownArrow 8645\n"
- + "UpDownArrow 8597\nUpEquilibrium 10606\nUpTee 8869\nUpTeeArrow 8613\nUparrow 8657\n"
- + "Updownarrow 8661\nUpperLeftArrow 8598\nUpperRightArrow 8599\nUpsi 978\nUpsilon 933\n"
- + "Uring 366\nUscr 119984\nUtilde 360\nUuml 220\nVDash 8875\nVbar 10987\nVcy 1042\n"
- + "Vdash 8873\nVdashl 10982\nVee 8897\nVerbar 8214\nVert 8214\nVerticalBar 8739\n"
- + "VerticalLine 124\nVerticalSeparator 10072\nVerticalTilde 8768\nVeryThinSpace 8202\n"
- + "Vfr 120089\nVopf 120141\nVscr 119985\nVvdash 8874\nWcirc 372\nWedge 8896\nWfr 120090\n"
- + "Wopf 120142\nWscr 119986\nXfr 120091\nXi 926\nXopf 120143\nXscr 119987\nYAcy 1071\n"
- + "YIcy 1031\nYUcy 1070\nYacute 221\nYcirc 374\nYcy 1067\nYfr 120092\nYopf 120144\n"
- + "Yscr 119988\nYuml 376\nZHcy 1046\nZacute 377\nZcaron 381\nZcy 1047\nZdot 379\n"
- + "ZeroWidthSpace 8203\nZeta 918\nZfr 8488\nZopf 8484\nZscr 119989\naacute 225\nabreve 259\n"
- + "ac 8766\nacE 8766,819\nacd 8767\nacirc 226\nacute 180\nacy 1072\naelig 230\naf 8289\n"
- + "afr 120094\nagrave 224\nalefsym 8501\naleph 8501\nalpha 945\namacr 257\namalg 10815\n"
- + "amp 38\nand 8743\nandand 10837\nandd 10844\nandslope 10840\nandv 10842\nang 8736\n"
- + "ange 10660\nangle 8736\nangmsd 8737\nangmsdaa 10664\nangmsdab 10665\nangmsdac 10666\n"
- + "angmsdad 10667\nangmsdae 10668\nangmsdaf 10669\nangmsdag 10670\nangmsdah 10671\n"
- + "angrt 8735\nangrtvb 8894\nangrtvbd 10653\nangsph 8738\nangst 197\nangzarr 9084\n"
- + "aogon 261\naopf 120146\nap 8776\napE 10864\napacir 10863\nape 8778\napid 8779\napos 39\n"
- + "approx 8776\napproxeq 8778\naring 229\nascr 119990\nast 42\nasymp 8776\nasympeq 8781\n"
- + "atilde 227\nauml 228\nawconint 8755\nawint 10769\nbNot 10989\nbackcong 8780\n"
- + "backepsilon 1014\nbackprime 8245\nbacksim 8765\nbacksimeq 8909\nbarvee 8893\nbarwed 8965\n"
- + "barwedge 8965\nbbrk 9141\nbbrktbrk 9142\nbcong 8780\nbcy 1073\nbdquo 8222\nbecaus 8757\n"
- + "because 8757\nbemptyv 10672\nbepsi 1014\nbernou 8492\nbeta 946\nbeth 8502\nbetween 8812\n"
- + "bfr 120095\nbigcap 8898\nbigcirc 9711\nbigcup 8899\nbigodot 10752\nbigoplus 10753\n"
- + "bigotimes 10754\nbigsqcup 10758\nbigstar 9733\nbigtriangledown 9661\nbigtriangleup 9651\n"
- + "biguplus 10756\nbigvee 8897\nbigwedge 8896\nbkarow 10509\nblacklozenge 10731\n"
- + "blacksquare 9642\nblacktriangle 9652\nblacktriangledown 9662\nblacktriangleleft 9666\n"
- + "blacktriangleright 9656\nblank 9251\nblk12 9618\nblk14 9617\nblk34 9619\nblock 9608\n"
- + "bne 61,8421\nbnequiv 8801,8421\nbnot 8976\nbopf 120147\nbot 8869\nbottom 8869\n"
- + "bowtie 8904\nboxDL 9559\nboxDR 9556\nboxDl 9558\nboxDr 9555\nboxH 9552\nboxHD 9574\n"
- + "boxHU 9577\nboxHd 9572\nboxHu 9575\nboxUL 9565\nboxUR 9562\nboxUl 9564\nboxUr 9561\n"
- + "boxV 9553\nboxVH 9580\nboxVL 9571\nboxVR 9568\nboxVh 9579\nboxVl 9570\nboxVr 9567\n"
- + "boxbox 10697\nboxdL 9557\nboxdR 9554\nboxdl 9488\nboxdr 9484\nboxh 9472\nboxhD 9573\n"
- + "boxhU 9576\nboxhd 9516\nboxhu 9524\nboxminus 8863\nboxplus 8862\nboxtimes 8864\n"
- + "boxuL 9563\nboxuR 9560\nboxul 9496\nboxur 9492\nboxv 9474\nboxvH 9578\nboxvL 9569\n"
- + "boxvR 9566\nboxvh 9532\nboxvl 9508\nboxvr 9500\nbprime 8245\nbreve 728\nbrvbar 166\n"
- + "bscr 119991\nbsemi 8271\nbsim 8765\nbsime 8909\nbsol 92\nbsolb 10693\nbsolhsub 10184\n"
- + "bull 8226\nbullet 8226\nbump 8782\nbumpE 10926\nbumpe 8783\nbumpeq 8783\ncacute 263\n"
- + "cap 8745\ncapand 10820\ncapbrcup 10825\ncapcap 10827\ncapcup 10823\ncapdot 10816\n"
- + "caps 8745,65024\ncaret 8257\ncaron 711\nccaps 10829\nccaron 269\nccedil 231\nccirc 265\n"
- + "ccups 10828\nccupssm 10832\ncdot 267\ncedil 184\ncemptyv 10674\ncent 162\ncenterdot 183\n"
- + "cfr 120096\nchcy 1095\ncheck 10003\ncheckmark 10003\nchi 967\ncir 9675\ncirE 10691\n"
- + "circ 710\ncirceq 8791\ncirclearrowleft 8634\ncirclearrowright 8635\ncircledR 174\n"
- + "circledS 9416\ncircledast 8859\ncircledcirc 8858\ncircleddash 8861\ncire 8791\n"
- + "cirfnint 10768\ncirmid 10991\ncirscir 10690\nclubs 9827\nclubsuit 9827\ncolon 58\n"
- + "colone 8788\ncoloneq 8788\ncomma 44\ncommat 64\ncomp 8705\ncompfn 8728\ncomplement 8705\n"
- + "complexes 8450\ncong 8773\ncongdot 10861\nconint 8750\ncopf 120148\ncoprod 8720\n"
- + "copy 169\ncopysr 8471\ncrarr 8629\ncross 10007\ncscr 119992\ncsub 10959\ncsube 10961\n"
- + "csup 10960\ncsupe 10962\nctdot 8943\ncudarrl 10552\ncudarrr 10549\ncuepr 8926\n"
- + "cuesc 8927\ncularr 8630\ncularrp 10557\ncup 8746\ncupbrcap 10824\ncupcap 10822\n"
- + "cupcup 10826\ncupdot 8845\ncupor 10821\ncups 8746,65024\ncurarr 8631\ncurarrm 10556\n"
- + "curlyeqprec 8926\ncurlyeqsucc 8927\ncurlyvee 8910\ncurlywedge 8911\ncurren 164\n"
- + "curvearrowleft 8630\ncurvearrowright 8631\ncuvee 8910\ncuwed 8911\ncwconint 8754\n"
- + "cwint 8753\ncylcty 9005\ndArr 8659\ndHar 10597\ndagger 8224\ndaleth 8504\ndarr 8595\n"
- + "dash 8208\ndashv 8867\ndbkarow 10511\ndblac 733\ndcaron 271\ndcy 1076\ndd 8518\n"
- + "ddagger 8225\nddarr 8650\nddotseq 10871\ndeg 176\ndelta 948\ndemptyv 10673\ndfisht 10623\n"
- + "dfr 120097\ndharl 8643\ndharr 8642\ndiam 8900\ndiamond 8900\ndiamondsuit 9830\n"
- + "diams 9830\ndie 168\ndigamma 989\ndisin 8946\ndiv 247\ndivide 247\ndivideontimes 8903\n"
- + "divonx 8903\ndjcy 1106\ndlcorn 8990\ndlcrop 8973\ndollar 36\ndopf 120149\ndot 729\n"
- + "doteq 8784\ndoteqdot 8785\ndotminus 8760\ndotplus 8724\ndotsquare 8865\n"
- + "doublebarwedge 8966\ndownarrow 8595\ndowndownarrows 8650\ndownharpoonleft 8643\n"
- + "downharpoonright 8642\ndrbkarow 10512\ndrcorn 8991\ndrcrop 8972\ndscr 119993\ndscy 1109\n"
- + "dsol 10742\ndstrok 273\ndtdot 8945\ndtri 9663\ndtrif 9662\nduarr 8693\nduhar 10607\n"
- + "dwangle 10662\ndzcy 1119\ndzigrarr 10239\neDDot 10871\neDot 8785\neacute 233\n"
- + "easter 10862\necaron 283\necir 8790\necirc 234\necolon 8789\necy 1101\nedot 279\nee 8519\n"
- + "efDot 8786\nefr 120098\neg 10906\negrave 232\negs 10902\negsdot 10904\nel 10905\n"
- + "elinters 9191\nell 8467\nels 10901\nelsdot 10903\nemacr 275\nempty 8709\nemptyset 8709\n"
- + "emptyv 8709\nemsp 8195\nemsp13 8196\nemsp14 8197\neng 331\nensp 8194\neogon 281\n"
- + "eopf 120150\nepar 8917\neparsl 10723\neplus 10865\nepsi 949\nepsilon 949\nepsiv 1013\n"
- + "eqcirc 8790\neqcolon 8789\neqsim 8770\neqslantgtr 10902\neqslantless 10901\nequals 61\n"
- + "equest 8799\nequiv 8801\nequivDD 10872\neqvparsl 10725\nerDot 8787\nerarr 10609\n"
- + "escr 8495\nesdot 8784\nesim 8770\neta 951\neth 240\neuml 235\neuro 8364\nexcl 33\n"
- + "exist 8707\nexpectation 8496\nexponentiale 8519\nfallingdotseq 8786\nfcy 1092\n"
- + "female 9792\nffilig 64259\nfflig 64256\nffllig 64260\nffr 120099\nfilig 64257\n"
- + "fjlig 102,106\nflat 9837\nfllig 64258\nfltns 9649\nfnof 402\nfopf 120151\nforall 8704\n"
- + "fork 8916\nforkv 10969\nfpartint 10765\nfrac12 189\nfrac13 8531\nfrac14 188\nfrac15 8533\n"
- + "frac16 8537\nfrac18 8539\nfrac23 8532\nfrac25 8534\nfrac34 190\nfrac35 8535\nfrac38 8540\n"
- + "frac45 8536\nfrac56 8538\nfrac58 8541\nfrac78 8542\nfrasl 8260\nfrown 8994\nfscr 119995\n"
- + "gE 8807\ngEl 10892\ngacute 501\ngamma 947\ngammad 989\ngap 10886\ngbreve 287\ngcirc 285\n"
- + "gcy 1075\ngdot 289\nge 8805\ngel 8923\ngeq 8805\ngeqq 8807\ngeqslant 10878\nges 10878\n"
- + "gescc 10921\ngesdot 10880\ngesdoto 10882\ngesdotol 10884\ngesl 8923,65024\ngesles 10900\n"
- + "gfr 120100\ngg 8811\nggg 8921\ngimel 8503\ngjcy 1107\ngl 8823\nglE 10898\ngla 10917\n"
- + "glj 10916\ngnE 8809\ngnap 10890\ngnapprox 10890\ngne 10888\ngneq 10888\ngneqq 8809\n"
- + "gnsim 8935\ngopf 120152\ngrave 96\ngscr 8458\ngsim 8819\ngsime 10894\ngsiml 10896\ngt 62\n"
- + "gtcc 10919\ngtcir 10874\ngtdot 8919\ngtlPar 10645\ngtquest 10876\ngtrapprox 10886\n"
- + "gtrarr 10616\ngtrdot 8919\ngtreqless 8923\ngtreqqless 10892\ngtrless 8823\ngtrsim 8819\n"
- + "gvertneqq 8809,65024\ngvnE 8809,65024\nhArr 8660\nhairsp 8202\nhalf 189\nhamilt 8459\n"
- + "hardcy 1098\nharr 8596\nharrcir 10568\nharrw 8621\nhbar 8463\nhcirc 293\nhearts 9829\n"
- + "heartsuit 9829\nhellip 8230\nhercon 8889\nhfr 120101\nhksearow 10533\nhkswarow 10534\n"
- + "hoarr 8703\nhomtht 8763\nhookleftarrow 8617\nhookrightarrow 8618\nhopf 120153\n"
- + "horbar 8213\nhscr 119997\nhslash 8463\nhstrok 295\nhybull 8259\nhyphen 8208\niacute 237\n"
- + "ic 8291\nicirc 238\nicy 1080\niecy 1077\niexcl 161\niff 8660\nifr 120102\nigrave 236\n"
- + "ii 8520\niiiint 10764\niiint 8749\niinfin 10716\niiota 8489\nijlig 307\nimacr 299\n"
- + "image 8465\nimagline 8464\nimagpart 8465\nimath 305\nimof 8887\nimped 437\nin 8712\n"
- + "incare 8453\ninfin 8734\ninfintie 10717\ninodot 305\nint 8747\nintcal 8890\n"
- + "integers 8484\nintercal 8890\nintlarhk 10775\nintprod 10812\niocy 1105\niogon 303\n"
- + "iopf 120154\niota 953\niprod 10812\niquest 191\niscr 119998\nisin 8712\nisinE 8953\n"
- + "isindot 8949\nisins 8948\nisinsv 8947\nisinv 8712\nit 8290\nitilde 297\niukcy 1110\n"
- + "iuml 239\njcirc 309\njcy 1081\njfr 120103\njmath 567\njopf 120155\njscr 119999\n"
- + "jsercy 1112\njukcy 1108\nkappa 954\nkappav 1008\nkcedil 311\nkcy 1082\nkfr 120104\n"
- + "kgreen 312\nkhcy 1093\nkjcy 1116\nkopf 120156\nkscr 120000\nlAarr 8666\nlArr 8656\n"
- + "lAtail 10523\nlBarr 10510\nlE 8806\nlEg 10891\nlHar 10594\nlacute 314\nlaemptyv 10676\n"
- + "lagran 8466\nlambda 955\nlang 10216\nlangd 10641\nlangle 10216\nlap 10885\nlaquo 171\n"
- + "larr 8592\nlarrb 8676\nlarrbfs 10527\nlarrfs 10525\nlarrhk 8617\nlarrlp 8619\n"
- + "larrpl 10553\nlarrsim 10611\nlarrtl 8610\nlat 10923\nlatail 10521\nlate 10925\n"
- + "lates 10925,65024\nlbarr 10508\nlbbrk 10098\nlbrace 123\nlbrack 91\nlbrke 10635\n"
- + "lbrksld 10639\nlbrkslu 10637\nlcaron 318\nlcedil 316\nlceil 8968\nlcub 123\nlcy 1083\n"
- + "ldca 10550\nldquo 8220\nldquor 8222\nldrdhar 10599\nldrushar 10571\nldsh 8626\nle 8804\n"
- + "leftarrow 8592\nleftarrowtail 8610\nleftharpoondown 8637\nleftharpoonup 8636\n"
- + "leftleftarrows 8647\nleftrightarrow 8596\nleftrightarrows 8646\nleftrightharpoons 8651\n"
- + "leftrightsquigarrow 8621\nleftthreetimes 8907\nleg 8922\nleq 8804\nleqq 8806\n"
- + "leqslant 10877\nles 10877\nlescc 10920\nlesdot 10879\nlesdoto 10881\nlesdotor 10883\n"
- + "lesg 8922,65024\nlesges 10899\nlessapprox 10885\nlessdot 8918\nlesseqgtr 8922\n"
- + "lesseqqgtr 10891\nlessgtr 8822\nlesssim 8818\nlfisht 10620\nlfloor 8970\nlfr 120105\n"
- + "lg 8822\nlgE 10897\nlhard 8637\nlharu 8636\nlharul 10602\nlhblk 9604\nljcy 1113\nll 8810\n"
- + "llarr 8647\nllcorner 8990\nllhard 10603\nlltri 9722\nlmidot 320\nlmoust 9136\n"
- + "lmoustache 9136\nlnE 8808\nlnap 10889\nlnapprox 10889\nlne 10887\nlneq 10887\nlneqq 8808\n"
- + "lnsim 8934\nloang 10220\nloarr 8701\nlobrk 10214\nlongleftarrow 10229\n"
- + "longleftrightarrow 10231\nlongmapsto 10236\nlongrightarrow 10230\nlooparrowleft 8619\n"
- + "looparrowright 8620\nlopar 10629\nlopf 120157\nloplus 10797\nlotimes 10804\nlowast 8727\n"
- + "lowbar 95\nloz 9674\nlozenge 9674\nlozf 10731\nlpar 40\nlparlt 10643\nlrarr 8646\n"
- + "lrcorner 8991\nlrhar 8651\nlrhard 10605\nlrm 8206\nlrtri 8895\nlsaquo 8249\nlscr 120001\n"
- + "lsh 8624\nlsim 8818\nlsime 10893\nlsimg 10895\nlsqb 91\nlsquo 8216\nlsquor 8218\n"
- + "lstrok 322\nlt 60\nltcc 10918\nltcir 10873\nltdot 8918\nlthree 8907\nltimes 8905\n"
- + "ltlarr 10614\nltquest 10875\nltrPar 10646\nltri 9667\nltrie 8884\nltrif 9666\n"
- + "lurdshar 10570\nluruhar 10598\nlvertneqq 8808,65024\nlvnE 8808,65024\nmDDot 8762\n"
- + "macr 175\nmale 9794\nmalt 10016\nmaltese 10016\nmap 8614\nmapsto 8614\nmapstodown 8615\n"
- + "mapstoleft 8612\nmapstoup 8613\nmarker 9646\nmcomma 10793\nmcy 1084\nmdash 8212\n"
- + "measuredangle 8737\nmfr 120106\nmho 8487\nmicro 181\nmid 8739\nmidast 42\nmidcir 10992\n"
- + "middot 183\nminus 8722\nminusb 8863\nminusd 8760\nminusdu 10794\nmlcp 10971\nmldr 8230\n"
- + "mnplus 8723\nmodels 8871\nmopf 120158\nmp 8723\nmscr 120002\nmstpos 8766\nmu 956\n"
- + "multimap 8888\nmumap 8888\nnGg 8921,824\nnGt 8811,8402\nnGtv 8811,824\nnLeftarrow 8653\n"
- + "nLeftrightarrow 8654\nnLl 8920,824\nnLt 8810,8402\nnLtv 8810,824\nnRightarrow 8655\n"
- + "nVDash 8879\nnVdash 8878\nnabla 8711\nnacute 324\nnang 8736,8402\nnap 8777\n"
- + "napE 10864,824\nnapid 8779,824\nnapos 329\nnapprox 8777\nnatur 9838\nnatural 9838\n"
- + "naturals 8469\nnbsp 160\nnbump 8782,824\nnbumpe 8783,824\nncap 10819\nncaron 328\n"
- + "ncedil 326\nncong 8775\nncongdot 10861,824\nncup 10818\nncy 1085\nndash 8211\nne 8800\n"
- + "neArr 8663\nnearhk 10532\nnearr 8599\nnearrow 8599\nnedot 8784,824\nnequiv 8802\n"
- + "nesear 10536\nnesim 8770,824\nnexist 8708\nnexists 8708\nnfr 120107\nngE 8807,824\n"
- + "nge 8817\nngeq 8817\nngeqq 8807,824\nngeqslant 10878,824\nnges 10878,824\nngsim 8821\n"
- + "ngt 8815\nngtr 8815\nnhArr 8654\nnharr 8622\nnhpar 10994\nni 8715\nnis 8956\nnisd 8954\n"
- + "niv 8715\nnjcy 1114\nnlArr 8653\nnlE 8806,824\nnlarr 8602\nnldr 8229\nnle 8816\n"
- + "nleftarrow 8602\nnleftrightarrow 8622\nnleq 8816\nnleqq 8806,824\nnleqslant 10877,824\n"
- + "nles 10877,824\nnless 8814\nnlsim 8820\nnlt 8814\nnltri 8938\nnltrie 8940\nnmid 8740\n"
- + "nopf 120159\nnot 172\nnotin 8713\nnotinE 8953,824\nnotindot 8949,824\nnotinva 8713\n"
- + "notinvb 8951\nnotinvc 8950\nnotni 8716\nnotniva 8716\nnotnivb 8958\nnotnivc 8957\n"
- + "npar 8742\nnparallel 8742\nnparsl 11005,8421\nnpart 8706,824\nnpolint 10772\nnpr 8832\n"
- + "nprcue 8928\nnpre 10927,824\nnprec 8832\nnpreceq 10927,824\nnrArr 8655\nnrarr 8603\n"
- + "nrarrc 10547,824\nnrarrw 8605,824\nnrightarrow 8603\nnrtri 8939\nnrtrie 8941\nnsc 8833\n"
- + "nsccue 8929\nnsce 10928,824\nnscr 120003\nnshortmid 8740\nnshortparallel 8742\nnsim 8769\n"
- + "nsime 8772\nnsimeq 8772\nnsmid 8740\nnspar 8742\nnsqsube 8930\nnsqsupe 8931\nnsub 8836\n"
- + "nsubE 10949,824\nnsube 8840\nnsubset 8834,8402\nnsubseteq 8840\nnsubseteqq 10949,824\n"
- + "nsucc 8833\nnsucceq 10928,824\nnsup 8837\nnsupE 10950,824\nnsupe 8841\nnsupset 8835,8402\n"
- + "nsupseteq 8841\nnsupseteqq 10950,824\nntgl 8825\nntilde 241\nntlg 8824\n"
- + "ntriangleleft 8938\nntrianglelefteq 8940\nntriangleright 8939\nntrianglerighteq 8941\n"
- + "nu 957\nnum 35\nnumero 8470\nnumsp 8199\nnvDash 8877\nnvHarr 10500\nnvap 8781,8402\n"
- + "nvdash 8876\nnvge 8805,8402\nnvgt 62,8402\nnvinfin 10718\nnvlArr 10498\nnvle 8804,8402\n"
- + "nvlt 60,8402\nnvltrie 8884,8402\nnvrArr 10499\nnvrtrie 8885,8402\nnvsim 8764,8402\n"
- + "nwArr 8662\nnwarhk 10531\nnwarr 8598\nnwarrow 8598\nnwnear 10535\noS 9416\noacute 243\n"
- + "oast 8859\nocir 8858\nocirc 244\nocy 1086\nodash 8861\nodblac 337\nodiv 10808\nodot 8857\n"
- + "odsold 10684\noelig 339\nofcir 10687\nofr 120108\nogon 731\nograve 242\nogt 10689\n"
- + "ohbar 10677\nohm 937\noint 8750\nolarr 8634\nolcir 10686\nolcross 10683\noline 8254\n"
- + "olt 10688\nomacr 333\nomega 969\nomicron 959\nomid 10678\nominus 8854\noopf 120160\n"
- + "opar 10679\noperp 10681\noplus 8853\nor 8744\norarr 8635\nord 10845\norder 8500\n"
- + "orderof 8500\nordf 170\nordm 186\norigof 8886\noror 10838\norslope 10839\norv 10843\n"
- + "oscr 8500\noslash 248\nosol 8856\notilde 245\notimes 8855\notimesas 10806\nouml 246\n"
- + "ovbar 9021\npar 8741\npara 182\nparallel 8741\nparsim 10995\nparsl 11005\npart 8706\n"
- + "pcy 1087\npercnt 37\nperiod 46\npermil 8240\nperp 8869\npertenk 8241\npfr 120109\n"
- + "phi 966\nphiv 981\nphmmat 8499\nphone 9742\npi 960\npitchfork 8916\npiv 982\nplanck 8463\n"
- + "planckh 8462\nplankv 8463\nplus 43\nplusacir 10787\nplusb 8862\npluscir 10786\n"
- + "plusdo 8724\nplusdu 10789\npluse 10866\nplusmn 177\nplussim 10790\nplustwo 10791\npm 177\n"
- + "pointint 10773\npopf 120161\npound 163\npr 8826\nprE 10931\nprap 10935\nprcue 8828\n"
- + "pre 10927\nprec 8826\nprecapprox 10935\npreccurlyeq 8828\npreceq 10927\n"
- + "precnapprox 10937\nprecneqq 10933\nprecnsim 8936\nprecsim 8830\nprime 8242\nprimes 8473\n"
- + "prnE 10933\nprnap 10937\nprnsim 8936\nprod 8719\nprofalar 9006\nprofline 8978\n"
- + "profsurf 8979\nprop 8733\npropto 8733\nprsim 8830\nprurel 8880\npscr 120005\npsi 968\n"
- + "puncsp 8200\nqfr 120110\nqint 10764\nqopf 120162\nqprime 8279\nqscr 120006\n"
- + "quaternions 8461\nquatint 10774\nquest 63\nquesteq 8799\nquot 34\nrAarr 8667\nrArr 8658\n"
- + "rAtail 10524\nrBarr 10511\nrHar 10596\nrace 8765,817\nracute 341\nradic 8730\n"
- + "raemptyv 10675\nrang 10217\nrangd 10642\nrange 10661\nrangle 10217\nraquo 187\nrarr 8594\n"
- + "rarrap 10613\nrarrb 8677\nrarrbfs 10528\nrarrc 10547\nrarrfs 10526\nrarrhk 8618\n"
- + "rarrlp 8620\nrarrpl 10565\nrarrsim 10612\nrarrtl 8611\nrarrw 8605\nratail 10522\n"
- + "ratio 8758\nrationals 8474\nrbarr 10509\nrbbrk 10099\nrbrace 125\nrbrack 93\nrbrke 10636\n"
- + "rbrksld 10638\nrbrkslu 10640\nrcaron 345\nrcedil 343\nrceil 8969\nrcub 125\nrcy 1088\n"
- + "rdca 10551\nrdldhar 10601\nrdquo 8221\nrdquor 8221\nrdsh 8627\nreal 8476\nrealine 8475\n"
- + "realpart 8476\nreals 8477\nrect 9645\nreg 174\nrfisht 10621\nrfloor 8971\nrfr 120111\n"
- + "rhard 8641\nrharu 8640\nrharul 10604\nrho 961\nrhov 1009\nrightarrow 8594\n"
- + "rightarrowtail 8611\nrightharpoondown 8641\nrightharpoonup 8640\nrightleftarrows 8644\n"
- + "rightleftharpoons 8652\nrightrightarrows 8649\nrightsquigarrow 8605\n"
- + "rightthreetimes 8908\nring 730\nrisingdotseq 8787\nrlarr 8644\nrlhar 8652\nrlm 8207\n"
- + "rmoust 9137\nrmoustache 9137\nrnmid 10990\nroang 10221\nroarr 8702\nrobrk 10215\n"
- + "ropar 10630\nropf 120163\nroplus 10798\nrotimes 10805\nrpar 41\nrpargt 10644\n"
- + "rppolint 10770\nrrarr 8649\nrsaquo 8250\nrscr 120007\nrsh 8625\nrsqb 93\nrsquo 8217\n"
- + "rsquor 8217\nrthree 8908\nrtimes 8906\nrtri 9657\nrtrie 8885\nrtrif 9656\nrtriltri 10702\n"
- + "ruluhar 10600\nrx 8478\nsacute 347\nsbquo 8218\nsc 8827\nscE 10932\nscap 10936\n"
- + "scaron 353\nsccue 8829\nsce 10928\nscedil 351\nscirc 349\nscnE 10934\nscnap 10938\n"
- + "scnsim 8937\nscpolint 10771\nscsim 8831\nscy 1089\nsdot 8901\nsdotb 8865\nsdote 10854\n"
- + "seArr 8664\nsearhk 10533\nsearr 8600\nsearrow 8600\nsect 167\nsemi 59\nseswar 10537\n"
- + "setminus 8726\nsetmn 8726\nsext 10038\nsfr 120112\nsfrown 8994\nsharp 9839\nshchcy 1097\n"
- + "shcy 1096\nshortmid 8739\nshortparallel 8741\nshy 173\nsigma 963\nsigmaf 962\nsigmav 962\n"
- + "sim 8764\nsimdot 10858\nsime 8771\nsimeq 8771\nsimg 10910\nsimgE 10912\nsiml 10909\n"
- + "simlE 10911\nsimne 8774\nsimplus 10788\nsimrarr 10610\nslarr 8592\nsmallsetminus 8726\n"
- + "smashp 10803\nsmeparsl 10724\nsmid 8739\nsmile 8995\nsmt 10922\nsmte 10924\n"
- + "smtes 10924,65024\nsoftcy 1100\nsol 47\nsolb 10692\nsolbar 9023\nsopf 120164\n"
- + "spades 9824\nspadesuit 9824\nspar 8741\nsqcap 8851\nsqcaps 8851,65024\nsqcup 8852\n"
- + "sqcups 8852,65024\nsqsub 8847\nsqsube 8849\nsqsubset 8847\nsqsubseteq 8849\nsqsup 8848\n"
- + "sqsupe 8850\nsqsupset 8848\nsqsupseteq 8850\nsqu 9633\nsquare 9633\nsquarf 9642\n"
- + "squf 9642\nsrarr 8594\nsscr 120008\nssetmn 8726\nssmile 8995\nsstarf 8902\nstar 9734\n"
- + "starf 9733\nstraightepsilon 1013\nstraightphi 981\nstrns 175\nsub 8834\nsubE 10949\n"
- + "subdot 10941\nsube 8838\nsubedot 10947\nsubmult 10945\nsubnE 10955\nsubne 8842\n"
- + "subplus 10943\nsubrarr 10617\nsubset 8834\nsubseteq 8838\nsubseteqq 10949\n"
- + "subsetneq 8842\nsubsetneqq 10955\nsubsim 10951\nsubsub 10965\nsubsup 10963\nsucc 8827\n"
- + "succapprox 10936\nsucccurlyeq 8829\nsucceq 10928\nsuccnapprox 10938\nsuccneqq 10934\n"
- + "succnsim 8937\nsuccsim 8831\nsum 8721\nsung 9834\nsup 8835\nsup1 185\nsup2 178\nsup3 179\n"
- + "supE 10950\nsupdot 10942\nsupdsub 10968\nsupe 8839\nsupedot 10948\nsuphsol 10185\n"
- + "suphsub 10967\nsuplarr 10619\nsupmult 10946\nsupnE 10956\nsupne 8843\nsupplus 10944\n"
- + "supset 8835\nsupseteq 8839\nsupseteqq 10950\nsupsetneq 8843\nsupsetneqq 10956\n"
- + "supsim 10952\nsupsub 10964\nsupsup 10966\nswArr 8665\nswarhk 10534\nswarr 8601\n"
- + "swarrow 8601\nswnwar 10538\nszlig 223\ntarget 8982\ntau 964\ntbrk 9140\ntcaron 357\n"
- + "tcedil 355\ntcy 1090\ntdot 8411\ntelrec 8981\ntfr 120113\nthere4 8756\ntherefore 8756\n"
- + "theta 952\nthetasym 977\nthetav 977\nthickapprox 8776\nthicksim 8764\nthinsp 8201\n"
- + "thkap 8776\nthksim 8764\nthorn 254\ntilde 732\ntimes 215\ntimesb 8864\ntimesbar 10801\n"
- + "timesd 10800\ntint 8749\ntoea 10536\ntop 8868\ntopbot 9014\ntopcir 10993\ntopf 120165\n"
- + "topfork 10970\ntosa 10537\ntprime 8244\ntrade 8482\ntriangle 9653\ntriangledown 9663\n"
- + "triangleleft 9667\ntrianglelefteq 8884\ntriangleq 8796\ntriangleright 9657\n"
- + "trianglerighteq 8885\ntridot 9708\ntrie 8796\ntriminus 10810\ntriplus 10809\ntrisb 10701\n"
- + "tritime 10811\ntrpezium 9186\ntscr 120009\ntscy 1094\ntshcy 1115\ntstrok 359\ntwixt 8812\n"
- + "twoheadleftarrow 8606\ntwoheadrightarrow 8608\nuArr 8657\nuHar 10595\nuacute 250\n"
- + "uarr 8593\nubrcy 1118\nubreve 365\nucirc 251\nucy 1091\nudarr 8645\nudblac 369\n"
- + "udhar 10606\nufisht 10622\nufr 120114\nugrave 249\nuharl 8639\nuharr 8638\nuhblk 9600\n"
- + "ulcorn 8988\nulcorner 8988\nulcrop 8975\nultri 9720\numacr 363\numl 168\nuogon 371\n"
- + "uopf 120166\nuparrow 8593\nupdownarrow 8597\nupharpoonleft 8639\nupharpoonright 8638\n"
- + "uplus 8846\nupsi 965\nupsih 978\nupsilon 965\nupuparrows 8648\nurcorn 8989\n"
- + "urcorner 8989\nurcrop 8974\nuring 367\nurtri 9721\nuscr 120010\nutdot 8944\nutilde 361\n"
- + "utri 9653\nutrif 9652\nuuarr 8648\nuuml 252\nuwangle 10663\nvArr 8661\nvBar 10984\n"
- + "vBarv 10985\nvDash 8872\nvangrt 10652\nvarepsilon 1013\nvarkappa 1008\nvarnothing 8709\n"
- + "varphi 981\nvarpi 982\nvarpropto 8733\nvarr 8597\nvarrho 1009\nvarsigma 962\n"
- + "varsubsetneq 8842,65024\nvarsubsetneqq 10955,65024\nvarsupsetneq 8843,65024\n"
- + "varsupsetneqq 10956,65024\nvartheta 977\nvartriangleleft 8882\nvartriangleright 8883\n"
- + "vcy 1074\nvdash 8866\nvee 8744\nveebar 8891\nveeeq 8794\nvellip 8942\nverbar 124\n"
- + "vert 124\nvfr 120115\nvltri 8882\nvnsub 8834,8402\nvnsup 8835,8402\nvopf 120167\n"
- + "vprop 8733\nvrtri 8883\nvscr 120011\nvsubnE 10955,65024\nvsubne 8842,65024\n"
- + "vsupnE 10956,65024\nvsupne 8843,65024\nvzigzag 10650\nwcirc 373\nwedbar 10847\n"
- + "wedge 8743\nwedgeq 8793\nweierp 8472\nwfr 120116\nwopf 120168\nwp 8472\nwr 8768\n"
- + "wreath 8768\nwscr 120012\nxcap 8898\nxcirc 9711\nxcup 8899\nxdtri 9661\nxfr 120117\n"
- + "xhArr 10234\nxharr 10231\nxi 958\nxlArr 10232\nxlarr 10229\nxmap 10236\nxnis 8955\n"
- + "xodot 10752\nxopf 120169\nxoplus 10753\nxotime 10754\nxrArr 10233\nxrarr 10230\n"
- + "xscr 120013\nxsqcup 10758\nxuplus 10756\nxutri 9651\nxvee 8897\nxwedge 8896\nyacute 253\n"
- + "yacy 1103\nycirc 375\nycy 1099\nyen 165\nyfr 120118\nyicy 1111\nyopf 120170\nyscr 120014\n"
- + "yucy 1102\nyuml 255\nzacute 378\nzcaron 382\nzcy 1079\nzdot 380\nzeetrf 8488\nzeta 950\n"
- + "zfr 120119\nzhcy 1078\nzigrarr 8669\nzopf 120171\nzscr 120015\nzwj 8205\nzwnj 8204\n"
- ;
- // ---------------------------------------------------------------------------
- // Markdown block structure (CommonMark 0.31.2, section 3)
- // ---------------------------------------------------------------------------
- //
- // A cmark-style line scanner: each line is matched against the stack of
- // open "container" blocks (document > blockquote > list > item > ...),
- // consuming their prefixes, then new blocks are attempted in order
- // (blockquote, ATX heading, fenced code, setext underline, thematic break,
- // list item, indented code). Whatever remains is appended to the deepest
- // open leaf, or becomes a lazy paragraph continuation.
- //
- // We do not implement HTML blocks as containers: raw HTML is a security
- // hazard for `innerHTML`, so HTML-block-looking paragraphs stay paragraphs
- // and get escaped by the inline pass like any other text. That also means
- // `<script>` cannot interrupt a paragraph the way the spec allows.
- /** Number of columns that count as an indented code block. */
- var MD_CODE_INDENT = 4;
- /** Characters that can begin a non-paragraph block (fast bail-out). */
- var MD_MAYBE_SPECIAL_RE = /^[#`~*+_=<>0-9\-]/;
- var MD_THEMATIC_RE = /^(?:\*[ \t]*){3,}$|^(?:_[ \t]*){3,}$|^(?:-[ \t]*){3,}$/;
- var MD_BULLET_RE = /^[*+\-]/;
- var MD_ORDERED_RE = /^(\d{1,9})([.)])/;
- var MD_ATX_RE = /^#{1,6}(?:[ \t]+|$)/;
- var MD_FENCE_RE = /^`{3,}(?!.*`)|^~{3,}/;
- var MD_CLOSE_FENCE_RE = /^(?:`{3,}|~{3,})(?=[ \t]*$)/;
- var MD_SETEXT_RE = /^(?:=+|-+)[ \t]*$/;
- var MD_NON_SPACE_RE = /[^ \t\f\v\r\n]/;
- /**
- * Create a block node of the given type.
- * @param {string} type document|blockquote|list|item|paragraph|heading|code|thematic
- */
- function mdNode(type) {
- return {
- type: type, parent: null, children: [], strings: [],
- open: true, info: '', literal: '',
- fenced: false, fenceChar: '', fenceLength: 0, fenceOffset: 0,
- level: 1, listData: null, tight: true, headingSetext: false,
- sourceLine: 0
- };
- }
- function mdParser() {
- var doc = mdNode('document');
- return {
- doc: doc, tip: doc, oldtip: doc,
- offset: 0, column: 0, nextNonspace: 0, nextNonspaceColumn: 0,
- indent: 0, indented: false, blank: false, partiallyConsumedTab: false,
- allClosed: true, lastMatchedContainer: doc,
- currentLine: '', lineNumber: 0, lastLineLength: 0,
- refmap: {}, lineOffsets: []
- };
- }
- /** Normalise endings and split into lines (trailing blank from final \n dropped). */
- function mdSplitInput(raw) {
- var text = String(raw).replace(/\r\n|\r(?!\n)/g, '\n').replace(/\r/g, '\n');
- var out = text.split('\n');
- if (out.length && out[out.length - 1] === '') out.pop();
- return out;
- }
- // --- parser cursor helpers ------------------------------------------------
- /** Find the next non-space/tab char; sets blank/indent/indented on p. */
- function mdFindNextNonspace(p) {
- var ln = p.currentLine, i = p.offset, cols = p.column, c;
- while ((c = ln.charAt(i)) !== '') {
- if (c === ' ') { i++; cols++; }
- else if (c === '\t') { i++; cols += 4 - (cols % 4); }
- else break;
- }
- p.blank = c === '' ;
- p.nextNonspace = i;
- p.nextNonspaceColumn = cols;
- p.indent = p.nextNonspaceColumn - p.column;
- p.indented = p.indent >= MD_CODE_INDENT;
- }
- /**
- * Advance the cursor by `count` columns (or characters when `columns` is
- * false). Handles partially consumed tabs, which stay in the line as the
- * equivalent spaces.
- */
- function mdAdvanceOffset(p, count, columns) {
- var ln = p.currentLine, charsToTab, advance, c;
- while (count > 0 && (c = ln.charAt(p.offset)) !== '') {
- if (c === '\t') {
- charsToTab = 4 - (p.column % 4);
- if (columns) {
- p.partiallyConsumedTab = charsToTab > count;
- advance = charsToTab > count ? count : charsToTab;
- p.column += advance;
- if (!p.partiallyConsumedTab) p.offset += 1;
- count -= advance;
- } else {
- p.partiallyConsumedTab = false;
- p.column += charsToTab;
- p.offset += 1;
- count -= 1;
- }
- } else {
- p.partiallyConsumedTab = false;
- p.offset += 1;
- p.column += 1;
- count -= 1;
- }
- }
- }
- function mdAdvanceNextNonspace(p) {
- p.offset = p.nextNonspace;
- p.column = p.nextNonspaceColumn;
- p.partiallyConsumedTab = false;
- }
- /**
- * Append the rest of the current line (from p.offset) to the tip. When a
- * tab was only partially consumed, the surviving columns are re-emitted as
- * spaces, exactly like cmark.
- */
- function mdAddLine(p) {
- var s = '';
- if (p.partiallyConsumedTab) {
- p.offset += 1; // skip the tab character itself
- var charsToTab = 4 - (p.column % 4);
- while (s.length < charsToTab) s += ' ';
- }
- p.tip.strings.push(s + p.currentLine.slice(p.offset));
- }
- function mdCanContain(type, child) {
- if (type === 'item' || type === 'blockquote' ||
- type === 'document' || type === 'list') {
- if (type === 'list') return child === 'item';
- return child !== 'item';
- }
- return false;
- }
- function mdAcceptsLines(type) {
- return type === 'paragraph' || type === 'code';
- }
- /** Close every block from tip down to (excluding) `lastMatched`. */
- function mdCloseUnmatched(p) {
- if (p.allClosed) return;
- while (p.oldtip !== p.lastMatchedContainer) {
- mdFinalize(p, p.oldtip, p.lineNumber - 1);
- p.oldtip = p.oldtip.parent;
- }
- p.allClosed = true;
- }
- /**
- * Add a child block of `tag` under the tip, finalising any tip that cannot
- * contain it first.
- */
- function mdAddChild(p, tag) {
- while (!mdCanContain(p.tip.type, tag)) mdFinalize(p, p.tip, p.lineNumber - 1);
- var node = mdNode(tag);
- node.parent = p.tip;
- node.sourceLine = p.lineNumber;
- p.tip.children.push(node);
- p.tip = node;
- return node;
- }
- // --- container continue checks -------------------------------------------
- // 0 = matched, 1 = not matched, 2 = line fully handled (fence close)
- function mdContinueBlock(p, container) {
- var ln = p.currentLine, t = container.type;
- if (t === 'document' || t === 'list') return 0;
- if (t === 'blockquote') {
- if (!p.indented && ln.charAt(p.nextNonspace) === '>') {
- mdAdvanceNextNonspace(p);
- mdAdvanceOffset(p, 1, false);
- if (ln.charAt(p.offset) === ' ' || ln.charAt(p.offset) === '\t') {
- mdAdvanceOffset(p, 1, true);
- }
- return 0;
- }
- return 1;
- }
- if (t === 'item') {
- if (p.blank) {
- if (!container.children.length) return 1; // blank after empty item
- mdAdvanceNextNonspace(p);
- return 0;
- }
- var need = container.listData.markerOffset + container.listData.padding;
- if (p.indent >= need) {
- mdAdvanceOffset(p, need, true);
- return 0;
- }
- return 1;
- }
- if (t === 'code') {
- if (container.fenced) {
- var rest = ln.slice(p.nextNonspace);
- if (p.indent <= 3 && ln.charAt(p.nextNonspace) === container.fenceChar &&
- MD_CLOSE_FENCE_RE.test(rest) && rest.match(MD_CLOSE_FENCE_RE)[0].length >= container.fenceLength) {
- mdFinalize(p, container, p.lineNumber);
- return 2;
- }
- // skip up to fenceOffset leading spaces
- var i = container.fenceOffset;
- while (i > 0 && (ln.charAt(p.offset) === ' ' || ln.charAt(p.offset) === '\t')) {
- mdAdvanceOffset(p, 1, true);
- i--;
- }
- return 0;
- }
- if (p.indent >= MD_CODE_INDENT) { mdAdvanceOffset(p, MD_CODE_INDENT, true); return 0; }
- if (p.blank) { mdAdvanceNextNonspace(p); return 0; }
- return 1;
- }
- if (t === 'heading' || t === 'thematic') return 1;
- if (t === 'paragraph') return p.blank ? 1 : 0;
- return 1;
- }
- /**
- * True when a blank line separates `node` from its following sibling (used
- * for the tight/loose list decision).
- */
- function mdEndsWithBlank(node) {
- if (!node.parent) return false;
- var idx = node.parent.children.indexOf(node);
- var next = node.parent.children[idx + 1];
- if (!next) return false;
- return mdNodeEndLine(node) !== next.sourceLine - 1;
- }
- /** Last source line number consumed by a node (tracked during the scan). */
- function mdNodeEndLine(node) {
- return node.endLine == null ? node.sourceLine : node.endLine;
- }
- // --- block starts ----------------------------------------------------------
- /**
- * Parse a list marker at the cursor. Returns the marker data or null.
- * Mirrors cmark: the marker itself, then 1-4 spaces (5+ or a blank rest
- * means "content starts one space after the marker").
- */
- function mdParseListMarker(p, container) {
- var rest = p.currentLine.slice(p.nextNonspace);
- var data = { type: null, tight: true, bulletChar: null, start: null,
- delimiter: null, padding: null, markerOffset: p.indent };
- var m, nextc;
- if (p.indent >= 4) return null;
- if ((m = rest.match(MD_BULLET_RE))) {
- data.type = 'bullet';
- data.bulletChar = m[0].charAt(0);
- } else if ((m = rest.match(MD_ORDERED_RE)) &&
- (container.type !== 'paragraph' || Number(m[1]) === 1)) {
- data.type = 'ordered';
- data.start = parseInt(m[1], 10);
- data.delimiter = m[2];
- } else {
- return null;
- }
- nextc = p.currentLine.charAt(p.nextNonspace + m[0].length);
- if (!(nextc === '' || nextc === ' ' || nextc === '\t')) return null;
- if (container.type === 'paragraph' &&
- !MD_NON_SPACE_RE.test(p.currentLine.slice(p.nextNonspace + m[0].length))) {
- return null;
- }
- mdAdvanceNextNonspace(p);
- mdAdvanceOffset(p, m[0].length, true);
- var spacesStartCol = p.column, spacesStartOffset = p.offset;
- do {
- mdAdvanceOffset(p, 1, true);
- nextc = p.currentLine.charAt(p.offset);
- } while (p.column - spacesStartCol < 5 && (nextc === ' ' || nextc === '\t'));
- var blankItem = p.currentLine.charAt(p.offset) === '' && p.offset >= p.currentLine.length;
- var spacesAfterMarker = p.column - spacesStartCol;
- if (spacesAfterMarker >= 5 || spacesAfterMarker < 1 || blankItem) {
- data.padding = m[0].length + 1;
- p.column = spacesStartCol;
- p.offset = spacesStartOffset;
- var c2 = p.currentLine.charAt(p.offset);
- if (c2 === ' ' || c2 === '\t') mdAdvanceOffset(p, 1, true);
- } else {
- data.padding = m[0].length + spacesAfterMarker;
- }
- return data;
- }
- function mdListsMatch(a, b) {
- return a.type === b.type && a.delimiter === b.delimiter &&
- a.bulletChar === b.bulletChar;
- }
- /**
- * Try to start a new block at the cursor. Returns 0 (no match), 1 (opened a
- * container, keep trying), or 2 (opened a leaf; the line is spent).
- */
- function mdTryBlockStart(p, container) {
- var ln = p.currentLine, m, node;
- // block quote
- if (!p.indented && ln.charAt(p.nextNonspace) === '>') {
- mdAdvanceNextNonspace(p);
- mdAdvanceOffset(p, 1, false);
- if (ln.charAt(p.offset) === ' ' || ln.charAt(p.offset) === '\t') {
- mdAdvanceOffset(p, 1, true);
- }
- mdCloseUnmatched(p);
- mdAddChild(p, 'blockquote');
- return 1;
- }
- // ATX heading
- if (!p.indented && (m = ln.slice(p.nextNonspace).match(MD_ATX_RE))) {
- mdAdvanceNextNonspace(p);
- mdAdvanceOffset(p, m[0].length, false);
- mdCloseUnmatched(p);
- node = mdAddChild(p, 'heading');
- node.level = m[0].replace(/[ \t]/g, '').length;
- node.strings.push(
- ln.slice(p.offset)
- .replace(/^[ \t]*#+[ \t]*$/, '')
- .replace(/[ \t]+#+[ \t]*$/, ''));
- mdAdvanceOffset(p, ln.length - p.offset, false);
- return 2;
- }
- // fenced code block
- if (!p.indented && (m = ln.slice(p.nextNonspace).match(MD_FENCE_RE))) {
- mdCloseUnmatched(p);
- node = mdAddChild(p, 'code');
- node.fenced = true;
- node.fenceLength = m[0].length;
- node.fenceChar = m[0].charAt(0);
- node.fenceOffset = p.indent;
- mdAdvanceNextNonspace(p);
- mdAdvanceOffset(p, m[0].length, false);
- return 2;
- }
- // setext heading underline
- if (!p.indented && container.type === 'paragraph' &&
- (m = ln.slice(p.nextNonspace).match(MD_SETEXT_RE))) {
- mdCloseUnmatched(p);
- var pos;
- var joined = container.strings.join('\n');
- while (joined.charAt(0) === '[' && (pos = mdParseReference(joined, p.refmap)) > 0) {
- joined = joined.slice(pos);
- }
- container.strings = joined.length ? [joined] : [];
- var content = container.strings.join('\n');
- if (content.length > 0) {
- node = mdNode('heading');
- node.level = m[0].charAt(0) === '=' ? 1 : 2;
- node.headingSetext = true;
- node.strings = container.strings.slice();
- node.sourceLine = container.sourceLine;
- node.endLine = p.lineNumber;
- node.parent = container.parent;
- var ci = container.parent.children.indexOf(container);
- container.parent.children[ci] = node;
- p.tip = node;
- mdAdvanceOffset(p, ln.length - p.offset, false);
- return 2;
- }
- return 0;
- }
- // thematic break
- if (!p.indented && MD_THEMATIC_RE.test(ln.slice(p.nextNonspace))) {
- mdCloseUnmatched(p);
- mdAddChild(p, 'thematic');
- mdAdvanceOffset(p, ln.length - p.offset, false);
- return 2;
- }
- // list item
- var data;
- if ((!p.indented || container.type === 'list') && (data = mdParseListMarker(p, container))) {
- mdCloseUnmatched(p);
- if (p.tip.type !== 'list' || !mdListsMatch(container.listData, data)) {
- var list = mdAddChild(p, 'list');
- list.listData = data;
- container = list;
- }
- var item = mdAddChild(p, 'item');
- item.listData = data;
- return 1;
- }
- // indented code block
- if (p.indented && p.tip.type !== 'paragraph' && !p.blank) {
- mdAdvanceOffset(p, MD_CODE_INDENT, true);
- mdCloseUnmatched(p);
- mdAddChild(p, 'code');
- return 2;
- }
- return 0;
- }
- // --- line incorporation and finalisation -----------------------------------
- /**
- * Process one source line into the open block tree: match container
- * prefixes, try to open new blocks, then hand the remainder to a leaf.
- */
- function mdIncorporateLine(p, ln) {
- var container = p.doc, lastChild, allMatched = true, res;
- p.oldtip = p.tip;
- p.offset = 0;
- p.column = 0;
- p.blank = false;
- p.partiallyConsumedTab = false;
- p.lineNumber += 1;
- p.currentLine = ln.indexOf('\u0000') >= 0 ? ln.replace(/\u0000/g, '\uFFFD') : ln;
- // 1. Match the open containers' prefixes, deepest first.
- while (container.children.length) {
- lastChild = container.children[container.children.length - 1];
- if (!lastChild.open) break;
- container = lastChild;
- mdFindNextNonspace(p);
- res = mdContinueBlock(p, container);
- if (res === 2) { p.lastLineLength = ln.length; return; }
- if (res === 1) { allMatched = false; container = container.parent; break; }
- }
- p.allClosed = container === p.oldtip;
- p.lastMatchedContainer = container;
- // 2. Unless we already sit in a leaf that accepts lines, try block starts.
- var matchedLeaf = container.type !== 'paragraph' && mdAcceptsLines(container.type);
- while (!matchedLeaf) {
- mdFindNextNonspace(p);
- if (!p.indented && !MD_MAYBE_SPECIAL_RE.test(p.currentLine.slice(p.nextNonspace))) {
- mdAdvanceNextNonspace(p);
- break;
- }
- res = mdTryBlockStart(p, container);
- if (res === 1) { container = p.tip; continue; }
- if (res === 2) { container = p.tip; matchedLeaf = true; break; }
- mdAdvanceNextNonspace(p);
- break;
- }
- // 3. The remainder is line content for the tip.
- if (!p.allClosed && !p.blank && p.tip.type === 'paragraph') {
- mdAddLine(p); // lazy paragraph continuation
- } else {
- mdCloseUnmatched(p);
- if (mdAcceptsLines(container.type)) {
- mdAddLine(p);
- } else if (p.offset < p.currentLine.length && !p.blank) {
- mdAddChild(p, 'paragraph');
- mdAdvanceNextNonspace(p);
- mdAddLine(p);
- }
- }
- p.lastLineLength = ln.length;
- }
- /**
- * Close a block: extract fenced info strings / indented-code literals, work
- * out list tightness, peel link reference definitions off paragraphs and
- * record which source line the block ended on.
- */
- function mdFinalize(p, block, endLine) {
- var above = block.parent;
- block.open = false;
- block.endLine = endLine == null ? p.lineNumber : endLine;
- if (block.type === 'code') {
- if (block.fenced) {
- var content = block.strings.join('\n');
- var nl = content.indexOf('\n');
- var firstLine = nl >= 0 ? content.slice(0, nl) : content;
- var rest = nl >= 0 ? content.slice(nl + 1) : '';
- block.info = mdUnescapeString(firstLine.replace(/^[ \t]+/, '').replace(/[ \t]+$/, ''));
- // cmark keeps the final newline of the block's content
- block.literal = rest.length ? rest + '\n' : (block.strings.length > 1 ? '\n' : '');
- } else {
- var lines = block.strings.slice();
- while (lines.length && !MD_NON_SPACE_RE.test(lines[lines.length - 1])) lines.pop();
- block.literal = lines.join('\n') + '\n';
- }
- block.strings = [];
- }
- if (block.type === 'paragraph') {
- // Reference definitions live at the start of paragraphs only; each
- // consumed definition must advance or we stop.
- var txt = block.strings.join('\n');
- var pos;
- while (txt.charAt(0) === '[' && (pos = mdParseReference(txt, p.refmap)) > 0) {
- txt = txt.slice(pos);
- }
- block.strings = txt.length ? [txt] : [];
- if (!txt.length) mdRemoveFromParent(block);
- }
- if ((block.type === 'item' || block.type === 'list') && block.children.length) {
- // items and lists end where their last child ends (a trailing blank
- // line is not part of them) — this drives the tight/loose rule.
- // Blockquotes deliberately keep the line their `>` marker last
- // appeared on: ` >` is not a blank line for these purposes.
- block.endLine = block.children[block.children.length - 1].endLine;
- }
- if (block.type === 'list') {
- block.tight = true;
- for (var i = 0; i < block.children.length; i++) {
- var item = block.children[i];
- if (i < block.children.length - 1 && mdEndsWithBlank(item)) { block.tight = false; break; }
- for (var j = 0; j < item.children.length; j++) {
- if (j < item.children.length - 1 && mdEndsWithBlank(item.children[j])) { block.tight = false; break; }
- }
- if (!block.tight) break;
- }
- }
- p.tip = above;
- }
- /** Detach a node (used when a paragraph turns out to be all references). */
- function mdRemoveFromParent(node) {
- if (!node.parent) return;
- var i = node.parent.children.indexOf(node);
- if (i >= 0) node.parent.children.splice(i, 1);
- }
- /** Parse the whole input into a block tree. */
- function mdParseDocument(raw) {
- var p = mdParser();
- var lines = mdSplitInput(raw);
- for (var i = 0; i < lines.length; i++) mdIncorporateLine(p, lines[i]);
- while (p.tip && p.tip.type !== 'document') mdFinalize(p, p.tip, lines.length);
- return p;
- }
- // --- shared inline regexes / URI handling -----------------------------------
- var MD_LINK_TITLE_RE = /(?:")([^"]*)(?:")|(?:')([^']*)(?:')/;
- /**
- * Scan a link title at `subject[pos]` without regex backtracking: a quoted
- * run (with `\"`-style escapes) or a parenthesised run. Returns
- * `{ text, len }` or null.
- * @param {string} subject
- * @param {number} pos
- * @returns {?{text: string, len: number}}
- */
- function mdScanLinkTitle(subject, pos) {
- var start = pos, q = subject.charAt(pos);
- if (q !== '"' && q !== "'" && q !== '(') return null;
- var close = q === '(' ? ')' : q;
- var i = pos + 1;
- while (i < subject.length) {
- var ch = subject.charAt(i);
- if (ch === '\\' && subject.charAt(i + 1) !== '' &&
- MD_ESCAPABLE.indexOf(subject.charAt(i + 1)) >= 0) { i += 2; continue; }
- if (ch === close) {
- return { text: subject.slice(start + 1, i), len: i + 1 - start };
- }
- if (ch === '\n' && subject.charAt(i + 1) === '\n') return null; // blank line ends it
- i++;
- }
- return null;
- }
- var MD_LINK_DEST_BRACES_RE = /^<(?:[^<>\n\\\x00]|\\.)*>/;
- /**
- * End bound for scanning a construct that cannot contain whitespace, '<' or
- * '>' from `pos` (autolinks; raw HTML tags scan themselves linearly).
- * Slicing to this index instead of the end of the subject keeps the inline
- * parser linear on pathological input (many unmatched '<' or '&'): the
- * anchored construct regexes cannot match past the bound anyway.
- * @param {string} subject
- * @param {number} pos
- * @returns {number}
- */
- function mdBoundScan(subject, pos) {
- var i = pos + 1, c;
- while (i < subject.length) {
- c = subject.charCodeAt(i);
- if (c <= 0x20 || c === 0x3C || c === 0x3E) break;
- i++;
- }
- return i < subject.length ? i + 1 : subject.length;
- }
- /**
- * Match a raw HTML open/close tag at subject[pos] using a linear scan
- * (the equivalent regex backtracks catastrophically on malformed input).
- * Returns the matched text or null. SECURITY: callers render this escaped.
- * @param {string} subject
- * @param {number} pos
- * @returns {?string}
- */
- function mdScanHtmlTag(subject, pos) {
- var i = pos;
- if (subject.charAt(i) !== '<') return null;
- i++;
- var closing = subject.charAt(i) === '/';
- if (closing) i++;
- if (!/[A-Za-z]/.test(subject.charAt(i))) return null;
- var start = i;
- while (i < subject.length && /[A-Za-z0-9-]/.test(subject.charAt(i))) i++;
- if (i === start) return null;
- if (closing) {
- while (i < subject.length && /[ \t\n]/.test(subject.charAt(i))) i++;
- if (subject.charAt(i) === '>') return subject.slice(pos, i + 1);
- return null;
- }
- // attributes
- while (i < subject.length) {
- var wsStart = i;
- while (i < subject.length && /[ \t\n]/.test(subject.charAt(i))) i++;
- if (subject.charAt(i) === '>') return subject.slice(pos, i + 1);
- if (subject.charAt(i) === '/' && subject.charAt(i + 1) === '>') return subject.slice(pos, i + 2);
- if (i === wsStart) return null; // attribute must be preceded by space
- var an = i;
- while (i < subject.length && !/[\s/=><]/.test(subject.charAt(i))) i++;
- if (i === an) return null;
- var eq = i;
- while (i < subject.length && /[ \t\n]/.test(subject.charAt(i))) i++;
- if (subject.charAt(i) !== '=') { i = eq; continue; }
- i++;
- while (i < subject.length && /[ \t\n]/.test(subject.charAt(i))) i++;
- var q = subject.charAt(i);
- if (q === '"' || q === "'") {
- i++;
- var endq = subject.indexOf(q, i);
- if (endq < 0) return null;
- i = endq + 1;
- } else {
- var v = i;
- while (i < subject.length && !/[\s>]/.test(subject.charAt(i))) i++;
- if (i === v) return null;
- }
- }
- return null;
- }
- /**
- * CommonMark's URL normalisation: percent-encode every character that is
- * not in the RFC 3986 "unreserved + reserved + '#' escape" set. Non-ASCII
- * characters become UTF-8 percent-escapes (like encodeURIComponent).
- * @param {string} uri
- * @returns {string}
- */
- function mdNormalizeUri(uri) {
- if (!uri) return '';
- var out = '', ch, i;
- for (i = 0; i < uri.length; i++) {
- ch = uri.charAt(i);
- if (MD_URI_SAFE_RE.test(ch)) { out += ch; continue; }
- // encode one code point (surrogate pairs together)
- var cp = uri.charCodeAt(i);
- var str = ch;
- if (cp >= 0xD800 && cp <= 0xDBFF && i + 1 < uri.length) {
- str += uri.charAt(i + 1);
- i++;
- }
- out += encodeURIComponent(str);
- }
- return out;
- }
- /** URI characters kept literally (unreserved, reserved and '%'). */
- var MD_URI_SAFE_RE = /^[A-Za-z0-9;,\/?:@&=+\$\-_\.!~\*'\(\)%#]$/;
- /**
- * Normalise a link label for reference lookup: strip brackets, trim,
- * collapse internal whitespace, case-fold.
- * @param {string} label raw `[...]` including brackets
- * @returns {string}
- */
- function mdNormalizeReference(label) {
- return label.slice(1, label.length - 1).trim()
- .replace(/[ \t\r\n]+/g, ' ')
- .toLowerCase().toUpperCase();
- }
- /**
- * Parse one link reference definition from the start of `s`. Returns the
- * number of characters consumed, or 0.
- * @param {string} s
- * @param {Object} refmap
- * @returns {number}
- */
- function mdParseReference(s, refmap) {
- var subject = s, pos = 0, rawlabel, dest, title = null, startpos = 0;
- function peek2() { return pos < subject.length ? subject.charAt(pos) : ''; }
- function match2(re) {
- var m = re.exec(subject.slice(pos));
- if (m) pos += m[0].length;
- return m;
- }
- function spnl2() { match2(/^ *(?:\n *)?/); }
- // label: one bracketed run, no nested brackets, no blank line
- var depth = 0, i = 0, ch;
- while (i < subject.length) {
- ch = subject.charAt(i);
- if (ch === '\\') { i += 2; continue; }
- if (ch === '[') { depth++; if (depth > 1) return 0; }
- else if (ch === ']') break;
- i++;
- }
- if (depth !== 1 || subject.charAt(i) !== ']') return 0;
- rawlabel = subject.slice(0, i + 1);
- if (rawlabel.length > 1001) return 0;
- pos = i + 1;
- if (peek2() !== ':') return 0;
- pos++;
- spnl2();
- // destination
- var m2 = match2(MD_LINK_DEST_BRACES_RE);
- if (m2) {
- dest = mdNormalizeUri(mdUnescapeString(m2[0].slice(1, -1)));
- } else {
- var save = pos, openparens = 0, c;
- while ((c = peek2()) !== '') {
- if (c === '\\' && subject.charAt(pos + 1) !== '' &&
- MD_ESCAPABLE.indexOf(subject.charAt(pos + 1)) >= 0) {
- pos += 1;
- if (peek2() !== '') pos += 1;
- } else if (c === '(') { pos++; openparens++; }
- else if (c === ')') { if (openparens < 1) break; pos++; openparens--; }
- else if (MD_WS_CHAR_RE.test(c)) break;
- else pos++;
- }
- if (pos === save && c !== ')') return 0;
- if (openparens !== 0) return 0;
- dest = mdNormalizeUri(mdUnescapeString(subject.slice(save, pos)));
- }
- var beforetitle = pos;
- spnl2();
- if (pos !== beforetitle) {
- var t = mdScanLinkTitle(subject, pos);
- if (t) { title = mdUnescapeString(t.text); pos += t.len; }
- }
- if (title === null) pos = beforetitle;
- // must be at end of line
- var atLineEnd = match2(/^ *(?:\n|$)/) !== null;
- if (!atLineEnd) {
- if (title !== null) {
- title = null;
- pos = beforetitle;
- atLineEnd = match2(/^ *(?:\n|$)/) !== null;
- }
- if (!atLineEnd) return 0;
- }
- var normlabel = mdNormalizeReference(rawlabel);
- if (normlabel === '') return 0;
- if (!refmap[normlabel]) {
- refmap[normlabel] = { destination: dest, title: title == null ? '' : title };
- }
- return pos;
- }
- // ---------------------------------------------------------------------------
- // Markdown inline parsing (CommonMark 0.31.2, section 6)
- // ---------------------------------------------------------------------------
- //
- // A hand-rolled scanner over paragraph/heading content: plain text runs are
- // copied until a special character (\n ` [ ] \ ! < & * _), then that
- // character's handler runs. Emphasis is resolved afterwards with the
- // delimiter-run algorithm from the spec: openers are searched bottom-up
- // with the "rule of 3" and openers_bottom optimisation; leftover delimiter
- // text stays literal. Links and images share a bracket stack; links may
- // not contain links.
- //
- // Inline nodes form a doubly-linked list (firstChild/lastChild/next/prev on
- // the parent) exactly like the block tree: process_emphasis has to splice
- // nodes out of the middle, which is painful with arrays.
- var MD_ESCAPABLE = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~';
- var MD_ASCII_PUNCT_TEST_RE = /^[!-/:-@[-`{-~]$/;
- var MD_ENTITY_HERE_RE = /^&(?:#x[a-f0-9]{1,6}|#[0-9]{1,7}|[a-z][a-z0-9]{1,31});/i;
- var MD_TICKS_HERE_RE = /^`+/;
- var MD_WS_CHAR_RE = /[ \t\n\x0b\x0c\x0d]/;
- var MD_FINAL_SPACE_RE = / *$/;
- /**
- * Unicode punctuation/symbol code points (categories P* and S*) above the
- * ASCII range, as "lo-hi" hex ranges (binary-searched). Needed for the
- * left/right-flanking rules on non-ASCII text; ES5 has no \p{P}.
- */
- var MD_UNICODE_PUNCT_RANGES = [
- 'A1-A9','AB-AC','AE-B1','B4','B6-B8','BB','BF','D7','F7','2C2-2C5','2D2-2DF','2E5-2EB',
- '2ED','2EF-2FF','375','37E','384-385','387','3F6','482','55A-55F','589-58A','58D-58F','5BE',
- '5C0','5C3','5C6','5F3-5F4','606-60F','61B','61D-61F','66A-66D','6D4','6DE','6E9','6FD-6FE',
- '700-70D','7F6-7F9','7FE-7FF','830-83E','85E','888','964-965','970','9F2-9F3','9FA-9FB',
- '9FD','A76','AF0-AF1','B70','BF3-BFA','C77','C7F','C84','D4F','D79','DF4','E3F','E4F',
- 'E5A-E5B','F01-F17','F1A-F1F','F34','F36','F38','F3A-F3D','F85','FBE-FC5','FC7-FCC',
- 'FCE-FDA','104A-104F','109E-109F','10FB','1360-1368','1390-1399','1400','166D-166E',
- '169B-169C','16EB-16ED','1735-1736','17D4-17D6','17D8-17DB','1800-180A','1940','1944-1945',
- '19DE-19FF','1A1E-1A1F','1AA0-1AA6','1AA8-1AAD','1B4E-1B4F','1B5A-1B6A','1B74-1B7F',
- '1BFC-1BFF','1C3B-1C3F','1C7E-1C7F','1CC0-1CC7','1CD3','1FBD','1FBF-1FC1','1FCD-1FCF',
- '1FDD-1FDF','1FED-1FEF','1FFD-1FFE','2010-2027','2030-205E','207A-207E','208A-208E',
- '20A0-20C0','2100-2101','2103-2106','2108-2109','2114','2116-2118','211E-2123','2125',
- '2127','2129','212E','213A-213B','2140-2144','214A-214D','214F','218A-218B','2190-2429',
- '2440-244A','249C-24E9','2500-2775','2794-2B73','2B76-2B95','2B97-2BFF','2CE5-2CEA',
- '2CF9-2CFC','2CFE-2CFF','2D70','2E00-2E2E','2E30-2E5D','2E80-2E99','2E9B-2EF3','2F00-2FD5',
- '2FF0-2FFF','3001-3004','3008-3020','3030','3036-3037','303D-303F','309B-309C','30A0',
- '30FB','3190-3191','3196-319F','31C0-31E5','31EF','3200-321E','322A-3247','3250',
- '3260-327F','328A-32B0','32C0-33FF','4DC0-4DFF','A490-A4C6','A4FE-A4FF','A60D-A60F','A673',
- 'A67E','A6F2-A6F7','A700-A716','A720-A721','A789-A78A','A828-A82B','A836-A839','A874-A877',
- 'A8CE-A8CF','A8F8-A8FA','A8FC','A92E-A92F','A95F','A9C1-A9CD','A9DE-A9DF','AA5C-AA5F',
- 'AA77-AA79','AADE-AADF','AAF0-AAF1','AB5B','AB6A-AB6B','ABEB','FB29','FBB2-FBC2',
- 'FD3E-FD4F','FDCF','FDFC-FDFF','FE10-FE19','FE30-FE52','FE54-FE66','FE68-FE6B','FF01-FF0F',
- 'FF1A-FF20','FF3B-FF40','FF5B-FF65','FFE0-FFE6','FFE8-FFEE','FFFC-FFFD','10100-10102',
- '10137-1013F','10179-10189','1018C-1018E','10190-1019C','101A0','101D0-101FC','1039F',
- '103D0','1056F','10857','10877-10878','1091F','1093F','10A50-10A58','10A7F','10AC8',
- '10AF0-10AF6','10B39-10B3F','10B99-10B9C','10D6E','10D8E-10D8F','10EAD','10F55-10F59',
- '10F86-10F89','11047-1104D','110BB-110BC','110BE-110C1','11140-11143','11174-11175',
- '111C5-111C8','111CD','111DB','111DD-111DF','11238-1123D','112A9','113D4-113D5',
- '113D7-113D8','1144B-1144F','1145A-1145B','1145D','114C6','115C1-115D7','11641-11643',
- '11660-1166C','116B9','1173C-1173F','1183B','11944-11946','119E2','11A3F-11A46',
- '11A9A-11A9C','11A9E-11AA2','11B00-11B09','11BE1','11C41-11C45','11C70-11C71','11EF7-11EF8',
- '11F43-11F4F','11FD5-11FF1','11FFF','12470-12474','12FF1-12FF2','16A6E-16A6F','16AF5',
- '16B37-16B3F','16B44-16B45','16D6D-16D6F','16E97-16E9A','16FE2','1BC9C','1BC9F',
- '1CC00-1CCEF','1CD00-1CEB3','1CF50-1CFC3','1D000-1D0F5','1D100-1D126','1D129-1D164',
- '1D16A-1D16C','1D183-1D184','1D18C-1D1A9','1D1AE-1D1EA','1D200-1D241','1D245','1D300-1D356',
- '1D6C1','1D6DB','1D6FB','1D715','1D735','1D74F','1D76F','1D789','1D7A9','1D7C3',
- '1D800-1D9FF','1DA37-1DA3A','1DA6D-1DA74','1DA76-1DA83','1DA85-1DA8B','1E14F','1E2FF',
- '1E5FF','1E95E-1E95F','1ECAC','1ECB0','1ED2E','1EEF0-1EEF1','1F000-1F02B','1F030-1F093',
- '1F0A0-1F0AE','1F0B1-1F0BF','1F0C1-1F0CF','1F0D1-1F0F5','1F10D-1F1AD','1F1E6-1F202',
- '1F210-1F23B','1F240-1F248','1F250-1F251','1F260-1F265','1F300-1F6D7','1F6DC-1F6EC',
- '1F6F0-1F6FC','1F700-1F776','1F77B-1F7D9','1F7E0-1F7EB','1F7F0','1F800-1F80B','1F810-1F847',
- '1F850-1F859','1F860-1F887','1F890-1F8AD','1F8B0-1F8BB','1F8C0-1F8C1','1F900-1FA53',
- '1FA60-1FA6D','1FA70-1FA7C','1FA80-1FA89','1FA8F-1FAC6','1FACE-1FADC','1FADF-1FAE9',
- '1FAF0-1FAF8','1FB00-1FB92','1FB94-1FBEF',
- ];
- function mdIsUnicodePunct(cp) {
- var lo = 0, hi = MD_UNICODE_PUNCT_RANGES.length - 1;
- while (lo <= hi) {
- var mid = (lo + hi) >> 1;
- var dash = MD_UNICODE_PUNCT_RANGES[mid].indexOf('-');
- var a, b;
- if (dash < 0) { a = b = parseInt(MD_UNICODE_PUNCT_RANGES[mid], 16); }
- else {
- a = parseInt(MD_UNICODE_PUNCT_RANGES[mid].slice(0, dash), 16);
- b = parseInt(MD_UNICODE_PUNCT_RANGES[mid].slice(dash + 1), 16);
- }
- if (cp < a) hi = mid - 1;
- else if (cp > b) lo = mid + 1;
- else return true;
- }
- return false;
- }
- function mdIsPunct(ch) {
- if (ch === '' || ch == null) return false;
- if (MD_ASCII_PUNCT_TEST_RE.test(ch)) return true;
- var cp = ch.charCodeAt(0);
- if (cp < 0xA1) return false;
- // combine a surrogate pair into one code point
- if (cp >= 0xD800 && cp <= 0xDBFF && ch.length > 1) {
- var lo = ch.charCodeAt(1);
- if (lo >= 0xDC00 && lo <= 0xDFFF) cp = 0x10000 + ((cp - 0xD800) << 10) + (lo - 0xDC00);
- }
- return mdIsUnicodePunct(cp);
- }
- /**
- * String.fromCharCode with surrogate-pair support.
- * @param {number} cp
- * @returns {string}
- */
- function mdFromCodePoint(cp) {
- if (cp == null || cp < 0 || cp > 0x10FFFF || (cp >= 0xD800 && cp <= 0xDFFF)) return '\uFFFD';
- if (cp <= 0xFFFF) return String.fromCharCode(cp);
- var c = cp - 0x10000;
- return String.fromCharCode(0xD800 + (c >> 10), 0xDC00 + (c & 0x3FF));
- }
- var mdEntityMap = null;
- /** Parse MD_ENTITIES_PACKED into a name -> string map (once). */
- function mdGetEntityMap() {
- if (mdEntityMap) return mdEntityMap;
- var map = {}, recs = MD_ENTITIES_PACKED.split('\n');
- for (var i = 0; i < recs.length; i++) {
- var sp = recs[i].indexOf(' ');
- if (sp < 0) continue;
- var cps = recs[i].slice(sp + 1).split(',');
- var s = '';
- for (var j = 0; j < cps.length; j++) s += mdFromCodePoint(parseInt(cps[j], 10));
- map[recs[i].slice(0, sp)] = s;
- }
- mdEntityMap = map;
- return map;
- }
- /**
- * Resolve an entity reference at the start of `s`; null when invalid.
- * @param {string} s
- * @returns {?string}
- */
- function mdReplaceEntity(s) {
- var m = s.match(MD_ENTITY_HERE_RE);
- if (!m) return null;
- var body = m[0].slice(1, -1);
- if (body.charAt(0) === '#') {
- var num = body.charAt(1) === 'x' || body.charAt(1) === 'X'
- ? parseInt(body.slice(2), 16)
- : parseInt(body.slice(1), 10);
- if (isNaN(num) || num === 0 || num > 0x10FFFF) return '\uFFFD';
- return mdFromCodePoint(num);
- }
- var map = mdGetEntityMap();
- return Object.prototype.hasOwnProperty.call(map, body) ? map[body] : null;
- }
- /**
- * Replace backslash escapes and entity references (spec 2.2/2.3). Used on
- * link destinations, titles, labels and code info strings.
- * @param {string} s
- * @returns {string}
- */
- function mdUnescapeString(s) {
- if (s.indexOf('\\') < 0 && s.indexOf('&') < 0) return s;
- var out = '', i = 0, ch, rep, m;
- while (i < s.length) {
- ch = s.charAt(i);
- if (ch === '\\' && MD_ESCAPABLE.indexOf(s.charAt(i + 1)) >= 0) {
- out += s.charAt(i + 1);
- i += 2;
- continue;
- }
- if (ch === '&') {
- // entity references are at most 34 characters long (spec 2.3), so a
- // bounded window is enough and keeps this loop linear in s.length
- rep = mdReplaceEntity(s.slice(i, i + 34));
- if (rep !== null) {
- m = s.slice(i, i + 34).match(MD_ENTITY_HERE_RE);
- out += rep;
- i += m[0].length;
- continue;
- }
- }
- out += ch;
- i++;
- }
- return out;
- }
- // --- inline nodes -----------------------------------------------------------
- /**
- * Create an inline node. Types: text, softbreak, code, emph, strong,
- * link, image, html (escaped text).
- */
- function mdInlineNode(type, literal) {
- return { type: type, literal: literal == null ? '' : literal,
- parent: null, next: null, prev: null,
- firstChild: null, lastChild: null,
- destination: null, title: null, hardBreak: false };
- }
- function mdAppendChild(parent, node) {
- node.parent = parent;
- node.prev = parent.lastChild;
- if (parent.lastChild) parent.lastChild.next = node;
- else parent.firstChild = node;
- parent.lastChild = node;
- return node;
- }
- function mdUnlink(node) {
- if (node.prev) node.prev.next = node.next;
- else if (node.parent) node.parent.firstChild = node.next;
- if (node.next) node.next.prev = node.prev;
- else if (node.parent) node.parent.lastChild = node.prev;
- node.parent = null;
- node.next = null;
- node.prev = null;
- }
- function mdInsertAfter(node, sibling) {
- sibling.parent = node.parent;
- sibling.next = node.next;
- sibling.prev = node;
- if (node.next) node.next.prev = sibling;
- else if (node.parent) node.parent.lastChild = sibling;
- node.next = sibling;
- }
- /** Collect a node's children into an array (for rendering). */
- function mdChildren(node) {
- var out = [], c = node.firstChild;
- while (c) { out.push(c); c = c.next; }
- return out;
- }
- // --- the subject scanner ----------------------------------------------------
- /**
- * Parse the inline content of one leaf block.
- * @param {string} subject already-trimmed paragraph/heading text
- * @param {Object} refmap normalised-label -> { destination, title }
- * @returns {Object} a synthetic parent whose children are the inlines
- */
- function mdParseInlines(subject, refmap) {
- var block = { parent: null, next: null, prev: null,
- firstChild: null, lastChild: null, type: 'root' };
- var pos = 0;
- var delimiters = null; // linked list, newest first
- var brackets = null; // linked list, newest first
- function text(s) { return mdAppendChild(block, mdInlineNode('text', s)); }
- function peek() { return pos < subject.length ? subject.charAt(pos) : ''; }
- function match(re) {
- var m = re.exec(subject.slice(pos));
- if (m) pos += m[0].length;
- return m;
- }
- function spnl() {
- match(/^ *(?:\n *)?/);
- return true;
- }
- // -- emphasis delimiter bookkeeping --
- function scanDelims(cc) {
- var numdelims = 0, startpos = pos;
- while (peek() === cc) { numdelims++; pos++; }
- // adjacent characters, taking surrogate pairs as one character
- var charBefore = startpos === 0 ? '\n'
- : (mdIsHighSurrogate(subject.charAt(startpos - 1))
- ? subject.slice(startpos - 2, startpos)
- : subject.charAt(startpos - 1));
- var nextCh = peek();
- var charAfter = nextCh === '' ? '\n'
- : (mdIsHighSurrogate(nextCh) ? subject.substr(pos, 2) : nextCh);
- var afterWs = /^\s/.test(charAfter);
- var beforeWs = /^\s/.test(charBefore);
- var afterPunct = mdIsPunct(charAfter);
- var beforePunct = mdIsPunct(charBefore);
- var leftFlanking = !afterWs && (!afterPunct || beforeWs || beforePunct);
- var rightFlanking = !beforeWs && (!beforePunct || afterWs || afterPunct);
- var canOpen, canClose;
- if (cc === '_') {
- canOpen = leftFlanking && (!rightFlanking || beforePunct);
- canClose = rightFlanking && (!leftFlanking || afterPunct);
- } else {
- canOpen = leftFlanking;
- canClose = rightFlanking;
- }
- pos = startpos;
- return { numdelims: numdelims, canOpen: canOpen, canClose: canClose };
- }
- function handleDelim(cc) {
- var res = scanDelims(cc);
- if (!res || res.numdelims === 0) return false;
- var node = text(subject.slice(pos, pos + res.numdelims));
- pos += res.numdelims;
- if (res.canOpen || res.canClose) {
- var d = { cc: cc, numdelims: res.numdelims, origdelims: res.numdelims,
- node: node, previous: delimiters, next: null,
- canOpen: res.canOpen, canClose: res.canClose };
- if (delimiters) delimiters.next = d;
- delimiters = d;
- }
- return true;
- }
- function removeDelimiter(d) {
- if (d.previous) d.previous.next = d.next;
- if (d.next === null) delimiters = d.previous;
- else d.next.previous = d.previous;
- }
- function removeDelimitersBetween(bottom, top) {
- if (bottom.next !== top) { bottom.next = top; top.previous = bottom; }
- }
- /** True for the high half of a UTF-16 surrogate pair. */
- function mdIsHighSurrogate(ch) {
- var c = ch.charCodeAt(0);
- return c >= 0xD800 && c <= 0xDBFF;
- }
- /** Emphasis resolution over the delimiter stack (spec 6.2). */
- function processEmphasis(stackBottom) {
- var openersBottom = new Array(8);
- for (var i = 0; i < 8; i++) openersBottom[i] = stackBottom;
- var closer = delimiters;
- while (closer !== null && closer.previous !== stackBottom) closer = closer.previous;
- var opener, openerInl, closerInl, useDelims, tmp, next, openerFound, oddMatch;
- while (closer !== null) {
- if (!closer.canClose) { closer = closer.next; continue; }
- opener = closer.previous;
- openerFound = false;
- // openers_bottom index: 0..3 for '_', 4..7 for '*' — see rule of 3
- var idx = (closer.cc === '_' ? 0 : 4) + (closer.canOpen ? 2 : 0) + (closer.origdelims % 3 === 0 ? 0 : 1);
- while (opener !== null && opener !== stackBottom && opener !== openersBottom[idx]) {
- oddMatch = (closer.canOpen || opener.canClose) &&
- closer.origdelims % 3 !== 0 &&
- (opener.origdelims + closer.origdelims) % 3 === 0;
- if (opener.cc === closer.cc && opener.canOpen && !oddMatch) { openerFound = true; break; }
- opener = opener.previous;
- }
- var oldCloser = closer;
- if (!openerFound) {
- openersBottom[idx] = oldCloser.previous;
- if (!oldCloser.canOpen) removeDelimiter(oldCloser);
- closer = closer.next;
- continue;
- }
- useDelims = closer.numdelims >= 2 && opener.numdelims >= 2 ? 2 : 1;
- openerInl = opener.node;
- closerInl = closer.node;
- opener.numdelims -= useDelims;
- closer.numdelims -= useDelims;
- openerInl.literal = openerInl.literal.slice(0, openerInl.literal.length - useDelims);
- closerInl.literal = closerInl.literal.slice(0, closerInl.literal.length - useDelims);
- var emph = mdInlineNode(useDelims === 1 ? 'emph' : 'strong');
- tmp = openerInl.next;
- while (tmp && tmp !== closerInl) {
- next = tmp.next;
- mdUnlink(tmp);
- mdAppendChild(emph, tmp);
- tmp = next;
- }
- mdInsertAfter(openerInl, emph);
- removeDelimitersBetween(opener, closer);
- if (opener.numdelims === 0) { mdUnlink(openerInl); removeDelimiter(opener); }
- if (closer.numdelims === 0) {
- mdUnlink(closerInl);
- var after = closer.next;
- removeDelimiter(closer);
- closer = after;
- }
- // when the closer still has delimiters left, stay on it: the next
- // iteration searches for another opener further left
- }
- while (delimiters !== null && delimiters !== stackBottom) removeDelimiter(delimiters);
- }
- // -- link / image machinery --
- /**
- * Parse a link title at pos; returns the unescaped title or null.
- * Uses the linear scanner (no regex backtracking).
- */
- function parseLinkTitle() {
- var res = mdScanLinkTitle(subject, pos);
- if (!res) return null;
- pos += res.len;
- return mdUnescapeString(res.text);
- }
- /** Parse `<dest>` or a bare destination; returns normalised URI or null. */
- function parseLinkDestination() {
- var m = match(MD_LINK_DEST_BRACES_RE);
- if (m) return mdNormalizeUri(mdUnescapeString(m[0].slice(1, -1)));
- if (peek() === '<') return null;
- var savepos = pos, openparens = 0, c;
- while ((c = peek()) !== '') {
- if (c === '\\' && subject.charAt(pos + 1) !== '' &&
- MD_ESCAPABLE.indexOf(subject.charAt(pos + 1)) >= 0) {
- pos += 1;
- if (peek() !== '') pos += 1;
- } else if (c === '(') { pos++; openparens++; }
- else if (c === ')') { if (openparens < 1) break; pos++; openparens--; }
- else if (MD_WS_CHAR_RE.test(c)) break;
- else pos++;
- }
- if (pos === savepos && c !== ')') return null;
- if (openparens !== 0) { pos = savepos; return null; }
- return mdNormalizeUri(mdUnescapeString(subject.slice(savepos, pos)));
- }
- /**
- * Parse `[...]` at pos; returns the consumed length (including both
- * brackets), or 0 when there is no well-formed label. A label may not
- * contain a blank line and is capped at 1000 characters.
- */
- function parseLinkLabel() {
- if (subject.charAt(pos) !== '[') return 0;
- var i = pos + 1, ch;
- while (i < subject.length) {
- ch = subject.charAt(i);
- if (ch === '\\') { i += 2; continue; }
- if (ch === '[') return 0; // nested brackets are not labels
- if (ch === ']') break;
- i++;
- }
- if (subject.charAt(i) !== ']') return 0;
- var len = i + 1 - pos;
- var label = subject.slice(pos, i + 1);
- if (len > 1001) return 0;
- if (/\n[ \t]*\n/.test(label)) return 0; // no blank lines inside
- return len;
- }
- function addBracket(node, index, image) {
- if (brackets) brackets.bracketAfter = true;
- brackets = { node: node, previous: brackets, previousDelimiter: delimiters,
- index: index, image: image, active: true, bracketAfter: false };
- }
- function removeBracket() { brackets = brackets.previous; }
- function parseCloseBracket() {
- var startpos = pos, isImage, dest, title, matched = false, reflabel;
- pos += 1;
- var opener = brackets;
- if (opener === null) { text(']'); return true; }
- if (!opener.active) { text(']'); removeBracket(); return true; }
- isImage = opener.image;
- var savepos = pos;
- if (peek() === '(') {
- pos++;
- if (spnl() && (dest = parseLinkDestination()) !== null) {
- var beforeTitle = pos;
- spnl();
- // A title is only allowed when whitespace separated it from the
- // destination (spec: "optional... preceded by a space").
- if (pos !== beforeTitle) {
- var tryTitle = parseLinkTitle();
- if (tryTitle !== null) {
- title = tryTitle;
- spnl();
- } else {
- pos = beforeTitle;
- }
- }
- if (peek() === ')') {
- pos += 1;
- matched = true;
- } else {
- pos = savepos;
- }
- } else {
- pos = savepos;
- }
- }
- if (!matched) {
- var beforelabel = pos;
- var n = parseLinkLabel();
- if (n > 2) {
- // full reference: [text][label]
- reflabel = subject.slice(beforelabel, beforelabel + n);
- pos = beforelabel + n;
- } else if (n === 2 && !opener.bracketAfter) {
- // collapsed reference: [text][] — consume the empty label
- reflabel = '[' + subject.slice(opener.index, startpos) + ']';
- pos = beforelabel + n;
- } else if (!opener.bracketAfter) {
- // shortcut reference: [text]
- reflabel = '[' + subject.slice(opener.index, startpos) + ']';
- }
- if (n === 0) pos = savepos;
- if (reflabel) {
- var link = refmap[mdNormalizeReference(reflabel)];
- if (link) { dest = link.destination; title = link.title; matched = true; }
- }
- }
- if (matched) {
- var node = mdInlineNode(isImage ? 'image' : 'link');
- node.destination = dest == null ? '' : dest;
- node.title = title == null ? '' : title;
- var tmp = opener.node.next, next;
- while (tmp) {
- next = tmp.next;
- mdUnlink(tmp);
- mdAppendChild(node, tmp);
- tmp = next;
- }
- // the link takes the opener's position in the parent's child list
- mdInsertAfter(opener.node, node);
- processEmphasis(opener.previousDelimiter);
- removeBracket();
- mdUnlink(opener.node);
- if (!isImage) {
- var b = brackets;
- while (b !== null) { if (!b.image) b.active = false; b = b.previous; }
- }
- return true;
- }
- removeBracket();
- // NB: `startpos` was captured before consuming ']', so pos now sits
- // just after it — do not rewind onto the bracket again.
- pos = startpos + 1;
- text(']');
- return true;
- }
- // -- autolinks and raw HTML (neutralised) --
- var MD_EMAIL_AUTOLINK_RE = /^<([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)>/;
- var MD_AUTOLINK_RE = /^<[A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\x00-\x20]*>/i;
- /**
- * Try an autolink at pos. Returns the node or null.
- */
- function parseAutolink() {
- // Autolinks cannot contain whitespace or '<'/'>' (MD_AUTOLINK_RE), so
- // slicing to the next such character bounds the scan without changing
- // what can match. Without this bound the slice+match was quadratic in
- // pathological input (thousands of unmatched '<').
- var rest = subject.slice(pos, mdBoundScan(subject, pos));
- var m = rest.match(MD_AUTOLINK_RE);
- var node;
- if (m) {
- node = mdInlineNode('link');
- node.destination = mdNormalizeUri(m[0].slice(1, -1));
- node.autolinkText = m[0].slice(1, -1);
- mdAppendChild(block, node);
- mdAppendChild(node, mdInlineNode('text', m[0].slice(1, -1)));
- pos += m[0].length;
- return node;
- }
- m = rest.match(MD_EMAIL_AUTOLINK_RE);
- if (m) {
- node = mdInlineNode('link');
- node.destination = 'mailto:' + m[1];
- node.autolinkText = m[1];
- mdAppendChild(block, node);
- mdAppendChild(node, mdInlineNode('text', m[1]));
- pos += m[0].length;
- return node;
- }
- return null;
- }
- /**
- * Match a raw HTML tag at pos. SECURITY: the matched text is returned so
- * the caller can render it escaped — it is never emitted as markup.
- */
- function parseHtmlTag() {
- var raw = mdScanHtmlTag(subject, pos);
- if (!raw) return null;
- var node = mdAppendChild(block, mdInlineNode('html'));
- node.literal = raw;
- pos += raw.length;
- return node;
- }
- // -- the main dispatch loop --
- while (pos < subject.length) {
- var c = peek();
- var res = false;
- switch (c) {
- case '\n':
- pos++;
- {
- var lastc = block.lastChild;
- if (lastc && lastc.type === 'text' && / $/.test(lastc.literal)) {
- var hard = / {2}$/.test(lastc.literal);
- lastc.literal = lastc.literal.replace(MD_FINAL_SPACE_RE, '');
- var sb = mdAppendChild(block, mdInlineNode('softbreak'));
- sb.hardBreak = hard;
- } else {
- mdAppendChild(block, mdInlineNode('softbreak'));
- }
- match(/^ */);
- }
- break;
- case '\\':
- if (subject.charAt(pos + 1) === '\n') {
- pos += 2;
- var hb = mdAppendChild(block, mdInlineNode('softbreak'));
- hb.hardBreak = true;
- match(/^ */);
- } else if (subject.charAt(pos + 1) !== '' &&
- MD_ESCAPABLE.indexOf(subject.charAt(pos + 1)) >= 0) {
- text(subject.charAt(pos + 1));
- pos += 2;
- } else {
- text('\\');
- pos++;
- }
- break;
- case '`':
- {
- // opening run, then the next run of backticks of the SAME length
- var ticks = subject.slice(pos).match(MD_TICKS_HERE_RE)[0];
- var afterOpen = pos + ticks.length;
- var searchPos = afterOpen, run;
- var codeNode = null;
- while ((run = subject.slice(searchPos).match(/^[\s\S]*?(`+)/)) && run[1]) {
- var runStart = searchPos + run[0].length - run[1].length;
- if (run[1].length === ticks.length) {
- // newline -> space; spaces *before* a newline are dropped
- // (spec: "line endings are replaced by spaces... preceded
- // by a space are removed")
- var content = subject.slice(afterOpen, runStart)
- .replace(/ *\n/g, '\n').replace(/\n/g, ' ');
- if (/^ /.test(content) && / $/.test(content) && content.replace(/ /g, '') !== '') {
- content = content.slice(1, content.length - 1);
- }
- codeNode = mdAppendChild(block, mdInlineNode('code', content));
- pos = runStart + run[1].length;
- break;
- }
- searchPos = runStart + run[1].length;
- }
- if (!codeNode) {
- text(ticks);
- pos = afterOpen;
- }
- }
- break;
- case '*':
- case '_':
- handleDelim(c);
- break;
- case '[':
- {
- var node = text('[');
- addBracket(node, pos + 1, false);
- pos++;
- }
- break;
- case '!':
- if (subject.charAt(pos + 1) === '[') {
- var n2 = text('![');
- addBracket(n2, pos + 2, true);
- pos += 2;
- } else {
- text('!');
- pos++;
- }
- break;
- case ']':
- parseCloseBracket();
- break;
- case '<':
- if (parseAutolink()) break;
- if (parseHtmlTag()) break;
- text('<');
- pos++;
- break;
- case '&':
- {
- var rep = mdReplaceEntity(subject.slice(pos, pos + 34));
- if (rep !== null) {
- text(rep);
- pos += subject.slice(pos, pos + 34).match(MD_ENTITY_HERE_RE)[0].length;
- } else {
- text('&');
- pos++;
- }
- }
- break;
- default:
- {
- var m = subject.slice(pos).match(/^[^\n`\\[\]!<&*_]+/);
- if (!m) { text(c); pos++; }
- else { text(m[0]); pos += m[0].length; }
- }
- }
- }
- processEmphasis(null);
- return block;
- }
- // ---------------------------------------------------------------------------
- // Markdown HTML rendering
- // ---------------------------------------------------------------------------
- /**
- * Escape the five HTML-significant characters. `"` becomes `"` (also
- * safe inside double-quoted attributes), matching cmark.
- * @param {string} s
- * @returns {string}
- */
- function mdEscape(s) {
- return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')
- .replace(/"/g, '"');
- }
- /**
- * Parse (once) and render a leaf block's inline content. The parsed inline
- * tree is cached on the block so image alt text can reuse it.
- */
- function mdLeafInlines(node, refmap) {
- if (!node._inlines) {
- node._inlines = mdParseInlines(node.strings.join('\n').trim(), refmap);
- }
- return node._inlines;
- }
- /** Render inline nodes to HTML (children of a paragraph/heading). */
- function mdRenderInlines(node) {
- var out = '', c = node.firstChild;
- while (c) {
- switch (c.type) {
- case 'text':
- out += mdEscape(c.literal);
- break;
- case 'softbreak':
- out += c.hardBreak ? '<br />\n' : '\n';
- break;
- case 'code':
- out += '<code>' + mdEscape(c.literal) + '</code>';
- break;
- case 'emph':
- out += '<em>' + mdRenderInlines(c) + '</em>';
- break;
- case 'strong':
- out += '<strong>' + mdRenderInlines(c) + '</strong>';
- break;
- case 'link':
- out += '<a href="' + safeMarkdownUrl(mdEscapeAttr(c.destination)) + '"' +
- (c.title ? ' title="' + mdEscapeAttr(c.title) + '"' : '') + '>' +
- mdRenderInlines(c) + '</a>';
- break;
- case 'image':
- out += '<img src="' + safeMarkdownUrl(mdEscapeAttr(c.destination)) + '"' +
- ' alt="' + mdImageAlt(c) + '"' +
- (c.title ? ' title="' + mdEscapeAttr(c.title) + '"' : '') + ' />';
- break;
- case 'html':
- out += mdEscape(c.literal);
- break;
- default:
- out += mdEscape(c.literal || '');
- }
- c = c.next;
- }
- return out;
- }
- /** Plain-text rendering of image alt text (markdown stripped). */
- function mdImageAlt(node) {
- var out = '', c = node.firstChild;
- while (c) {
- if (c.type === 'text' || c.type === 'code' || c.type === 'html') out += c.literal;
- else if (c.type === 'softbreak') out += c.hardBreak ? '\n' : '\n';
- else if (c.firstChild) out += mdImageAlt(c);
- c = c.next;
- }
- return mdEscapeAttr(out);
- }
- /** Escape for a double-quoted attribute value. */
- function mdEscapeAttr(s) {
- return String(s).replace(/&/g, '&').replace(/"/g, '"')
- .replace(/</g, '<').replace(/>/g, '>');
- }
- /**
- * Output buffer that suppresses repeated newlines (cmark's `cr`).
- */
- function mdOut() {
- // `last` starts as a newline so the very first cr() is a no-op
- return { s: '', last: '\n' };
- }
- /** Append a literal string. */
- function mdLit(out, s) {
- if (!s) return;
- out.s += s;
- out.last = s.charAt(s.length - 1);
- }
- /** Append a newline unless the output already ends with one. */
- function mdCr(out) {
- if (out.last !== '\n') mdLit(out, '\n');
- }
- /**
- * Render one block node (and its children) to HTML. `tight` is the
- * enclosing list's tightness: tight lists suppress `<p>` wrappers.
- */
- function mdRenderBlocks(node, tight, out, refmap) {
- var i, child;
- switch (node.type) {
- case 'document':
- for (i = 0; i < node.children.length; i++) mdRenderBlocks(node.children[i], tight, out, refmap);
- break;
- case 'paragraph':
- // in a tight list the paragraph renders bare
- if (tight) { mdLit(out, mdRenderInlines(mdLeafInlines(node, refmap))); }
- else {
- mdCr(out);
- mdLit(out, '<p>');
- mdLit(out, mdRenderInlines(mdLeafInlines(node, refmap)));
- mdLit(out, '</p>');
- mdCr(out);
- }
- break;
- case 'heading':
- mdCr(out);
- mdLit(out, '<h' + node.level + '>');
- mdLit(out, mdRenderInlines(mdLeafInlines(node, refmap)));
- mdLit(out, '</h' + node.level + '>');
- mdCr(out);
- break;
- case 'thematic':
- mdCr(out);
- mdLit(out, '<hr />');
- mdCr(out);
- break;
- case 'code':
- mdCr(out);
- var info = node.info ? node.info.split(/\s+/)[0] : '';
- var attrs = '';
- if (info) attrs = ' class="language-' + mdEscapeAttr(info) + '"';
- mdLit(out, '<pre><code' + attrs + '>' + mdEscape(node.literal) + '</code></pre>');
- mdCr(out);
- break;
- case 'blockquote':
- mdCr(out);
- mdLit(out, '<blockquote>');
- mdCr(out);
- // cmark unwraps paragraphs only when their grandparent is a tight
- // list; inside a blockquote they always keep their <p>.
- for (i = 0; i < node.children.length; i++) mdRenderBlocks(node.children[i], false, out, refmap);
- mdCr(out);
- mdLit(out, '</blockquote>');
- mdCr(out);
- break;
- case 'list':
- mdCr(out);
- var tag = node.listData.type === 'ordered' ? 'ol' : 'ul';
- var start = '';
- if (tag === 'ol' && node.listData.start != null && node.listData.start !== 1) {
- start = ' start="' + node.listData.start + '"';
- }
- mdLit(out, '<' + tag + start + '>');
- mdCr(out);
- for (i = 0; i < node.children.length; i++) mdRenderBlocks(node.children[i], node.tight, out, refmap);
- mdCr(out);
- mdLit(out, '</' + tag + '>');
- mdCr(out);
- break;
- case 'item':
- mdLit(out, '<li>');
- for (i = 0; i < node.children.length; i++) {
- // tightness applies to the item's own paragraphs and lists;
- // blockquote contents are always loose.
- mdRenderBlocks(node.children[i], node.children[i].type === 'blockquote' ? false : tight, out, refmap);
- }
- mdLit(out, '</li>');
- mdCr(out);
- break;
- default:
- break;
- }
- }
- /**
- * Render markdown to safe HTML.
- *
- * CommonMark 0.31.2 minus raw HTML (escaped instead, see the note at the
- * top of the markdown section) and minus HTML-block constructs that only
- * exist to feed raw HTML through.
- * @param {string} raw markdown source
- * @returns {string} HTML safe for `innerHTML`
- */
- function renderMarkdown(raw) {
- var parser = mdParseDocument(raw);
- var out = mdOut();
- mdRenderBlocks(parser.doc, false, out, parser.refmap);
- return out.s;
- }
- /**
- * Demote child header tags by N levels (h1 → h2, etc.), capping at h6.
- */
- function handleHDemotion(el) {
- var attr = el.getAttribute('stm-h-demotion');
- if (!attr) return;
- var n = parseInt(attr, 10);
- if (isNaN(n) || n <= 0) return;
- el.querySelectorAll('h1,h2,h3,h4,h5,h6').forEach(function (h) {
- var level = parseInt(h.tagName.charAt(1), 10);
- var newLevel = Math.min(level + n, 6);
- if (newLevel === level) return;
- var replacement = document.createElement('h' + newLevel);
- for (var i = 0; i < h.attributes.length; i++)
- replacement.setAttribute(h.attributes[i].name, h.attributes[i].value);
- while (h.firstChild) replacement.appendChild(h.firstChild);
- h.replaceWith(replacement);
- });
- }
- // ---------------------------------------------------------------------------
- // Bindings (module seam) + programmatic API
- // ---------------------------------------------------------------------------
- /** Normalise a binding value to markdown source (`null`/`undefined` -> ''). */
- function mdSource(value) {
- return value === null || value === undefined ? '' : String(value);
- }
- /**
- * Apply a markdown value to an element: the single code path shared by the
- * `stm-markdown` handler and `statum.markdown.renderTo`. Per the "leave
- * original DOM content" policy, an unresolved value (`undefined`) leaves
- * the element untouched.
- */
- function applyMarkdown(el, value) {
- if (value === undefined) return;
- el.innerHTML = renderMarkdown(mdSource(value));
- }
- /** Bind `stm-markdown`: render the expression's value as markdown. */
- function handleMarkdown(el, scope) {
- if (el.hasAttribute('stm-markdown')) {
- var md = evalExpr(el.getAttribute('stm-markdown'), scope);
- applyMarkdown(el, md);
- }
- }
- /**
- * Bind `stm-h-demotion`: demote the element's headers. Registered after
- * `stm-markdown` (and therefore also after `stm-html`) so the rendered
- * headers are present in the DOM when it runs.
- */
- function handleDemotion(el) {
- if (el.hasAttribute('stm-h-demotion')) handleHDemotion(el);
- }
- /**
- * Programmatic markdown API, sharing the binding's code path.
- */
- window.statum.markdown = {
- /** Render markdown source to safe HTML. @param {string} src */
- render: function (src) { return renderMarkdown(mdSource(src)); },
- /** Render markdown source into an element (replaces its content). */
- renderTo: function (el, src) { applyMarkdown(el, src); }
- };
- // Ordering constraints: markdown renders before demotion so the headers it
- // produces exist when demotion runs.
- bridge.registerAttribute('stm-markdown', handleMarkdown, { after: 'stm-html' });
- bridge.registerAttribute('stm-h-demotion', handleDemotion, { after: 'stm-markdown' });
- // Test-only escape hatch: tests/markdown and tests/split load these module
- // files under QuickJS with `window.__STATUM_TEST__` set beforehand and
- // reach the engine through statum._testMarkdown. Shipped pages never set
- // the flag, so this adds no surface to the public API.
- if (window.__STATUM_TEST__) window.statum._testMarkdown = renderMarkdown;
- })();
|