markdeep.js 219 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202
  1. /**
  2. markdeep.js
  3. Version 0.23
  4. Copyright 2015-2017, Morgan McGuire, http://casual-effects.com
  5. All rights reserved.
  6. -------------------------------------------------------------
  7. See http://casual-effects.com/markdeep for documentation on how to
  8. use this script make your plain text documents render beautifully
  9. in web browsers.
  10. Markdeep was created by Morgan McGuire. It extends the work of:
  11. - John Gruber's original Markdown
  12. - Ben Hollis' Maruku Markdown dialect
  13. - Michel Fortin's Markdown Extras dialect
  14. - Ivan Sagalaev's highlight.js
  15. - Contributors to the above open source projects
  16. -------------------------------------------------------------
  17. You may use, extend, and redistribute this code under the terms of
  18. the BSD license at https://opensource.org/licenses/BSD-2-Clause.
  19. Contains highlight.js (https://github.com/isagalaev/highlight.js) by Ivan
  20. Sagalaev, which is used for code highlighting. (BSD 3-clause license)
  21. */
  22. /**See http://casual-effects.com/markdeep for @license and documentation.
  23. markdeep.min.js 0.23 (C) 2017 Morgan McGuire
  24. highlight.min.js 9.5.0 (C) 2016 Ivan Sagalaev https://highlightjs.org/*/
  25. (function() {
  26. 'use strict';
  27. var MARKDEEP_FOOTER = '<div class="markdeepFooter"><i>formatted by <a href="http://casual-effects.com/markdeep" style="color:#999">Markdeep&nbsp;0.23&nbsp;&nbsp;</a></i><div style="display:inline-block;font-size:13px;font-family:\'Times New Roman\',serif;vertical-align:middle;transform:translate(-3px,-1px)rotate(135deg);">&#x2712;</div></div>';
  28. // For minification. This is admittedly scary.
  29. var _ = String.prototype;
  30. _.rp = _.replace;
  31. _.ss = _.substring;
  32. // Regular expression version of String.indexOf
  33. _.regexIndexOf = function(regex, startpos) {
  34. var i = this.ss(startpos || 0).search(regex);
  35. return (i >= 0) ? (i + (startpos || 0)) : i;
  36. }
  37. /** Enable for debugging to view character bounds in diagrams */
  38. var DEBUG_SHOW_GRID = false;
  39. /** Overlay the non-empty characters of the original source in diagrams */
  40. var DEBUG_SHOW_SOURCE = DEBUG_SHOW_GRID;
  41. /** Use to suppress passing through text in diagrams */
  42. var DEBUG_HIDE_PASSTHROUGH = DEBUG_SHOW_SOURCE;
  43. /** In pixels of lines in diagrams */
  44. var STROKE_WIDTH = 2;
  45. /** A box of these denotes a diagram */
  46. var DIAGRAM_MARKER = '*';
  47. // http://stackoverflow.com/questions/1877475/repeat-character-n-times
  48. // ECMAScript 6 has a String.repeat method, but that's not available everywhere
  49. var DIAGRAM_START = Array(5 + 1).join(DIAGRAM_MARKER);
  50. /** attribs are optional */
  51. function entag(tag, content, attribs) {
  52. return '<' + tag + (attribs ? ' ' + attribs : '') + '>' + content + '</' + tag + '>';
  53. }
  54. function measureFontSize(fontStack) {
  55. try {
  56. var canvas = document.createElement('canvas');
  57. var ctx = canvas.getContext('2d');
  58. ctx.font = '10pt ' + fontStack;
  59. return ctx.measureText("M").width;
  60. } catch (e) {
  61. // Needed for Firefox include...iframe canvas doesn't work for some reason
  62. return 10;
  63. }
  64. }
  65. /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */
  66. !function(e){var n="object"==typeof window&&window||"object"==typeof self&&self;"undefined"!=typeof exports?e(exports):n&&(n.hljs=e({}),"function"==typeof define&&define.amd&&define([],function(){return n.hljs}))}(function(e){function n(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function t(e){return e.nodeName.toLowerCase()}function r(e,n){var t=e&&e.exec(n);return t&&0===t.index}function a(e){return k.test(e)}function i(e){var n,t,r,i,o=e.className+" ";if(o+=e.parentNode?e.parentNode.className:"",t=B.exec(o))return w(t[1])?t[1]:"no-highlight";for(o=o.split(/\s+/),n=0,r=o.length;r>n;n++)if(i=o[n],a(i)||w(i))return i}function o(e){var n,t={},r=Array.prototype.slice.call(arguments,1);for(n in e)t[n]=e[n];return r.forEach(function(e){for(n in e)t[n]=e[n]}),t}function u(e){var n=[];return function r(e,a){for(var i=e.firstChild;i;i=i.nextSibling)3===i.nodeType?a+=i.nodeValue.length:1===i.nodeType&&(n.push({event:"start",offset:a,node:i}),a=r(i,a),t(i).match(/br|hr|img|input/)||n.push({event:"stop",offset:a,node:i}));return a}(e,0),n}function c(e,r,a){function i(){return e.length&&r.length?e[0].offset!==r[0].offset?e[0].offset<r[0].offset?e:r:"start"===r[0].event?e:r:e.length?e:r}function o(e){function r(e){return" "+e.nodeName+'="'+n(e.value).replace('"',"&quot;")+'"'}s+="<"+t(e)+E.map.call(e.attributes,r).join("")+">"}function u(e){s+="</"+t(e)+">"}function c(e){("start"===e.event?o:u)(e.node)}for(var l=0,s="",f=[];e.length||r.length;){var g=i();if(s+=n(a.substring(l,g[0].offset)),l=g[0].offset,g===e){f.reverse().forEach(u);do c(g.splice(0,1)[0]),g=i();while(g===e&&g.length&&g[0].offset===l);f.reverse().forEach(o)}else"start"===g[0].event?f.push(g[0].node):f.pop(),c(g.splice(0,1)[0])}return s+n(a.substr(l))}function l(e){return e.v&&!e.cached_variants&&(e.cached_variants=e.v.map(function(n){return o(e,{v:null},n)})),e.cached_variants||e.eW&&[o(e)]||[e]}function s(e){function n(e){return e&&e.source||e}function t(t,r){return new RegExp(n(t),"m"+(e.cI?"i":"")+(r?"g":""))}function r(a,i){if(!a.compiled){if(a.compiled=!0,a.k=a.k||a.bK,a.k){var o={},u=function(n,t){e.cI&&(t=t.toLowerCase()),t.split(" ").forEach(function(e){var t=e.split("|");o[t[0]]=[n,t[1]?Number(t[1]):1]})};"string"==typeof a.k?u("keyword",a.k):x(a.k).forEach(function(e){u(e,a.k[e])}),a.k=o}a.lR=t(a.l||/\w+/,!0),i&&(a.bK&&(a.b="\\b("+a.bK.split(" ").join("|")+")\\b"),a.b||(a.b=/\B|\b/),a.bR=t(a.b),a.e||a.eW||(a.e=/\B|\b/),a.e&&(a.eR=t(a.e)),a.tE=n(a.e)||"",a.eW&&i.tE&&(a.tE+=(a.e?"|":"")+i.tE)),a.i&&(a.iR=t(a.i)),null==a.r&&(a.r=1),a.c||(a.c=[]),a.c=Array.prototype.concat.apply([],a.c.map(function(e){return l("self"===e?a:e)})),a.c.forEach(function(e){r(e,a)}),a.starts&&r(a.starts,i);var c=a.c.map(function(e){return e.bK?"\\.?("+e.b+")\\.?":e.b}).concat([a.tE,a.i]).map(n).filter(Boolean);a.t=c.length?t(c.join("|"),!0):{exec:function(){return null}}}}r(e)}function f(e,t,a,i){function o(e,n){var t,a;for(t=0,a=n.c.length;a>t;t++)if(r(n.c[t].bR,e))return n.c[t]}function u(e,n){if(r(e.eR,n)){for(;e.endsParent&&e.parent;)e=e.parent;return e}return e.eW?u(e.parent,n):void 0}function c(e,n){return!a&&r(n.iR,e)}function l(e,n){var t=N.cI?n[0].toLowerCase():n[0];return e.k.hasOwnProperty(t)&&e.k[t]}function p(e,n,t,r){var a=r?"":I.classPrefix,i='<span class="'+a,o=t?"":C;return i+=e+'">',i+n+o}function h(){var e,t,r,a;if(!E.k)return n(k);for(a="",t=0,E.lR.lastIndex=0,r=E.lR.exec(k);r;)a+=n(k.substring(t,r.index)),e=l(E,r),e?(B+=e[1],a+=p(e[0],n(r[0]))):a+=n(r[0]),t=E.lR.lastIndex,r=E.lR.exec(k);return a+n(k.substr(t))}function d(){var e="string"==typeof E.sL;if(e&&!y[E.sL])return n(k);var t=e?f(E.sL,k,!0,x[E.sL]):g(k,E.sL.length?E.sL:void 0);return E.r>0&&(B+=t.r),e&&(x[E.sL]=t.top),p(t.language,t.value,!1,!0)}function b(){L+=null!=E.sL?d():h(),k=""}function v(e){L+=e.cN?p(e.cN,"",!0):"",E=Object.create(e,{parent:{value:E}})}function m(e,n){if(k+=e,null==n)return b(),0;var t=o(n,E);if(t)return t.skip?k+=n:(t.eB&&(k+=n),b(),t.rB||t.eB||(k=n)),v(t,n),t.rB?0:n.length;var r=u(E,n);if(r){var a=E;a.skip?k+=n:(a.rE||a.eE||(k+=n),b(),a.eE&&(k=n));do E.cN&&(L+=C),E.skip||(B+=E.r),E=E.parent;while(E!==r.parent);return r.starts&&v(r.starts,""),a.rE?0:n.length}if(c(n,E))throw new Error('Illegal lexeme "'+n+'" for mode "'+(E.cN||"<unnamed>")+'"');return k+=n,n.length||1}var N=w(e);if(!N)throw new Error('Unknown language: "'+e+'"');s(N);var R,E=i||N,x={},L="";for(R=E;R!==N;R=R.parent)R.cN&&(L=p(R.cN,"",!0)+L);var k="",B=0;try{for(var M,j,O=0;;){if(E.t.lastIndex=O,M=E.t.exec(t),!M)break;j=m(t.substring(O,M.index),M[0]),O=M.index+j}for(m(t.substr(O)),R=E;R.parent;R=R.parent)R.cN&&(L+=C);return{r:B,value:L,language:e,top:E}}catch(T){if(T.message&&-1!==T.message.indexOf("Illegal"))return{r:0,value:n(t)};throw T}}function g(e,t){t=t||I.languages||x(y);var r={r:0,value:n(e)},a=r;return t.filter(w).forEach(function(n){var t=f(n,e,!1);t.language=n,t.r>a.r&&(a=t),t.r>r.r&&(a=r,r=t)}),a.language&&(r.second_best=a),r}function p(e){return I.tabReplace||I.useBR?e.replace(M,function(e,n){return I.useBR&&"\n"===e?"<br>":I.tabReplace?n.replace(/\t/g,I.tabReplace):""}):e}function h(e,n,t){var r=n?L[n]:t,a=[e.trim()];return e.match(/\bhljs\b/)||a.push("hljs"),-1===e.indexOf(r)&&a.push(r),a.join(" ").trim()}function d(e){var n,t,r,o,l,s=i(e);a(s)||(I.useBR?(n=document.createElementNS("http://www.w3.org/1999/xhtml","div"),n.innerHTML=e.innerHTML.replace(/\n/g,"").replace(/<br[ \/]*>/g,"\n")):n=e,l=n.textContent,r=s?f(s,l,!0):g(l),t=u(n),t.length&&(o=document.createElementNS("http://www.w3.org/1999/xhtml","div"),o.innerHTML=r.value,r.value=c(t,u(o),l)),r.value=p(r.value),e.innerHTML=r.value,e.className=h(e.className,s,r.language),e.result={language:r.language,re:r.r},r.second_best&&(e.second_best={language:r.second_best.language,re:r.second_best.r}))}function b(e){I=o(I,e)}function v(){if(!v.called){v.called=!0;var e=document.querySelectorAll("pre code");E.forEach.call(e,d)}}function m(){addEventListener("DOMContentLoaded",v,!1),addEventListener("load",v,!1)}function N(n,t){var r=y[n]=t(e);r.aliases&&r.aliases.forEach(function(e){L[e]=n})}function R(){return x(y)}function w(e){return e=(e||"").toLowerCase(),y[e]||y[L[e]]}var E=[],x=Object.keys,y={},L={},k=/^(no-?highlight|plain|text)$/i,B=/\blang(?:uage)?-([\w-]+)\b/i,M=/((^(<[^>]+>|\t|)+|(?:\n)))/gm,C="</span>",I={classPrefix:"hljs-",tabReplace:null,useBR:!1,languages:void 0};return e.highlight=f,e.highlightAuto=g,e.fixMarkup=p,e.highlightBlock=d,e.configure=b,e.initHighlighting=v,e.initHighlightingOnLoad=m,e.registerLanguage=N,e.listLanguages=R,e.getLanguage=w,e.inherit=o,e.IR="[a-zA-Z]\\w*",e.UIR="[a-zA-Z_]\\w*",e.NR="\\b\\d+(\\.\\d+)?",e.CNR="(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)",e.BNR="\\b(0b[01]+)",e.RSR="!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~",e.BE={b:"\\\\[\\s\\S]",r:0},e.ASM={cN:"string",b:"'",e:"'",i:"\\n",c:[e.BE]},e.QSM={cN:"string",b:'"',e:'"',i:"\\n",c:[e.BE]},e.PWM={b:/\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/},e.C=function(n,t,r){var a=e.inherit({cN:"comment",b:n,e:t,c:[]},r||{});return a.c.push(e.PWM),a.c.push({cN:"doctag",b:"(?:TODO|FIXME|NOTE|BUG|XXX):",r:0}),a},e.CLCM=e.C("//","$"),e.CBCM=e.C("/\\*","\\*/"),e.HCM=e.C("#","$"),e.NM={cN:"number",b:e.NR,r:0},e.CNM={cN:"number",b:e.CNR,r:0},e.BNM={cN:"number",b:e.BNR,r:0},e.CSSNM={cN:"number",b:e.NR+"(%|em|ex|ch|rem|vw|vh|vmin|vmax|cm|mm|in|pt|pc|px|deg|grad|rad|turn|s|ms|Hz|kHz|dpi|dpcm|dppx)?",r:0},e.RM={cN:"regexp",b:/\//,e:/\/[gimuy]*/,i:/\n/,c:[e.BE,{b:/\[/,e:/\]/,r:0,c:[e.BE]}]},e.TM={cN:"title",b:e.IR,r:0},e.UTM={cN:"title",b:e.UIR,r:0},e.METHOD_GUARD={b:"\\.\\s*"+e.UIR,r:0},e});hljs.registerLanguage("objectivec",function(e){var t={cN:"built_in",b:"\\b(AV|CA|CF|CG|CI|CL|CM|CN|CT|MK|MP|MTK|MTL|NS|SCN|SK|UI|WK|XC)\\w+"},_={keyword:"int float while char export sizeof typedef const struct for union unsigned long volatile static bool mutable if do return goto void enum else break extern asm case short default double register explicit signed typename this switch continue wchar_t inline readonly assign readwrite self @synchronized id typeof nonatomic super unichar IBOutlet IBAction strong weak copy in out inout bycopy byref oneway __strong __weak __block __autoreleasing @private @protected @public @try @property @end @throw @catch @finally @autoreleasepool @synthesize @dynamic @selector @optional @required @encode @package @import @defs @compatibility_alias __bridge __bridge_transfer __bridge_retained __bridge_retain __covariant __contravariant __kindof _Nonnull _Nullable _Null_unspecified __FUNCTION__ __PRETTY_FUNCTION__ __attribute__ getter setter retain unsafe_unretained nonnull nullable null_unspecified null_resettable class instancetype NS_DESIGNATED_INITIALIZER NS_UNAVAILABLE NS_REQUIRES_SUPER NS_RETURNS_INNER_POINTER NS_INLINE NS_AVAILABLE NS_DEPRECATED NS_ENUM NS_OPTIONS NS_SWIFT_UNAVAILABLE NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_END NS_REFINED_FOR_SWIFT NS_SWIFT_NAME NS_SWIFT_NOTHROW NS_DURING NS_HANDLER NS_ENDHANDLER NS_VALUERETURN NS_VOIDRETURN",literal:"false true FALSE TRUE nil YES NO NULL",built_in:"BOOL dispatch_once_t dispatch_queue_t dispatch_sync dispatch_async dispatch_once"},i=/[a-zA-Z@][a-zA-Z0-9_]*/,n="@interface @class @protocol @implementation";return{aliases:["mm","objc","obj-c"],k:_,l:i,i:"</",c:[t,e.CLCM,e.CBCM,e.CNM,e.QSM,{cN:"string",v:[{b:'@"',e:'"',i:"\\n",c:[e.BE]},{b:"'",e:"[^\\\\]'",i:"[^\\\\][^']"}]},{cN:"meta",b:"#",e:"$",c:[{cN:"meta-string",v:[{b:'"',e:'"'},{b:"<",e:">"}]}]},{cN:"class",b:"("+n.split(" ").join("|")+")\\b",e:"({|$)",eE:!0,k:n,l:i,c:[e.UTM]},{b:"\\."+e.UIR,r:0}]}});hljs.registerLanguage("ini",function(e){var b={cN:"string",c:[e.BE],v:[{b:"'''",e:"'''",r:10},{b:'"""',e:'"""',r:10},{b:'"',e:'"'},{b:"'",e:"'"}]};return{aliases:["toml"],cI:!0,i:/\S/,c:[e.C(";","$"),e.HCM,{cN:"section",b:/^\s*\[+/,e:/\]+/},{b:/^[a-z0-9\[\]_-]+\s*=\s*/,e:"$",rB:!0,c:[{cN:"attr",b:/[a-z0-9\[\]_-]+/},{b:/=/,eW:!0,r:0,c:[{cN:"literal",b:/\bon|off|true|false|yes|no\b/},{cN:"variable",v:[{b:/\$[\w\d"][\w\d_]*/},{b:/\$\{(.*?)}/}]},b,{cN:"number",b:/([\+\-]+)?[\d]+_[\d_]+/},e.NM]}]}]}});hljs.registerLanguage("javascript",function(e){var r="[A-Za-z$_][0-9A-Za-z$_]*",t={keyword:"in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as",literal:"true false null undefined NaN Infinity",built_in:"eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect Promise"},a={cN:"number",v:[{b:"\\b(0[bB][01]+)"},{b:"\\b(0[oO][0-7]+)"},{b:e.CNR}],r:0},n={cN:"subst",b:"\\$\\{",e:"\\}",k:t,c:[]},c={cN:"string",b:"`",e:"`",c:[e.BE,n]};n.c=[e.ASM,e.QSM,c,a,e.RM];var s=n.c.concat([e.CBCM,e.CLCM]);return{aliases:["js","jsx"],k:t,c:[{cN:"meta",r:10,b:/^\s*['"]use (strict|asm)['"]/},{cN:"meta",b:/^#!/,e:/$/},e.ASM,e.QSM,c,e.CLCM,e.CBCM,a,{b:/[{,]\s*/,r:0,c:[{b:r+"\\s*:",rB:!0,r:0,c:[{cN:"attr",b:r,r:0}]}]},{b:"("+e.RSR+"|\\b(case|return|throw)\\b)\\s*",k:"return throw case",c:[e.CLCM,e.CBCM,e.RM,{cN:"function",b:"(\\(.*?\\)|"+r+")\\s*=>",rB:!0,e:"\\s*=>",c:[{cN:"params",v:[{b:r},{b:/\(\s*\)/},{b:/\(/,e:/\)/,eB:!0,eE:!0,k:t,c:s}]}]},{b:/</,e:/(\/\w+|\w+\/)>/,sL:"xml",c:[{b:/<\w+\s*\/>/,skip:!0},{b:/<\w+/,e:/(\/\w+|\w+\/)>/,skip:!0,c:[{b:/<\w+\s*\/>/,skip:!0},"self"]}]}],r:0},{cN:"function",bK:"function",e:/\{/,eE:!0,c:[e.inherit(e.TM,{b:r}),{cN:"params",b:/\(/,e:/\)/,eB:!0,eE:!0,c:s}],i:/\[|%/},{b:/\$[(.]/},e.METHOD_GUARD,{cN:"class",bK:"class",e:/[{;=]/,eE:!0,i:/[:"\[\]]/,c:[{bK:"extends"},e.UTM]},{bK:"constructor",e:/\{/,eE:!0}],i:/#(?!!)/}});hljs.registerLanguage("python",function(e){var r={keyword:"and elif is global as in if from raise for except finally print import pass return exec else break not with class assert yield try while continue del or def lambda async await nonlocal|10 None True False",built_in:"Ellipsis NotImplemented"},b={cN:"meta",b:/^(>>>|\.\.\.) /},c={cN:"subst",b:/\{/,e:/\}/,k:r,i:/#/},a={cN:"string",c:[e.BE],v:[{b:/(u|b)?r?'''/,e:/'''/,c:[b],r:10},{b:/(u|b)?r?"""/,e:/"""/,c:[b],r:10},{b:/(fr|rf|f)'''/,e:/'''/,c:[b,c]},{b:/(fr|rf|f)"""/,e:/"""/,c:[b,c]},{b:/(u|r|ur)'/,e:/'/,r:10},{b:/(u|r|ur)"/,e:/"/,r:10},{b:/(b|br)'/,e:/'/},{b:/(b|br)"/,e:/"/},{b:/(fr|rf|f)'/,e:/'/,c:[c]},{b:/(fr|rf|f)"/,e:/"/,c:[c]},e.ASM,e.QSM]},s={cN:"number",r:0,v:[{b:e.BNR+"[lLjJ]?"},{b:"\\b(0o[0-7]+)[lLjJ]?"},{b:e.CNR+"[lLjJ]?"}]},i={cN:"params",b:/\(/,e:/\)/,c:["self",b,s,a]};return c.c=[a,s,b],{aliases:["py","gyp"],k:r,i:/(<\/|->|\?)|=>/,c:[b,s,a,e.HCM,{v:[{cN:"function",bK:"def"},{cN:"class",bK:"class"}],e:/:/,i:/[${=;\n,]/,c:[e.UTM,i,{b:/->/,eW:!0,k:"None"}]},{cN:"meta",b:/^[\t ]*@/,e:/$/},{b:/\b(print|exec)\(/}]}});hljs.registerLanguage("xml",function(s){var e="[A-Za-z0-9\\._:-]+",t={eW:!0,i:/</,r:0,c:[{cN:"attr",b:e,r:0},{b:/=\s*/,r:0,c:[{cN:"string",endsParent:!0,v:[{b:/"/,e:/"/},{b:/'/,e:/'/},{b:/[^\s"'=<>`]+/}]}]}]};return{aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist"],cI:!0,c:[{cN:"meta",b:"<!DOCTYPE",e:">",r:10,c:[{b:"\\[",e:"\\]"}]},s.C("<!--","-->",{r:10}),{b:"<\\!\\[CDATA\\[",e:"\\]\\]>",r:10},{b:/<\?(php)?/,e:/\?>/,sL:"php",c:[{b:"/\\*",e:"\\*/",skip:!0}]},{cN:"tag",b:"<style(?=\\s|>|$)",e:">",k:{name:"style"},c:[t],starts:{e:"</style>",rE:!0,sL:["css","xml"]}},{cN:"tag",b:"<script(?=\\s|>|$)",e:">",k:{name:"script"},c:[t],starts:{e:"</script>",rE:!0,sL:["actionscript","javascript","handlebars","xml"]}},{cN:"meta",v:[{b:/<\?xml/,e:/\?>/,r:10},{b:/<\?\w+/,e:/\?>/}]},{cN:"tag",b:"</?",e:"/?>",c:[{cN:"name",b:/[^\/><\s]+/,r:0},t]}]}});hljs.registerLanguage("markdown",function(e){return{aliases:["md","mkdown","mkd"],c:[{cN:"section",v:[{b:"^#{1,6}",e:"$"},{b:"^.+?\\n[=-]{2,}$"}]},{b:"<",e:">",sL:"xml",r:0},{cN:"bullet",b:"^([*+-]|(\\d+\\.))\\s+"},{cN:"strong",b:"[*_]{2}.+?[*_]{2}"},{cN:"emphasis",v:[{b:"\\*.+?\\*"},{b:"_.+?_",r:0}]},{cN:"quote",b:"^>\\s+",e:"$"},{cN:"code",v:[{b:"^```w*s*$",e:"^```s*$"},{b:"`.+?`"},{b:"^( {4}| )",e:"$",r:0}]},{b:"^[-\\*]{3,}",e:"$"},{b:"\\[.+?\\][\\(\\[].*?[\\)\\]]",rB:!0,c:[{cN:"string",b:"\\[",e:"\\]",eB:!0,rE:!0,r:0},{cN:"link",b:"\\]\\(",e:"\\)",eB:!0,eE:!0},{cN:"symbol",b:"\\]\\[",e:"\\]",eB:!0,eE:!0}],r:10},{b:/^\[[^\n]+\]:/,rB:!0,c:[{cN:"symbol",b:/\[/,e:/\]/,eB:!0,eE:!0},{cN:"link",b:/:\s*/,e:/$/,eB:!0}]}]}});hljs.registerLanguage("php",function(e){var c={b:"\\$+[a-zA-Z_-ÿ][a-zA-Z0-9_-ÿ]*"},i={cN:"meta",b:/<\?(php)?|\?>/},t={cN:"string",c:[e.BE,i],v:[{b:'b"',e:'"'},{b:"b'",e:"'"},e.inherit(e.ASM,{i:null}),e.inherit(e.QSM,{i:null})]},a={v:[e.BNM,e.CNM]};return{aliases:["php3","php4","php5","php6"],cI:!0,k:"and include_once list abstract global private echo interface as static endswitch array null if endwhile or const for endforeach self var while isset public protected exit foreach throw elseif include __FILE__ empty require_once do xor return parent clone use __CLASS__ __LINE__ else break print eval new catch __METHOD__ case exception default die require __FUNCTION__ enddeclare final try switch continue endfor endif declare unset true false trait goto instanceof insteadof __DIR__ __NAMESPACE__ yield finally",c:[e.HCM,e.C("//","$",{c:[i]}),e.C("/\\*","\\*/",{c:[{cN:"doctag",b:"@[A-Za-z]+"}]}),e.C("__halt_compiler.+?;",!1,{eW:!0,k:"__halt_compiler",l:e.UIR}),{cN:"string",b:/<<<['"]?\w+['"]?$/,e:/^\w+;?$/,c:[e.BE,{cN:"subst",v:[{b:/\$\w+/},{b:/\{\$/,e:/\}/}]}]},i,{cN:"keyword",b:/\$this\b/},c,{b:/(::|->)+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/},{cN:"function",bK:"function",e:/[;{]/,eE:!0,i:"\\$|\\[|%",c:[e.UTM,{cN:"params",b:"\\(",e:"\\)",c:["self",c,e.CBCM,t,a]}]},{cN:"class",bK:"class interface",e:"{",eE:!0,i:/[:\(\$"]/,c:[{bK:"extends implements"},e.UTM]},{bK:"namespace",e:";",i:/[\.']/,c:[e.UTM]},{bK:"use",e:";",c:[e.UTM]},{b:"=>"},t,a]}});hljs.registerLanguage("tex",function(c){var e={cN:"tag",b:/\\/,r:0,c:[{cN:"name",v:[{b:/[a-zA-Zа-яА-я]+[*]?/},{b:/[^a-zA-Zа-яА-я0-9]/}],starts:{eW:!0,r:0,c:[{cN:"string",v:[{b:/\[/,e:/\]/},{b:/\{/,e:/\}/}]},{b:/\s*=\s*/,eW:!0,r:0,c:[{cN:"number",b:/-?\d*\.?\d+(pt|pc|mm|cm|in|dd|cc|ex|em)?/}]}]}}]};return{c:[e,{cN:"formula",c:[e],r:0,v:[{b:/\$\$/,e:/\$\$/},{b:/\$/,e:/\$/}]},c.C("%","$",{r:0})]}});hljs.registerLanguage("lisp",function(b){var e="[a-zA-Z_\\-\\+\\*\\/\\<\\=\\>\\&\\#][a-zA-Z0-9_\\-\\+\\*\\/\\<\\=\\>\\&\\#!]*",c="\\|[^]*?\\|",r="(\\-|\\+)?\\d+(\\.\\d+|\\/\\d+)?((d|e|f|l|s|D|E|F|L|S)(\\+|\\-)?\\d+)?",a={cN:"meta",b:"^#!",e:"$"},l={cN:"literal",b:"\\b(t{1}|nil)\\b"},n={cN:"number",v:[{b:r,r:0},{b:"#(b|B)[0-1]+(/[0-1]+)?"},{b:"#(o|O)[0-7]+(/[0-7]+)?"},{b:"#(x|X)[0-9a-fA-F]+(/[0-9a-fA-F]+)?"},{b:"#(c|C)\\("+r+" +"+r,e:"\\)"}]},i=b.inherit(b.QSM,{i:null}),t=b.C(";","$",{r:0}),s={b:"\\*",e:"\\*"},u={cN:"symbol",b:"[:&]"+e},d={b:e,r:0},f={b:c},m={b:"\\(",e:"\\)",c:["self",l,i,n,d]},o={c:[n,i,s,u,m,d],v:[{b:"['`]\\(",e:"\\)"},{b:"\\(quote ",e:"\\)",k:{name:"quote"}},{b:"'"+c}]},v={v:[{b:"'"+e},{b:"#'"+e+"(::"+e+")*"}]},N={b:"\\(\\s*",e:"\\)"},A={eW:!0,r:0};return N.c=[{cN:"name",v:[{b:e},{b:c}]},A],A.c=[o,v,N,l,n,i,t,s,u,f,d],{i:/\S/,c:[n,a,l,i,t,o,v,N,d]}});hljs.registerLanguage("json",function(e){var i={literal:"true false null"},n=[e.QSM,e.CNM],r={e:",",eW:!0,eE:!0,c:n,k:i},t={b:"{",e:"}",c:[{cN:"attr",b:/"/,e:/"/,c:[e.BE],i:"\\n"},e.inherit(r,{b:/:/})],i:"\\S"},c={b:"\\[",e:"\\]",c:[e.inherit(r)],i:"\\S"};return n.splice(n.length,0,t,c),{c:n,k:i,i:"\\S"}});hljs.registerLanguage("perl",function(e){var t="getpwent getservent quotemeta msgrcv scalar kill dbmclose undef lc ma syswrite tr send umask sysopen shmwrite vec qx utime local oct semctl localtime readpipe do return format read sprintf dbmopen pop getpgrp not getpwnam rewinddir qqfileno qw endprotoent wait sethostent bless s|0 opendir continue each sleep endgrent shutdown dump chomp connect getsockname die socketpair close flock exists index shmgetsub for endpwent redo lstat msgctl setpgrp abs exit select print ref gethostbyaddr unshift fcntl syscall goto getnetbyaddr join gmtime symlink semget splice x|0 getpeername recv log setsockopt cos last reverse gethostbyname getgrnam study formline endhostent times chop length gethostent getnetent pack getprotoent getservbyname rand mkdir pos chmod y|0 substr endnetent printf next open msgsnd readdir use unlink getsockopt getpriority rindex wantarray hex system getservbyport endservent int chr untie rmdir prototype tell listen fork shmread ucfirst setprotoent else sysseek link getgrgid shmctl waitpid unpack getnetbyname reset chdir grep split require caller lcfirst until warn while values shift telldir getpwuid my getprotobynumber delete and sort uc defined srand accept package seekdir getprotobyname semop our rename seek if q|0 chroot sysread setpwent no crypt getc chown sqrt write setnetent setpriority foreach tie sin msgget map stat getlogin unless elsif truncate exec keys glob tied closedirioctl socket readlink eval xor readline binmode setservent eof ord bind alarm pipe atan2 getgrent exp time push setgrent gt lt or ne m|0 break given say state when",r={cN:"subst",b:"[$@]\\{",e:"\\}",k:t},s={b:"->{",e:"}"},n={v:[{b:/\$\d/},{b:/[\$%@](\^\w\b|#\w+(::\w+)*|{\w+}|\w+(::\w*)*)/},{b:/[\$%@][^\s\w{]/,r:0}]},i=[e.BE,r,n],o=[n,e.HCM,e.C("^\\=\\w","\\=cut",{eW:!0}),s,{cN:"string",c:i,v:[{b:"q[qwxr]?\\s*\\(",e:"\\)",r:5},{b:"q[qwxr]?\\s*\\[",e:"\\]",r:5},{b:"q[qwxr]?\\s*\\{",e:"\\}",r:5},{b:"q[qwxr]?\\s*\\|",e:"\\|",r:5},{b:"q[qwxr]?\\s*\\<",e:"\\>",r:5},{b:"qw\\s+q",e:"q",r:5},{b:"'",e:"'",c:[e.BE]},{b:'"',e:'"'},{b:"`",e:"`",c:[e.BE]},{b:"{\\w+}",c:[],r:0},{b:"-?\\w+\\s*\\=\\>",c:[],r:0}]},{cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},{b:"(\\/\\/|"+e.RSR+"|\\b(split|return|print|reverse|grep)\\b)\\s*",k:"split return print reverse grep",r:0,c:[e.HCM,{cN:"regexp",b:"(s|tr|y)/(\\\\.|[^/])*/(\\\\.|[^/])*/[a-z]*",r:10},{cN:"regexp",b:"(m|qr)?/",e:"/[a-z]*",c:[e.BE],r:0}]},{cN:"function",bK:"sub",e:"(\\s*\\(.*?\\))?[;{]",eE:!0,r:5,c:[e.TM]},{b:"-\\w\\b",r:0},{b:"^__DATA__$",e:"^__END__$",sL:"mojolicious",c:[{b:"^@@.*",e:"$",cN:"comment"}]}];return r.c=o,s.c=o,{aliases:["pl","pm"],l:/[\w\.]+/,k:t,c:o}});hljs.registerLanguage("ruby",function(e){var b="[a-zA-Z_]\\w*[!?=]?|[-+~]\\@|<<|>>|=~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~`|]|\\[\\]=?",r={keyword:"and then defined module in return redo if BEGIN retry end for self when next until do begin unless END rescue else break undef not super class case require yield alias while ensure elsif or include attr_reader attr_writer attr_accessor",literal:"true false nil"},c={cN:"doctag",b:"@[A-Za-z]+"},a={b:"#<",e:">"},s=[e.C("#","$",{c:[c]}),e.C("^\\=begin","^\\=end",{c:[c],r:10}),e.C("^__END__","\\n$")],n={cN:"subst",b:"#\\{",e:"}",k:r},t={cN:"string",c:[e.BE,n],v:[{b:/'/,e:/'/},{b:/"/,e:/"/},{b:/`/,e:/`/},{b:"%[qQwWx]?\\(",e:"\\)"},{b:"%[qQwWx]?\\[",e:"\\]"},{b:"%[qQwWx]?{",e:"}"},{b:"%[qQwWx]?<",e:">"},{b:"%[qQwWx]?/",e:"/"},{b:"%[qQwWx]?%",e:"%"},{b:"%[qQwWx]?-",e:"-"},{b:"%[qQwWx]?\\|",e:"\\|"},{b:/\B\?(\\\d{1,3}|\\x[A-Fa-f0-9]{1,2}|\\u[A-Fa-f0-9]{4}|\\?\S)\b/},{b:/<<(-?)\w+$/,e:/^\s*\w+$/}]},i={cN:"params",b:"\\(",e:"\\)",endsParent:!0,k:r},d=[t,a,{cN:"class",bK:"class module",e:"$|;",i:/=/,c:[e.inherit(e.TM,{b:"[A-Za-z_]\\w*(::\\w+)*(\\?|\\!)?"}),{b:"<\\s*",c:[{b:"("+e.IR+"::)?"+e.IR}]}].concat(s)},{cN:"function",bK:"def",e:"$|;",c:[e.inherit(e.TM,{b:b}),i].concat(s)},{b:e.IR+"::"},{cN:"symbol",b:e.UIR+"(\\!|\\?)?:",r:0},{cN:"symbol",b:":(?!\\s)",c:[t,{b:b}],r:0},{cN:"number",b:"(\\b0[0-7_]+)|(\\b0x[0-9a-fA-F_]+)|(\\b[1-9][0-9_]*(\\.[0-9_]+)?)|[0_]\\b",r:0},{b:"(\\$\\W)|((\\$|\\@\\@?)(\\w+))"},{cN:"params",b:/\|/,e:/\|/,k:r},{b:"("+e.RSR+"|unless)\\s*",k:"unless",c:[a,{cN:"regexp",c:[e.BE,n],i:/\n/,v:[{b:"/",e:"/[a-z]*"},{b:"%r{",e:"}[a-z]*"},{b:"%r\\(",e:"\\)[a-z]*"},{b:"%r!",e:"![a-z]*"},{b:"%r\\[",e:"\\][a-z]*"}]}].concat(s),r:0}].concat(s);n.c=d,i.c=d;var l="[>?]>",o="[\\w#]+\\(\\w+\\):\\d+:\\d+>",u="(\\w+-)?\\d+\\.\\d+\\.\\d(p\\d+)?[^>]+>",w=[{b:/^\s*=>/,starts:{e:"$",c:d}},{cN:"meta",b:"^("+l+"|"+o+"|"+u+")",starts:{e:"$",c:d}}];return{aliases:["rb","gemspec","podspec","thor","irb"],k:r,i:/\/\*/,c:s.concat(w).concat(d)}});hljs.registerLanguage("makefile",function(e){var i={cN:"variable",v:[{b:"\\$\\("+e.UIR+"\\)",c:[e.BE]},{b:/\$[@%<?\^\+\*]/}]},r={cN:"string",b:/"/,e:/"/,c:[e.BE,i]},a={cN:"variable",b:/\$\([\w-]+\s/,e:/\)/,k:{built_in:"subst patsubst strip findstring filter filter-out sort word wordlist firstword lastword dir notdir suffix basename addsuffix addprefix join wildcard realpath abspath error warning shell origin flavor foreach if or and call eval file value"},c:[i]},n={b:"^"+e.UIR+"\\s*[:+?]?=",i:"\\n",rB:!0,c:[{b:"^"+e.UIR,e:"[:+?]?=",eE:!0}]},t={cN:"meta",b:/^\.PHONY:/,e:/$/,k:{"meta-keyword":".PHONY"},l:/[\.\w]+/},l={cN:"section",b:/^[^\s]+:/,e:/$/,c:[i]};return{aliases:["mk","mak"],k:"define endef undefine ifdef ifndef ifeq ifneq else endif include -include sinclude override export unexport private vpath",l:/[\w-]+/,c:[e.HCM,i,r,a,n,t,l]}});hljs.registerLanguage("css",function(e){var c="[a-zA-Z-][a-zA-Z0-9_-]*",t={b:/[A-Z\_\.\-]+\s*:/,rB:!0,e:";",eW:!0,c:[{cN:"attribute",b:/\S/,e:":",eE:!0,starts:{eW:!0,eE:!0,c:[{b:/[\w-]+\(/,rB:!0,c:[{cN:"built_in",b:/[\w-]+/},{b:/\(/,e:/\)/,c:[e.ASM,e.QSM]}]},e.CSSNM,e.QSM,e.ASM,e.CBCM,{cN:"number",b:"#[0-9A-Fa-f]+"},{cN:"meta",b:"!important"}]}}]};return{cI:!0,i:/[=\/|'\$]/,c:[e.CBCM,{cN:"selector-id",b:/#[A-Za-z0-9_-]+/},{cN:"selector-class",b:/\.[A-Za-z0-9_-]+/},{cN:"selector-attr",b:/\[/,e:/\]/,i:"$"},{cN:"selector-pseudo",b:/:(:)?[a-zA-Z0-9\_\-\+\(\)"'.]+/},{b:"@(font-face|page)",l:"[a-z-]+",k:"font-face page"},{b:"@",e:"[{;]",i:/:/,c:[{cN:"keyword",b:/\w+/},{b:/\s/,eW:!0,eE:!0,r:0,c:[e.ASM,e.QSM,e.CSSNM]}]},{cN:"selector-tag",b:c,r:0},{b:"{",e:"}",i:/\S/,c:[e.CBCM,t]}]}});hljs.registerLanguage("java",function(e){var a="[À-ʸa-zA-Z_$][À-ʸa-zA-Z_$0-9]*",t=a+"(<"+a+"(\\s*,\\s*"+a+")*>)?",r="false synchronized int abstract float private char boolean static null if const for true while long strictfp finally protected import native final void enum else break transient catch instanceof byte super volatile case assert short package default double public try this switch continue throws protected public private module requires exports do",s="\\b(0[bB]([01]+[01_]+[01]+|[01]+)|0[xX]([a-fA-F0-9]+[a-fA-F0-9_]+[a-fA-F0-9]+|[a-fA-F0-9]+)|(([\\d]+[\\d_]+[\\d]+|[\\d]+)(\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))?|\\.([\\d]+[\\d_]+[\\d]+|[\\d]+))([eE][-+]?\\d+)?)[lLfF]?",c={cN:"number",b:s,r:0};return{aliases:["jsp"],k:r,i:/<\/|#/,c:[e.C("/\\*\\*","\\*/",{r:0,c:[{b:/\w+@/,r:0},{cN:"doctag",b:"@[A-Za-z]+"}]}),e.CLCM,e.CBCM,e.ASM,e.QSM,{cN:"class",bK:"class interface",e:/[{;=]/,eE:!0,k:"class interface",i:/[:"\[\]]/,c:[{bK:"extends implements"},e.UTM]},{bK:"new throw return else",r:0},{cN:"function",b:"("+t+"\\s+)+"+e.UIR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:r,c:[{b:e.UIR+"\\s*\\(",rB:!0,r:0,c:[e.UTM]},{cN:"params",b:/\(/,e:/\)/,k:r,r:0,c:[e.ASM,e.QSM,e.CNM,e.CBCM]},e.CLCM,e.CBCM]},c,{cN:"meta",b:"@[A-Za-z]+"}]}});hljs.registerLanguage("cpp",function(t){var e={cN:"keyword",b:"\\b[a-z\\d_]*_t\\b"},r={cN:"string",v:[{b:'(u8?|U)?L?"',e:'"',i:"\\n",c:[t.BE]},{b:'(u8?|U)?R"',e:'"',c:[t.BE]},{b:"'\\\\?.",e:"'",i:"."}]},s={cN:"number",v:[{b:"\\b(0b[01']+)"},{b:"(-?)\\b([\\d']+(\\.[\\d']*)?|\\.[\\d']+)(u|U|l|L|ul|UL|f|F|b|B)"},{b:"(-?)(\\b0[xX][a-fA-F0-9']+|(\\b[\\d']+(\\.[\\d']*)?|\\.[\\d']+)([eE][-+]?[\\d']+)?)"}],r:0},i={cN:"meta",b:/#\s*[a-z]+\b/,e:/$/,k:{"meta-keyword":"if else elif endif define undef warning error line pragma ifdef ifndef include"},c:[{b:/\\\n/,r:0},t.inherit(r,{cN:"meta-string"}),{cN:"meta-string",b:/<[^\n>]*>/,e:/$/,i:"\\n"},t.CLCM,t.CBCM]},a=t.IR+"\\s*\\(",c={keyword:"int float while private char catch import module export virtual operator sizeof dynamic_cast|10 typedef const_cast|10 const for static_cast|10 union namespace unsigned long volatile static protected bool template mutable if public friend do goto auto void enum else break extern using asm case typeid short reinterpret_cast|10 default double register explicit signed typename try this switch continue inline delete alignof constexpr decltype noexcept static_assert thread_local restrict _Bool complex _Complex _Imaginary atomic_bool atomic_char atomic_schar atomic_uchar atomic_short atomic_ushort atomic_int atomic_uint atomic_long atomic_ulong atomic_llong atomic_ullong new throw return and or not",built_in:"std string cin cout cerr clog stdin stdout stderr stringstream istringstream ostringstream auto_ptr deque list queue stack vector map set bitset multiset multimap unordered_set unordered_map unordered_multiset unordered_multimap array shared_ptr abs acos asin atan2 atan calloc ceil cosh cos exit exp fabs floor fmod fprintf fputs free frexp fscanf isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper labs ldexp log10 log malloc realloc memchr memcmp memcpy memset modf pow printf putchar puts scanf sinh sin snprintf sprintf sqrt sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strrchr strspn strstr tanh tan vfprintf vprintf vsprintf endl initializer_list unique_ptr",literal:"true false nullptr NULL"},n=[e,t.CLCM,t.CBCM,s,r];return{aliases:["c","cc","h","c++","h++","hpp"],k:c,i:"</",c:n.concat([i,{b:"\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*<",e:">",k:c,c:["self",e]},{b:t.IR+"::",k:c},{v:[{b:/=/,e:/;/},{b:/\(/,e:/\)/},{bK:"new throw return else",e:/;/}],k:c,c:n.concat([{b:/\(/,e:/\)/,k:c,c:n.concat(["self"]),r:0}]),r:0},{cN:"function",b:"("+t.IR+"[\\*&\\s]+)+"+a,rB:!0,e:/[{;=]/,eE:!0,k:c,i:/[^\w\s\*&]/,c:[{b:a,rB:!0,c:[t.TM],r:0},{cN:"params",b:/\(/,e:/\)/,k:c,r:0,c:[t.CLCM,t.CBCM,r,s,e]},t.CLCM,t.CBCM,i]},{cN:"class",bK:"class struct",e:/[{;:]/,c:[{b:/</,e:/>/,c:["self"]},t.TM]}]),exports:{preprocessor:i,strings:r,k:c}}});hljs.registerLanguage("bash",function(e){var t={cN:"variable",v:[{b:/\$[\w\d#@][\w\d_]*/},{b:/\$\{(.*?)}/}]},s={cN:"string",b:/"/,e:/"/,c:[e.BE,t,{cN:"variable",b:/\$\(/,e:/\)/,c:[e.BE]}]},a={cN:"string",b:/'/,e:/'/};return{aliases:["sh","zsh"],l:/\b-?[a-z\._]+\b/,k:{keyword:"if then else elif fi for while in do done case esac function",literal:"true false",built_in:"break cd continue eval exec exit export getopts hash pwd readonly return shift test times trap umask unset alias bind builtin caller command declare echo enable help let local logout mapfile printf read readarray source type typeset ulimit unalias set shopt autoload bg bindkey bye cap chdir clone comparguments compcall compctl compdescribe compfiles compgroups compquote comptags comptry compvalues dirs disable disown echotc echoti emulate fc fg float functions getcap getln history integer jobs kill limit log noglob popd print pushd pushln rehash sched setcap setopt stat suspend ttyctl unfunction unhash unlimit unsetopt vared wait whence where which zcompile zformat zftp zle zmodload zparseopts zprof zpty zregexparse zsocket zstyle ztcp",_:"-ne -eq -lt -gt -f -d -e -s -l -a"},c:[{cN:"meta",b:/^#![^\n]+sh\s*$/,r:10},{cN:"function",b:/\w[\w\d_]*\s*\(\s*\)\s*\{/,rB:!0,c:[e.inherit(e.TM,{b:/\w[\w\d_]*/})],r:0},e.HCM,s,a,t]}});hljs.registerLanguage("shell",function(s){return{aliases:["console"],c:[{cN:"meta",b:"^\\s{0,3}[\\w\\d\\[\\]()@-]*[>%$#]",starts:{e:"$",sL:"bash"}}]}});hljs.registerLanguage("http",function(e){var t="HTTP/[0-9\\.]+";return{aliases:["https"],i:"\\S",c:[{b:"^"+t,e:"$",c:[{cN:"number",b:"\\b\\d{3}\\b"}]},{b:"^[A-Z]+ (.*?) "+t+"$",rB:!0,e:"$",c:[{cN:"string",b:" ",e:" ",eB:!0,eE:!0},{b:t},{cN:"keyword",b:"[A-Z]+"}]},{cN:"attribute",b:"^\\w",e:": ",eE:!0,i:"\\n|\\s|=",starts:{e:"$",r:0}},{b:"\\n\\n",starts:{sL:[],eW:!0}}]}});hljs.registerLanguage("cs",function(e){var i={keyword:"abstract as base bool break byte case catch char checked const continue decimal default delegate do double enum event explicit extern finally fixed float for foreach goto if implicit in int interface internal is lock long nameof object operator out override params private protected public readonly ref sbyte sealed short sizeof stackalloc static string struct switch this try typeof uint ulong unchecked unsafe ushort using virtual void volatile while add alias ascending async await by descending dynamic equals from get global group into join let on orderby partial remove select set value var where yield",literal:"null false true"},t={cN:"string",b:'@"',e:'"',c:[{b:'""'}]},r=e.inherit(t,{i:/\n/}),a={cN:"subst",b:"{",e:"}",k:i},c=e.inherit(a,{i:/\n/}),n={cN:"string",b:/\$"/,e:'"',i:/\n/,c:[{b:"{{"},{b:"}}"},e.BE,c]},s={cN:"string",b:/\$@"/,e:'"',c:[{b:"{{"},{b:"}}"},{b:'""'},a]},o=e.inherit(s,{i:/\n/,c:[{b:"{{"},{b:"}}"},{b:'""'},c]});a.c=[s,n,t,e.ASM,e.QSM,e.CNM,e.CBCM],c.c=[o,n,r,e.ASM,e.QSM,e.CNM,e.inherit(e.CBCM,{i:/\n/})];var l={v:[s,n,t,e.ASM,e.QSM]},b=e.IR+"(<"+e.IR+"(\\s*,\\s*"+e.IR+")*>)?(\\[\\])?";return{aliases:["csharp"],k:i,i:/::/,c:[e.C("///","$",{rB:!0,c:[{cN:"doctag",v:[{b:"///",r:0},{b:"<!--|-->"},{b:"</?",e:">"}]}]}),e.CLCM,e.CBCM,{cN:"meta",b:"#",e:"$",k:{"meta-keyword":"if else elif endif define undef warning error line region endregion pragma checksum"}},l,e.CNM,{bK:"class interface",e:/[{;=]/,i:/[^\s:]/,c:[e.TM,e.CLCM,e.CBCM]},{bK:"namespace",e:/[{;=]/,i:/[^\s:]/,c:[e.inherit(e.TM,{b:"[a-zA-Z](\\.?\\w)*"}),e.CLCM,e.CBCM]},{cN:"meta",b:"^\\s*\\[",eB:!0,e:"\\]",eE:!0,c:[{cN:"meta-string",b:/"/,e:/"/}]},{bK:"new return throw await else",r:0},{cN:"function",b:"("+b+"\\s+)+"+e.IR+"\\s*\\(",rB:!0,e:/[{;=]/,eE:!0,k:i,c:[{b:e.IR+"\\s*\\(",rB:!0,c:[e.TM],r:0},{cN:"params",b:/\(/,e:/\)/,eB:!0,eE:!0,k:i,r:0,c:[l,e.CNM,e.CBCM]},e.CLCM,e.CBCM]}]}});hljs.registerLanguage("coffeescript",function(e){var c={keyword:"in if for while finally new do return else break catch instanceof throw try this switch continue typeof delete debugger super yield import export from as default await then unless until loop of by when and or is isnt not",literal:"true false null undefined yes no on off",built_in:"npm require console print module global window document"},n="[A-Za-z$_][0-9A-Za-z$_]*",r={cN:"subst",b:/#\{/,e:/}/,k:c},i=[e.BNM,e.inherit(e.CNM,{starts:{e:"(\\s*/)?",r:0}}),{cN:"string",v:[{b:/'''/,e:/'''/,c:[e.BE]},{b:/'/,e:/'/,c:[e.BE]},{b:/"""/,e:/"""/,c:[e.BE,r]},{b:/"/,e:/"/,c:[e.BE,r]}]},{cN:"regexp",v:[{b:"///",e:"///",c:[r,e.HCM]},{b:"//[gim]*",r:0},{b:/\/(?![ *])(\\\/|.)*?\/[gim]*(?=\W|$)/}]},{b:"@"+n},{sL:"javascript",eB:!0,eE:!0,v:[{b:"```",e:"```"},{b:"`",e:"`"}]}];r.c=i;var s=e.inherit(e.TM,{b:n}),t="(\\(.*\\))?\\s*\\B[-=]>",o={cN:"params",b:"\\([^\\(]",rB:!0,c:[{b:/\(/,e:/\)/,k:c,c:["self"].concat(i)}]};return{aliases:["coffee","cson","iced"],k:c,i:/\/\*/,c:i.concat([e.C("###","###"),e.HCM,{cN:"function",b:"^\\s*"+n+"\\s*=\\s*"+t,e:"[-=]>",rB:!0,c:[s,o]},{b:/[:\(,=]\s*/,r:0,c:[{cN:"function",b:t,e:"[-=]>",rB:!0,c:[o]}]},{cN:"class",bK:"class",e:"$",i:/[:="\[\]]/,c:[{bK:"extends",eW:!0,i:/[:="\[\]]/,c:[s]},s]},{b:n+":",e:":",rB:!0,rE:!0,r:0}])}});hljs.registerLanguage("glsl",function(e){return{k:{keyword:"break continue discard do else for if return while switch case default attribute binding buffer ccw centroid centroid varying coherent column_major const cw depth_any depth_greater depth_less depth_unchanged early_fragment_tests equal_spacing flat fractional_even_spacing fractional_odd_spacing highp in index inout invariant invocations isolines layout line_strip lines lines_adjacency local_size_x local_size_y local_size_z location lowp max_vertices mediump noperspective offset origin_upper_left out packed patch pixel_center_integer point_mode points precise precision quads r11f_g11f_b10f r16 r16_snorm r16f r16i r16ui r32f r32i r32ui r8 r8_snorm r8i r8ui readonly restrict rg16 rg16_snorm rg16f rg16i rg16ui rg32f rg32i rg32ui rg8 rg8_snorm rg8i rg8ui rgb10_a2 rgb10_a2ui rgba16 rgba16_snorm rgba16f rgba16i rgba16ui rgba32f rgba32i rgba32ui rgba8 rgba8_snorm rgba8i rgba8ui row_major sample shared smooth std140 std430 stream triangle_strip triangles triangles_adjacency uniform varying vertices volatile writeonly",type:"atomic_uint bool bvec2 bvec3 bvec4 dmat2 dmat2x2 dmat2x3 dmat2x4 dmat3 dmat3x2 dmat3x3 dmat3x4 dmat4 dmat4x2 dmat4x3 dmat4x4 double dvec2 dvec3 dvec4 float iimage1D iimage1DArray iimage2D iimage2DArray iimage2DMS iimage2DMSArray iimage2DRect iimage3D iimageBufferiimageCube iimageCubeArray image1D image1DArray image2D image2DArray image2DMS image2DMSArray image2DRect image3D imageBuffer imageCube imageCubeArray int isampler1D isampler1DArray isampler2D isampler2DArray isampler2DMS isampler2DMSArray isampler2DRect isampler3D isamplerBuffer isamplerCube isamplerCubeArray ivec2 ivec3 ivec4 mat2 mat2x2 mat2x3 mat2x4 mat3 mat3x2 mat3x3 mat3x4 mat4 mat4x2 mat4x3 mat4x4 sampler1D sampler1DArray sampler1DArrayShadow sampler1DShadow sampler2D sampler2DArray sampler2DArrayShadow sampler2DMS sampler2DMSArray sampler2DRect sampler2DRectShadow sampler2DShadow sampler3D samplerBuffer samplerCube samplerCubeArray samplerCubeArrayShadow samplerCubeShadow image1D uimage1DArray uimage2D uimage2DArray uimage2DMS uimage2DMSArray uimage2DRect uimage3D uimageBuffer uimageCube uimageCubeArray uint usampler1D usampler1DArray usampler2D usampler2DArray usampler2DMS usampler2DMSArray usampler2DRect usampler3D samplerBuffer usamplerCube usamplerCubeArray uvec2 uvec3 uvec4 vec2 vec3 vec4 void",built_in:"gl_MaxAtomicCounterBindings gl_MaxAtomicCounterBufferSize gl_MaxClipDistances gl_MaxClipPlanes gl_MaxCombinedAtomicCounterBuffers gl_MaxCombinedAtomicCounters gl_MaxCombinedImageUniforms gl_MaxCombinedImageUnitsAndFragmentOutputs gl_MaxCombinedTextureImageUnits gl_MaxComputeAtomicCounterBuffers gl_MaxComputeAtomicCounters gl_MaxComputeImageUniforms gl_MaxComputeTextureImageUnits gl_MaxComputeUniformComponents gl_MaxComputeWorkGroupCount gl_MaxComputeWorkGroupSize gl_MaxDrawBuffers gl_MaxFragmentAtomicCounterBuffers gl_MaxFragmentAtomicCounters gl_MaxFragmentImageUniforms gl_MaxFragmentInputComponents gl_MaxFragmentInputVectors gl_MaxFragmentUniformComponents gl_MaxFragmentUniformVectors gl_MaxGeometryAtomicCounterBuffers gl_MaxGeometryAtomicCounters gl_MaxGeometryImageUniforms gl_MaxGeometryInputComponents gl_MaxGeometryOutputComponents gl_MaxGeometryOutputVertices gl_MaxGeometryTextureImageUnits gl_MaxGeometryTotalOutputComponents gl_MaxGeometryUniformComponents gl_MaxGeometryVaryingComponents gl_MaxImageSamples gl_MaxImageUnits gl_MaxLights gl_MaxPatchVertices gl_MaxProgramTexelOffset gl_MaxTessControlAtomicCounterBuffers gl_MaxTessControlAtomicCounters gl_MaxTessControlImageUniforms gl_MaxTessControlInputComponents gl_MaxTessControlOutputComponents gl_MaxTessControlTextureImageUnits gl_MaxTessControlTotalOutputComponents gl_MaxTessControlUniformComponents gl_MaxTessEvaluationAtomicCounterBuffers gl_MaxTessEvaluationAtomicCounters gl_MaxTessEvaluationImageUniforms gl_MaxTessEvaluationInputComponents gl_MaxTessEvaluationOutputComponents gl_MaxTessEvaluationTextureImageUnits gl_MaxTessEvaluationUniformComponents gl_MaxTessGenLevel gl_MaxTessPatchComponents gl_MaxTextureCoords gl_MaxTextureImageUnits gl_MaxTextureUnits gl_MaxVaryingComponents gl_MaxVaryingFloats gl_MaxVaryingVectors gl_MaxVertexAtomicCounterBuffers gl_MaxVertexAtomicCounters gl_MaxVertexAttribs gl_MaxVertexImageUniforms gl_MaxVertexOutputComponents gl_MaxVertexOutputVectors gl_MaxVertexTextureImageUnits gl_MaxVertexUniformComponents gl_MaxVertexUniformVectors gl_MaxViewports gl_MinProgramTexelOffset gl_BackColor gl_BackLightModelProduct gl_BackLightProduct gl_BackMaterial gl_BackSecondaryColor gl_ClipDistance gl_ClipPlane gl_ClipVertex gl_Color gl_DepthRange gl_EyePlaneQ gl_EyePlaneR gl_EyePlaneS gl_EyePlaneT gl_Fog gl_FogCoord gl_FogFragCoord gl_FragColor gl_FragCoord gl_FragData gl_FragDepth gl_FrontColor gl_FrontFacing gl_FrontLightModelProduct gl_FrontLightProduct gl_FrontMaterial gl_FrontSecondaryColor gl_GlobalInvocationID gl_InstanceID gl_InvocationID gl_Layer gl_LightModel gl_LightSource gl_LocalInvocationID gl_LocalInvocationIndex gl_ModelViewMatrix gl_ModelViewMatrixInverse gl_ModelViewMatrixInverseTranspose gl_ModelViewMatrixTranspose gl_ModelViewProjectionMatrix gl_ModelViewProjectionMatrixInverse gl_ModelViewProjectionMatrixInverseTranspose gl_ModelViewProjectionMatrixTranspose gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 gl_Normal gl_NormalMatrix gl_NormalScale gl_NumSamples gl_NumWorkGroups gl_ObjectPlaneQ gl_ObjectPlaneR gl_ObjectPlaneS gl_ObjectPlaneT gl_PatchVerticesIn gl_Point gl_PointCoord gl_PointSize gl_Position gl_PrimitiveID gl_PrimitiveIDIn gl_ProjectionMatrix gl_ProjectionMatrixInverse gl_ProjectionMatrixInverseTranspose gl_ProjectionMatrixTranspose gl_SampleID gl_SampleMask gl_SampleMaskIn gl_SamplePosition gl_SecondaryColor gl_TessCoord gl_TessLevelInner gl_TessLevelOuter gl_TexCoord gl_TextureEnvColor gl_TextureMatrix gl_TextureMatrixInverse gl_TextureMatrixInverseTranspose gl_TextureMatrixTranspose gl_Vertex gl_VertexID gl_ViewportIndex gl_WorkGroupID gl_WorkGroupSize gl_in gl_out EmitStreamVertex EmitVertex EndPrimitive EndStreamPrimitive abs acos acosh all any asin asinh atan atanh atomicAdd atomicAnd atomicCompSwap atomicCounter atomicCounterDecrement atomicCounterIncrement atomicExchange atomicMax atomicMin atomicOr atomicXor barrier bitCount bitfieldExtract bitfieldInsert bitfieldReverse ceil clamp cos cosh cross dFdx dFdy degrees determinant distance dot equal exp exp2 faceforward findLSB findMSB floatBitsToInt floatBitsToUint floor fma fract frexp ftransform fwidth greaterThan greaterThanEqual groupMemoryBarrier imageAtomicAdd imageAtomicAnd imageAtomicCompSwap imageAtomicExchange imageAtomicMax imageAtomicMin imageAtomicOr imageAtomicXor imageLoad imageSize imageStore imulExtended intBitsToFloat interpolateAtCentroid interpolateAtOffset interpolateAtSample inverse inversesqrt isinf isnan ldexp length lessThan lessThanEqual log log2 matrixCompMult max memoryBarrier memoryBarrierAtomicCounter memoryBarrierBuffer memoryBarrierImage memoryBarrierShared min mix mod modf noise1 noise2 noise3 noise4 normalize not notEqual outerProduct packDouble2x32 packHalf2x16 packSnorm2x16 packSnorm4x8 packUnorm2x16 packUnorm4x8 pow radians reflect refract round roundEven shadow1D shadow1DLod shadow1DProj shadow1DProjLod shadow2D shadow2DLod shadow2DProj shadow2DProjLod sign sin sinh smoothstep sqrt step tan tanh texelFetch texelFetchOffset texture texture1D texture1DLod texture1DProj texture1DProjLod texture2D texture2DLod texture2DProj texture2DProjLod texture3D texture3DLod texture3DProj texture3DProjLod textureCube textureCubeLod textureGather textureGatherOffset textureGatherOffsets textureGrad textureGradOffset textureLod textureLodOffset textureOffset textureProj textureProjGrad textureProjGradOffset textureProjLod textureProjLodOffset textureProjOffset textureQueryLevels textureQueryLod textureSize transpose trunc uaddCarry uintBitsToFloat umulExtended unpackDouble2x32 unpackHalf2x16 unpackSnorm2x16 unpackSnorm4x8 unpackUnorm2x16 unpackUnorm4x8 usubBorrow",literal:"true false"},i:'"',c:[e.CLCM,e.CBCM,e.CNM,{cN:"meta",b:"#",e:"$"}]}});hljs.registerLanguage("sql",function(e){var t=e.C("--","$");return{cI:!0,i:/[<>{}*#]/,c:[{bK:"begin end start commit rollback savepoint lock alter create drop rename call delete do handler insert load replace select truncate update set show pragma grant merge describe use explain help declare prepare execute deallocate release unlock purge reset change stop analyze cache flush optimize repair kill install uninstall checksum restore check backup revoke comment",e:/;/,eW:!0,l:/[\w\.]+/,k:{keyword:"abs",literal:"true false null",built_in:"array bigint binary bit blob boolean char character date dec decimal float int int8 integer interval number numeric real record serial serial8 smallint text varchar varying void"},c:[{cN:"string",b:"'",e:"'",c:[e.BE,{b:"''"}]},{cN:"string",b:'"',e:'"',c:[e.BE,{b:'""'}]},{cN:"string",b:"`",e:"`",c:[e.BE]},e.CNM,e.CBCM,t]},e.CBCM,t]}});hljs.registerLanguage("apache",function(e){var r={cN:"number",b:"[\\$%]\\d+"};return{aliases:["apacheconf"],cI:!0,c:[e.HCM,{cN:"section",b:"</?",e:">"},{cN:"attribute",b:/\w+/,r:0,k:{nomarkup:"order deny allow setenv rewriterule rewriteengine rewritecond documentroot sethandler errordocument loadmodule options header listen serverroot servername"},starts:{e:/$/,r:0,k:{literal:"on off all"},c:[{cN:"meta",b:"\\s\\[",e:"\\]$"},{cN:"variable",b:"[\\$%]\\{",e:"\\}",c:["self",r]},r,e.QSM]}}],i:/\S/}});
  67. // To reduce script size in the minified file, I cut these keywords from less-frequently used languages:
  68. //abort absolute acc acce accep accept access accessed accessible account acos action activate add addtime admin administer advanced advise aes_decrypt aes_encrypt after agent aggregate ali alia alias allocate allow alter always analyze ancillary and any anydata anydataset anyschema anytype apply archive archived archivelog are as asc ascii asin assembly assertion associate asynchronous at atan atn2 attr attri attrib attribu attribut attribute attributes audit authenticated authentication authid authors auto autoallocate autodblink autoextend automatic availability avg backup badfile basicfile before begin beginning benchmark between bfile bfile_base big bigfile bin binary_double binary_float binlog bit_and bit_count bit_length bit_or bit_xor bitmap blob_base block blocksize body both bound buffer_cache buffer_pool build bulk by byte byteordermark bytes c cache caching call calling cancel capacity cascade cascaded case cast catalog category ceil ceiling chain change changed char_base char_length character_length characters characterset charindex charset charsetform charsetid check checksum checksum_agg child choose chr chunk class cleanup clear client clob clob_base clone close cluster_id cluster_probability cluster_set clustering coalesce coercibility col collate collation collect colu colum column column_value columns columns_updated comment commit compact compatibility compiled complete composite_limit compound compress compute concat concat_ws concurrent confirm conn connec connect connect_by_iscycle connect_by_isleaf connect_by_root connect_time connection consider consistent constant constraint constraints constructor container content contents context contributors controlfile conv convert convert_tz corr corr_k corr_s corresponding corruption cos cost count count_big counted covar_pop covar_samp cpu_per_call cpu_per_session crc32 create creation critical cross cube cume_dist curdate current current_date current_time current_timestamp current_user cursor curtime customdatum cycle d data database databases datafile datafiles datalength date_add date_cache date_format date_sub dateadd datediff datefromparts datename datepart datetime2fromparts day day_to_second dayname dayofmonth dayofweek dayofyear days db_role_change dbtimezone ddl deallocate declare decode decompose decrement decrypt deduplicate def defa defau defaul default defaults deferred defi defin define degrees delayed delegate delete delete_all delimited demand dense_rank depth dequeue des_decrypt des_encrypt des_key_file desc descr descri describ describe descriptor deterministic diagnostics difference dimension direct_load directory disable disable_all disallow disassociate discardfile disconnect diskgroup distinct distinctrow distribute distributed div do document domain dotnet double downgrade drop dumpfile duplicate duration e each edition editionable editions element ellipsis else elsif elt empty enable enable_all enclosed encode encoding encrypt end end-exec endian enforced engine engines enqueue enterprise entityescaping eomonth error errors escaped evalname evaluate event eventdata events except exception exceptions exchange exclude excluding execu execut execute exempt exists exit exp expire explain export export_set extended extent external external_1 external_2 externally extract f failed failed_login_attempts failover failure far fast feature_set feature_value fetch field fields file file_name_convert filesystem_like_logging final finish first first_value fixed flash_cache flashback floor flush following follows for forall force form forma format found found_rows freelist freelists freepools fresh from from_base64 from_days ftp full function g general generated get get_format get_lock getdate getutcdate global global_name globally go goto grant grants greatest group group_concat group_id grouping grouping_id groups gtid_subtract guarantee guard handler hash hashkeys having hea head headi headin heading heap help hex hierarchy high high_priority hosts hour http i id ident_current ident_incr ident_seed identified identity idle_time if ifnull ignore iif ilike ilm immediate import in include including increment index indexes indexing indextype indicator indices inet6_aton inet6_ntoa inet_aton inet_ntoa infile initial initialized initially initrans inmemory inner innodb input insert install instance instantiable instr interface interleaved intersect into invalidate invisible is is_free_lock is_ipv4 is_ipv4_compat is_not is_not_null is_used_lock isdate isnull isolation iterate java join json json_exists k keep keep_duplicates key keys kill l language large last last_day last_insert_id last_value lax lcase lead leading least leaves left len lenght length less level levels library like like2 like4 likec limit lines link list listagg little ln load load_file lob lobs local localtime localtimestamp locate locator lock locked log log10 log2 logfile logfiles logging logical logical_reads_per_call logoff logon logs long loop low low_priority lower lpad lrtrim ltrim m main make_set makedate maketime managed management manual map mapping mask master master_pos_wait match matched materialized max maxextents maximize maxinstances maxlen maxlogfiles maxloghistory maxlogmembers maxsize maxtrans md5 measures median medium member memcompress memory merge microsecond mid migration min minextents minimum mining minus minute minvalue missing mod mode model modification modify module monitoring month months mount move movement multiset mutex n name name_const names nan national native natural nav nchar nclob nested never new newline next nextval no no_write_to_binlog noarchivelog noaudit nobadfile nocheck nocompress nocopy nocycle nodelay nodiscardfile noentityescaping noguarantee nokeep nologfile nomapping nomaxvalue nominimize nominvalue nomonitoring none noneditionable nonschema noorder nopr nopro noprom nopromp noprompt norely noresetlogs noreverse normal norowdependencies noschemacheck noswitch not nothing notice notrim novalidate now nowait nth_value nullif nulls num numb numbe nvarchar nvarchar2 object ocicoll ocidate ocidatetime ociduration ociinterval ociloblocator ocinumber ociref ocirefcursor ocirowid ocistring ocitype oct octet_length of off offline offset oid oidindex old on online only opaque open operations operator optimal optimize option optionally or oracle oracle_date oradata ord ordaudio orddicom orddoc order ordimage ordinality ordvideo organization orlany orlvary out outer outfile outline output over overflow overriding p package pad parallel parallel_enable parameters parent parse partial partition partitions pascal passing password password_grace_time password_lock_time password_reuse_max password_reuse_time password_verify_function patch path patindex pctincrease pctthreshold pctused pctversion percent percent_rank percentile_cont percentile_disc performance period period_add period_diff permanent physical pi pipe pipelined pivot pluggable plugin policy position post_transaction pow power pragma prebuilt precedes preceding precision prediction prediction_cost prediction_details prediction_probability prediction_set prepare present preserve prior priority private private_sga privileges procedural procedure procedure_analyze processlist profiles project prompt protection public publishingservername purge quarter query quick quiesce quota quotename radians raise rand range rank raw read reads readsize rebuild record records recover recovery recursive recycle redo reduced ref reference referenced references referencing refresh regexp_like register regr_avgx regr_avgy regr_count regr_intercept regr_r2 regr_slope regr_sxx regr_sxy reject rekey relational relative relaylog release release_lock relies_on relocate rely rem remainder rename repair repeat replace replicate replication required reset resetlogs resize resource respect restore restricted result result_cache resumable resume retention return returning returns reuse reverse revoke right rlike role roles rollback rolling rollup round row row_count rowdependencies rowid rownum rows rtrim rules safe salt sample save savepoint sb1 sb2 sb4 scan schema schemacheck scn scope scroll sdo_georaster sdo_topo_geometry search sec_to_time second section securefile security seed segment select self sequence sequential serializable server servererror session session_user sessions_per_user set sets settings sha sha1 sha2 share shared shared_pool short show shrink shutdown si_averagecolor si_colorhistogram si_featurelist si_positionalcolor si_stillimage si_texture siblings sid sign sin size size_t sizes skip slave sleep smalldatetimefromparts smallfile snapshot some soname sort soundex source space sparse spfile split sql sql_big_result sql_buffer_result sql_cache sql_calc_found_rows sql_small_result sql_variant_property sqlcode sqldata sqlerror sqlname sqlstate sqrt square standalone standby start starting startup statement static statistics stats_binomial_test stats_crosstab stats_ks_test stats_mode stats_mw_test stats_one_way_anova stats_t_test_ stats_t_test_indep stats_t_test_one stats_t_test_paired stats_wsr_test status std stddev stddev_pop stddev_samp stdev stop storage store stored str str_to_date straight_join strcmp strict string struct stuff style subdate subpartition subpartitions substitutable substr substring subtime subtring_index subtype success sum suspend switch switchoffset switchover sync synchronous synonym sys sys_xmlagg sysasm sysaux sysdate sysdatetimeoffset sysdba sysoper system system_user sysutcdatetime t table tables tablespace tan tdo template temporary terminated tertiary_weights test than then thread through tier ties time time_format time_zone timediff timefromparts timeout timestamp timestampadd timestampdiff timezone_abbr timezone_minute timezone_region to to_base64 to_date to_days to_seconds todatetimeoffset trace tracking transaction transactional translate translation treat trigger trigger_nestlevel triggers trim truncate try_cast try_convert try_parse type ub1 ub2 ub4 ucase unarchived unbounded uncompress under undo unhex unicode uniform uninstall union unique unix_timestamp unknown unlimited unlock unpivot unrecoverable unsafe unsigned until untrusted unusable unused update updated upgrade upped upper upsert url urowid usable usage use use_stored_outlines user user_data user_resources users using utc_date utc_timestamp uuid uuid_short validate validate_password_strength validation valist value values var var_samp varcharc vari varia variab variabl variable variables variance varp varraw varrawc varray verify version versions view virtual visible void wait wallet warning warnings week weekday weekofyear wellformed when whene whenev wheneve whenever where while whitespace with within without work wrapped xdb xml xmlagg xmlattributes xmlcast xmlcolattval xmlelement xmlexists xmlforest xmlindex xmlnamespaces xmlpi xmlquery xmlroot xmlschema xmlserialize xmltable xmltype xor year year_to_month years yearweek
  69. // Lucida Console on Windows has capital V's that look like lower case, so don't use it
  70. var codeFontStack = "Menlo,Consolas,monospace";
  71. var codeFontSize = 105.1316178 / measureFontSize(codeFontStack) + 'px';
  72. var BODY_STYLESHEET = entag('style', 'body{max-width:680px;' +
  73. 'margin:auto;' +
  74. 'padding:20px;' +
  75. 'text-align:justify;' +
  76. 'line-height:140%; ' +
  77. '-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;font-smoothing:antialiased;' +
  78. 'color:#222;' +
  79. 'font-family:Palatino,Georgia,"Times New Roman",serif}');
  80. /** You can embed your own stylesheet AFTER the <script> tags in your
  81. file to override these defaults. */
  82. var STYLESHEET = entag('style',
  83. 'body{' +
  84. 'counter-reset: h1 h2 h3 h4 h5 h6 paragraph' +
  85. '}' +
  86. '.md code,pre{' +
  87. 'font-family:' + codeFontStack + ';' +
  88. 'font-size:' + codeFontSize + ';' +
  89. 'line-height:140%' +
  90. '}' +
  91. '.md div.title{' +
  92. 'font-size:26px;' +
  93. 'font-weight:800;' +
  94. 'line-height:120%;' +
  95. 'text-align:center' +
  96. '}' +
  97. '.md div.afterTitles{height:10px}' +
  98. '.md div.subtitle{' +
  99. 'text-align:center' +
  100. '}' +
  101. '.md .image{display:inline-block}' +
  102. '.md div.imagecaption,.md div.tablecaption,.md div.listingcaption{' +
  103. 'margin:5px 5px 5px 5px;' +
  104. 'text-align: justify;' +
  105. 'font-style:italic' +
  106. '}' +
  107. '.md div.imagecaption{' +
  108. 'margin-bottom:0' +
  109. '}' +
  110. '.md img{' +
  111. 'max-width:100%;' +
  112. 'page-break-inside:avoid' +
  113. '}' +
  114. // Justification tends to handle URLs and code blocks poorly
  115. // when inside of a bullet, so disable it there
  116. '.md li{text-align:left};' +
  117. // Force captions on line listings down close and then center them
  118. '.md div.tilde{' +
  119. 'margin:20px 0 -10px;' +
  120. 'text-align:center' +
  121. '}' +
  122. '.md blockquote.fancyquote{' +
  123. 'margin:25px 0 25px;' +
  124. 'text-align:left;' +
  125. 'line-height:160%' +
  126. '}' +
  127. '.md blockquote.fancyquote::before{' +
  128. 'content:"\u201C";' +
  129. 'color:#DDD;' +
  130. 'font-family:Times New Roman;' +
  131. 'font-size:45px;' +
  132. 'line-height:0;' +
  133. 'margin-right:6px;' +
  134. 'vertical-align:-0.3em' +
  135. '}' +
  136. '.md span.fancyquote{' +
  137. 'font-size:118%;' +
  138. 'color:#777;' +
  139. 'font-style:italic' +
  140. '}' +
  141. '.md span.fancyquote::after{' +
  142. 'content:"\u201D";' +
  143. 'font-style:normal;' +
  144. 'color:#DDD;' +
  145. 'font-family:Times New Roman;' +
  146. 'font-size:45px;' +
  147. 'line-height:0;' +
  148. 'margin-left:6px;' +
  149. 'vertical-align:-0.3em' +
  150. '}' +
  151. '.md blockquote.fancyquote .author{' +
  152. 'width:100%;' +
  153. 'margin-top:10px;' +
  154. 'display:inline-block;' +
  155. 'text-align:right' +
  156. '}' +
  157. '.md small{font-size:60%}' +
  158. '.md div.title,contents,.md .tocHeader,h1,h2,h3,h4,h5,h6,.md .shortTOC,.md .mediumTOC,.nonumberh1,.nonumberh2,.nonumberh3,.nonumberh4,.nonumberh5,.nonumberh6{' +
  159. 'font-family:Verdana,Helvetica,Arial,sans-serif;' +
  160. 'margin:13.4px 0 13.4px;' +
  161. 'padding:15px 0 3px;' +
  162. 'border-top:none;' +
  163. 'clear:both' +
  164. '}' +
  165. '.md h1,.md h2,.md h3,.md h4,.md h5,.md h6,.md .nonumberh1,.md .nonumberh2,.md .nonumberh3,.md .nonumberh4,.md .nonumberh5,.md .nonumberh6{' +
  166. 'page-break-after:avoid;break-after:avoid' +
  167. '}'+
  168. '.md svg.diagram{' +
  169. 'display:block;' +
  170. 'font-family:' + codeFontStack + ';' +
  171. 'font-size:' + codeFontSize + ';' +
  172. 'text-align:center;' +
  173. 'stroke-linecap:round;' +
  174. 'stroke-width:' + STROKE_WIDTH + 'px;'+
  175. 'page-break-inside:avoid;' +
  176. 'stroke:#000;' +
  177. 'fill:#000' +
  178. '}' +
  179. '.md svg.diagram .opendot{' +
  180. 'fill:#FFF' +
  181. '}' +
  182. '.md svg.diagram text{' +
  183. 'stroke:none' +
  184. '}' +
  185. // pagebreak hr
  186. '@media print{.md .pagebreak{page-break-after:always;visibility:hidden}}' +
  187. // Not restricted to a:link because we want things like svn URLs to have this font, which
  188. // makes "//" look better.
  189. '.md a{font-family:Georgia,Palatino,\'Times New Roman\'}' +
  190. '.md h1,.md .tocHeader,.md .nonumberh1{' +
  191. 'border-bottom:3px solid;' +
  192. 'font-size:20px;' +
  193. 'font-weight:bold;' +
  194. '}' +
  195. '.md h1,.md .nonumberh1{' +
  196. 'counter-reset: h2 h3 h4 h5 h6' +
  197. '}' +
  198. '.md h2,.md .nonumberh2{' +
  199. 'counter-reset: h3 h4 h5 h6;' +
  200. 'border-bottom:2px solid #999;' +
  201. 'color:#555;' +
  202. 'font-weight:bold;'+
  203. 'font-size:18px;' +
  204. '}' +
  205. '.md h3,.md h4,.md h5,.md h6,.md .nonumberh3,.md .nonumberh4,.md .nonumberh5,.md .nonumberh6{' +
  206. 'font-family:Helvetica,Arial,sans-serif;' +
  207. 'color:#555;' +
  208. 'font-size:16px;' +
  209. '}' +
  210. '.md h3{counter-reset:h4 h5 h6}' +
  211. '.md h4{counter-reset:h5 h6}' +
  212. '.md h5{counter-reset:h6}' +
  213. '.md div.table{' +
  214. 'margin:16px 0 16px 0' +
  215. '}' +
  216. '.md table{' +
  217. 'font-size:9px;'+
  218. 'border-collapse:collapse;' +
  219. 'line-height:140%;' +
  220. 'page-break-inside:avoid' +
  221. '}' +
  222. '.md table.table{' +
  223. 'margin:auto' +
  224. '}' +
  225. '.md table.calendar{' +
  226. 'width:100%;' +
  227. 'margin:auto;' +
  228. 'font-size:11px;' +
  229. 'font-family:Helvetica,Arial,sans-serif' +
  230. '}' +
  231. '.md table.calendar th{' +
  232. 'font-size:16px' +
  233. '}' +
  234. '.md .today{' +
  235. 'background:#ECF8FA' +
  236. '}' +
  237. '.md .calendar .parenthesized{' +
  238. 'color:#999;' +
  239. 'font-style:italic' +
  240. '}' +
  241. '.md div.tablecaption{' +
  242. 'text-align:center' +
  243. '}' +
  244. '.md table.table th{' +
  245. 'color:#FFF;' +
  246. 'background-color:#AAA;' +
  247. 'border:1px solid #888;' +
  248. // top right bottom left
  249. 'padding:8px 15px 8px 15px' +
  250. '}' +
  251. '.md table.table td{' +
  252. // top right bottom left
  253. 'padding:5px 15px 5px 15px;' +
  254. 'border:1px solid #888' +
  255. '}' +
  256. '.md table.table tr:nth-child(even){'+
  257. 'background:#EEE' +
  258. '}' +
  259. '.md pre.tilde{' +
  260. 'border-top: 1px solid #CCC;' +
  261. 'border-bottom: 1px solid #CCC;' +
  262. 'padding: 5px 0 5px 20px;' +
  263. 'margin:0 0 0 0;' +
  264. 'background:#FCFCFC;' +
  265. 'page-break-inside:avoid' +
  266. '}' +
  267. '.md a.target{width:0px;height:0px;visibility:hidden;font-size:0px;display:inline-block}' +
  268. '.md a:link, .md a:visited{color:#38A;text-decoration:none}' +
  269. '.md a:link:hover{text-decoration:underline}' +
  270. '.md dt{' +
  271. 'font-weight:700' +
  272. '}' +
  273. // Remove excess space above definitions due to paragraph breaks, and add some at the bottom
  274. '.md dl>dd{margin-top:-8px; margin-bottom:8px}' +
  275. // Extra space around terse definition lists
  276. '.md dl>table{' +
  277. 'margin:35px 0 30px' +
  278. '}' +
  279. '.md code{' +
  280. 'white-space:pre;' +
  281. 'page-break-inside:avoid' +
  282. '}' +
  283. '.md .endnote{' +
  284. 'font-size:13px;' +
  285. 'line-height:15px;' +
  286. 'padding-left:10px;' +
  287. 'text-indent:-10px' +
  288. '}' +
  289. '.md .bib{' +
  290. 'padding-left:80px;' +
  291. 'text-indent:-80px;' +
  292. 'text-align:left' +
  293. '}' +
  294. '.markdeepFooter{font-size:9px;text-align:right;padding-top:80px;color:#999}' +
  295. '.md .mediumTOC{float:right;font-size:12px;line-height:15px;border-left:1px solid #CCC;padding-left:15px;margin:15px 0px 15px 25px}' +
  296. '.md .mediumTOC .level1{font-weight:600}' +
  297. '.md .longTOC .level1{font-weight:600;display:block;padding-top:12px;margin:0 0 -20px}' +
  298. '.md .shortTOC{text-align:center;font-weight:bold;margin-top:15px;font-size:14px}' +
  299. '.md .admonition{' +
  300. 'position:relative;' +
  301. 'margin:1em 0;' +
  302. 'padding:.4rem 1rem;' +
  303. 'border-radius:.2rem;' +
  304. 'border-left:2.5rem solid rgba(68,138,255,.4);' +
  305. 'background-color:rgba(68,138,255,.15);' +
  306. '}' +
  307. '.md .admonition-title{' +
  308. 'font-weight:bold;' +
  309. 'border-bottom:solid 1px rgba(68,138,255,.4);' +
  310. 'padding-bottom:4px;' +
  311. 'margin-bottom:4px;' +
  312. 'margin-left: -1rem;' +
  313. 'padding-left:1rem;' +
  314. 'margin-right:-1rem;' +
  315. 'border-color:rgba(68,138,255,.4)' +
  316. '}' +
  317. '.md .admonition.tip{' +
  318. 'border-left:2.5rem solid rgba(50,255,90,.4);' +
  319. 'background-color:rgba(50,255,90,.15)' +
  320. '}' +
  321. '.md .admonition.tip::before{' +
  322. 'content:"\\24d8";' +
  323. 'font-weight:bold;' +
  324. 'font-size:150%;' +
  325. 'position:relative;' +
  326. 'top:3px;' +
  327. 'color:rgba(26,128,46,.8);' +
  328. 'left:-2.95rem;' +
  329. 'display:block;' +
  330. 'width:0;' +
  331. 'height:0' +
  332. '}' +
  333. '.md .admonition.tip>.admonition-title{' +
  334. 'border-color:rgba(50,255,90,.4)' +
  335. '}' +
  336. '.md .admonition.warn,.md .admonition.warning{' +
  337. 'border-left:2.5rem solid rgba(255,145,0,.4);' +
  338. 'background-color:rgba(255,145,0,.15)' +
  339. '}' +
  340. '.md .admonition.warn::before,.md .admonition.warning::before{' +
  341. 'content:"\\26A0";' +
  342. 'font-weight:bold;' +
  343. 'font-size:150%;' +
  344. 'position:relative;' +
  345. 'top:2px;' +
  346. 'color:rgba(128,73,0,.8);' +
  347. 'left:-2.95rem;' +
  348. 'display:block;' +
  349. 'width:0;' +
  350. 'height:0' +
  351. '}' +
  352. '.md .admonition.warn>.admonition-title{' +
  353. 'border-color:rgba(255,145,0,.4)' +
  354. '}' +
  355. '.md .admonition.error{' +
  356. 'border-left: 2.5rem solid rgba(255,23,68,.4);'+
  357. 'background-color:rgba(255,23,68,.15)' +
  358. '}' +
  359. '.md .admonition.error>.admonition-title{' +
  360. 'border-color:rgba(255,23,68,.4)'+
  361. '}' +
  362. '.md .admonition.error::before{' +
  363. 'content: "\\2612";' +
  364. 'font-family:"Arial";' +
  365. 'font-size:200%;' +
  366. 'position:relative;' +
  367. 'color:rgba(128,12,34,.8);' +
  368. 'top:-2px;' +
  369. 'left:-3rem;' +
  370. 'display:block;' +
  371. 'width:0;' +
  372. 'height:0' +
  373. '}' +
  374. '.md .admonition p:last-child{margin-bottom:0}'
  375. );
  376. var MARKDEEP_LINE = '<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js"></script><script src="https://casual-effects.com/markdeep/latest/markdeep.min.js?"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script>';
  377. // Language options:
  378. var FRENCH = {
  379. keyword: {
  380. table: 'tableau',
  381. figure: 'figure',
  382. listing: 'liste',
  383. diagram: 'diagramme',
  384. contents: 'Table des matières',
  385. sec: 'sec',
  386. section: 'section',
  387. subsection: 'paragraphe',
  388. Monday: 'lundi',
  389. Tuesday: 'mardi',
  390. Wednesday: 'mercredi',
  391. Thursday: 'jeudi',
  392. Friday: 'vendredi',
  393. Saturday: 'samedi',
  394. Sunday: 'dimanche',
  395. January: 'Janvier',
  396. February: 'Février',
  397. March: 'Mars',
  398. April: 'Avril',
  399. May: 'Mai',
  400. June: 'Juin',
  401. July: 'Julliet',
  402. August: 'Août',
  403. September: 'Septembre',
  404. October: 'Octobre',
  405. November: 'Novembre',
  406. December: 'Décembre',
  407. jan: 'janv',
  408. feb: 'févr',
  409. mar: 'mars',
  410. apr: 'avril',
  411. may: 'mai',
  412. jun: 'juin',
  413. jul: 'juil',
  414. aug: 'août',
  415. sep: 'sept',
  416. oct: 'oct',
  417. nov: 'nov',
  418. dec: 'déc'
  419. }
  420. };
  421. // Translated by Zdravko Velinov
  422. var BULGARIAN = {
  423. keyword: {
  424. table: 'таблица',
  425. figure: 'фигура',
  426. listing: 'списък',
  427. diagram: 'диаграма',
  428. contents: 'cъдържание',
  429. sec: 'сек',
  430. section: 'раздел',
  431. subsection: 'подраздел',
  432. Monday: 'понеделник',
  433. Tuesday: 'вторник',
  434. Wednesday: 'сряда',
  435. Thursday: 'четвъртък',
  436. Friday: 'петък',
  437. Saturday: 'събота',
  438. Sunday: 'неделя',
  439. January: 'януари',
  440. February: 'февруари',
  441. March: 'март',
  442. April: 'април',
  443. May: 'май',
  444. June: 'юни',
  445. July: 'юли',
  446. August: 'август',
  447. September: 'септември',
  448. October: 'октомври',
  449. November: 'ноември',
  450. December: 'декември',
  451. jan: 'ян',
  452. feb: 'февр',
  453. mar: 'март',
  454. apr: 'апр',
  455. may: 'май',
  456. jun: 'юни',
  457. jul: 'юли',
  458. aug: 'авг',
  459. sep: 'септ',
  460. oct: 'окт',
  461. nov: 'ноем',
  462. dec: 'дек'
  463. }
  464. };
  465. var RUSSIAN = {
  466. keyword: {
  467. table: 'таблица',
  468. figure: 'рисунок',
  469. listing: 'листинг',
  470. diagram: 'диаграмма',
  471. contents: 'Содержание',
  472. sec: 'сек',
  473. section: 'раздел',
  474. subsection: 'подраздел',
  475. Monday: 'понедельник',
  476. Tuesday: 'вторник',
  477. Wednesday: 'среда',
  478. Thursday: 'четверг',
  479. Friday: 'пятница',
  480. Saturday: 'суббота',
  481. Sunday: 'воскресенье',
  482. January: 'январьr',
  483. February: 'февраль',
  484. March: 'март',
  485. April: 'апрель',
  486. May: 'май',
  487. June: 'июнь',
  488. July: 'июль',
  489. August: 'август',
  490. September: 'сентябрь',
  491. October: 'октябрь',
  492. November: 'ноябрь',
  493. December: 'декабрь',
  494. jan: 'янв',
  495. feb: 'февр',
  496. mar: 'март',
  497. apr: 'апр',
  498. may: 'май',
  499. jun: 'июнь',
  500. jul: 'июль',
  501. aug: 'авг',
  502. sep: 'сент',
  503. oct: 'окт',
  504. nov: 'ноябрь',
  505. dec: 'дек'
  506. }
  507. };
  508. // Translated by Dariusz Kuśnierek
  509. var POLISH = {
  510. keyword: {
  511. table: 'tabela',
  512. figure: 'ilustracja',
  513. listing: 'wykaz',
  514. diagram: 'diagram',
  515. contents: 'Spis treści',
  516. sec: 'rozdz.',
  517. section: 'rozdział',
  518. subsection: 'podrozdział',
  519. Monday: 'Poniedziałek',
  520. Tuesday: 'Wtorek',
  521. Wednesday: 'Środa',
  522. Thursday: 'Czwartek',
  523. Friday: 'Piątek',
  524. Saturday: 'Sobota',
  525. Sunday: 'Niedziela',
  526. January: 'Styczeń',
  527. February: 'Luty',
  528. March: 'Marzec',
  529. April: 'Kwiecień',
  530. May: 'Maj',
  531. June: 'Czerwiec',
  532. July: 'Lipiec',
  533. August: 'Sierpień',
  534. September: 'Wrzesień',
  535. October: 'Październik',
  536. November: 'Listopad',
  537. December: 'Grudzień',
  538. jan: 'sty',
  539. feb: 'lut',
  540. mar: 'mar',
  541. apr: 'kwi',
  542. may: 'maj',
  543. jun: 'cze',
  544. jul: 'lip',
  545. aug: 'sie',
  546. sep: 'wrz',
  547. oct: 'paź',
  548. nov: 'lis',
  549. dec: 'gru'
  550. }
  551. };
  552. // Translated by Sandor Berczi
  553. var HUNGARIAN = {
  554. keyword: {
  555. table: 'táblázat',
  556. figure: 'ábra',
  557. listing: 'lista',
  558. diagram: 'diagramm',
  559. contents: 'Tartalomjegyzék',
  560. sec: 'fej', // Abbreviation for section
  561. section: 'fejezet',
  562. subsection:'alfejezet',
  563. Monday: 'hétfő',
  564. Tuesday: 'kedd',
  565. Wednesday: 'szerda',
  566. Thursday: 'csütörtök',
  567. Friday: 'péntek',
  568. Saturday: 'szombat',
  569. Sunday: 'vasárnap',
  570. January: 'január',
  571. February: 'február',
  572. March: 'március',
  573. April: 'április',
  574. May: 'május',
  575. June: 'június',
  576. July: 'július',
  577. August: 'augusztus',
  578. September: 'szeptember',
  579. October: 'október',
  580. November: 'november',
  581. December: 'december',
  582. jan: 'jan',
  583. feb: 'febr',
  584. mar: 'márc',
  585. apr: 'ápr',
  586. may: 'máj',
  587. jun: 'jún',
  588. jul: 'júl',
  589. aug: 'aug',
  590. sep: 'szept',
  591. oct: 'okt',
  592. nov: 'nov',
  593. dec: 'dec'
  594. }
  595. };
  596. // Translated by Takashi Masuyama
  597. var JAPANESE = {
  598. keyword: {
  599. table: '表',
  600. figure: '図',
  601. listing: '一覧',
  602. diagram: '図',
  603. contents: '目次',
  604. sec: '章',
  605. section: '節',
  606. subsection: '項',
  607. Monday: '月',
  608. Tuesday: '火',
  609. Wednesday: '水',
  610. Thursday: '木',
  611. Friday: '金',
  612. Saturday: '土',
  613. Sunday: '日',
  614. January: '1月',
  615. February: '2月',
  616. March: '3月',
  617. April: '4月',
  618. May: '5月',
  619. June: '6月',
  620. July: '7月',
  621. August: '8月',
  622. September: '9月',
  623. October: '10月',
  624. November: '11月',
  625. December: '12月',
  626. jan: '1月',
  627. feb: '2月',
  628. mar: '3月',
  629. apr: '4月',
  630. may: '5月',
  631. jun: '6月',
  632. jul: '7月',
  633. aug: '8月',
  634. sep: '9月',
  635. oct: '10月',
  636. nov: '11月',
  637. dec: '12月'
  638. }
  639. };
  640. // Translated by Sandor Berczi
  641. var GERMAN = {
  642. keyword: {
  643. table: 'Tabelle',
  644. figure: 'Abbildung',
  645. listing: 'Auflistung',
  646. diagram: 'Diagramm',
  647. contents: 'Inhaltsverzeichnis',
  648. sec: 'Kap',
  649. section: 'Kapitel',
  650. subsection:'Unterabschnitt',
  651. Monday: 'Montag',
  652. Tuesday: 'Dienstag',
  653. Wednesday: 'Mittwoch',
  654. Thursday: 'Donnerstag',
  655. Friday: 'Freitag',
  656. Saturday: 'Samstag',
  657. Sunday: 'Sonntag',
  658. January: 'Januar',
  659. February: 'Februar',
  660. March: 'März',
  661. April: 'April',
  662. May: 'Mai',
  663. June: 'Juni',
  664. July: 'Juli',
  665. August: 'August',
  666. September: 'September',
  667. October: 'Oktober',
  668. November: 'November',
  669. December: 'Dezember',
  670. jan: 'Jan',
  671. feb: 'Feb',
  672. mar: 'Mär',
  673. apr: 'Apr',
  674. may: 'Mai',
  675. jun: 'Jun',
  676. jul: 'Jul',
  677. aug: 'Aug',
  678. sep: 'Sep',
  679. oct: 'Okt',
  680. nov: 'Nov',
  681. dec: 'Dez'
  682. }
  683. };
  684. // Translated by Nils Nilsson
  685. var SWEDISH = {
  686. keyword: {
  687. table: 'tabell',
  688. figure: 'figur',
  689. listing: 'lista',
  690. diagram: 'diagram',
  691. contents: 'innehållsförteckning',
  692. sec: 'sek',
  693. subsection:'undersektion',
  694. Monday: 'måndag',
  695. Tuesday: 'tisdag',
  696. Wednesday: 'onsdag',
  697. Thursday: 'torsdag',
  698. Friday: 'fredag',
  699. Saturday: 'lördag',
  700. Sunday: 'söndag',
  701. January: 'januari',
  702. February: 'februari',
  703. March: 'mars',
  704. April: 'april',
  705. May: 'maj',
  706. June: 'juni',
  707. July: 'juli',
  708. August: 'augusti',
  709. September: 'september',
  710. October: 'oktober',
  711. November: 'november',
  712. December: 'december',
  713. jan: 'jan',
  714. feb: 'feb',
  715. mar: 'mar',
  716. apr: 'apr',
  717. may: 'maj',
  718. jun: 'jun',
  719. jul: 'jul',
  720. aug: 'aug',
  721. sep: 'sep',
  722. oct: 'okt',
  723. nov: 'nov',
  724. dec: 'dec'
  725. }
  726. };
  727. var DEFAULT_OPTIONS = {
  728. mode: 'markdeep',
  729. detectMath: true,
  730. lang: {keyword:{}}, // English
  731. tocStyle: 'auto',
  732. hideEmptyWeekends: true,
  733. showLabels: false,
  734. sortScheduleLists: true,
  735. captionAbove: {diagram: false,
  736. image: false,
  737. table: false,
  738. listing: false}
  739. };
  740. // See http://www.i18nguy.com/unicode/language-identifiers.html for keys
  741. var LANG_TABLE = {
  742. en: {keyword:{}},
  743. ru: RUSSIAN,
  744. fr: FRENCH,
  745. pl: POLISH,
  746. bg: BULGARIAN,
  747. de: GERMAN,
  748. hu: HUNGARIAN,
  749. sv: SWEDISH,
  750. ja: JAPANESE
  751. // Awaiting localization by a native speaker:
  752. // es: SPANISH
  753. // ...
  754. };
  755. [].slice.call(document.getElementsByTagName('meta')).forEach(function(elt) {
  756. var att = elt.getAttribute('lang');
  757. if (att) {
  758. var lang = LANG_TABLE[att];
  759. if (lang) {
  760. DEFAULT_OPTIONS.lang = lang;
  761. }
  762. }
  763. });
  764. var max = Math.max;
  765. var min = Math.min;
  766. var abs = Math.abs;
  767. var sign = Math.sign || function (x) {
  768. return ( +x === x ) ? ((x === 0) ? x : (x > 0) ? 1 : -1) : NaN;
  769. };
  770. /** Get an option, or return the corresponding value from DEFAULT_OPTIONS */
  771. function option(key, key2) {
  772. if (window.markdeepOptions && (window.markdeepOptions[key] !== undefined)) {
  773. var val = window.markdeepOptions[key];
  774. if (key2) {
  775. val = val[key2]
  776. if (val !== undefined) {
  777. return val;
  778. } else {
  779. return DEFAULT_OPTIONS[key][key2];
  780. }
  781. } else {
  782. return window.markdeepOptions[key];
  783. }
  784. } else if (DEFAULT_OPTIONS[key] !== undefined) {
  785. if (key2) {
  786. return DEFAULT_OPTIONS[key][key2];
  787. } else {
  788. return DEFAULT_OPTIONS[key];
  789. }
  790. } else {
  791. console.warn('Illegal option: "' + key + '"');
  792. return undefined;
  793. }
  794. }
  795. function maybeShowLabel(url, tag) {
  796. if (option('showLabels')) {
  797. var text = ' {\u00A0' + url + '\u00A0}';
  798. return tag ? entag(tag, text) : text;
  799. } else {
  800. return '';
  801. }
  802. }
  803. // Returns the localized version of word, defaulting to the word itself
  804. function keyword(word) {
  805. return option('lang').keyword[word.toLowerCase()] || word;
  806. }
  807. /** Converts <>&" to their HTML escape sequences */
  808. function escapeHTMLEntities(str) {
  809. return String(str).rp(/&/g, '&amp;').rp(/</g, '&lt;').rp(/>/g, '&gt;').rp(/"/g, '&quot;');
  810. }
  811. /** Restores the original source string's '<' and '>' as entered in
  812. the document, before the browser processed it as HTML. There is no
  813. way in an HTML document to distinguish an entity that was entered
  814. as an entity. */
  815. function unescapeHTMLEntities(str) {
  816. // Process &amp; last so that we don't recursively unescape
  817. // escaped escape sequences.
  818. return str.
  819. rp(/&lt;/g, '<').
  820. rp(/&gt;/g, '>').
  821. rp(/&quot;/g, '"').
  822. rp(/&#39;/g, "'").
  823. rp(/&ndash;/g, '\u2013').
  824. rp(/&mdash;/g, '---').
  825. rp(/&amp;/g, '&');
  826. }
  827. function removeHTMLTags(str) {
  828. return str.rp(/<.*?>/g, '');
  829. }
  830. /** Turn the argument into a legal URL anchor */
  831. function mangle(text) {
  832. return encodeURI(text.rp(/\s/g, '').toLowerCase());
  833. }
  834. /** Creates a style sheet containing elements like:
  835. hn::before {
  836. content: counter(h1) "." counter(h2) "." ... counter(hn) " ";
  837. counter-increment: hn;
  838. }
  839. */
  840. function sectionNumberingStylesheet() {
  841. var s = '';
  842. for (var i = 1; i <= 6; ++i) {
  843. s += '.md h' + i + '::before {\ncontent:';
  844. for (var j = 1; j <= i; ++j) {
  845. s += 'counter(h' + j + ') "' + ((j < i) ? '.' : ' ') + '"';
  846. }
  847. s += ';\ncounter-increment: h' + i + ';margin-right:10px}';
  848. }
  849. return entag('style', s);
  850. }
  851. /**
  852. \param node A node from an HTML DOM
  853. \return A String that is a very good reconstruction of what the
  854. original source looked like before the browser tried to correct
  855. it to legal HTML.
  856. */
  857. function nodeToMarkdeepSource(node, leaveEscapes) {
  858. var source = node.innerHTML;
  859. // Markdown uses <[email protected]> e-mail syntax, which HTML parsing
  860. // will try to close by inserting the matching close tags at the end of the
  861. // document. Remove anything that looks like that and comes *after*
  862. // the first fallback style.
  863. source = source.rp(/(?:<style class="fallback">[\s\S]*?<\/style>[\s\S]*)<\/\S+@\S+\.\S+?>/gim, '');
  864. // Remove artificially inserted close tags
  865. source = source.rp(/<\/h?ttps?:.*>/gi, '');
  866. // Now try to fix the URLs themselves, which will be
  867. // transformed like this: <http: casual-effects.com="" markdeep="">
  868. source = source.rp(/<(https?): (.*?)>/gi, function (match, protocol, list) {
  869. // Remove any quotes--they wouldn't have been legal in the URL anyway
  870. var s = '<' + protocol + '://' + list.rp(/=""\s/g, '/');
  871. if (s.ss(s.length - 3) === '=""') {
  872. s = s.ss(0, s.length - 3);
  873. }
  874. // Remove any lingering quotes (since they
  875. // wouldn't have been legal in the URL)
  876. s = s.rp(/"/g, '');
  877. return s + '>';
  878. });
  879. // Remove the "fallback" style tags
  880. source = source.rp(/<style class=["']fallback["']>.*?<\/style>/gmi, '');
  881. source = unescapeHTMLEntities(source);
  882. return source;
  883. }
  884. /** Extracts one diagram from a Markdown string.
  885. Returns {beforeString, diagramString, alignmentHint, afterString}
  886. diagramString will be empty if nothing was found. The
  887. DIAGRAM_MARKER is stripped from the diagramString.
  888. alignmentHint may be:
  889. floatleft
  890. floatright
  891. center
  892. flushleft
  893. diagramString does not include the marker characters.
  894. If there is a caption, it will appear in the afterString and not be parsed.
  895. */
  896. function extractDiagram(sourceString) {
  897. // Returns the number of wide Unicode symbols (outside the BMP) in string s between indices
  898. // start and end - 1
  899. function unicodeSyms(s, start, end) {
  900. var p = start;
  901. for (var i = start; i < end; ++i, ++p) {
  902. var c = s.charCodeAt(p);
  903. p += (c >= 0xD800) && (c <= 0xDBFF);
  904. }
  905. return p - end;
  906. }
  907. function advance() {
  908. nextLineBeginning = sourceString.indexOf('\n', lineBeginning) + 1;
  909. wideCharacters = unicodeSyms(sourceString, lineBeginning + xMin, lineBeginning + xMax);
  910. textOnLeft = textOnLeft || /\S/.test(sourceString.ss(lineBeginning, lineBeginning + xMin));
  911. // Text on the right ... if the line is not all '*'
  912. textOnRight = textOnRight || /[^ *\t\n\r]/.test(sourceString.ss(lineBeginning + xMax + wideCharacters + 1, nextLineBeginning));
  913. }
  914. var noDiagramResult = {beforeString: sourceString, diagramString: '', alignmentHint: '', afterString: ''};
  915. // Search sourceString for the first rectangle of enclosed
  916. // DIAGRAM_MARKER characters at least DIAGRAM_START.length wide
  917. for (var i = sourceString.indexOf(DIAGRAM_START);
  918. i >= 0;
  919. i = sourceString.indexOf(DIAGRAM_START, i + DIAGRAM_START.length)) {
  920. // We found what looks like a diagram start. See if it has either a full border of
  921. // aligned '*' characters, or top-left-bottom borders and nothing but white space on
  922. // the left.
  923. // Look backwards to find the beginning of the line (or of the string)
  924. // and measure the start character relative to it
  925. var lineBeginning = max(0, sourceString.lastIndexOf('\n', i)) + 1;
  926. var xMin = i - lineBeginning;
  927. // Find the first non-diagram character on this line...or the end of the entire source string
  928. var j;
  929. for (j = i + DIAGRAM_START.length; sourceString[j] === DIAGRAM_MARKER; ++j) {}
  930. var xMax = j - lineBeginning - 1;
  931. // We have a potential hit. Start accumulating a result. If there was anything
  932. // between the newline and the diagram, move it to the after string for proper alignment.
  933. var result = {
  934. beforeString: sourceString.ss(0, lineBeginning),
  935. diagramString: '',
  936. alignmentHint: 'center',
  937. afterString: sourceString.ss(lineBeginning, i).rp(/[ \t]+$/, ' ')
  938. };
  939. var nextLineBeginning = 0, wideCharacters = 0;
  940. var textOnLeft = false, textOnRight = false;
  941. advance();
  942. // Now, see if the pattern repeats on subsequent lines
  943. for (var good = true, previousEnding = j; good; ) {
  944. // Find the next line
  945. lineBeginning = nextLineBeginning;
  946. advance();
  947. if (lineBeginning === 0) {
  948. // Hit the end of the string before the end of the pattern
  949. return noDiagramResult;
  950. }
  951. if (textOnLeft) {
  952. // Even if there is text on *both* sides
  953. result.alignmentHint = 'floatright';
  954. } else if (textOnRight) {
  955. result.alignmentHint = 'floatleft';
  956. }
  957. // See if there are markers at the correct locations on the next line
  958. if ((sourceString[lineBeginning + xMin] === DIAGRAM_MARKER) &&
  959. (! textOnLeft || (sourceString[lineBeginning + xMax + wideCharacters] === DIAGRAM_MARKER))) {
  960. // See if there's a complete line of DIAGRAM_MARKER, which would end the diagram
  961. var x;
  962. for (x = xMin; (x < xMax) && (sourceString[lineBeginning + x] === DIAGRAM_MARKER); ++x) {}
  963. var begin = lineBeginning + xMin;
  964. var end = lineBeginning + xMax + wideCharacters;
  965. if (! textOnLeft) {
  966. // This may be an incomplete line
  967. var newlineLocation = sourceString.indexOf('\n', begin);
  968. if (newlineLocation !== -1) {
  969. end = Math.min(end, newlineLocation);
  970. }
  971. }
  972. // Trim any excess whitespace caused by our truncation because Markdown will
  973. // interpret that as fixed-formatted lines
  974. result.afterString += sourceString.ss(previousEnding, begin).rp(/^[ \t]*[ \t]/, ' ').rp(/[ \t][ \t]*$/, ' ');
  975. if (x === xMax) {
  976. // We found the last row. Put everything else into
  977. // the afterString and return the result.
  978. result.afterString += sourceString.ss(lineBeginning + xMax + 1);
  979. return result;
  980. } else {
  981. // A line of a diagram. Extract everything before
  982. // the diagram line started into the string of
  983. // content to be placed after the diagram in the
  984. // final HTML
  985. result.diagramString += sourceString.ss(begin + 1, end) + '\n';
  986. previousEnding = end + 1;
  987. }
  988. } else {
  989. // Found an incorrectly delimited line. Abort
  990. // processing of this potential diagram, which is now
  991. // known to NOT be a diagram after all.
  992. good = false;
  993. }
  994. } // Iterate over verticals in the potential box
  995. } // Search for the start
  996. return noDiagramResult;
  997. }
  998. /**
  999. Find the specified delimiterRegExp used as a quote (e.g., *foo*)
  1000. and replace it with the HTML tag and optional attributes.
  1001. */
  1002. function replaceMatched(string, delimiterRegExp, tag, attribs) {
  1003. var delimiter = delimiterRegExp.source;
  1004. var flanking = '[^ \\t\\n' + delimiter + ']';
  1005. var pattern = '([^A-Za-z0-9])(' + delimiter + ')' +
  1006. '(' + flanking + '.*?(\\n.+?)*?)' +
  1007. delimiter + '(?![A-Za-z0-9])';
  1008. return string.rp(new RegExp(pattern, 'g'),
  1009. '$1<' + tag + (attribs ? ' ' + attribs : '') +
  1010. '>$3</' + tag + '>');
  1011. }
  1012. /** Maruku ("github")-style table processing */
  1013. function replaceTables(s, protect) {
  1014. var TABLE_ROW = /(?:\n[ \t]*(?:(?:\|?[ \t\S]+?(?:\|[ \t\S]+?)+\|?)|\|[ \t\S]+\|)(?=\n))/.source;
  1015. var TABLE_SEPARATOR = /\n[ \t]*(?:(?:\|? *\:?-+\:?(?: *\| *\:?-+\:?)+ *\|?|)|\|[\:-]+\|)(?=\n)/.source;
  1016. var TABLE_CAPTION = /\n[ \t]*\[[^\n\|]+\][ \t]*(?=\n)/.source;
  1017. var TABLE_REGEXP = new RegExp(TABLE_ROW + TABLE_SEPARATOR + TABLE_ROW + '+(' + TABLE_CAPTION + ')?', 'g');
  1018. function trimTableRowEnds(row) {
  1019. return row.trim().rp(/^\||\|$/g, '');
  1020. }
  1021. s = s.rp(TABLE_REGEXP, function (match) {
  1022. // Found a table, actually parse it by rows
  1023. var rowArray = match.split('\n');
  1024. var result = '';
  1025. // Skip the bogus leading row
  1026. var startRow = (rowArray[0] === '') ? 1 : 0;
  1027. var caption = rowArray[rowArray.length - 1].trim();
  1028. if ((caption.length > 3) && (caption[0] === '[') && (caption[caption.length - 1] === ']')) {
  1029. // Remove the caption from the row array
  1030. rowArray.pop();
  1031. caption = caption.ss(1, caption.length - 1);
  1032. } else {
  1033. caption = undefined;
  1034. }
  1035. // Parse the separator row for left/center/right-indicating colons
  1036. var columnStyle = [];
  1037. trimTableRowEnds(rowArray[startRow + 1]).rp(/:?-+:?/g, function (match) {
  1038. var left = (match[0] === ':');
  1039. var right = (match[match.length - 1] === ':');
  1040. columnStyle.push(protect(' style="text-align:' + ((left && right) ? 'center' : (right ? 'right' : 'left')) + '"'));
  1041. });
  1042. var row = rowArray[startRow + 1].trim();
  1043. var hasLeadingBar = row[0] === '|';
  1044. var hasTrailingBar = row[row.length - 1] === '|';
  1045. var tag = 'th';
  1046. for (var r = startRow; r < rowArray.length; ++r) {
  1047. // Remove leading and trailing whitespace and column delimiters
  1048. row = rowArray[r].trim();
  1049. if (! hasLeadingBar && (row[0] === '|')) {
  1050. // Empty first column
  1051. row = '&nbsp;' + row;
  1052. }
  1053. if (! hasTrailingBar && (row[row.length - 1] === '|')) {
  1054. // Empty last column
  1055. row += '&nbsp;';
  1056. }
  1057. row = trimTableRowEnds(row);
  1058. var i = 0;
  1059. result += entag('tr', '<' + tag + columnStyle[0] + '> ' +
  1060. row.rp(/ *\| */g, function () {
  1061. ++i;
  1062. return ' </' + tag + '><' + tag + columnStyle[i] + '> ';
  1063. }) + ' </' + tag + '>') + '\n';
  1064. // Skip the header-separator row
  1065. if (r == startRow) {
  1066. ++r;
  1067. tag = 'td';
  1068. }
  1069. }
  1070. result = entag('table', result, protect('class="table"'));
  1071. if (caption) {
  1072. caption = entag('div', caption, protect('class="tablecaption"'));
  1073. if (option('captionAbove', 'table')) {
  1074. result = caption + result;
  1075. } else {
  1076. result = '\n' + result + caption;
  1077. }
  1078. }
  1079. return entag('div', result, "class='table'");
  1080. });
  1081. return s;
  1082. }
  1083. function replaceLists(s, protect) {
  1084. // Identify list blocks:
  1085. // Blank line or line ending in colon, line that starts with #., *, +, or -,
  1086. // and then any number of lines until another blank line
  1087. var BLANK_LINES = /\n\s*\n/.source;
  1088. // Preceding line ending in a colon
  1089. var PREFIX = /[:,]\s*\n/.source;
  1090. var LIST_BLOCK_REGEXP =
  1091. new RegExp('(' + PREFIX + '|' + BLANK_LINES + '|<p>\s*\n|<br/>\s*\n?)' +
  1092. /((?:[ \t]*(?:\d+\.|-|\+|\*)(?:[ \t]+.+\n(?:[ \t]*\n)?)+)+)/.source, 'gm');
  1093. var keepGoing = true;
  1094. var ATTRIBS = {'+': protect('class="plus"'), '-': protect('class="minus"'), '*': protect('class="asterisk"')};
  1095. var NUMBER_ATTRIBS = protect('class="number"');
  1096. // Sometimes the list regexp grabs too much because subsequent lines are indented *less*
  1097. // than the first line. So, if that case is found, re-run the regexp.
  1098. while (keepGoing) {
  1099. keepGoing = false;
  1100. s = s.rp(LIST_BLOCK_REGEXP, function (match, prefix, block) {
  1101. var result = prefix;
  1102. // Contains {indentLevel, tag}
  1103. var stack = [];
  1104. var current = {indentLevel: -1};
  1105. /* function logStack(stack) {
  1106. var s = '[';
  1107. stack.forEach(function(v) { s += v.indentLevel + ', '; });
  1108. console.log(s.ss(0, s.length - 2) + ']');
  1109. } */
  1110. block.split('\n').forEach(function (line) {
  1111. var trimmed = line.rp(/^\s*/, '');
  1112. var indentLevel = line.length - trimmed.length;
  1113. // Add a CSS class based on the type of list bullet
  1114. var attribs = ATTRIBS[trimmed[0]];
  1115. var isUnordered = !! attribs; // JavaScript for: attribs !== undefined
  1116. attribs = attribs || NUMBER_ATTRIBS;
  1117. var isOrdered = /^\d+\.[ \t]/.test(trimmed);
  1118. var isBlank = trimmed === '';
  1119. var start = isOrdered ? ' ' + protect('start=' + trimmed.match(/^\d+/)[0]) : '';
  1120. if (isOrdered || isUnordered) {
  1121. // Add the indentation for the bullet itself
  1122. indentLevel += 2;
  1123. }
  1124. if (! current) {
  1125. // Went below top-level indent
  1126. result += '\n' + line;
  1127. } else if (! isOrdered && ! isUnordered && (isBlank || (indentLevel >= current.indentLevel))) {
  1128. // Line without a marker
  1129. result += '\n' + current.indentChars + line;
  1130. } else {
  1131. //console.log(indentLevel + ":" + line);
  1132. if (indentLevel !== current.indentLevel) {
  1133. // Enter or leave indentation level
  1134. if ((current.indentLevel !== -1) && (indentLevel < current.indentLevel)) {
  1135. while (current && (indentLevel < current.indentLevel)) {
  1136. stack.pop();
  1137. // End the current list and decrease indentation
  1138. result += '\n</li></' + current.tag + '>';
  1139. current = stack[stack.length - 1];
  1140. }
  1141. } else {
  1142. // Start a new list that is more indented
  1143. current = {indentLevel: indentLevel,
  1144. tag: isOrdered ? 'ol' : 'ul',
  1145. // Subtract off the two indent characters we added above
  1146. indentChars: line.ss(0, indentLevel - 2)};
  1147. stack.push(current);
  1148. result += '\n<' + current.tag + start + '>';
  1149. }
  1150. } else if (current.indentLevel !== -1) {
  1151. // End previous list item, if there was one
  1152. result += '\n</li>';
  1153. } // Indent level changed
  1154. if (current) {
  1155. // Add the list item
  1156. result += '\n' + current.indentChars + '<li ' + attribs + '>' + trimmed.rp(/^(\d+\.|-|\+|\*) /, '');
  1157. } else {
  1158. // Just reached something that is *less* indented than the root--
  1159. // copy forward and then re-process that list
  1160. result += '\n' + line;
  1161. keepGoing = true;
  1162. }
  1163. }
  1164. }); // For each line
  1165. // Remove trailing whitespace
  1166. result = result.replace(/\s+$/,'');
  1167. // Finish the last item and anything else on the stack (if needed)
  1168. for (current = stack.pop(); current; current = stack.pop()) {
  1169. result += '</li></' + current.tag + '>';
  1170. }
  1171. return result + '\n\n';
  1172. });
  1173. } // while keep going
  1174. return s;
  1175. }
  1176. /**
  1177. Identifies schedule lists, which look like:
  1178. date: title
  1179. events
  1180. Where date must contain a day, month, and four-number year and may
  1181. also contain a day of the week. Note that the date must not be
  1182. indented and the events must be indented.
  1183. Multiple events per date are permitted.
  1184. */
  1185. function replaceScheduleLists(str, protect) {
  1186. // Must open with something other than indentation or a list
  1187. // marker. There must be a four-digit number somewhere on the
  1188. // line. Exclude lines that begin with an HTML tag...this will
  1189. // avoid parsing headers that have dates in them.
  1190. var BEGINNING = /^(?:[^\|<>\s-\+\*\d].*[12]\d{3}(?!\d).*?|(?:[12]\d{3}(?!\.).*\d.*?)|(?:\d{1,3}(?!\.).*[12]\d{3}(?!\d).*?))/.source;
  1191. // There must be at least one more number in a date, a colon, and then some more text
  1192. var DATE_AND_TITLE = '(' + BEGINNING + '):' + /[ \t]+([^ \t\n].*)\n/.source;
  1193. // The body of the schedule item. It may begin with a blank line and contain
  1194. // multiple paragraphs separated by blank lines...as long as there is indenting
  1195. var EVENTS = /(?:[ \t]*\n)?((?:[ \t]+.+\n(?:[ \t]*\n){0,3})*)/.source;
  1196. var ENTRY = DATE_AND_TITLE + EVENTS;
  1197. var ENTRY_REGEXP = new RegExp(ENTRY, 'gm');
  1198. var rowAttribs = protect('valign="top"');
  1199. var dateTDAttribs = protect('style="width:100px;padding-right:15px" rowspan="2"');
  1200. var eventTDAttribs = protect('style="padding-bottom:25px"');
  1201. var DAY_NAME = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'].map(keyword);
  1202. var MONTH_NAME = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'].map(keyword);
  1203. var MONTH_NAME_LIST = MONTH_NAME.join('|');
  1204. var MONTH_FULL_NAME = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'].map(keyword);
  1205. // Used to mark the center of each day. Not close to midnight to avoid daylight
  1206. // savings problems.
  1207. var standardHour = 9;
  1208. try {
  1209. var scheduleNumber = 0;
  1210. str =
  1211. str.rp(new RegExp('(' + ENTRY + '){2,}', 'gm'),
  1212. function (schedule) {
  1213. ++scheduleNumber;
  1214. // Each entry has the form {date:date, title:string, text:string}
  1215. var entryArray = [];
  1216. // Now parse the schedule into individual day entries
  1217. var anyWeekendEvents = false;
  1218. schedule.rp(ENTRY_REGEXP,
  1219. function (entry, date, title, events) {
  1220. // Remove the day from the date (we'll reconstruct it below). This is actually unnecessary, since we
  1221. // explicitly compute the value anyway and the parser is robust to extra characters, but it aides
  1222. // in debugging.
  1223. //
  1224. // date = date.rp(/(?:(?:sun|mon|tues|wednes|thurs|fri|satur)day|(?:sun|mon|tue|wed|thu|fri|sat)\.?|(?:su|mo|tu|we|th|fr|sa)),?/gi, '');
  1225. // Parse the date. The Javascript Date class's parser is useless because it
  1226. // is locale dependent, so we do this with a regexp.
  1227. var year = '', month = '', day = '', parenthesized = false;
  1228. date = date.trim();
  1229. if ((date[0] === '(') && (date.slice(-1) === ')')) {
  1230. // This is a parenthesized entry
  1231. date = date.slice(1, -1);
  1232. parenthesized = true;
  1233. }
  1234. // DD MM YYYY
  1235. var match = date.match(RegExp('([0123]?\\d)\\D+([01]?\\d|' + MONTH_NAME_LIST + ')\\D+([12]\\d{3})', 'i'));
  1236. if (match) {
  1237. day = match[1]; month = match[2]; year = match[3];
  1238. } else {
  1239. // YYYY MM DD
  1240. match = date.match(RegExp('([12]\\d{3})\\D+([01]?\\d|' + MONTH_NAME_LIST + ')\\D+([0123]?\\d)', 'i'));
  1241. if (match) {
  1242. day = match[3]; month = match[2]; year = match[1];
  1243. } else {
  1244. // monthname day year
  1245. match = date.match(RegExp('(' + MONTH_NAME_LIST + ')\\D+([0123]?\\d)\\D+([12]\\d{3})', 'i'));
  1246. if (match) {
  1247. day = match[2]; month = match[1]; year = match[3];
  1248. } else {
  1249. throw "Could not parse date";
  1250. }
  1251. }
  1252. }
  1253. // Reconstruct standardized date format
  1254. date = day + ' ' + month + ' ' + year;
  1255. // Detect the month
  1256. var monthNumber = parseInt(month) - 1;
  1257. if (isNaN(monthNumber)) {
  1258. monthNumber = MONTH_NAME.indexOf(month.toLowerCase());
  1259. }
  1260. var dateVal = new Date(Date.UTC(parseInt(year), monthNumber, parseInt(day), standardHour));
  1261. // Reconstruct the day of the week
  1262. var dayOfWeek = dateVal.getUTCDay();
  1263. date = DAY_NAME[dayOfWeek] + '<br/>' + date;
  1264. anyWeekendEvents = anyWeekendEvents || (dayOfWeek === 0) || (dayOfWeek === 6);
  1265. entryArray.push({date: dateVal,
  1266. title: title,
  1267. sourceOrder: entryArray.length,
  1268. parenthesized: parenthesized,
  1269. // Don't show text if parenthesized with no body
  1270. text: parenthesized ? '' :
  1271. entag('tr',
  1272. entag('td',
  1273. '<a ' + protect('class="target" name="schedule' + scheduleNumber + '_' + dateVal.getUTCFullYear() + '-' + (dateVal.getUTCMonth() + 1) + '-' + dateVal.getUTCDate() + '"') + '>&nbsp;</a>' +
  1274. date, dateTDAttribs) +
  1275. entag('td', entag('b', title)), rowAttribs) +
  1276. entag('tr', entag('td', '\n\n' + events, eventTDAttribs), rowAttribs)});
  1277. return '';
  1278. });
  1279. // Shallow copy the entries to bypass sorting if needed
  1280. var sourceEntryArray = option('sortScheduleLists') ? entryArray : entryArray.slice(0);
  1281. // Sort by date
  1282. entryArray.sort(function (a, b) {
  1283. // Javascript's sort is not specified to be
  1284. // stable, so we have to preserve
  1285. // sourceOrder in ties.
  1286. var ta = a.date.getTime();
  1287. var tb = b.date.getTime();
  1288. return (ta === tb) ? (a.sourceOrder - b.sourceOrder) : (ta - tb);
  1289. });
  1290. var MILLISECONDS_PER_DAY = 1000 * 60 * 60 * 24;
  1291. // May be slightly off due to daylight savings time
  1292. var approximateDaySpan = (entryArray[entryArray.length - 1].date.getTime() - entryArray[0].date.getTime()) / MILLISECONDS_PER_DAY;
  1293. var today = new Date();
  1294. // Move back to midnight
  1295. today = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate(), standardHour));
  1296. var calendar = '';
  1297. // Make a calendar view with links, if suitable
  1298. if ((approximateDaySpan > 14) && (approximateDaySpan / entryArray.length < 16)) {
  1299. var DAY_HEADER_ATTRIBS = protect('colspan="2" width="14%" style="padding-top:5px;text-align:center;font-style:italic"');
  1300. var DATE_ATTRIBS = protect('width="1%" height="30px" style="text-align:right;border:1px solid #EEE;border-right:none;"');
  1301. var FADED_ATTRIBS = protect('width="1%" height="30px" style="color:#BBB;text-align:right;"');
  1302. var ENTRY_ATTRIBS = protect('width="14%" style="border:1px solid #EEE;border-left:none;"');
  1303. var PARENTHESIZED_ATTRIBS = protect('class="parenthesized"');
  1304. // Find the first day of the first month
  1305. var date = entryArray[0].date;
  1306. var index = 0;
  1307. var hideWeekends = ! anyWeekendEvents && option('hideEmptyWeekends');
  1308. var showDate = hideWeekends ? function(date) { return (date.getUTCDay() > 0) && (date.getUTCDay() < 6);} : function() { return true; };
  1309. var sameDay = function (d1, d2) {
  1310. // Account for daylight savings time
  1311. return (abs(d1.getTime() - d2.getTime()) < MILLISECONDS_PER_DAY / 2);
  1312. }
  1313. // Go to the first of the month
  1314. date = new Date(date.getUTCFullYear(), date.getUTCMonth(), 1, standardHour);
  1315. while (date.getTime() < entryArray[entryArray.length - 1].date.getTime()) {
  1316. // Create the calendar header
  1317. calendar += '<table ' + protect('class="calendar"') + '>\n' +
  1318. entag('tr', entag('th', MONTH_FULL_NAME[date.getUTCMonth()] + ' ' + date.getUTCFullYear(), protect('colspan="14"'))) + '<tr>';
  1319. (hideWeekends ? DAY_NAME.slice(1, 6) : DAY_NAME).forEach(function (name) {
  1320. calendar += entag('td', name, DAY_HEADER_ATTRIBS);
  1321. });
  1322. calendar += '</tr>';
  1323. // Go back into the previous month to reach a Sunday. Check the time at noon
  1324. // to avoid problems with daylight saving time occuring early in the morning
  1325. while (date.getUTCDay() !== 0) {
  1326. date = new Date(date.getTime() - MILLISECONDS_PER_DAY);
  1327. }
  1328. // Insert the days from the previous month
  1329. if (date.getDate() !== 1) {
  1330. calendar += '<tr ' + rowAttribs + '>';
  1331. while (date.getDate() !== 1) {
  1332. if (showDate(date)) { calendar += '<td ' + FADED_ATTRIBS + '>' + date.getUTCDate() + '</td><td>&nbsp;</td>'; }
  1333. date = new Date(date.getTime() + MILLISECONDS_PER_DAY);
  1334. }
  1335. }
  1336. // Run until the end of the month
  1337. do {
  1338. if (date.getUTCDay() === 0) {
  1339. // Sunday, start a row
  1340. calendar += '<tr ' + rowAttribs + '>';
  1341. }
  1342. if (showDate(date)) {
  1343. var attribs = '';
  1344. if (sameDay(date, today)) {
  1345. attribs = protect('class="today"');
  1346. }
  1347. // Insert links as needed from entries
  1348. var contents = '';
  1349. for (var entry = entryArray[index]; entry && sameDay(entry.date, date); ++index, entry = entryArray[index]) {
  1350. if (contents) { contents += '<br/>'; }
  1351. if (entry.parenthesized) {
  1352. // Parenthesized with no body, no need for a link
  1353. contents += entag('span', entry.title, PARENTHESIZED_ATTRIBS);
  1354. } else {
  1355. contents += entag('a', entry.title, protect('href="#schedule' + scheduleNumber + '_' + date.getUTCFullYear() + '-' + (date.getUTCMonth() + 1) + '-' + date.getUTCDate() + '"'));
  1356. }
  1357. }
  1358. if (contents) {
  1359. calendar += entag('td', entag('b', date.getUTCDate()), DATE_ATTRIBS + attribs) + entag('td', contents, ENTRY_ATTRIBS + attribs);
  1360. } else {
  1361. calendar += '<td ' + DATE_ATTRIBS + attribs + '></a>' + date.getUTCDate() + '</td><td ' + ENTRY_ATTRIBS + attribs + '> &nbsp; </td>';
  1362. }
  1363. }
  1364. if (date.getUTCDay() === 6) {
  1365. // Saturday, end a row
  1366. calendar += '</tr>';
  1367. }
  1368. // Go to (approximately) the next day
  1369. date = new Date(date.getTime() + MILLISECONDS_PER_DAY);
  1370. } while (date.getUTCDate() > 1);
  1371. // Finish out the week after the end of the month
  1372. if (date.getUTCDay() !== 0) {
  1373. while (date.getUTCDay() !== 0) {
  1374. if (showDate(date)) { calendar += '<td ' + FADED_ATTRIBS + '>' + date.getUTCDate() + '</td><td>&nbsp</td>'; }
  1375. date = new Date(date.getTime() + MILLISECONDS_PER_DAY);
  1376. }
  1377. calendar += '</tr>';
  1378. }
  1379. calendar += '</table><br/>\n';
  1380. // Go to the first of the (new) month
  1381. date = new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), 1, standardHour));
  1382. } // Until all days covered
  1383. } // if add calendar
  1384. // Construct the schedule
  1385. schedule = '';
  1386. sourceEntryArray.forEach(function (entry) {
  1387. schedule += entry.text;
  1388. });
  1389. return calendar + entag('table', schedule, protect('class="schedule"')) + '\n\n';
  1390. });
  1391. } catch (ignore) {
  1392. // Maybe this wasn't a schedule after all, since we couldn't parse a date
  1393. console.log(ignore + ' in a Markdeep schedule list');
  1394. }
  1395. return str;
  1396. }
  1397. /**
  1398. Term
  1399. : description, which might be multiple
  1400. lines and include blanks.
  1401. Next Term
  1402. becomes
  1403. <dl>
  1404. <dt>Term</dt>
  1405. <dd> description, which might be multiple
  1406. lines and include blanks.</dd>
  1407. <dt>Next Term</dt>
  1408. </dl>
  1409. ... unless it is very short, in which case it becomes a table.
  1410. */
  1411. function replaceDefinitionLists(s, protect) {
  1412. var TERM = /^.+\n:(?=[ \t])/.source;
  1413. // Definition can contain multiple paragraphs
  1414. var DEFINITION = '(\s*\n|[: \t].+\n)+';
  1415. s = s.rp(new RegExp('(' + TERM + DEFINITION + ')+', 'gm'),
  1416. function (block) {
  1417. var list = [];
  1418. // Parse the block
  1419. var currentEntry = null;
  1420. block.split('\n').forEach(function (line, i) {
  1421. // What kind of line is this?
  1422. if (line.trim().length === 0) {
  1423. if (currentEntry) {
  1424. // Empty line
  1425. currentEntry.definition += '\n';
  1426. }
  1427. } else if (! /\s/.test(line[0]) && (line[0] !== ':')) {
  1428. currentEntry = {term: line, definition: ''};
  1429. list.push(currentEntry);
  1430. } else {
  1431. // Add the line to the current definition, stripping any single leading ':'
  1432. if (line[0] === ':') { line = ' ' + line.ss(1); }
  1433. currentEntry.definition += line + '\n';
  1434. }
  1435. });
  1436. var longestDefinition = 0;
  1437. list.forEach(function (entry) {
  1438. if (/\n\s*\n/.test(entry.definition.trim())) {
  1439. // This definition contains multiple paragraphs. Force it into long mode
  1440. longestDefinition = Infinity;
  1441. } else {
  1442. // Normal case
  1443. longestDefinition = max(longestDefinition, unescapeHTMLEntities(removeHTMLTags(entry.definition)).length);
  1444. }
  1445. });
  1446. var result = '';
  1447. if (longestDefinition < 160) {
  1448. var rowAttribs = protect('valign=top');
  1449. // This list has short definitions. Format it as a table
  1450. list.forEach(function (entry) {
  1451. result += entag('tr',
  1452. entag('td', entag('dt', entry.term)) +
  1453. entag('td', entag('dd', entag('p', entry.definition))),
  1454. rowAttribs);
  1455. });
  1456. result = entag('table', result);
  1457. } else {
  1458. list.forEach(function (entry) {
  1459. // Leave *two* blanks at the start of a
  1460. // definition so that subsequent processing
  1461. // can detect block formatting within it.
  1462. result += entag('dt', entry.term) + entag('dd', entag('p', entry.definition));
  1463. });
  1464. }
  1465. return entag('dl', result);
  1466. });
  1467. return s;
  1468. }
  1469. /** Inserts a table of contents in the document and then returns
  1470. [string, table], where the table maps strings to levels. */
  1471. function insertTableOfContents(s, protect) {
  1472. // Gather headers for table of contents (TOC). We
  1473. // accumulate a long and short TOC and then choose which
  1474. // to insert at the end.
  1475. var fullTOC = '';
  1476. var shortTOC = '';
  1477. // headerCounter[i] is the current counter for header level (i - 1)
  1478. var headerCounter = [0];
  1479. var currentLevel = 0;
  1480. var numAboveLevel1 = 0;
  1481. var table = {};
  1482. s = s.rp(/<h([1-6])>(.*?)<\/h\1>/gi, function (header, level, text) {
  1483. level = parseInt(level)
  1484. text = text.trim();
  1485. // If becoming more nested:
  1486. for (var i = currentLevel; i < level; ++i) { headerCounter[i] = 0; }
  1487. // If becoming less nested:
  1488. headerCounter.splice(level, currentLevel - level);
  1489. currentLevel = level;
  1490. ++headerCounter[currentLevel - 1];
  1491. // Generate a unique name for this element
  1492. var number = headerCounter.join('.');
  1493. var name = 'toc' + number;
  1494. table[removeHTMLTags(text).trim().toLowerCase()] = number;
  1495. // Only insert for the first three levels
  1496. if (level <= 3) {
  1497. // Indent and append (the Array() call generates spaces)
  1498. fullTOC += Array(level).join('&nbsp;&nbsp;') + '<a href="#' + name + '" class="level' + level + '"><span class="tocNumber">' + number + '&nbsp; </span>' + text + '</a><br/>\n';
  1499. if (level === 1) {
  1500. shortTOC += ' &middot; <a href="#' + name + '">' + text + '</a>';
  1501. } else {
  1502. ++numAboveLevel1;
  1503. }
  1504. }
  1505. return entag('a', '&nbsp;', protect('class="target" name="' + name + '"')) + header;
  1506. });
  1507. if (shortTOC.length > 0) {
  1508. // Strip the leading " &middot; "
  1509. shortTOC = shortTOC.ss(10);
  1510. }
  1511. var numLevel1 = headerCounter[0];
  1512. var numHeaders = numLevel1 + numAboveLevel1;
  1513. // The location of the first header is indicative of the length of
  1514. // the abstract...as well as where we insert. The first header may be accompanied by
  1515. // <a name> tags, which we want to appear before.
  1516. var firstHeaderLocation = s.regexIndexOf(/((<a\s+\S+>&nbsp;<\/a>)\s*)*?<h\d>/i);
  1517. if (firstHeaderLocation === -1) { firstHeaderLocation = 0; }
  1518. var AFTER_TITLES = '<div class="afterTitles"><\/div>';
  1519. var insertLocation = s.indexOf(AFTER_TITLES);
  1520. if (insertLocation === -1) {
  1521. insertLocation = 0;
  1522. } else {
  1523. insertLocation += AFTER_TITLES.length;
  1524. }
  1525. // Which TOC style should we use?
  1526. var tocStyle = option('tocStyle');
  1527. var TOC = '';
  1528. if ((tocStyle === 'auto') || (tocStyle === '')) {
  1529. if (((numHeaders < 4) && (numLevel1 <= 1)) || (s.length < 2048)) {
  1530. // No TOC; this document is really short
  1531. tocStyle = 'none';
  1532. } else if ((numLevel1 < 7) && (numHeaders / numLevel1 < 2.5)) {
  1533. // We can use the short TOC
  1534. tocStyle = 'short';
  1535. } else if ((firstHeaderLocation === -1) || (firstHeaderLocation / 55 > numHeaders)) {
  1536. // The abstract is long enough to float alongside, and there
  1537. // are not too many levels.
  1538. // Insert the medium-length TOC floating
  1539. tocStyle = 'medium';
  1540. } else {
  1541. // This is a long table of contents or a short abstract
  1542. // Insert a long toc...right before the first header
  1543. tocStyle = 'long';
  1544. }
  1545. }
  1546. switch (tocStyle) {
  1547. case 'none':
  1548. case '':
  1549. break;
  1550. case 'short':
  1551. TOC = '<div class="shortTOC">' + shortTOC + '</div>';
  1552. break;
  1553. case 'medium':
  1554. TOC = '<div class="mediumTOC"><center><b>' + keyword('Contents') + '</b></center><p>' + fullTOC + '</p></div>';
  1555. break;
  1556. case 'long':
  1557. insertLocation = firstHeaderLocation;
  1558. TOC = '<div class="longTOC"><div class="tocHeader">' + keyword('Contents') + '</div><p>' + fullTOC + '</p></div>';
  1559. break;
  1560. default:
  1561. console.log('markdeepOptions.tocStyle = "' + tocStyle + '" specified in your document is not a legal value');
  1562. }
  1563. s = s.ss(0, insertLocation) + TOC + s.ss(insertLocation);
  1564. return [s, table];
  1565. }
  1566. function escapeRegExpCharacters(str) {
  1567. return str.rp(/([\.\[\]\(\)\*\+\?\^\$\\\{\}\|])/g, '\\$1');
  1568. }
  1569. /** Returns true if there are at least two newlines in each of the arguments */
  1570. function isolated(preSpaces, postSpaces) {
  1571. if (preSpaces && postSpaces) {
  1572. preSpaces = preSpaces.match(/\n/g);
  1573. postSpaces = postSpaces.match(/\n/g);
  1574. return preSpaces && (preSpaces.length > 1) && postSpaces && (postSpaces.length > 1);
  1575. } else {
  1576. return false;
  1577. }
  1578. }
  1579. /**
  1580. Performs Markdeep processing on str, which must be a string or a
  1581. DOM element. Returns a string that is the HTML to display for the
  1582. body. The result does not include the header: Markdeep stylesheet
  1583. and script tags for including a math library, or the Markdeep
  1584. signature footer.
  1585. Optional argument elementMode defaults to true. This avoids turning a bold first word into a
  1586. title or introducing a table of contents. Section captions are unaffected by this argument.
  1587. Set elementMode = false if processing a whole document instead of an internal node.
  1588. */
  1589. function markdeepToHTML(str, elementMode) {
  1590. // Map names to the number used for end notes, in the order
  1591. // encountered in the text.
  1592. var endNoteTable = {}, endNoteCount = 0;
  1593. // Reference links
  1594. var referenceLinkTable = {};
  1595. // In the private use area
  1596. var PROTECT_CHARACTER = '\ue010';
  1597. // Use base 36 for encoding numbers
  1598. var PROTECT_RADIX = 35;
  1599. var protectedStringArray = [];
  1600. // Gives 1.5M possible sequences in base 56
  1601. var PROTECT_DIGITS = 4;
  1602. // Put the protect character at BOTH ends to avoid having the protected number encoding
  1603. // look like an actual number to further markdown processing
  1604. var PROTECT_REGEXP = RegExp(PROTECT_CHARACTER + '[0-9a-wyz]{' + PROTECT_DIGITS + ',' + PROTECT_DIGITS + '}' + PROTECT_CHARACTER, 'g');
  1605. /** Given an arbitrary string, returns an escaped identifier
  1606. string to temporarily replace it with to prevent Markdeep from
  1607. processing the contents. See expose() */
  1608. function protect(s) {
  1609. var i = (protectedStringArray.push(s) - 1).toString(PROTECT_RADIX);
  1610. // Avoid the pattern "#x#", which Markdeep would interpret as a dimension eligible for
  1611. // beautification.
  1612. i = i.rp(/x/gi, 'z');
  1613. // Ensure fixed length
  1614. while (i.length < PROTECT_DIGITS) {
  1615. i = '0' + i;
  1616. }
  1617. return PROTECT_CHARACTER + i + PROTECT_CHARACTER;
  1618. }
  1619. /** Given the escaped identifier string from protect(), returns
  1620. the orginal string. */
  1621. function expose(i) {
  1622. // Strip the escape character and parse, then look up in the
  1623. // dictionary.
  1624. var j = parseInt(i.ss(1, i.length - 1).rp(/z/g, 'x'), PROTECT_RADIX);
  1625. return protectedStringArray[j];
  1626. }
  1627. /** First-class function to pass to String.replace to protect a
  1628. sequence defined by a regular expression. */
  1629. function protector(match, protectee) {
  1630. return protect(protectee);
  1631. }
  1632. function protectorWithPrefix(match, prefix, protectee) {
  1633. return prefix + protect(protectee);
  1634. }
  1635. // SECTION HEADERS
  1636. // This is common code for numbered headers. Nno-number ATX headers are processed
  1637. // separately
  1638. function makeHeaderFunc(level) {
  1639. return function (match, header) {
  1640. return '\n\n</p>\n<a ' + protect('class="target" name="' + mangle(removeHTMLTags(header)) + '"') +
  1641. '>&nbsp;</a>' + entag('h' + level, header) + '\n<p>\n\n';
  1642. }
  1643. }
  1644. if (elementMode === undefined) {
  1645. elementMode = true;
  1646. }
  1647. if (str.innerHTML !== undefined) {
  1648. str = str.innerHTML;
  1649. }
  1650. // Prefix a newline so that blocks beginning at the top of the
  1651. // document are processed correctly
  1652. str = '\n\n' + str;
  1653. // Replace pre-formatted script tags that are used to protect
  1654. // less-than signs, e.g., in std::vector<Value>
  1655. str = str.rp(/<script\s+type\s*=\s*['"]preformatted['"]\s*>([\s\S]*?)<\/script>/gi, '$1');
  1656. function replaceDiagrams(str) {
  1657. var result = extractDiagram(str);
  1658. if (result.diagramString) {
  1659. var CAPTION_REGEXP = /^\n*[ \t]*\[[^\n]+\][ \t]*(?=\n)/;
  1660. result.afterString = result.afterString.rp(CAPTION_REGEXP, function (caption) {
  1661. // Strip whitespace and enclosing brackets from the caption
  1662. caption = caption.trim();
  1663. caption = caption.ss(1, caption.length - 1);
  1664. result.caption = entag('center', entag('div', caption, protect('class="imagecaption"')));
  1665. return '';
  1666. });
  1667. var diagramSVG = diagramToSVG(result.diagramString, result.alignmentHint);
  1668. var captionAbove = option('captionAbove', 'diagram')
  1669. return result.beforeString +
  1670. (result.caption && captionAbove ? result.caption : '') +
  1671. diagramSVG +
  1672. (result.caption && ! captionAbove ? result.caption : '') + '\n' +
  1673. replaceDiagrams(result.afterString);
  1674. } else {
  1675. return str;
  1676. }
  1677. }
  1678. // CODE FENCES, with styles. Do this before other
  1679. // processing so that their code is protected from further
  1680. // Markdown processing
  1681. var stylizeFence = function (cssClass, symbol) {
  1682. var pattern = new RegExp('\\n([ \\t]*)' + symbol + '{3,}([ \\t]*\\S*)([ \\t]+.+)?\n([\\s\\S]+?)\n\\1' + symbol + '{3,}\\s*\n([ \t]*\\[.+(?:\n.+){0,3}\\])?', 'g');
  1683. str = str.rp(pattern, function(match, indent, lang, cssSubClass, sourceCode, caption) {
  1684. if (caption) {
  1685. caption = caption.trim();
  1686. caption = '<div ' + protect('class="listingcaption ' + cssClass + '"') + '>' + caption.ss(1, caption.length - 1) + '</div>\n';
  1687. }
  1688. lang = lang ? lang.trim() : lang;
  1689. lang = lang ? [lang] : undefined;
  1690. // Remove the block's own indentation from each line of sourceCode
  1691. sourceCode = sourceCode.rp(new RegExp('(^|\n)' + indent, 'g'), '$1');
  1692. var captionAbove = option('captionAbove', 'listing')
  1693. var nextSourceCode, nextLang, nextCssSubClass;
  1694. var body = '';
  1695. do {
  1696. nextSourceCode = nextLang = nextCssSubClass = undefined;
  1697. sourceCode = sourceCode.rp(new RegExp('\\n([ \\t]*)' + symbol + '{3,}([ \\t]*\\S+)([ \\t]+.+)?\n([\\s\\S]*)'),
  1698. function (match, indent, lang, cssSubClass, everythingElse) {
  1699. nextLang = [lang];
  1700. nextCssSubClass = cssSubClass;
  1701. nextSourceCode = everythingElse;
  1702. return '';
  1703. });
  1704. // Highlight and append this block
  1705. var highlighted = hljs.highlightAuto(sourceCode, lang).value;
  1706. if (cssSubClass) {
  1707. highlighted = entag('div', highlighted, 'class="' + cssSubClass + '"');
  1708. }
  1709. body += highlighted;
  1710. // Advance the next nested block
  1711. sourceCode = nextSourceCode;
  1712. lang = nextLang;
  1713. cssSubClass = nextCssSubClass;
  1714. } while (sourceCode);
  1715. // Insert paragraph close/open tags, since browsers force them anyway around pre tags
  1716. // We need the indent in case this is a code block inside a list that is indented.
  1717. return '\n' + indent + '</p>' + (caption && captionAbove ? caption : '') +
  1718. protect(entag('pre', entag('code', body), 'class="listing ' + cssClass + '"')) +
  1719. (caption && ! captionAbove ? caption : '') + '<p>\n';
  1720. });
  1721. };
  1722. stylizeFence('tilde', '~');
  1723. stylizeFence('backtick', '`');
  1724. // Protect raw <CODE> content
  1725. str = str.rp(/(<code\b.*?<\/code>)/gi, protector);
  1726. // Remove XML/HTML COMMENTS
  1727. str = str.rp(/<!--\s[\s\S]+?\s-->/g, '');
  1728. str = replaceDiagrams(str);
  1729. // Protect SVG blocks (including the ones we just inserted)
  1730. str = str.rp(/<svg( .*?)?>([\s\S]*?)<\/svg>/gi, function (match, attribs, body) {
  1731. return '<svg' + protect(attribs) + '>' + protect(body) + '</svg>';
  1732. });
  1733. // Protect STYLE blocks
  1734. str = str.rp(/<style>([\s\S]*?)<\/style>/gi, function (match, body) {
  1735. return entag('style', protect(body));
  1736. });
  1737. // Protect the very special case of img tags with newlines and
  1738. // breaks in them AND mismatched angle brackets. This happens for
  1739. // gravizo graphs.
  1740. str = str.rp(/<img\s+src=(["'])[\s\S]*?\1\s*>/gi, function (match, quote) {
  1741. // Strip the "<img " and ">", and then protect:
  1742. return "<img " + protect(match.ss(5, match.length - 1)) + ">";
  1743. });
  1744. // INLINE CODE: Surrounded in back ticks on a single line. Do this before any other
  1745. // processing to protect code blocks from further interference. Don't process back ticks
  1746. // inside of code fences. Allow a single newline, but not wrapping further because that
  1747. // might just pick up quotes used as other punctuation across lines. Explicitly exclude
  1748. // cases where the second quote immediately preceeds a number, e.g., "the old `97"
  1749. str = str.rp(/(`)(.+?(?:\n.+?)?)`(?!\d)/g, entag('code', '$2'));
  1750. // CODE: Escape angle brackets inside code blocks (including the ones we just introduced),
  1751. // and then protect the blocks themselves
  1752. str = str.rp(/(<code(?: .*?)?>)([\s\S]*?)<\/code>/gi, function (match, open, inlineCode) {
  1753. return protect(open + escapeHTMLEntities(inlineCode) + '</code>');
  1754. });
  1755. // PRE: Protect pre blocks
  1756. str = str.rp(/(<pre\b[\s\S]*?<\/pre>)/gi, protector);
  1757. // Protect raw HTML attributes from processing
  1758. str = str.rp(/(<\w[^ \n<>]*?[ \t]+)(.*?)(?=\/?>)/g, protectorWithPrefix);
  1759. // End of processing literal blocks
  1760. /////////////////////////////////////////////////////////////////////////////
  1761. // Temporarily hide $$ MathJax LaTeX blocks from Markdown processing (this must
  1762. // come before single $ block detection below)
  1763. str = str.rp(/(\$\$[\s\S]+?\$\$)/g, protector);
  1764. // Convert LaTeX $ ... $ to MathJax, but verify that this
  1765. // actually looks like math and not just dollar
  1766. // signs. Don't rp double-dollar signs. Do this only
  1767. // outside of protected blocks.
  1768. // Also allow LaTeX of the form $...$ if the close tag is not US$ or Can$
  1769. // and there are spaces outside of the dollar signs.
  1770. //
  1771. // Test: " $3 or US$2 and 3$, $x$ $y + \n 2x$ or ($z$) $k$. or $2 or $2".match(pattern) =
  1772. // ["$x$", "$y + 2x$", "$z$", "$k$"];
  1773. str = str.rp(/((?:[^\w\d]))\$(\S(?:[^\$]*?\S(?!US|Can))??)\$(?![\w\d])/g, '$1\\($2\\)');
  1774. //
  1775. // Literally: find a non-dollar sign, non-number followed
  1776. // by a dollar sign and a space. Then, find any number of
  1777. // characters until the same pattern reversed, allowing
  1778. // one punctuation character before the final space. We're
  1779. // trying to exclude things like Canadian 1$ and US $1
  1780. // triggering math mode.
  1781. str = str.rp(/((?:[^\w\d]))\$([ \t][^\$]+?[ \t])\$(?![\w\d])/g, '$1\\($2\\)');
  1782. // Temporarily hide MathJax LaTeX blocks from Markdown processing
  1783. str = str.rp(/(\\\([\s\S]+?\\\))/g, protector);
  1784. str = str.rp(/(\\begin\{equation\}[\s\S]*?\\end\{equation\})/g, protector);
  1785. str = str.rp(/(\\begin\{eqnarray\}[\s\S]*?\\end\{eqnarray\})/g, protector);
  1786. str = str.rp(/(\\begin\{equation\*\}[\s\S]*?\\end\{equation\*\})/g, protector);
  1787. // For headers, we consume leading and trailing whitespace to avoid creating an
  1788. // extra paragraph tag around the header itself.
  1789. // Setext-style H1: Text with ======== right under it
  1790. str = str.rp(/(?:^|\s*\n)(.+?)\n[ \t]*={3,}[ \t]*\n/g, makeHeaderFunc(1));
  1791. // Setext-style H2: Text with -------- right under it
  1792. str = str.rp(/(?:^|\s*\n)(.+?)\n[ \t]*-{3,}[ \t]*\n/g, makeHeaderFunc(2));
  1793. // ATX-style headers:
  1794. for (var i = 6; i > 0; --i) {
  1795. str = str.rp(new RegExp(/^\s*/.source + '#{' + i + ',' + i +'}(?:[ \t])([^\n#]+)#*[ \t]*\n', 'gm'),
  1796. makeHeaderFunc(i));
  1797. // No-number headers
  1798. str = str.rp(new RegExp(/^\s*/.source + '\\(#{' + i + ',' + i +'}\\)(?:[ \t])([^\n#]+)\\(?#*\\)?\\n[ \t]*\n', 'gm'),
  1799. '\n</p>\n' + entag('div', '$1', protect('class="nonumberh' + i + '"')) + '\n<p>\n\n');
  1800. }
  1801. // HORIZONTAL RULE: * * *, - - -, _ _ _
  1802. str = str.rp(/\n[ \t]*((\*|-|_)[ \t]*){3,}[ \t]*\n/g, '\n<hr/>\n');
  1803. // PAGE BREAK or HORIZONTAL RULE: +++++
  1804. str = str.rp(/\n[ \t]*\+{5,}[ \t]*\n/g, '\n<hr ' + protect('class="pagebreak"') + '/>\n');
  1805. // ADMONITION: !!! (class) (title)\n body
  1806. str = str.rp(/^!!![ \t]*([^\s"'><&\:]*)\:?(.*)\n([ \t]{3,}.*\s*\n)*/gm, function (match, cssClass, title) {
  1807. // Have to extract the body by splitting match because the regex doesn't capture the body correctly in the multi-line case
  1808. match = match.trim();
  1809. return '\n\n' + entag('div', ((title ? entag('div', title, protect('class="admonition-title"')) + '\n' : '') + match.ss(match.indexOf('\n'))).trim(), protect('class="admonition ' + cssClass.toLowerCase().trim() + '"')) + '\n\n';
  1810. });
  1811. // FANCY QUOTE in a blockquote:
  1812. // > " .... "
  1813. // > -- Foo
  1814. var FANCY_QUOTE = protect('class="fancyquote"');
  1815. str = str.rp(/\n>[ \t]*"(.*(?:\n>.*)*)"[ \t]*(?:\n>[ \t]*)?(\n>[ \t]{2,}\S.*)?\n/g,
  1816. function (match, quote, author) {
  1817. return entag('blockquote',
  1818. entag('span',
  1819. quote.rp(/\n>/g, '\n'),
  1820. FANCY_QUOTE) +
  1821. (author ? entag('span',
  1822. author.rp(/\n>/g, '\n'),
  1823. protect('class="author"')) : ''),
  1824. FANCY_QUOTE);
  1825. });
  1826. // BLOCKQUOTE: > in front of a series of lines
  1827. // Process iteratively to support nested blockquotes
  1828. var foundBlockquote = false;
  1829. do {
  1830. foundBlockquote = false;
  1831. str = str.rp(/(?:\n>.*){2,}/g, function (match) {
  1832. // Strip the leading '>'
  1833. foundBlockquote = true;
  1834. return entag('blockquote', match.rp(/\n>/g, '\n'));
  1835. });
  1836. } while (foundBlockquote);
  1837. // FOOTNOTES/ENDNOTES: [^symbolic name]. Disallow spaces in footnote names to
  1838. // make parsing unambiguous
  1839. str = str.rp(/\s*\[\^(\S+)\](?!:)/g, function (match, symbolicName) {
  1840. symbolicName = symbolicName.toLowerCase().trim();
  1841. if (! (symbolicName in endNoteTable)) {
  1842. ++endNoteCount;
  1843. endNoteTable[symbolicName] = endNoteCount;
  1844. }
  1845. return '<sup><a ' + protect('href="#endnote-' + symbolicName + '"') +
  1846. '>' + endNoteTable[symbolicName] + '</a></sup>';
  1847. });
  1848. // CITATIONS: [#symbolicname]
  1849. // The reference: (don't use \S+ because it can grab trailing punctuation)
  1850. str = str.rp(/\[#([^\)\(\[\]\.#\s]+)\](?!:)/g, function (match, symbolicName) {
  1851. symbolicName = symbolicName.trim();
  1852. return '[<a ' + protect('href="#citation-' + symbolicName.toLowerCase() + '"') +
  1853. '>' + symbolicName + '</a>]';
  1854. });
  1855. // The bibliography entry:
  1856. str = str.rp(/\n\[#(\S+)\]:[ \t]+((?:[ \t]*\S[^\n]*\n?)*)/g, function (match, symbolicName, entry) {
  1857. symbolicName = symbolicName.trim();
  1858. return '<div ' + protect('class="bib"') + '>[<a ' + protect('class="target" name="citation-' + symbolicName.toLowerCase() + '"') +
  1859. '>&nbsp;</a><b>' + symbolicName + '</b>] ' + entry + '</div>';
  1860. });
  1861. // TABLES: line with | over line containing only | and -
  1862. // (process before reference links to avoid ambiguity on the captions)
  1863. str = replaceTables(str, protect);
  1864. // REFERENCE-LINKS: [foo][] or [bar][foo] + [foo]: http://foo.com
  1865. str = str.rp(/^\[([^\^#].*?)\]:(.*?)$/gm, function (match, symbolicName, url) {
  1866. referenceLinkTable[symbolicName.toLowerCase().trim()] = {link: url.trim(), used: false};
  1867. return '';
  1868. });
  1869. // E-MAIL ADDRESS: <[email protected]> or [email protected]
  1870. str = str.rp(/(?:<|(?!<)\b)(\S+@(\S+\.)+?\S{3,}?)(?:$|>|(?=<)|(?=\s)(?!>))/g, function (match, addr) {
  1871. return '<a ' + protect('href="mailto:' + addr + '"') + '>' + addr + '</a>';
  1872. });
  1873. // Common code for formatting images
  1874. var formatImage = function (ignore, url, attribs) {
  1875. attribs = attribs || '';
  1876. var img;
  1877. var hash;
  1878. // Detect videos
  1879. if (/(.mp4|.m4v|.avi|.mpg|.mov)$/i.test(url)) {
  1880. // This is video. Any attributes provided will override the defaults given here
  1881. img = '<video ' + protect('class="markdeep" src="' + url + '"' + attribs + ' width="480px" controls="true"') + '/>';
  1882. } else if (hash = url.match(/^https:\/\/(?:www\.)?(?:youtube\.com\/\S*?v=|youtu\.be\/)([\w\d-]+)(&.*)?$/i)) {
  1883. // Youtube video
  1884. img = '<iframe ' + protect('class="markdeep" src="https://www.youtube.com/embed/' + hash[1] + '"' + attribs + ' width="480px" height="300px" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen') + '></iframe>';
  1885. } else if (hash = url.match(/^https:\/\/(?:www\.)?vimeo.com\/\S*?\/([\w\d-]+)$/i)) {
  1886. // Vimeo video
  1887. img = '<iframe ' + protect('class="markdeep" src="https://player.vimeo.com/video/' + hash[1] + '"' + attribs + ' width="480px" height="300px" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen') + '></iframe>';
  1888. } else {
  1889. // Image (trailing space is needed in case attribs must be quoted by the
  1890. // browser...without the space, the browser will put the closing slash in the
  1891. // quotes.)
  1892. img = '<img ' + protect('class="markdeep" src="' + url + '"' + attribs) + ' />';
  1893. // Check for width or height (or max-width and max-height). If they exist,
  1894. // link this to the full-size image as well. The current code ALWAYS makes
  1895. // this link.
  1896. //if (/\b(width|height)\b/i.test(attribs)) {
  1897. img = entag('a ', img, protect('href="' + url + '" target="_blank"'));
  1898. //}
  1899. }
  1900. return img;
  1901. };
  1902. // Reformat figure links that have subfigure labels in parentheses, to avoid them being
  1903. // processed as links
  1904. str = str.rp(/\b(figure|fig\.|table|tbl\.|listing|lst\.)\s*\[([^\s\]]+)\](?=\()/gi, function (match) {
  1905. return match + '<span/>';
  1906. });
  1907. // Process links before images so that captions can contain links
  1908. // Detect gravizo URLs inside of markdown images and protect them,
  1909. // which will cause them to be parsed sort-of reasonably. This is
  1910. // a really special case needed to handle the newlines and potential
  1911. // nested parentheses. Use the pattern from http://blog.stevenlevithan.com/archives/regex-recursion
  1912. // (could be extended to multiple nested parens if needed)
  1913. str = str.rp(/\(http:\/\/g.gravizo.com\/g\?((?:[^\(\)]|\([^\(\)]*\))*)\)/gi, function(match, url) {
  1914. return "(http://g.gravizo.com/g?" + encodeURIComponent(url) + ")";
  1915. });
  1916. // HYPERLINKS: [text](url attribs)
  1917. str = str.rp(/(^|[^!])\[([^\[\]]+?)\]\(("?)([^<>\s"]+?)\3(\s+[^\)]*?)?\)/g, function (match, pre, text, maybeQuote, url, attribs) {
  1918. attribs = attribs || '';
  1919. return pre + '<a ' + protect('href="' + url + '"' + attribs) + '>' + text + '</a>' + maybeShowLabel(url);
  1920. });
  1921. // EMPTY HYPERLINKS: [](url)
  1922. str = str.rp(/(^|[^!])\[[ \t]*?\]\(("?)([^<>\s"]+?)\2\)/g, function (match, pre, maybeQuote, url) {
  1923. return pre + '<a ' + protect('href="' + url + '"') + '>' + url + '</a>';
  1924. });
  1925. // IMAGE GRID: Rewrite rows and grids of images into a grid
  1926. var imageGridAttribs = protect('width="100%"');
  1927. var imageGridRowAttribs = protect('valign="top"');
  1928. str = str.rp(/(?:\n(?:[ \t]*!\[[^\n]*?\]\(("?)[^<>\s]+?(?:[^\n\)]*?)?\)){2,}[ \t]*)+\n/g, function (match) {
  1929. var table = '';
  1930. // Break into rows:
  1931. match = match.split('\n');
  1932. // Parse each row:
  1933. match.forEach(function(row) {
  1934. row = row.trim();
  1935. if (row) {
  1936. // Parse each image
  1937. table += entag('tr', row.rp(/[ \t]*!\[[^\n]*?\]\([^\)\s]+([^\)]*?)?\)/g, function(image, attribs) {
  1938. //if (! /width|height/i.test(attribs) {
  1939. // Add a bogus "width" attribute to force the images to be hyperlinked to their
  1940. // full-resolution versions
  1941. //}
  1942. return entag('td', '\n\n'+ image + '\n\n');
  1943. }), imageGridRowAttribs);
  1944. }
  1945. });
  1946. return '\n' + entag('table', table, imageGridAttribs) + '\n';
  1947. });
  1948. // SIMPLE IMAGE: ![](url attribs)
  1949. str = str.rp(/(\s*)!\[\]\(("?)([^"<>\s]+?)\2(\s[^\)]*?)?\)(\s*)/g, function (match, preSpaces, maybeQuote, url, attribs, postSpaces) {
  1950. var img = formatImage(match, url, attribs);
  1951. if (isolated(preSpaces, postSpaces)) {
  1952. // In a block by itself: center
  1953. img = entag('center', img);
  1954. }
  1955. return preSpaces + img + postSpaces;
  1956. });
  1957. // Explicit loop so that the output will be re-processed, preserving spaces between blocks.
  1958. // Note that there is intentionally no global flag on the first regexp since we only want
  1959. // to process the first occurance.
  1960. var loop = true;
  1961. var imageCaptionAbove = option('captionAbove', 'image');
  1962. while (loop) {
  1963. loop = false;
  1964. // CAPTIONED IMAGE: ![caption](url attribs)
  1965. str = str.rp(/(\s*)!\[([\s\S]+?)?\]\(("?)([^"<>\s]+?)\3(\s[^\)]*?)?\)(\s*)/, function (match, preSpaces, caption, maybeQuote, url, attribs, postSpaces) {
  1966. loop = true;
  1967. var divStyle = '';
  1968. var iso = isolated(preSpaces, postSpaces);
  1969. // Only floating images get their size attributes moved to the whole box
  1970. if (attribs && ! iso) {
  1971. // Move any width *attribute* specification to the box itself
  1972. attribs = attribs.rp(/((?:max-)?width)\s*:\s*[^;'"]*/g, function (attribMatch, attrib) {
  1973. divStyle = attribMatch + ';';
  1974. return attrib + ':100%';
  1975. });
  1976. // Move any width *style* specification to the box itself
  1977. attribs = attribs.rp(/((?:max-)?width)\s*=\s*('\S+?'|"\S+?")/g, function (attribMatch, attrib, expr) {
  1978. // Strip the quotes
  1979. divStyle = attrib + ':' + expr.ss(1, expr.length - 1) + ';';
  1980. return 'style="' + attrib + ':100%" ';
  1981. });
  1982. }
  1983. var img = formatImage(match, url, attribs);
  1984. if (iso) {
  1985. // In its own block: center
  1986. preSpaces += '<center>';
  1987. postSpaces = '</center>' + postSpaces;
  1988. } else {
  1989. // Embedded: float
  1990. divStyle += 'float:right;margin:4px 0px 0px 25px;'
  1991. }
  1992. caption = entag('div', caption + maybeShowLabel(url), protect('class="imagecaption"'));
  1993. return preSpaces +
  1994. entag('div', (imageCaptionAbove ? caption : '') + img + (! imageCaptionAbove ? caption : ''), protect('class="image" style="' + divStyle + '"')) +
  1995. postSpaces;
  1996. });
  1997. } // while replacements made
  1998. // Process these after links, so that URLs with underscores and tildes are protected.
  1999. // STRONG: Must run before italic, since they use the
  2000. // same symbols. **b** __b__
  2001. str = replaceMatched(str, /\*\*/, 'strong', protect('class="asterisk"'));
  2002. str = replaceMatched(str, /__/, 'strong', protect('class="underscore"'));
  2003. // EM (ITALICS): *i* _i_
  2004. str = replaceMatched(str, /\*/, 'em', protect('class="asterisk"'));
  2005. str = replaceMatched(str, /_/, 'em', protect('class="underscore"'));
  2006. // STRIKETHROUGH: ~~text~~
  2007. str = str.rp(/\~\~([^~].*?)\~\~/g, entag('del', '$1'));
  2008. // SMART DOUBLE QUOTES: "a -> &ldquo; z" -> &rdquo;
  2009. // Allow situations such as "foo"==>"bar" and foo:"bar", but not 3' 9"
  2010. str = str.rp(/(^|[ \t->])(")(?=\w)/gm, '$1&ldquo;');
  2011. str = str.rp(/([A-Za-z\.,:;\?!=<])(")(?=$|\W)/gm, '$1&rdquo;');
  2012. // ARROWS:
  2013. str = str.rp(/(\s|^)<==(\s)/g, '$1\u21D0$2');
  2014. str = str.rp(/(\s|^)->(\s)/g, '$1&rarr;$2');
  2015. // (this requires having removed HTML comments first)
  2016. str = str.rp(/(\s|^)-->(\s)/g, '$1&xrarr;$2');
  2017. str = str.rp(/(\s|^)==>(\s)/g, '$1\u21D2$2');
  2018. str = str.rp(/(\s|^)<-(\s)/g, '$1&larr;$2');
  2019. str = str.rp(/(\s|^)<--(\s)/g, '$1&xlarr;$2');
  2020. str = str.rp(/(\s|^)<==>(\s)/g, '$1\u21D4$2');
  2021. str = str.rp(/(\s|^)<->(\s)/g, '$1\u2194$2');
  2022. // EM DASH: ---
  2023. // (exclude things that look like table delimiters!)
  2024. str = str.rp(/([^-!\:\|])---([^->\:\|])/g, '$1&mdash;$2');
  2025. // other EM DASH: -- (we don't support en dash...it is too short and looks like a minus)
  2026. // (exclude things that look like table delimiters!)
  2027. str = str.rp(/([^-!\:\|])--([^->\:\|])/g, '$1&mdash;$2');
  2028. // NUMBER x NUMBER:
  2029. str = str.rp(/(\d+\s?)x(\s?\d+)/g, '$1&times;$2');
  2030. // MINUS: -4 or 2 - 1
  2031. str = str.rp(/([\s\(\[<\|])-(\d)/g, '$1&minus;$2');
  2032. str = str.rp(/(\d) - (\d)/g, '$1 &minus; $2');
  2033. // EXPONENTS: ^1 ^-1 (no decimal places allowed)
  2034. str = str.rp(/\^([-+]?\d+)\b/g, '<sup>$1</sup>');
  2035. // PAGE BREAK:
  2036. str = str.rp(/\b\\(pagebreak|newpage)\b/gi, protect('<div style="page-break-after:always"> </div>\n'))
  2037. // SCHEDULE LISTS: date : title followed by indented content
  2038. str = replaceScheduleLists(str, protect);
  2039. // DEFINITION LISTS: Word followed by a colon list
  2040. // Use <dl><dt>term</dt><dd>definition</dd></dl>
  2041. // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dl
  2042. //
  2043. // Process these before lists so that lists within definition lists
  2044. // work correctly
  2045. str = replaceDefinitionLists(str, protect);
  2046. // LISTS: lines with -, +, *, or number.
  2047. str = replaceLists(str, protect);
  2048. // DEGREE: ##-degree
  2049. str = str.rp(/(\d+?)[ \t-]degree(?:s?)/g, '$1&deg;');
  2050. // PARAGRAPH: Newline, any amount of space, newline...as long as there isn't already
  2051. // a paragraph break there.
  2052. str = str.rp(/(?:<p>)?\n\s*\n+(?!<\/p>)/gi,
  2053. function(match) { return (/^<p>/i.test(match)) ? match : '\n\n</p><p>\n\n';});
  2054. // Remove empty paragraphs (mostly avoided by the above, but some can still occur)
  2055. str = str.rp(/<p>[\s\n]*<\/p>/gi, '');
  2056. // Reference links
  2057. str = str.rp(/\[(.+?)\]\[(.*?)\]/g, function (match, text, symbolicName) {
  2058. // Empty symbolic name is replaced by the text
  2059. if (! symbolicName.trim()) {
  2060. symbolicName = text;
  2061. }
  2062. symbolicName = symbolicName.toLowerCase().trim();
  2063. var t = referenceLinkTable[symbolicName];
  2064. if (! t) {
  2065. console.log("Reference link '" + symbolicName + "' never defined");
  2066. return '?';
  2067. } else {
  2068. t.used = true;
  2069. return '<a ' + protect('href="' + t.link + '"') + '>' + text + '</a>';
  2070. }
  2071. });
  2072. // FOOTNOTES/ENDNOTES
  2073. str = str.rp(/\n\[\^(\S+)\]: ((?:.+?\n?)*)/g, function (match, symbolicName, note) {
  2074. symbolicName = symbolicName.toLowerCase().trim();
  2075. if (symbolicName in endNoteTable) {
  2076. return '\n<div ' + protect('class="endnote"') + '><a ' +
  2077. protect('class="target" name="endnote-' + symbolicName + '"') +
  2078. '>&nbsp;</a><sup>' + endNoteTable[symbolicName] + '</sup> ' + note + '</div>';
  2079. } else {
  2080. return "\n";
  2081. }
  2082. });
  2083. // SECTION LINKS: XXX section, XXX subsection.
  2084. // Do this by rediscovering the headers and then recursively
  2085. // searching for links to them. Process after other
  2086. // forms of links to avoid ambiguity.
  2087. var allHeaders = str.match(/<h([1-6])>(.*?)<\/h\1>/gi);
  2088. if (allHeaders) {
  2089. allHeaders.forEach(function (header) {
  2090. header = removeHTMLTags(header.ss(4, header.length - 5)).trim();
  2091. var link = '<a ' + protect('href="#' + mangle(header) + '"') + '>';
  2092. // Search for links to this section
  2093. str = str.rp(RegExp("(\\b" + escapeRegExpCharacters(header) + ")(?=\\s" + keyword('subsection') + "|\\s" +
  2094. keyword('section') + ")", 'gi'),
  2095. link + "$1</a>");
  2096. });
  2097. }
  2098. // TABLE, LISTING, and FIGURE LABEL NUMBERING: Figure [symbol]: Table [symbol]: Listing [symbol]: Diagram [symbols]:
  2099. // This data structure maps caption types [by localized name] to a count of how many of
  2100. // that type of object exist.
  2101. var refCounter = {};
  2102. // refTable['type_symbolicName'] = {number: number to link to, used: bool}
  2103. var refTable = {};
  2104. str = str.rp(RegExp(/($|>)\s*/.source + '(' + keyword('figure') + '|' + keyword('table') + '|' + keyword('listing') + '|' + keyword('diagram') + ')' + /\s+\[(.+?)\]:/.source, 'gim'), function (match, prefix, _type, _ref) {
  2105. var type = _type.toLowerCase();
  2106. // Increment the counter
  2107. var count = refCounter[type] = (refCounter[type] | 0) + 1;
  2108. var ref = type + '_' + mangle(_ref.toLowerCase().trim());
  2109. // Store the reference number
  2110. refTable[ref] = {number: count, used: false, source: type + ' [' + _ref + ']'};
  2111. return prefix +
  2112. entag('a', '&nbsp;', protect('class="target" name="' + ref + '"')) + entag('b', type[0].toUpperCase() + type.ss(1) + '&nbsp;' + count + ':', protect('style="font-style:normal;"')) +
  2113. maybeShowLabel(_ref);
  2114. });
  2115. // FIGURE, TABLE, and LISTING references:
  2116. // (must come after figure/table/listing processing, obviously)
  2117. str = str.rp(/\b(figure|fig\.|table|tbl\.|listing|lst\.)\s+\[([^\s\]]+)\]/gi, function (match, _type, _ref) {
  2118. // Fix abbreviations
  2119. var type = _type.toLowerCase();
  2120. switch (type) {
  2121. case 'fig.': type = 'figure'; break;
  2122. case 'tbl.': type = 'table'; break;
  2123. case 'lst.': type = 'listing'; break;
  2124. }
  2125. // Clean up the reference
  2126. var ref = type + '_' + mangle(_ref.toLowerCase().trim());
  2127. var t = refTable[ref];
  2128. if (t) {
  2129. t.used = true;
  2130. return '<a ' + protect('href="#' + ref + '"') + '>' + _type + '&nbsp;' + t.number + maybeShowLabel(_ref) + '</a>';
  2131. } else {
  2132. console.log("Reference to undefined '" + type + " [" + _ref + "]'");
  2133. return _type + ' ?';
  2134. }
  2135. });
  2136. // URL: <http://baz> or http://baz
  2137. // Must be detected after [link]() processing
  2138. str = str.rp(/(?:<|(?!<)\b)(\w{3,6}:\/\/.+?)(?:$|>|(?=<)|(?=\s|\u00A0)(?!<))/g, function (match, url) {
  2139. var extra = '';
  2140. if (url[url.length - 1] == '.') {
  2141. // Accidentally sucked in a period at the end of a sentence
  2142. url = url.ss(0, url.length - 1);
  2143. extra = '.';
  2144. }
  2145. // svn and perforce URLs are not hyperlinked. All others (http/https/ftp/mailto/tel, etc. are)
  2146. return '<a ' + ((url[0] !== 's' && url[0] !== 'p') ? protect('href="' + url + '" class="url"') : '') + '>' + url + '</a>' + extra;
  2147. });
  2148. if (! elementMode) {
  2149. var TITLE_PATTERN = /^\s*(?:<\/p><p>)?\s*<strong.*?>([^ \t\*].*?[^ \t\*])<\/strong>(?:<\/p>)?[ \t]*\n/.source;
  2150. var ALL_SUBTITLES_PATTERN = /([ {4,}\t][ \t]*\S.*\n)*/.source;
  2151. // Detect a bold first line and make it into a title; detect indented lines
  2152. // below it and make them subtitles
  2153. str = str.rp(
  2154. new RegExp(TITLE_PATTERN + ALL_SUBTITLES_PATTERN, 'g'),
  2155. function (match, title) {
  2156. title = title.trim();
  2157. // rp + RegExp won't give us the full list of
  2158. // subtitles, only the last one. So, we have to
  2159. // re-process match.
  2160. var subtitles = match.ss(match.indexOf('\n', match.indexOf('</strong>')));
  2161. subtitles = subtitles ? subtitles.rp(/[ \t]*(\S.*?)\n/g, '<div class="subtitle"> $1 </div>\n') : '';
  2162. // Remove all tags from the title when inside the <TITLE> tag
  2163. return entag('title', removeHTMLTags(title)) + maybeShowLabel(window.location.href, 'center') +
  2164. '<div class="title"> ' + title +
  2165. ' </div>\n' + subtitles + '<div class="afterTitles"></div>\n';
  2166. });
  2167. } // if ! noTitles
  2168. // Remove any bogus leading close-paragraph tag inserted by our extra newlines
  2169. str = str.rp(/^\s*<\/p>/, '');
  2170. // If not in element mode and not an INSERT child, maybe add a TOC
  2171. if (! elementMode) {// && ! myURLParse[2]) {
  2172. var temp = insertTableOfContents(str, protect);
  2173. str = temp[0];
  2174. var toc = temp[1];
  2175. // SECTION LINKS: Replace sec. [X], section [X], subsection [X]
  2176. str = str.rp(RegExp('\\b(' + keyword('sec') + '\\.|' + keyword('section') + '|' + keyword('subsection') + ')\\s\\[(.+?)\\]', 'gi'),
  2177. function (match, prefix, ref) {
  2178. var link = toc[ref.toLowerCase().trim()];
  2179. if (link) {
  2180. return prefix + ' <a ' + protect('href="#toc' + link + '"') + '>' + link + '</a>';
  2181. } else {
  2182. return prefix + ' ?';
  2183. }
  2184. });
  2185. }
  2186. // Expose all protected values. We may need to do this
  2187. // recursively, because pre and code blocks can be nested.
  2188. while (str.indexOf(PROTECT_CHARACTER) + 1) {
  2189. str = str.rp(PROTECT_REGEXP, expose);
  2190. }
  2191. // Warn about unused references
  2192. Object.keys(referenceLinkTable).forEach(function (key) {
  2193. if (! referenceLinkTable[key].used) {
  2194. console.log("Reference link '[" + key + "]' is defined but never used");
  2195. }
  2196. });
  2197. Object.keys(refTable).forEach(function (key) {
  2198. if (! refTable[key].used) {
  2199. console.log("'" + refTable[key].source + "' is never referenced");
  2200. }
  2201. });
  2202. return '<span class="md">' + entag('p', str) + '</span>';
  2203. }
  2204. /**
  2205. Adds whitespace at the end of each line of str, so that all lines have equal length in
  2206. unicode characters (which is not the same as JavaScript characters when high-index/escape
  2207. characters are present).
  2208. */
  2209. function equalizeLineLengths(str) {
  2210. var lineArray = str.split('\n');
  2211. var longest = 0;
  2212. lineArray.forEach(function(line) {
  2213. longest = max(longest, Array.from(line).length);
  2214. });
  2215. // Worst case spaces needed for equalizing lengths
  2216. // http://stackoverflow.com/questions/1877475/repeat-character-n-times
  2217. var spaces = Array(longest + 1).join(' ');
  2218. var result = '';
  2219. lineArray.forEach(function(line) {
  2220. // Append the needed number of spaces onto each line, and
  2221. // reconstruct the output with newlines
  2222. result += line + spaces.ss(Array.from(line).length) + '\n';
  2223. });
  2224. return result;
  2225. }
  2226. /** Finds the longest common whitespace prefix of all non-empty lines
  2227. and then removes it */
  2228. function removeLeadingSpace(str) {
  2229. var lineArray = str.split('\n');
  2230. var minimum = Infinity;
  2231. lineArray.forEach(function (line) {
  2232. if (line.trim() !== '') {
  2233. // This is a non-empty line
  2234. var spaceArray = line.match(/^([ \t]*)/);
  2235. if (spaceArray) {
  2236. minimum = min(minimum, spaceArray[0].length);
  2237. }
  2238. }
  2239. });
  2240. if (minimum === 0) {
  2241. // No leading space
  2242. return str;
  2243. }
  2244. var result = '';
  2245. lineArray.forEach(function(line) {
  2246. // Strip the common spaces
  2247. result += line.ss(minimum) + '\n';
  2248. });
  2249. return result;
  2250. }
  2251. /** Returns true if this character is a "letter" under the ASCII definition */
  2252. function isASCIILetter(c) {
  2253. var code = c.charCodeAt(0);
  2254. return ((code >= 65) && (code <= 90)) || ((code >= 97) && (code <= 122));
  2255. }
  2256. /** Converts diagramString, which is a Markdeep diagram without the surrounding asterisks, to
  2257. SVG (HTML). Lines may have ragged lengths.
  2258. alignmentHint is the float alignment desired for the SVG tag,
  2259. which can be 'floatleft', 'floatright', or ''
  2260. */
  2261. function diagramToSVG(diagramString, alignmentHint) {
  2262. // Clean up diagramString if line endings are ragged
  2263. diagramString = equalizeLineLengths(diagramString);
  2264. // Temporarily replace 'o' that is surrounded by other text
  2265. // with another character to avoid processing it as a point
  2266. // decoration. This will be replaced in the final svg and is
  2267. // faster than checking each neighborhood each time.
  2268. var HIDE_O = '\ue004';
  2269. diagramString = diagramString.rp(/([a-zA-Z]{2})o/g, '$1' + HIDE_O);
  2270. diagramString = diagramString.rp(/o([a-zA-Z]{2})/g, HIDE_O + '$1');
  2271. diagramString = diagramString.rp(/([a-zA-Z\ue004])o([a-zA-Z\ue004])/g, '$1' + HIDE_O + '$2');
  2272. /** Pixels per character */
  2273. var SCALE = 8;
  2274. /** Multiply Y coordinates by this when generating the final SVG
  2275. result to account for the aspect ratio of text files. This
  2276. MUST be 2 */
  2277. var ASPECT = 2;
  2278. var DIAGONAL_ANGLE = Math.atan(1.0 / ASPECT) * 180 / Math.PI;
  2279. var EPSILON = 1e-6;
  2280. // The order of the following is based on rotation angles
  2281. // and is used for ArrowSet.toSVG
  2282. var ARROW_HEAD_CHARACTERS = '>v<^';
  2283. var POINT_CHARACTERS = 'o*';
  2284. var JUMP_CHARACTERS = '()';
  2285. var UNDIRECTED_VERTEX_CHARACTERS = "+";
  2286. var VERTEX_CHARACTERS = UNDIRECTED_VERTEX_CHARACTERS + ".'";
  2287. // GRAY[i] is the Unicode block character for (i+1)/4 level gray
  2288. var GRAY_CHARACTERS = '\u2591\u2592\u2593\u2594\u2589';
  2289. // TRI[i] is a right-triangle rotated by 90*i
  2290. var TRI_CHARACTERS = '\u25E2\u25E3\u25E4\u25E5';
  2291. var DECORATION_CHARACTERS = ARROW_HEAD_CHARACTERS + POINT_CHARACTERS + JUMP_CHARACTERS + GRAY_CHARACTERS + TRI_CHARACTERS;
  2292. function isUndirectedVertex(c) { return UNDIRECTED_VERTEX_CHARACTERS.indexOf(c) + 1; }
  2293. function isVertex(c) { return VERTEX_CHARACTERS.indexOf(c) !== -1; }
  2294. function isTopVertex(c) { return isUndirectedVertex(c) || (c === '.'); }
  2295. function isBottomVertex(c) { return isUndirectedVertex(c) || (c === "'"); }
  2296. function isVertexOrLeftDecoration(c){ return isVertex(c) || (c === '<') || isPoint(c); }
  2297. function isVertexOrRightDecoration(c){return isVertex(c) || (c === '>') || isPoint(c); }
  2298. function isArrowHead(c) { return ARROW_HEAD_CHARACTERS.indexOf(c) + 1; }
  2299. function isGray(c) { return GRAY_CHARACTERS.indexOf(c) + 1; }
  2300. function isTri(c) { return TRI_CHARACTERS.indexOf(c) + 1; }
  2301. // "D" = Diagonal slash (/), "B" = diagonal Backslash (\)
  2302. // Characters that may appear anywhere on a solid line
  2303. function isSolidHLine(c) { return (c === '-') || isUndirectedVertex(c) || isJump(c); }
  2304. function isSolidVLineOrJumpOrPoint(c) { return isSolidVLine(c) || isJump(c) || isPoint(c); }
  2305. function isSolidVLine(c) { return (c === '|') || isUndirectedVertex(c); }
  2306. function isSolidDLine(c) { return (c === '/') || isUndirectedVertex(c) }
  2307. function isSolidBLine(c) { return (c === '\\') || isUndirectedVertex(c); }
  2308. function isJump(c) { return JUMP_CHARACTERS.indexOf(c) + 1; }
  2309. function isPoint(c) { return POINT_CHARACTERS.indexOf(c) + 1; }
  2310. function isDecoration(c) { return DECORATION_CHARACTERS.indexOf(c) + 1; }
  2311. function isEmpty(c) { return c === ' '; }
  2312. ///////////////////////////////////////////////////////////////////////////////
  2313. // Math library
  2314. /** Invoke as new Vec2(v) to clone or new Vec2(x, y) to create from coordinates.
  2315. Can also invoke without new for brevity. */
  2316. function Vec2(x, y) {
  2317. // Detect when being run without new
  2318. if (! (this instanceof Vec2)) { return new Vec2(x, y); }
  2319. if (y === undefined) {
  2320. if (x === undefined) { x = y = 0; }
  2321. else if (x instanceof Vec2) { y = x.y; x = x.x; }
  2322. else { console.error("Vec2 requires one Vec2 or (x, y) as an argument"); }
  2323. }
  2324. this.x = x;
  2325. this.y = y;
  2326. Object.seal(this);
  2327. }
  2328. /** Returns an SVG representation */
  2329. Vec2.prototype.toString = Vec2.prototype.toSVG =
  2330. function () { return '' + (this.x * SCALE) + ',' + (this.y * SCALE * ASPECT) + ' '; };
  2331. /** Converts a "rectangular" string defined by newlines into 2D
  2332. array of characters. Grids are immutable. */
  2333. function makeGrid(str) {
  2334. /** Returns ' ' for out of bounds values */
  2335. var grid = function(x, y) {
  2336. if (y === undefined) {
  2337. if (x instanceof Vec2) { y = x.y; x = x.x; }
  2338. else { console.error('grid requires either a Vec2 or (x, y)'); }
  2339. }
  2340. return ((x >= 0) && (x < grid.width) && (y >= 0) && (y < grid.height)) ?
  2341. str[y * (grid.width + 1) + x] : ' ';
  2342. };
  2343. // Elements are true when consumed
  2344. grid._used = [];
  2345. grid.height = str.split('\n').length;
  2346. if (str[str.length - 1] === '\n') { --grid.height; }
  2347. // Convert the string to an array to better handle greater-than 16-bit unicode
  2348. // characters, which JavaScript does not process correctly with indices. Do this after
  2349. // the above string processing.
  2350. str = Array.from(str);
  2351. grid.width = str.indexOf('\n');
  2352. /** Mark this location. Takes a Vec2 or (x, y) */
  2353. grid.setUsed = function (x, y) {
  2354. if (y === undefined) {
  2355. if (x instanceof Vec2) { y = x.y; x = x.x; }
  2356. else { console.error('grid requires either a Vec2 or (x, y)'); }
  2357. }
  2358. if ((x >= 0) && (x < grid.width) && (y >= 0) && (y < grid.height)) {
  2359. // Match the source string indexing
  2360. grid._used[y * (grid.width + 1) + x] = true;
  2361. }
  2362. };
  2363. grid.isUsed = function (x, y) {
  2364. if (y === undefined) {
  2365. if (x instanceof Vec2) { y = x.y; x = x.x; }
  2366. else { console.error('grid requires either a Vec2 or (x, y)'); }
  2367. }
  2368. return (this._used[y * (this.width + 1) + x] === true);
  2369. };
  2370. /** Returns true if there is a solid vertical line passing through (x, y) */
  2371. grid.isSolidVLineAt = function (x, y) {
  2372. if (y === undefined) { y = x.x; x = x.x; }
  2373. var up = grid(x, y - 1);
  2374. var c = grid(x, y);
  2375. var dn = grid(x, y + 1);
  2376. var uprt = grid(x + 1, y - 1);
  2377. var uplt = grid(x - 1, y - 1);
  2378. if (isSolidVLine(c)) {
  2379. // Looks like a vertical line...does it continue?
  2380. return (isTopVertex(up) || (up === '^') || isSolidVLine(up) || isJump(up) ||
  2381. isBottomVertex(dn) || (dn === 'v') || isSolidVLine(dn) || isJump(dn) ||
  2382. isPoint(up) || isPoint(dn) || (grid(x, y - 1) === '_') || (uplt === '_') ||
  2383. (uprt === '_') ||
  2384. // Special case of 1-high vertical on two curved corners
  2385. ((isTopVertex(uplt) || isTopVertex(uprt)) &&
  2386. (isBottomVertex(grid(x - 1, y + 1)) || isBottomVertex(grid(x + 1, y + 1)))));
  2387. } else if (isTopVertex(c) || (c === '^')) {
  2388. // May be the top of a vertical line
  2389. return isSolidVLine(dn) || (isJump(dn) && (c !== '.'));
  2390. } else if (isBottomVertex(c) || (c === 'v')) {
  2391. return isSolidVLine(up) || (isJump(up) && (c !== "'"));
  2392. } else if (isPoint(c)) {
  2393. return isSolidVLine(up) || isSolidVLine(dn);
  2394. }
  2395. return false;
  2396. };
  2397. /** Returns true if there is a solid middle (---) horizontal line
  2398. passing through (x, y). Ignores underscores. */
  2399. grid.isSolidHLineAt = function (x, y) {
  2400. if (y === undefined) { y = x.x; x = x.x; }
  2401. var ltlt = grid(x - 2, y);
  2402. var lt = grid(x - 1, y);
  2403. var c = grid(x + 0, y);
  2404. var rt = grid(x + 1, y);
  2405. var rtrt = grid(x + 2, y);
  2406. if (isSolidHLine(c) || (isSolidHLine(lt) && isJump(c))) {
  2407. // Looks like a horizontal line...does it continue? We need three in a row.
  2408. if (isSolidHLine(lt)) {
  2409. return isSolidHLine(rt) || isVertexOrRightDecoration(rt) ||
  2410. isSolidHLine(ltlt) || isVertexOrLeftDecoration(ltlt);
  2411. } else if (isVertexOrLeftDecoration(lt)) {
  2412. return isSolidHLine(rt);
  2413. } else {
  2414. return isSolidHLine(rt) && (isSolidHLine(rtrt) || isVertexOrRightDecoration(rtrt));
  2415. }
  2416. } else if (c === '<') {
  2417. return isSolidHLine(rt) && isSolidHLine(rtrt)
  2418. } else if (c === '>') {
  2419. return isSolidHLine(lt) && isSolidHLine(ltlt);
  2420. } else if (isVertex(c)) {
  2421. return ((isSolidHLine(lt) && isSolidHLine(ltlt)) ||
  2422. (isSolidHLine(rt) && isSolidHLine(rtrt)));
  2423. }
  2424. return false;
  2425. };
  2426. /** Returns true if there is a solid backslash line passing through (x, y) */
  2427. grid.isSolidBLineAt = function (x, y) {
  2428. if (y === undefined) { y = x.x; x = x.x; }
  2429. var c = grid(x, y);
  2430. var lt = grid(x - 1, y - 1);
  2431. var rt = grid(x + 1, y + 1);
  2432. if (c === '\\') {
  2433. // Looks like a diagonal line...does it continue? We need two in a row.
  2434. return (isSolidBLine(rt) || isBottomVertex(rt) || isPoint(rt) || (rt === 'v') ||
  2435. isSolidBLine(lt) || isTopVertex(lt) || isPoint(lt) || (lt === '^') ||
  2436. (grid(x, y - 1) === '/') || (grid(x, y + 1) === '/') || (rt === '_') || (lt === '_'));
  2437. } else if (c === '.') {
  2438. return (rt === '\\');
  2439. } else if (c === "'") {
  2440. return (lt === '\\');
  2441. } else if (c === '^') {
  2442. return rt === '\\';
  2443. } else if (c === 'v') {
  2444. return lt === '\\';
  2445. } else if (isVertex(c) || isPoint(c) || (c === '|')) {
  2446. return isSolidBLine(lt) || isSolidBLine(rt);
  2447. }
  2448. };
  2449. /** Returns true if there is a solid diagonal line passing through (x, y) */
  2450. grid.isSolidDLineAt = function (x, y) {
  2451. if (y === undefined) { y = x.x; x = x.x; }
  2452. var c = grid(x, y);
  2453. var lt = grid(x - 1, y + 1);
  2454. var rt = grid(x + 1, y - 1);
  2455. if (c === '/' && ((grid(x, y - 1) === '\\') || (grid(x, y + 1) === '\\'))) {
  2456. // Special case of tiny hexagon corner
  2457. return true;
  2458. } else if (isSolidDLine(c)) {
  2459. // Looks like a diagonal line...does it continue? We need two in a row.
  2460. return (isSolidDLine(rt) || isTopVertex(rt) || isPoint(rt) || (rt === '^') || (rt === '_') ||
  2461. isSolidDLine(lt) || isBottomVertex(lt) || isPoint(lt) || (lt === 'v') || (lt === '_'));
  2462. } else if (c === '.') {
  2463. return (lt === '/');
  2464. } else if (c === "'") {
  2465. return (rt === '/');
  2466. } else if (c === '^') {
  2467. return lt === '/';
  2468. } else if (c === 'v') {
  2469. return rt === '/';
  2470. } else if (isVertex(c) || isPoint(c) || (c === '|')) {
  2471. return isSolidDLine(lt) || isSolidDLine(rt);
  2472. }
  2473. return false;
  2474. };
  2475. grid.toString = function () { return str; };
  2476. return Object.freeze(grid);
  2477. }
  2478. /** A 1D curve. If C is specified, the result is a bezier with
  2479. that as the tangent control point */
  2480. function Path(A, B, C, D, dashed) {
  2481. if (! ((A instanceof Vec2) && (B instanceof Vec2))) {
  2482. console.error('Path constructor requires at least two Vec2s');
  2483. }
  2484. this.A = A;
  2485. this.B = B;
  2486. if (C) {
  2487. this.C = C;
  2488. if (D) {
  2489. this.D = D;
  2490. } else {
  2491. this.D = C;
  2492. }
  2493. }
  2494. this.dashed = dashed || false;
  2495. Object.freeze(this);
  2496. }
  2497. var _ = Path.prototype;
  2498. _.isVertical = function () {
  2499. return this.B.x === this.A.x;
  2500. };
  2501. _.isHorizontal = function () {
  2502. return this.B.y === this.A.y;
  2503. };
  2504. /** Diagonal lines look like: / See also backDiagonal */
  2505. _.isDiagonal = function () {
  2506. var dx = this.B.x - this.A.x;
  2507. var dy = this.B.y - this.A.y;
  2508. return (abs(dy + dx) < EPSILON);
  2509. };
  2510. _.isBackDiagonal = function () {
  2511. var dx = this.B.x - this.A.x;
  2512. var dy = this.B.y - this.A.y;
  2513. return (abs(dy - dx) < EPSILON);
  2514. };
  2515. _.isCurved = function () {
  2516. return this.C !== undefined;
  2517. };
  2518. /** Does this path have any end at (x, y) */
  2519. _.endsAt = function (x, y) {
  2520. if (y === undefined) { y = x.y; x = x.x; }
  2521. return ((this.A.x === x) && (this.A.y === y)) ||
  2522. ((this.B.x === x) && (this.B.y === y));
  2523. };
  2524. /** Does this path have an up end at (x, y) */
  2525. _.upEndsAt = function (x, y) {
  2526. if (y === undefined) { y = x.y; x = x.x; }
  2527. return this.isVertical() && (this.A.x === x) && (min(this.A.y, this.B.y) === y);
  2528. };
  2529. /** Does this path have an up end at (x, y) */
  2530. _.diagonalUpEndsAt = function (x, y) {
  2531. if (! this.isDiagonal()) { return false; }
  2532. if (y === undefined) { y = x.y; x = x.x; }
  2533. if (this.A.y < this.B.y) {
  2534. return (this.A.x === x) && (this.A.y === y);
  2535. } else {
  2536. return (this.B.x === x) && (this.B.y === y);
  2537. }
  2538. };
  2539. /** Does this path have a down end at (x, y) */
  2540. _.diagonalDownEndsAt = function (x, y) {
  2541. if (! this.isDiagonal()) { return false; }
  2542. if (y === undefined) { y = x.y; x = x.x; }
  2543. if (this.B.y < this.A.y) {
  2544. return (this.A.x === x) && (this.A.y === y);
  2545. } else {
  2546. return (this.B.x === x) && (this.B.y === y);
  2547. }
  2548. };
  2549. /** Does this path have an up end at (x, y) */
  2550. _.backDiagonalUpEndsAt = function (x, y) {
  2551. if (! this.isBackDiagonal()) { return false; }
  2552. if (y === undefined) { y = x.y; x = x.x; }
  2553. if (this.A.y < this.B.y) {
  2554. return (this.A.x === x) && (this.A.y === y);
  2555. } else {
  2556. return (this.B.x === x) && (this.B.y === y);
  2557. }
  2558. };
  2559. /** Does this path have a down end at (x, y) */
  2560. _.backDiagonalDownEndsAt = function (x, y) {
  2561. if (! this.isBackDiagonal()) { return false; }
  2562. if (y === undefined) { y = x.y; x = x.x; }
  2563. if (this.B.y < this.A.y) {
  2564. return (this.A.x === x) && (this.A.y === y);
  2565. } else {
  2566. return (this.B.x === x) && (this.B.y === y);
  2567. }
  2568. };
  2569. /** Does this path have a down end at (x, y) */
  2570. _.downEndsAt = function (x, y) {
  2571. if (y === undefined) { y = x.y; x = x.x; }
  2572. return this.isVertical() && (this.A.x === x) && (max(this.A.y, this.B.y) === y);
  2573. };
  2574. /** Does this path have a left end at (x, y) */
  2575. _.leftEndsAt = function (x, y) {
  2576. if (y === undefined) { y = x.y; x = x.x; }
  2577. return this.isHorizontal() && (this.A.y === y) && (min(this.A.x, this.B.x) === x);
  2578. };
  2579. /** Does this path have a right end at (x, y) */
  2580. _.rightEndsAt = function (x, y) {
  2581. if (y === undefined) { y = x.y; x = x.x; }
  2582. return this.isHorizontal() && (this.A.y === y) && (max(this.A.x, this.B.x) === x);
  2583. };
  2584. _.verticalPassesThrough = function (x, y) {
  2585. if (y === undefined) { y = x.y; x = x.x; }
  2586. return this.isVertical() &&
  2587. (this.A.x === x) &&
  2588. (min(this.A.y, this.B.y) <= y) &&
  2589. (max(this.A.y, this.B.y) >= y);
  2590. }
  2591. _.horizontalPassesThrough = function (x, y) {
  2592. if (y === undefined) { y = x.y; x = x.x; }
  2593. return this.isHorizontal() &&
  2594. (this.A.y === y) &&
  2595. (min(this.A.x, this.B.x) <= x) &&
  2596. (max(this.A.x, this.B.x) >= x);
  2597. }
  2598. /** Returns a string suitable for inclusion in an SVG tag */
  2599. _.toSVG = function () {
  2600. var svg = '<path d="M ' + this.A;
  2601. if (this.isCurved()) {
  2602. svg += 'C ' + this.C + this.D + this.B;
  2603. } else {
  2604. svg += 'L ' + this.B;
  2605. }
  2606. svg += '" style="fill:none;"';
  2607. if (this.dashed) {
  2608. svg += ' stroke-dasharray="3,6"';
  2609. }
  2610. svg += '/>';
  2611. return svg;
  2612. };
  2613. /** A group of 1D curves. This was designed so that all of the
  2614. methods can later be implemented in O(1) time, but it
  2615. currently uses O(n) implementations for source code
  2616. simplicity. */
  2617. function PathSet() {
  2618. this._pathArray = [];
  2619. }
  2620. var PS = PathSet.prototype;
  2621. PS.insert = function (path) {
  2622. this._pathArray.push(path);
  2623. };
  2624. /** Returns a new method that returns true if method(x, y)
  2625. returns true on any element of _pathAray */
  2626. function makeFilterAny(method) {
  2627. return function(x, y) {
  2628. for (var i = 0; i < this._pathArray.length; ++i) {
  2629. if (method.call(this._pathArray[i], x, y)) { return true; }
  2630. }
  2631. // Fall through: return undefined == false
  2632. }
  2633. }
  2634. // True if an up line ends at these coordinates. Recall that the
  2635. // variable _ is bound to the Path prototype still.
  2636. PS.upEndsAt = makeFilterAny(_.upEndsAt);
  2637. PS.diagonalUpEndsAt = makeFilterAny(_.diagonalUpEndsAt);
  2638. PS.backDiagonalUpEndsAt = makeFilterAny(_.backDiagonalUpEndsAt);
  2639. PS.diagonalDownEndsAt = makeFilterAny(_.diagonalDownEndsAt);
  2640. PS.backDiagonalDownEndsAt = makeFilterAny(_.backDiagonalDownEndsAt);
  2641. PS.downEndsAt = makeFilterAny(_.downEndsAt);
  2642. PS.leftEndsAt = makeFilterAny(_.leftEndsAt);
  2643. PS.rightEndsAt = makeFilterAny(_.rightEndsAt);
  2644. PS.endsAt = makeFilterAny(_.endsAt);
  2645. PS.verticalPassesThrough = makeFilterAny(_.verticalPassesThrough);
  2646. PS.horizontalPassesThrough = makeFilterAny(_.horizontalPassesThrough);
  2647. /** Returns an SVG string */
  2648. PS.toSVG = function () {
  2649. var svg = '';
  2650. for (var i = 0; i < this._pathArray.length; ++i) {
  2651. svg += this._pathArray[i].toSVG() + '\n';
  2652. }
  2653. return svg;
  2654. };
  2655. function DecorationSet() {
  2656. this._decorationArray = [];
  2657. }
  2658. var DS = DecorationSet.prototype;
  2659. /** insert(x, y, type, <angle>)
  2660. insert(vec, type, <angle>)
  2661. angle is the angle in degrees to rotate the result */
  2662. DS.insert = function(x, y, type, angle) {
  2663. if (type === undefined) { type = y; y = x.y; x = x.x; }
  2664. if (! isDecoration(type)) {
  2665. console.error('Illegal decoration character: ' + type);
  2666. }
  2667. var d = {C: Vec2(x, y), type: type, angle:angle || 0};
  2668. // Put arrows at the front and points at the back so that
  2669. // arrows always draw under points
  2670. if (isPoint(type)) {
  2671. this._decorationArray.push(d);
  2672. } else {
  2673. this._decorationArray.unshift(d);
  2674. }
  2675. };
  2676. DS.toSVG = function () {
  2677. var svg = '';
  2678. for (var i = 0; i < this._decorationArray.length; ++i) {
  2679. var decoration = this._decorationArray[i];
  2680. var C = decoration.C;
  2681. if (isJump(decoration.type)) {
  2682. // Slide jumps
  2683. var dx = (decoration.type === ')') ? +0.75 : -0.75;
  2684. var up = Vec2(C.x, C.y - 0.5);
  2685. var dn = Vec2(C.x, C.y + 0.5);
  2686. var cup = Vec2(C.x + dx, C.y - 0.5);
  2687. var cdn = Vec2(C.x + dx, C.y + 0.5);
  2688. svg += '<path d="M ' + dn + ' C ' + cdn + cup + up + '" style="fill:none;"/>';
  2689. } else if (isPoint(decoration.type)) {
  2690. svg += '<circle cx="' + (C.x * SCALE) + '" cy="' + (C.y * SCALE * ASPECT) +
  2691. '" r="' + (SCALE - STROKE_WIDTH) + '" class="' + ((decoration.type === '*') ? 'closed' : 'open') + 'dot"/>';
  2692. } else if (isGray(decoration.type)) {
  2693. var shade = Math.round((3 - GRAY_CHARACTERS.indexOf(decoration.type)) * 63.75);
  2694. svg += '<rect x="' + ((C.x - 0.5) * SCALE) + '" y="' + ((C.y - 0.5) * SCALE * ASPECT) + '" width="' + SCALE + '" height="' + (SCALE * ASPECT) + '" stroke=none fill="rgb(' + shade + ',' + shade + ',' + shade +')"/>';
  2695. } else if (isTri(decoration.type)) {
  2696. // 30-60-90 triangle
  2697. var index = TRI_CHARACTERS.indexOf(decoration.type);
  2698. var xs = 0.5 - (index & 1);
  2699. var ys = 0.5 - (index >> 1);
  2700. xs *= sign(ys);
  2701. var tip = Vec2(C.x + xs, C.y - ys);
  2702. var up = Vec2(C.x + xs, C.y + ys);
  2703. var dn = Vec2(C.x - xs, C.y + ys);
  2704. svg += '<polygon points="' + tip + up + dn + '" style="stroke:none"/>\n';
  2705. } else { // Arrow head
  2706. var tip = Vec2(C.x + 1, C.y);
  2707. var up = Vec2(C.x - 0.5, C.y - 0.35);
  2708. var dn = Vec2(C.x - 0.5, C.y + 0.35);
  2709. svg += '<polygon points="' + tip + up + dn +
  2710. '" style="stroke:none" transform="rotate(' + decoration.angle + ',' + C + ')"/>\n';
  2711. }
  2712. }
  2713. return svg;
  2714. };
  2715. ////////////////////////////////////////////////////////////////////////////
  2716. function findPaths(grid, pathSet) {
  2717. // Does the line from A to B contain at least one c?
  2718. function lineContains(A, B, c) {
  2719. var dx = sign(B.x - A.x);
  2720. var dy = sign(B.y - A.y);
  2721. var x, y;
  2722. for (x = A.x, y = A.y; (x !== B.x) || (y !== B.y); x += dx, y += dy) {
  2723. if (grid(x, y) === c) { return true; }
  2724. }
  2725. // Last point
  2726. return (grid(x, y) === c);
  2727. }
  2728. // Find all solid vertical lines. Iterate horizontally
  2729. // so that we never hit the same line twice
  2730. for (var x = 0; x < grid.width; ++x) {
  2731. for (var y = 0; y < grid.height; ++y) {
  2732. if (grid.isSolidVLineAt(x, y)) {
  2733. // This character begins a vertical line...now, find the end
  2734. var A = Vec2(x, y);
  2735. do { grid.setUsed(x, y); ++y; } while (grid.isSolidVLineAt(x, y));
  2736. var B = Vec2(x, y - 1);
  2737. var up = grid(A);
  2738. var upup = grid(A.x, A.y - 1);
  2739. if (! isVertex(up) && ((upup === '-') || (upup === '_') || (grid(A.x - 1, A.y - 1) === '_') ||
  2740. (grid(A.x + 1, A.y - 1) === '_') ||
  2741. isBottomVertex(upup)) || isJump(upup)) {
  2742. // Stretch up to almost reach the line above (if there is a decoration,
  2743. // it will finish the gap)
  2744. A.y -= 0.5;
  2745. }
  2746. var dn = grid(B);
  2747. var dndn = grid(B.x, B.y + 1);
  2748. if (! isVertex(dn) && ((dndn === '-') || isTopVertex(dndn)) || isJump(dndn) ||
  2749. (grid(B.x - 1, B.y) === '_') || (grid(B.x + 1, B.y) === '_')) {
  2750. // Stretch down to almost reach the line below
  2751. B.y += 0.5;
  2752. }
  2753. // Don't insert degenerate lines
  2754. if ((A.x !== B.x) || (A.y !== B.y)) {
  2755. pathSet.insert(new Path(A, B));
  2756. }
  2757. // Continue the search from the end value y+1
  2758. }
  2759. // Some very special patterns for the short lines needed on
  2760. // circuit diagrams. Only invoke these if not also on a curve
  2761. // _ _
  2762. // -' '-
  2763. else if ((grid(x, y) === "'") &&
  2764. (((grid(x - 1, y) === '-') && (grid(x + 1, y - 1) === '_') &&
  2765. ! isSolidVLineOrJumpOrPoint(grid(x - 1, y - 1))) ||
  2766. ((grid(x - 1, y - 1) === '_') && (grid(x + 1, y) === '-') &&
  2767. ! isSolidVLineOrJumpOrPoint(grid(x + 1, y - 1))))) {
  2768. pathSet.insert(new Path(Vec2(x, y - 0.5), Vec2(x, y)));
  2769. }
  2770. // _.- -._
  2771. else if ((grid(x, y) === '.') &&
  2772. (((grid(x - 1, y) === '_') && (grid(x + 1, y) === '-') &&
  2773. ! isSolidVLineOrJumpOrPoint(grid(x + 1, y + 1))) ||
  2774. ((grid(x - 1, y) === '-') && (grid(x + 1, y) === '_') &&
  2775. ! isSolidVLineOrJumpOrPoint(grid(x - 1, y + 1))))) {
  2776. pathSet.insert(new Path(Vec2(x, y), Vec2(x, y + 0.5)));
  2777. }
  2778. } // y
  2779. } // x
  2780. // Find all solid horizontal lines
  2781. for (var y = 0; y < grid.height; ++y) {
  2782. for (var x = 0; x < grid.width; ++x) {
  2783. if (grid.isSolidHLineAt(x, y)) {
  2784. // Begins a line...find the end
  2785. var A = Vec2(x, y);
  2786. do { grid.setUsed(x, y); ++x; } while (grid.isSolidHLineAt(x, y));
  2787. var B = Vec2(x - 1, y);
  2788. // Detect curves and shorten the edge
  2789. if ( ! isVertex(grid(A.x - 1, A.y)) &&
  2790. ((isTopVertex(grid(A)) && isSolidVLineOrJumpOrPoint(grid(A.x - 1, A.y + 1))) ||
  2791. (isBottomVertex(grid(A)) && isSolidVLineOrJumpOrPoint(grid(A.x - 1, A.y - 1))))) {
  2792. ++A.x;
  2793. }
  2794. if ( ! isVertex(grid(B.x + 1, B.y)) &&
  2795. ((isTopVertex(grid(B)) && isSolidVLineOrJumpOrPoint(grid(B.x + 1, B.y + 1))) ||
  2796. (isBottomVertex(grid(B)) && isSolidVLineOrJumpOrPoint(grid(B.x + 1, B.y - 1))))) {
  2797. --B.x;
  2798. }
  2799. // Don't insert degenerate lines
  2800. if ((A.x !== B.x) || (A.y !== B.y)) {
  2801. pathSet.insert(new Path(A, B));
  2802. }
  2803. // Continue the search from the end x+1
  2804. }
  2805. }
  2806. } // y
  2807. // Find all solid left-to-right downward diagonal lines (BACK DIAGONAL)
  2808. for (var i = -grid.height; i < grid.width; ++i) {
  2809. for (var x = i, y = 0; y < grid.height; ++y, ++x) {
  2810. if (grid.isSolidBLineAt(x, y)) {
  2811. // Begins a line...find the end
  2812. var A = Vec2(x, y);
  2813. do { ++x; ++y; } while (grid.isSolidBLineAt(x, y));
  2814. var B = Vec2(x - 1, y - 1);
  2815. // Ensure that the entire line wasn't just vertices
  2816. if (lineContains(A, B, '\\')) {
  2817. for (var j = A.x; j <= B.x; ++j) {
  2818. grid.setUsed(j, A.y + (j - A.x));
  2819. }
  2820. var top = grid(A);
  2821. var up = grid(A.x, A.y - 1);
  2822. var uplt = grid(A.x - 1, A.y - 1);
  2823. if ((up === '/') || (uplt === '_') || (up === '_') ||
  2824. (! isVertex(top) &&
  2825. (isSolidHLine(uplt) || isSolidVLine(uplt)))) {
  2826. // Continue half a cell more to connect for:
  2827. // ___ ___
  2828. // \ \ / ---- |
  2829. // \ \ \ ^ |^
  2830. A.x -= 0.5; A.y -= 0.5;
  2831. } else if (isPoint(uplt)) {
  2832. // Continue 1/4 cell more to connect for:
  2833. //
  2834. // o
  2835. // ^
  2836. // \
  2837. A.x -= 0.25; A.y -= 0.25;
  2838. }
  2839. var bottom = grid(B);
  2840. var dnrt = grid(B.x + 1, B.y + 1);
  2841. if ((grid(B.x, B.y + 1) === '/') || (grid(B.x + 1, B.y) === '_') ||
  2842. (grid(B.x - 1, B.y) === '_') ||
  2843. (! isVertex(grid(B)) &&
  2844. (isSolidHLine(dnrt) || isSolidVLine(dnrt)))) {
  2845. // Continue half a cell more to connect for:
  2846. // \ \ |
  2847. // \ \ \ v v|
  2848. // \__ __\ / ---- |
  2849. B.x += 0.5; B.y += 0.5;
  2850. } else if (isPoint(dnrt)) {
  2851. // Continue 1/4 cell more to connect for:
  2852. //
  2853. // \
  2854. // v
  2855. // o
  2856. B.x += 0.25; B.y += 0.25;
  2857. }
  2858. pathSet.insert(new Path(A, B));
  2859. // Continue the search from the end x+1,y+1
  2860. } // lineContains
  2861. }
  2862. }
  2863. } // i
  2864. // Find all solid left-to-right upward diagonal lines (DIAGONAL)
  2865. for (var i = -grid.height; i < grid.width; ++i) {
  2866. for (var x = i, y = grid.height - 1; y >= 0; --y, ++x) {
  2867. if (grid.isSolidDLineAt(x, y)) {
  2868. // Begins a line...find the end
  2869. var A = Vec2(x, y);
  2870. do { ++x; --y; } while (grid.isSolidDLineAt(x, y));
  2871. var B = Vec2(x - 1, y + 1);
  2872. if (lineContains(A, B, '/')) {
  2873. // This is definitely a line. Commit the characters on it
  2874. for (var j = A.x; j <= B.x; ++j) {
  2875. grid.setUsed(j, A.y - (j - A.x));
  2876. }
  2877. var up = grid(B.x, B.y - 1);
  2878. var uprt = grid(B.x + 1, B.y - 1);
  2879. var bottom = grid(B);
  2880. if ((up === '\\') || (up === '_') || (uprt === '_') ||
  2881. (! isVertex(grid(B)) &&
  2882. (isSolidHLine(uprt) || isSolidVLine(uprt)))) {
  2883. // Continue half a cell more to connect at:
  2884. // __ __ --- |
  2885. // / / ^ ^|
  2886. // / / / / |
  2887. B.x += 0.5; B.y -= 0.5;
  2888. } else if (isPoint(uprt)) {
  2889. // Continue 1/4 cell more to connect at:
  2890. //
  2891. // o
  2892. // ^
  2893. // /
  2894. B.x += 0.25; B.y -= 0.25;
  2895. }
  2896. var dnlt = grid(A.x - 1, A.y + 1);
  2897. var top = grid(A);
  2898. if ((grid(A.x, A.y + 1) === '\\') || (grid(A.x - 1, A.y) === '_') || (grid(A.x + 1, A.y) === '_') ||
  2899. (! isVertex(grid(A)) &&
  2900. (isSolidHLine(dnlt) || isSolidVLine(dnlt)))) {
  2901. // Continue half a cell more to connect at:
  2902. // / \ |
  2903. // / / v v|
  2904. // __/ /__ ---- |
  2905. A.x -= 0.5; A.y += 0.5;
  2906. } else if (isPoint(dnlt)) {
  2907. // Continue 1/4 cell more to connect at:
  2908. //
  2909. // /
  2910. // v
  2911. // o
  2912. A.x -= 0.25; A.y += 0.25;
  2913. }
  2914. pathSet.insert(new Path(A, B));
  2915. // Continue the search from the end x+1,y-1
  2916. } // lineContains
  2917. }
  2918. }
  2919. } // y
  2920. // Now look for curved corners. The syntax constraints require
  2921. // that these can always be identified by looking at three
  2922. // horizontally-adjacent characters.
  2923. for (var y = 0; y < grid.height; ++y) {
  2924. for (var x = 0; x < grid.width; ++x) {
  2925. var c = grid(x, y);
  2926. // Note that because of undirected vertices, the
  2927. // following cases are not exclusive
  2928. if (isTopVertex(c)) {
  2929. // -.
  2930. // |
  2931. if (isSolidHLine(grid(x - 1, y)) && isSolidVLine(grid(x + 1, y + 1))) {
  2932. grid.setUsed(x - 1, y); grid.setUsed(x, y); grid.setUsed(x + 1, y + 1);
  2933. pathSet.insert(new Path(Vec2(x - 1, y), Vec2(x + 1, y + 1),
  2934. Vec2(x + 1.1, y), Vec2(x + 1, y + 1)));
  2935. }
  2936. // .-
  2937. // |
  2938. if (isSolidHLine(grid(x + 1, y)) && isSolidVLine(grid(x - 1, y + 1))) {
  2939. grid.setUsed(x - 1, y + 1); grid.setUsed(x, y); grid.setUsed(x + 1, y);
  2940. pathSet.insert(new Path(Vec2(x + 1, y), Vec2(x - 1, y + 1),
  2941. Vec2(x - 1.1, y), Vec2(x - 1, y + 1)));
  2942. }
  2943. }
  2944. // Special case patterns:
  2945. // . . . .
  2946. // ( o ) o
  2947. // ' . ' '
  2948. if (((c === ')') || isPoint(c)) && (grid(x - 1, y - 1) === '.') && (grid(x - 1, y + 1) === "\'")) {
  2949. grid.setUsed(x, y); grid.setUsed(x - 1, y - 1); grid.setUsed(x - 1, y + 1);
  2950. pathSet.insert(new Path(Vec2(x - 2, y - 1), Vec2(x - 2, y + 1),
  2951. Vec2(x + 0.6, y - 1), Vec2(x + 0.6, y + 1)));
  2952. }
  2953. if (((c === '(') || isPoint(c)) && (grid(x + 1, y - 1) === '.') && (grid(x + 1, y + 1) === "\'")) {
  2954. grid.setUsed(x, y); grid.setUsed(x + 1, y - 1); grid.setUsed(x + 1, y + 1);
  2955. pathSet.insert(new Path(Vec2(x + 2, y - 1), Vec2(x + 2, y + 1),
  2956. Vec2(x - 0.6, y - 1), Vec2(x - 0.6, y + 1)));
  2957. }
  2958. if (isBottomVertex(c)) {
  2959. // |
  2960. // -'
  2961. if (isSolidHLine(grid(x - 1, y)) && isSolidVLine(grid(x + 1, y - 1))) {
  2962. grid.setUsed(x - 1, y); grid.setUsed(x, y); grid.setUsed(x + 1, y - 1);
  2963. pathSet.insert(new Path(Vec2(x - 1, y), Vec2(x + 1, y - 1),
  2964. Vec2(x + 1.1, y), Vec2(x + 1, y - 1)));
  2965. }
  2966. // |
  2967. // '-
  2968. if (isSolidHLine(grid(x + 1, y)) && isSolidVLine(grid(x - 1, y - 1))) {
  2969. grid.setUsed(x - 1, y - 1); grid.setUsed(x, y); grid.setUsed(x + 1, y);
  2970. pathSet.insert(new Path(Vec2(x + 1, y), Vec2(x - 1, y - 1),
  2971. Vec2(x - 1.1, y), Vec2(x - 1, y - 1)));
  2972. }
  2973. }
  2974. } // for x
  2975. } // for y
  2976. // Find low horizontal lines marked with underscores. These
  2977. // are so simple compared to the other cases that we process
  2978. // them directly here without a helper function. Process these
  2979. // from top to bottom and left to right so that we can read
  2980. // them in a single sweep.
  2981. //
  2982. // Exclude the special case of double underscores going right
  2983. // into an ASCII character, which could be a source code
  2984. // identifier such as __FILE__ embedded in the diagram.
  2985. for (var y = 0; y < grid.height; ++y) {
  2986. for (var x = 0; x < grid.width - 2; ++x) {
  2987. var lt = grid(x - 1, y);
  2988. if ((grid(x, y) === '_') && (grid(x + 1, y) === '_') &&
  2989. (! isASCIILetter(grid(x + 2, y)) || (lt === '_')) &&
  2990. (! isASCIILetter(lt) || (grid(x + 2, y) === '_'))) {
  2991. var ltlt = grid(x - 2, y);
  2992. var A = Vec2(x - 0.5, y + 0.5);
  2993. if ((lt === '|') || (grid(x - 1, y + 1) === '|') ||
  2994. (lt === '.') || (grid(x - 1, y + 1) === "'")) {
  2995. // Extend to meet adjacent vertical
  2996. A.x -= 0.5;
  2997. // Very special case of overrunning into the side of a curve,
  2998. // needed for logic gate diagrams
  2999. if ((lt === '.') &&
  3000. ((ltlt === '-') ||
  3001. (ltlt === '.')) &&
  3002. (grid(x - 2, y + 1) === '(')) {
  3003. A.x -= 0.5;
  3004. }
  3005. } else if (lt === '/') {
  3006. A.x -= 1.0;
  3007. }
  3008. // Detect overrun of a tight double curve
  3009. if ((lt === '(') && (ltlt === '(') &&
  3010. (grid(x, y + 1) === "'") && (grid(x, y - 1) === '.')) {
  3011. A.x += 0.5;
  3012. }
  3013. lt = ltlt = undefined;
  3014. do { grid.setUsed(x, y); ++x; } while (grid(x, y) === '_');
  3015. var B = Vec2(x - 0.5, y + 0.5);
  3016. var c = grid(x, y);
  3017. var rt = grid(x + 1, y);
  3018. var dn = grid(x, y + 1);
  3019. if ((c === '|') || (dn === '|') || (c === '.') || (dn === "'")) {
  3020. // Extend to meet adjacent vertical
  3021. B.x += 0.5;
  3022. // Very special case of overrunning into the side of a curve,
  3023. // needed for logic gate diagrams
  3024. if ((c === '.') &&
  3025. ((rt === '-') || (rt === '.')) &&
  3026. (grid(x + 1, y + 1) === ')')) {
  3027. B.x += 0.5;
  3028. }
  3029. } else if ((c === '\\')) {
  3030. B.x += 1.0;
  3031. }
  3032. // Detect overrun of a tight double curve
  3033. if ((c === ')') && (rt === ')') && (grid(x - 1, y + 1) === "'") && (grid(x - 1, y - 1) === '.')) {
  3034. B.x += -0.5;
  3035. }
  3036. pathSet.insert(new Path(A, B));
  3037. }
  3038. } // for x
  3039. } // for y
  3040. } // findPaths
  3041. function findDecorations(grid, pathSet, decorationSet) {
  3042. function isEmptyOrVertex(c) { return (c === ' ') || /[^a-zA-Z0-9]|[ov]/.test(c); }
  3043. function isLetter(c) { var x = c.toUpperCase().charCodeAt(0); return (x > 64) && (x < 91); }
  3044. /** Is the point in the center of these values on a line? Allow points that are vertically
  3045. adjacent but not horizontally--they wouldn't fit anyway, and might be text. */
  3046. function onLine(up, dn, lt, rt) {
  3047. return ((isEmptyOrVertex(dn) || isPoint(dn)) &&
  3048. (isEmptyOrVertex(up) || isPoint(up)) &&
  3049. isEmptyOrVertex(rt) &&
  3050. isEmptyOrVertex(lt));
  3051. }
  3052. for (var x = 0; x < grid.width; ++x) {
  3053. for (var j = 0; j < grid.height; ++j) {
  3054. var c = grid(x, j);
  3055. var y = j;
  3056. if (isJump(c)) {
  3057. // Ensure that this is really a jump and not a stray character
  3058. if (pathSet.downEndsAt(x, y - 0.5) &&
  3059. pathSet.upEndsAt(x, y + 0.5)) {
  3060. decorationSet.insert(x, y, c);
  3061. grid.setUsed(x, y);
  3062. }
  3063. } else if (isPoint(c)) {
  3064. var up = grid(x, y - 1);
  3065. var dn = grid(x, y + 1);
  3066. var lt = grid(x - 1, y);
  3067. var rt = grid(x + 1, y);
  3068. var llt = grid(x - 2, y);
  3069. var rrt = grid(x + 2, y);
  3070. if (pathSet.rightEndsAt(x - 1, y) || // Must be at the end of a line...
  3071. pathSet.leftEndsAt(x + 1, y) || // or completely isolated NSEW
  3072. pathSet.downEndsAt(x, y - 1) ||
  3073. pathSet.upEndsAt(x, y + 1) ||
  3074. pathSet.upEndsAt(x, y) || // For points on vertical lines
  3075. pathSet.downEndsAt(x, y) || // that are surrounded by other characters
  3076. onLine(up, dn, lt, rt)) {
  3077. decorationSet.insert(x, y, c);
  3078. grid.setUsed(x, y);
  3079. }
  3080. } else if (isGray(c)) {
  3081. decorationSet.insert(x, y, c);
  3082. grid.setUsed(x, y);
  3083. } else if (isTri(c)) {
  3084. decorationSet.insert(x, y, c);
  3085. grid.setUsed(x, y);
  3086. } else { // Arrow heads
  3087. // If we find one, ensure that it is really an
  3088. // arrow head and not a stray character by looking
  3089. // for a connecting line.
  3090. var dx = 0;
  3091. if ((c === '>') && (pathSet.rightEndsAt(x, y) ||
  3092. pathSet.horizontalPassesThrough(x, y))) {
  3093. if (isPoint(grid(x + 1, y))) {
  3094. // Back up if connecting to a point so as to not
  3095. // overlap it
  3096. dx = -0.5;
  3097. }
  3098. decorationSet.insert(x + dx, y, '>', 0);
  3099. grid.setUsed(x, y);
  3100. } else if ((c === '<') && (pathSet.leftEndsAt(x, y) ||
  3101. pathSet.horizontalPassesThrough(x, y))) {
  3102. if (isPoint(grid(x - 1, y))) {
  3103. // Back up if connecting to a point so as to not
  3104. // overlap it
  3105. dx = 0.5;
  3106. }
  3107. decorationSet.insert(x + dx, y, '>', 180);
  3108. grid.setUsed(x, y);
  3109. } else if (c === '^') {
  3110. // Because of the aspect ratio, we need to look
  3111. // in two slots for the end of the previous line
  3112. if (pathSet.upEndsAt(x, y - 0.5)) {
  3113. decorationSet.insert(x, y - 0.5, '>', 270);
  3114. grid.setUsed(x, y);
  3115. } else if (pathSet.upEndsAt(x, y)) {
  3116. decorationSet.insert(x, y, '>', 270);
  3117. grid.setUsed(x, y);
  3118. } else if (pathSet.diagonalUpEndsAt(x + 0.5, y - 0.5)) {
  3119. decorationSet.insert(x + 0.5, y - 0.5, '>', 270 + DIAGONAL_ANGLE);
  3120. grid.setUsed(x, y);
  3121. } else if (pathSet.diagonalUpEndsAt(x + 0.25, y - 0.25)) {
  3122. decorationSet.insert(x + 0.25, y - 0.25, '>', 270 + DIAGONAL_ANGLE);
  3123. grid.setUsed(x, y);
  3124. } else if (pathSet.diagonalUpEndsAt(x, y)) {
  3125. decorationSet.insert(x, y, '>', 270 + DIAGONAL_ANGLE);
  3126. grid.setUsed(x, y);
  3127. } else if (pathSet.backDiagonalUpEndsAt(x, y)) {
  3128. decorationSet.insert(x, y, c, 270 - DIAGONAL_ANGLE);
  3129. grid.setUsed(x, y);
  3130. } else if (pathSet.backDiagonalUpEndsAt(x - 0.5, y - 0.5)) {
  3131. decorationSet.insert(x - 0.5, y - 0.5, c, 270 - DIAGONAL_ANGLE);
  3132. grid.setUsed(x, y);
  3133. } else if (pathSet.backDiagonalUpEndsAt(x - 0.25, y - 0.25)) {
  3134. decorationSet.insert(x - 0.25, y - 0.25, c, 270 - DIAGONAL_ANGLE);
  3135. grid.setUsed(x, y);
  3136. } else if (pathSet.verticalPassesThrough(x, y)) {
  3137. // Only try this if all others failed
  3138. decorationSet.insert(x, y - 0.5, '>', 270);
  3139. grid.setUsed(x, y);
  3140. }
  3141. } else if (c === 'v') {
  3142. if (pathSet.downEndsAt(x, y + 0.5)) {
  3143. decorationSet.insert(x, y + 0.5, '>', 90);
  3144. grid.setUsed(x, y);
  3145. } else if (pathSet.downEndsAt(x, y)) {
  3146. decorationSet.insert(x, y, '>', 90);
  3147. grid.setUsed(x, y);
  3148. } else if (pathSet.diagonalDownEndsAt(x, y)) {
  3149. decorationSet.insert(x, y, '>', 90 + DIAGONAL_ANGLE);
  3150. grid.setUsed(x, y);
  3151. } else if (pathSet.diagonalDownEndsAt(x - 0.5, y + 0.5)) {
  3152. decorationSet.insert(x - 0.5, y + 0.5, '>', 90 + DIAGONAL_ANGLE);
  3153. grid.setUsed(x, y);
  3154. } else if (pathSet.diagonalDownEndsAt(x - 0.25, y + 0.25)) {
  3155. decorationSet.insert(x - 0.25, y + 0.25, '>', 90 + DIAGONAL_ANGLE);
  3156. grid.setUsed(x, y);
  3157. } else if (pathSet.backDiagonalDownEndsAt(x, y)) {
  3158. decorationSet.insert(x, y, '>', 90 - DIAGONAL_ANGLE);
  3159. grid.setUsed(x, y);
  3160. } else if (pathSet.backDiagonalDownEndsAt(x + 0.5, y + 0.5)) {
  3161. decorationSet.insert(x + 0.5, y + 0.5, '>', 90 - DIAGONAL_ANGLE);
  3162. grid.setUsed(x, y);
  3163. } else if (pathSet.backDiagonalDownEndsAt(x + 0.25, y + 0.25)) {
  3164. decorationSet.insert(x + 0.25, y + 0.25, '>', 90 - DIAGONAL_ANGLE);
  3165. grid.setUsed(x, y);
  3166. } else if (pathSet.verticalPassesThrough(x, y)) {
  3167. // Only try this if all others failed
  3168. decorationSet.insert(x, y + 0.5, '>', 90);
  3169. grid.setUsed(x, y);
  3170. }
  3171. } // arrow heads
  3172. } // decoration type
  3173. } // y
  3174. } // x
  3175. } // findArrowHeads
  3176. var grid = makeGrid(diagramString);
  3177. var pathSet = new PathSet();
  3178. var decorationSet = new DecorationSet();
  3179. findPaths(grid, pathSet);
  3180. findDecorations(grid, pathSet, decorationSet);
  3181. var svg = '<svg class="diagram" xmlns="http://www.w3.org/2000/svg" version="1.1" height="' +
  3182. ((grid.height + 1) * SCALE * ASPECT) + '" width="' + ((grid.width + 1) * SCALE) + '"';
  3183. if (alignmentHint === 'floatleft') {
  3184. svg += ' style="float:left;margin:15px 30px 15px 0;"';
  3185. } else if (alignmentHint === 'floatright') {
  3186. svg += ' style="float:right;margin:15px 0 15px 30px;"';
  3187. } else if (alignmentHint === 'center') {
  3188. svg += ' style="margin:0 auto 0 auto;"';
  3189. }
  3190. svg += '><g transform="translate(' + Vec2(1, 1) + ')">\n';
  3191. if (DEBUG_SHOW_GRID) {
  3192. svg += '<g style="opacity:0.1">\n';
  3193. for (var x = 0; x < grid.width; ++x) {
  3194. for (var y = 0; y < grid.height; ++y) {
  3195. svg += '<rect x="' + ((x - 0.5) * SCALE + 1) + '" + y="' + ((y - 0.5) * SCALE * ASPECT + 2) + '" width="' + (SCALE - 2) + '" height="' + (SCALE * ASPECT - 2) + '" style="fill:';
  3196. if (grid.isUsed(x, y)) {
  3197. svg += 'red;';
  3198. } else if (grid(x, y) === ' ') {
  3199. svg += 'gray;opacity:0.05';
  3200. } else {
  3201. svg += 'blue;';
  3202. }
  3203. svg += '"/>\n';
  3204. }
  3205. }
  3206. svg += '</g>\n';
  3207. }
  3208. svg += pathSet.toSVG();
  3209. svg += decorationSet.toSVG();
  3210. // Convert any remaining characters
  3211. if (! DEBUG_HIDE_PASSTHROUGH) {
  3212. svg += '<g transform="translate(0,0)">';
  3213. for (var y = 0; y < grid.height; ++y) {
  3214. for (var x = 0; x < grid.width; ++x) {
  3215. var c = grid(x, y);
  3216. if (/[\u2B22\u2B21]/.test(c)) {
  3217. // Enlarge hexagons so that they fill a grid
  3218. svg += '<text text-anchor="middle" x="' + (x * SCALE) + '" y="' + (4 + y * SCALE * ASPECT) + '" style="font-size:20.5px">' + escapeHTMLEntities(c) + '</text>';
  3219. } else if ((c !== ' ') && ! grid.isUsed(x, y)) {
  3220. svg += '<text text-anchor="middle" x="' + (x * SCALE) + '" y="' + (4 + y * SCALE * ASPECT) + '">' + escapeHTMLEntities(c) + '</text>';
  3221. } // if
  3222. } // y
  3223. } // x
  3224. svg += '</g>';
  3225. }
  3226. if (DEBUG_SHOW_SOURCE) {
  3227. // Offset the characters a little for easier viewing
  3228. svg += '<g transform="translate(2,2)">\n';
  3229. for (var x = 0; x < grid.width; ++x) {
  3230. for (var y = 0; y < grid.height; ++y) {
  3231. var c = grid(x, y);
  3232. if (c !== ' ') {
  3233. svg += '<text text-anchor="middle" x="' + (x * SCALE) + '" y="' + (4 + y * SCALE * ASPECT) + '" style="fill:#F00;font-family:Menlo,monospace;font-size:12px;text-align:center">' + escapeHTMLEntities(c) + '</text>';
  3234. } // if
  3235. } // y
  3236. } // x
  3237. svg += '</g>';
  3238. } // if
  3239. svg += '</g></svg>';
  3240. svg = svg.rp(new RegExp(HIDE_O, 'g'), 'o');
  3241. return svg;
  3242. }
  3243. /* xcode.min.js modified */
  3244. var HIGHLIGHT_STYLESHEET =
  3245. "<style>.hljs{display:block;overflow-x:auto;padding:0.5em;background:#fff;color:#000;-webkit-text-size-adjust:none}"+
  3246. ".hljs-comment{color:#006a00}" +
  3247. ".hljs-keyword{color:#02E}" +
  3248. ".hljs-literal,.nginx .hljs-title{color:#aa0d91}" +
  3249. ".method,.hljs-list .hljs-title,.hljs-tag .hljs-title,.setting .hljs-value,.hljs-winutils,.tex .hljs-command,.http .hljs-title,.hljs-request,.hljs-status,.hljs-name{color:#008}" +
  3250. ".hljs-envvar,.tex .hljs-special{color:#660}" +
  3251. ".hljs-string{color:#c41a16}" +
  3252. ".hljs-tag .hljs-value,.hljs-cdata,.hljs-filter .hljs-argument,.hljs-attr_selector,.apache .hljs-cbracket,.hljs-date,.hljs-regexp{color:#080}" +
  3253. ".hljs-sub .hljs-identifier,.hljs-pi,.hljs-tag,.hljs-tag .hljs-keyword,.hljs-decorator,.ini .hljs-title,.hljs-shebang,.hljs-prompt,.hljs-hexcolor,.hljs-rule .hljs-value,.hljs-symbol,.hljs-symbol .hljs-string,.hljs-number,.css .hljs-function,.hljs-function .hljs-title,.coffeescript .hljs-attribute{color:#A0C}" +
  3254. ".hljs-function .hljs-title{font-weight:bold;color:#000}" +
  3255. ".hljs-class .hljs-title,.smalltalk .hljs-class,.hljs-type,.hljs-typename,.hljs-tag .hljs-attribute,.hljs-doctype,.hljs-class .hljs-id,.hljs-built_in,.setting,.hljs-params,.clojure .hljs-attribute{color:#5c2699}" +
  3256. ".hljs-variable{color:#3f6e74}" +
  3257. ".css .hljs-tag,.hljs-rule .hljs-property,.hljs-pseudo,.hljs-subst{color:#000}" +
  3258. ".css .hljs-class,.css .hljs-id{color:#9b703f}" +
  3259. ".hljs-value .hljs-important{color:#ff7700;font-weight:bold}" +
  3260. ".hljs-rule .hljs-keyword{color:#c5af75}" +
  3261. ".hljs-annotation,.apache .hljs-sqbracket,.nginx .hljs-built_in{color:#9b859d}" +
  3262. ".hljs-preprocessor,.hljs-preprocessor *,.hljs-pragma{color:#643820}" +
  3263. ".tex .hljs-formula{background-color:#eee;font-style:italic}" +
  3264. ".diff .hljs-header,.hljs-chunk{color:#808080;font-weight:bold}" +
  3265. ".diff .hljs-change{background-color:#bccff9}" +
  3266. ".hljs-addition{background-color:#baeeba}" +
  3267. ".hljs-deletion{background-color:#ffc8bd}" +
  3268. ".hljs-comment .hljs-doctag{font-weight:bold}" +
  3269. ".method .hljs-id{color:#000}</style>";
  3270. function isMarkdeepScriptName(str) { return str.search(/markdeep\S*?\.js$/i) !== -1; }
  3271. function toArray(list) { return Array.prototype.slice.call(list); }
  3272. // Intentionally uninitialized global variable used to detect
  3273. // recursive invocations
  3274. if (! window.alreadyProcessedMarkdeep) {
  3275. window.alreadyProcessedMarkdeep = true;
  3276. // Detect the noformat argument to the URL
  3277. var noformat = (window.location.href.search(/\?.*noformat.*/i) !== -1);
  3278. // Export relevant methods
  3279. window.markdeep = Object.freeze({
  3280. format: markdeepToHTML,
  3281. formatDiagram: diagramToSVG,
  3282. stylesheet: function() {
  3283. return STYLESHEET + sectionNumberingStylesheet() + HIGHLIGHT_STYLESHEET;
  3284. }
  3285. });
  3286. var MATHJAX_CONFIG ='<script type="text/x-mathjax-config">MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });</script>' +
  3287. '<span style="display:none">' +
  3288. // Custom definitions (NC == \newcommand)
  3289. '$$NC{\\n}{\\hat{n}}NC{\\w}{\\hat{\\omega}}NC{\\wi}{\\w_\\mathrm{i}}NC{\\wo}{\\w_\\mathrm{o}}NC{\\wh}{\\w_\\mathrm{h}}NC{\\Li}{L_\\mathrm{i}}NC{\\Lo}{L_\\mathrm{o}}NC{\\Le}{L_\\mathrm{e}}NC{\\Lr}{L_\\mathrm{r}}NC{\\Lt}{L_\\mathrm{t}}NC{\\O}{\\mathrm{O}}NC{\\degrees}{{^{\\large\\circ}}}NC{\\T}{\\mathsf{T}}NC{\\mathset}[1]{\\mathbb{#1}}NC{\\Real}{\\mathset{R}}NC{\\Integer}{\\mathset{Z}}NC{\\Boolean}{\\mathset{B}}NC{\\Complex}{\\mathset{C}}NC{\\un}[1]{\\,\\mathrm{#1}}$$\n'.rp(/NC/g, '\\newcommand') +
  3290. '</span>\n'
  3291. var MATHJAX_URL = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
  3292. function loadMathJax() {
  3293. // Dynamically load mathjax
  3294. var script = document.createElement("script");
  3295. script.type = "text/javascript";
  3296. script.src = MATHJAX_URL;
  3297. document.getElementsByTagName("head")[0].appendChild(script);
  3298. }
  3299. function needsMathJax(html) {
  3300. // Need MathJax if $$ ... $$, \( ... \), or \begin{
  3301. return option('detectMath') &&
  3302. ((html.search(/(?:\$\$[\s\S]+\$\$)|(?:\\begin{)/m) !== -1) ||
  3303. (html.search(/\\\(.*\\\)/) !== -1));
  3304. }
  3305. var mode = option('mode');
  3306. switch (mode) {
  3307. case 'script':
  3308. // Nothing to do
  3309. return;
  3310. case 'html':
  3311. case 'doxygen':
  3312. toArray(document.getElementsByClassName('diagram')).concat(toArray(document.getElementsByTagName('diagram'))).forEach(
  3313. function (element) {
  3314. var src = unescapeHTMLEntities(element.innerHTML);
  3315. // Remove the first and last string (which probably
  3316. // had the pre or diagram tag as part of them) if they are
  3317. // empty except for whitespace.
  3318. src = src.rp(/(:?^[ \t]*\n)|(:?\n[ \t]*)$/g, '');
  3319. if (mode === 'doxygen') {
  3320. // Undo Doxygen's &ndash and &mdash, which are impossible to
  3321. // detect once the browser has parsed the document
  3322. src = src.rp(new RegExp('\u2013', 'g'), '--');
  3323. src = src.rp(new RegExp('\u2014', 'g'), '---');
  3324. // Undo Doxygen's links within the diagram because they throw off spacing
  3325. src = src.rp(/<a class="el" .*>(.*)<\/a>/g, '$1');
  3326. }
  3327. element.outerHTML = '<center class="md">' + diagramToSVG(removeLeadingSpace(src), '') + '</center>';
  3328. });
  3329. var anyNeedsMathJax = false;
  3330. toArray(document.getElementsByClassName('markdeep')).concat(toArray(document.getElementsByTagName('markdeep'))).forEach(
  3331. function (src) {
  3332. var dst = document.createElement('div');
  3333. var html = markdeepToHTML(removeLeadingSpace(unescapeHTMLEntities(src.innerHTML)), true);
  3334. anyNeedsMathJax = anyNeedsMathJax || needsMathJax(html);
  3335. dst.innerHTML = html;
  3336. src.parentNode.replaceChild(dst, src);
  3337. });
  3338. // Include our stylesheet even if there are no MARKDEEP tags, but do not include the BODY_STYLESHEET.
  3339. document.head.innerHTML = window.markdeep.stylesheet() + document.head.innerHTML + (anyNeedsMathJax ? MATHJAX_CONFIG : '');
  3340. loadMathJax();
  3341. return;
  3342. }
  3343. // The following is Morgan's massive hack for allowing browsers to
  3344. // directly parse Markdown from what appears to be a text file, but is
  3345. // actually an intentionally malformed HTML file.
  3346. // In order to be able to show what source files look like, the
  3347. // noformat argument may be supplied.
  3348. if (! noformat) {
  3349. // Remove any recursive references to this script so that we don't trigger the cost of
  3350. // recursive *loading*. (The alreadyProcessedMarkdeep variable will prevent recursive
  3351. // *execution*.) We allow other scripts to pass through.
  3352. toArray(document.getElementsByTagName('script')).forEach(function(node) {
  3353. if (isMarkdeepScriptName(node.src)) {
  3354. node.parentNode.removeChild(node);
  3355. }
  3356. });
  3357. // Hide the body while formatting
  3358. document.body.style.visibility = 'hidden';
  3359. }
  3360. var source = nodeToMarkdeepSource(document.body);
  3361. if (noformat) {
  3362. // Abort processing.
  3363. source = source.rp(/<!-- Markdeep:.+$/gm, '') + MARKDEEP_LINE;
  3364. // Escape the <> (not ampersand) that we just added
  3365. source = source.rp(/</g, '&lt;').rp(/>/g, '&gt;');
  3366. // Replace the Markdeep line itself so that ?noformat examples have a valid line to copy
  3367. document.body.innerHTML = entag('pre', source);
  3368. var fallbackNodes = document.getElementsByClassName('fallback');
  3369. for (var i = 0; i < fallbackNodes.length; ++i) {
  3370. fallbackNodes[i].remove();
  3371. }
  3372. return;
  3373. }
  3374. var markdeepProcessor = function() {
  3375. // Recompute the source text from the current version of the document
  3376. var source = nodeToMarkdeepSource(document.body);
  3377. source = unescapeHTMLEntities(source);
  3378. var markdeepHTML = markdeepToHTML(source, false);
  3379. // console.log(markdeepHTML); // Final processed source
  3380. var needMathJax = needsMathJax(markdeepHTML);
  3381. if (needMathJax) {
  3382. markdeepHTML = MATHJAX_CONFIG + markdeepHTML;
  3383. }
  3384. markdeepHTML += MARKDEEP_FOOTER;
  3385. // Replace the document. If using MathJax, include the custom Markdeep definitions
  3386. var longDocument = source.length > 1000;
  3387. var head = BODY_STYLESHEET + STYLESHEET + sectionNumberingStylesheet() + HIGHLIGHT_STYLESHEET;
  3388. if (longDocument) {
  3389. // Add more spacing before the title in a long document
  3390. head += entag('style', 'div.title { padding-top: 40px; } div.afterTitles { height: 15px; }');
  3391. }
  3392. if (window.location.href.search(/\?.*export.*/i) !== -1) {
  3393. // Export mode
  3394. var text = '<meta charset="UTF-8"><meta http-equiv="content-type" content="text/html;charset=UTF-8">' + head + document.head.innerHTML + markdeepHTML;
  3395. if (needMathJax) {
  3396. // Dynamically load mathjax
  3397. text += '<script src="' + MATHJAX_URL +'"></script>';
  3398. }
  3399. document.body.innerHTML = entag('code', escapeHTMLEntities(text));
  3400. } else {
  3401. document.head.innerHTML = '<meta charset="UTF-8"><meta http-equiv="content-type" content="text/html;charset=UTF-8">' + head + document.head.innerHTML;
  3402. document.body.innerHTML = markdeepHTML;
  3403. if (needMathJax) { loadMathJax(); }
  3404. }
  3405. document.body.style.visibility = 'visible';
  3406. };
  3407. ///////////// INSERT command processing
  3408. // Helper function for use by children
  3409. function sendContentsToMyParent() {
  3410. // console.log(location.pathname + " sent message to parent");
  3411. // Send the document contents after the childFrame replaced itself
  3412. // (not the source variable captured when this function was defined!)
  3413. parent.postMessage(myID + '=' + document.body.innerHTML, '*');
  3414. }
  3415. // Strip the filename from the url, if there is one (and it is a string)
  3416. function removeFilename(url) {
  3417. return url && url.ss(0, url.lastIndexOf('/') + 1);
  3418. }
  3419. var myURLParse = /([^?]+)(?:\?id=(inc\d+)&p=([^&]+))?/.exec(location.href);
  3420. var myBase = removeFilename(myURLParse[1]);
  3421. var myID = myURLParse[2];
  3422. var parentBase = removeFilename(myURLParse[3] && decodeURIComponent(myURLParse[3]));
  3423. var childFrameStyle = 'display:none';
  3424. var includeCounter = 0;
  3425. var IAmAChild = myID; // !== undefined
  3426. var IAmAParent = false;
  3427. var numIncludeChildrenLeft = 0;
  3428. var messageCallback = function (event) {
  3429. // Parse the message. Ensure that it is for the Markdeep/include.js system.
  3430. var childID = false;
  3431. var childBody = event.data.substring && event.data.replace(/^(inc\d+)=/, function (match, a) {
  3432. childID = a;
  3433. return '';
  3434. });
  3435. if (childID) {
  3436. // This message event was for the Markdeep/include.js system
  3437. //console.log(location.href + ' received a message from child ' + childID);
  3438. // Replace the corresponding node's contents
  3439. var childFrame = document.getElementById(childID);
  3440. childFrame.outerHTML = '\n' + childBody + '\n';
  3441. --numIncludeChildrenLeft;
  3442. // console.log(window.location.pathname, 'numIncludeChildrenLeft = ' + numIncludeChildrenLeft);
  3443. if (numIncludeChildrenLeft <= 0) {
  3444. if (IAmAChild) {
  3445. //console.log("Intermediate node " + location.pathname + " sending to parent");
  3446. sendContentsToMyParent();
  3447. } else {
  3448. // The entire document is complete, so run the markdeep processor
  3449. // as soon as the document has recovered from our replacements
  3450. setTimeout(markdeepProcessor, 0);
  3451. }
  3452. }
  3453. }
  3454. };
  3455. source = source.rp(/(?:^|\s)\(insert[ \t]+(\S+\.\S*)[ \t]+here\)\s/g, function(match, src) {
  3456. if (numIncludeChildrenLeft === 0) {
  3457. // This is the first child observed. Prepare to receive messages from the
  3458. // embedded children.
  3459. IAmAParent = true;
  3460. addEventListener("message", messageCallback);
  3461. }
  3462. ++numIncludeChildrenLeft;
  3463. // console.log(window.location.pathname, 'numIncludeChildrenLeft = ' + numIncludeChildrenLeft);
  3464. // Replace this tag with a frame that loads the document. Once loaded, it will
  3465. // send a message with its contents for use as a replacement.
  3466. var childID = 'inc' + (++includeCounter);
  3467. return '<iframe src="' + src + '?id=' + childID + '&p=' + encodeURIComponent(myBase) +
  3468. '"id="' + childID + '"style="' + childFrameStyle + '" content="text/html;charset=UTF-8"></iframe>';
  3469. });
  3470. // console.log("after insert: "+ source);
  3471. if (IAmAParent) {
  3472. // I'm waiting on children, so don't run the full processor yet,
  3473. // but do substitute the iframe code so that it can launch.
  3474. document.body.innerHTML = source;
  3475. } else if (IAmAChild) {
  3476. // I'm a child and not a parent, so trigger the send now
  3477. // console.log("Leaf node " + location.pathname + " sending to parent");
  3478. sendContentsToMyParent();
  3479. } else {
  3480. // No includes. Run markdeep processing after the rest of this file parses
  3481. // console.log("non-parent, non-child Parent scheduling markdeepProcessor");
  3482. setTimeout(markdeepProcessor, 0);
  3483. }
  3484. }
  3485. })();