No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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