Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

5 роки тому
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758
  1. <!DOCTYPE html>
  2. <html>
  3. <meta charset="utf-8">
  4. <head>
  5. <style>
  6. table
  7. {
  8. border-collapse: collapse;
  9. width: 100%;
  10. }
  11. table, th, td
  12. {
  13. border: 1px solid #aaa;
  14. padding: 0.5em;
  15. margin-top: 0.5em;
  16. margin-bottom: 0.5em;
  17. }
  18. .error
  19. {
  20. color: red;
  21. }
  22. .section
  23. {
  24. text-align: center;
  25. font-weight: bold;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <table>
  31. <tr>
  32. <td colspan="2" class="section">
  33. <a href="http://opengamestudio.org/lfsa">Local file system access</a>
  34. </td>
  35. </tr>
  36. <tr>
  37. <td>Path:</td>
  38. <td id="lfsaPath">Updating...</td>
  39. </tr>
  40. <tr>
  41. <td colspan="2" class="section">
  42. Configuration
  43. <button type="button" onclick="window.pskovTool.saveCfg()">Save</button>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td>Input directory:</td>
  48. <td><input id="input"></input></td>
  49. </tr>
  50. <tr>
  51. <td>Item template:</td>
  52. <td><input id="item"></input></td>
  53. </tr>
  54. <tr>
  55. <td>Preview template:</td>
  56. <td><input id="preview"></input></td>
  57. </tr>
  58. <tr>
  59. <td>Index template:</td>
  60. <td><input id="index"></input></td>
  61. </tr>
  62. <tr>
  63. <td>Pagination 'Previous' template:</td>
  64. <td><input id="paginationPrev"></input></td>
  65. </tr>
  66. <tr>
  67. <td>Pagination 'Next' template:</td>
  68. <td><input id="paginationNext"></input></td>
  69. </tr>
  70. <tr>
  71. <td>Pagination 'Previous/Next' template:</td>
  72. <td><input id="paginationPrevNext"></input></td>
  73. </tr>
  74. <tr>
  75. <td>Preview characters limit:</td>
  76. <td><input id="previewSize"></input></td>
  77. </tr>
  78. <tr>
  79. <td>Preview ending string:</td>
  80. <td><input id="previewEnding"></input></td>
  81. </tr>
  82. <tr>
  83. <td>Previews per page:</td>
  84. <td><input id="previewsPerPage"></input></td>
  85. </tr>
  86. <tr>
  87. <td>Preview page base name:</td>
  88. <td><input id="previewPageBaseName"></input></td>
  89. </tr>
  90. <tr>
  91. <td colspan="2" class="section">
  92. News
  93. <button type="button" onclick="window.pskovTool.generateNews()">Generate</button>
  94. </td>
  95. </tr>
  96. <tr>
  97. <td colspan="2" class="section">Log</td>
  98. </tr>
  99. <tr>
  100. <td id="log" colspan="2"></td>
  101. </tr>
  102. </table>
  103. <script type="text/javascript">
  104. <!-- showdown.js -->
  105. ;/*! showdown v 2.0.0-alpha1 - 24-10-2018 */
  106. (function(){
  107. /**
  108. * Created by Tivie on 13-07-2015.
  109. */
  110. function getDefaultOpts (simple) {
  111. 'use strict';
  112. var defaultOptions = {
  113. omitExtraWLInCodeBlocks: {
  114. defaultValue: false,
  115. describe: 'Omit the default extra whiteline added to code blocks',
  116. type: 'boolean'
  117. },
  118. noHeaderId: {
  119. defaultValue: false,
  120. describe: 'Turn on/off generated header id',
  121. type: 'boolean'
  122. },
  123. prefixHeaderId: {
  124. defaultValue: false,
  125. describe: 'Add a prefix to the generated header ids. Passing a string will prefix that string to the header id. Setting to true will add a generic \'section-\' prefix',
  126. type: 'string'
  127. },
  128. rawPrefixHeaderId: {
  129. defaultValue: false,
  130. describe: 'Setting this option to true will prevent showdown from modifying the prefix. This might result in malformed IDs (if, for instance, the " char is used in the prefix)',
  131. type: 'boolean'
  132. },
  133. ghCompatibleHeaderId: {
  134. defaultValue: false,
  135. describe: 'Generate header ids compatible with github style (spaces are replaced with dashes, a bunch of non alphanumeric chars are removed)',
  136. type: 'boolean'
  137. },
  138. rawHeaderId: {
  139. defaultValue: false,
  140. describe: 'Remove only spaces, \' and " from generated header ids (including prefixes), replacing them with dashes (-). WARNING: This might result in malformed ids',
  141. type: 'boolean'
  142. },
  143. headerLevelStart: {
  144. defaultValue: false,
  145. describe: 'The header blocks level start',
  146. type: 'integer'
  147. },
  148. parseImgDimensions: {
  149. defaultValue: false,
  150. describe: 'Turn on/off image dimension parsing',
  151. type: 'boolean'
  152. },
  153. simplifiedAutoLink: {
  154. defaultValue: false,
  155. describe: 'Turn on/off GFM autolink style',
  156. type: 'boolean'
  157. },
  158. literalMidWordUnderscores: {
  159. defaultValue: false,
  160. describe: 'Parse midword underscores as literal underscores',
  161. type: 'boolean'
  162. },
  163. literalMidWordAsterisks: {
  164. defaultValue: false,
  165. describe: 'Parse midword asterisks as literal asterisks',
  166. type: 'boolean'
  167. },
  168. strikethrough: {
  169. defaultValue: false,
  170. describe: 'Turn on/off strikethrough support',
  171. type: 'boolean'
  172. },
  173. tables: {
  174. defaultValue: false,
  175. describe: 'Turn on/off tables support',
  176. type: 'boolean'
  177. },
  178. tablesHeaderId: {
  179. defaultValue: false,
  180. describe: 'Add an id to table headers',
  181. type: 'boolean'
  182. },
  183. ghCodeBlocks: {
  184. defaultValue: true,
  185. describe: 'Turn on/off GFM fenced code blocks support',
  186. type: 'boolean'
  187. },
  188. tasklists: {
  189. defaultValue: false,
  190. describe: 'Turn on/off GFM tasklist support',
  191. type: 'boolean'
  192. },
  193. smoothLivePreview: {
  194. defaultValue: false,
  195. describe: 'Prevents weird effects in live previews due to incomplete input',
  196. type: 'boolean'
  197. },
  198. smartIndentationFix: {
  199. defaultValue: false,
  200. description: 'Tries to smartly fix indentation in es6 strings',
  201. type: 'boolean'
  202. },
  203. disableForced4SpacesIndentedSublists: {
  204. defaultValue: false,
  205. description: 'Disables the requirement of indenting nested sublists by 4 spaces',
  206. type: 'boolean'
  207. },
  208. simpleLineBreaks: {
  209. defaultValue: false,
  210. description: 'Parses simple line breaks as <br> (GFM Style)',
  211. type: 'boolean'
  212. },
  213. requireSpaceBeforeHeadingText: {
  214. defaultValue: false,
  215. description: 'Makes adding a space between `#` and the header text mandatory (GFM Style)',
  216. type: 'boolean'
  217. },
  218. ghMentions: {
  219. defaultValue: false,
  220. description: 'Enables github @mentions',
  221. type: 'boolean'
  222. },
  223. ghMentionsLink: {
  224. defaultValue: 'https://github.com/{u}',
  225. description: 'Changes the link generated by @mentions. Only applies if ghMentions option is enabled.',
  226. type: 'string'
  227. },
  228. encodeEmails: {
  229. defaultValue: true,
  230. description: 'Encode e-mail addresses through the use of Character Entities, transforming ASCII e-mail addresses into its equivalent decimal entities',
  231. type: 'boolean'
  232. },
  233. openLinksInNewWindow: {
  234. defaultValue: false,
  235. description: 'Open all links in new windows',
  236. type: 'boolean'
  237. },
  238. backslashEscapesHTMLTags: {
  239. defaultValue: false,
  240. description: 'Support for HTML Tag escaping. ex: \<div>foo\</div>',
  241. type: 'boolean'
  242. },
  243. emoji: {
  244. defaultValue: false,
  245. description: 'Enable emoji support. Ex: `this is a :smile: emoji`',
  246. type: 'boolean'
  247. },
  248. underline: {
  249. defaultValue: false,
  250. description: 'Enable support for underline. Syntax is double or triple underscores: `__underline word__`. With this option enabled, underscores no longer parses into `<em>` and `<strong>`',
  251. type: 'boolean'
  252. },
  253. completeHTMLDocument: {
  254. defaultValue: false,
  255. description: 'Outputs a complete html document, including `<html>`, `<head>` and `<body>` tags',
  256. type: 'boolean'
  257. },
  258. metadata: {
  259. defaultValue: false,
  260. description: 'Enable support for document metadata (defined at the top of the document between `«««` and `»»»` or between `---` and `---`).',
  261. type: 'boolean'
  262. },
  263. splitAdjacentBlockquotes: {
  264. defaultValue: false,
  265. description: 'Split adjacent blockquote blocks',
  266. type: 'boolean'
  267. }
  268. };
  269. if (simple === false) {
  270. return JSON.parse(JSON.stringify(defaultOptions));
  271. }
  272. var ret = {};
  273. for (var opt in defaultOptions) {
  274. if (defaultOptions.hasOwnProperty(opt)) {
  275. ret[opt] = defaultOptions[opt].defaultValue;
  276. }
  277. }
  278. return ret;
  279. }
  280. function allOptionsOn () {
  281. 'use strict';
  282. var options = getDefaultOpts(true),
  283. ret = {};
  284. for (var opt in options) {
  285. if (options.hasOwnProperty(opt)) {
  286. ret[opt] = true;
  287. }
  288. }
  289. return ret;
  290. }
  291. /**
  292. * Created by Tivie on 06-01-2015.
  293. */
  294. // Private properties
  295. var showdown = {},
  296. parsers = {},
  297. extensions = {},
  298. globalOptions = getDefaultOpts(true),
  299. setFlavor = 'vanilla',
  300. flavor = {
  301. github: {
  302. omitExtraWLInCodeBlocks: true,
  303. simplifiedAutoLink: true,
  304. literalMidWordUnderscores: true,
  305. strikethrough: true,
  306. tables: true,
  307. tablesHeaderId: true,
  308. ghCodeBlocks: true,
  309. tasklists: true,
  310. disableForced4SpacesIndentedSublists: true,
  311. simpleLineBreaks: true,
  312. requireSpaceBeforeHeadingText: true,
  313. ghCompatibleHeaderId: true,
  314. ghMentions: true,
  315. backslashEscapesHTMLTags: true,
  316. emoji: true,
  317. splitAdjacentBlockquotes: true
  318. },
  319. original: {
  320. noHeaderId: true,
  321. ghCodeBlocks: false
  322. },
  323. ghost: {
  324. omitExtraWLInCodeBlocks: true,
  325. parseImgDimensions: true,
  326. simplifiedAutoLink: true,
  327. literalMidWordUnderscores: true,
  328. strikethrough: true,
  329. tables: true,
  330. tablesHeaderId: true,
  331. ghCodeBlocks: true,
  332. tasklists: true,
  333. smoothLivePreview: true,
  334. simpleLineBreaks: true,
  335. requireSpaceBeforeHeadingText: true,
  336. ghMentions: false,
  337. encodeEmails: true
  338. },
  339. vanilla: getDefaultOpts(true),
  340. allOn: allOptionsOn()
  341. };
  342. /**
  343. * helper namespace
  344. * @type {{}}
  345. */
  346. showdown.helper = {};
  347. /**
  348. * TODO LEGACY SUPPORT CODE
  349. * @type {{}}
  350. */
  351. showdown.extensions = {};
  352. /**
  353. * Set a global option
  354. * @static
  355. * @param {string} key
  356. * @param {*} value
  357. * @returns {showdown}
  358. */
  359. showdown.setOption = function (key, value) {
  360. 'use strict';
  361. globalOptions[key] = value;
  362. return this;
  363. };
  364. /**
  365. * Get a global option
  366. * @static
  367. * @param {string} key
  368. * @returns {*}
  369. */
  370. showdown.getOption = function (key) {
  371. 'use strict';
  372. return globalOptions[key];
  373. };
  374. /**
  375. * Get the global options
  376. * @static
  377. * @returns {{}}
  378. */
  379. showdown.getOptions = function () {
  380. 'use strict';
  381. return globalOptions;
  382. };
  383. /**
  384. * Reset global options to the default values
  385. * @static
  386. */
  387. showdown.resetOptions = function () {
  388. 'use strict';
  389. globalOptions = getDefaultOpts(true);
  390. };
  391. /**
  392. * Set the flavor showdown should use as default
  393. * @param {string} name
  394. */
  395. showdown.setFlavor = function (name) {
  396. 'use strict';
  397. if (!flavor.hasOwnProperty(name)) {
  398. throw Error(name + ' flavor was not found');
  399. }
  400. showdown.resetOptions();
  401. var preset = flavor[name];
  402. setFlavor = name;
  403. for (var option in preset) {
  404. if (preset.hasOwnProperty(option)) {
  405. globalOptions[option] = preset[option];
  406. }
  407. }
  408. };
  409. /**
  410. * Get the currently set flavor
  411. * @returns {string}
  412. */
  413. showdown.getFlavor = function () {
  414. 'use strict';
  415. return setFlavor;
  416. };
  417. /**
  418. * Get the options of a specified flavor. Returns undefined if the flavor was not found
  419. * @param {string} name Name of the flavor
  420. * @returns {{}|undefined}
  421. */
  422. showdown.getFlavorOptions = function (name) {
  423. 'use strict';
  424. if (flavor.hasOwnProperty(name)) {
  425. return flavor[name];
  426. }
  427. };
  428. /**
  429. * Get the default options
  430. * @static
  431. * @param {boolean} [simple=true]
  432. * @returns {{}}
  433. */
  434. showdown.getDefaultOptions = function (simple) {
  435. 'use strict';
  436. return getDefaultOpts(simple);
  437. };
  438. /**
  439. * Get or set a subParser
  440. *
  441. * subParser(name) - Get a registered subParser
  442. * subParser(name, func) - Register a subParser
  443. * @static
  444. * @param {string} name
  445. * @param {function} [func]
  446. * @returns {*}
  447. */
  448. showdown.subParser = function (name, func) {
  449. 'use strict';
  450. if (showdown.helper.isString(name)) {
  451. if (typeof func !== 'undefined') {
  452. parsers[name] = func;
  453. } else {
  454. if (parsers.hasOwnProperty(name)) {
  455. return parsers[name];
  456. } else {
  457. throw Error('SubParser named ' + name + ' not registered!');
  458. }
  459. }
  460. } else {
  461. throw Error('showdown.subParser function first argument must be a string (the name of the subparser)');
  462. }
  463. };
  464. /**
  465. * Gets or registers an extension
  466. * @static
  467. * @param {string} name
  468. * @param {object|function=} ext
  469. * @returns {*}
  470. */
  471. showdown.extension = function (name, ext) {
  472. 'use strict';
  473. if (!showdown.helper.isString(name)) {
  474. throw Error('Extension \'name\' must be a string');
  475. }
  476. name = showdown.helper.stdExtName(name);
  477. // Getter
  478. if (showdown.helper.isUndefined(ext)) {
  479. if (!extensions.hasOwnProperty(name)) {
  480. throw Error('Extension named ' + name + ' is not registered!');
  481. }
  482. return extensions[name];
  483. // Setter
  484. } else {
  485. // Expand extension if it's wrapped in a function
  486. if (typeof ext === 'function') {
  487. ext = ext();
  488. }
  489. // Ensure extension is an array
  490. if (!showdown.helper.isArray(ext)) {
  491. ext = [ext];
  492. }
  493. var validExtension = validate(ext, name);
  494. if (validExtension.valid) {
  495. extensions[name] = ext;
  496. } else {
  497. throw Error(validExtension.error);
  498. }
  499. }
  500. };
  501. /**
  502. * Gets all extensions registered
  503. * @returns {{}}
  504. */
  505. showdown.getAllExtensions = function () {
  506. 'use strict';
  507. return extensions;
  508. };
  509. /**
  510. * Remove an extension
  511. * @param {string} name
  512. */
  513. showdown.removeExtension = function (name) {
  514. 'use strict';
  515. delete extensions[name];
  516. };
  517. /**
  518. * Removes all extensions
  519. */
  520. showdown.resetExtensions = function () {
  521. 'use strict';
  522. extensions = {};
  523. };
  524. /**
  525. * Validate extension
  526. * @param {array} extension
  527. * @param {string} name
  528. * @returns {{valid: boolean, error: string}}
  529. */
  530. function validate (extension, name) {
  531. 'use strict';
  532. var errMsg = (name) ? 'Error in ' + name + ' extension->' : 'Error in unnamed extension',
  533. ret = {
  534. valid: true,
  535. error: ''
  536. };
  537. if (!showdown.helper.isArray(extension)) {
  538. extension = [extension];
  539. }
  540. for (var i = 0; i < extension.length; ++i) {
  541. var baseMsg = errMsg + ' sub-extension ' + i + ': ',
  542. ext = extension[i];
  543. if (typeof ext !== 'object') {
  544. ret.valid = false;
  545. ret.error = baseMsg + 'must be an object, but ' + typeof ext + ' given';
  546. return ret;
  547. }
  548. if (!showdown.helper.isString(ext.type)) {
  549. ret.valid = false;
  550. ret.error = baseMsg + 'property "type" must be a string, but ' + typeof ext.type + ' given';
  551. return ret;
  552. }
  553. var type = ext.type = ext.type.toLowerCase();
  554. // normalize extension type
  555. if (type === 'language') {
  556. type = ext.type = 'lang';
  557. }
  558. if (type === 'html') {
  559. type = ext.type = 'output';
  560. }
  561. if (type !== 'lang' && type !== 'output' && type !== 'listener') {
  562. ret.valid = false;
  563. ret.error = baseMsg + 'type ' + type + ' is not recognized. Valid values: "lang/language", "output/html" or "listener"';
  564. return ret;
  565. }
  566. if (type === 'listener') {
  567. if (showdown.helper.isUndefined(ext.listeners)) {
  568. ret.valid = false;
  569. ret.error = baseMsg + '. Extensions of type "listener" must have a property called "listeners"';
  570. return ret;
  571. }
  572. } else {
  573. if (showdown.helper.isUndefined(ext.filter) && showdown.helper.isUndefined(ext.regex)) {
  574. ret.valid = false;
  575. ret.error = baseMsg + type + ' extensions must define either a "regex" property or a "filter" method';
  576. return ret;
  577. }
  578. }
  579. if (ext.listeners) {
  580. if (typeof ext.listeners !== 'object') {
  581. ret.valid = false;
  582. ret.error = baseMsg + '"listeners" property must be an object but ' + typeof ext.listeners + ' given';
  583. return ret;
  584. }
  585. for (var ln in ext.listeners) {
  586. if (ext.listeners.hasOwnProperty(ln)) {
  587. if (typeof ext.listeners[ln] !== 'function') {
  588. ret.valid = false;
  589. ret.error = baseMsg + '"listeners" property must be an hash of [event name]: [callback]. listeners.' + ln +
  590. ' must be a function but ' + typeof ext.listeners[ln] + ' given';
  591. return ret;
  592. }
  593. }
  594. }
  595. }
  596. if (ext.filter) {
  597. if (typeof ext.filter !== 'function') {
  598. ret.valid = false;
  599. ret.error = baseMsg + '"filter" must be a function, but ' + typeof ext.filter + ' given';
  600. return ret;
  601. }
  602. } else if (ext.regex) {
  603. if (showdown.helper.isString(ext.regex)) {
  604. ext.regex = new RegExp(ext.regex, 'g');
  605. }
  606. if (!(ext.regex instanceof RegExp)) {
  607. ret.valid = false;
  608. ret.error = baseMsg + '"regex" property must either be a string or a RegExp object, but ' + typeof ext.regex + ' given';
  609. return ret;
  610. }
  611. if (showdown.helper.isUndefined(ext.replace)) {
  612. ret.valid = false;
  613. ret.error = baseMsg + '"regex" extensions must implement a replace string or function';
  614. return ret;
  615. }
  616. }
  617. }
  618. return ret;
  619. }
  620. /**
  621. * Validate extension
  622. * @param {object} ext
  623. * @returns {boolean}
  624. */
  625. showdown.validateExtension = function (ext) {
  626. 'use strict';
  627. var validateExtension = validate(ext, null);
  628. if (!validateExtension.valid) {
  629. console.warn(validateExtension.error);
  630. return false;
  631. }
  632. return true;
  633. };
  634. /**
  635. * showdownjs helper functions
  636. */
  637. if (!showdown.hasOwnProperty('helper')) {
  638. showdown.helper = {};
  639. }
  640. if (typeof this.document === 'undefined' && typeof this.window === 'undefined') {
  641. var jsdom = require('jsdom');
  642. this.window = new jsdom.JSDOM('', {}).window; // jshint ignore:line
  643. }
  644. showdown.helper.document = this.window.document;
  645. /**
  646. * Check if var is string
  647. * @static
  648. * @param {string} a
  649. * @returns {boolean}
  650. */
  651. showdown.helper.isString = function (a) {
  652. 'use strict';
  653. return (typeof a === 'string' || a instanceof String);
  654. };
  655. /**
  656. * Check if var is a function
  657. * @static
  658. * @param {*} a
  659. * @returns {boolean}
  660. */
  661. showdown.helper.isFunction = function (a) {
  662. 'use strict';
  663. var getType = {};
  664. return a && getType.toString.call(a) === '[object Function]';
  665. };
  666. /**
  667. * isArray helper function
  668. * @static
  669. * @param {*} a
  670. * @returns {boolean}
  671. */
  672. showdown.helper.isArray = function (a) {
  673. 'use strict';
  674. return Array.isArray(a);
  675. };
  676. /**
  677. * Check if value is undefined
  678. * @static
  679. * @param {*} value The value to check.
  680. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  681. */
  682. showdown.helper.isUndefined = function (value) {
  683. 'use strict';
  684. return typeof value === 'undefined';
  685. };
  686. /**
  687. * ForEach helper function
  688. * Iterates over Arrays and Objects (own properties only)
  689. * @static
  690. * @param {*} obj
  691. * @param {function} callback Accepts 3 params: 1. value, 2. key, 3. the original array/object
  692. */
  693. showdown.helper.forEach = function (obj, callback) {
  694. 'use strict';
  695. // check if obj is defined
  696. if (showdown.helper.isUndefined(obj)) {
  697. throw new Error('obj param is required');
  698. }
  699. if (showdown.helper.isUndefined(callback)) {
  700. throw new Error('callback param is required');
  701. }
  702. if (!showdown.helper.isFunction(callback)) {
  703. throw new Error('callback param must be a function/closure');
  704. }
  705. if (typeof obj.forEach === 'function') {
  706. obj.forEach(callback);
  707. } else if (showdown.helper.isArray(obj)) {
  708. for (var i = 0; i < obj.length; i++) {
  709. callback(obj[i], i, obj);
  710. }
  711. } else if (typeof (obj) === 'object') {
  712. for (var prop in obj) {
  713. if (obj.hasOwnProperty(prop)) {
  714. callback(obj[prop], prop, obj);
  715. }
  716. }
  717. } else {
  718. throw new Error('obj does not seem to be an array or an iterable object');
  719. }
  720. };
  721. /**
  722. * Standardidize extension name
  723. * @static
  724. * @param {string} s extension name
  725. * @returns {string}
  726. */
  727. showdown.helper.stdExtName = function (s) {
  728. 'use strict';
  729. return s.replace(/[_?*+\/\\.^-]/g, '').replace(/\s/g, '').toLowerCase();
  730. };
  731. function escapeCharactersCallback (wholeMatch, m1) {
  732. 'use strict';
  733. var charCodeToEscape = m1.charCodeAt(0);
  734. return '¨E' + charCodeToEscape + 'E';
  735. }
  736. /**
  737. * Callback used to escape characters when passing through String.replace
  738. * @static
  739. * @param {string} wholeMatch
  740. * @param {string} m1
  741. * @returns {string}
  742. */
  743. showdown.helper.escapeCharactersCallback = escapeCharactersCallback;
  744. /**
  745. * Escape characters in a string
  746. * @static
  747. * @param {string} text
  748. * @param {string} charsToEscape
  749. * @param {boolean} afterBackslash
  750. * @returns {XML|string|void|*}
  751. */
  752. showdown.helper.escapeCharacters = function (text, charsToEscape, afterBackslash) {
  753. 'use strict';
  754. // First we have to escape the escape characters so that
  755. // we can build a character class out of them
  756. var regexString = '([' + charsToEscape.replace(/([\[\]\\])/g, '\\$1') + '])';
  757. if (afterBackslash) {
  758. regexString = '\\\\' + regexString;
  759. }
  760. var regex = new RegExp(regexString, 'g');
  761. text = text.replace(regex, escapeCharactersCallback);
  762. return text;
  763. };
  764. var rgxFindMatchPos = function (str, left, right, flags) {
  765. 'use strict';
  766. var f = flags || '',
  767. g = f.indexOf('g') > -1,
  768. x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
  769. l = new RegExp(left, f.replace(/g/g, '')),
  770. pos = [],
  771. t, s, m, start, end;
  772. do {
  773. t = 0;
  774. while ((m = x.exec(str))) {
  775. if (l.test(m[0])) {
  776. if (!(t++)) {
  777. s = x.lastIndex;
  778. start = s - m[0].length;
  779. }
  780. } else if (t) {
  781. if (!--t) {
  782. end = m.index + m[0].length;
  783. var obj = {
  784. left: {start: start, end: s},
  785. match: {start: s, end: m.index},
  786. right: {start: m.index, end: end},
  787. wholeMatch: {start: start, end: end}
  788. };
  789. pos.push(obj);
  790. if (!g) {
  791. return pos;
  792. }
  793. }
  794. }
  795. }
  796. } while (t && (x.lastIndex = s));
  797. return pos;
  798. };
  799. /**
  800. * matchRecursiveRegExp
  801. *
  802. * (c) 2007 Steven Levithan <stevenlevithan.com>
  803. * MIT License
  804. *
  805. * Accepts a string to search, a left and right format delimiter
  806. * as regex patterns, and optional regex flags. Returns an array
  807. * of matches, allowing nested instances of left/right delimiters.
  808. * Use the "g" flag to return all matches, otherwise only the
  809. * first is returned. Be careful to ensure that the left and
  810. * right format delimiters produce mutually exclusive matches.
  811. * Backreferences are not supported within the right delimiter
  812. * due to how it is internally combined with the left delimiter.
  813. * When matching strings whose format delimiters are unbalanced
  814. * to the left or right, the output is intentionally as a
  815. * conventional regex library with recursion support would
  816. * produce, e.g. "<<x>" and "<x>>" both produce ["x"] when using
  817. * "<" and ">" as the delimiters (both strings contain a single,
  818. * balanced instance of "<x>").
  819. *
  820. * examples:
  821. * matchRecursiveRegExp("test", "\\(", "\\)")
  822. * returns: []
  823. * matchRecursiveRegExp("<t<<e>><s>>t<>", "<", ">", "g")
  824. * returns: ["t<<e>><s>", ""]
  825. * matchRecursiveRegExp("<div id=\"x\">test</div>", "<div\\b[^>]*>", "</div>", "gi")
  826. * returns: ["test"]
  827. */
  828. showdown.helper.matchRecursiveRegExp = function (str, left, right, flags) {
  829. 'use strict';
  830. var matchPos = rgxFindMatchPos (str, left, right, flags),
  831. results = [];
  832. for (var i = 0; i < matchPos.length; ++i) {
  833. results.push([
  834. str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
  835. str.slice(matchPos[i].match.start, matchPos[i].match.end),
  836. str.slice(matchPos[i].left.start, matchPos[i].left.end),
  837. str.slice(matchPos[i].right.start, matchPos[i].right.end)
  838. ]);
  839. }
  840. return results;
  841. };
  842. /**
  843. *
  844. * @param {string} str
  845. * @param {string|function} replacement
  846. * @param {string} left
  847. * @param {string} right
  848. * @param {string} flags
  849. * @returns {string}
  850. */
  851. showdown.helper.replaceRecursiveRegExp = function (str, replacement, left, right, flags) {
  852. 'use strict';
  853. if (!showdown.helper.isFunction(replacement)) {
  854. var repStr = replacement;
  855. replacement = function () {
  856. return repStr;
  857. };
  858. }
  859. var matchPos = rgxFindMatchPos(str, left, right, flags),
  860. finalStr = str,
  861. lng = matchPos.length;
  862. if (lng > 0) {
  863. var bits = [];
  864. if (matchPos[0].wholeMatch.start !== 0) {
  865. bits.push(str.slice(0, matchPos[0].wholeMatch.start));
  866. }
  867. for (var i = 0; i < lng; ++i) {
  868. bits.push(
  869. replacement(
  870. str.slice(matchPos[i].wholeMatch.start, matchPos[i].wholeMatch.end),
  871. str.slice(matchPos[i].match.start, matchPos[i].match.end),
  872. str.slice(matchPos[i].left.start, matchPos[i].left.end),
  873. str.slice(matchPos[i].right.start, matchPos[i].right.end)
  874. )
  875. );
  876. if (i < lng - 1) {
  877. bits.push(str.slice(matchPos[i].wholeMatch.end, matchPos[i + 1].wholeMatch.start));
  878. }
  879. }
  880. if (matchPos[lng - 1].wholeMatch.end < str.length) {
  881. bits.push(str.slice(matchPos[lng - 1].wholeMatch.end));
  882. }
  883. finalStr = bits.join('');
  884. }
  885. return finalStr;
  886. };
  887. /**
  888. * Returns the index within the passed String object of the first occurrence of the specified regex,
  889. * starting the search at fromIndex. Returns -1 if the value is not found.
  890. *
  891. * @param {string} str string to search
  892. * @param {RegExp} regex Regular expression to search
  893. * @param {int} [fromIndex = 0] Index to start the search
  894. * @returns {Number}
  895. * @throws InvalidArgumentError
  896. */
  897. showdown.helper.regexIndexOf = function (str, regex, fromIndex) {
  898. 'use strict';
  899. if (!showdown.helper.isString(str)) {
  900. throw 'InvalidArgumentError: first parameter of showdown.helper.regexIndexOf function must be a string';
  901. }
  902. if (regex instanceof RegExp === false) {
  903. throw 'InvalidArgumentError: second parameter of showdown.helper.regexIndexOf function must be an instance of RegExp';
  904. }
  905. var indexOf = str.substring(fromIndex || 0).search(regex);
  906. return (indexOf >= 0) ? (indexOf + (fromIndex || 0)) : indexOf;
  907. };
  908. /**
  909. * Splits the passed string object at the defined index, and returns an array composed of the two substrings
  910. * @param {string} str string to split
  911. * @param {int} index index to split string at
  912. * @returns {[string,string]}
  913. * @throws InvalidArgumentError
  914. */
  915. showdown.helper.splitAtIndex = function (str, index) {
  916. 'use strict';
  917. if (!showdown.helper.isString(str)) {
  918. throw 'InvalidArgumentError: first parameter of showdown.helper.regexIndexOf function must be a string';
  919. }
  920. return [str.substring(0, index), str.substring(index)];
  921. };
  922. /**
  923. * Obfuscate an e-mail address through the use of Character Entities,
  924. * transforming ASCII characters into their equivalent decimal or hex entities.
  925. *
  926. * Since it has a random component, subsequent calls to this function produce different results
  927. *
  928. * @param {string} mail
  929. * @returns {string}
  930. */
  931. showdown.helper.encodeEmailAddress = function (mail) {
  932. 'use strict';
  933. var encode = [
  934. function (ch) {
  935. return '&#' + ch.charCodeAt(0) + ';';
  936. },
  937. function (ch) {
  938. return '&#x' + ch.charCodeAt(0).toString(16) + ';';
  939. },
  940. function (ch) {
  941. return ch;
  942. }
  943. ];
  944. mail = mail.replace(/./g, function (ch) {
  945. if (ch === '@') {
  946. // this *must* be encoded. I insist.
  947. ch = encode[Math.floor(Math.random() * 2)](ch);
  948. } else {
  949. var r = Math.random();
  950. // roughly 10% raw, 45% hex, 45% dec
  951. ch = (
  952. r > 0.9 ? encode[2](ch) : r > 0.45 ? encode[1](ch) : encode[0](ch)
  953. );
  954. }
  955. return ch;
  956. });
  957. return mail;
  958. };
  959. /**
  960. *
  961. * @param str
  962. * @param targetLength
  963. * @param padString
  964. * @returns {string}
  965. */
  966. showdown.helper.padEnd = function padEnd (str, targetLength, padString) {
  967. 'use strict';
  968. /*jshint bitwise: false*/
  969. // eslint-disable-next-line space-infix-ops
  970. targetLength = targetLength>>0; //floor if number or convert non-number to 0;
  971. /*jshint bitwise: true*/
  972. padString = String(padString || ' ');
  973. if (str.length > targetLength) {
  974. return String(str);
  975. } else {
  976. targetLength = targetLength - str.length;
  977. if (targetLength > padString.length) {
  978. padString += padString.repeat(targetLength / padString.length); //append to original to ensure we are longer than needed
  979. }
  980. return String(str) + padString.slice(0,targetLength);
  981. }
  982. };
  983. /**
  984. * Unescape HTML entities
  985. * @param txt
  986. * @returns {string}
  987. */
  988. showdown.helper.unescapeHTMLEntities = function (txt) {
  989. 'use strict';
  990. return txt
  991. .replace(/&quot;/g, '"')
  992. .replace(/&lt;/g, '<')
  993. .replace(/&gt;/g, '>')
  994. .replace(/&amp;/g, '&');
  995. };
  996. showdown.helper._hashHTMLSpan = function (html, globals) {
  997. return '¨C' + (globals.gHtmlSpans.push(html) - 1) + 'C';
  998. };
  999. /**
  1000. * Showdown's Event Object
  1001. * @param {string} name Name of the event
  1002. * @param {string} text Text
  1003. * @param {{}} params optional. params of the event
  1004. * @constructor
  1005. */
  1006. showdown.helper.Event = function (name, text, params) {
  1007. 'use strict';
  1008. var regexp = params.regexp || null;
  1009. var matches = params.matches || {};
  1010. var options = params.options || {};
  1011. var converter = params.converter || null;
  1012. var globals = params.globals || {};
  1013. /**
  1014. * Get the name of the event
  1015. * @returns {string}
  1016. */
  1017. this.getName = function () {
  1018. return name;
  1019. };
  1020. this.getEventName = function () {
  1021. return name;
  1022. };
  1023. this._stopExecution = false;
  1024. this.parsedText = params.parsedText || null;
  1025. this.getRegexp = function () {
  1026. return regexp;
  1027. };
  1028. this.getOptions = function () {
  1029. return options;
  1030. };
  1031. this.getConverter = function () {
  1032. return converter;
  1033. };
  1034. this.getGlobals = function () {
  1035. return globals;
  1036. };
  1037. this.getCapturedText = function () {
  1038. return text;
  1039. };
  1040. this.getText = function () {
  1041. return text;
  1042. };
  1043. this.setText = function (newText) {
  1044. text = newText;
  1045. };
  1046. this.getMatches = function () {
  1047. return matches;
  1048. };
  1049. this.setMatches = function (newMatches) {
  1050. matches = newMatches;
  1051. };
  1052. this.preventDefault = function (bool) {
  1053. this._stopExecution = !bool;
  1054. };
  1055. };
  1056. /**
  1057. * POLYFILLS
  1058. */
  1059. // use this instead of builtin is undefined for IE8 compatibility
  1060. if (typeof(console) === 'undefined') {
  1061. console = {
  1062. warn: function (msg) {
  1063. 'use strict';
  1064. alert(msg);
  1065. },
  1066. log: function (msg) {
  1067. 'use strict';
  1068. alert(msg);
  1069. },
  1070. error: function (msg) {
  1071. 'use strict';
  1072. throw msg;
  1073. }
  1074. };
  1075. }
  1076. /**
  1077. * Common regexes.
  1078. * We declare some common regexes to improve performance
  1079. */
  1080. showdown.helper.regexes = {
  1081. asteriskDashTildeAndColon: /([*_:~])/g,
  1082. asteriskDashAndTilde: /([*_~])/g
  1083. };
  1084. /**
  1085. * EMOJIS LIST
  1086. */
  1087. showdown.helper.emojis = {
  1088. '+1':'\ud83d\udc4d',
  1089. '-1':'\ud83d\udc4e',
  1090. '100':'\ud83d\udcaf',
  1091. '1234':'\ud83d\udd22',
  1092. '1st_place_medal':'\ud83e\udd47',
  1093. '2nd_place_medal':'\ud83e\udd48',
  1094. '3rd_place_medal':'\ud83e\udd49',
  1095. '8ball':'\ud83c\udfb1',
  1096. 'a':'\ud83c\udd70\ufe0f',
  1097. 'ab':'\ud83c\udd8e',
  1098. 'abc':'\ud83d\udd24',
  1099. 'abcd':'\ud83d\udd21',
  1100. 'accept':'\ud83c\ude51',
  1101. 'aerial_tramway':'\ud83d\udea1',
  1102. 'airplane':'\u2708\ufe0f',
  1103. 'alarm_clock':'\u23f0',
  1104. 'alembic':'\u2697\ufe0f',
  1105. 'alien':'\ud83d\udc7d',
  1106. 'ambulance':'\ud83d\ude91',
  1107. 'amphora':'\ud83c\udffa',
  1108. 'anchor':'\u2693\ufe0f',
  1109. 'angel':'\ud83d\udc7c',
  1110. 'anger':'\ud83d\udca2',
  1111. 'angry':'\ud83d\ude20',
  1112. 'anguished':'\ud83d\ude27',
  1113. 'ant':'\ud83d\udc1c',
  1114. 'apple':'\ud83c\udf4e',
  1115. 'aquarius':'\u2652\ufe0f',
  1116. 'aries':'\u2648\ufe0f',
  1117. 'arrow_backward':'\u25c0\ufe0f',
  1118. 'arrow_double_down':'\u23ec',
  1119. 'arrow_double_up':'\u23eb',
  1120. 'arrow_down':'\u2b07\ufe0f',
  1121. 'arrow_down_small':'\ud83d\udd3d',
  1122. 'arrow_forward':'\u25b6\ufe0f',
  1123. 'arrow_heading_down':'\u2935\ufe0f',
  1124. 'arrow_heading_up':'\u2934\ufe0f',
  1125. 'arrow_left':'\u2b05\ufe0f',
  1126. 'arrow_lower_left':'\u2199\ufe0f',
  1127. 'arrow_lower_right':'\u2198\ufe0f',
  1128. 'arrow_right':'\u27a1\ufe0f',
  1129. 'arrow_right_hook':'\u21aa\ufe0f',
  1130. 'arrow_up':'\u2b06\ufe0f',
  1131. 'arrow_up_down':'\u2195\ufe0f',
  1132. 'arrow_up_small':'\ud83d\udd3c',
  1133. 'arrow_upper_left':'\u2196\ufe0f',
  1134. 'arrow_upper_right':'\u2197\ufe0f',
  1135. 'arrows_clockwise':'\ud83d\udd03',
  1136. 'arrows_counterclockwise':'\ud83d\udd04',
  1137. 'art':'\ud83c\udfa8',
  1138. 'articulated_lorry':'\ud83d\ude9b',
  1139. 'artificial_satellite':'\ud83d\udef0',
  1140. 'astonished':'\ud83d\ude32',
  1141. 'athletic_shoe':'\ud83d\udc5f',
  1142. 'atm':'\ud83c\udfe7',
  1143. 'atom_symbol':'\u269b\ufe0f',
  1144. 'avocado':'\ud83e\udd51',
  1145. 'b':'\ud83c\udd71\ufe0f',
  1146. 'baby':'\ud83d\udc76',
  1147. 'baby_bottle':'\ud83c\udf7c',
  1148. 'baby_chick':'\ud83d\udc24',
  1149. 'baby_symbol':'\ud83d\udebc',
  1150. 'back':'\ud83d\udd19',
  1151. 'bacon':'\ud83e\udd53',
  1152. 'badminton':'\ud83c\udff8',
  1153. 'baggage_claim':'\ud83d\udec4',
  1154. 'baguette_bread':'\ud83e\udd56',
  1155. 'balance_scale':'\u2696\ufe0f',
  1156. 'balloon':'\ud83c\udf88',
  1157. 'ballot_box':'\ud83d\uddf3',
  1158. 'ballot_box_with_check':'\u2611\ufe0f',
  1159. 'bamboo':'\ud83c\udf8d',
  1160. 'banana':'\ud83c\udf4c',
  1161. 'bangbang':'\u203c\ufe0f',
  1162. 'bank':'\ud83c\udfe6',
  1163. 'bar_chart':'\ud83d\udcca',
  1164. 'barber':'\ud83d\udc88',
  1165. 'baseball':'\u26be\ufe0f',
  1166. 'basketball':'\ud83c\udfc0',
  1167. 'basketball_man':'\u26f9\ufe0f',
  1168. 'basketball_woman':'\u26f9\ufe0f&zwj;\u2640\ufe0f',
  1169. 'bat':'\ud83e\udd87',
  1170. 'bath':'\ud83d\udec0',
  1171. 'bathtub':'\ud83d\udec1',
  1172. 'battery':'\ud83d\udd0b',
  1173. 'beach_umbrella':'\ud83c\udfd6',
  1174. 'bear':'\ud83d\udc3b',
  1175. 'bed':'\ud83d\udecf',
  1176. 'bee':'\ud83d\udc1d',
  1177. 'beer':'\ud83c\udf7a',
  1178. 'beers':'\ud83c\udf7b',
  1179. 'beetle':'\ud83d\udc1e',
  1180. 'beginner':'\ud83d\udd30',
  1181. 'bell':'\ud83d\udd14',
  1182. 'bellhop_bell':'\ud83d\udece',
  1183. 'bento':'\ud83c\udf71',
  1184. 'biking_man':'\ud83d\udeb4',
  1185. 'bike':'\ud83d\udeb2',
  1186. 'biking_woman':'\ud83d\udeb4&zwj;\u2640\ufe0f',
  1187. 'bikini':'\ud83d\udc59',
  1188. 'biohazard':'\u2623\ufe0f',
  1189. 'bird':'\ud83d\udc26',
  1190. 'birthday':'\ud83c\udf82',
  1191. 'black_circle':'\u26ab\ufe0f',
  1192. 'black_flag':'\ud83c\udff4',
  1193. 'black_heart':'\ud83d\udda4',
  1194. 'black_joker':'\ud83c\udccf',
  1195. 'black_large_square':'\u2b1b\ufe0f',
  1196. 'black_medium_small_square':'\u25fe\ufe0f',
  1197. 'black_medium_square':'\u25fc\ufe0f',
  1198. 'black_nib':'\u2712\ufe0f',
  1199. 'black_small_square':'\u25aa\ufe0f',
  1200. 'black_square_button':'\ud83d\udd32',
  1201. 'blonde_man':'\ud83d\udc71',
  1202. 'blonde_woman':'\ud83d\udc71&zwj;\u2640\ufe0f',
  1203. 'blossom':'\ud83c\udf3c',
  1204. 'blowfish':'\ud83d\udc21',
  1205. 'blue_book':'\ud83d\udcd8',
  1206. 'blue_car':'\ud83d\ude99',
  1207. 'blue_heart':'\ud83d\udc99',
  1208. 'blush':'\ud83d\ude0a',
  1209. 'boar':'\ud83d\udc17',
  1210. 'boat':'\u26f5\ufe0f',
  1211. 'bomb':'\ud83d\udca3',
  1212. 'book':'\ud83d\udcd6',
  1213. 'bookmark':'\ud83d\udd16',
  1214. 'bookmark_tabs':'\ud83d\udcd1',
  1215. 'books':'\ud83d\udcda',
  1216. 'boom':'\ud83d\udca5',
  1217. 'boot':'\ud83d\udc62',
  1218. 'bouquet':'\ud83d\udc90',
  1219. 'bowing_man':'\ud83d\ude47',
  1220. 'bow_and_arrow':'\ud83c\udff9',
  1221. 'bowing_woman':'\ud83d\ude47&zwj;\u2640\ufe0f',
  1222. 'bowling':'\ud83c\udfb3',
  1223. 'boxing_glove':'\ud83e\udd4a',
  1224. 'boy':'\ud83d\udc66',
  1225. 'bread':'\ud83c\udf5e',
  1226. 'bride_with_veil':'\ud83d\udc70',
  1227. 'bridge_at_night':'\ud83c\udf09',
  1228. 'briefcase':'\ud83d\udcbc',
  1229. 'broken_heart':'\ud83d\udc94',
  1230. 'bug':'\ud83d\udc1b',
  1231. 'building_construction':'\ud83c\udfd7',
  1232. 'bulb':'\ud83d\udca1',
  1233. 'bullettrain_front':'\ud83d\ude85',
  1234. 'bullettrain_side':'\ud83d\ude84',
  1235. 'burrito':'\ud83c\udf2f',
  1236. 'bus':'\ud83d\ude8c',
  1237. 'business_suit_levitating':'\ud83d\udd74',
  1238. 'busstop':'\ud83d\ude8f',
  1239. 'bust_in_silhouette':'\ud83d\udc64',
  1240. 'busts_in_silhouette':'\ud83d\udc65',
  1241. 'butterfly':'\ud83e\udd8b',
  1242. 'cactus':'\ud83c\udf35',
  1243. 'cake':'\ud83c\udf70',
  1244. 'calendar':'\ud83d\udcc6',
  1245. 'call_me_hand':'\ud83e\udd19',
  1246. 'calling':'\ud83d\udcf2',
  1247. 'camel':'\ud83d\udc2b',
  1248. 'camera':'\ud83d\udcf7',
  1249. 'camera_flash':'\ud83d\udcf8',
  1250. 'camping':'\ud83c\udfd5',
  1251. 'cancer':'\u264b\ufe0f',
  1252. 'candle':'\ud83d\udd6f',
  1253. 'candy':'\ud83c\udf6c',
  1254. 'canoe':'\ud83d\udef6',
  1255. 'capital_abcd':'\ud83d\udd20',
  1256. 'capricorn':'\u2651\ufe0f',
  1257. 'car':'\ud83d\ude97',
  1258. 'card_file_box':'\ud83d\uddc3',
  1259. 'card_index':'\ud83d\udcc7',
  1260. 'card_index_dividers':'\ud83d\uddc2',
  1261. 'carousel_horse':'\ud83c\udfa0',
  1262. 'carrot':'\ud83e\udd55',
  1263. 'cat':'\ud83d\udc31',
  1264. 'cat2':'\ud83d\udc08',
  1265. 'cd':'\ud83d\udcbf',
  1266. 'chains':'\u26d3',
  1267. 'champagne':'\ud83c\udf7e',
  1268. 'chart':'\ud83d\udcb9',
  1269. 'chart_with_downwards_trend':'\ud83d\udcc9',
  1270. 'chart_with_upwards_trend':'\ud83d\udcc8',
  1271. 'checkered_flag':'\ud83c\udfc1',
  1272. 'cheese':'\ud83e\uddc0',
  1273. 'cherries':'\ud83c\udf52',
  1274. 'cherry_blossom':'\ud83c\udf38',
  1275. 'chestnut':'\ud83c\udf30',
  1276. 'chicken':'\ud83d\udc14',
  1277. 'children_crossing':'\ud83d\udeb8',
  1278. 'chipmunk':'\ud83d\udc3f',
  1279. 'chocolate_bar':'\ud83c\udf6b',
  1280. 'christmas_tree':'\ud83c\udf84',
  1281. 'church':'\u26ea\ufe0f',
  1282. 'cinema':'\ud83c\udfa6',
  1283. 'circus_tent':'\ud83c\udfaa',
  1284. 'city_sunrise':'\ud83c\udf07',
  1285. 'city_sunset':'\ud83c\udf06',
  1286. 'cityscape':'\ud83c\udfd9',
  1287. 'cl':'\ud83c\udd91',
  1288. 'clamp':'\ud83d\udddc',
  1289. 'clap':'\ud83d\udc4f',
  1290. 'clapper':'\ud83c\udfac',
  1291. 'classical_building':'\ud83c\udfdb',
  1292. 'clinking_glasses':'\ud83e\udd42',
  1293. 'clipboard':'\ud83d\udccb',
  1294. 'clock1':'\ud83d\udd50',
  1295. 'clock10':'\ud83d\udd59',
  1296. 'clock1030':'\ud83d\udd65',
  1297. 'clock11':'\ud83d\udd5a',
  1298. 'clock1130':'\ud83d\udd66',
  1299. 'clock12':'\ud83d\udd5b',
  1300. 'clock1230':'\ud83d\udd67',
  1301. 'clock130':'\ud83d\udd5c',
  1302. 'clock2':'\ud83d\udd51',
  1303. 'clock230':'\ud83d\udd5d',
  1304. 'clock3':'\ud83d\udd52',
  1305. 'clock330':'\ud83d\udd5e',
  1306. 'clock4':'\ud83d\udd53',
  1307. 'clock430':'\ud83d\udd5f',
  1308. 'clock5':'\ud83d\udd54',
  1309. 'clock530':'\ud83d\udd60',
  1310. 'clock6':'\ud83d\udd55',
  1311. 'clock630':'\ud83d\udd61',
  1312. 'clock7':'\ud83d\udd56',
  1313. 'clock730':'\ud83d\udd62',
  1314. 'clock8':'\ud83d\udd57',
  1315. 'clock830':'\ud83d\udd63',
  1316. 'clock9':'\ud83d\udd58',
  1317. 'clock930':'\ud83d\udd64',
  1318. 'closed_book':'\ud83d\udcd5',
  1319. 'closed_lock_with_key':'\ud83d\udd10',
  1320. 'closed_umbrella':'\ud83c\udf02',
  1321. 'cloud':'\u2601\ufe0f',
  1322. 'cloud_with_lightning':'\ud83c\udf29',
  1323. 'cloud_with_lightning_and_rain':'\u26c8',
  1324. 'cloud_with_rain':'\ud83c\udf27',
  1325. 'cloud_with_snow':'\ud83c\udf28',
  1326. 'clown_face':'\ud83e\udd21',
  1327. 'clubs':'\u2663\ufe0f',
  1328. 'cocktail':'\ud83c\udf78',
  1329. 'coffee':'\u2615\ufe0f',
  1330. 'coffin':'\u26b0\ufe0f',
  1331. 'cold_sweat':'\ud83d\ude30',
  1332. 'comet':'\u2604\ufe0f',
  1333. 'computer':'\ud83d\udcbb',
  1334. 'computer_mouse':'\ud83d\uddb1',
  1335. 'confetti_ball':'\ud83c\udf8a',
  1336. 'confounded':'\ud83d\ude16',
  1337. 'confused':'\ud83d\ude15',
  1338. 'congratulations':'\u3297\ufe0f',
  1339. 'construction':'\ud83d\udea7',
  1340. 'construction_worker_man':'\ud83d\udc77',
  1341. 'construction_worker_woman':'\ud83d\udc77&zwj;\u2640\ufe0f',
  1342. 'control_knobs':'\ud83c\udf9b',
  1343. 'convenience_store':'\ud83c\udfea',
  1344. 'cookie':'\ud83c\udf6a',
  1345. 'cool':'\ud83c\udd92',
  1346. 'policeman':'\ud83d\udc6e',
  1347. 'copyright':'\u00a9\ufe0f',
  1348. 'corn':'\ud83c\udf3d',
  1349. 'couch_and_lamp':'\ud83d\udecb',
  1350. 'couple':'\ud83d\udc6b',
  1351. 'couple_with_heart_woman_man':'\ud83d\udc91',
  1352. 'couple_with_heart_man_man':'\ud83d\udc68&zwj;\u2764\ufe0f&zwj;\ud83d\udc68',
  1353. 'couple_with_heart_woman_woman':'\ud83d\udc69&zwj;\u2764\ufe0f&zwj;\ud83d\udc69',
  1354. 'couplekiss_man_man':'\ud83d\udc68&zwj;\u2764\ufe0f&zwj;\ud83d\udc8b&zwj;\ud83d\udc68',
  1355. 'couplekiss_man_woman':'\ud83d\udc8f',
  1356. 'couplekiss_woman_woman':'\ud83d\udc69&zwj;\u2764\ufe0f&zwj;\ud83d\udc8b&zwj;\ud83d\udc69',
  1357. 'cow':'\ud83d\udc2e',
  1358. 'cow2':'\ud83d\udc04',
  1359. 'cowboy_hat_face':'\ud83e\udd20',
  1360. 'crab':'\ud83e\udd80',
  1361. 'crayon':'\ud83d\udd8d',
  1362. 'credit_card':'\ud83d\udcb3',
  1363. 'crescent_moon':'\ud83c\udf19',
  1364. 'cricket':'\ud83c\udfcf',
  1365. 'crocodile':'\ud83d\udc0a',
  1366. 'croissant':'\ud83e\udd50',
  1367. 'crossed_fingers':'\ud83e\udd1e',
  1368. 'crossed_flags':'\ud83c\udf8c',
  1369. 'crossed_swords':'\u2694\ufe0f',
  1370. 'crown':'\ud83d\udc51',
  1371. 'cry':'\ud83d\ude22',
  1372. 'crying_cat_face':'\ud83d\ude3f',
  1373. 'crystal_ball':'\ud83d\udd2e',
  1374. 'cucumber':'\ud83e\udd52',
  1375. 'cupid':'\ud83d\udc98',
  1376. 'curly_loop':'\u27b0',
  1377. 'currency_exchange':'\ud83d\udcb1',
  1378. 'curry':'\ud83c\udf5b',
  1379. 'custard':'\ud83c\udf6e',
  1380. 'customs':'\ud83d\udec3',
  1381. 'cyclone':'\ud83c\udf00',
  1382. 'dagger':'\ud83d\udde1',
  1383. 'dancer':'\ud83d\udc83',
  1384. 'dancing_women':'\ud83d\udc6f',
  1385. 'dancing_men':'\ud83d\udc6f&zwj;\u2642\ufe0f',
  1386. 'dango':'\ud83c\udf61',
  1387. 'dark_sunglasses':'\ud83d\udd76',
  1388. 'dart':'\ud83c\udfaf',
  1389. 'dash':'\ud83d\udca8',
  1390. 'date':'\ud83d\udcc5',
  1391. 'deciduous_tree':'\ud83c\udf33',
  1392. 'deer':'\ud83e\udd8c',
  1393. 'department_store':'\ud83c\udfec',
  1394. 'derelict_house':'\ud83c\udfda',
  1395. 'desert':'\ud83c\udfdc',
  1396. 'desert_island':'\ud83c\udfdd',
  1397. 'desktop_computer':'\ud83d\udda5',
  1398. 'male_detective':'\ud83d\udd75\ufe0f',
  1399. 'diamond_shape_with_a_dot_inside':'\ud83d\udca0',
  1400. 'diamonds':'\u2666\ufe0f',
  1401. 'disappointed':'\ud83d\ude1e',
  1402. 'disappointed_relieved':'\ud83d\ude25',
  1403. 'dizzy':'\ud83d\udcab',
  1404. 'dizzy_face':'\ud83d\ude35',
  1405. 'do_not_litter':'\ud83d\udeaf',
  1406. 'dog':'\ud83d\udc36',
  1407. 'dog2':'\ud83d\udc15',
  1408. 'dollar':'\ud83d\udcb5',
  1409. 'dolls':'\ud83c\udf8e',
  1410. 'dolphin':'\ud83d\udc2c',
  1411. 'door':'\ud83d\udeaa',
  1412. 'doughnut':'\ud83c\udf69',
  1413. 'dove':'\ud83d\udd4a',
  1414. 'dragon':'\ud83d\udc09',
  1415. 'dragon_face':'\ud83d\udc32',
  1416. 'dress':'\ud83d\udc57',
  1417. 'dromedary_camel':'\ud83d\udc2a',
  1418. 'drooling_face':'\ud83e\udd24',
  1419. 'droplet':'\ud83d\udca7',
  1420. 'drum':'\ud83e\udd41',
  1421. 'duck':'\ud83e\udd86',
  1422. 'dvd':'\ud83d\udcc0',
  1423. 'e-mail':'\ud83d\udce7',
  1424. 'eagle':'\ud83e\udd85',
  1425. 'ear':'\ud83d\udc42',
  1426. 'ear_of_rice':'\ud83c\udf3e',
  1427. 'earth_africa':'\ud83c\udf0d',
  1428. 'earth_americas':'\ud83c\udf0e',
  1429. 'earth_asia':'\ud83c\udf0f',
  1430. 'egg':'\ud83e\udd5a',
  1431. 'eggplant':'\ud83c\udf46',
  1432. 'eight_pointed_black_star':'\u2734\ufe0f',
  1433. 'eight_spoked_asterisk':'\u2733\ufe0f',
  1434. 'electric_plug':'\ud83d\udd0c',
  1435. 'elephant':'\ud83d\udc18',
  1436. 'email':'\u2709\ufe0f',
  1437. 'end':'\ud83d\udd1a',
  1438. 'envelope_with_arrow':'\ud83d\udce9',
  1439. 'euro':'\ud83d\udcb6',
  1440. 'european_castle':'\ud83c\udff0',
  1441. 'european_post_office':'\ud83c\udfe4',
  1442. 'evergreen_tree':'\ud83c\udf32',
  1443. 'exclamation':'\u2757\ufe0f',
  1444. 'expressionless':'\ud83d\ude11',
  1445. 'eye':'\ud83d\udc41',
  1446. 'eye_speech_bubble':'\ud83d\udc41&zwj;\ud83d\udde8',
  1447. 'eyeglasses':'\ud83d\udc53',
  1448. 'eyes':'\ud83d\udc40',
  1449. 'face_with_head_bandage':'\ud83e\udd15',
  1450. 'face_with_thermometer':'\ud83e\udd12',
  1451. 'fist_oncoming':'\ud83d\udc4a',
  1452. 'factory':'\ud83c\udfed',
  1453. 'fallen_leaf':'\ud83c\udf42',
  1454. 'family_man_woman_boy':'\ud83d\udc6a',
  1455. 'family_man_boy':'\ud83d\udc68&zwj;\ud83d\udc66',
  1456. 'family_man_boy_boy':'\ud83d\udc68&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1457. 'family_man_girl':'\ud83d\udc68&zwj;\ud83d\udc67',
  1458. 'family_man_girl_boy':'\ud83d\udc68&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1459. 'family_man_girl_girl':'\ud83d\udc68&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1460. 'family_man_man_boy':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc66',
  1461. 'family_man_man_boy_boy':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1462. 'family_man_man_girl':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc67',
  1463. 'family_man_man_girl_boy':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1464. 'family_man_man_girl_girl':'\ud83d\udc68&zwj;\ud83d\udc68&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1465. 'family_man_woman_boy_boy':'\ud83d\udc68&zwj;\ud83d\udc69&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1466. 'family_man_woman_girl':'\ud83d\udc68&zwj;\ud83d\udc69&zwj;\ud83d\udc67',
  1467. 'family_man_woman_girl_boy':'\ud83d\udc68&zwj;\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1468. 'family_man_woman_girl_girl':'\ud83d\udc68&zwj;\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1469. 'family_woman_boy':'\ud83d\udc69&zwj;\ud83d\udc66',
  1470. 'family_woman_boy_boy':'\ud83d\udc69&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1471. 'family_woman_girl':'\ud83d\udc69&zwj;\ud83d\udc67',
  1472. 'family_woman_girl_boy':'\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1473. 'family_woman_girl_girl':'\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1474. 'family_woman_woman_boy':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc66',
  1475. 'family_woman_woman_boy_boy':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc66&zwj;\ud83d\udc66',
  1476. 'family_woman_woman_girl':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc67',
  1477. 'family_woman_woman_girl_boy':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc66',
  1478. 'family_woman_woman_girl_girl':'\ud83d\udc69&zwj;\ud83d\udc69&zwj;\ud83d\udc67&zwj;\ud83d\udc67',
  1479. 'fast_forward':'\u23e9',
  1480. 'fax':'\ud83d\udce0',
  1481. 'fearful':'\ud83d\ude28',
  1482. 'feet':'\ud83d\udc3e',
  1483. 'female_detective':'\ud83d\udd75\ufe0f&zwj;\u2640\ufe0f',
  1484. 'ferris_wheel':'\ud83c\udfa1',
  1485. 'ferry':'\u26f4',
  1486. 'field_hockey':'\ud83c\udfd1',
  1487. 'file_cabinet':'\ud83d\uddc4',
  1488. 'file_folder':'\ud83d\udcc1',
  1489. 'film_projector':'\ud83d\udcfd',
  1490. 'film_strip':'\ud83c\udf9e',
  1491. 'fire':'\ud83d\udd25',
  1492. 'fire_engine':'\ud83d\ude92',
  1493. 'fireworks':'\ud83c\udf86',
  1494. 'first_quarter_moon':'\ud83c\udf13',
  1495. 'first_quarter_moon_with_face':'\ud83c\udf1b',
  1496. 'fish':'\ud83d\udc1f',
  1497. 'fish_cake':'\ud83c\udf65',
  1498. 'fishing_pole_and_fish':'\ud83c\udfa3',
  1499. 'fist_raised':'\u270a',
  1500. 'fist_left':'\ud83e\udd1b',
  1501. 'fist_right':'\ud83e\udd1c',
  1502. 'flags':'\ud83c\udf8f',
  1503. 'flashlight':'\ud83d\udd26',
  1504. 'fleur_de_lis':'\u269c\ufe0f',
  1505. 'flight_arrival':'\ud83d\udeec',
  1506. 'flight_departure':'\ud83d\udeeb',
  1507. 'floppy_disk':'\ud83d\udcbe',
  1508. 'flower_playing_cards':'\ud83c\udfb4',
  1509. 'flushed':'\ud83d\ude33',
  1510. 'fog':'\ud83c\udf2b',
  1511. 'foggy':'\ud83c\udf01',
  1512. 'football':'\ud83c\udfc8',
  1513. 'footprints':'\ud83d\udc63',
  1514. 'fork_and_knife':'\ud83c\udf74',
  1515. 'fountain':'\u26f2\ufe0f',
  1516. 'fountain_pen':'\ud83d\udd8b',
  1517. 'four_leaf_clover':'\ud83c\udf40',
  1518. 'fox_face':'\ud83e\udd8a',
  1519. 'framed_picture':'\ud83d\uddbc',
  1520. 'free':'\ud83c\udd93',
  1521. 'fried_egg':'\ud83c\udf73',
  1522. 'fried_shrimp':'\ud83c\udf64',
  1523. 'fries':'\ud83c\udf5f',
  1524. 'frog':'\ud83d\udc38',
  1525. 'frowning':'\ud83d\ude26',
  1526. 'frowning_face':'\u2639\ufe0f',
  1527. 'frowning_man':'\ud83d\ude4d&zwj;\u2642\ufe0f',
  1528. 'frowning_woman':'\ud83d\ude4d',
  1529. 'middle_finger':'\ud83d\udd95',
  1530. 'fuelpump':'\u26fd\ufe0f',
  1531. 'full_moon':'\ud83c\udf15',
  1532. 'full_moon_with_face':'\ud83c\udf1d',
  1533. 'funeral_urn':'\u26b1\ufe0f',
  1534. 'game_die':'\ud83c\udfb2',
  1535. 'gear':'\u2699\ufe0f',
  1536. 'gem':'\ud83d\udc8e',
  1537. 'gemini':'\u264a\ufe0f',
  1538. 'ghost':'\ud83d\udc7b',
  1539. 'gift':'\ud83c\udf81',
  1540. 'gift_heart':'\ud83d\udc9d',
  1541. 'girl':'\ud83d\udc67',
  1542. 'globe_with_meridians':'\ud83c\udf10',
  1543. 'goal_net':'\ud83e\udd45',
  1544. 'goat':'\ud83d\udc10',
  1545. 'golf':'\u26f3\ufe0f',
  1546. 'golfing_man':'\ud83c\udfcc\ufe0f',
  1547. 'golfing_woman':'\ud83c\udfcc\ufe0f&zwj;\u2640\ufe0f',
  1548. 'gorilla':'\ud83e\udd8d',
  1549. 'grapes':'\ud83c\udf47',
  1550. 'green_apple':'\ud83c\udf4f',
  1551. 'green_book':'\ud83d\udcd7',
  1552. 'green_heart':'\ud83d\udc9a',
  1553. 'green_salad':'\ud83e\udd57',
  1554. 'grey_exclamation':'\u2755',
  1555. 'grey_question':'\u2754',
  1556. 'grimacing':'\ud83d\ude2c',
  1557. 'grin':'\ud83d\ude01',
  1558. 'grinning':'\ud83d\ude00',
  1559. 'guardsman':'\ud83d\udc82',
  1560. 'guardswoman':'\ud83d\udc82&zwj;\u2640\ufe0f',
  1561. 'guitar':'\ud83c\udfb8',
  1562. 'gun':'\ud83d\udd2b',
  1563. 'haircut_woman':'\ud83d\udc87',
  1564. 'haircut_man':'\ud83d\udc87&zwj;\u2642\ufe0f',
  1565. 'hamburger':'\ud83c\udf54',
  1566. 'hammer':'\ud83d\udd28',
  1567. 'hammer_and_pick':'\u2692',
  1568. 'hammer_and_wrench':'\ud83d\udee0',
  1569. 'hamster':'\ud83d\udc39',
  1570. 'hand':'\u270b',
  1571. 'handbag':'\ud83d\udc5c',
  1572. 'handshake':'\ud83e\udd1d',
  1573. 'hankey':'\ud83d\udca9',
  1574. 'hatched_chick':'\ud83d\udc25',
  1575. 'hatching_chick':'\ud83d\udc23',
  1576. 'headphones':'\ud83c\udfa7',
  1577. 'hear_no_evil':'\ud83d\ude49',
  1578. 'heart':'\u2764\ufe0f',
  1579. 'heart_decoration':'\ud83d\udc9f',
  1580. 'heart_eyes':'\ud83d\ude0d',
  1581. 'heart_eyes_cat':'\ud83d\ude3b',
  1582. 'heartbeat':'\ud83d\udc93',
  1583. 'heartpulse':'\ud83d\udc97',
  1584. 'hearts':'\u2665\ufe0f',
  1585. 'heavy_check_mark':'\u2714\ufe0f',
  1586. 'heavy_division_sign':'\u2797',
  1587. 'heavy_dollar_sign':'\ud83d\udcb2',
  1588. 'heavy_heart_exclamation':'\u2763\ufe0f',
  1589. 'heavy_minus_sign':'\u2796',
  1590. 'heavy_multiplication_x':'\u2716\ufe0f',
  1591. 'heavy_plus_sign':'\u2795',
  1592. 'helicopter':'\ud83d\ude81',
  1593. 'herb':'\ud83c\udf3f',
  1594. 'hibiscus':'\ud83c\udf3a',
  1595. 'high_brightness':'\ud83d\udd06',
  1596. 'high_heel':'\ud83d\udc60',
  1597. 'hocho':'\ud83d\udd2a',
  1598. 'hole':'\ud83d\udd73',
  1599. 'honey_pot':'\ud83c\udf6f',
  1600. 'horse':'\ud83d\udc34',
  1601. 'horse_racing':'\ud83c\udfc7',
  1602. 'hospital':'\ud83c\udfe5',
  1603. 'hot_pepper':'\ud83c\udf36',
  1604. 'hotdog':'\ud83c\udf2d',
  1605. 'hotel':'\ud83c\udfe8',
  1606. 'hotsprings':'\u2668\ufe0f',
  1607. 'hourglass':'\u231b\ufe0f',
  1608. 'hourglass_flowing_sand':'\u23f3',
  1609. 'house':'\ud83c\udfe0',
  1610. 'house_with_garden':'\ud83c\udfe1',
  1611. 'houses':'\ud83c\udfd8',
  1612. 'hugs':'\ud83e\udd17',
  1613. 'hushed':'\ud83d\ude2f',
  1614. 'ice_cream':'\ud83c\udf68',
  1615. 'ice_hockey':'\ud83c\udfd2',
  1616. 'ice_skate':'\u26f8',
  1617. 'icecream':'\ud83c\udf66',
  1618. 'id':'\ud83c\udd94',
  1619. 'ideograph_advantage':'\ud83c\ude50',
  1620. 'imp':'\ud83d\udc7f',
  1621. 'inbox_tray':'\ud83d\udce5',
  1622. 'incoming_envelope':'\ud83d\udce8',
  1623. 'tipping_hand_woman':'\ud83d\udc81',
  1624. 'information_source':'\u2139\ufe0f',
  1625. 'innocent':'\ud83d\ude07',
  1626. 'interrobang':'\u2049\ufe0f',
  1627. 'iphone':'\ud83d\udcf1',
  1628. 'izakaya_lantern':'\ud83c\udfee',
  1629. 'jack_o_lantern':'\ud83c\udf83',
  1630. 'japan':'\ud83d\uddfe',
  1631. 'japanese_castle':'\ud83c\udfef',
  1632. 'japanese_goblin':'\ud83d\udc7a',
  1633. 'japanese_ogre':'\ud83d\udc79',
  1634. 'jeans':'\ud83d\udc56',
  1635. 'joy':'\ud83d\ude02',
  1636. 'joy_cat':'\ud83d\ude39',
  1637. 'joystick':'\ud83d\udd79',
  1638. 'kaaba':'\ud83d\udd4b',
  1639. 'key':'\ud83d\udd11',
  1640. 'keyboard':'\u2328\ufe0f',
  1641. 'keycap_ten':'\ud83d\udd1f',
  1642. 'kick_scooter':'\ud83d\udef4',
  1643. 'kimono':'\ud83d\udc58',
  1644. 'kiss':'\ud83d\udc8b',
  1645. 'kissing':'\ud83d\ude17',
  1646. 'kissing_cat':'\ud83d\ude3d',
  1647. 'kissing_closed_eyes':'\ud83d\ude1a',
  1648. 'kissing_heart':'\ud83d\ude18',
  1649. 'kissing_smiling_eyes':'\ud83d\ude19',
  1650. 'kiwi_fruit':'\ud83e\udd5d',
  1651. 'koala':'\ud83d\udc28',
  1652. 'koko':'\ud83c\ude01',
  1653. 'label':'\ud83c\udff7',
  1654. 'large_blue_circle':'\ud83d\udd35',
  1655. 'large_blue_diamond':'\ud83d\udd37',
  1656. 'large_orange_diamond':'\ud83d\udd36',
  1657. 'last_quarter_moon':'\ud83c\udf17',
  1658. 'last_quarter_moon_with_face':'\ud83c\udf1c',
  1659. 'latin_cross':'\u271d\ufe0f',
  1660. 'laughing':'\ud83d\ude06',
  1661. 'leaves':'\ud83c\udf43',
  1662. 'ledger':'\ud83d\udcd2',
  1663. 'left_luggage':'\ud83d\udec5',
  1664. 'left_right_arrow':'\u2194\ufe0f',
  1665. 'leftwards_arrow_with_hook':'\u21a9\ufe0f',
  1666. 'lemon':'\ud83c\udf4b',
  1667. 'leo':'\u264c\ufe0f',
  1668. 'leopard':'\ud83d\udc06',
  1669. 'level_slider':'\ud83c\udf9a',
  1670. 'libra':'\u264e\ufe0f',
  1671. 'light_rail':'\ud83d\ude88',
  1672. 'link':'\ud83d\udd17',
  1673. 'lion':'\ud83e\udd81',
  1674. 'lips':'\ud83d\udc44',
  1675. 'lipstick':'\ud83d\udc84',
  1676. 'lizard':'\ud83e\udd8e',
  1677. 'lock':'\ud83d\udd12',
  1678. 'lock_with_ink_pen':'\ud83d\udd0f',
  1679. 'lollipop':'\ud83c\udf6d',
  1680. 'loop':'\u27bf',
  1681. 'loud_sound':'\ud83d\udd0a',
  1682. 'loudspeaker':'\ud83d\udce2',
  1683. 'love_hotel':'\ud83c\udfe9',
  1684. 'love_letter':'\ud83d\udc8c',
  1685. 'low_brightness':'\ud83d\udd05',
  1686. 'lying_face':'\ud83e\udd25',
  1687. 'm':'\u24c2\ufe0f',
  1688. 'mag':'\ud83d\udd0d',
  1689. 'mag_right':'\ud83d\udd0e',
  1690. 'mahjong':'\ud83c\udc04\ufe0f',
  1691. 'mailbox':'\ud83d\udceb',
  1692. 'mailbox_closed':'\ud83d\udcea',
  1693. 'mailbox_with_mail':'\ud83d\udcec',
  1694. 'mailbox_with_no_mail':'\ud83d\udced',
  1695. 'man':'\ud83d\udc68',
  1696. 'man_artist':'\ud83d\udc68&zwj;\ud83c\udfa8',
  1697. 'man_astronaut':'\ud83d\udc68&zwj;\ud83d\ude80',
  1698. 'man_cartwheeling':'\ud83e\udd38&zwj;\u2642\ufe0f',
  1699. 'man_cook':'\ud83d\udc68&zwj;\ud83c\udf73',
  1700. 'man_dancing':'\ud83d\udd7a',
  1701. 'man_facepalming':'\ud83e\udd26&zwj;\u2642\ufe0f',
  1702. 'man_factory_worker':'\ud83d\udc68&zwj;\ud83c\udfed',
  1703. 'man_farmer':'\ud83d\udc68&zwj;\ud83c\udf3e',
  1704. 'man_firefighter':'\ud83d\udc68&zwj;\ud83d\ude92',
  1705. 'man_health_worker':'\ud83d\udc68&zwj;\u2695\ufe0f',
  1706. 'man_in_tuxedo':'\ud83e\udd35',
  1707. 'man_judge':'\ud83d\udc68&zwj;\u2696\ufe0f',
  1708. 'man_juggling':'\ud83e\udd39&zwj;\u2642\ufe0f',
  1709. 'man_mechanic':'\ud83d\udc68&zwj;\ud83d\udd27',
  1710. 'man_office_worker':'\ud83d\udc68&zwj;\ud83d\udcbc',
  1711. 'man_pilot':'\ud83d\udc68&zwj;\u2708\ufe0f',
  1712. 'man_playing_handball':'\ud83e\udd3e&zwj;\u2642\ufe0f',
  1713. 'man_playing_water_polo':'\ud83e\udd3d&zwj;\u2642\ufe0f',
  1714. 'man_scientist':'\ud83d\udc68&zwj;\ud83d\udd2c',
  1715. 'man_shrugging':'\ud83e\udd37&zwj;\u2642\ufe0f',
  1716. 'man_singer':'\ud83d\udc68&zwj;\ud83c\udfa4',
  1717. 'man_student':'\ud83d\udc68&zwj;\ud83c\udf93',
  1718. 'man_teacher':'\ud83d\udc68&zwj;\ud83c\udfeb',
  1719. 'man_technologist':'\ud83d\udc68&zwj;\ud83d\udcbb',
  1720. 'man_with_gua_pi_mao':'\ud83d\udc72',
  1721. 'man_with_turban':'\ud83d\udc73',
  1722. 'tangerine':'\ud83c\udf4a',
  1723. 'mans_shoe':'\ud83d\udc5e',
  1724. 'mantelpiece_clock':'\ud83d\udd70',
  1725. 'maple_leaf':'\ud83c\udf41',
  1726. 'martial_arts_uniform':'\ud83e\udd4b',
  1727. 'mask':'\ud83d\ude37',
  1728. 'massage_woman':'\ud83d\udc86',
  1729. 'massage_man':'\ud83d\udc86&zwj;\u2642\ufe0f',
  1730. 'meat_on_bone':'\ud83c\udf56',
  1731. 'medal_military':'\ud83c\udf96',
  1732. 'medal_sports':'\ud83c\udfc5',
  1733. 'mega':'\ud83d\udce3',
  1734. 'melon':'\ud83c\udf48',
  1735. 'memo':'\ud83d\udcdd',
  1736. 'men_wrestling':'\ud83e\udd3c&zwj;\u2642\ufe0f',
  1737. 'menorah':'\ud83d\udd4e',
  1738. 'mens':'\ud83d\udeb9',
  1739. 'metal':'\ud83e\udd18',
  1740. 'metro':'\ud83d\ude87',
  1741. 'microphone':'\ud83c\udfa4',
  1742. 'microscope':'\ud83d\udd2c',
  1743. 'milk_glass':'\ud83e\udd5b',
  1744. 'milky_way':'\ud83c\udf0c',
  1745. 'minibus':'\ud83d\ude90',
  1746. 'minidisc':'\ud83d\udcbd',
  1747. 'mobile_phone_off':'\ud83d\udcf4',
  1748. 'money_mouth_face':'\ud83e\udd11',
  1749. 'money_with_wings':'\ud83d\udcb8',
  1750. 'moneybag':'\ud83d\udcb0',
  1751. 'monkey':'\ud83d\udc12',
  1752. 'monkey_face':'\ud83d\udc35',
  1753. 'monorail':'\ud83d\ude9d',
  1754. 'moon':'\ud83c\udf14',
  1755. 'mortar_board':'\ud83c\udf93',
  1756. 'mosque':'\ud83d\udd4c',
  1757. 'motor_boat':'\ud83d\udee5',
  1758. 'motor_scooter':'\ud83d\udef5',
  1759. 'motorcycle':'\ud83c\udfcd',
  1760. 'motorway':'\ud83d\udee3',
  1761. 'mount_fuji':'\ud83d\uddfb',
  1762. 'mountain':'\u26f0',
  1763. 'mountain_biking_man':'\ud83d\udeb5',
  1764. 'mountain_biking_woman':'\ud83d\udeb5&zwj;\u2640\ufe0f',
  1765. 'mountain_cableway':'\ud83d\udea0',
  1766. 'mountain_railway':'\ud83d\ude9e',
  1767. 'mountain_snow':'\ud83c\udfd4',
  1768. 'mouse':'\ud83d\udc2d',
  1769. 'mouse2':'\ud83d\udc01',
  1770. 'movie_camera':'\ud83c\udfa5',
  1771. 'moyai':'\ud83d\uddff',
  1772. 'mrs_claus':'\ud83e\udd36',
  1773. 'muscle':'\ud83d\udcaa',
  1774. 'mushroom':'\ud83c\udf44',
  1775. 'musical_keyboard':'\ud83c\udfb9',
  1776. 'musical_note':'\ud83c\udfb5',
  1777. 'musical_score':'\ud83c\udfbc',
  1778. 'mute':'\ud83d\udd07',
  1779. 'nail_care':'\ud83d\udc85',
  1780. 'name_badge':'\ud83d\udcdb',
  1781. 'national_park':'\ud83c\udfde',
  1782. 'nauseated_face':'\ud83e\udd22',
  1783. 'necktie':'\ud83d\udc54',
  1784. 'negative_squared_cross_mark':'\u274e',
  1785. 'nerd_face':'\ud83e\udd13',
  1786. 'neutral_face':'\ud83d\ude10',
  1787. 'new':'\ud83c\udd95',
  1788. 'new_moon':'\ud83c\udf11',
  1789. 'new_moon_with_face':'\ud83c\udf1a',
  1790. 'newspaper':'\ud83d\udcf0',
  1791. 'newspaper_roll':'\ud83d\uddde',
  1792. 'next_track_button':'\u23ed',
  1793. 'ng':'\ud83c\udd96',
  1794. 'no_good_man':'\ud83d\ude45&zwj;\u2642\ufe0f',
  1795. 'no_good_woman':'\ud83d\ude45',
  1796. 'night_with_stars':'\ud83c\udf03',
  1797. 'no_bell':'\ud83d\udd15',
  1798. 'no_bicycles':'\ud83d\udeb3',
  1799. 'no_entry':'\u26d4\ufe0f',
  1800. 'no_entry_sign':'\ud83d\udeab',
  1801. 'no_mobile_phones':'\ud83d\udcf5',
  1802. 'no_mouth':'\ud83d\ude36',
  1803. 'no_pedestrians':'\ud83d\udeb7',
  1804. 'no_smoking':'\ud83d\udead',
  1805. 'non-potable_water':'\ud83d\udeb1',
  1806. 'nose':'\ud83d\udc43',
  1807. 'notebook':'\ud83d\udcd3',
  1808. 'notebook_with_decorative_cover':'\ud83d\udcd4',
  1809. 'notes':'\ud83c\udfb6',
  1810. 'nut_and_bolt':'\ud83d\udd29',
  1811. 'o':'\u2b55\ufe0f',
  1812. 'o2':'\ud83c\udd7e\ufe0f',
  1813. 'ocean':'\ud83c\udf0a',
  1814. 'octopus':'\ud83d\udc19',
  1815. 'oden':'\ud83c\udf62',
  1816. 'office':'\ud83c\udfe2',
  1817. 'oil_drum':'\ud83d\udee2',
  1818. 'ok':'\ud83c\udd97',
  1819. 'ok_hand':'\ud83d\udc4c',
  1820. 'ok_man':'\ud83d\ude46&zwj;\u2642\ufe0f',
  1821. 'ok_woman':'\ud83d\ude46',
  1822. 'old_key':'\ud83d\udddd',
  1823. 'older_man':'\ud83d\udc74',
  1824. 'older_woman':'\ud83d\udc75',
  1825. 'om':'\ud83d\udd49',
  1826. 'on':'\ud83d\udd1b',
  1827. 'oncoming_automobile':'\ud83d\ude98',
  1828. 'oncoming_bus':'\ud83d\ude8d',
  1829. 'oncoming_police_car':'\ud83d\ude94',
  1830. 'oncoming_taxi':'\ud83d\ude96',
  1831. 'open_file_folder':'\ud83d\udcc2',
  1832. 'open_hands':'\ud83d\udc50',
  1833. 'open_mouth':'\ud83d\ude2e',
  1834. 'open_umbrella':'\u2602\ufe0f',
  1835. 'ophiuchus':'\u26ce',
  1836. 'orange_book':'\ud83d\udcd9',
  1837. 'orthodox_cross':'\u2626\ufe0f',
  1838. 'outbox_tray':'\ud83d\udce4',
  1839. 'owl':'\ud83e\udd89',
  1840. 'ox':'\ud83d\udc02',
  1841. 'package':'\ud83d\udce6',
  1842. 'page_facing_up':'\ud83d\udcc4',
  1843. 'page_with_curl':'\ud83d\udcc3',
  1844. 'pager':'\ud83d\udcdf',
  1845. 'paintbrush':'\ud83d\udd8c',
  1846. 'palm_tree':'\ud83c\udf34',
  1847. 'pancakes':'\ud83e\udd5e',
  1848. 'panda_face':'\ud83d\udc3c',
  1849. 'paperclip':'\ud83d\udcce',
  1850. 'paperclips':'\ud83d\udd87',
  1851. 'parasol_on_ground':'\u26f1',
  1852. 'parking':'\ud83c\udd7f\ufe0f',
  1853. 'part_alternation_mark':'\u303d\ufe0f',
  1854. 'partly_sunny':'\u26c5\ufe0f',
  1855. 'passenger_ship':'\ud83d\udef3',
  1856. 'passport_control':'\ud83d\udec2',
  1857. 'pause_button':'\u23f8',
  1858. 'peace_symbol':'\u262e\ufe0f',
  1859. 'peach':'\ud83c\udf51',
  1860. 'peanuts':'\ud83e\udd5c',
  1861. 'pear':'\ud83c\udf50',
  1862. 'pen':'\ud83d\udd8a',
  1863. 'pencil2':'\u270f\ufe0f',
  1864. 'penguin':'\ud83d\udc27',
  1865. 'pensive':'\ud83d\ude14',
  1866. 'performing_arts':'\ud83c\udfad',
  1867. 'persevere':'\ud83d\ude23',
  1868. 'person_fencing':'\ud83e\udd3a',
  1869. 'pouting_woman':'\ud83d\ude4e',
  1870. 'phone':'\u260e\ufe0f',
  1871. 'pick':'\u26cf',
  1872. 'pig':'\ud83d\udc37',
  1873. 'pig2':'\ud83d\udc16',
  1874. 'pig_nose':'\ud83d\udc3d',
  1875. 'pill':'\ud83d\udc8a',
  1876. 'pineapple':'\ud83c\udf4d',
  1877. 'ping_pong':'\ud83c\udfd3',
  1878. 'pisces':'\u2653\ufe0f',
  1879. 'pizza':'\ud83c\udf55',
  1880. 'place_of_worship':'\ud83d\uded0',
  1881. 'plate_with_cutlery':'\ud83c\udf7d',
  1882. 'play_or_pause_button':'\u23ef',
  1883. 'point_down':'\ud83d\udc47',
  1884. 'point_left':'\ud83d\udc48',
  1885. 'point_right':'\ud83d\udc49',
  1886. 'point_up':'\u261d\ufe0f',
  1887. 'point_up_2':'\ud83d\udc46',
  1888. 'police_car':'\ud83d\ude93',
  1889. 'policewoman':'\ud83d\udc6e&zwj;\u2640\ufe0f',
  1890. 'poodle':'\ud83d\udc29',
  1891. 'popcorn':'\ud83c\udf7f',
  1892. 'post_office':'\ud83c\udfe3',
  1893. 'postal_horn':'\ud83d\udcef',
  1894. 'postbox':'\ud83d\udcee',
  1895. 'potable_water':'\ud83d\udeb0',
  1896. 'potato':'\ud83e\udd54',
  1897. 'pouch':'\ud83d\udc5d',
  1898. 'poultry_leg':'\ud83c\udf57',
  1899. 'pound':'\ud83d\udcb7',
  1900. 'rage':'\ud83d\ude21',
  1901. 'pouting_cat':'\ud83d\ude3e',
  1902. 'pouting_man':'\ud83d\ude4e&zwj;\u2642\ufe0f',
  1903. 'pray':'\ud83d\ude4f',
  1904. 'prayer_beads':'\ud83d\udcff',
  1905. 'pregnant_woman':'\ud83e\udd30',
  1906. 'previous_track_button':'\u23ee',
  1907. 'prince':'\ud83e\udd34',
  1908. 'princess':'\ud83d\udc78',
  1909. 'printer':'\ud83d\udda8',
  1910. 'purple_heart':'\ud83d\udc9c',
  1911. 'purse':'\ud83d\udc5b',
  1912. 'pushpin':'\ud83d\udccc',
  1913. 'put_litter_in_its_place':'\ud83d\udeae',
  1914. 'question':'\u2753',
  1915. 'rabbit':'\ud83d\udc30',
  1916. 'rabbit2':'\ud83d\udc07',
  1917. 'racehorse':'\ud83d\udc0e',
  1918. 'racing_car':'\ud83c\udfce',
  1919. 'radio':'\ud83d\udcfb',
  1920. 'radio_button':'\ud83d\udd18',
  1921. 'radioactive':'\u2622\ufe0f',
  1922. 'railway_car':'\ud83d\ude83',
  1923. 'railway_track':'\ud83d\udee4',
  1924. 'rainbow':'\ud83c\udf08',
  1925. 'rainbow_flag':'\ud83c\udff3\ufe0f&zwj;\ud83c\udf08',
  1926. 'raised_back_of_hand':'\ud83e\udd1a',
  1927. 'raised_hand_with_fingers_splayed':'\ud83d\udd90',
  1928. 'raised_hands':'\ud83d\ude4c',
  1929. 'raising_hand_woman':'\ud83d\ude4b',
  1930. 'raising_hand_man':'\ud83d\ude4b&zwj;\u2642\ufe0f',
  1931. 'ram':'\ud83d\udc0f',
  1932. 'ramen':'\ud83c\udf5c',
  1933. 'rat':'\ud83d\udc00',
  1934. 'record_button':'\u23fa',
  1935. 'recycle':'\u267b\ufe0f',
  1936. 'red_circle':'\ud83d\udd34',
  1937. 'registered':'\u00ae\ufe0f',
  1938. 'relaxed':'\u263a\ufe0f',
  1939. 'relieved':'\ud83d\ude0c',
  1940. 'reminder_ribbon':'\ud83c\udf97',
  1941. 'repeat':'\ud83d\udd01',
  1942. 'repeat_one':'\ud83d\udd02',
  1943. 'rescue_worker_helmet':'\u26d1',
  1944. 'restroom':'\ud83d\udebb',
  1945. 'revolving_hearts':'\ud83d\udc9e',
  1946. 'rewind':'\u23ea',
  1947. 'rhinoceros':'\ud83e\udd8f',
  1948. 'ribbon':'\ud83c\udf80',
  1949. 'rice':'\ud83c\udf5a',
  1950. 'rice_ball':'\ud83c\udf59',
  1951. 'rice_cracker':'\ud83c\udf58',
  1952. 'rice_scene':'\ud83c\udf91',
  1953. 'right_anger_bubble':'\ud83d\uddef',
  1954. 'ring':'\ud83d\udc8d',
  1955. 'robot':'\ud83e\udd16',
  1956. 'rocket':'\ud83d\ude80',
  1957. 'rofl':'\ud83e\udd23',
  1958. 'roll_eyes':'\ud83d\ude44',
  1959. 'roller_coaster':'\ud83c\udfa2',
  1960. 'rooster':'\ud83d\udc13',
  1961. 'rose':'\ud83c\udf39',
  1962. 'rosette':'\ud83c\udff5',
  1963. 'rotating_light':'\ud83d\udea8',
  1964. 'round_pushpin':'\ud83d\udccd',
  1965. 'rowing_man':'\ud83d\udea3',
  1966. 'rowing_woman':'\ud83d\udea3&zwj;\u2640\ufe0f',
  1967. 'rugby_football':'\ud83c\udfc9',
  1968. 'running_man':'\ud83c\udfc3',
  1969. 'running_shirt_with_sash':'\ud83c\udfbd',
  1970. 'running_woman':'\ud83c\udfc3&zwj;\u2640\ufe0f',
  1971. 'sa':'\ud83c\ude02\ufe0f',
  1972. 'sagittarius':'\u2650\ufe0f',
  1973. 'sake':'\ud83c\udf76',
  1974. 'sandal':'\ud83d\udc61',
  1975. 'santa':'\ud83c\udf85',
  1976. 'satellite':'\ud83d\udce1',
  1977. 'saxophone':'\ud83c\udfb7',
  1978. 'school':'\ud83c\udfeb',
  1979. 'school_satchel':'\ud83c\udf92',
  1980. 'scissors':'\u2702\ufe0f',
  1981. 'scorpion':'\ud83e\udd82',
  1982. 'scorpius':'\u264f\ufe0f',
  1983. 'scream':'\ud83d\ude31',
  1984. 'scream_cat':'\ud83d\ude40',
  1985. 'scroll':'\ud83d\udcdc',
  1986. 'seat':'\ud83d\udcba',
  1987. 'secret':'\u3299\ufe0f',
  1988. 'see_no_evil':'\ud83d\ude48',
  1989. 'seedling':'\ud83c\udf31',
  1990. 'selfie':'\ud83e\udd33',
  1991. 'shallow_pan_of_food':'\ud83e\udd58',
  1992. 'shamrock':'\u2618\ufe0f',
  1993. 'shark':'\ud83e\udd88',
  1994. 'shaved_ice':'\ud83c\udf67',
  1995. 'sheep':'\ud83d\udc11',
  1996. 'shell':'\ud83d\udc1a',
  1997. 'shield':'\ud83d\udee1',
  1998. 'shinto_shrine':'\u26e9',
  1999. 'ship':'\ud83d\udea2',
  2000. 'shirt':'\ud83d\udc55',
  2001. 'shopping':'\ud83d\udecd',
  2002. 'shopping_cart':'\ud83d\uded2',
  2003. 'shower':'\ud83d\udebf',
  2004. 'shrimp':'\ud83e\udd90',
  2005. 'signal_strength':'\ud83d\udcf6',
  2006. 'six_pointed_star':'\ud83d\udd2f',
  2007. 'ski':'\ud83c\udfbf',
  2008. 'skier':'\u26f7',
  2009. 'skull':'\ud83d\udc80',
  2010. 'skull_and_crossbones':'\u2620\ufe0f',
  2011. 'sleeping':'\ud83d\ude34',
  2012. 'sleeping_bed':'\ud83d\udecc',
  2013. 'sleepy':'\ud83d\ude2a',
  2014. 'slightly_frowning_face':'\ud83d\ude41',
  2015. 'slightly_smiling_face':'\ud83d\ude42',
  2016. 'slot_machine':'\ud83c\udfb0',
  2017. 'small_airplane':'\ud83d\udee9',
  2018. 'small_blue_diamond':'\ud83d\udd39',
  2019. 'small_orange_diamond':'\ud83d\udd38',
  2020. 'small_red_triangle':'\ud83d\udd3a',
  2021. 'small_red_triangle_down':'\ud83d\udd3b',
  2022. 'smile':'\ud83d\ude04',
  2023. 'smile_cat':'\ud83d\ude38',
  2024. 'smiley':'\ud83d\ude03',
  2025. 'smiley_cat':'\ud83d\ude3a',
  2026. 'smiling_imp':'\ud83d\ude08',
  2027. 'smirk':'\ud83d\ude0f',
  2028. 'smirk_cat':'\ud83d\ude3c',
  2029. 'smoking':'\ud83d\udeac',
  2030. 'snail':'\ud83d\udc0c',
  2031. 'snake':'\ud83d\udc0d',
  2032. 'sneezing_face':'\ud83e\udd27',
  2033. 'snowboarder':'\ud83c\udfc2',
  2034. 'snowflake':'\u2744\ufe0f',
  2035. 'snowman':'\u26c4\ufe0f',
  2036. 'snowman_with_snow':'\u2603\ufe0f',
  2037. 'sob':'\ud83d\ude2d',
  2038. 'soccer':'\u26bd\ufe0f',
  2039. 'soon':'\ud83d\udd1c',
  2040. 'sos':'\ud83c\udd98',
  2041. 'sound':'\ud83d\udd09',
  2042. 'space_invader':'\ud83d\udc7e',
  2043. 'spades':'\u2660\ufe0f',
  2044. 'spaghetti':'\ud83c\udf5d',
  2045. 'sparkle':'\u2747\ufe0f',
  2046. 'sparkler':'\ud83c\udf87',
  2047. 'sparkles':'\u2728',
  2048. 'sparkling_heart':'\ud83d\udc96',
  2049. 'speak_no_evil':'\ud83d\ude4a',
  2050. 'speaker':'\ud83d\udd08',
  2051. 'speaking_head':'\ud83d\udde3',
  2052. 'speech_balloon':'\ud83d\udcac',
  2053. 'speedboat':'\ud83d\udea4',
  2054. 'spider':'\ud83d\udd77',
  2055. 'spider_web':'\ud83d\udd78',
  2056. 'spiral_calendar':'\ud83d\uddd3',
  2057. 'spiral_notepad':'\ud83d\uddd2',
  2058. 'spoon':'\ud83e\udd44',
  2059. 'squid':'\ud83e\udd91',
  2060. 'stadium':'\ud83c\udfdf',
  2061. 'star':'\u2b50\ufe0f',
  2062. 'star2':'\ud83c\udf1f',
  2063. 'star_and_crescent':'\u262a\ufe0f',
  2064. 'star_of_david':'\u2721\ufe0f',
  2065. 'stars':'\ud83c\udf20',
  2066. 'station':'\ud83d\ude89',
  2067. 'statue_of_liberty':'\ud83d\uddfd',
  2068. 'steam_locomotive':'\ud83d\ude82',
  2069. 'stew':'\ud83c\udf72',
  2070. 'stop_button':'\u23f9',
  2071. 'stop_sign':'\ud83d\uded1',
  2072. 'stopwatch':'\u23f1',
  2073. 'straight_ruler':'\ud83d\udccf',
  2074. 'strawberry':'\ud83c\udf53',
  2075. 'stuck_out_tongue':'\ud83d\ude1b',
  2076. 'stuck_out_tongue_closed_eyes':'\ud83d\ude1d',
  2077. 'stuck_out_tongue_winking_eye':'\ud83d\ude1c',
  2078. 'studio_microphone':'\ud83c\udf99',
  2079. 'stuffed_flatbread':'\ud83e\udd59',
  2080. 'sun_behind_large_cloud':'\ud83c\udf25',
  2081. 'sun_behind_rain_cloud':'\ud83c\udf26',
  2082. 'sun_behind_small_cloud':'\ud83c\udf24',
  2083. 'sun_with_face':'\ud83c\udf1e',
  2084. 'sunflower':'\ud83c\udf3b',
  2085. 'sunglasses':'\ud83d\ude0e',
  2086. 'sunny':'\u2600\ufe0f',
  2087. 'sunrise':'\ud83c\udf05',
  2088. 'sunrise_over_mountains':'\ud83c\udf04',
  2089. 'surfing_man':'\ud83c\udfc4',
  2090. 'surfing_woman':'\ud83c\udfc4&zwj;\u2640\ufe0f',
  2091. 'sushi':'\ud83c\udf63',
  2092. 'suspension_railway':'\ud83d\ude9f',
  2093. 'sweat':'\ud83d\ude13',
  2094. 'sweat_drops':'\ud83d\udca6',
  2095. 'sweat_smile':'\ud83d\ude05',
  2096. 'sweet_potato':'\ud83c\udf60',
  2097. 'swimming_man':'\ud83c\udfca',
  2098. 'swimming_woman':'\ud83c\udfca&zwj;\u2640\ufe0f',
  2099. 'symbols':'\ud83d\udd23',
  2100. 'synagogue':'\ud83d\udd4d',
  2101. 'syringe':'\ud83d\udc89',
  2102. 'taco':'\ud83c\udf2e',
  2103. 'tada':'\ud83c\udf89',
  2104. 'tanabata_tree':'\ud83c\udf8b',
  2105. 'taurus':'\u2649\ufe0f',
  2106. 'taxi':'\ud83d\ude95',
  2107. 'tea':'\ud83c\udf75',
  2108. 'telephone_receiver':'\ud83d\udcde',
  2109. 'telescope':'\ud83d\udd2d',
  2110. 'tennis':'\ud83c\udfbe',
  2111. 'tent':'\u26fa\ufe0f',
  2112. 'thermometer':'\ud83c\udf21',
  2113. 'thinking':'\ud83e\udd14',
  2114. 'thought_balloon':'\ud83d\udcad',
  2115. 'ticket':'\ud83c\udfab',
  2116. 'tickets':'\ud83c\udf9f',
  2117. 'tiger':'\ud83d\udc2f',
  2118. 'tiger2':'\ud83d\udc05',
  2119. 'timer_clock':'\u23f2',
  2120. 'tipping_hand_man':'\ud83d\udc81&zwj;\u2642\ufe0f',
  2121. 'tired_face':'\ud83d\ude2b',
  2122. 'tm':'\u2122\ufe0f',
  2123. 'toilet':'\ud83d\udebd',
  2124. 'tokyo_tower':'\ud83d\uddfc',
  2125. 'tomato':'\ud83c\udf45',
  2126. 'tongue':'\ud83d\udc45',
  2127. 'top':'\ud83d\udd1d',
  2128. 'tophat':'\ud83c\udfa9',
  2129. 'tornado':'\ud83c\udf2a',
  2130. 'trackball':'\ud83d\uddb2',
  2131. 'tractor':'\ud83d\ude9c',
  2132. 'traffic_light':'\ud83d\udea5',
  2133. 'train':'\ud83d\ude8b',
  2134. 'train2':'\ud83d\ude86',
  2135. 'tram':'\ud83d\ude8a',
  2136. 'triangular_flag_on_post':'\ud83d\udea9',
  2137. 'triangular_ruler':'\ud83d\udcd0',
  2138. 'trident':'\ud83d\udd31',
  2139. 'triumph':'\ud83d\ude24',
  2140. 'trolleybus':'\ud83d\ude8e',
  2141. 'trophy':'\ud83c\udfc6',
  2142. 'tropical_drink':'\ud83c\udf79',
  2143. 'tropical_fish':'\ud83d\udc20',
  2144. 'truck':'\ud83d\ude9a',
  2145. 'trumpet':'\ud83c\udfba',
  2146. 'tulip':'\ud83c\udf37',
  2147. 'tumbler_glass':'\ud83e\udd43',
  2148. 'turkey':'\ud83e\udd83',
  2149. 'turtle':'\ud83d\udc22',
  2150. 'tv':'\ud83d\udcfa',
  2151. 'twisted_rightwards_arrows':'\ud83d\udd00',
  2152. 'two_hearts':'\ud83d\udc95',
  2153. 'two_men_holding_hands':'\ud83d\udc6c',
  2154. 'two_women_holding_hands':'\ud83d\udc6d',
  2155. 'u5272':'\ud83c\ude39',
  2156. 'u5408':'\ud83c\ude34',
  2157. 'u55b6':'\ud83c\ude3a',
  2158. 'u6307':'\ud83c\ude2f\ufe0f',
  2159. 'u6708':'\ud83c\ude37\ufe0f',
  2160. 'u6709':'\ud83c\ude36',
  2161. 'u6e80':'\ud83c\ude35',
  2162. 'u7121':'\ud83c\ude1a\ufe0f',
  2163. 'u7533':'\ud83c\ude38',
  2164. 'u7981':'\ud83c\ude32',
  2165. 'u7a7a':'\ud83c\ude33',
  2166. 'umbrella':'\u2614\ufe0f',
  2167. 'unamused':'\ud83d\ude12',
  2168. 'underage':'\ud83d\udd1e',
  2169. 'unicorn':'\ud83e\udd84',
  2170. 'unlock':'\ud83d\udd13',
  2171. 'up':'\ud83c\udd99',
  2172. 'upside_down_face':'\ud83d\ude43',
  2173. 'v':'\u270c\ufe0f',
  2174. 'vertical_traffic_light':'\ud83d\udea6',
  2175. 'vhs':'\ud83d\udcfc',
  2176. 'vibration_mode':'\ud83d\udcf3',
  2177. 'video_camera':'\ud83d\udcf9',
  2178. 'video_game':'\ud83c\udfae',
  2179. 'violin':'\ud83c\udfbb',
  2180. 'virgo':'\u264d\ufe0f',
  2181. 'volcano':'\ud83c\udf0b',
  2182. 'volleyball':'\ud83c\udfd0',
  2183. 'vs':'\ud83c\udd9a',
  2184. 'vulcan_salute':'\ud83d\udd96',
  2185. 'walking_man':'\ud83d\udeb6',
  2186. 'walking_woman':'\ud83d\udeb6&zwj;\u2640\ufe0f',
  2187. 'waning_crescent_moon':'\ud83c\udf18',
  2188. 'waning_gibbous_moon':'\ud83c\udf16',
  2189. 'warning':'\u26a0\ufe0f',
  2190. 'wastebasket':'\ud83d\uddd1',
  2191. 'watch':'\u231a\ufe0f',
  2192. 'water_buffalo':'\ud83d\udc03',
  2193. 'watermelon':'\ud83c\udf49',
  2194. 'wave':'\ud83d\udc4b',
  2195. 'wavy_dash':'\u3030\ufe0f',
  2196. 'waxing_crescent_moon':'\ud83c\udf12',
  2197. 'wc':'\ud83d\udebe',
  2198. 'weary':'\ud83d\ude29',
  2199. 'wedding':'\ud83d\udc92',
  2200. 'weight_lifting_man':'\ud83c\udfcb\ufe0f',
  2201. 'weight_lifting_woman':'\ud83c\udfcb\ufe0f&zwj;\u2640\ufe0f',
  2202. 'whale':'\ud83d\udc33',
  2203. 'whale2':'\ud83d\udc0b',
  2204. 'wheel_of_dharma':'\u2638\ufe0f',
  2205. 'wheelchair':'\u267f\ufe0f',
  2206. 'white_check_mark':'\u2705',
  2207. 'white_circle':'\u26aa\ufe0f',
  2208. 'white_flag':'\ud83c\udff3\ufe0f',
  2209. 'white_flower':'\ud83d\udcae',
  2210. 'white_large_square':'\u2b1c\ufe0f',
  2211. 'white_medium_small_square':'\u25fd\ufe0f',
  2212. 'white_medium_square':'\u25fb\ufe0f',
  2213. 'white_small_square':'\u25ab\ufe0f',
  2214. 'white_square_button':'\ud83d\udd33',
  2215. 'wilted_flower':'\ud83e\udd40',
  2216. 'wind_chime':'\ud83c\udf90',
  2217. 'wind_face':'\ud83c\udf2c',
  2218. 'wine_glass':'\ud83c\udf77',
  2219. 'wink':'\ud83d\ude09',
  2220. 'wolf':'\ud83d\udc3a',
  2221. 'woman':'\ud83d\udc69',
  2222. 'woman_artist':'\ud83d\udc69&zwj;\ud83c\udfa8',
  2223. 'woman_astronaut':'\ud83d\udc69&zwj;\ud83d\ude80',
  2224. 'woman_cartwheeling':'\ud83e\udd38&zwj;\u2640\ufe0f',
  2225. 'woman_cook':'\ud83d\udc69&zwj;\ud83c\udf73',
  2226. 'woman_facepalming':'\ud83e\udd26&zwj;\u2640\ufe0f',
  2227. 'woman_factory_worker':'\ud83d\udc69&zwj;\ud83c\udfed',
  2228. 'woman_farmer':'\ud83d\udc69&zwj;\ud83c\udf3e',
  2229. 'woman_firefighter':'\ud83d\udc69&zwj;\ud83d\ude92',
  2230. 'woman_health_worker':'\ud83d\udc69&zwj;\u2695\ufe0f',
  2231. 'woman_judge':'\ud83d\udc69&zwj;\u2696\ufe0f',
  2232. 'woman_juggling':'\ud83e\udd39&zwj;\u2640\ufe0f',
  2233. 'woman_mechanic':'\ud83d\udc69&zwj;\ud83d\udd27',
  2234. 'woman_office_worker':'\ud83d\udc69&zwj;\ud83d\udcbc',
  2235. 'woman_pilot':'\ud83d\udc69&zwj;\u2708\ufe0f',
  2236. 'woman_playing_handball':'\ud83e\udd3e&zwj;\u2640\ufe0f',
  2237. 'woman_playing_water_polo':'\ud83e\udd3d&zwj;\u2640\ufe0f',
  2238. 'woman_scientist':'\ud83d\udc69&zwj;\ud83d\udd2c',
  2239. 'woman_shrugging':'\ud83e\udd37&zwj;\u2640\ufe0f',
  2240. 'woman_singer':'\ud83d\udc69&zwj;\ud83c\udfa4',
  2241. 'woman_student':'\ud83d\udc69&zwj;\ud83c\udf93',
  2242. 'woman_teacher':'\ud83d\udc69&zwj;\ud83c\udfeb',
  2243. 'woman_technologist':'\ud83d\udc69&zwj;\ud83d\udcbb',
  2244. 'woman_with_turban':'\ud83d\udc73&zwj;\u2640\ufe0f',
  2245. 'womans_clothes':'\ud83d\udc5a',
  2246. 'womans_hat':'\ud83d\udc52',
  2247. 'women_wrestling':'\ud83e\udd3c&zwj;\u2640\ufe0f',
  2248. 'womens':'\ud83d\udeba',
  2249. 'world_map':'\ud83d\uddfa',
  2250. 'worried':'\ud83d\ude1f',
  2251. 'wrench':'\ud83d\udd27',
  2252. 'writing_hand':'\u270d\ufe0f',
  2253. 'x':'\u274c',
  2254. 'yellow_heart':'\ud83d\udc9b',
  2255. 'yen':'\ud83d\udcb4',
  2256. 'yin_yang':'\u262f\ufe0f',
  2257. 'yum':'\ud83d\ude0b',
  2258. 'zap':'\u26a1\ufe0f',
  2259. 'zipper_mouth_face':'\ud83e\udd10',
  2260. 'zzz':'\ud83d\udca4',
  2261. /* special emojis :P */
  2262. 'octocat': '<img width="20" height="20" align="absmiddle" src="https://assets-cdn.github.com/images/icons/emoji/octocat.png">',
  2263. 'showdown': '<img width="20" height="20" align="absmiddle" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAS1BMVEX///8jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS0jJS3b1q3b1q3b1q3b1q3b1q3b1q3b1q3b1q0565CIAAAAGXRSTlMAQHCAYCCw/+DQwPCQUBAwoHCAEP+wwFBgS2fvBgAAAUZJREFUeAHs1cGy7BAUheFFsEDw/k97VTq3T6ge2EmdM+pvrP6Iwd74XV9Kb52xuMU4/uc1YNgZLFOeV8FGdhGrNk5SEgUyPxAEdj4LlMRDyhVAMVEa2M7TBSeVZAFPdqHgzSZJwPKgcLFLAooHDJo4EDCw4gAtBoJA5UFj4Ng5LOGLwVXZuoIlji/jeQHFk7+baHxrCjeUwB9+s88KndvlhcyBN5BSkYNQIVVb4pV+Npm7hhuKDs/uMP5KxT3WzSNNLIuuoDpMmuAVMruMSeDyQBi24DTr43LAY7ILA1QYaWkgfHzFthYYzg67SQsCbB8GhJUEGCtO9n0rSaCLxgJQjS/JSgMTg2eBDEHAJ+H350AsjYNYscrErgI2e/l+mdR967TCX/v6N0EhPECYCP0i+IAoYQOE8BogNhQMEMdrgAQWHaMAAGi5I5euoY9NAAAAAElFTkSuQmCC">'
  2264. };
  2265. /**
  2266. * These are all the transformations that form block-level
  2267. * tags like paragraphs, headers, and list items.
  2268. */
  2269. showdown.subParser('makehtml.blockGamut', function (text, options, globals) {
  2270. 'use strict';
  2271. text = globals.converter._dispatch('makehtml.blockGamut.before', text, options, globals).getText();
  2272. // we parse blockquotes first so that we can have headings and hrs
  2273. // inside blockquotes
  2274. text = showdown.subParser('makehtml.blockQuotes')(text, options, globals);
  2275. text = showdown.subParser('makehtml.headers')(text, options, globals);
  2276. // Do Horizontal Rules:
  2277. text = showdown.subParser('makehtml.horizontalRule')(text, options, globals);
  2278. text = showdown.subParser('makehtml.lists')(text, options, globals);
  2279. text = showdown.subParser('makehtml.codeBlocks')(text, options, globals);
  2280. text = showdown.subParser('makehtml.tables')(text, options, globals);
  2281. // We already ran _HashHTMLBlocks() before, in Markdown(), but that
  2282. // was to escape raw HTML in the original Markdown source. This time,
  2283. // we're escaping the markup we've just created, so that we don't wrap
  2284. // <p> tags around block-level tags.
  2285. text = showdown.subParser('makehtml.hashHTMLBlocks')(text, options, globals);
  2286. text = showdown.subParser('makehtml.paragraphs')(text, options, globals);
  2287. text = globals.converter._dispatch('makehtml.blockGamut.after', text, options, globals).getText();
  2288. return text;
  2289. });
  2290. showdown.subParser('makehtml.blockQuotes', function (text, options, globals) {
  2291. 'use strict';
  2292. text = globals.converter._dispatch('makehtml.blockQuotes.before', text, options, globals).getText();
  2293. // add a couple extra lines after the text and endtext mark
  2294. text = text + '\n\n';
  2295. var rgx = /(^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+/gm;
  2296. if (options.splitAdjacentBlockquotes) {
  2297. rgx = /^ {0,3}>[\s\S]*?(?:\n\n)/gm;
  2298. }
  2299. text = text.replace(rgx, function (bq) {
  2300. // attacklab: hack around Konqueror 3.5.4 bug:
  2301. // "----------bug".replace(/^-/g,"") == "bug"
  2302. bq = bq.replace(/^[ \t]*>[ \t]?/gm, ''); // trim one level of quoting
  2303. // attacklab: clean up hack
  2304. bq = bq.replace(/¨0/g, '');
  2305. bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines
  2306. bq = showdown.subParser('makehtml.githubCodeBlocks')(bq, options, globals);
  2307. bq = showdown.subParser('makehtml.blockGamut')(bq, options, globals); // recurse
  2308. bq = bq.replace(/(^|\n)/g, '$1 ');
  2309. // These leading spaces screw with <pre> content, so we need to fix that:
  2310. bq = bq.replace(/(\s*<pre>[^\r]+?<\/pre>)/gm, function (wholeMatch, m1) {
  2311. var pre = m1;
  2312. // attacklab: hack around Konqueror 3.5.4 bug:
  2313. pre = pre.replace(/^ /mg, '¨0');
  2314. pre = pre.replace(/¨0/g, '');
  2315. return pre;
  2316. });
  2317. return showdown.subParser('makehtml.hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals);
  2318. });
  2319. text = globals.converter._dispatch('makehtml.blockQuotes.after', text, options, globals).getText();
  2320. return text;
  2321. });
  2322. /**
  2323. * Process Markdown `<pre><code>` blocks.
  2324. */
  2325. showdown.subParser('makehtml.codeBlocks', function (text, options, globals) {
  2326. 'use strict';
  2327. text = globals.converter._dispatch('makehtml.codeBlocks.before', text, options, globals).getText();
  2328. // sentinel workarounds for lack of \A and \Z, safari\khtml bug
  2329. text += '¨0';
  2330. var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=¨0))/g;
  2331. text = text.replace(pattern, function (wholeMatch, m1, m2) {
  2332. var codeblock = m1,
  2333. nextChar = m2,
  2334. end = '\n';
  2335. codeblock = showdown.subParser('makehtml.outdent')(codeblock, options, globals);
  2336. codeblock = showdown.subParser('makehtml.encodeCode')(codeblock, options, globals);
  2337. codeblock = showdown.subParser('makehtml.detab')(codeblock, options, globals);
  2338. codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
  2339. codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines
  2340. if (options.omitExtraWLInCodeBlocks) {
  2341. end = '';
  2342. }
  2343. codeblock = '<pre><code>' + codeblock + end + '</code></pre>';
  2344. return showdown.subParser('makehtml.hashBlock')(codeblock, options, globals) + nextChar;
  2345. });
  2346. // strip sentinel
  2347. text = text.replace(/¨0/, '');
  2348. text = globals.converter._dispatch('makehtml.codeBlocks.after', text, options, globals).getText();
  2349. return text;
  2350. });
  2351. /**
  2352. *
  2353. * * Backtick quotes are used for <code></code> spans.
  2354. *
  2355. * * You can use multiple backticks as the delimiters if you want to
  2356. * include literal backticks in the code span. So, this input:
  2357. *
  2358. * Just type ``foo `bar` baz`` at the prompt.
  2359. *
  2360. * Will translate to:
  2361. *
  2362. * <p>Just type <code>foo `bar` baz</code> at the prompt.</p>
  2363. *
  2364. * There's no arbitrary limit to the number of backticks you
  2365. * can use as delimters. If you need three consecutive backticks
  2366. * in your code, use four for delimiters, etc.
  2367. *
  2368. * * You can use spaces to get literal backticks at the edges:
  2369. *
  2370. * ... type `` `bar` `` ...
  2371. *
  2372. * Turns to:
  2373. *
  2374. * ... type <code>`bar`</code> ...
  2375. */
  2376. showdown.subParser('makehtml.codeSpans', function (text, options, globals) {
  2377. 'use strict';
  2378. text = globals.converter._dispatch('makehtml.codeSpans.before', text, options, globals).getText();
  2379. if (typeof(text) === 'undefined') {
  2380. text = '';
  2381. }
  2382. text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
  2383. function (wholeMatch, m1, m2, m3) {
  2384. var c = m3;
  2385. c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
  2386. c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
  2387. c = showdown.subParser('makehtml.encodeCode')(c, options, globals);
  2388. c = m1 + '<code>' + c + '</code>';
  2389. c = showdown.subParser('makehtml.hashHTMLSpans')(c, options, globals);
  2390. return c;
  2391. }
  2392. );
  2393. text = globals.converter._dispatch('makehtml.codeSpans.after', text, options, globals).getText();
  2394. return text;
  2395. });
  2396. /**
  2397. * Create a full HTML document from the processed markdown
  2398. */
  2399. showdown.subParser('makehtml.completeHTMLDocument', function (text, options, globals) {
  2400. 'use strict';
  2401. if (!options.completeHTMLDocument) {
  2402. return text;
  2403. }
  2404. text = globals.converter._dispatch('makehtml.completeHTMLDocument.before', text, options, globals).getText();
  2405. var doctype = 'html',
  2406. doctypeParsed = '<!DOCTYPE HTML>\n',
  2407. title = '',
  2408. charset = '<meta charset="utf-8">\n',
  2409. lang = '',
  2410. metadata = '';
  2411. if (typeof globals.metadata.parsed.doctype !== 'undefined') {
  2412. doctypeParsed = '<!DOCTYPE ' + globals.metadata.parsed.doctype + '>\n';
  2413. doctype = globals.metadata.parsed.doctype.toString().toLowerCase();
  2414. if (doctype === 'html' || doctype === 'html5') {
  2415. charset = '<meta charset="utf-8">';
  2416. }
  2417. }
  2418. for (var meta in globals.metadata.parsed) {
  2419. if (globals.metadata.parsed.hasOwnProperty(meta)) {
  2420. switch (meta.toLowerCase()) {
  2421. case 'doctype':
  2422. break;
  2423. case 'title':
  2424. title = '<title>' + globals.metadata.parsed.title + '</title>\n';
  2425. break;
  2426. case 'charset':
  2427. if (doctype === 'html' || doctype === 'html5') {
  2428. charset = '<meta charset="' + globals.metadata.parsed.charset + '">\n';
  2429. } else {
  2430. charset = '<meta name="charset" content="' + globals.metadata.parsed.charset + '">\n';
  2431. }
  2432. break;
  2433. case 'language':
  2434. case 'lang':
  2435. lang = ' lang="' + globals.metadata.parsed[meta] + '"';
  2436. metadata += '<meta name="' + meta + '" content="' + globals.metadata.parsed[meta] + '">\n';
  2437. break;
  2438. default:
  2439. metadata += '<meta name="' + meta + '" content="' + globals.metadata.parsed[meta] + '">\n';
  2440. }
  2441. }
  2442. }
  2443. text = doctypeParsed + '<html' + lang + '>\n<head>\n' + title + charset + metadata + '</head>\n<body>\n' + text.trim() + '\n</body>\n</html>';
  2444. text = globals.converter._dispatch('makehtml.completeHTMLDocument.after', text, options, globals).getText();
  2445. return text;
  2446. });
  2447. /**
  2448. * Convert all tabs to spaces
  2449. */
  2450. showdown.subParser('makehtml.detab', function (text, options, globals) {
  2451. 'use strict';
  2452. text = globals.converter._dispatch('makehtml.detab.before', text, options, globals).getText();
  2453. // expand first n-1 tabs
  2454. text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
  2455. // replace the nth with two sentinels
  2456. text = text.replace(/\t/g, '¨A¨B');
  2457. // use the sentinel to anchor our regex so it doesn't explode
  2458. text = text.replace(/¨B(.+?)¨A/g, function (wholeMatch, m1) {
  2459. var leadingText = m1,
  2460. numSpaces = 4 - leadingText.length % 4; // g_tab_width
  2461. // there *must* be a better way to do this:
  2462. for (var i = 0; i < numSpaces; i++) {
  2463. leadingText += ' ';
  2464. }
  2465. return leadingText;
  2466. });
  2467. // clean up sentinels
  2468. text = text.replace(/¨A/g, ' '); // g_tab_width
  2469. text = text.replace(/¨B/g, '');
  2470. text = globals.converter._dispatch('makehtml.detab.after', text, options, globals).getText();
  2471. return text;
  2472. });
  2473. showdown.subParser('makehtml.ellipsis', function (text, options, globals) {
  2474. 'use strict';
  2475. text = globals.converter._dispatch('makehtml.ellipsis.before', text, options, globals).getText();
  2476. text = text.replace(/\.\.\./g, '…');
  2477. text = globals.converter._dispatch('makehtml.ellipsis.after', text, options, globals).getText();
  2478. return text;
  2479. });
  2480. /**
  2481. * These are all the transformations that occur *within* block-level
  2482. * tags like paragraphs, headers, and list items.
  2483. */
  2484. showdown.subParser('makehtml.emoji', function (text, options, globals) {
  2485. 'use strict';
  2486. if (!options.emoji) {
  2487. return text;
  2488. }
  2489. text = globals.converter._dispatch('makehtml.emoji.before', text, options, globals).getText();
  2490. var emojiRgx = /:([\S]+?):/g;
  2491. text = text.replace(emojiRgx, function (wm, emojiCode) {
  2492. if (showdown.helper.emojis.hasOwnProperty(emojiCode)) {
  2493. return showdown.helper.emojis[emojiCode];
  2494. }
  2495. return wm;
  2496. });
  2497. text = globals.converter._dispatch('makehtml.emoji.after', text, options, globals).getText();
  2498. return text;
  2499. });
  2500. /**
  2501. * Smart processing for ampersands and angle brackets that need to be encoded.
  2502. */
  2503. showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, globals) {
  2504. 'use strict';
  2505. text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.before', text, options, globals).getText();
  2506. // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
  2507. // http://bumppo.net/projects/amputator/
  2508. text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, '&amp;');
  2509. // Encode naked <'s
  2510. text = text.replace(/<(?![a-z\/?$!])/gi, '&lt;');
  2511. // Encode <
  2512. text = text.replace(/</g, '&lt;');
  2513. // Encode >
  2514. text = text.replace(/>/g, '&gt;');
  2515. text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.after', text, options, globals).getText();
  2516. return text;
  2517. });
  2518. /**
  2519. * Returns the string, with after processing the following backslash escape sequences.
  2520. *
  2521. * attacklab: The polite way to do this is with the new escapeCharacters() function:
  2522. *
  2523. * text = escapeCharacters(text,"\\",true);
  2524. * text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
  2525. *
  2526. * ...but we're sidestepping its use of the (slow) RegExp constructor
  2527. * as an optimization for Firefox. This function gets called a LOT.
  2528. */
  2529. showdown.subParser('makehtml.encodeBackslashEscapes', function (text, options, globals) {
  2530. 'use strict';
  2531. text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.before', text, options, globals).getText();
  2532. text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
  2533. text = text.replace(/\\([`*_{}\[\]()>#+.!~=|:-])/g, showdown.helper.escapeCharactersCallback);
  2534. text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.after', text, options, globals).getText();
  2535. return text;
  2536. });
  2537. /**
  2538. * Encode/escape certain characters inside Markdown code runs.
  2539. * The point is that in code, these characters are literals,
  2540. * and lose their special Markdown meanings.
  2541. */
  2542. showdown.subParser('makehtml.encodeCode', function (text, options, globals) {
  2543. 'use strict';
  2544. text = globals.converter._dispatch('makehtml.encodeCode.before', text, options, globals).getText();
  2545. // Encode all ampersands; HTML entities are not
  2546. // entities within a Markdown code span.
  2547. text = text
  2548. .replace(/&/g, '&amp;')
  2549. // Do the angle bracket song and dance:
  2550. .replace(/</g, '&lt;')
  2551. .replace(/>/g, '&gt;')
  2552. // Now, escape characters that are magic in Markdown:
  2553. .replace(/([*_{}\[\]\\=~-])/g, showdown.helper.escapeCharactersCallback);
  2554. text = globals.converter._dispatch('makehtml.encodeCode.after', text, options, globals).getText();
  2555. return text;
  2556. });
  2557. /**
  2558. * Within tags -- meaning between < and > -- encode [\ ` * _ ~ =] so they
  2559. * don't conflict with their use in Markdown for code, italics and strong.
  2560. */
  2561. showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (text, options, globals) {
  2562. 'use strict';
  2563. text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.before', text, options, globals).getText();
  2564. // Build a regex to find HTML tags.
  2565. var tags = /<\/?[a-z\d_:-]+(?:[\s]+[\s\S]+?)?>/gi,
  2566. comments = /<!(--(?:(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>/gi;
  2567. text = text.replace(tags, function (wholeMatch) {
  2568. return wholeMatch
  2569. .replace(/(.)<\/?code>(?=.)/g, '$1`')
  2570. .replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
  2571. });
  2572. text = text.replace(comments, function (wholeMatch) {
  2573. return wholeMatch
  2574. .replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
  2575. });
  2576. text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.after', text, options, globals).getText();
  2577. return text;
  2578. });
  2579. /**
  2580. * Handle github codeblocks prior to running HashHTML so that
  2581. * HTML contained within the codeblock gets escaped properly
  2582. * Example:
  2583. * ```ruby
  2584. * def hello_world(x)
  2585. * puts "Hello, #{x}"
  2586. * end
  2587. * ```
  2588. */
  2589. showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals) {
  2590. 'use strict';
  2591. // early exit if option is not enabled
  2592. if (!options.ghCodeBlocks) {
  2593. return text;
  2594. }
  2595. text = globals.converter._dispatch('makehtml.githubCodeBlocks.before', text, options, globals).getText();
  2596. text += '¨0';
  2597. text = text.replace(/(?:^|\n)(?: {0,3})(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n(?: {0,3})\1/g, function (wholeMatch, delim, language, codeblock) {
  2598. var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
  2599. // First parse the github code block
  2600. codeblock = showdown.subParser('makehtml.encodeCode')(codeblock, options, globals);
  2601. codeblock = showdown.subParser('makehtml.detab')(codeblock, options, globals);
  2602. codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
  2603. codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
  2604. codeblock = '<pre><code' + (language ? ' class="' + language + ' language-' + language + '"' : '') + '>' + codeblock + end + '</code></pre>';
  2605. codeblock = showdown.subParser('makehtml.hashBlock')(codeblock, options, globals);
  2606. // Since GHCodeblocks can be false positives, we need to
  2607. // store the primitive text and the parsed text in a global var,
  2608. // and then return a token
  2609. return '\n\n¨G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
  2610. });
  2611. // attacklab: strip sentinel
  2612. text = text.replace(/¨0/, '');
  2613. return globals.converter._dispatch('makehtml.githubCodeBlocks.after', text, options, globals).getText();
  2614. });
  2615. showdown.subParser('makehtml.hashBlock', function (text, options, globals) {
  2616. 'use strict';
  2617. text = globals.converter._dispatch('makehtml.hashBlock.before', text, options, globals).getText();
  2618. text = text.replace(/(^\n+|\n+$)/g, '');
  2619. text = '\n\n¨K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
  2620. text = globals.converter._dispatch('makehtml.hashBlock.after', text, options, globals).getText();
  2621. return text;
  2622. });
  2623. /**
  2624. * Hash and escape <code> elements that should not be parsed as markdown
  2625. */
  2626. showdown.subParser('makehtml.hashCodeTags', function (text, options, globals) {
  2627. 'use strict';
  2628. text = globals.converter._dispatch('makehtml.hashCodeTags.before', text, options, globals).getText();
  2629. var repFunc = function (wholeMatch, match, left, right) {
  2630. var codeblock = left + showdown.subParser('makehtml.encodeCode')(match, options, globals) + right;
  2631. return '¨C' + (globals.gHtmlSpans.push(codeblock) - 1) + 'C';
  2632. };
  2633. // Hash naked <code>
  2634. text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '<code\\b[^>]*>', '</code>', 'gim');
  2635. text = globals.converter._dispatch('makehtml.hashCodeTags.after', text, options, globals).getText();
  2636. return text;
  2637. });
  2638. showdown.subParser('makehtml.hashElement', function (text, options, globals) {
  2639. 'use strict';
  2640. return function (wholeMatch, m1) {
  2641. var blockText = m1;
  2642. // Undo double lines
  2643. blockText = blockText.replace(/\n\n/g, '\n');
  2644. blockText = blockText.replace(/^\n/, '');
  2645. // strip trailing blank lines
  2646. blockText = blockText.replace(/\n+$/g, '');
  2647. // Replace the element text with a marker ("¨KxK" where x is its key)
  2648. blockText = '\n\n¨K' + (globals.gHtmlBlocks.push(blockText) - 1) + 'K\n\n';
  2649. return blockText;
  2650. };
  2651. });
  2652. showdown.subParser('makehtml.hashHTMLBlocks', function (text, options, globals) {
  2653. 'use strict';
  2654. text = globals.converter._dispatch('makehtml.hashHTMLBlocks.before', text, options, globals).getText();
  2655. var blockTags = [
  2656. 'pre',
  2657. 'div',
  2658. 'h1',
  2659. 'h2',
  2660. 'h3',
  2661. 'h4',
  2662. 'h5',
  2663. 'h6',
  2664. 'blockquote',
  2665. 'table',
  2666. 'dl',
  2667. 'ol',
  2668. 'ul',
  2669. 'script',
  2670. 'noscript',
  2671. 'form',
  2672. 'fieldset',
  2673. 'iframe',
  2674. 'math',
  2675. 'style',
  2676. 'section',
  2677. 'header',
  2678. 'footer',
  2679. 'nav',
  2680. 'article',
  2681. 'aside',
  2682. 'address',
  2683. 'audio',
  2684. 'canvas',
  2685. 'figure',
  2686. 'hgroup',
  2687. 'output',
  2688. 'video',
  2689. 'p'
  2690. ],
  2691. repFunc = function (wholeMatch, match, left, right) {
  2692. var txt = wholeMatch;
  2693. // check if this html element is marked as markdown
  2694. // if so, it's contents should be parsed as markdown
  2695. if (left.search(/\bmarkdown\b/) !== -1) {
  2696. txt = left + globals.converter.makeHtml(match) + right;
  2697. }
  2698. return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
  2699. };
  2700. if (options.backslashEscapesHTMLTags) {
  2701. // encode backslash escaped HTML tags
  2702. text = text.replace(/\\<(\/?[^>]+?)>/g, function (wm, inside) {
  2703. return '&lt;' + inside + '&gt;';
  2704. });
  2705. }
  2706. // hash HTML Blocks
  2707. for (var i = 0; i < blockTags.length; ++i) {
  2708. var opTagPos,
  2709. rgx1 = new RegExp('^ {0,3}(<' + blockTags[i] + '\\b[^>]*>)', 'im'),
  2710. patLeft = '<' + blockTags[i] + '\\b[^>]*>',
  2711. patRight = '</' + blockTags[i] + '>';
  2712. // 1. Look for the first position of the first opening HTML tag in the text
  2713. while ((opTagPos = showdown.helper.regexIndexOf(text, rgx1)) !== -1) {
  2714. // if the HTML tag is \ escaped, we need to escape it and break
  2715. //2. Split the text in that position
  2716. var subTexts = showdown.helper.splitAtIndex(text, opTagPos),
  2717. //3. Match recursively
  2718. newSubText1 = showdown.helper.replaceRecursiveRegExp(subTexts[1], repFunc, patLeft, patRight, 'im');
  2719. // prevent an infinite loop
  2720. if (newSubText1 === subTexts[1]) {
  2721. break;
  2722. }
  2723. text = subTexts[0].concat(newSubText1);
  2724. }
  2725. }
  2726. // HR SPECIAL CASE
  2727. text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
  2728. showdown.subParser('makehtml.hashElement')(text, options, globals));
  2729. // Special case for standalone HTML comments
  2730. text = showdown.helper.replaceRecursiveRegExp(text, function (txt) {
  2731. return '\n\n¨K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
  2732. }, '^ {0,3}<!--', '-->', 'gm');
  2733. // PHP and ASP-style processor instructions (<?...?> and <%...%>)
  2734. text = text.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
  2735. showdown.subParser('makehtml.hashElement')(text, options, globals));
  2736. text = globals.converter._dispatch('makehtml.hashHTMLBlocks.after', text, options, globals).getText();
  2737. return text;
  2738. });
  2739. /**
  2740. * Hash span elements that should not be parsed as markdown
  2741. */
  2742. showdown.subParser('makehtml.hashHTMLSpans', function (text, options, globals) {
  2743. 'use strict';
  2744. text = globals.converter._dispatch('makehtml.hashHTMLSpans.before', text, options, globals).getText();
  2745. // Hash Self Closing tags
  2746. text = text.replace(/<[^>]+?\/>/gi, function (wm) {
  2747. return showdown.helper._hashHTMLSpan(wm, globals);
  2748. });
  2749. // Hash tags without properties
  2750. text = text.replace(/<([^>]+?)>[\s\S]*?<\/\1>/g, function (wm) {
  2751. return showdown.helper._hashHTMLSpan(wm, globals);
  2752. });
  2753. // Hash tags with properties
  2754. text = text.replace(/<([^>]+?)\s[^>]+?>[\s\S]*?<\/\1>/g, function (wm) {
  2755. return showdown.helper._hashHTMLSpan(wm, globals);
  2756. });
  2757. // Hash self closing tags without />
  2758. text = text.replace(/<[^>]+?>/gi, function (wm) {
  2759. return showdown.helper._hashHTMLSpan(wm, globals);
  2760. });
  2761. text = globals.converter._dispatch('makehtml.hashHTMLSpans.after', text, options, globals).getText();
  2762. return text;
  2763. });
  2764. /**
  2765. * Unhash HTML spans
  2766. */
  2767. showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals) {
  2768. 'use strict';
  2769. text = globals.converter._dispatch('makehtml.unhashHTMLSpans.before', text, options, globals).getText();
  2770. for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
  2771. var repText = globals.gHtmlSpans[i],
  2772. // limiter to prevent infinite loop (assume 10 as limit for recurse)
  2773. limit = 0;
  2774. while (/¨C(\d+)C/.test(repText)) {
  2775. var num = RegExp.$1;
  2776. repText = repText.replace('¨C' + num + 'C', globals.gHtmlSpans[num]);
  2777. if (limit === 10) {
  2778. console.error('maximum nesting of 10 spans reached!!!');
  2779. break;
  2780. }
  2781. ++limit;
  2782. }
  2783. text = text.replace('¨C' + i + 'C', repText);
  2784. }
  2785. text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals).getText();
  2786. return text;
  2787. });
  2788. /**
  2789. * Hash and escape <pre><code> elements that should not be parsed as markdown
  2790. */
  2791. showdown.subParser('makehtml.hashPreCodeTags', function (text, options, globals) {
  2792. 'use strict';
  2793. text = globals.converter._dispatch('makehtml.hashPreCodeTags.before', text, options, globals).getText();
  2794. var repFunc = function (wholeMatch, match, left, right) {
  2795. // encode html entities
  2796. var codeblock = left + showdown.subParser('makehtml.encodeCode')(match, options, globals) + right;
  2797. return '\n\n¨G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
  2798. };
  2799. // Hash <pre><code>
  2800. text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<pre\\b[^>]*>\\s*<code\\b[^>]*>', '^ {0,3}</code>\\s*</pre>', 'gim');
  2801. text = globals.converter._dispatch('makehtml.hashPreCodeTags.after', text, options, globals).getText();
  2802. return text;
  2803. });
  2804. showdown.subParser('makehtml.headers', function (text, options, globals) {
  2805. 'use strict';
  2806. text = globals.converter._dispatch('makehtml.headers.before', text, options, globals).getText();
  2807. var headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
  2808. // Set text-style headers:
  2809. // Header 1
  2810. // ========
  2811. //
  2812. // Header 2
  2813. // --------
  2814. //
  2815. setextRegexH1 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n={2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n=+[ \t]*\n+/gm,
  2816. setextRegexH2 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n-+[ \t]*\n+/gm;
  2817. text = text.replace(setextRegexH1, function (wholeMatch, m1) {
  2818. var spanGamut = showdown.subParser('makehtml.spanGamut')(m1, options, globals),
  2819. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
  2820. hLevel = headerLevelStart,
  2821. hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
  2822. return showdown.subParser('makehtml.hashBlock')(hashBlock, options, globals);
  2823. });
  2824. text = text.replace(setextRegexH2, function (matchFound, m1) {
  2825. var spanGamut = showdown.subParser('makehtml.spanGamut')(m1, options, globals),
  2826. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
  2827. hLevel = headerLevelStart + 1,
  2828. hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
  2829. return showdown.subParser('makehtml.hashBlock')(hashBlock, options, globals);
  2830. });
  2831. // atx-style headers:
  2832. // # Header 1
  2833. // ## Header 2
  2834. // ## Header 2 with closing hashes ##
  2835. // ...
  2836. // ###### Header 6
  2837. //
  2838. var atxStyle = (options.requireSpaceBeforeHeadingText) ? /^(#{1,6})[ \t]+(.+?)[ \t]*#*\n+/gm : /^(#{1,6})[ \t]*(.+?)[ \t]*#*\n+/gm;
  2839. text = text.replace(atxStyle, function (wholeMatch, m1, m2) {
  2840. var hText = m2;
  2841. if (options.customizedHeaderId) {
  2842. hText = m2.replace(/\s?\{([^{]+?)}\s*$/, '');
  2843. }
  2844. var span = showdown.subParser('makehtml.spanGamut')(hText, options, globals),
  2845. hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
  2846. hLevel = headerLevelStart - 1 + m1.length,
  2847. header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
  2848. return showdown.subParser('makehtml.hashBlock')(header, options, globals);
  2849. });
  2850. function headerId (m) {
  2851. var title,
  2852. prefix;
  2853. // It is separate from other options to allow combining prefix and customized
  2854. if (options.customizedHeaderId) {
  2855. var match = m.match(/\{([^{]+?)}\s*$/);
  2856. if (match && match[1]) {
  2857. m = match[1];
  2858. }
  2859. }
  2860. title = m;
  2861. // Prefix id to prevent causing inadvertent pre-existing style matches.
  2862. if (showdown.helper.isString(options.prefixHeaderId)) {
  2863. prefix = options.prefixHeaderId;
  2864. } else if (options.prefixHeaderId === true) {
  2865. prefix = 'section-';
  2866. } else {
  2867. prefix = '';
  2868. }
  2869. if (!options.rawPrefixHeaderId) {
  2870. title = prefix + title;
  2871. }
  2872. if (options.ghCompatibleHeaderId) {
  2873. title = title
  2874. .replace(/ /g, '-')
  2875. // replace previously escaped chars (&, ¨ and $)
  2876. .replace(/&amp;/g, '')
  2877. .replace(/¨T/g, '')
  2878. .replace(/¨D/g, '')
  2879. // replace rest of the chars (&~$ are repeated as they might have been escaped)
  2880. // borrowed from github's redcarpet (some they should produce similar results)
  2881. .replace(/[&+$,\/:;=?@"#{}|^¨~\[\]`\\*)(%.!'<>]/g, '')
  2882. .toLowerCase();
  2883. } else if (options.rawHeaderId) {
  2884. title = title
  2885. .replace(/ /g, '-')
  2886. // replace previously escaped chars (&, ¨ and $)
  2887. .replace(/&amp;/g, '&')
  2888. .replace(/¨T/g, '¨')
  2889. .replace(/¨D/g, '$')
  2890. // replace " and '
  2891. .replace(/["']/g, '-')
  2892. .toLowerCase();
  2893. } else {
  2894. title = title
  2895. .replace(/[^\w]/g, '')
  2896. .toLowerCase();
  2897. }
  2898. if (options.rawPrefixHeaderId) {
  2899. title = prefix + title;
  2900. }
  2901. if (globals.hashLinkCounts[title]) {
  2902. title = title + '-' + (globals.hashLinkCounts[title]++);
  2903. } else {
  2904. globals.hashLinkCounts[title] = 1;
  2905. }
  2906. return title;
  2907. }
  2908. text = globals.converter._dispatch('makehtml.headers.after', text, options, globals).getText();
  2909. return text;
  2910. });
  2911. /**
  2912. * Turn Markdown horizontal rule shortcuts into <hr /> tags.
  2913. *
  2914. * Any 3 or more unindented consecutive hyphens, asterisks or underscores with or without a space beetween them
  2915. * in a single line is considered a horizontal rule
  2916. */
  2917. showdown.subParser('makehtml.horizontalRule', function (text, options, globals) {
  2918. 'use strict';
  2919. text = globals.converter._dispatch('makehtml.horizontalRule.before', text, options, globals).getText();
  2920. var key = showdown.subParser('makehtml.hashBlock')('<hr />', options, globals);
  2921. text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
  2922. text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
  2923. text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
  2924. text = globals.converter._dispatch('makehtml.horizontalRule.after', text, options, globals).getText();
  2925. return text;
  2926. });
  2927. /**
  2928. * Turn Markdown image shortcuts into <img> tags.
  2929. */
  2930. showdown.subParser('makehtml.images', function (text, options, globals) {
  2931. 'use strict';
  2932. text = globals.converter._dispatch('makehtml.images.before', text, options, globals).getText();
  2933. var inlineRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<?([\S]+?(?:\([\S]*?\)[\S]*?)?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g,
  2934. crazyRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<([^>]*)>(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(?:(["'])([^"]*?)\6))?[ \t]?\)/g,
  2935. base64RegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<?(data:.+?\/.+?;base64,[A-Za-z0-9+/=\n]+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g,
  2936. referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[([\s\S]*?)]()()()()()/g,
  2937. refShortcutRegExp = /!\[([^\[\]]+)]()()()()()/g;
  2938. function writeImageTagBase64 (wholeMatch, altText, linkId, url, width, height, m5, title) {
  2939. url = url.replace(/\s/g, '');
  2940. return writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title);
  2941. }
  2942. function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
  2943. var gUrls = globals.gUrls,
  2944. gTitles = globals.gTitles,
  2945. gDims = globals.gDimensions;
  2946. linkId = linkId.toLowerCase();
  2947. if (!title) {
  2948. title = '';
  2949. }
  2950. // Special case for explicit empty url
  2951. if (wholeMatch.search(/\(<?\s*>? ?(['"].*['"])?\)$/m) > -1) {
  2952. url = '';
  2953. } else if (url === '' || url === null) {
  2954. if (linkId === '' || linkId === null) {
  2955. // lower-case and turn embedded newlines into spaces
  2956. linkId = altText.toLowerCase().replace(/ ?\n/g, ' ');
  2957. }
  2958. url = '#' + linkId;
  2959. if (!showdown.helper.isUndefined(gUrls[linkId])) {
  2960. url = gUrls[linkId];
  2961. if (!showdown.helper.isUndefined(gTitles[linkId])) {
  2962. title = gTitles[linkId];
  2963. }
  2964. if (!showdown.helper.isUndefined(gDims[linkId])) {
  2965. width = gDims[linkId].width;
  2966. height = gDims[linkId].height;
  2967. }
  2968. } else {
  2969. return wholeMatch;
  2970. }
  2971. }
  2972. altText = altText
  2973. .replace(/"/g, '&quot;')
  2974. //altText = showdown.helper.escapeCharacters(altText, '*_', false);
  2975. .replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  2976. //url = showdown.helper.escapeCharacters(url, '*_', false);
  2977. url = url.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  2978. var result = '<img src="' + url + '" alt="' + altText + '"';
  2979. if (title && showdown.helper.isString(title)) {
  2980. title = title
  2981. .replace(/"/g, '&quot;')
  2982. //title = showdown.helper.escapeCharacters(title, '*_', false);
  2983. .replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  2984. result += ' title="' + title + '"';
  2985. }
  2986. if (width && height) {
  2987. width = (width === '*') ? 'auto' : width;
  2988. height = (height === '*') ? 'auto' : height;
  2989. result += ' width="' + width + '"';
  2990. result += ' height="' + height + '"';
  2991. }
  2992. result += ' />';
  2993. return result;
  2994. }
  2995. // First, handle reference-style labeled images: ![alt text][id]
  2996. text = text.replace(referenceRegExp, writeImageTag);
  2997. // Next, handle inline images: ![alt text](url =<width>x<height> "optional title")
  2998. // base64 encoded images
  2999. text = text.replace(base64RegExp, writeImageTagBase64);
  3000. // cases with crazy urls like ./image/cat1).png
  3001. text = text.replace(crazyRegExp, writeImageTag);
  3002. // normal cases
  3003. text = text.replace(inlineRegExp, writeImageTag);
  3004. // handle reference-style shortcuts: ![img text]
  3005. text = text.replace(refShortcutRegExp, writeImageTag);
  3006. text = globals.converter._dispatch('makehtml.images.after', text, options, globals).getText();
  3007. return text;
  3008. });
  3009. showdown.subParser('makehtml.italicsAndBold', function (text, options, globals) {
  3010. 'use strict';
  3011. text = globals.converter._dispatch('makehtml.italicsAndBold.before', text, options, globals).getText();
  3012. // it's faster to have 3 separate regexes for each case than have just one
  3013. // because of backtracing, in some cases, it could lead to an exponential effect
  3014. // called "catastrophic backtrace". Ominous!
  3015. function parseInside (txt, left, right) {
  3016. return left + txt + right;
  3017. }
  3018. // Parse underscores
  3019. if (options.literalMidWordUnderscores) {
  3020. text = text.replace(/\b___(\S[\s\S]*?)___\b/g, function (wm, txt) {
  3021. return parseInside (txt, '<strong><em>', '</em></strong>');
  3022. });
  3023. text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) {
  3024. return parseInside (txt, '<strong>', '</strong>');
  3025. });
  3026. text = text.replace(/\b_(\S[\s\S]*?)_\b/g, function (wm, txt) {
  3027. return parseInside (txt, '<em>', '</em>');
  3028. });
  3029. } else {
  3030. text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) {
  3031. return (/\S$/.test(m)) ? parseInside (m, '<strong><em>', '</em></strong>') : wm;
  3032. });
  3033. text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) {
  3034. return (/\S$/.test(m)) ? parseInside (m, '<strong>', '</strong>') : wm;
  3035. });
  3036. text = text.replace(/_([^\s_][\s\S]*?)_/g, function (wm, m) {
  3037. // !/^_[^_]/.test(m) - test if it doesn't start with __ (since it seems redundant, we removed it)
  3038. return (/\S$/.test(m)) ? parseInside (m, '<em>', '</em>') : wm;
  3039. });
  3040. }
  3041. // Now parse asterisks
  3042. /*
  3043. if (options.literalMidWordAsterisks) {
  3044. text = text.replace(/([^*]|^)\B\*\*\*(\S[\s\S]+?)\*\*\*\B(?!\*)/g, function (wm, lead, txt) {
  3045. return parseInside (txt, lead + '<strong><em>', '</em></strong>');
  3046. });
  3047. text = text.replace(/([^*]|^)\B\*\*(\S[\s\S]+?)\*\*\B(?!\*)/g, function (wm, lead, txt) {
  3048. return parseInside (txt, lead + '<strong>', '</strong>');
  3049. });
  3050. text = text.replace(/([^*]|^)\B\*(\S[\s\S]+?)\*\B(?!\*)/g, function (wm, lead, txt) {
  3051. return parseInside (txt, lead + '<em>', '</em>');
  3052. });
  3053. } else {
  3054. */
  3055. text = text.replace(/\*\*\*(\S[\s\S]*?)\*\*\*/g, function (wm, m) {
  3056. return (/\S$/.test(m)) ? parseInside (m, '<strong><em>', '</em></strong>') : wm;
  3057. });
  3058. text = text.replace(/\*\*(\S[\s\S]*?)\*\*/g, function (wm, m) {
  3059. return (/\S$/.test(m)) ? parseInside (m, '<strong>', '</strong>') : wm;
  3060. });
  3061. text = text.replace(/\*([^\s*][\s\S]*?)\*/g, function (wm, m) {
  3062. // !/^\*[^*]/.test(m) - test if it doesn't start with ** (since it seems redundant, we removed it)
  3063. return (/\S$/.test(m)) ? parseInside (m, '<em>', '</em>') : wm;
  3064. });
  3065. //}
  3066. text = globals.converter._dispatch('makehtml.italicsAndBold.after', text, options, globals).getText();
  3067. return text;
  3068. });
  3069. ////
  3070. // makehtml/links.js
  3071. // Copyright (c) 2018 ShowdownJS
  3072. //
  3073. // Transforms MD links into `<a>` html anchors
  3074. //
  3075. // A link contains link text (the visible text), a link destination (the URI that is the link destination), and
  3076. // optionally a link title. There are two basic kinds of links in Markdown.
  3077. // In inline links the destination and title are given immediately after the link text.
  3078. // In reference links the destination and title are defined elsewhere in the document.
  3079. //
  3080. // ***Author:***
  3081. // - Estevão Soares dos Santos (Tivie) <https://github.com/tivie>
  3082. ////
  3083. (function () {
  3084. /**
  3085. * Helper function: Wrapper function to pass as second replace parameter
  3086. *
  3087. * @param {RegExp} rgx
  3088. * @param {string} evtRootName
  3089. * @param {{}} options
  3090. * @param {{}} globals
  3091. * @returns {Function}
  3092. */
  3093. function replaceAnchorTag (rgx, evtRootName, options, globals, emptyCase) {
  3094. emptyCase = !!emptyCase;
  3095. return function (wholeMatch, text, id, url, m5, m6, title) {
  3096. // bail we we find 2 newlines somewhere
  3097. if (/\n\n/.test(wholeMatch)) {
  3098. return wholeMatch;
  3099. }
  3100. var evt = createEvent(rgx, evtRootName + '.captureStart', wholeMatch, text, id, url, title, options, globals);
  3101. return writeAnchorTag(evt, options, globals, emptyCase);
  3102. };
  3103. }
  3104. /**
  3105. * TODO Normalize this
  3106. * Helper function: Create a capture event
  3107. * @param {RegExp} rgx
  3108. * @param {String} evtName Event name
  3109. * @param {String} wholeMatch
  3110. * @param {String} text
  3111. * @param {String} id
  3112. * @param {String} url
  3113. * @param {String} title
  3114. * @param {{}} options
  3115. * @param {{}} globals
  3116. * @returns {showdown.helper.Event|*}
  3117. */
  3118. function createEvent (rgx, evtName, wholeMatch, text, id, url, title, options, globals) {
  3119. return globals.converter._dispatch(evtName, wholeMatch, options, globals, {
  3120. regexp: rgx,
  3121. matches: {
  3122. wholeMatch: wholeMatch,
  3123. text: text,
  3124. id: id,
  3125. url: url,
  3126. title: title
  3127. }
  3128. });
  3129. }
  3130. /**
  3131. * Helper Function: Normalize and write an anchor tag based on passed parameters
  3132. * @param evt
  3133. * @param options
  3134. * @param globals
  3135. * @param {boolean} emptyCase
  3136. * @returns {string}
  3137. */
  3138. function writeAnchorTag (evt, options, globals, emptyCase) {
  3139. var wholeMatch = evt.getMatches().wholeMatch;
  3140. var text = evt.getMatches().text;
  3141. var id = evt.getMatches().id;
  3142. var url = evt.getMatches().url;
  3143. var title = evt.getMatches().title;
  3144. var target = '';
  3145. if (!title) {
  3146. title = '';
  3147. }
  3148. id = (id) ? id.toLowerCase() : '';
  3149. if (emptyCase) {
  3150. url = '';
  3151. } else if (!url) {
  3152. if (!id) {
  3153. // lower-case and turn embedded newlines into spaces
  3154. id = text.toLowerCase().replace(/ ?\n/g, ' ');
  3155. }
  3156. url = '#' + id;
  3157. if (!showdown.helper.isUndefined(globals.gUrls[id])) {
  3158. url = globals.gUrls[id];
  3159. if (!showdown.helper.isUndefined(globals.gTitles[id])) {
  3160. title = globals.gTitles[id];
  3161. }
  3162. } else {
  3163. return wholeMatch;
  3164. }
  3165. }
  3166. //url = showdown.helper.escapeCharacters(url, '*_:~', false); // replaced line to improve performance
  3167. url = url.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  3168. if (title !== '' && title !== null) {
  3169. title = title.replace(/"/g, '&quot;');
  3170. //title = showdown.helper.escapeCharacters(title, '*_', false); // replaced line to improve performance
  3171. title = title.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  3172. title = ' title="' + title + '"';
  3173. }
  3174. // optionLinksInNewWindow only applies
  3175. // to external links. Hash links (#) open in same page
  3176. if (options.openLinksInNewWindow && !/^#/.test(url)) {
  3177. // escaped _
  3178. target = ' target="¨E95Eblank"';
  3179. }
  3180. // Text can be a markdown element, so we run through the appropriate parsers
  3181. text = showdown.subParser('makehtml.codeSpans')(text, options, globals);
  3182. text = showdown.subParser('makehtml.emoji')(text, options, globals);
  3183. text = showdown.subParser('makehtml.underline')(text, options, globals);
  3184. text = showdown.subParser('makehtml.italicsAndBold')(text, options, globals);
  3185. text = showdown.subParser('makehtml.strikethrough')(text, options, globals);
  3186. text = showdown.subParser('makehtml.ellipsis')(text, options, globals);
  3187. text = showdown.subParser('makehtml.hashHTMLSpans')(text, options, globals);
  3188. //evt = createEvent(rgx, evtRootName + '.captureEnd', wholeMatch, text, id, url, title, options, globals);
  3189. var result = '<a href="' + url + '"' + title + target + '>' + text + '</a>';
  3190. //evt = createEvent(rgx, evtRootName + '.beforeHash', wholeMatch, text, id, url, title, options, globals);
  3191. result = showdown.subParser('makehtml.hashHTMLSpans')(result, options, globals);
  3192. return result;
  3193. }
  3194. var evtRootName = 'makehtml.links';
  3195. /**
  3196. * Turn Markdown link shortcuts into XHTML <a> tags.
  3197. */
  3198. showdown.subParser('makehtml.links', function (text, options, globals) {
  3199. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3200. // 1. Handle reference-style links: [link text] [id]
  3201. text = showdown.subParser('makehtml.links.reference')(text, options, globals);
  3202. // 2. Handle inline-style links: [link text](url "optional title")
  3203. text = showdown.subParser('makehtml.links.inline')(text, options, globals);
  3204. // 3. Handle reference-style shortcuts: [link text]
  3205. // These must come last in case there's a [link text][1] or [link text](/foo)
  3206. text = showdown.subParser('makehtml.links.referenceShortcut')(text, options, globals);
  3207. // 4. Handle angle brackets links -> `<http://example.com/>`
  3208. // Must come after links, because you can use < and > delimiters in inline links like [this](<url>).
  3209. text = showdown.subParser('makehtml.links.angleBrackets')(text, options, globals);
  3210. // 5. Handle GithubMentions (if option is enabled)
  3211. text = showdown.subParser('makehtml.links.ghMentions')(text, options, globals);
  3212. // 6. Handle <a> tags and img tags
  3213. text = text.replace(/<a\s[^>]*>[\s\S]*<\/a>/g, function (wholeMatch) {
  3214. return showdown.helper._hashHTMLSpan(wholeMatch, globals);
  3215. });
  3216. text = text.replace(/<img\s[^>]*\/?>/g, function (wholeMatch) {
  3217. return showdown.helper._hashHTMLSpan(wholeMatch, globals);
  3218. });
  3219. // 7. Handle naked links (if option is enabled)
  3220. text = showdown.subParser('makehtml.links.naked')(text, options, globals);
  3221. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3222. return text;
  3223. });
  3224. /**
  3225. * TODO WRITE THIS DOCUMENTATION
  3226. */
  3227. showdown.subParser('makehtml.links.inline', function (text, options, globals) {
  3228. var evtRootName = evtRootName + '.inline';
  3229. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3230. // 1. Look for empty cases: []() and [empty]() and []("title")
  3231. var rgxEmpty = /\[(.*?)]()()()()\(<? ?>? ?(?:["'](.*)["'])?\)/g;
  3232. text = text.replace(rgxEmpty, replaceAnchorTag(rgxEmpty, evtRootName, options, globals, true));
  3233. // 2. Look for cases with crazy urls like ./image/cat1).png
  3234. var rgxCrazy = /\[((?:\[[^\]]*]|[^\[\]])*)]()\s?\([ \t]?<([^>]*)>(?:[ \t]*((["'])([^"]*?)\5))?[ \t]?\)/g;
  3235. text = text.replace(rgxCrazy, replaceAnchorTag(rgxCrazy, evtRootName, options, globals));
  3236. // 3. inline links with no title or titles wrapped in ' or ":
  3237. // [text](url.com) || [text](<url.com>) || [text](url.com "title") || [text](<url.com> "title")
  3238. //var rgx2 = /\[[ ]*[\s]?[ ]*([^\n\[\]]*?)[ ]*[\s]?[ ]*] ?()\(<?[ ]*[\s]?[ ]*([^\s'"]*)>?(?:[ ]*[\n]?[ ]*()(['"])(.*?)\5)?[ ]*[\s]?[ ]*\)/; // this regex is too slow!!!
  3239. var rgx2 = /\[([\S ]*?)]\s?()\( *<?([^\s'"]*?(?:\([\S]*?\)[\S]*?)?)>?\s*(?:()(['"])(.*?)\5)? *\)/g;
  3240. text = text.replace(rgx2, replaceAnchorTag(rgx2, evtRootName, options, globals));
  3241. // 4. inline links with titles wrapped in (): [foo](bar.com (title))
  3242. var rgx3 = /\[([\S ]*?)]\s?()\( *<?([^\s'"]*?(?:\([\S]*?\)[\S]*?)?)>?\s+()()\((.*?)\) *\)/g;
  3243. text = text.replace(rgx3, replaceAnchorTag(rgx3, evtRootName, options, globals));
  3244. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3245. return text;
  3246. });
  3247. /**
  3248. * TODO WRITE THIS DOCUMENTATION
  3249. */
  3250. showdown.subParser('makehtml.links.reference', function (text, options, globals) {
  3251. var evtRootName = evtRootName + '.reference';
  3252. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3253. var rgx = /\[((?:\[[^\]]*]|[^\[\]])*)] ?(?:\n *)?\[(.*?)]()()()()/g;
  3254. text = text.replace(rgx, replaceAnchorTag(rgx, evtRootName, options, globals));
  3255. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3256. return text;
  3257. });
  3258. /**
  3259. * TODO WRITE THIS DOCUMENTATION
  3260. */
  3261. showdown.subParser('makehtml.links.referenceShortcut', function (text, options, globals) {
  3262. var evtRootName = evtRootName + '.referenceShortcut';
  3263. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3264. var rgx = /\[([^\[\]]+)]()()()()()/g;
  3265. text = text.replace(rgx, replaceAnchorTag(rgx, evtRootName, options, globals));
  3266. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3267. return text;
  3268. });
  3269. /**
  3270. * TODO WRITE THIS DOCUMENTATION
  3271. */
  3272. showdown.subParser('makehtml.links.ghMentions', function (text, options, globals) {
  3273. var evtRootName = evtRootName + 'ghMentions';
  3274. if (!options.ghMentions) {
  3275. return text;
  3276. }
  3277. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3278. var rgx = /(^|\s)(\\)?(@([a-z\d]+(?:[a-z\d._-]+?[a-z\d]+)*))/gi;
  3279. text = text.replace(rgx, function (wholeMatch, st, escape, mentions, username) {
  3280. // bail if the mentions was escaped
  3281. if (escape === '\\') {
  3282. return st + mentions;
  3283. }
  3284. // check if options.ghMentionsLink is a string
  3285. // TODO Validation should be done at initialization not at runtime
  3286. if (!showdown.helper.isString(options.ghMentionsLink)) {
  3287. throw new Error('ghMentionsLink option must be a string');
  3288. }
  3289. var url = options.ghMentionsLink.replace(/{u}/g, username);
  3290. var evt = createEvent(rgx, evtRootName + '.captureStart', wholeMatch, mentions, null, url, null, options, globals);
  3291. // captureEnd Event is triggered inside writeAnchorTag function
  3292. return st + writeAnchorTag(evt, options, globals);
  3293. });
  3294. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3295. return text;
  3296. });
  3297. /**
  3298. * TODO WRITE THIS DOCUMENTATION
  3299. */
  3300. showdown.subParser('makehtml.links.angleBrackets', function (text, options, globals) {
  3301. var evtRootName = 'makehtml.links.angleBrackets';
  3302. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3303. // 1. Parse links first
  3304. var urlRgx = /<(((?:https?|ftp):\/\/|www\.)[^'">\s]+)>/gi;
  3305. text = text.replace(urlRgx, function (wholeMatch, url, urlStart) {
  3306. var text = url;
  3307. url = (urlStart === 'www.') ? 'http://' + url : url;
  3308. var evt = createEvent(urlRgx, evtRootName + '.captureStart', wholeMatch, text, null, url, null, options, globals);
  3309. return writeAnchorTag(evt, options, globals);
  3310. });
  3311. // 2. Then Mail Addresses
  3312. var mailRgx = /<(?:mailto:)?([-.\w]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi;
  3313. text = text.replace(mailRgx, function (wholeMatch, mail) {
  3314. var url = 'mailto:';
  3315. mail = showdown.subParser('makehtml.unescapeSpecialChars')(mail, options, globals);
  3316. if (options.encodeEmails) {
  3317. url = showdown.helper.encodeEmailAddress(url + mail);
  3318. mail = showdown.helper.encodeEmailAddress(mail);
  3319. } else {
  3320. url = url + mail;
  3321. }
  3322. var evt = createEvent(mailRgx, evtRootName + '.captureStart', wholeMatch, mail, null, url, null, options, globals);
  3323. return writeAnchorTag(evt, options, globals);
  3324. });
  3325. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3326. return text;
  3327. });
  3328. /**
  3329. * TODO MAKE THIS WORK (IT'S NOT ACTIVATED)
  3330. * TODO WRITE THIS DOCUMENTATION
  3331. */
  3332. showdown.subParser('makehtml.links.naked', function (text, options, globals) {
  3333. if (!options.simplifiedAutoLink) {
  3334. return text;
  3335. }
  3336. var evtRootName = 'makehtml.links.naked';
  3337. text = globals.converter._dispatch(evtRootName + '.start', text, options, globals).getText();
  3338. // 2. Now we check for
  3339. // we also include leading markdown magic chars [_*~] for cases like __https://www.google.com/foobar__
  3340. var urlRgx = /([_*~]*?)(((?:https?|ftp):\/\/|www\.)[^\s<>"'`´.-][^\s<>"'`´]*?\.[a-z\d.]+[^\s<>"']*)\1/gi;
  3341. text = text.replace(urlRgx, function (wholeMatch, leadingMDChars, url, urlPrefix) {
  3342. // we now will start traversing the url from the front to back, looking for punctuation chars [_*~,;:.!?\)\]]
  3343. var len = url.length;
  3344. var suffix = '';
  3345. for (var i = len - 1; i >= 0; --i) {
  3346. var char = url.charAt(i);
  3347. if (/[_*~,;:.!?]/.test(char)) {
  3348. // it's a punctuation char
  3349. // we remove it from the url
  3350. url = url.slice(0, -1);
  3351. // and prepend it to the suffix
  3352. suffix = char + suffix;
  3353. } else if (/\)/.test(char)) {
  3354. var opPar = url.match(/\(/g) || [];
  3355. var clPar = url.match(/\)/g);
  3356. // it's a curved parenthesis so we need to check for "balance" (kinda)
  3357. if (opPar.length < clPar.length) {
  3358. // there are more closing Parenthesis than opening so chop it!!!!!
  3359. url = url.slice(0, -1);
  3360. // and prepend it to the suffix
  3361. suffix = char + suffix;
  3362. } else {
  3363. // it's (kinda) balanced so our work is done
  3364. break;
  3365. }
  3366. } else if (/]/.test(char)) {
  3367. var opPar2 = url.match(/\[/g) || [];
  3368. var clPar2 = url.match(/\]/g);
  3369. // it's a squared parenthesis so we need to check for "balance" (kinda)
  3370. if (opPar2.length < clPar2.length) {
  3371. // there are more closing Parenthesis than opening so chop it!!!!!
  3372. url = url.slice(0, -1);
  3373. // and prepend it to the suffix
  3374. suffix = char + suffix;
  3375. } else {
  3376. // it's (kinda) balanced so our work is done
  3377. break;
  3378. }
  3379. } else {
  3380. // it's not a punctuation or a parenthesis so our work is done
  3381. break;
  3382. }
  3383. }
  3384. // we copy the treated url to the text variable
  3385. var text = url;
  3386. // finally, if it's a www shortcut, we prepend http
  3387. url = (urlPrefix === 'www.') ? 'http://' + url : url;
  3388. // url part is done so let's take care of text now
  3389. // we need to escape the text (because of links such as www.example.com/foo__bar__baz)
  3390. text = text.replace(showdown.helper.regexes.asteriskDashTildeAndColon, showdown.helper.escapeCharactersCallback);
  3391. // finally we dispatch the event
  3392. var evt = createEvent(urlRgx, evtRootName + '.captureStart', wholeMatch, text, null, url, null, options, globals);
  3393. // and return the link tag, with the leadingMDChars and suffix. The leadingMDChars are added at the end too because
  3394. // we consumed those characters in the regexp
  3395. return leadingMDChars + writeAnchorTag(evt, options, globals) + suffix + leadingMDChars;
  3396. });
  3397. // 2. Then mails
  3398. var mailRgx = /(^|\s)(?:mailto:)?([A-Za-z0-9!#$%&'*+-/=?^_`{|}~.]+@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)(?=$|\s)/gmi;
  3399. text = text.replace(mailRgx, function (wholeMatch, leadingChar, mail) {
  3400. var url = 'mailto:';
  3401. mail = showdown.subParser('makehtml.unescapeSpecialChars')(mail, options, globals);
  3402. if (options.encodeEmails) {
  3403. url = showdown.helper.encodeEmailAddress(url + mail);
  3404. mail = showdown.helper.encodeEmailAddress(mail);
  3405. } else {
  3406. url = url + mail;
  3407. }
  3408. var evt = createEvent(mailRgx, evtRootName + '.captureStart', wholeMatch, mail, null, url, null, options, globals);
  3409. return leadingChar + writeAnchorTag(evt, options, globals);
  3410. });
  3411. text = globals.converter._dispatch(evtRootName + '.end', text, options, globals).getText();
  3412. return text;
  3413. });
  3414. })();
  3415. /**
  3416. * Form HTML ordered (numbered) and unordered (bulleted) lists.
  3417. */
  3418. showdown.subParser('makehtml.lists', function (text, options, globals) {
  3419. 'use strict';
  3420. /**
  3421. * Process the contents of a single ordered or unordered list, splitting it
  3422. * into individual list items.
  3423. * @param {string} listStr
  3424. * @param {boolean} trimTrailing
  3425. * @returns {string}
  3426. */
  3427. function processListItems (listStr, trimTrailing) {
  3428. // The $g_list_level global keeps track of when we're inside a list.
  3429. // Each time we enter a list, we increment it; when we leave a list,
  3430. // we decrement. If it's zero, we're not in a list anymore.
  3431. //
  3432. // We do this because when we're not inside a list, we want to treat
  3433. // something like this:
  3434. //
  3435. // I recommend upgrading to version
  3436. // 8. Oops, now this line is treated
  3437. // as a sub-list.
  3438. //
  3439. // As a single paragraph, despite the fact that the second line starts
  3440. // with a digit-period-space sequence.
  3441. //
  3442. // Whereas when we're inside a list (or sub-list), that line will be
  3443. // treated as the start of a sub-list. What a kludge, huh? This is
  3444. // an aspect of Markdown's syntax that's hard to parse perfectly
  3445. // without resorting to mind-reading. Perhaps the solution is to
  3446. // change the syntax rules such that sub-lists must start with a
  3447. // starting cardinal number; e.g. "1." or "a.".
  3448. globals.gListLevel++;
  3449. // trim trailing blank lines:
  3450. listStr = listStr.replace(/\n{2,}$/, '\n');
  3451. // attacklab: add sentinel to emulate \z
  3452. listStr += '¨0';
  3453. var rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0| {0,3}([*+-]|\d+[.])[ \t]+))/gm,
  3454. isParagraphed = (/\n[ \t]*\n(?!¨0)/.test(listStr));
  3455. // Since version 1.5, nesting sublists requires 4 spaces (or 1 tab) indentation,
  3456. // which is a syntax breaking change
  3457. // activating this option reverts to old behavior
  3458. // This will be removed in version 2.0
  3459. if (options.disableForced4SpacesIndentedSublists) {
  3460. rgx = /(\n)?(^ {0,3})([*+-]|\d+[.])[ \t]+((\[(x|X| )?])?[ \t]*[^\r]+?(\n{1,2}))(?=\n*(¨0|\2([*+-]|\d+[.])[ \t]+))/gm;
  3461. }
  3462. listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) {
  3463. checked = (checked && checked.trim() !== '');
  3464. var item = showdown.subParser('makehtml.outdent')(m4, options, globals),
  3465. bulletStyle = '';
  3466. // Support for github tasklists
  3467. if (taskbtn && options.tasklists) {
  3468. bulletStyle = ' class="task-list-item" style="list-style-type: none;"';
  3469. item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () {
  3470. var otp = '<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"';
  3471. if (checked) {
  3472. otp += ' checked';
  3473. }
  3474. otp += '>';
  3475. return otp;
  3476. });
  3477. }
  3478. // ISSUE #312
  3479. // This input: - - - a
  3480. // causes trouble to the parser, since it interprets it as:
  3481. // <ul><li><li><li>a</li></li></li></ul>
  3482. // instead of:
  3483. // <ul><li>- - a</li></ul>
  3484. // So, to prevent it, we will put a marker (¨A)in the beginning of the line
  3485. // Kind of hackish/monkey patching, but seems more effective than overcomplicating the list parser
  3486. item = item.replace(/^([-*+]|\d\.)[ \t]+[\S\n ]*/g, function (wm2) {
  3487. return '¨A' + wm2;
  3488. });
  3489. // SPECIAL CASE: an heading followed by a paragraph of text that is not separated by a double newline
  3490. // or/nor indented. ex:
  3491. //
  3492. // - # foo
  3493. // bar is great
  3494. //
  3495. // While this does now follow the spec per se, not allowing for this might cause confusion since
  3496. // header blocks don't need double newlines after
  3497. if (/^#+.+\n.+/.test(item)) {
  3498. item = item.replace(/^(#+.+)$/m, '$1\n');
  3499. }
  3500. // m1 - Leading line or
  3501. // Has a double return (multi paragraph)
  3502. if (m1 || (item.search(/\n{2,}/) > -1)) {
  3503. item = showdown.subParser('makehtml.githubCodeBlocks')(item, options, globals);
  3504. item = showdown.subParser('makehtml.blockGamut')(item, options, globals);
  3505. } else {
  3506. // Recursion for sub-lists:
  3507. item = showdown.subParser('makehtml.lists')(item, options, globals);
  3508. item = item.replace(/\n$/, ''); // chomp(item)
  3509. item = showdown.subParser('makehtml.hashHTMLBlocks')(item, options, globals);
  3510. // Colapse double linebreaks
  3511. item = item.replace(/\n\n+/g, '\n\n');
  3512. if (isParagraphed) {
  3513. item = showdown.subParser('makehtml.paragraphs')(item, options, globals);
  3514. } else {
  3515. item = showdown.subParser('makehtml.spanGamut')(item, options, globals);
  3516. }
  3517. }
  3518. // now we need to remove the marker (¨A)
  3519. item = item.replace('¨A', '');
  3520. // we can finally wrap the line in list item tags
  3521. item = '<li' + bulletStyle + '>' + item + '</li>\n';
  3522. return item;
  3523. });
  3524. // attacklab: strip sentinel
  3525. listStr = listStr.replace(/¨0/g, '');
  3526. globals.gListLevel--;
  3527. if (trimTrailing) {
  3528. listStr = listStr.replace(/\s+$/, '');
  3529. }
  3530. return listStr;
  3531. }
  3532. function styleStartNumber (list, listType) {
  3533. // check if ol and starts by a number different than 1
  3534. if (listType === 'ol') {
  3535. var res = list.match(/^ *(\d+)\./);
  3536. if (res && res[1] !== '1') {
  3537. return ' start="' + res[1] + '"';
  3538. }
  3539. }
  3540. return '';
  3541. }
  3542. /**
  3543. * Check and parse consecutive lists (better fix for issue #142)
  3544. * @param {string} list
  3545. * @param {string} listType
  3546. * @param {boolean} trimTrailing
  3547. * @returns {string}
  3548. */
  3549. function parseConsecutiveLists (list, listType, trimTrailing) {
  3550. // check if we caught 2 or more consecutive lists by mistake
  3551. // we use the counterRgx, meaning if listType is UL we look for OL and vice versa
  3552. var olRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?\d+\.[ \t]/gm : /^ {0,3}\d+\.[ \t]/gm,
  3553. ulRgx = (options.disableForced4SpacesIndentedSublists) ? /^ ?[*+-][ \t]/gm : /^ {0,3}[*+-][ \t]/gm,
  3554. counterRxg = (listType === 'ul') ? olRgx : ulRgx,
  3555. result = '';
  3556. if (list.search(counterRxg) !== -1) {
  3557. (function parseCL (txt) {
  3558. var pos = txt.search(counterRxg),
  3559. style = styleStartNumber(list, listType);
  3560. if (pos !== -1) {
  3561. // slice
  3562. result += '\n\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';
  3563. // invert counterType and listType
  3564. listType = (listType === 'ul') ? 'ol' : 'ul';
  3565. counterRxg = (listType === 'ul') ? olRgx : ulRgx;
  3566. //recurse
  3567. parseCL(txt.slice(pos));
  3568. } else {
  3569. result += '\n\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
  3570. }
  3571. })(list);
  3572. } else {
  3573. var style = styleStartNumber(list, listType);
  3574. result = '\n\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
  3575. }
  3576. return result;
  3577. }
  3578. // Start of list parsing
  3579. var subListRgx = /^(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
  3580. var mainListRgx = /(\n\n|^\n?)(( {0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(¨0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
  3581. text = globals.converter._dispatch('lists.before', text, options, globals).getText();
  3582. // add sentinel to hack around khtml/safari bug:
  3583. // http://bugs.webkit.org/show_bug.cgi?id=11231
  3584. text += '¨0';
  3585. if (globals.gListLevel) {
  3586. text = text.replace(subListRgx, function (wholeMatch, list, m2) {
  3587. var listType = (m2.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
  3588. return parseConsecutiveLists(list, listType, true);
  3589. });
  3590. } else {
  3591. text = text.replace(mainListRgx, function (wholeMatch, m1, list, m3) {
  3592. var listType = (m3.search(/[*+-]/g) > -1) ? 'ul' : 'ol';
  3593. return parseConsecutiveLists(list, listType, false);
  3594. });
  3595. }
  3596. // strip sentinel
  3597. text = text.replace(/¨0/, '');
  3598. text = globals.converter._dispatch('makehtml.lists.after', text, options, globals).getText();
  3599. return text;
  3600. });
  3601. /**
  3602. * Parse metadata at the top of the document
  3603. */
  3604. showdown.subParser('makehtml.metadata', function (text, options, globals) {
  3605. 'use strict';
  3606. if (!options.metadata) {
  3607. return text;
  3608. }
  3609. text = globals.converter._dispatch('makehtml.metadata.before', text, options, globals).getText();
  3610. function parseMetadataContents (content) {
  3611. // raw is raw so it's not changed in any way
  3612. globals.metadata.raw = content;
  3613. // escape chars forbidden in html attributes
  3614. // double quotes
  3615. content = content
  3616. // ampersand first
  3617. .replace(/&/g, '&amp;')
  3618. // double quotes
  3619. .replace(/"/g, '&quot;');
  3620. content = content.replace(/\n {4}/g, ' ');
  3621. content.replace(/^([\S ]+): +([\s\S]+?)$/gm, function (wm, key, value) {
  3622. globals.metadata.parsed[key] = value;
  3623. return '';
  3624. });
  3625. }
  3626. text = text.replace(/^\s*«««+(\S*?)\n([\s\S]+?)\n»»»+\n/, function (wholematch, format, content) {
  3627. parseMetadataContents(content);
  3628. return '¨M';
  3629. });
  3630. text = text.replace(/^\s*---+(\S*?)\n([\s\S]+?)\n---+\n/, function (wholematch, format, content) {
  3631. if (format) {
  3632. globals.metadata.format = format;
  3633. }
  3634. parseMetadataContents(content);
  3635. return '¨M';
  3636. });
  3637. text = text.replace(/¨M/g, '');
  3638. text = globals.converter._dispatch('makehtml.metadata.after', text, options, globals).getText();
  3639. return text;
  3640. });
  3641. /**
  3642. * Remove one level of line-leading tabs or spaces
  3643. */
  3644. showdown.subParser('makehtml.outdent', function (text, options, globals) {
  3645. 'use strict';
  3646. text = globals.converter._dispatch('makehtml.outdent.before', text, options, globals).getText();
  3647. // attacklab: hack around Konqueror 3.5.4 bug:
  3648. // "----------bug".replace(/^-/g,"") == "bug"
  3649. text = text.replace(/^(\t|[ ]{1,4})/gm, '¨0'); // attacklab: g_tab_width
  3650. // attacklab: clean up hack
  3651. text = text.replace(/¨0/g, '');
  3652. text = globals.converter._dispatch('makehtml.outdent.after', text, options, globals).getText();
  3653. return text;
  3654. });
  3655. /**
  3656. *
  3657. */
  3658. showdown.subParser('makehtml.paragraphs', function (text, options, globals) {
  3659. 'use strict';
  3660. text = globals.converter._dispatch('makehtml.paragraphs.before', text, options, globals).getText();
  3661. // Strip leading and trailing lines:
  3662. text = text.replace(/^\n+/g, '');
  3663. text = text.replace(/\n+$/g, '');
  3664. var grafs = text.split(/\n{2,}/g),
  3665. grafsOut = [],
  3666. end = grafs.length; // Wrap <p> tags
  3667. for (var i = 0; i < end; i++) {
  3668. var str = grafs[i];
  3669. // if this is an HTML marker, copy it
  3670. if (str.search(/¨(K|G)(\d+)\1/g) >= 0) {
  3671. grafsOut.push(str);
  3672. // test for presence of characters to prevent empty lines being parsed
  3673. // as paragraphs (resulting in undesired extra empty paragraphs)
  3674. } else if (str.search(/\S/) >= 0) {
  3675. str = showdown.subParser('makehtml.spanGamut')(str, options, globals);
  3676. str = str.replace(/^([ \t]*)/g, '<p>');
  3677. str += '</p>';
  3678. grafsOut.push(str);
  3679. }
  3680. }
  3681. /** Unhashify HTML blocks */
  3682. end = grafsOut.length;
  3683. for (i = 0; i < end; i++) {
  3684. var blockText = '',
  3685. grafsOutIt = grafsOut[i],
  3686. codeFlag = false;
  3687. // if this is a marker for an html block...
  3688. // use RegExp.test instead of string.search because of QML bug
  3689. while (/¨(K|G)(\d+)\1/.test(grafsOutIt)) {
  3690. var delim = RegExp.$1,
  3691. num = RegExp.$2;
  3692. if (delim === 'K') {
  3693. blockText = globals.gHtmlBlocks[num];
  3694. } else {
  3695. // we need to check if ghBlock is a false positive
  3696. if (codeFlag) {
  3697. // use encoded version of all text
  3698. blockText = showdown.subParser('makehtml.encodeCode')(globals.ghCodeBlocks[num].text, options, globals);
  3699. } else {
  3700. blockText = globals.ghCodeBlocks[num].codeblock;
  3701. }
  3702. }
  3703. blockText = blockText.replace(/\$/g, '$$$$'); // Escape any dollar signs
  3704. grafsOutIt = grafsOutIt.replace(/(\n\n)?¨(K|G)\d+\2(\n\n)?/, blockText);
  3705. // Check if grafsOutIt is a pre->code
  3706. if (/^<pre\b[^>]*>\s*<code\b[^>]*>/.test(grafsOutIt)) {
  3707. codeFlag = true;
  3708. }
  3709. }
  3710. grafsOut[i] = grafsOutIt;
  3711. }
  3712. text = grafsOut.join('\n');
  3713. // Strip leading and trailing lines:
  3714. text = text.replace(/^\n+/g, '');
  3715. text = text.replace(/\n+$/g, '');
  3716. return globals.converter._dispatch('makehtml.paragraphs.after', text, options, globals).getText();
  3717. });
  3718. /**
  3719. * Run extension
  3720. */
  3721. showdown.subParser('makehtml.runExtension', function (ext, text, options, globals) {
  3722. 'use strict';
  3723. if (ext.filter) {
  3724. text = ext.filter(text, globals.converter, options);
  3725. } else if (ext.regex) {
  3726. // TODO remove this when old extension loading mechanism is deprecated
  3727. var re = ext.regex;
  3728. if (!(re instanceof RegExp)) {
  3729. re = new RegExp(re, 'g');
  3730. }
  3731. text = text.replace(re, ext.replace);
  3732. }
  3733. return text;
  3734. });
  3735. /**
  3736. * These are all the transformations that occur *within* block-level
  3737. * tags like paragraphs, headers, and list items.
  3738. */
  3739. showdown.subParser('makehtml.spanGamut', function (text, options, globals) {
  3740. 'use strict';
  3741. text = globals.converter._dispatch('makehtml.span.before', text, options, globals).getText();
  3742. text = showdown.subParser('makehtml.codeSpans')(text, options, globals);
  3743. text = showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes')(text, options, globals);
  3744. text = showdown.subParser('makehtml.encodeBackslashEscapes')(text, options, globals);
  3745. // Process link and image tags. Images must come first,
  3746. // because ![foo][f] looks like a link.
  3747. text = showdown.subParser('makehtml.images')(text, options, globals);
  3748. text = globals.converter._dispatch('smakehtml.links.before', text, options, globals).getText();
  3749. text = showdown.subParser('makehtml.links')(text, options, globals);
  3750. text = globals.converter._dispatch('smakehtml.links.after', text, options, globals).getText();
  3751. //text = showdown.subParser('makehtml.autoLinks')(text, options, globals);
  3752. //text = showdown.subParser('makehtml.simplifiedAutoLinks')(text, options, globals);
  3753. text = showdown.subParser('makehtml.emoji')(text, options, globals);
  3754. text = showdown.subParser('makehtml.underline')(text, options, globals);
  3755. text = showdown.subParser('makehtml.italicsAndBold')(text, options, globals);
  3756. text = showdown.subParser('makehtml.strikethrough')(text, options, globals);
  3757. text = showdown.subParser('makehtml.ellipsis')(text, options, globals);
  3758. // we need to hash HTML tags inside spans
  3759. text = showdown.subParser('makehtml.hashHTMLSpans')(text, options, globals);
  3760. // now we encode amps and angles
  3761. text = showdown.subParser('makehtml.encodeAmpsAndAngles')(text, options, globals);
  3762. // Do hard breaks
  3763. if (options.simpleLineBreaks) {
  3764. // GFM style hard breaks
  3765. // only add line breaks if the text does not contain a block (special case for lists)
  3766. if (!/\n\n¨K/.test(text)) {
  3767. text = text.replace(/\n+/g, '<br />\n');
  3768. }
  3769. } else {
  3770. // Vanilla hard breaks
  3771. text = text.replace(/ +\n/g, '<br />\n');
  3772. }
  3773. text = globals.converter._dispatch('makehtml.spanGamut.after', text, options, globals).getText();
  3774. return text;
  3775. });
  3776. showdown.subParser('makehtml.strikethrough', function (text, options, globals) {
  3777. 'use strict';
  3778. if (options.strikethrough) {
  3779. text = globals.converter._dispatch('makehtml.strikethrough.before', text, options, globals).getText();
  3780. text = text.replace(/(?:~){2}([\s\S]+?)(?:~){2}/g, function (wm, txt) { return '<del>' + txt + '</del>'; });
  3781. text = globals.converter._dispatch('makehtml.strikethrough.after', text, options, globals).getText();
  3782. }
  3783. return text;
  3784. });
  3785. /**
  3786. * Strips link definitions from text, stores the URLs and titles in
  3787. * hash references.
  3788. * Link defs are in the form: ^[id]: url "optional title"
  3789. */
  3790. showdown.subParser('makehtml.stripLinkDefinitions', function (text, options, globals) {
  3791. 'use strict';
  3792. var regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?([^>\s]+)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=¨0))/gm,
  3793. base64Regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?(data:.+?\/.+?;base64,[A-Za-z0-9+/=\n]+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n\n|(?=¨0)|(?=\n\[))/gm;
  3794. // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
  3795. text += '¨0';
  3796. var replaceFunc = function (wholeMatch, linkId, url, width, height, blankLines, title) {
  3797. linkId = linkId.toLowerCase();
  3798. if (url.match(/^data:.+?\/.+?;base64,/)) {
  3799. // remove newlines
  3800. globals.gUrls[linkId] = url.replace(/\s/g, '');
  3801. } else {
  3802. globals.gUrls[linkId] = showdown.subParser('makehtml.encodeAmpsAndAngles')(url, options, globals); // Link IDs are case-insensitive
  3803. }
  3804. if (blankLines) {
  3805. // Oops, found blank lines, so it's not a title.
  3806. // Put back the parenthetical statement we stole.
  3807. return blankLines + title;
  3808. } else {
  3809. if (title) {
  3810. globals.gTitles[linkId] = title.replace(/"|'/g, '&quot;');
  3811. }
  3812. if (options.parseImgDimensions && width && height) {
  3813. globals.gDimensions[linkId] = {
  3814. width: width,
  3815. height: height
  3816. };
  3817. }
  3818. }
  3819. // Completely remove the definition from the text
  3820. return '';
  3821. };
  3822. // first we try to find base64 link references
  3823. text = text.replace(base64Regex, replaceFunc);
  3824. text = text.replace(regex, replaceFunc);
  3825. // attacklab: strip sentinel
  3826. text = text.replace(/¨0/, '');
  3827. return text;
  3828. });
  3829. showdown.subParser('makehtml.tables', function (text, options, globals) {
  3830. 'use strict';
  3831. if (!options.tables) {
  3832. return text;
  3833. }
  3834. var tableRgx = /^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|¨0)/gm,
  3835. //singeColTblRgx = /^ {0,3}\|.+\|\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n(?: {0,3}\|.+\|\n)+(?:\n\n|¨0)/gm;
  3836. singeColTblRgx = /^ {0,3}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|¨0)/gm;
  3837. function parseStyles (sLine) {
  3838. if (/^:[ \t]*--*$/.test(sLine)) {
  3839. return ' style="text-align:left;"';
  3840. } else if (/^--*[ \t]*:[ \t]*$/.test(sLine)) {
  3841. return ' style="text-align:right;"';
  3842. } else if (/^:[ \t]*--*[ \t]*:$/.test(sLine)) {
  3843. return ' style="text-align:center;"';
  3844. } else {
  3845. return '';
  3846. }
  3847. }
  3848. function parseHeaders (header, style) {
  3849. var id = '';
  3850. header = header.trim();
  3851. // support both tablesHeaderId and tableHeaderId due to error in documentation so we don't break backwards compatibility
  3852. if (options.tablesHeaderId || options.tableHeaderId) {
  3853. id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
  3854. }
  3855. header = showdown.subParser('makehtml.spanGamut')(header, options, globals);
  3856. return '<th' + id + style + '>' + header + '</th>\n';
  3857. }
  3858. function parseCells (cell, style) {
  3859. var subText = showdown.subParser('makehtml.spanGamut')(cell, options, globals);
  3860. return '<td' + style + '>' + subText + '</td>\n';
  3861. }
  3862. function buildTable (headers, cells) {
  3863. var tb = '<table>\n<thead>\n<tr>\n',
  3864. tblLgn = headers.length;
  3865. for (var i = 0; i < tblLgn; ++i) {
  3866. tb += headers[i];
  3867. }
  3868. tb += '</tr>\n</thead>\n<tbody>\n';
  3869. for (i = 0; i < cells.length; ++i) {
  3870. tb += '<tr>\n';
  3871. for (var ii = 0; ii < tblLgn; ++ii) {
  3872. tb += cells[i][ii];
  3873. }
  3874. tb += '</tr>\n';
  3875. }
  3876. tb += '</tbody>\n</table>\n';
  3877. return tb;
  3878. }
  3879. function parseTable (rawTable) {
  3880. var i, tableLines = rawTable.split('\n');
  3881. for (i = 0; i < tableLines.length; ++i) {
  3882. // strip wrong first and last column if wrapped tables are used
  3883. if (/^ {0,3}\|/.test(tableLines[i])) {
  3884. tableLines[i] = tableLines[i].replace(/^ {0,3}\|/, '');
  3885. }
  3886. if (/\|[ \t]*$/.test(tableLines[i])) {
  3887. tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, '');
  3888. }
  3889. // parse code spans first, but we only support one line code spans
  3890. tableLines[i] = showdown.subParser('makehtml.codeSpans')(tableLines[i], options, globals);
  3891. }
  3892. var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}),
  3893. rawStyles = tableLines[1].split('|').map(function (s) { return s.trim();}),
  3894. rawCells = [],
  3895. headers = [],
  3896. styles = [],
  3897. cells = [];
  3898. tableLines.shift();
  3899. tableLines.shift();
  3900. for (i = 0; i < tableLines.length; ++i) {
  3901. if (tableLines[i].trim() === '') {
  3902. continue;
  3903. }
  3904. rawCells.push(
  3905. tableLines[i]
  3906. .split('|')
  3907. .map(function (s) {
  3908. return s.trim();
  3909. })
  3910. );
  3911. }
  3912. if (rawHeaders.length < rawStyles.length) {
  3913. return rawTable;
  3914. }
  3915. for (i = 0; i < rawStyles.length; ++i) {
  3916. styles.push(parseStyles(rawStyles[i]));
  3917. }
  3918. for (i = 0; i < rawHeaders.length; ++i) {
  3919. if (showdown.helper.isUndefined(styles[i])) {
  3920. styles[i] = '';
  3921. }
  3922. headers.push(parseHeaders(rawHeaders[i], styles[i]));
  3923. }
  3924. for (i = 0; i < rawCells.length; ++i) {
  3925. var row = [];
  3926. for (var ii = 0; ii < headers.length; ++ii) {
  3927. if (showdown.helper.isUndefined(rawCells[i][ii])) {
  3928. }
  3929. row.push(parseCells(rawCells[i][ii], styles[ii]));
  3930. }
  3931. cells.push(row);
  3932. }
  3933. return buildTable(headers, cells);
  3934. }
  3935. text = globals.converter._dispatch('makehtml.tables.before', text, options, globals).getText();
  3936. // find escaped pipe characters
  3937. text = text.replace(/\\(\|)/g, showdown.helper.escapeCharactersCallback);
  3938. // parse multi column tables
  3939. text = text.replace(tableRgx, parseTable);
  3940. // parse one column tables
  3941. text = text.replace(singeColTblRgx, parseTable);
  3942. text = globals.converter._dispatch('makehtml.tables.after', text, options, globals).getText();
  3943. return text;
  3944. });
  3945. showdown.subParser('makehtml.underline', function (text, options, globals) {
  3946. 'use strict';
  3947. if (!options.underline) {
  3948. return text;
  3949. }
  3950. text = globals.converter._dispatch('makehtml.underline.before', text, options, globals).getText();
  3951. if (options.literalMidWordUnderscores) {
  3952. text = text.replace(/\b___(\S[\s\S]*?)___\b/g, function (wm, txt) {
  3953. return '<u>' + txt + '</u>';
  3954. });
  3955. text = text.replace(/\b__(\S[\s\S]*?)__\b/g, function (wm, txt) {
  3956. return '<u>' + txt + '</u>';
  3957. });
  3958. } else {
  3959. text = text.replace(/___(\S[\s\S]*?)___/g, function (wm, m) {
  3960. return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm;
  3961. });
  3962. text = text.replace(/__(\S[\s\S]*?)__/g, function (wm, m) {
  3963. return (/\S$/.test(m)) ? '<u>' + m + '</u>' : wm;
  3964. });
  3965. }
  3966. // escape remaining underscores to prevent them being parsed by italic and bold
  3967. text = text.replace(/(_)/g, showdown.helper.escapeCharactersCallback);
  3968. text = globals.converter._dispatch('makehtml.underline.after', text, options, globals).getText();
  3969. return text;
  3970. });
  3971. /**
  3972. * Swap back in all the special characters we've hidden.
  3973. */
  3974. showdown.subParser('makehtml.unescapeSpecialChars', function (text, options, globals) {
  3975. 'use strict';
  3976. text = globals.converter._dispatch('makehtml.unescapeSpecialChars.before', text, options, globals).getText();
  3977. text = text.replace(/¨E(\d+)E/g, function (wholeMatch, m1) {
  3978. var charCodeToReplace = parseInt(m1);
  3979. return String.fromCharCode(charCodeToReplace);
  3980. });
  3981. text = globals.converter._dispatch('makehtml.unescapeSpecialChars.after', text, options, globals).getText();
  3982. return text;
  3983. });
  3984. showdown.subParser('makeMarkdown.blockquote', function (node, globals) {
  3985. 'use strict';
  3986. var txt = '';
  3987. if (node.hasChildNodes()) {
  3988. var children = node.childNodes,
  3989. childrenLength = children.length;
  3990. for (var i = 0; i < childrenLength; ++i) {
  3991. var innerTxt = showdown.subParser('makeMarkdown.node')(children[i], globals);
  3992. if (innerTxt === '') {
  3993. continue;
  3994. }
  3995. txt += innerTxt;
  3996. }
  3997. }
  3998. // cleanup
  3999. txt = txt.trim();
  4000. txt = '> ' + txt.split('\n').join('\n> ');
  4001. return txt;
  4002. });
  4003. showdown.subParser('makeMarkdown.codeBlock', function (node, globals) {
  4004. 'use strict';
  4005. var lang = node.getAttribute('language'),
  4006. num = node.getAttribute('precodenum');
  4007. return '```' + lang + '\n' + globals.preList[num] + '\n```';
  4008. });
  4009. showdown.subParser('makeMarkdown.codeSpan', function (node) {
  4010. 'use strict';
  4011. return '`' + node.innerHTML + '`';
  4012. });
  4013. showdown.subParser('makeMarkdown.emphasis', function (node, globals) {
  4014. 'use strict';
  4015. var txt = '';
  4016. if (node.hasChildNodes()) {
  4017. txt += '*';
  4018. var children = node.childNodes,
  4019. childrenLength = children.length;
  4020. for (var i = 0; i < childrenLength; ++i) {
  4021. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4022. }
  4023. txt += '*';
  4024. }
  4025. return txt;
  4026. });
  4027. showdown.subParser('makeMarkdown.header', function (node, globals, headerLevel) {
  4028. 'use strict';
  4029. var headerMark = new Array(headerLevel + 1).join('#'),
  4030. txt = '';
  4031. if (node.hasChildNodes()) {
  4032. txt = headerMark + ' ';
  4033. var children = node.childNodes,
  4034. childrenLength = children.length;
  4035. for (var i = 0; i < childrenLength; ++i) {
  4036. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4037. }
  4038. }
  4039. return txt;
  4040. });
  4041. showdown.subParser('makeMarkdown.hr', function () {
  4042. 'use strict';
  4043. return '---';
  4044. });
  4045. showdown.subParser('makeMarkdown.image', function (node) {
  4046. 'use strict';
  4047. var txt = '';
  4048. if (node.hasAttribute('src')) {
  4049. txt += '![' + node.getAttribute('alt') + '](';
  4050. txt += '<' + node.getAttribute('src') + '>';
  4051. if (node.hasAttribute('width') && node.hasAttribute('height')) {
  4052. txt += ' =' + node.getAttribute('width') + 'x' + node.getAttribute('height');
  4053. }
  4054. if (node.hasAttribute('title')) {
  4055. txt += ' "' + node.getAttribute('title') + '"';
  4056. }
  4057. txt += ')';
  4058. }
  4059. return txt;
  4060. });
  4061. showdown.subParser('makeMarkdown.links', function (node, globals) {
  4062. 'use strict';
  4063. var txt = '';
  4064. if (node.hasChildNodes() && node.hasAttribute('href')) {
  4065. var children = node.childNodes,
  4066. childrenLength = children.length;
  4067. txt = '[';
  4068. for (var i = 0; i < childrenLength; ++i) {
  4069. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4070. }
  4071. txt += '](';
  4072. txt += '<' + node.getAttribute('href') + '>';
  4073. if (node.hasAttribute('title')) {
  4074. txt += ' "' + node.getAttribute('title') + '"';
  4075. }
  4076. txt += ')';
  4077. }
  4078. return txt;
  4079. });
  4080. showdown.subParser('makeMarkdown.list', function (node, globals, type) {
  4081. 'use strict';
  4082. var txt = '';
  4083. if (!node.hasChildNodes()) {
  4084. return '';
  4085. }
  4086. var listItems = node.childNodes,
  4087. listItemsLenght = listItems.length,
  4088. listNum = node.getAttribute('start') || 1;
  4089. for (var i = 0; i < listItemsLenght; ++i) {
  4090. if (typeof listItems[i].tagName === 'undefined' || listItems[i].tagName.toLowerCase() !== 'li') {
  4091. continue;
  4092. }
  4093. // define the bullet to use in list
  4094. var bullet = '';
  4095. if (type === 'ol') {
  4096. bullet = listNum.toString() + '. ';
  4097. } else {
  4098. bullet = '- ';
  4099. }
  4100. // parse list item
  4101. txt += bullet + showdown.subParser('makeMarkdown.listItem')(listItems[i], globals);
  4102. ++listNum;
  4103. }
  4104. return txt.trim();
  4105. });
  4106. showdown.subParser('makeMarkdown.listItem', function (node, globals) {
  4107. 'use strict';
  4108. var listItemTxt = '';
  4109. var children = node.childNodes,
  4110. childrenLenght = children.length;
  4111. for (var i = 0; i < childrenLenght; ++i) {
  4112. listItemTxt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4113. }
  4114. // if it's only one liner, we need to add a newline at the end
  4115. if (!/\n$/.test(listItemTxt)) {
  4116. listItemTxt += '\n';
  4117. } else {
  4118. // it's multiparagraph, so we need to indent
  4119. listItemTxt = listItemTxt
  4120. .split('\n')
  4121. .join('\n ')
  4122. .replace(/^ {4}$/gm, '')
  4123. .replace(/\n\n+/g, '\n\n');
  4124. }
  4125. return listItemTxt;
  4126. });
  4127. showdown.subParser('makeMarkdown.node', function (node, globals, spansOnly) {
  4128. 'use strict';
  4129. spansOnly = spansOnly || false;
  4130. var txt = '';
  4131. // edge case of text without wrapper paragraph
  4132. if (node.nodeType === 3) {
  4133. return showdown.subParser('makeMarkdown.txt')(node, globals);
  4134. }
  4135. // HTML comment
  4136. if (node.nodeType === 8) {
  4137. return '<!--' + node.data + '-->\n\n';
  4138. }
  4139. // process only node elements
  4140. if (node.nodeType !== 1) {
  4141. return '';
  4142. }
  4143. var tagName = node.tagName.toLowerCase();
  4144. switch (tagName) {
  4145. //
  4146. // BLOCKS
  4147. //
  4148. case 'h1':
  4149. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 1) + '\n\n'; }
  4150. break;
  4151. case 'h2':
  4152. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 2) + '\n\n'; }
  4153. break;
  4154. case 'h3':
  4155. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 3) + '\n\n'; }
  4156. break;
  4157. case 'h4':
  4158. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 4) + '\n\n'; }
  4159. break;
  4160. case 'h5':
  4161. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 5) + '\n\n'; }
  4162. break;
  4163. case 'h6':
  4164. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.header')(node, globals, 6) + '\n\n'; }
  4165. break;
  4166. case 'p':
  4167. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.paragraph')(node, globals) + '\n\n'; }
  4168. break;
  4169. case 'blockquote':
  4170. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.blockquote')(node, globals) + '\n\n'; }
  4171. break;
  4172. case 'hr':
  4173. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.hr')(node, globals) + '\n\n'; }
  4174. break;
  4175. case 'ol':
  4176. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.list')(node, globals, 'ol') + '\n\n'; }
  4177. break;
  4178. case 'ul':
  4179. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.list')(node, globals, 'ul') + '\n\n'; }
  4180. break;
  4181. case 'precode':
  4182. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.codeBlock')(node, globals) + '\n\n'; }
  4183. break;
  4184. case 'pre':
  4185. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.pre')(node, globals) + '\n\n'; }
  4186. break;
  4187. case 'table':
  4188. if (!spansOnly) { txt = showdown.subParser('makeMarkdown.table')(node, globals) + '\n\n'; }
  4189. break;
  4190. //
  4191. // SPANS
  4192. //
  4193. case 'code':
  4194. txt = showdown.subParser('makeMarkdown.codeSpan')(node, globals);
  4195. break;
  4196. case 'em':
  4197. case 'i':
  4198. txt = showdown.subParser('makeMarkdown.emphasis')(node, globals);
  4199. break;
  4200. case 'strong':
  4201. case 'b':
  4202. txt = showdown.subParser('makeMarkdown.strong')(node, globals);
  4203. break;
  4204. case 'del':
  4205. txt = showdown.subParser('makeMarkdown.strikethrough')(node, globals);
  4206. break;
  4207. case 'a':
  4208. txt = showdown.subParser('makeMarkdown.links')(node, globals);
  4209. break;
  4210. case 'img':
  4211. txt = showdown.subParser('makeMarkdown.image')(node, globals);
  4212. break;
  4213. default:
  4214. txt = node.outerHTML + '\n\n';
  4215. }
  4216. // common normalization
  4217. // TODO eventually
  4218. return txt;
  4219. });
  4220. showdown.subParser('makeMarkdown.paragraph', function (node, globals) {
  4221. 'use strict';
  4222. var txt = '';
  4223. if (node.hasChildNodes()) {
  4224. var children = node.childNodes,
  4225. childrenLength = children.length;
  4226. for (var i = 0; i < childrenLength; ++i) {
  4227. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4228. }
  4229. }
  4230. // some text normalization
  4231. txt = txt.trim();
  4232. return txt;
  4233. });
  4234. showdown.subParser('makeMarkdown.pre', function (node, globals) {
  4235. 'use strict';
  4236. var num = node.getAttribute('prenum');
  4237. return '<pre>' + globals.preList[num] + '</pre>';
  4238. });
  4239. showdown.subParser('makeMarkdown.strikethrough', function (node, globals) {
  4240. 'use strict';
  4241. var txt = '';
  4242. if (node.hasChildNodes()) {
  4243. txt += '~~';
  4244. var children = node.childNodes,
  4245. childrenLength = children.length;
  4246. for (var i = 0; i < childrenLength; ++i) {
  4247. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4248. }
  4249. txt += '~~';
  4250. }
  4251. return txt;
  4252. });
  4253. showdown.subParser('makeMarkdown.strong', function (node, globals) {
  4254. 'use strict';
  4255. var txt = '';
  4256. if (node.hasChildNodes()) {
  4257. txt += '**';
  4258. var children = node.childNodes,
  4259. childrenLength = children.length;
  4260. for (var i = 0; i < childrenLength; ++i) {
  4261. txt += showdown.subParser('makeMarkdown.node')(children[i], globals);
  4262. }
  4263. txt += '**';
  4264. }
  4265. return txt;
  4266. });
  4267. showdown.subParser('makeMarkdown.table', function (node, globals) {
  4268. 'use strict';
  4269. var txt = '',
  4270. tableArray = [[], []],
  4271. headings = node.querySelectorAll('thead>tr>th'),
  4272. rows = node.querySelectorAll('tbody>tr'),
  4273. i, ii;
  4274. for (i = 0; i < headings.length; ++i) {
  4275. var headContent = showdown.subParser('makeMarkdown.tableCell')(headings[i], globals),
  4276. allign = '---';
  4277. if (headings[i].hasAttribute('style')) {
  4278. var style = headings[i].getAttribute('style').toLowerCase().replace(/\s/g, '');
  4279. switch (style) {
  4280. case 'text-align:left;':
  4281. allign = ':---';
  4282. break;
  4283. case 'text-align:right;':
  4284. allign = '---:';
  4285. break;
  4286. case 'text-align:center;':
  4287. allign = ':---:';
  4288. break;
  4289. }
  4290. }
  4291. tableArray[0][i] = headContent.trim();
  4292. tableArray[1][i] = allign;
  4293. }
  4294. for (i = 0; i < rows.length; ++i) {
  4295. var r = tableArray.push([]) - 1,
  4296. cols = rows[i].getElementsByTagName('td');
  4297. for (ii = 0; ii < headings.length; ++ii) {
  4298. var cellContent = ' ';
  4299. if (typeof cols[ii] !== 'undefined') {
  4300. cellContent = showdown.subParser('makeMarkdown.tableCell')(cols[ii], globals);
  4301. }
  4302. tableArray[r].push(cellContent);
  4303. }
  4304. }
  4305. var cellSpacesCount = 3;
  4306. for (i = 0; i < tableArray.length; ++i) {
  4307. for (ii = 0; ii < tableArray[i].length; ++ii) {
  4308. var strLen = tableArray[i][ii].length;
  4309. if (strLen > cellSpacesCount) {
  4310. cellSpacesCount = strLen;
  4311. }
  4312. }
  4313. }
  4314. for (i = 0; i < tableArray.length; ++i) {
  4315. for (ii = 0; ii < tableArray[i].length; ++ii) {
  4316. if (i === 1) {
  4317. if (tableArray[i][ii].slice(-1) === ':') {
  4318. tableArray[i][ii] = showdown.helper.padEnd(tableArray[i][ii].slice(-1), cellSpacesCount - 1, '-') + ':';
  4319. } else {
  4320. tableArray[i][ii] = showdown.helper.padEnd(tableArray[i][ii], cellSpacesCount, '-');
  4321. }
  4322. } else {
  4323. tableArray[i][ii] = showdown.helper.padEnd(tableArray[i][ii], cellSpacesCount);
  4324. }
  4325. }
  4326. txt += '| ' + tableArray[i].join(' | ') + ' |\n';
  4327. }
  4328. return txt.trim();
  4329. });
  4330. showdown.subParser('makeMarkdown.tableCell', function (node, globals) {
  4331. 'use strict';
  4332. var txt = '';
  4333. if (!node.hasChildNodes()) {
  4334. return '';
  4335. }
  4336. var children = node.childNodes,
  4337. childrenLength = children.length;
  4338. for (var i = 0; i < childrenLength; ++i) {
  4339. txt += showdown.subParser('makeMarkdown.node')(children[i], globals, true);
  4340. }
  4341. return txt.trim();
  4342. });
  4343. showdown.subParser('makeMarkdown.txt', function (node) {
  4344. 'use strict';
  4345. var txt = node.nodeValue;
  4346. // multiple spaces are collapsed
  4347. txt = txt.replace(/ +/g, ' ');
  4348. // replace the custom ¨NBSP; with a space
  4349. txt = txt.replace(/¨NBSP;/g, ' ');
  4350. // ", <, > and & should replace escaped html entities
  4351. txt = showdown.helper.unescapeHTMLEntities(txt);
  4352. // escape markdown magic characters
  4353. // emphasis, strong and strikethrough - can appear everywhere
  4354. // we also escape pipe (|) because of tables
  4355. // and escape ` because of code blocks and spans
  4356. txt = txt.replace(/([*_~|`])/g, '\\$1');
  4357. // escape > because of blockquotes
  4358. txt = txt.replace(/^(\s*)>/g, '\\$1>');
  4359. // hash character, only troublesome at the beginning of a line because of headers
  4360. txt = txt.replace(/^#/gm, '\\#');
  4361. // horizontal rules
  4362. txt = txt.replace(/^(\s*)([-=]{3,})(\s*)$/, '$1\\$2$3');
  4363. // dot, because of ordered lists, only troublesome at the beginning of a line when preceded by an integer
  4364. txt = txt.replace(/^( {0,3}\d+)\./gm, '$1\\.');
  4365. // +, * and -, at the beginning of a line becomes a list, so we need to escape them also (asterisk was already escaped)
  4366. txt = txt.replace(/^( {0,3})([+-])/gm, '$1\\$2');
  4367. // images and links, ] followed by ( is problematic, so we escape it
  4368. txt = txt.replace(/]([\s]*)\(/g, '\\]$1\\(');
  4369. // reference URIs must also be escaped
  4370. txt = txt.replace(/^ {0,3}\[([\S \t]*?)]:/gm, '\\[$1]:');
  4371. return txt;
  4372. });
  4373. /**
  4374. * Created by Estevao on 31-05-2015.
  4375. */
  4376. /**
  4377. * Showdown Converter class
  4378. * @class
  4379. * @param {object} [converterOptions]
  4380. * @returns {Converter}
  4381. */
  4382. showdown.Converter = function (converterOptions) {
  4383. 'use strict';
  4384. var
  4385. /**
  4386. * Options used by this converter
  4387. * @private
  4388. * @type {{}}
  4389. */
  4390. options = {},
  4391. /**
  4392. * Language extensions used by this converter
  4393. * @private
  4394. * @type {Array}
  4395. */
  4396. langExtensions = [],
  4397. /**
  4398. * Output modifiers extensions used by this converter
  4399. * @private
  4400. * @type {Array}
  4401. */
  4402. outputModifiers = [],
  4403. /**
  4404. * Event listeners
  4405. * @private
  4406. * @type {{}}
  4407. */
  4408. listeners = {},
  4409. /**
  4410. * The flavor set in this converter
  4411. */
  4412. setConvFlavor = setFlavor,
  4413. /**
  4414. * Metadata of the document
  4415. * @type {{parsed: {}, raw: string, format: string}}
  4416. */
  4417. metadata = {
  4418. parsed: {},
  4419. raw: '',
  4420. format: ''
  4421. };
  4422. _constructor();
  4423. /**
  4424. * Converter constructor
  4425. * @private
  4426. */
  4427. function _constructor () {
  4428. converterOptions = converterOptions || {};
  4429. for (var gOpt in globalOptions) {
  4430. if (globalOptions.hasOwnProperty(gOpt)) {
  4431. options[gOpt] = globalOptions[gOpt];
  4432. }
  4433. }
  4434. // Merge options
  4435. if (typeof converterOptions === 'object') {
  4436. for (var opt in converterOptions) {
  4437. if (converterOptions.hasOwnProperty(opt)) {
  4438. options[opt] = converterOptions[opt];
  4439. }
  4440. }
  4441. } else {
  4442. throw Error('Converter expects the passed parameter to be an object, but ' + typeof converterOptions +
  4443. ' was passed instead.');
  4444. }
  4445. if (options.extensions) {
  4446. showdown.helper.forEach(options.extensions, _parseExtension);
  4447. }
  4448. }
  4449. /**
  4450. * Parse extension
  4451. * @param {*} ext
  4452. * @param {string} [name='']
  4453. * @private
  4454. */
  4455. function _parseExtension (ext, name) {
  4456. name = name || null;
  4457. // If it's a string, the extension was previously loaded
  4458. if (showdown.helper.isString(ext)) {
  4459. ext = showdown.helper.stdExtName(ext);
  4460. name = ext;
  4461. // LEGACY_SUPPORT CODE
  4462. if (showdown.extensions[ext]) {
  4463. console.warn('DEPRECATION WARNING: ' + ext + ' is an old extension that uses a deprecated loading method.' +
  4464. 'Please inform the developer that the extension should be updated!');
  4465. legacyExtensionLoading(showdown.extensions[ext], ext);
  4466. return;
  4467. // END LEGACY SUPPORT CODE
  4468. } else if (!showdown.helper.isUndefined(extensions[ext])) {
  4469. ext = extensions[ext];
  4470. } else {
  4471. throw Error('Extension "' + ext + '" could not be loaded. It was either not found or is not a valid extension.');
  4472. }
  4473. }
  4474. if (typeof ext === 'function') {
  4475. ext = ext();
  4476. }
  4477. if (!showdown.helper.isArray(ext)) {
  4478. ext = [ext];
  4479. }
  4480. var validExt = validate(ext, name);
  4481. if (!validExt.valid) {
  4482. throw Error(validExt.error);
  4483. }
  4484. for (var i = 0; i < ext.length; ++i) {
  4485. switch (ext[i].type) {
  4486. case 'lang':
  4487. langExtensions.push(ext[i]);
  4488. break;
  4489. case 'output':
  4490. outputModifiers.push(ext[i]);
  4491. break;
  4492. }
  4493. if (ext[i].hasOwnProperty('listeners')) {
  4494. for (var ln in ext[i].listeners) {
  4495. if (ext[i].listeners.hasOwnProperty(ln)) {
  4496. listen(ln, ext[i].listeners[ln]);
  4497. }
  4498. }
  4499. }
  4500. }
  4501. }
  4502. /**
  4503. * LEGACY_SUPPORT
  4504. * @param {*} ext
  4505. * @param {string} name
  4506. */
  4507. function legacyExtensionLoading (ext, name) {
  4508. if (typeof ext === 'function') {
  4509. ext = ext(new showdown.Converter());
  4510. }
  4511. if (!showdown.helper.isArray(ext)) {
  4512. ext = [ext];
  4513. }
  4514. var valid = validate(ext, name);
  4515. if (!valid.valid) {
  4516. throw Error(valid.error);
  4517. }
  4518. for (var i = 0; i < ext.length; ++i) {
  4519. switch (ext[i].type) {
  4520. case 'lang':
  4521. langExtensions.push(ext[i]);
  4522. break;
  4523. case 'output':
  4524. outputModifiers.push(ext[i]);
  4525. break;
  4526. default:// should never reach here
  4527. throw Error('Extension loader error: Type unrecognized!!!');
  4528. }
  4529. }
  4530. }
  4531. /**
  4532. * Listen to an event
  4533. * @param {string} name
  4534. * @param {function} callback
  4535. */
  4536. function listen (name, callback) {
  4537. if (!showdown.helper.isString(name)) {
  4538. throw Error('Invalid argument in converter.listen() method: name must be a string, but ' + typeof name + ' given');
  4539. }
  4540. if (typeof callback !== 'function') {
  4541. throw Error('Invalid argument in converter.listen() method: callback must be a function, but ' + typeof callback + ' given');
  4542. }
  4543. name = name.toLowerCase();
  4544. if (!listeners.hasOwnProperty(name)) {
  4545. listeners[name] = [];
  4546. }
  4547. listeners[name].push(callback);
  4548. }
  4549. function rTrimInputText (text) {
  4550. var rsp = text.match(/^\s*/)[0].length,
  4551. rgx = new RegExp('^\\s{0,' + rsp + '}', 'gm');
  4552. return text.replace(rgx, '');
  4553. }
  4554. /**
  4555. *
  4556. * @param {string} evtName Event name
  4557. * @param {string} text Text
  4558. * @param {{}} options Converter Options
  4559. * @param {{}} globals Converter globals
  4560. * @param {{}} pParams extra params for event
  4561. * @returns showdown.helper.Event
  4562. * @private
  4563. */
  4564. this._dispatch = function dispatch (evtName, text, options, globals, pParams) {
  4565. evtName = evtName.toLowerCase();
  4566. var params = pParams || {};
  4567. params.converter = this;
  4568. params.text = text;
  4569. params.options = options;
  4570. params.globals = globals;
  4571. var event = new showdown.helper.Event(evtName, text, params);
  4572. if (listeners.hasOwnProperty(evtName)) {
  4573. for (var ei = 0; ei < listeners[evtName].length; ++ei) {
  4574. var nText = listeners[evtName][ei](event);
  4575. if (nText && typeof nText !== 'undefined') {
  4576. event.setText(nText);
  4577. }
  4578. }
  4579. }
  4580. return event;
  4581. };
  4582. /**
  4583. * Listen to an event
  4584. * @param {string} name
  4585. * @param {function} callback
  4586. * @returns {showdown.Converter}
  4587. */
  4588. this.listen = function (name, callback) {
  4589. listen(name, callback);
  4590. return this;
  4591. };
  4592. /**
  4593. * Converts a markdown string into HTML string
  4594. * @param {string} text
  4595. * @returns {*}
  4596. */
  4597. this.makeHtml = function (text) {
  4598. //check if text is not falsy
  4599. if (!text) {
  4600. return text;
  4601. }
  4602. var globals = {
  4603. gHtmlBlocks: [],
  4604. gHtmlMdBlocks: [],
  4605. gHtmlSpans: [],
  4606. gUrls: {},
  4607. gTitles: {},
  4608. gDimensions: {},
  4609. gListLevel: 0,
  4610. hashLinkCounts: {},
  4611. langExtensions: langExtensions,
  4612. outputModifiers: outputModifiers,
  4613. converter: this,
  4614. ghCodeBlocks: [],
  4615. metadata: {
  4616. parsed: {},
  4617. raw: '',
  4618. format: ''
  4619. }
  4620. };
  4621. // This lets us use ¨ trema as an escape char to avoid md5 hashes
  4622. // The choice of character is arbitrary; anything that isn't
  4623. // magic in Markdown will work.
  4624. text = text.replace(/¨/g, '¨T');
  4625. // Replace $ with ¨D
  4626. // RegExp interprets $ as a special character
  4627. // when it's in a replacement string
  4628. text = text.replace(/\$/g, '¨D');
  4629. // Standardize line endings
  4630. text = text.replace(/\r\n/g, '\n'); // DOS to Unix
  4631. text = text.replace(/\r/g, '\n'); // Mac to Unix
  4632. // Stardardize line spaces
  4633. text = text.replace(/\u00A0/g, '&nbsp;');
  4634. if (options.smartIndentationFix) {
  4635. text = rTrimInputText(text);
  4636. }
  4637. // Make sure text begins and ends with a couple of newlines:
  4638. text = '\n\n' + text + '\n\n';
  4639. // detab
  4640. text = showdown.subParser('makehtml.detab')(text, options, globals);
  4641. /**
  4642. * Strip any lines consisting only of spaces and tabs.
  4643. * This makes subsequent regexs easier to write, because we can
  4644. * match consecutive blank lines with /\n+/ instead of something
  4645. * contorted like /[ \t]*\n+/
  4646. */
  4647. text = text.replace(/^[ \t]+$/mg, '');
  4648. //run languageExtensions
  4649. showdown.helper.forEach(langExtensions, function (ext) {
  4650. text = showdown.subParser('makehtml.runExtension')(ext, text, options, globals);
  4651. });
  4652. // run the sub parsers
  4653. text = showdown.subParser('makehtml.metadata')(text, options, globals);
  4654. text = showdown.subParser('makehtml.hashPreCodeTags')(text, options, globals);
  4655. text = showdown.subParser('makehtml.githubCodeBlocks')(text, options, globals);
  4656. text = showdown.subParser('makehtml.hashHTMLBlocks')(text, options, globals);
  4657. text = showdown.subParser('makehtml.hashCodeTags')(text, options, globals);
  4658. text = showdown.subParser('makehtml.stripLinkDefinitions')(text, options, globals);
  4659. text = showdown.subParser('makehtml.blockGamut')(text, options, globals);
  4660. text = showdown.subParser('makehtml.unhashHTMLSpans')(text, options, globals);
  4661. text = showdown.subParser('makehtml.unescapeSpecialChars')(text, options, globals);
  4662. // attacklab: Restore dollar signs
  4663. text = text.replace(/¨D/g, '$$');
  4664. // attacklab: Restore tremas
  4665. text = text.replace(/¨T/g, '¨');
  4666. // render a complete html document instead of a partial if the option is enabled
  4667. text = showdown.subParser('makehtml.completeHTMLDocument')(text, options, globals);
  4668. // Run output modifiers
  4669. showdown.helper.forEach(outputModifiers, function (ext) {
  4670. text = showdown.subParser('makehtml.runExtension')(ext, text, options, globals);
  4671. });
  4672. // update metadata
  4673. metadata = globals.metadata;
  4674. return text;
  4675. };
  4676. /**
  4677. * Converts an HTML string into a markdown string
  4678. * @param src
  4679. * @returns {string}
  4680. */
  4681. this.makeMarkdown = function (src) {
  4682. // replace \r\n with \n
  4683. src = src.replace(/\r\n/g, '\n');
  4684. src = src.replace(/\r/g, '\n'); // old macs
  4685. // due to an edge case, we need to find this: > <
  4686. // to prevent removing of non silent white spaces
  4687. // ex: <em>this is</em> <strong>sparta</strong>
  4688. src = src.replace(/>[ \t]+</, '>¨NBSP;<');
  4689. var doc = showdown.helper.document.createElement('div');
  4690. doc.innerHTML = src;
  4691. var globals = {
  4692. preList: substitutePreCodeTags(doc)
  4693. };
  4694. // remove all newlines and collapse spaces
  4695. clean(doc);
  4696. // some stuff, like accidental reference links must now be escaped
  4697. // TODO
  4698. // doc.innerHTML = doc.innerHTML.replace(/\[[\S\t ]]/);
  4699. var nodes = doc.childNodes,
  4700. mdDoc = '';
  4701. for (var i = 0; i < nodes.length; i++) {
  4702. mdDoc += showdown.subParser('makeMarkdown.node')(nodes[i], globals);
  4703. }
  4704. function clean (node) {
  4705. for (var n = 0; n < node.childNodes.length; ++n) {
  4706. var child = node.childNodes[n];
  4707. if (child.nodeType === 3) {
  4708. if (!/\S/.test(child.nodeValue)) {
  4709. node.removeChild(child);
  4710. --n;
  4711. } else {
  4712. child.nodeValue = child.nodeValue.split('\n').join(' ');
  4713. child.nodeValue = child.nodeValue.replace(/(\s)+/g, '$1');
  4714. }
  4715. } else if (child.nodeType === 1) {
  4716. clean(child);
  4717. }
  4718. }
  4719. }
  4720. // find all pre tags and replace contents with placeholder
  4721. // we need this so that we can remove all indentation from html
  4722. // to ease up parsing
  4723. function substitutePreCodeTags (doc) {
  4724. var pres = doc.querySelectorAll('pre'),
  4725. presPH = [];
  4726. for (var i = 0; i < pres.length; ++i) {
  4727. if (pres[i].childElementCount === 1 && pres[i].firstChild.tagName.toLowerCase() === 'code') {
  4728. var content = pres[i].firstChild.innerHTML.trim(),
  4729. language = pres[i].firstChild.getAttribute('data-language') || '';
  4730. // if data-language attribute is not defined, then we look for class language-*
  4731. if (language === '') {
  4732. var classes = pres[i].firstChild.className.split(' ');
  4733. for (var c = 0; c < classes.length; ++c) {
  4734. var matches = classes[c].match(/^language-(.+)$/);
  4735. if (matches !== null) {
  4736. language = matches[1];
  4737. break;
  4738. }
  4739. }
  4740. }
  4741. // unescape html entities in content
  4742. content = showdown.helper.unescapeHTMLEntities(content);
  4743. presPH.push(content);
  4744. pres[i].outerHTML = '<precode language="' + language + '" precodenum="' + i.toString() + '"></precode>';
  4745. } else {
  4746. presPH.push(pres[i].innerHTML);
  4747. pres[i].innerHTML = '';
  4748. pres[i].setAttribute('prenum', i.toString());
  4749. }
  4750. }
  4751. return presPH;
  4752. }
  4753. return mdDoc;
  4754. };
  4755. /**
  4756. * Set an option of this Converter instance
  4757. * @param {string} key
  4758. * @param {*} value
  4759. */
  4760. this.setOption = function (key, value) {
  4761. options[key] = value;
  4762. };
  4763. /**
  4764. * Get the option of this Converter instance
  4765. * @param {string} key
  4766. * @returns {*}
  4767. */
  4768. this.getOption = function (key) {
  4769. return options[key];
  4770. };
  4771. /**
  4772. * Get the options of this Converter instance
  4773. * @returns {{}}
  4774. */
  4775. this.getOptions = function () {
  4776. return options;
  4777. };
  4778. /**
  4779. * Add extension to THIS converter
  4780. * @param {{}} extension
  4781. * @param {string} [name=null]
  4782. */
  4783. this.addExtension = function (extension, name) {
  4784. name = name || null;
  4785. _parseExtension(extension, name);
  4786. };
  4787. /**
  4788. * Use a global registered extension with THIS converter
  4789. * @param {string} extensionName Name of the previously registered extension
  4790. */
  4791. this.useExtension = function (extensionName) {
  4792. _parseExtension(extensionName);
  4793. };
  4794. /**
  4795. * Set the flavor THIS converter should use
  4796. * @param {string} name
  4797. */
  4798. this.setFlavor = function (name) {
  4799. if (!flavor.hasOwnProperty(name)) {
  4800. throw Error(name + ' flavor was not found');
  4801. }
  4802. var preset = flavor[name];
  4803. setConvFlavor = name;
  4804. for (var option in preset) {
  4805. if (preset.hasOwnProperty(option)) {
  4806. options[option] = preset[option];
  4807. }
  4808. }
  4809. };
  4810. /**
  4811. * Get the currently set flavor of this converter
  4812. * @returns {string}
  4813. */
  4814. this.getFlavor = function () {
  4815. return setConvFlavor;
  4816. };
  4817. /**
  4818. * Remove an extension from THIS converter.
  4819. * Note: This is a costly operation. It's better to initialize a new converter
  4820. * and specify the extensions you wish to use
  4821. * @param {Array} extension
  4822. */
  4823. this.removeExtension = function (extension) {
  4824. if (!showdown.helper.isArray(extension)) {
  4825. extension = [extension];
  4826. }
  4827. for (var a = 0; a < extension.length; ++a) {
  4828. var ext = extension[a];
  4829. for (var i = 0; i < langExtensions.length; ++i) {
  4830. if (langExtensions[i] === ext) {
  4831. langExtensions[i].splice(i, 1);
  4832. }
  4833. }
  4834. for (var ii = 0; ii < outputModifiers.length; ++i) {
  4835. if (outputModifiers[ii] === ext) {
  4836. outputModifiers[ii].splice(i, 1);
  4837. }
  4838. }
  4839. }
  4840. };
  4841. /**
  4842. * Get all extension of THIS converter
  4843. * @returns {{language: Array, output: Array}}
  4844. */
  4845. this.getAllExtensions = function () {
  4846. return {
  4847. language: langExtensions,
  4848. output: outputModifiers
  4849. };
  4850. };
  4851. /**
  4852. * Get the metadata of the previously parsed document
  4853. * @param raw
  4854. * @returns {string|{}}
  4855. */
  4856. this.getMetadata = function (raw) {
  4857. if (raw) {
  4858. return metadata.raw;
  4859. } else {
  4860. return metadata.parsed;
  4861. }
  4862. };
  4863. /**
  4864. * Get the metadata format of the previously parsed document
  4865. * @returns {string}
  4866. */
  4867. this.getMetadataFormat = function () {
  4868. return metadata.format;
  4869. };
  4870. /**
  4871. * Private: set a single key, value metadata pair
  4872. * @param {string} key
  4873. * @param {string} value
  4874. */
  4875. this._setMetadataPair = function (key, value) {
  4876. metadata.parsed[key] = value;
  4877. };
  4878. /**
  4879. * Private: set metadata format
  4880. * @param {string} format
  4881. */
  4882. this._setMetadataFormat = function (format) {
  4883. metadata.format = format;
  4884. };
  4885. /**
  4886. * Private: set metadata raw text
  4887. * @param {string} raw
  4888. */
  4889. this._setMetadataRaw = function (raw) {
  4890. metadata.raw = raw;
  4891. };
  4892. };
  4893. var root = this;
  4894. // AMD Loader
  4895. if (typeof define === 'function' && define.amd) {
  4896. define(function () {
  4897. 'use strict';
  4898. return showdown;
  4899. });
  4900. // CommonJS/nodeJS Loader
  4901. } else if (typeof module !== 'undefined' && module.exports) {
  4902. module.exports = showdown;
  4903. // Regular Browser loader
  4904. } else {
  4905. root.showdown = showdown;
  4906. }
  4907. }).call(this);
  4908. //# sourceMappingURL=showdown.js.map
  4909. <!-- Reusable -->
  4910. // Topic: ES6 String contains, starts with, ends with to ES5
  4911. // Source: https://gist.github.com/hamiltondanielb/a174bc415fdd71966de1
  4912. String.prototype.endsWith = String.prototype.endsWith || function(suffix) {
  4913. return this.indexOf(suffix, this.length - suffix.length) >= 0;
  4914. };
  4915. // Topic: ES6 String contains, starts with, ends with to ES5
  4916. // Source: https://gist.github.com/hamiltondanielb/a174bc415fdd71966de1
  4917. String.prototype.startsWith = String.prototype.startsWith || function(prefix) {
  4918. return this.indexOf(prefix) === 0;
  4919. };
  4920. function fileExists(fileName, fileList)
  4921. {
  4922. for (var id in fileList)
  4923. {
  4924. var file = fileList[id];
  4925. if (file.path === fileName)
  4926. {
  4927. return true;
  4928. }
  4929. }
  4930. return false;
  4931. }
  4932. // Topic: Create GUID / UUID in JavaScript?
  4933. // Source: https://stackoverflow.com/a/2117523
  4934. function generateUUID()
  4935. {
  4936. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
  4937. /[xy]/g,
  4938. function(c)
  4939. {
  4940. var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
  4941. return v.toString(16);
  4942. }
  4943. );
  4944. }
  4945. function LOG(message)
  4946. {
  4947. var log = document.getElementById("log");
  4948. var now = new Date();
  4949. log.innerHTML += now.toISOString() + " " + message + "<br>";
  4950. }
  4951. function parseINI(contents)
  4952. {
  4953. var cfg = { };
  4954. var lines = contents.split(/\r\n|\r|\n/);
  4955. for (var id in lines)
  4956. {
  4957. var line = lines[id];
  4958. var keyAndValue = line.split(/=/);
  4959. if (keyAndValue.length == 2)
  4960. {
  4961. var key = keyAndValue[0].trim();
  4962. var value = keyAndValue[1].trim();
  4963. cfg[key] = value;
  4964. }
  4965. }
  4966. return cfg;
  4967. }
  4968. // ReporterSubscription class.
  4969. function ReporterSubscription(id, callback, reporter)
  4970. {
  4971. this.id = id;
  4972. this.callback = callback;
  4973. this.reporter = reporter;
  4974. }
  4975. // Reporter class.
  4976. function Reporter(name)
  4977. {
  4978. this.name =
  4979. (typeof name !== "undefined") ?
  4980. name :
  4981. "";
  4982. this.subscriptions = [];
  4983. }
  4984. Reporter.prototype.report = function()
  4985. {
  4986. for (var id in this.subscriptions)
  4987. {
  4988. var subscription = this.subscriptions[id];
  4989. subscription.callback();
  4990. }
  4991. }
  4992. Reporter.prototype.subscribe = function(callback)
  4993. {
  4994. var id = generateUUID();
  4995. var subscription = new ReporterSubscription(id, callback, this);
  4996. this.subscriptions.push(subscription);
  4997. return subscription;
  4998. }
  4999. <!-- LFSA -->
  5000. // LFSA class to communicate with local-file-system-access instance.
  5001. function LFSA()
  5002. {
  5003. this.host = "http://127.0.0.1";
  5004. this.port = 8000;
  5005. }
  5006. LFSA.prototype.get = function(url, successCallback, failureCallback)
  5007. {
  5008. var req = new XMLHttpRequest();
  5009. req.addEventListener(
  5010. "load",
  5011. function()
  5012. {
  5013. //console.log("get.successCallback.responseText: '" + this.responseText + "'");
  5014. successCallback(this.responseText);
  5015. }
  5016. );
  5017. req.addEventListener(
  5018. "error",
  5019. function()
  5020. {
  5021. failureCallback();
  5022. }
  5023. );
  5024. req.addEventListener(
  5025. "abort",
  5026. function()
  5027. {
  5028. failureCallback();
  5029. }
  5030. );
  5031. const prefix = this.host + ":" + this.port;
  5032. const addr = prefix + url;
  5033. //console.log("GET addr: '" + addr + "'");
  5034. req.open("GET", addr);
  5035. req.send();
  5036. }
  5037. LFSA.prototype.requestPath = function(successCallback, failureCallback)
  5038. {
  5039. this.get("/path", successCallback, failureCallback);
  5040. }
  5041. LFSA.prototype.post = function(url, data, successCallback, failureCallback)
  5042. {
  5043. var req = new XMLHttpRequest();
  5044. req.addEventListener(
  5045. "load",
  5046. function()
  5047. {
  5048. //console.log("POST.successCallback.responseText: '" + this.responseText + "'");
  5049. successCallback(this.responseText);
  5050. }
  5051. );
  5052. req.addEventListener(
  5053. "error",
  5054. function()
  5055. {
  5056. failureCallback();
  5057. }
  5058. );
  5059. req.addEventListener(
  5060. "abort",
  5061. function()
  5062. {
  5063. failureCallback();
  5064. }
  5065. );
  5066. const prefix = this.host + ":" + this.port;
  5067. const addr = prefix + url;
  5068. //console.log("POST addr: '" + addr + "'");
  5069. req.open("POST", addr);
  5070. req.send(data);
  5071. }
  5072. LFSA.prototype.requestFileList = function(dir, successCallback, failureCallback)
  5073. {
  5074. this.post(
  5075. "/list",
  5076. dir,
  5077. function(response)
  5078. {
  5079. var json = JSON.parse(response);
  5080. successCallback(json);
  5081. },
  5082. failureCallback
  5083. );
  5084. }
  5085. LFSA.prototype.requestFile = function(path, successCallback, failureCallback)
  5086. {
  5087. this.post(
  5088. "/read",
  5089. path,
  5090. successCallback,
  5091. failureCallback
  5092. );
  5093. }
  5094. LFSA.prototype.base64encode = function(str)
  5095. {
  5096. // Topic: javascript atob returning 'String contains an invalid character'
  5097. // Source: https://stackoverflow.com/a/9786592
  5098. return btoa(unescape(encodeURIComponent(str)));
  5099. }
  5100. LFSA.prototype.saveFile = function(path, contents, successCallback, failureCallback)
  5101. {
  5102. var data = {};
  5103. data["path"] = path;
  5104. data["contents"] = this.base64encode(contents);
  5105. var datastr = JSON.stringify(data);
  5106. this.post(
  5107. "/write",
  5108. datastr,
  5109. successCallback,
  5110. failureCallback
  5111. );
  5112. }
  5113. // FileOperation class is used for bulk read/write LFSA operations.
  5114. function FileOperation()
  5115. {
  5116. this.path = null;
  5117. this.contents = null;
  5118. this.isSuccessful = null;
  5119. }
  5120. LFSA.prototype.requestFiles = function(operations, processCallback, completionCallback)
  5121. {
  5122. var self = this;
  5123. // Prepare operation queue.
  5124. var queue = [];
  5125. for (var id in operations)
  5126. {
  5127. var operation = operations[id];
  5128. queue.push(operation);
  5129. }
  5130. // Currently processed operation.
  5131. var operation = null;
  5132. // Function to read single file.
  5133. function process()
  5134. {
  5135. // Continue.
  5136. if (queue.length > 0)
  5137. {
  5138. operation = queue.shift();
  5139. self.requestFile(operation.path, success, failure);
  5140. if (processCallback)
  5141. {
  5142. processCallback();
  5143. }
  5144. }
  5145. // Interrupt.
  5146. else
  5147. {
  5148. if (completionCallback)
  5149. {
  5150. completionCallback();
  5151. }
  5152. }
  5153. }
  5154. var success = function(contents)
  5155. {
  5156. operation.contents = contents;
  5157. operation.isSuccessful = true;
  5158. process();
  5159. }
  5160. var failure = function()
  5161. {
  5162. operation.isSuccessful = false;
  5163. process();
  5164. }
  5165. // Start processing.
  5166. process();
  5167. }
  5168. LFSA.prototype.saveFiles = function(operations, processCallback, completionCallback)
  5169. {
  5170. var self = this;
  5171. // Prepare operation queue.
  5172. var queue = [];
  5173. for (var id in operations)
  5174. {
  5175. var operation = operations[id];
  5176. queue.push(operation);
  5177. }
  5178. // Currently processed operation.
  5179. var operation = null;
  5180. // Function to save single file.
  5181. function process()
  5182. {
  5183. // Continue.
  5184. if (queue.length > 0)
  5185. {
  5186. operation = queue.shift();
  5187. self.saveFile(operation.path, operation.contents, success, failure);
  5188. if (processCallback)
  5189. {
  5190. processCallback();
  5191. }
  5192. }
  5193. // Interrupt.
  5194. else
  5195. {
  5196. if (completionCallback)
  5197. {
  5198. completionCallback();
  5199. }
  5200. }
  5201. }
  5202. var success = function()
  5203. {
  5204. operation.isSuccessful = true;
  5205. process();
  5206. }
  5207. var failure = function()
  5208. {
  5209. operation.isSuccessful = false;
  5210. process();
  5211. }
  5212. // Start processing.
  5213. process();
  5214. }
  5215. <!-- Common -->
  5216. // NewsItem class.
  5217. function NewsItem()
  5218. {
  5219. this.date = null;
  5220. this.slug = null;
  5221. this.contents = "";
  5222. // Currently unused properties.
  5223. this.lang = null;
  5224. this.category = null;
  5225. }
  5226. // PreviewPage class.
  5227. function PreviewPage()
  5228. {
  5229. this.items = [];
  5230. this.previews = [];
  5231. }
  5232. <!-- Cfg -->
  5233. // Cfg class.
  5234. function Cfg()
  5235. {
  5236. this.lfsa = null;
  5237. this.cfg = {};
  5238. this.cfgChanged = new Reporter();
  5239. this.exists = false;
  5240. this.existsChanged = new Reporter();
  5241. this.saved = new Reporter();
  5242. }
  5243. // Cfg's startup sequence.
  5244. Cfg.prototype.run = function()
  5245. {
  5246. var self = this;
  5247. this.checkExistence();
  5248. this.existsChanged.subscribe(function(){
  5249. self.LOG("`cfg` file exists: '" + self.exists + "'");
  5250. });
  5251. this.existsChanged.subscribe(function(){
  5252. self.load();
  5253. });
  5254. this.cfgChanged.subscribe(function(){
  5255. self.display();
  5256. });
  5257. this.saved.subscribe(function(){
  5258. self.load();
  5259. });
  5260. this.saved.subscribe(function(){
  5261. self.LOG("Saved configuration");
  5262. });
  5263. this.cfgChanged.subscribe(function(){
  5264. self.cfg["output"] = self.cfg["input"];
  5265. });
  5266. }
  5267. Cfg.prototype.LOG = function(message)
  5268. {
  5269. LOG("Cfg " + message);
  5270. }
  5271. Cfg.prototype.checkExistence = function()
  5272. {
  5273. var self = this;
  5274. var success = function(fileList)
  5275. {
  5276. var exists = fileExists("cfg", fileList);
  5277. if (!exists)
  5278. {
  5279. self.LOG("ERROR `cfg` file does not exist");
  5280. return;
  5281. }
  5282. // Report.
  5283. self.exists = true;
  5284. self.existsChanged.report();
  5285. }
  5286. var failure = function()
  5287. {
  5288. self.LOG("ERROR Could not check if `cfg` file exists because LFSA request failed");
  5289. }
  5290. this.lfsa.requestFileList("", success, failure);
  5291. }
  5292. Cfg.prototype.load = function()
  5293. {
  5294. var self = this;
  5295. var success = function(contents)
  5296. {
  5297. self.cfg = parseINI(contents);
  5298. self.cfgChanged.report();
  5299. }
  5300. var failure = function()
  5301. {
  5302. self.LOG("ERROR Could not read `cfg` file");
  5303. }
  5304. this.lfsa.requestFile("cfg", success, failure);
  5305. }
  5306. Cfg.prototype.display = function()
  5307. {
  5308. var input = document.getElementById("input");
  5309. input.value = this.cfg["input"];
  5310. var item = document.getElementById("item");
  5311. item.value = this.cfg["item"];
  5312. var preview = document.getElementById("preview");
  5313. preview.value = this.cfg["preview"];
  5314. var index = document.getElementById("index");
  5315. index.value = this.cfg["index"];
  5316. var paginationPrev = document.getElementById("paginationPrev");
  5317. paginationPrev.value = this.cfg["paginationPrev"];
  5318. var paginationNext = document.getElementById("paginationNext");
  5319. paginationNext.value = this.cfg["paginationNext"];
  5320. var paginationPrevNext = document.getElementById("paginationPrevNext");
  5321. paginationPrevNext.value = this.cfg["paginationPrevNext"];
  5322. var previewSize = document.getElementById("previewSize");
  5323. previewSize.value = this.cfg["previewSize"];
  5324. var previewEnding = document.getElementById("previewEnding");
  5325. previewEnding.value = this.cfg["previewEnding"];
  5326. var previewsPerPage = document.getElementById("previewsPerPage");
  5327. previewsPerPage.value = this.cfg["previewsPerPage"];
  5328. var previewPageBaseName = document.getElementById("previewPageBaseName");
  5329. previewPageBaseName.value = this.cfg["previewPageBaseName"];
  5330. }
  5331. Cfg.prototype.save = function()
  5332. {
  5333. var cfgFile = "";
  5334. this.LOG("Saving configuration into `cfg` file...");
  5335. var input = document.getElementById("input");
  5336. cfgFile += "input = " + input.value + "\n";
  5337. var item = document.getElementById("item");
  5338. cfgFile += "item = " + item.value + "\n";
  5339. var preview = document.getElementById("preview");
  5340. cfgFile += "preview = " + preview.value + "\n";
  5341. var index = document.getElementById("index");
  5342. cfgFile += "index = " + index.value + "\n";
  5343. var paginationPrev = document.getElementById("paginationPrev");
  5344. cfgFile += "paginationPrev = " + paginationPrev.value + "\n";
  5345. var paginationNext = document.getElementById("paginationNext");
  5346. cfgFile += "paginationNext = " + paginationNext.value + "\n";
  5347. var paginationPrevNext = document.getElementById("paginationPrevNext");
  5348. cfgFile += "paginationPrevNext = " + paginationPrevNext.value + "\n";
  5349. var previewSize = document.getElementById("previewSize");
  5350. cfgFile += "previewSize = " + previewSize.value + "\n";
  5351. var previewEnding = document.getElementById("previewEnding");
  5352. cfgFile += "previewEnding = " + previewEnding.value + "\n";
  5353. var previewsPerPage = document.getElementById("previewsPerPage");
  5354. cfgFile += "previewsPerPage = " + previewsPerPage.value + "\n";
  5355. var previewPageBaseName = document.getElementById("previewPageBaseName");
  5356. cfgFile += "previewPageBaseName = " + previewPageBaseName.value + "\n";
  5357. var self = this;
  5358. var success = function()
  5359. {
  5360. self.saved.report();
  5361. }
  5362. var failure = function()
  5363. {
  5364. self.LOG("ERROR Could not save `cfg` file");
  5365. }
  5366. this.lfsa.saveFile("cfg", cfgFile, success, failure);
  5367. }
  5368. <!-- News -->
  5369. // News class.
  5370. function News()
  5371. {
  5372. var self = this;
  5373. this.cfg = null;
  5374. this.lfsa = null;
  5375. this.inputFiles = [];
  5376. this.inputFilesChanged = new Reporter();
  5377. this.markdownFiles = [];
  5378. this.markdownFilesChanged = new Reporter();
  5379. this.markdownFileContents = [];
  5380. this.markdownFileContentsChanged = new Reporter();
  5381. this.newsItems = [];
  5382. this.newsItemsChanged = new Reporter();
  5383. this.templatesToLocate = [
  5384. "item",
  5385. "preview",
  5386. "index",
  5387. "paginationPrev",
  5388. "paginationNext",
  5389. "paginationPrevNext"
  5390. ]
  5391. // Name -> File name.
  5392. this.templates = {};
  5393. // File name -> Name.
  5394. this.templateNames = {};
  5395. this.templatesChanged = new Reporter();
  5396. this.templateContents = {};
  5397. this.templateContentsChanged = new Reporter();
  5398. this.savedItems = new Reporter();
  5399. this.previews = [];
  5400. this.previewsChanged = new Reporter();
  5401. this.previewPages = [];
  5402. this.previewPagesChanged = new Reporter();
  5403. this.paginatedPreviewPages = [];
  5404. this.paginatedPreviewPagesChanged = new Reporter();
  5405. this.savedPreviewPages = new Reporter();
  5406. this.finished = new Reporter();
  5407. this.inputFilesChanged.subscribe(function(){
  5408. self.locateMarkdownFiles();
  5409. });
  5410. this.templateContentsChanged.subscribe(function(){
  5411. self.readMarkdownFiles();
  5412. });
  5413. this.markdownFileContentsChanged.subscribe(function(){
  5414. self.parseMarkdownFiles();
  5415. });
  5416. this.inputFilesChanged.subscribe(function(){
  5417. self.locateTemplates();
  5418. });
  5419. this.newsItemsChanged.subscribe(function(){
  5420. self.saveItems();
  5421. });
  5422. this.savedItems.subscribe(function(){
  5423. self.LOG("Saved news items");
  5424. });
  5425. this.savedItems.subscribe(function(){
  5426. self.generatePreviewsIfTemplatesExist();
  5427. });
  5428. this.previewsChanged.subscribe(function(){
  5429. self.LOG("Generated '" + self.previews.length + "' previews");
  5430. });
  5431. this.previewsChanged.subscribe(function(){
  5432. self.generatePreviewPages();
  5433. });
  5434. this.previewPagesChanged.subscribe(function(){
  5435. self.LOG("Generated '" + self.previewPages.length + "' preview pages");
  5436. });
  5437. this.previewPagesChanged.subscribe(function(){
  5438. self.paginatePreviewPages();
  5439. });
  5440. this.paginatedPreviewPagesChanged.subscribe(function(){
  5441. self.LOG("Paginated preview pages");
  5442. });
  5443. this.paginatedPreviewPagesChanged.subscribe(function(){
  5444. self.savePreviewPages();
  5445. });
  5446. this.savedPreviewPages.subscribe(function(){
  5447. self.LOG("Saved preview pages");
  5448. });
  5449. this.templatesChanged.subscribe(function(){
  5450. self.generateUponCounter(2);
  5451. });
  5452. this.markdownFilesChanged.subscribe(function(){
  5453. self.generateUponCounter(2);
  5454. });
  5455. this.savedPreviewPages.subscribe(function(){
  5456. self.finished.report();
  5457. });
  5458. }
  5459. News.prototype.run = function()
  5460. {
  5461. var self = this;
  5462. }
  5463. News.prototype.generate = function()
  5464. {
  5465. this.generationCounter = 0;
  5466. this.locateInputFiles();
  5467. }
  5468. News.prototype.generateUponCounter = function(limit)
  5469. {
  5470. this.generationCounter += 1;
  5471. if (this.generationCounter == limit)
  5472. {
  5473. this.readTemplates();
  5474. }
  5475. }
  5476. News.prototype.LOG = function(message)
  5477. {
  5478. LOG("News " + message);
  5479. }
  5480. News.prototype.locateInputFiles = function()
  5481. {
  5482. var self = this;
  5483. var success = function(fileList)
  5484. {
  5485. self.inputFiles = fileList;
  5486. self.inputFilesChanged.report();
  5487. }
  5488. var failure = function()
  5489. {
  5490. self.LOG("ERROR Could not locate input files because LFSA request failed");
  5491. }
  5492. var path = this.cfg["input"];
  5493. this.lfsa.requestFileList(path, success, failure);
  5494. }
  5495. News.prototype.locateMarkdownFiles = function()
  5496. {
  5497. var files = [];
  5498. for (var id in this.inputFiles)
  5499. {
  5500. var file = this.inputFiles[id];
  5501. if (file.path.endsWith(".md"))
  5502. {
  5503. files.push(file.path);
  5504. }
  5505. }
  5506. if (files.length == 0)
  5507. {
  5508. this.LOG("ERROR No markdown files were found");
  5509. }
  5510. // Sort by name descending, effectively making latest news the first ones.
  5511. files.sort();
  5512. files.reverse();
  5513. // Report.
  5514. this.markdownFiles = files;
  5515. this.markdownFilesChanged.report();
  5516. }
  5517. News.prototype.readMarkdownFiles = function()
  5518. {
  5519. var self = this;
  5520. // Prepare.
  5521. var dir = this.cfg["input"] + "/";
  5522. var operations = [];
  5523. for (var id in this.markdownFiles)
  5524. {
  5525. var fileName = this.markdownFiles[id];
  5526. var path = dir + fileName;
  5527. var operation = new FileOperation();
  5528. operation.path = path;
  5529. operations.push(operation);
  5530. }
  5531. var completion = function()
  5532. {
  5533. var fileContents = [];
  5534. for (var id in operations)
  5535. {
  5536. var operation = operations[id];
  5537. fileContents.push(operation.contents);
  5538. }
  5539. self.LOG("Read '" + operations.length + "' markdown files");
  5540. self.markdownFileContents = fileContents;
  5541. self.markdownFileContentsChanged.report();
  5542. }
  5543. // Read.
  5544. this.lfsa.requestFiles(operations, null, completion);
  5545. }
  5546. News.prototype.parseMarkdownFiles = function()
  5547. {
  5548. var items = []
  5549. for (var id in this.markdownFileContents)
  5550. {
  5551. var fileName = this.markdownFiles[id];
  5552. var contents = this.markdownFileContents[id];
  5553. var item = this.parseNewsItem(contents, fileName);
  5554. items.push(item);
  5555. }
  5556. this.LOG("Parsed '" + items.length + "' markdown files");
  5557. // Report.
  5558. this.newsItems = items;
  5559. this.newsItemsChanged.report();
  5560. }
  5561. News.prototype.parseNewsItem = function(contents, fileName)
  5562. {
  5563. var newsItem = new NewsItem();
  5564. var lines = contents.split(/\r?\n/);
  5565. for (var id in lines)
  5566. {
  5567. var ln = lines[id];
  5568. if (ln.startsWith("Title:"))
  5569. {
  5570. newsItem.title = ln.replace("Title:", "").trim();
  5571. }
  5572. else if (ln.startsWith("Date:"))
  5573. {
  5574. newsItem.date = ln.replace("Date:", "").trim();
  5575. }
  5576. else if (ln.startsWith("Slug:"))
  5577. {
  5578. newsItem.slug = ln.replace("Slug:", "").trim();
  5579. }
  5580. else if (ln.startsWith("Category:"))
  5581. {
  5582. newsItem.category = ln.replace("Category:", "").trim();
  5583. }
  5584. else if (ln.startsWith("Lang:"))
  5585. {
  5586. newsItem.lang = ln.replace("Lang:", "").trim();
  5587. }
  5588. // Contents.
  5589. else
  5590. {
  5591. newsItem.contents += ln + "\n";
  5592. }
  5593. }
  5594. return newsItem;
  5595. }
  5596. News.prototype.locateTemplates = function()
  5597. {
  5598. var self = this;
  5599. var templates = {};
  5600. var templateNames = {};
  5601. function locateTemplate(name)
  5602. {
  5603. var fileName = self.cfg[name];
  5604. if (fileExists(fileName, self.inputFiles))
  5605. {
  5606. templates[name] = fileName;
  5607. templateNames[fileName] = name;
  5608. }
  5609. else
  5610. {
  5611. this.LOG("WARNING `" + name + "` template is missing");
  5612. }
  5613. }
  5614. for (var id in this.templatesToLocate)
  5615. {
  5616. var name = this.templatesToLocate[id];
  5617. locateTemplate(name);
  5618. }
  5619. // Report.
  5620. this.templates = templates;
  5621. this.templateNames = templateNames;
  5622. this.templatesChanged.report();
  5623. }
  5624. News.prototype.readTemplates = function()
  5625. {
  5626. var self = this;
  5627. // Prepare.
  5628. var dir = this.cfg["input"] + "/";
  5629. var operations = [];
  5630. for (var name in this.templates)
  5631. {
  5632. var fileName = this.templates[name];
  5633. var path = dir + fileName;
  5634. var operation = new FileOperation();
  5635. operation.path = path;
  5636. operations.push(operation);
  5637. }
  5638. var completion = function()
  5639. {
  5640. var templateContents = {};
  5641. for (var id in operations)
  5642. {
  5643. var operation = operations[id];
  5644. var fileName = operation.path.replace(dir, "")
  5645. var name = self.templateNames[fileName];
  5646. templateContents[name] = operation.contents;
  5647. }
  5648. self.LOG("Read '" + operations.length + "' templates");
  5649. self.templateContents = templateContents;
  5650. self.templateContentsChanged.report();
  5651. }
  5652. // Read.
  5653. this.lfsa.requestFiles(operations, null, completion);
  5654. }
  5655. News.prototype.saveItems = function()
  5656. {
  5657. var self = this;
  5658. // Prepare.
  5659. var operations = [];
  5660. for (var id in this.newsItems)
  5661. {
  5662. var newsItem = this.newsItems[id];
  5663. var fileName = newsItem.slug + ".html";
  5664. var contents = this.newsItemContents(newsItem, fileName)
  5665. var path = this.cfg["output"] + "/" + fileName;
  5666. var operation = new FileOperation();
  5667. operation.path = path;
  5668. operation.contents = contents;
  5669. operations.push(operation);
  5670. }
  5671. // Save.
  5672. this.lfsa.saveFiles(
  5673. operations,
  5674. null,
  5675. function()
  5676. {
  5677. self.savedItems.report();
  5678. }
  5679. );
  5680. }
  5681. News.prototype.newsItemContents = function(item, fileName)
  5682. {
  5683. var contents = this.templateContents["item"];
  5684. contents = contents.replace(/PSKOV_ITEM_TITLE/g, item.title);
  5685. contents = contents.replace(/PSKOV_ITEM_DATE/g, item.date);
  5686. contents = contents.replace(/PSKOV_ITEM_URL/g, fileName);
  5687. // Convert Markdown to HTML.
  5688. var converter = new showdown.Converter();
  5689. converter.setOption("tables", true);
  5690. var html = converter.makeHtml(item.contents);
  5691. contents = contents.replace(/PSKOV_ITEM_CONTENTS/g, html);
  5692. return contents;
  5693. }
  5694. News.prototype.generatePreviews = function()
  5695. {
  5696. var previews = []
  5697. for (var id in this.newsItems)
  5698. {
  5699. var item = this.newsItems[id];
  5700. var preview = this.newsItemPreview(item);
  5701. previews.push(preview);
  5702. }
  5703. this.previews = previews;
  5704. this.previewsChanged.report();
  5705. }
  5706. News.prototype.lineIsLink = function(ln)
  5707. {
  5708. return ln.search(/^\[.+\]:.+/) != -1;
  5709. }
  5710. News.prototype.newsItemPreview = function(newsItem)
  5711. {
  5712. // 1. Get news item content lines that have approximately `previewSize` characters.
  5713. // 2. Append `previewEnding` string.
  5714. // 3. Append links section.
  5715. // 4. Convert resulting preview into HTML.
  5716. // Contents section.
  5717. var contents = "";
  5718. const limit = this.cfg["previewSize"];
  5719. var lines = newsItem.contents.split(/\r?\n/);
  5720. for (var id in lines)
  5721. {
  5722. var ln = lines[id];
  5723. if (!this.lineIsLink(ln))
  5724. {
  5725. contents += "\n" + ln;
  5726. if (contents.length >= limit)
  5727. {
  5728. break;
  5729. }
  5730. }
  5731. }
  5732. // Ending.
  5733. contents += this.cfg["previewEnding"];
  5734. // Links section.
  5735. var links = "";
  5736. for (var id in lines)
  5737. {
  5738. var ln = lines[id];
  5739. if (this.lineIsLink(ln))
  5740. {
  5741. links += ln + "\n";
  5742. }
  5743. }
  5744. // Convert.
  5745. var preview = contents + "\n\n\n" + links;
  5746. var converter = new showdown.Converter();
  5747. converter.setOption("tables", true);
  5748. var html = converter.makeHtml(preview);
  5749. return html;
  5750. }
  5751. News.prototype.generatePreviewsIfTemplatesExist = function()
  5752. {
  5753. // Find out if any of the templates does not exist.
  5754. var ok = true;
  5755. for (var id in this.templatesToLocate)
  5756. {
  5757. var name = this.templatesToLocate[id];
  5758. if (!(name in this.templates))
  5759. {
  5760. ok = false;
  5761. break;
  5762. }
  5763. }
  5764. // Generate previews if all templates exist.
  5765. if (ok)
  5766. {
  5767. this.generatePreviews();
  5768. }
  5769. // Report finish otherwise.
  5770. else
  5771. {
  5772. this.finished.report();
  5773. }
  5774. }
  5775. News.prototype.previewPageName = function(id)
  5776. {
  5777. /* Generate file names like this:
  5778. * <basename>.html for id = 0
  5779. * <basename>2.html for id = 1
  5780. * <basename>3.html for id = 2
  5781. * etc..
  5782. */
  5783. var result = this.cfg["previewPageBaseName"];
  5784. if (id > 0)
  5785. {
  5786. result += Number(id) + 1;
  5787. }
  5788. return result + ".html";
  5789. }
  5790. News.prototype.generatePreviewPages = function()
  5791. {
  5792. var previewPages = [];
  5793. var pages = this.splitPreviewsIntoPages();
  5794. for (var id in pages)
  5795. {
  5796. var page = pages[id];
  5797. var previewPage = this.generatePreviewPage(page);
  5798. previewPages.push(previewPage);
  5799. }
  5800. this.previewPages = previewPages;
  5801. this.previewPagesChanged.report();
  5802. }
  5803. News.prototype.generatePreviewPage = function(page)
  5804. {
  5805. var previewsContents = "";
  5806. for (var id in page.items)
  5807. {
  5808. var item = page.items[id];
  5809. var preview = page.previews[id];
  5810. var html = this.convertPreviewToHTML(preview, item);
  5811. previewsContents += html;
  5812. }
  5813. var contents = this.templateContents["index"];
  5814. contents = contents.replace(/PSKOV_PREVIEWS/g, previewsContents);
  5815. return contents;
  5816. }
  5817. News.prototype.convertPreviewToHTML = function(preview, item)
  5818. {
  5819. var contents = this.templateContents["preview"];
  5820. contents = contents.replace(/PSKOV_ITEM_TITLE/g, item.title);
  5821. contents = contents.replace(/PSKOV_ITEM_DATE/g, item.date);
  5822. var fileName = item.slug + ".html";
  5823. contents = contents.replace(/PSKOV_ITEM_URL/g, fileName);
  5824. // Convert Markdown to HTML.
  5825. var converter = new showdown.Converter();
  5826. converter.setOption("tables", true);
  5827. var html = converter.makeHtml(preview);
  5828. contents = contents.replace(/PSKOV_PREVIEW/g, html);
  5829. return contents;
  5830. }
  5831. News.prototype.splitPreviewsIntoPages = function()
  5832. {
  5833. var pages = [];
  5834. var items = [];
  5835. var previews = [];
  5836. function createPage()
  5837. {
  5838. var page = new PreviewPage();
  5839. page.items = items.slice();
  5840. page.previews = previews.slice();
  5841. pages.push(page);
  5842. items = [];
  5843. previews = [];
  5844. }
  5845. var previewsPerPage = this.cfg["previewsPerPage"];
  5846. for (var id in this.newsItems)
  5847. {
  5848. var item = this.newsItems[id];
  5849. var preview = this.previews[id];
  5850. items.push(item);
  5851. previews.push(preview);
  5852. // Paginate.
  5853. if (items.length == previewsPerPage)
  5854. {
  5855. createPage();
  5856. }
  5857. }
  5858. // Create last page.
  5859. if (items.length > 0)
  5860. {
  5861. createPage();
  5862. }
  5863. return pages;
  5864. }
  5865. News.prototype.paginatePreviewPages = function()
  5866. {
  5867. var paginatedPreviewPages = [];
  5868. var count = this.previewPages.length;
  5869. for (var id in this.previewPages)
  5870. {
  5871. var pageId = Number(id);
  5872. var contents = this.previewPages[id];
  5873. var prevPageExists = (pageId > 0);
  5874. var nextPageExists = (pageId + 1 < count);
  5875. var paginationSection = null;
  5876. if (prevPageExists && nextPageExists)
  5877. {
  5878. var prevURL = this.previewPageName(pageId - 1);
  5879. var nextURL = this.previewPageName(pageId + 1);
  5880. paginationSection = this.templateContents["paginationPrevNext"];
  5881. paginationSection = paginationSection.replace(/PSKOV_PREV_PAGE_URL/g, prevURL);
  5882. paginationSection = paginationSection.replace(/PSKOV_NEXT_PAGE_URL/g, nextURL);
  5883. }
  5884. else if (prevPageExists)
  5885. {
  5886. var prevURL = this.previewPageName(pageId - 1);
  5887. paginationSection = this.templateContents["paginationPrev"];
  5888. paginationSection = paginationSection.replace(/PSKOV_PREV_PAGE_URL/g, prevURL);
  5889. }
  5890. else if (nextPageExists)
  5891. {
  5892. var nextURL = this.previewPageName(pageId + 1);
  5893. paginationSection = this.templateContents["paginationNext"];
  5894. paginationSection = paginationSection.replace(/PSKOV_NEXT_PAGE_URL/g, nextURL);
  5895. }
  5896. contents = contents.replace(/PSKOV_PAGINATION/g, paginationSection);
  5897. contents = contents.replace(/PSKOV_PAGE_ID/g, pageId + 1);
  5898. contents = contents.replace(/PSKOV_PAGES_COUNT/g, count);
  5899. var url = this.previewPageName(pageId);
  5900. contents = contents.replace(/PSKOV_INDEX_URL/g, url);
  5901. paginatedPreviewPages.push(contents);
  5902. }
  5903. this.paginatedPreviewPages = paginatedPreviewPages;
  5904. this.paginatedPreviewPagesChanged.report();
  5905. }
  5906. News.prototype.savePreviewPages = function()
  5907. {
  5908. var self = this;
  5909. // Prepare.
  5910. var dir = this.cfg["output"] + "/";
  5911. var operations = [];
  5912. for (var id in this.paginatedPreviewPages)
  5913. {
  5914. var fileName = this.previewPageName(id);
  5915. var path = dir + fileName;
  5916. var contents = this.paginatedPreviewPages[id];
  5917. var operation = new FileOperation();
  5918. operation.path = path;
  5919. operation.contents = contents;
  5920. operations.push(operation);
  5921. }
  5922. // Save.
  5923. this.lfsa.saveFiles(
  5924. operations,
  5925. null,
  5926. function()
  5927. {
  5928. self.savedPreviewPages.report();
  5929. }
  5930. );
  5931. }
  5932. <!-- Tool -->
  5933. // Tool class.
  5934. function Tool()
  5935. {
  5936. var self = this;
  5937. this.lfsa = new LFSA();
  5938. this.cfg = new Cfg();
  5939. this.cfg.lfsa = this.lfsa;
  5940. this.news = new News();
  5941. this.news.finished.subscribe(function(){
  5942. // Continue processing.
  5943. self.processNewsGeneration();
  5944. });
  5945. }
  5946. // Tool's startup sequence.
  5947. Tool.prototype.run = function()
  5948. {
  5949. var self = this;
  5950. this.refreshLFSAPath();
  5951. this.cfg.run();
  5952. // Execute news startup sequence each time cfg is changed.
  5953. this.cfg.cfgChanged.subscribe(function(){
  5954. self.news.lfsa = self.lfsa;
  5955. self.news.cfg = self.cfg.cfg;
  5956. self.news.run();
  5957. });
  5958. }
  5959. Tool.prototype.refreshLFSAPath = function()
  5960. {
  5961. var lfsaPath = document.getElementById("lfsaPath");
  5962. var success = function(response)
  5963. {
  5964. lfsaPath.innerHTML = response;
  5965. }
  5966. var failure = function()
  5967. {
  5968. lfsaPath.innerHTML = "<span class='error'>Error</span>";
  5969. }
  5970. this.lfsa.requestPath(success, failure);
  5971. }
  5972. Tool.prototype.saveCfg = function()
  5973. {
  5974. this.cfg.save();
  5975. }
  5976. Tool.prototype.generateNews = function()
  5977. {
  5978. // Keep original 'input' to restore it after generation.
  5979. this.originalInput = this.cfg.cfg["input"];
  5980. // Get news dirs by splitting input by ";".
  5981. this.newsDirs = this.cfg.cfg["input"].split(/;/);
  5982. // Start processing.
  5983. this.processNewsGeneration();
  5984. }
  5985. Tool.prototype.processNewsGeneration = function()
  5986. {
  5987. if (this.newsDirs.length > 0)
  5988. {
  5989. var dir = this.newsDirs.shift();
  5990. LOG("Generating news for directory '" + dir + "'");
  5991. this.cfg.cfg["input"] = dir;
  5992. this.cfg.cfg["output"] = this.cfg.cfg["input"];
  5993. this.news.generate();
  5994. }
  5995. else
  5996. {
  5997. LOG("Finished generating news for all directories");
  5998. // Restore original 'input'.
  5999. this.cfg.cfg["input"] = this.originalInput;
  6000. // Delete temorary 'output'.
  6001. delete this.cfg.cfg["output"];
  6002. }
  6003. }
  6004. <!-- Startup -->
  6005. window.pskovTool = new Tool();
  6006. window.pskovTool.run()
  6007. </script>
  6008. </body>
  6009. </html>