notes.mjs 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548
  1. var G = Object.defineProperty;
  2. var tt = (l, n, e) => n in l ? G(l, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[n] = e;
  3. var D = (l, n, e) => (tt(l, typeof n != "symbol" ? n + "" : n, e), e);
  4. const et = `<!--
  5. NOTE: You need to build the notes plugin after making changes to this file.
  6. -->
  7. <html lang="en">
  8. <head>
  9. <meta charset="utf-8">
  10. <title>reveal.js - Speaker View</title>
  11. <style>
  12. body {
  13. font-family: Helvetica;
  14. font-size: 18px;
  15. }
  16. #current-slide,
  17. #upcoming-slide,
  18. #speaker-controls {
  19. padding: 6px;
  20. box-sizing: border-box;
  21. -moz-box-sizing: border-box;
  22. }
  23. #current-slide iframe,
  24. #upcoming-slide iframe {
  25. width: 100%;
  26. height: 100%;
  27. border: 1px solid #ddd;
  28. }
  29. #current-slide .label,
  30. #upcoming-slide .label {
  31. position: absolute;
  32. top: 10px;
  33. left: 10px;
  34. z-index: 2;
  35. }
  36. #connection-status {
  37. position: absolute;
  38. top: 0;
  39. left: 0;
  40. width: 100%;
  41. height: 100%;
  42. z-index: 20;
  43. padding: 30% 20% 20% 20%;
  44. font-size: 18px;
  45. color: #222;
  46. background: #fff;
  47. text-align: center;
  48. box-sizing: border-box;
  49. line-height: 1.4;
  50. }
  51. .overlay-element {
  52. height: 34px;
  53. line-height: 34px;
  54. padding: 0 10px;
  55. text-shadow: none;
  56. background: rgba( 220, 220, 220, 0.8 );
  57. color: #222;
  58. font-size: 14px;
  59. }
  60. .overlay-element.interactive:hover {
  61. background: rgba( 220, 220, 220, 1 );
  62. }
  63. #current-slide {
  64. position: absolute;
  65. width: 60%;
  66. height: 100%;
  67. top: 0;
  68. left: 0;
  69. padding-right: 0;
  70. }
  71. #upcoming-slide {
  72. position: absolute;
  73. width: 40%;
  74. height: 40%;
  75. right: 0;
  76. top: 0;
  77. }
  78. /* Speaker controls */
  79. #speaker-controls {
  80. position: absolute;
  81. top: 40%;
  82. right: 0;
  83. width: 40%;
  84. height: 60%;
  85. overflow: auto;
  86. font-size: 18px;
  87. }
  88. .speaker-controls-time.hidden,
  89. .speaker-controls-notes.hidden {
  90. display: none;
  91. }
  92. .speaker-controls-time .label,
  93. .speaker-controls-pace .label,
  94. .speaker-controls-notes .label {
  95. text-transform: uppercase;
  96. font-weight: normal;
  97. font-size: 0.66em;
  98. color: #666;
  99. margin: 0;
  100. }
  101. .speaker-controls-time, .speaker-controls-pace {
  102. border-bottom: 1px solid rgba( 200, 200, 200, 0.5 );
  103. margin-bottom: 10px;
  104. padding: 10px 16px;
  105. padding-bottom: 20px;
  106. cursor: pointer;
  107. }
  108. .speaker-controls-time .reset-button {
  109. opacity: 0;
  110. float: right;
  111. color: #666;
  112. text-decoration: none;
  113. }
  114. .speaker-controls-time:hover .reset-button {
  115. opacity: 1;
  116. }
  117. .speaker-controls-time .timer,
  118. .speaker-controls-time .clock {
  119. width: 50%;
  120. }
  121. .speaker-controls-time .timer,
  122. .speaker-controls-time .clock,
  123. .speaker-controls-time .pacing .hours-value,
  124. .speaker-controls-time .pacing .minutes-value,
  125. .speaker-controls-time .pacing .seconds-value {
  126. font-size: 1.9em;
  127. }
  128. .speaker-controls-time .timer {
  129. float: left;
  130. }
  131. .speaker-controls-time .clock {
  132. float: right;
  133. text-align: right;
  134. }
  135. .speaker-controls-time span.mute {
  136. opacity: 0.3;
  137. }
  138. .speaker-controls-time .pacing-title {
  139. margin-top: 5px;
  140. }
  141. .speaker-controls-time .pacing.ahead {
  142. color: blue;
  143. }
  144. .speaker-controls-time .pacing.on-track {
  145. color: green;
  146. }
  147. .speaker-controls-time .pacing.behind {
  148. color: red;
  149. }
  150. .speaker-controls-notes {
  151. padding: 10px 16px;
  152. }
  153. .speaker-controls-notes .value {
  154. margin-top: 5px;
  155. line-height: 1.4;
  156. font-size: 1.2em;
  157. }
  158. /* Layout selector */
  159. #speaker-layout {
  160. position: absolute;
  161. top: 10px;
  162. right: 10px;
  163. color: #222;
  164. z-index: 10;
  165. }
  166. #speaker-layout select {
  167. position: absolute;
  168. width: 100%;
  169. height: 100%;
  170. top: 0;
  171. left: 0;
  172. border: 0;
  173. box-shadow: 0;
  174. cursor: pointer;
  175. opacity: 0;
  176. font-size: 1em;
  177. background-color: transparent;
  178. -moz-appearance: none;
  179. -webkit-appearance: none;
  180. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  181. }
  182. #speaker-layout select:focus {
  183. outline: none;
  184. box-shadow: none;
  185. }
  186. .clear {
  187. clear: both;
  188. }
  189. /* Speaker layout: Wide */
  190. body[data-speaker-layout="wide"] #current-slide,
  191. body[data-speaker-layout="wide"] #upcoming-slide {
  192. width: 50%;
  193. height: 45%;
  194. padding: 6px;
  195. }
  196. body[data-speaker-layout="wide"] #current-slide {
  197. top: 0;
  198. left: 0;
  199. }
  200. body[data-speaker-layout="wide"] #upcoming-slide {
  201. top: 0;
  202. left: 50%;
  203. }
  204. body[data-speaker-layout="wide"] #speaker-controls {
  205. top: 45%;
  206. left: 0;
  207. width: 100%;
  208. height: 50%;
  209. font-size: 1.25em;
  210. }
  211. /* Speaker layout: Tall */
  212. body[data-speaker-layout="tall"] #current-slide,
  213. body[data-speaker-layout="tall"] #upcoming-slide {
  214. width: 45%;
  215. height: 50%;
  216. padding: 6px;
  217. }
  218. body[data-speaker-layout="tall"] #current-slide {
  219. top: 0;
  220. left: 0;
  221. }
  222. body[data-speaker-layout="tall"] #upcoming-slide {
  223. top: 50%;
  224. left: 0;
  225. }
  226. body[data-speaker-layout="tall"] #speaker-controls {
  227. padding-top: 40px;
  228. top: 0;
  229. left: 45%;
  230. width: 55%;
  231. height: 100%;
  232. font-size: 1.25em;
  233. }
  234. /* Speaker layout: Notes only */
  235. body[data-speaker-layout="notes-only"] #current-slide,
  236. body[data-speaker-layout="notes-only"] #upcoming-slide {
  237. display: none;
  238. }
  239. body[data-speaker-layout="notes-only"] #speaker-controls {
  240. padding-top: 40px;
  241. top: 0;
  242. left: 0;
  243. width: 100%;
  244. height: 100%;
  245. font-size: 1.25em;
  246. }
  247. @media screen and (max-width: 1080px) {
  248. body[data-speaker-layout="default"] #speaker-controls {
  249. font-size: 16px;
  250. }
  251. }
  252. @media screen and (max-width: 900px) {
  253. body[data-speaker-layout="default"] #speaker-controls {
  254. font-size: 14px;
  255. }
  256. }
  257. @media screen and (max-width: 800px) {
  258. body[data-speaker-layout="default"] #speaker-controls {
  259. font-size: 12px;
  260. }
  261. }
  262. </style>
  263. </head>
  264. <body>
  265. <div id="connection-status">Loading speaker view...</div>
  266. <div id="current-slide"></div>
  267. <div id="upcoming-slide"><span class="overlay-element label">Upcoming</span></div>
  268. <div id="speaker-controls">
  269. <div class="speaker-controls-time">
  270. <h4 class="label">Time <span class="reset-button">Click to Reset</span></h4>
  271. <div class="clock">
  272. <span class="clock-value">0:00 AM</span>
  273. </div>
  274. <div class="timer">
  275. <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
  276. </div>
  277. <div class="clear"></div>
  278. <h4 class="label pacing-title" style="display: none">Pacing – Time to finish current slide</h4>
  279. <div class="pacing" style="display: none">
  280. <span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
  281. </div>
  282. </div>
  283. <div class="speaker-controls-notes hidden">
  284. <h4 class="label">Notes</h4>
  285. <div class="value"></div>
  286. </div>
  287. </div>
  288. <div id="speaker-layout" class="overlay-element interactive">
  289. <span class="speaker-layout-label"></span>
  290. <select class="speaker-layout-dropdown"></select>
  291. </div>
  292. <script>
  293. (function() {
  294. var notes,
  295. notesValue,
  296. currentState,
  297. currentSlide,
  298. upcomingSlide,
  299. layoutLabel,
  300. layoutDropdown,
  301. pendingCalls = {},
  302. lastRevealApiCallId = 0,
  303. connected = false
  304. var connectionStatus = document.querySelector( '#connection-status' );
  305. var SPEAKER_LAYOUTS = {
  306. 'default': 'Default',
  307. 'wide': 'Wide',
  308. 'tall': 'Tall',
  309. 'notes-only': 'Notes only'
  310. };
  311. setupLayout();
  312. let openerOrigin;
  313. try {
  314. openerOrigin = window.opener.location.origin;
  315. }
  316. catch ( error ) { console.warn( error ) }
  317. // In order to prevent XSS, the speaker view will only run if its
  318. // opener has the same origin as itself
  319. if( window.location.origin !== openerOrigin ) {
  320. connectionStatus.innerHTML = 'Cross origin error.<br>The speaker window can only be opened from the same origin.';
  321. return;
  322. }
  323. var connectionTimeout = setTimeout( function() {
  324. connectionStatus.innerHTML = 'Error connecting to main window.<br>Please try closing and reopening the speaker view.';
  325. }, 5000 );
  326. window.addEventListener( 'message', function( event ) {
  327. // Validate the origin of all messages to avoid parsing messages
  328. // that aren't meant for us. Ignore when running off file:// so
  329. // that the speaker view continues to work without a web server.
  330. if( window.location.origin !== event.origin && window.location.origin !== 'file://' ) {
  331. return
  332. }
  333. clearTimeout( connectionTimeout );
  334. connectionStatus.style.display = 'none';
  335. var data = JSON.parse( event.data );
  336. // The overview mode is only useful to the reveal.js instance
  337. // where navigation occurs so we don't sync it
  338. if( data.state ) delete data.state.overview;
  339. // Messages sent by the notes plugin inside of the main window
  340. if( data && data.namespace === 'reveal-notes' ) {
  341. if( data.type === 'connect' ) {
  342. handleConnectMessage( data );
  343. }
  344. else if( data.type === 'state' ) {
  345. handleStateMessage( data );
  346. }
  347. else if( data.type === 'return' ) {
  348. pendingCalls[data.callId](data.result);
  349. delete pendingCalls[data.callId];
  350. }
  351. }
  352. // Messages sent by the reveal.js inside of the current slide preview
  353. else if( data && data.namespace === 'reveal' ) {
  354. if( /ready/.test( data.eventName ) ) {
  355. // Send a message back to notify that the handshake is complete
  356. window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' );
  357. }
  358. else if( /slidechanged|fragmentshown|fragmenthidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
  359. dispatchStateToMainWindow( data.state );
  360. }
  361. }
  362. } );
  363. /**
  364. * Updates the presentation in the main window to match the state
  365. * of the presentation in the notes window.
  366. */
  367. const dispatchStateToMainWindow = debounce(( state ) => {
  368. window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ state ]} ), '*' );
  369. }, 500);
  370. /**
  371. * Asynchronously calls the Reveal.js API of the main frame.
  372. */
  373. function callRevealApi( methodName, methodArguments, callback ) {
  374. var callId = ++lastRevealApiCallId;
  375. pendingCalls[callId] = callback;
  376. window.opener.postMessage( JSON.stringify( {
  377. namespace: 'reveal-notes',
  378. type: 'call',
  379. callId: callId,
  380. methodName: methodName,
  381. arguments: methodArguments
  382. } ), '*' );
  383. }
  384. /**
  385. * Called when the main window is trying to establish a
  386. * connection.
  387. */
  388. function handleConnectMessage( data ) {
  389. if( connected === false ) {
  390. connected = true;
  391. setupIframes( data );
  392. setupKeyboard();
  393. setupNotes();
  394. setupTimer();
  395. setupHeartbeat();
  396. }
  397. }
  398. /**
  399. * Called when the main window sends an updated state.
  400. */
  401. function handleStateMessage( data ) {
  402. // Store the most recently set state to avoid circular loops
  403. // applying the same state
  404. currentState = JSON.stringify( data.state );
  405. // No need for updating the notes in case of fragment changes
  406. if ( data.notes ) {
  407. notes.classList.remove( 'hidden' );
  408. notesValue.style.whiteSpace = data.whitespace;
  409. if( data.markdown ) {
  410. notesValue.innerHTML = marked( data.notes );
  411. }
  412. else {
  413. notesValue.innerHTML = data.notes;
  414. }
  415. }
  416. else {
  417. notes.classList.add( 'hidden' );
  418. }
  419. // Update the note slides
  420. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  421. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ] }), '*' );
  422. upcomingSlide.contentWindow.postMessage( JSON.stringify({ method: 'next' }), '*' );
  423. }
  424. // Limit to max one state update per X ms
  425. handleStateMessage = debounce( handleStateMessage, 200 );
  426. /**
  427. * Forward keyboard events to the current slide window.
  428. * This enables keyboard events to work even if focus
  429. * isn't set on the current slide iframe.
  430. *
  431. * Block F5 default handling, it reloads and disconnects
  432. * the speaker notes window.
  433. */
  434. function setupKeyboard() {
  435. document.addEventListener( 'keydown', function( event ) {
  436. if( event.keyCode === 116 || ( event.metaKey && event.keyCode === 82 ) ) {
  437. event.preventDefault();
  438. return false;
  439. }
  440. currentSlide.contentWindow.postMessage( JSON.stringify({ method: 'triggerKey', args: [ event.keyCode ] }), '*' );
  441. } );
  442. }
  443. /**
  444. * Creates the preview iframes.
  445. */
  446. function setupIframes( data ) {
  447. var params = [
  448. 'receiver',
  449. 'progress=false',
  450. 'history=false',
  451. 'transition=none',
  452. 'autoSlide=0',
  453. 'backgroundTransition=none'
  454. ].join( '&' );
  455. var urlSeparator = /\\?/.test(data.url) ? '&' : '?';
  456. var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
  457. var currentURL = data.url + urlSeparator + params + '&scrollActivationWidth=false&postMessageEvents=true' + hash;
  458. var upcomingURL = data.url + urlSeparator + params + '&scrollActivationWidth=false&controls=false' + hash;
  459. currentSlide = document.createElement( 'iframe' );
  460. currentSlide.setAttribute( 'width', 1280 );
  461. currentSlide.setAttribute( 'height', 1024 );
  462. currentSlide.setAttribute( 'src', currentURL );
  463. document.querySelector( '#current-slide' ).appendChild( currentSlide );
  464. upcomingSlide = document.createElement( 'iframe' );
  465. upcomingSlide.setAttribute( 'width', 640 );
  466. upcomingSlide.setAttribute( 'height', 512 );
  467. upcomingSlide.setAttribute( 'src', upcomingURL );
  468. document.querySelector( '#upcoming-slide' ).appendChild( upcomingSlide );
  469. }
  470. /**
  471. * Setup the notes UI.
  472. */
  473. function setupNotes() {
  474. notes = document.querySelector( '.speaker-controls-notes' );
  475. notesValue = document.querySelector( '.speaker-controls-notes .value' );
  476. }
  477. /**
  478. * We send out a heartbeat at all times to ensure we can
  479. * reconnect with the main presentation window after reloads.
  480. */
  481. function setupHeartbeat() {
  482. setInterval( () => {
  483. window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'heartbeat'} ), '*' );
  484. }, 1000 );
  485. }
  486. function getTimings( callback ) {
  487. callRevealApi( 'getSlidesAttributes', [], function ( slideAttributes ) {
  488. callRevealApi( 'getConfig', [], function ( config ) {
  489. var totalTime = config.totalTime;
  490. var minTimePerSlide = config.minimumTimePerSlide || 0;
  491. var defaultTiming = config.defaultTiming;
  492. if ((defaultTiming == null) && (totalTime == null)) {
  493. callback(null);
  494. return;
  495. }
  496. // Setting totalTime overrides defaultTiming
  497. if (totalTime) {
  498. defaultTiming = 0;
  499. }
  500. var timings = [];
  501. for ( var i in slideAttributes ) {
  502. var slide = slideAttributes[ i ];
  503. var timing = defaultTiming;
  504. if( slide.hasOwnProperty( 'data-timing' )) {
  505. var t = slide[ 'data-timing' ];
  506. timing = parseInt(t);
  507. if( isNaN(timing) ) {
  508. console.warn("Could not parse timing '" + t + "' of slide " + i + "; using default of " + defaultTiming);
  509. timing = defaultTiming;
  510. }
  511. }
  512. timings.push(timing);
  513. }
  514. if ( totalTime ) {
  515. // After we've allocated time to individual slides, we summarize it and
  516. // subtract it from the total time
  517. var remainingTime = totalTime - timings.reduce( function(a, b) { return a + b; }, 0 );
  518. // The remaining time is divided by the number of slides that have 0 seconds
  519. // allocated at the moment, giving the average time-per-slide on the remaining slides
  520. var remainingSlides = (timings.filter( function(x) { return x == 0 }) ).length
  521. var timePerSlide = Math.round( remainingTime / remainingSlides, 0 )
  522. // And now we replace every zero-value timing with that average
  523. timings = timings.map( function(x) { return (x==0 ? timePerSlide : x) } );
  524. }
  525. var slidesUnderMinimum = timings.filter( function(x) { return (x < minTimePerSlide) } ).length
  526. if ( slidesUnderMinimum ) {
  527. message = "The pacing time for " + slidesUnderMinimum + " slide(s) is under the configured minimum of " + minTimePerSlide + " seconds. Check the data-timing attribute on individual slides, or consider increasing the totalTime or minimumTimePerSlide configuration options (or removing some slides).";
  528. alert(message);
  529. }
  530. callback( timings );
  531. } );
  532. } );
  533. }
  534. /**
  535. * Return the number of seconds allocated for presenting
  536. * all slides up to and including this one.
  537. */
  538. function getTimeAllocated( timings, callback ) {
  539. callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) {
  540. var allocated = 0;
  541. for (var i in timings.slice(0, currentSlide + 1)) {
  542. allocated += timings[i];
  543. }
  544. callback( allocated );
  545. } );
  546. }
  547. /**
  548. * Create the timer and clock and start updating them
  549. * at an interval.
  550. */
  551. function setupTimer() {
  552. var start = new Date(),
  553. timeEl = document.querySelector( '.speaker-controls-time' ),
  554. clockEl = timeEl.querySelector( '.clock-value' ),
  555. hoursEl = timeEl.querySelector( '.hours-value' ),
  556. minutesEl = timeEl.querySelector( '.minutes-value' ),
  557. secondsEl = timeEl.querySelector( '.seconds-value' ),
  558. pacingTitleEl = timeEl.querySelector( '.pacing-title' ),
  559. pacingEl = timeEl.querySelector( '.pacing' ),
  560. pacingHoursEl = pacingEl.querySelector( '.hours-value' ),
  561. pacingMinutesEl = pacingEl.querySelector( '.minutes-value' ),
  562. pacingSecondsEl = pacingEl.querySelector( '.seconds-value' );
  563. var timings = null;
  564. getTimings( function ( _timings ) {
  565. timings = _timings;
  566. if (_timings !== null) {
  567. pacingTitleEl.style.removeProperty('display');
  568. pacingEl.style.removeProperty('display');
  569. }
  570. // Update once directly
  571. _updateTimer();
  572. // Then update every second
  573. setInterval( _updateTimer, 1000 );
  574. } );
  575. function _resetTimer() {
  576. if (timings == null) {
  577. start = new Date();
  578. _updateTimer();
  579. }
  580. else {
  581. // Reset timer to beginning of current slide
  582. getTimeAllocated( timings, function ( slideEndTimingSeconds ) {
  583. var slideEndTiming = slideEndTimingSeconds * 1000;
  584. callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) {
  585. var currentSlideTiming = timings[currentSlide] * 1000;
  586. var previousSlidesTiming = slideEndTiming - currentSlideTiming;
  587. var now = new Date();
  588. start = new Date(now.getTime() - previousSlidesTiming);
  589. _updateTimer();
  590. } );
  591. } );
  592. }
  593. }
  594. timeEl.addEventListener( 'click', function() {
  595. _resetTimer();
  596. return false;
  597. } );
  598. function _displayTime( hrEl, minEl, secEl, time) {
  599. var sign = Math.sign(time) == -1 ? "-" : "";
  600. time = Math.abs(Math.round(time / 1000));
  601. var seconds = time % 60;
  602. var minutes = Math.floor( time / 60 ) % 60 ;
  603. var hours = Math.floor( time / ( 60 * 60 )) ;
  604. hrEl.innerHTML = sign + zeroPadInteger( hours );
  605. if (hours == 0) {
  606. hrEl.classList.add( 'mute' );
  607. }
  608. else {
  609. hrEl.classList.remove( 'mute' );
  610. }
  611. minEl.innerHTML = ':' + zeroPadInteger( minutes );
  612. if (hours == 0 && minutes == 0) {
  613. minEl.classList.add( 'mute' );
  614. }
  615. else {
  616. minEl.classList.remove( 'mute' );
  617. }
  618. secEl.innerHTML = ':' + zeroPadInteger( seconds );
  619. }
  620. function _updateTimer() {
  621. var diff, hours, minutes, seconds,
  622. now = new Date();
  623. diff = now.getTime() - start.getTime();
  624. clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
  625. _displayTime( hoursEl, minutesEl, secondsEl, diff );
  626. if (timings !== null) {
  627. _updatePacing(diff);
  628. }
  629. }
  630. function _updatePacing(diff) {
  631. getTimeAllocated( timings, function ( slideEndTimingSeconds ) {
  632. var slideEndTiming = slideEndTimingSeconds * 1000;
  633. callRevealApi( 'getSlidePastCount', [], function ( currentSlide ) {
  634. var currentSlideTiming = timings[currentSlide] * 1000;
  635. var timeLeftCurrentSlide = slideEndTiming - diff;
  636. if (timeLeftCurrentSlide < 0) {
  637. pacingEl.className = 'pacing behind';
  638. }
  639. else if (timeLeftCurrentSlide < currentSlideTiming) {
  640. pacingEl.className = 'pacing on-track';
  641. }
  642. else {
  643. pacingEl.className = 'pacing ahead';
  644. }
  645. _displayTime( pacingHoursEl, pacingMinutesEl, pacingSecondsEl, timeLeftCurrentSlide );
  646. } );
  647. } );
  648. }
  649. }
  650. /**
  651. * Sets up the speaker view layout and layout selector.
  652. */
  653. function setupLayout() {
  654. layoutDropdown = document.querySelector( '.speaker-layout-dropdown' );
  655. layoutLabel = document.querySelector( '.speaker-layout-label' );
  656. // Render the list of available layouts
  657. for( var id in SPEAKER_LAYOUTS ) {
  658. var option = document.createElement( 'option' );
  659. option.setAttribute( 'value', id );
  660. option.textContent = SPEAKER_LAYOUTS[ id ];
  661. layoutDropdown.appendChild( option );
  662. }
  663. // Monitor the dropdown for changes
  664. layoutDropdown.addEventListener( 'change', function( event ) {
  665. setLayout( layoutDropdown.value );
  666. }, false );
  667. // Restore any currently persisted layout
  668. setLayout( getLayout() );
  669. }
  670. /**
  671. * Sets a new speaker view layout. The layout is persisted
  672. * in local storage.
  673. */
  674. function setLayout( value ) {
  675. var title = SPEAKER_LAYOUTS[ value ];
  676. layoutLabel.innerHTML = 'Layout' + ( title ? ( ': ' + title ) : '' );
  677. layoutDropdown.value = value;
  678. document.body.setAttribute( 'data-speaker-layout', value );
  679. // Persist locally
  680. if( supportsLocalStorage() ) {
  681. window.localStorage.setItem( 'reveal-speaker-layout', value );
  682. }
  683. }
  684. /**
  685. * Returns the ID of the most recently set speaker layout
  686. * or our default layout if none has been set.
  687. */
  688. function getLayout() {
  689. if( supportsLocalStorage() ) {
  690. var layout = window.localStorage.getItem( 'reveal-speaker-layout' );
  691. if( layout ) {
  692. return layout;
  693. }
  694. }
  695. // Default to the first record in the layouts hash
  696. for( var id in SPEAKER_LAYOUTS ) {
  697. return id;
  698. }
  699. }
  700. function supportsLocalStorage() {
  701. try {
  702. localStorage.setItem('test', 'test');
  703. localStorage.removeItem('test');
  704. return true;
  705. }
  706. catch( e ) {
  707. return false;
  708. }
  709. }
  710. function zeroPadInteger( num ) {
  711. var str = '00' + parseInt( num );
  712. return str.substring( str.length - 2 );
  713. }
  714. /**
  715. * Limits the frequency at which a function can be called.
  716. */
  717. function debounce( fn, ms ) {
  718. var lastTime = 0,
  719. timeout;
  720. return function() {
  721. var args = arguments;
  722. var context = this;
  723. clearTimeout( timeout );
  724. var timeSinceLastCall = Date.now() - lastTime;
  725. if( timeSinceLastCall > ms ) {
  726. fn.apply( context, args );
  727. lastTime = Date.now();
  728. }
  729. else {
  730. timeout = setTimeout( function() {
  731. fn.apply( context, args );
  732. lastTime = Date.now();
  733. }, ms - timeSinceLastCall );
  734. }
  735. }
  736. }
  737. })();
  738. <\/script>
  739. </body>
  740. </html>`;
  741. function W() {
  742. return {
  743. async: !1,
  744. baseUrl: null,
  745. breaks: !1,
  746. extensions: null,
  747. gfm: !0,
  748. headerIds: !0,
  749. headerPrefix: "",
  750. highlight: null,
  751. hooks: null,
  752. langPrefix: "language-",
  753. mangle: !0,
  754. pedantic: !1,
  755. renderer: null,
  756. sanitize: !1,
  757. sanitizer: null,
  758. silent: !1,
  759. smartypants: !1,
  760. tokenizer: null,
  761. walkTokens: null,
  762. xhtml: !1
  763. };
  764. }
  765. let A = W();
  766. function nt(l) {
  767. A = l;
  768. }
  769. const Q = /[&<>"']/, it = new RegExp(Q.source, "g"), K = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/, st = new RegExp(K.source, "g"), rt = {
  770. "&": "&amp;",
  771. "<": "&lt;",
  772. ">": "&gt;",
  773. '"': "&quot;",
  774. "'": "&#39;"
  775. }, U = (l) => rt[l];
  776. function S(l, n) {
  777. if (n) {
  778. if (Q.test(l))
  779. return l.replace(it, U);
  780. } else if (K.test(l))
  781. return l.replace(st, U);
  782. return l;
  783. }
  784. const at = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
  785. function V(l) {
  786. return l.replace(at, (n, e) => (e = e.toLowerCase(), e === "colon" ? ":" : e.charAt(0) === "#" ? e.charAt(1) === "x" ? String.fromCharCode(parseInt(e.substring(2), 16)) : String.fromCharCode(+e.substring(1)) : ""));
  787. }
  788. const lt = /(^|[^\[])\^/g;
  789. function k(l, n) {
  790. l = typeof l == "string" ? l : l.source, n = n || "";
  791. const e = {
  792. replace: (t, i) => (i = i.source || i, i = i.replace(lt, "$1"), l = l.replace(t, i), e),
  793. getRegex: () => new RegExp(l, n)
  794. };
  795. return e;
  796. }
  797. const ot = /[^\w:]/g, ct = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
  798. function B(l, n, e) {
  799. if (l) {
  800. let t;
  801. try {
  802. t = decodeURIComponent(V(e)).replace(ot, "").toLowerCase();
  803. } catch {
  804. return null;
  805. }
  806. if (t.indexOf("javascript:") === 0 || t.indexOf("vbscript:") === 0 || t.indexOf("data:") === 0)
  807. return null;
  808. }
  809. n && !ct.test(e) && (e = ht(n, e));
  810. try {
  811. e = encodeURI(e).replace(/%25/g, "%");
  812. } catch {
  813. return null;
  814. }
  815. return e;
  816. }
  817. const I = {}, ut = /^[^:]+:\/*[^/]*$/, pt = /^([^:]+:)[\s\S]*$/, dt = /^([^:]+:\/*[^/]*)[\s\S]*$/;
  818. function ht(l, n) {
  819. I[" " + l] || (ut.test(l) ? I[" " + l] = l + "/" : I[" " + l] = C(l, "/", !0)), l = I[" " + l];
  820. const e = l.indexOf(":") === -1;
  821. return n.substring(0, 2) === "//" ? e ? n : l.replace(pt, "$1") + n : n.charAt(0) === "/" ? e ? n : l.replace(dt, "$1") + n : l + n;
  822. }
  823. const M = { exec: function() {
  824. } };
  825. function Z(l, n) {
  826. const e = l.replace(/\|/g, (s, a, r) => {
  827. let c = !1, m = a;
  828. for (; --m >= 0 && r[m] === "\\"; )
  829. c = !c;
  830. return c ? "|" : " |";
  831. }), t = e.split(/ \|/);
  832. let i = 0;
  833. if (t[0].trim() || t.shift(), t.length > 0 && !t[t.length - 1].trim() && t.pop(), t.length > n)
  834. t.splice(n);
  835. else
  836. for (; t.length < n; )
  837. t.push("");
  838. for (; i < t.length; i++)
  839. t[i] = t[i].trim().replace(/\\\|/g, "|");
  840. return t;
  841. }
  842. function C(l, n, e) {
  843. const t = l.length;
  844. if (t === 0)
  845. return "";
  846. let i = 0;
  847. for (; i < t; ) {
  848. const s = l.charAt(t - i - 1);
  849. if (s === n && !e)
  850. i++;
  851. else if (s !== n && e)
  852. i++;
  853. else
  854. break;
  855. }
  856. return l.slice(0, t - i);
  857. }
  858. function gt(l, n) {
  859. if (l.indexOf(n[1]) === -1)
  860. return -1;
  861. const e = l.length;
  862. let t = 0, i = 0;
  863. for (; i < e; i++)
  864. if (l[i] === "\\")
  865. i++;
  866. else if (l[i] === n[0])
  867. t++;
  868. else if (l[i] === n[1] && (t--, t < 0))
  869. return i;
  870. return -1;
  871. }
  872. function ft(l) {
  873. l && l.sanitize && !l.silent && console.warn("marked(): sanitize and sanitizer parameters are deprecated since version 0.7.0, should not be used and will be removed in the future. Read more here: https://marked.js.org/#/USING_ADVANCED.md#options");
  874. }
  875. function H(l, n) {
  876. if (n < 1)
  877. return "";
  878. let e = "";
  879. for (; n > 1; )
  880. n & 1 && (e += l), n >>= 1, l += l;
  881. return e + l;
  882. }
  883. function j(l, n, e, t) {
  884. const i = n.href, s = n.title ? S(n.title) : null, a = l[1].replace(/\\([\[\]])/g, "$1");
  885. if (l[0].charAt(0) !== "!") {
  886. t.state.inLink = !0;
  887. const r = {
  888. type: "link",
  889. raw: e,
  890. href: i,
  891. title: s,
  892. text: a,
  893. tokens: t.inlineTokens(a)
  894. };
  895. return t.state.inLink = !1, r;
  896. }
  897. return {
  898. type: "image",
  899. raw: e,
  900. href: i,
  901. title: s,
  902. text: S(a)
  903. };
  904. }
  905. function mt(l, n) {
  906. const e = l.match(/^(\s+)(?:```)/);
  907. if (e === null)
  908. return n;
  909. const t = e[1];
  910. return n.split(`
  911. `).map((i) => {
  912. const s = i.match(/^\s+/);
  913. if (s === null)
  914. return i;
  915. const [a] = s;
  916. return a.length >= t.length ? i.slice(t.length) : i;
  917. }).join(`
  918. `);
  919. }
  920. class P {
  921. constructor(n) {
  922. this.options = n || A;
  923. }
  924. space(n) {
  925. const e = this.rules.block.newline.exec(n);
  926. if (e && e[0].length > 0)
  927. return {
  928. type: "space",
  929. raw: e[0]
  930. };
  931. }
  932. code(n) {
  933. const e = this.rules.block.code.exec(n);
  934. if (e) {
  935. const t = e[0].replace(/^ {1,4}/gm, "");
  936. return {
  937. type: "code",
  938. raw: e[0],
  939. codeBlockStyle: "indented",
  940. text: this.options.pedantic ? t : C(t, `
  941. `)
  942. };
  943. }
  944. }
  945. fences(n) {
  946. const e = this.rules.block.fences.exec(n);
  947. if (e) {
  948. const t = e[0], i = mt(t, e[3] || "");
  949. return {
  950. type: "code",
  951. raw: t,
  952. lang: e[2] ? e[2].trim().replace(this.rules.inline._escapes, "$1") : e[2],
  953. text: i
  954. };
  955. }
  956. }
  957. heading(n) {
  958. const e = this.rules.block.heading.exec(n);
  959. if (e) {
  960. let t = e[2].trim();
  961. if (/#$/.test(t)) {
  962. const i = C(t, "#");
  963. (this.options.pedantic || !i || / $/.test(i)) && (t = i.trim());
  964. }
  965. return {
  966. type: "heading",
  967. raw: e[0],
  968. depth: e[1].length,
  969. text: t,
  970. tokens: this.lexer.inline(t)
  971. };
  972. }
  973. }
  974. hr(n) {
  975. const e = this.rules.block.hr.exec(n);
  976. if (e)
  977. return {
  978. type: "hr",
  979. raw: e[0]
  980. };
  981. }
  982. blockquote(n) {
  983. const e = this.rules.block.blockquote.exec(n);
  984. if (e) {
  985. const t = e[0].replace(/^ *>[ \t]?/gm, ""), i = this.lexer.state.top;
  986. this.lexer.state.top = !0;
  987. const s = this.lexer.blockTokens(t);
  988. return this.lexer.state.top = i, {
  989. type: "blockquote",
  990. raw: e[0],
  991. tokens: s,
  992. text: t
  993. };
  994. }
  995. }
  996. list(n) {
  997. let e = this.rules.block.list.exec(n);
  998. if (e) {
  999. let t, i, s, a, r, c, m, f, d, p, o, x, b = e[1].trim();
  1000. const v = b.length > 1, w = {
  1001. type: "list",
  1002. raw: "",
  1003. ordered: v,
  1004. start: v ? +b.slice(0, -1) : "",
  1005. loose: !1,
  1006. items: []
  1007. };
  1008. b = v ? `\\d{1,9}\\${b.slice(-1)}` : `\\${b}`, this.options.pedantic && (b = v ? b : "[*+-]");
  1009. const y = new RegExp(`^( {0,3}${b})((?:[ ][^\\n]*)?(?:\\n|$))`);
  1010. for (; n && (x = !1, !(!(e = y.exec(n)) || this.rules.block.hr.test(n))); ) {
  1011. if (t = e[0], n = n.substring(t.length), f = e[2].split(`
  1012. `, 1)[0].replace(/^\t+/, (z) => " ".repeat(3 * z.length)), d = n.split(`
  1013. `, 1)[0], this.options.pedantic ? (a = 2, o = f.trimLeft()) : (a = e[2].search(/[^ ]/), a = a > 4 ? 1 : a, o = f.slice(a), a += e[1].length), c = !1, !f && /^ *$/.test(d) && (t += d + `
  1014. `, n = n.substring(d.length + 1), x = !0), !x) {
  1015. const z = new RegExp(`^ {0,${Math.min(3, a - 1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`), T = new RegExp(`^ {0,${Math.min(3, a - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`), _ = new RegExp(`^ {0,${Math.min(3, a - 1)}}(?:\`\`\`|~~~)`), L = new RegExp(`^ {0,${Math.min(3, a - 1)}}#`);
  1016. for (; n && (p = n.split(`
  1017. `, 1)[0], d = p, this.options.pedantic && (d = d.replace(/^ {1,4}(?=( {4})*[^ ])/g, " ")), !(_.test(d) || L.test(d) || z.test(d) || T.test(n))); ) {
  1018. if (d.search(/[^ ]/) >= a || !d.trim())
  1019. o += `
  1020. ` + d.slice(a);
  1021. else {
  1022. if (c || f.search(/[^ ]/) >= 4 || _.test(f) || L.test(f) || T.test(f))
  1023. break;
  1024. o += `
  1025. ` + d;
  1026. }
  1027. !c && !d.trim() && (c = !0), t += p + `
  1028. `, n = n.substring(p.length + 1), f = d.slice(a);
  1029. }
  1030. }
  1031. w.loose || (m ? w.loose = !0 : /\n *\n *$/.test(t) && (m = !0)), this.options.gfm && (i = /^\[[ xX]\] /.exec(o), i && (s = i[0] !== "[ ] ", o = o.replace(/^\[[ xX]\] +/, ""))), w.items.push({
  1032. type: "list_item",
  1033. raw: t,
  1034. task: !!i,
  1035. checked: s,
  1036. loose: !1,
  1037. text: o
  1038. }), w.raw += t;
  1039. }
  1040. w.items[w.items.length - 1].raw = t.trimRight(), w.items[w.items.length - 1].text = o.trimRight(), w.raw = w.raw.trimRight();
  1041. const R = w.items.length;
  1042. for (r = 0; r < R; r++)
  1043. if (this.lexer.state.top = !1, w.items[r].tokens = this.lexer.blockTokens(w.items[r].text, []), !w.loose) {
  1044. const z = w.items[r].tokens.filter((_) => _.type === "space"), T = z.length > 0 && z.some((_) => /\n.*\n/.test(_.raw));
  1045. w.loose = T;
  1046. }
  1047. if (w.loose)
  1048. for (r = 0; r < R; r++)
  1049. w.items[r].loose = !0;
  1050. return w;
  1051. }
  1052. }
  1053. html(n) {
  1054. const e = this.rules.block.html.exec(n);
  1055. if (e) {
  1056. const t = {
  1057. type: "html",
  1058. raw: e[0],
  1059. pre: !this.options.sanitizer && (e[1] === "pre" || e[1] === "script" || e[1] === "style"),
  1060. text: e[0]
  1061. };
  1062. if (this.options.sanitize) {
  1063. const i = this.options.sanitizer ? this.options.sanitizer(e[0]) : S(e[0]);
  1064. t.type = "paragraph", t.text = i, t.tokens = this.lexer.inline(i);
  1065. }
  1066. return t;
  1067. }
  1068. }
  1069. def(n) {
  1070. const e = this.rules.block.def.exec(n);
  1071. if (e) {
  1072. const t = e[1].toLowerCase().replace(/\s+/g, " "), i = e[2] ? e[2].replace(/^<(.*)>$/, "$1").replace(this.rules.inline._escapes, "$1") : "", s = e[3] ? e[3].substring(1, e[3].length - 1).replace(this.rules.inline._escapes, "$1") : e[3];
  1073. return {
  1074. type: "def",
  1075. tag: t,
  1076. raw: e[0],
  1077. href: i,
  1078. title: s
  1079. };
  1080. }
  1081. }
  1082. table(n) {
  1083. const e = this.rules.block.table.exec(n);
  1084. if (e) {
  1085. const t = {
  1086. type: "table",
  1087. header: Z(e[1]).map((i) => ({ text: i })),
  1088. align: e[2].replace(/^ *|\| *$/g, "").split(/ *\| */),
  1089. rows: e[3] && e[3].trim() ? e[3].replace(/\n[ \t]*$/, "").split(`
  1090. `) : []
  1091. };
  1092. if (t.header.length === t.align.length) {
  1093. t.raw = e[0];
  1094. let i = t.align.length, s, a, r, c;
  1095. for (s = 0; s < i; s++)
  1096. /^ *-+: *$/.test(t.align[s]) ? t.align[s] = "right" : /^ *:-+: *$/.test(t.align[s]) ? t.align[s] = "center" : /^ *:-+ *$/.test(t.align[s]) ? t.align[s] = "left" : t.align[s] = null;
  1097. for (i = t.rows.length, s = 0; s < i; s++)
  1098. t.rows[s] = Z(t.rows[s], t.header.length).map((m) => ({ text: m }));
  1099. for (i = t.header.length, a = 0; a < i; a++)
  1100. t.header[a].tokens = this.lexer.inline(t.header[a].text);
  1101. for (i = t.rows.length, a = 0; a < i; a++)
  1102. for (c = t.rows[a], r = 0; r < c.length; r++)
  1103. c[r].tokens = this.lexer.inline(c[r].text);
  1104. return t;
  1105. }
  1106. }
  1107. }
  1108. lheading(n) {
  1109. const e = this.rules.block.lheading.exec(n);
  1110. if (e)
  1111. return {
  1112. type: "heading",
  1113. raw: e[0],
  1114. depth: e[2].charAt(0) === "=" ? 1 : 2,
  1115. text: e[1],
  1116. tokens: this.lexer.inline(e[1])
  1117. };
  1118. }
  1119. paragraph(n) {
  1120. const e = this.rules.block.paragraph.exec(n);
  1121. if (e) {
  1122. const t = e[1].charAt(e[1].length - 1) === `
  1123. ` ? e[1].slice(0, -1) : e[1];
  1124. return {
  1125. type: "paragraph",
  1126. raw: e[0],
  1127. text: t,
  1128. tokens: this.lexer.inline(t)
  1129. };
  1130. }
  1131. }
  1132. text(n) {
  1133. const e = this.rules.block.text.exec(n);
  1134. if (e)
  1135. return {
  1136. type: "text",
  1137. raw: e[0],
  1138. text: e[0],
  1139. tokens: this.lexer.inline(e[0])
  1140. };
  1141. }
  1142. escape(n) {
  1143. const e = this.rules.inline.escape.exec(n);
  1144. if (e)
  1145. return {
  1146. type: "escape",
  1147. raw: e[0],
  1148. text: S(e[1])
  1149. };
  1150. }
  1151. tag(n) {
  1152. const e = this.rules.inline.tag.exec(n);
  1153. if (e)
  1154. return !this.lexer.state.inLink && /^<a /i.test(e[0]) ? this.lexer.state.inLink = !0 : this.lexer.state.inLink && /^<\/a>/i.test(e[0]) && (this.lexer.state.inLink = !1), !this.lexer.state.inRawBlock && /^<(pre|code|kbd|script)(\s|>)/i.test(e[0]) ? this.lexer.state.inRawBlock = !0 : this.lexer.state.inRawBlock && /^<\/(pre|code|kbd|script)(\s|>)/i.test(e[0]) && (this.lexer.state.inRawBlock = !1), {
  1155. type: this.options.sanitize ? "text" : "html",
  1156. raw: e[0],
  1157. inLink: this.lexer.state.inLink,
  1158. inRawBlock: this.lexer.state.inRawBlock,
  1159. text: this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(e[0]) : S(e[0]) : e[0]
  1160. };
  1161. }
  1162. link(n) {
  1163. const e = this.rules.inline.link.exec(n);
  1164. if (e) {
  1165. const t = e[2].trim();
  1166. if (!this.options.pedantic && /^</.test(t)) {
  1167. if (!/>$/.test(t))
  1168. return;
  1169. const a = C(t.slice(0, -1), "\\");
  1170. if ((t.length - a.length) % 2 === 0)
  1171. return;
  1172. } else {
  1173. const a = gt(e[2], "()");
  1174. if (a > -1) {
  1175. const c = (e[0].indexOf("!") === 0 ? 5 : 4) + e[1].length + a;
  1176. e[2] = e[2].substring(0, a), e[0] = e[0].substring(0, c).trim(), e[3] = "";
  1177. }
  1178. }
  1179. let i = e[2], s = "";
  1180. if (this.options.pedantic) {
  1181. const a = /^([^'"]*[^\s])\s+(['"])(.*)\2/.exec(i);
  1182. a && (i = a[1], s = a[3]);
  1183. } else
  1184. s = e[3] ? e[3].slice(1, -1) : "";
  1185. return i = i.trim(), /^</.test(i) && (this.options.pedantic && !/>$/.test(t) ? i = i.slice(1) : i = i.slice(1, -1)), j(e, {
  1186. href: i && i.replace(this.rules.inline._escapes, "$1"),
  1187. title: s && s.replace(this.rules.inline._escapes, "$1")
  1188. }, e[0], this.lexer);
  1189. }
  1190. }
  1191. reflink(n, e) {
  1192. let t;
  1193. if ((t = this.rules.inline.reflink.exec(n)) || (t = this.rules.inline.nolink.exec(n))) {
  1194. let i = (t[2] || t[1]).replace(/\s+/g, " ");
  1195. if (i = e[i.toLowerCase()], !i) {
  1196. const s = t[0].charAt(0);
  1197. return {
  1198. type: "text",
  1199. raw: s,
  1200. text: s
  1201. };
  1202. }
  1203. return j(t, i, t[0], this.lexer);
  1204. }
  1205. }
  1206. emStrong(n, e, t = "") {
  1207. let i = this.rules.inline.emStrong.lDelim.exec(n);
  1208. if (!i || i[3] && t.match(/[\p{L}\p{N}]/u))
  1209. return;
  1210. const s = i[1] || i[2] || "";
  1211. if (!s || s && (t === "" || this.rules.inline.punctuation.exec(t))) {
  1212. const a = i[0].length - 1;
  1213. let r, c, m = a, f = 0;
  1214. const d = i[0][0] === "*" ? this.rules.inline.emStrong.rDelimAst : this.rules.inline.emStrong.rDelimUnd;
  1215. for (d.lastIndex = 0, e = e.slice(-1 * n.length + a); (i = d.exec(e)) != null; ) {
  1216. if (r = i[1] || i[2] || i[3] || i[4] || i[5] || i[6], !r)
  1217. continue;
  1218. if (c = r.length, i[3] || i[4]) {
  1219. m += c;
  1220. continue;
  1221. } else if ((i[5] || i[6]) && a % 3 && !((a + c) % 3)) {
  1222. f += c;
  1223. continue;
  1224. }
  1225. if (m -= c, m > 0)
  1226. continue;
  1227. c = Math.min(c, c + m + f);
  1228. const p = n.slice(0, a + i.index + (i[0].length - r.length) + c);
  1229. if (Math.min(a, c) % 2) {
  1230. const x = p.slice(1, -1);
  1231. return {
  1232. type: "em",
  1233. raw: p,
  1234. text: x,
  1235. tokens: this.lexer.inlineTokens(x)
  1236. };
  1237. }
  1238. const o = p.slice(2, -2);
  1239. return {
  1240. type: "strong",
  1241. raw: p,
  1242. text: o,
  1243. tokens: this.lexer.inlineTokens(o)
  1244. };
  1245. }
  1246. }
  1247. }
  1248. codespan(n) {
  1249. const e = this.rules.inline.code.exec(n);
  1250. if (e) {
  1251. let t = e[2].replace(/\n/g, " ");
  1252. const i = /[^ ]/.test(t), s = /^ /.test(t) && / $/.test(t);
  1253. return i && s && (t = t.substring(1, t.length - 1)), t = S(t, !0), {
  1254. type: "codespan",
  1255. raw: e[0],
  1256. text: t
  1257. };
  1258. }
  1259. }
  1260. br(n) {
  1261. const e = this.rules.inline.br.exec(n);
  1262. if (e)
  1263. return {
  1264. type: "br",
  1265. raw: e[0]
  1266. };
  1267. }
  1268. del(n) {
  1269. const e = this.rules.inline.del.exec(n);
  1270. if (e)
  1271. return {
  1272. type: "del",
  1273. raw: e[0],
  1274. text: e[2],
  1275. tokens: this.lexer.inlineTokens(e[2])
  1276. };
  1277. }
  1278. autolink(n, e) {
  1279. const t = this.rules.inline.autolink.exec(n);
  1280. if (t) {
  1281. let i, s;
  1282. return t[2] === "@" ? (i = S(this.options.mangle ? e(t[1]) : t[1]), s = "mailto:" + i) : (i = S(t[1]), s = i), {
  1283. type: "link",
  1284. raw: t[0],
  1285. text: i,
  1286. href: s,
  1287. tokens: [
  1288. {
  1289. type: "text",
  1290. raw: i,
  1291. text: i
  1292. }
  1293. ]
  1294. };
  1295. }
  1296. }
  1297. url(n, e) {
  1298. let t;
  1299. if (t = this.rules.inline.url.exec(n)) {
  1300. let i, s;
  1301. if (t[2] === "@")
  1302. i = S(this.options.mangle ? e(t[0]) : t[0]), s = "mailto:" + i;
  1303. else {
  1304. let a;
  1305. do
  1306. a = t[0], t[0] = this.rules.inline._backpedal.exec(t[0])[0];
  1307. while (a !== t[0]);
  1308. i = S(t[0]), t[1] === "www." ? s = "http://" + t[0] : s = t[0];
  1309. }
  1310. return {
  1311. type: "link",
  1312. raw: t[0],
  1313. text: i,
  1314. href: s,
  1315. tokens: [
  1316. {
  1317. type: "text",
  1318. raw: i,
  1319. text: i
  1320. }
  1321. ]
  1322. };
  1323. }
  1324. }
  1325. inlineText(n, e) {
  1326. const t = this.rules.inline.text.exec(n);
  1327. if (t) {
  1328. let i;
  1329. return this.lexer.state.inRawBlock ? i = this.options.sanitize ? this.options.sanitizer ? this.options.sanitizer(t[0]) : S(t[0]) : t[0] : i = S(this.options.smartypants ? e(t[0]) : t[0]), {
  1330. type: "text",
  1331. raw: t[0],
  1332. text: i
  1333. };
  1334. }
  1335. }
  1336. }
  1337. const h = {
  1338. newline: /^(?: *(?:\n|$))+/,
  1339. code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
  1340. fences: /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
  1341. hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
  1342. heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
  1343. blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
  1344. list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
  1345. html: "^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$))",
  1346. def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
  1347. table: M,
  1348. lheading: /^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
  1349. // regex template, placeholders will be replaced according to different paragraph
  1350. // interruption rules of commonmark and the original markdown spec:
  1351. _paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
  1352. text: /^[^\n]+/
  1353. };
  1354. h._label = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
  1355. h._title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
  1356. h.def = k(h.def).replace("label", h._label).replace("title", h._title).getRegex();
  1357. h.bullet = /(?:[*+-]|\d{1,9}[.)])/;
  1358. h.listItemStart = k(/^( *)(bull) */).replace("bull", h.bullet).getRegex();
  1359. h.list = k(h.list).replace(/bull/g, h.bullet).replace("hr", "\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))").replace("def", "\\n+(?=" + h.def.source + ")").getRegex();
  1360. h._tag = "address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul";
  1361. h._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
  1362. h.html = k(h.html, "i").replace("comment", h._comment).replace("tag", h._tag).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
  1363. h.paragraph = k(h._paragraph).replace("hr", h.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", h._tag).getRegex();
  1364. h.blockquote = k(h.blockquote).replace("paragraph", h.paragraph).getRegex();
  1365. h.normal = { ...h };
  1366. h.gfm = {
  1367. ...h.normal,
  1368. table: "^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"
  1369. // Cells
  1370. };
  1371. h.gfm.table = k(h.gfm.table).replace("hr", h.hr).replace("heading", " {0,3}#{1,6} ").replace("blockquote", " {0,3}>").replace("code", " {4}[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", h._tag).getRegex();
  1372. h.gfm.paragraph = k(h._paragraph).replace("hr", h.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("table", h.gfm.table).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", h._tag).getRegex();
  1373. h.pedantic = {
  1374. ...h.normal,
  1375. html: k(
  1376. `^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`
  1377. ).replace("comment", h._comment).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
  1378. def: /^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,
  1379. heading: /^(#{1,6})(.*)(?:\n+|$)/,
  1380. fences: M,
  1381. // fences not supported
  1382. lheading: /^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
  1383. paragraph: k(h.normal._paragraph).replace("hr", h.hr).replace("heading", ` *#{1,6} *[^
  1384. ]`).replace("lheading", h.lheading).replace("blockquote", " {0,3}>").replace("|fences", "").replace("|list", "").replace("|html", "").getRegex()
  1385. };
  1386. const u = {
  1387. escape: /^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,
  1388. autolink: /^<(scheme:[^\s\x00-\x1f<>]*|email)>/,
  1389. url: M,
  1390. tag: "^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>",
  1391. // CDATA section
  1392. link: /^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/,
  1393. reflink: /^!?\[(label)\]\[(ref)\]/,
  1394. nolink: /^!?\[(ref)\](?:\[\])?/,
  1395. reflinkSearch: "reflink|nolink(?!\\()",
  1396. emStrong: {
  1397. lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
  1398. // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
  1399. // () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
  1400. rDelimAst: /^(?:[^_*\\]|\\.)*?\_\_(?:[^_*\\]|\\.)*?\*(?:[^_*\\]|\\.)*?(?=\_\_)|(?:[^*\\]|\\.)+(?=[^*])|[punct_](\*+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|(?:[^punct*_\s\\]|\\.)(\*+)(?=[^punct*_\s])/,
  1401. rDelimUnd: /^(?:[^_*\\]|\\.)*?\*\*(?:[^_*\\]|\\.)*?\_(?:[^_*\\]|\\.)*?(?=\*\*)|(?:[^_\\]|\\.)+(?=[^_])|[punct*](\_+)(?=[\s]|$)|(?:[^punct*_\s\\]|\\.)(\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/
  1402. // ^- Not allowed for _
  1403. },
  1404. code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
  1405. br: /^( {2,}|\\)\n(?!\s*$)/,
  1406. del: M,
  1407. text: /^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,
  1408. punctuation: /^([\spunctuation])/
  1409. };
  1410. u._punctuation = "!\"#$%&'()+\\-.,/:;<=>?@\\[\\]`^{|}~";
  1411. u.punctuation = k(u.punctuation).replace(/punctuation/g, u._punctuation).getRegex();
  1412. u.blockSkip = /\[[^\]]*?\]\([^\)]*?\)|`[^`]*?`|<[^>]*?>/g;
  1413. u.escapedEmSt = /(?:^|[^\\])(?:\\\\)*\\[*_]/g;
  1414. u._comment = k(h._comment).replace("(?:-->|$)", "-->").getRegex();
  1415. u.emStrong.lDelim = k(u.emStrong.lDelim).replace(/punct/g, u._punctuation).getRegex();
  1416. u.emStrong.rDelimAst = k(u.emStrong.rDelimAst, "g").replace(/punct/g, u._punctuation).getRegex();
  1417. u.emStrong.rDelimUnd = k(u.emStrong.rDelimUnd, "g").replace(/punct/g, u._punctuation).getRegex();
  1418. u._escapes = /\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/g;
  1419. u._scheme = /[a-zA-Z][a-zA-Z0-9+.-]{1,31}/;
  1420. u._email = /[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
  1421. u.autolink = k(u.autolink).replace("scheme", u._scheme).replace("email", u._email).getRegex();
  1422. u._attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
  1423. u.tag = k(u.tag).replace("comment", u._comment).replace("attribute", u._attribute).getRegex();
  1424. u._label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
  1425. u._href = /<(?:\\.|[^\n<>\\])+>|[^\s\x00-\x1f]*/;
  1426. u._title = /"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/;
  1427. u.link = k(u.link).replace("label", u._label).replace("href", u._href).replace("title", u._title).getRegex();
  1428. u.reflink = k(u.reflink).replace("label", u._label).replace("ref", h._label).getRegex();
  1429. u.nolink = k(u.nolink).replace("ref", h._label).getRegex();
  1430. u.reflinkSearch = k(u.reflinkSearch, "g").replace("reflink", u.reflink).replace("nolink", u.nolink).getRegex();
  1431. u.normal = { ...u };
  1432. u.pedantic = {
  1433. ...u.normal,
  1434. strong: {
  1435. start: /^__|\*\*/,
  1436. middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
  1437. endAst: /\*\*(?!\*)/g,
  1438. endUnd: /__(?!_)/g
  1439. },
  1440. em: {
  1441. start: /^_|\*/,
  1442. middle: /^()\*(?=\S)([\s\S]*?\S)\*(?!\*)|^_(?=\S)([\s\S]*?\S)_(?!_)/,
  1443. endAst: /\*(?!\*)/g,
  1444. endUnd: /_(?!_)/g
  1445. },
  1446. link: k(/^!?\[(label)\]\((.*?)\)/).replace("label", u._label).getRegex(),
  1447. reflink: k(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", u._label).getRegex()
  1448. };
  1449. u.gfm = {
  1450. ...u.normal,
  1451. escape: k(u.escape).replace("])", "~|])").getRegex(),
  1452. _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
  1453. url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
  1454. _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
  1455. del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
  1456. text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
  1457. };
  1458. u.gfm.url = k(u.gfm.url, "i").replace("email", u.gfm._extended_email).getRegex();
  1459. u.breaks = {
  1460. ...u.gfm,
  1461. br: k(u.br).replace("{2,}", "*").getRegex(),
  1462. text: k(u.gfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
  1463. };
  1464. function kt(l) {
  1465. return l.replace(/---/g, "—").replace(/--/g, "–").replace(/(^|[-\u2014/(\[{"\s])'/g, "$1‘").replace(/'/g, "’").replace(/(^|[-\u2014/(\[{\u2018\s])"/g, "$1“").replace(/"/g, "”").replace(/\.{3}/g, "…");
  1466. }
  1467. function J(l) {
  1468. let n = "", e, t;
  1469. const i = l.length;
  1470. for (e = 0; e < i; e++)
  1471. t = l.charCodeAt(e), Math.random() > 0.5 && (t = "x" + t.toString(16)), n += "&#" + t + ";";
  1472. return n;
  1473. }
  1474. class $ {
  1475. constructor(n) {
  1476. this.tokens = [], this.tokens.links = /* @__PURE__ */ Object.create(null), this.options = n || A, this.options.tokenizer = this.options.tokenizer || new P(), this.tokenizer = this.options.tokenizer, this.tokenizer.options = this.options, this.tokenizer.lexer = this, this.inlineQueue = [], this.state = {
  1477. inLink: !1,
  1478. inRawBlock: !1,
  1479. top: !0
  1480. };
  1481. const e = {
  1482. block: h.normal,
  1483. inline: u.normal
  1484. };
  1485. this.options.pedantic ? (e.block = h.pedantic, e.inline = u.pedantic) : this.options.gfm && (e.block = h.gfm, this.options.breaks ? e.inline = u.breaks : e.inline = u.gfm), this.tokenizer.rules = e;
  1486. }
  1487. /**
  1488. * Expose Rules
  1489. */
  1490. static get rules() {
  1491. return {
  1492. block: h,
  1493. inline: u
  1494. };
  1495. }
  1496. /**
  1497. * Static Lex Method
  1498. */
  1499. static lex(n, e) {
  1500. return new $(e).lex(n);
  1501. }
  1502. /**
  1503. * Static Lex Inline Method
  1504. */
  1505. static lexInline(n, e) {
  1506. return new $(e).inlineTokens(n);
  1507. }
  1508. /**
  1509. * Preprocessing
  1510. */
  1511. lex(n) {
  1512. n = n.replace(/\r\n|\r/g, `
  1513. `), this.blockTokens(n, this.tokens);
  1514. let e;
  1515. for (; e = this.inlineQueue.shift(); )
  1516. this.inlineTokens(e.src, e.tokens);
  1517. return this.tokens;
  1518. }
  1519. /**
  1520. * Lexing
  1521. */
  1522. blockTokens(n, e = []) {
  1523. this.options.pedantic ? n = n.replace(/\t/g, " ").replace(/^ +$/gm, "") : n = n.replace(/^( *)(\t+)/gm, (r, c, m) => c + " ".repeat(m.length));
  1524. let t, i, s, a;
  1525. for (; n; )
  1526. if (!(this.options.extensions && this.options.extensions.block && this.options.extensions.block.some((r) => (t = r.call({ lexer: this }, n, e)) ? (n = n.substring(t.raw.length), e.push(t), !0) : !1))) {
  1527. if (t = this.tokenizer.space(n)) {
  1528. n = n.substring(t.raw.length), t.raw.length === 1 && e.length > 0 ? e[e.length - 1].raw += `
  1529. ` : e.push(t);
  1530. continue;
  1531. }
  1532. if (t = this.tokenizer.code(n)) {
  1533. n = n.substring(t.raw.length), i = e[e.length - 1], i && (i.type === "paragraph" || i.type === "text") ? (i.raw += `
  1534. ` + t.raw, i.text += `
  1535. ` + t.text, this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : e.push(t);
  1536. continue;
  1537. }
  1538. if (t = this.tokenizer.fences(n)) {
  1539. n = n.substring(t.raw.length), e.push(t);
  1540. continue;
  1541. }
  1542. if (t = this.tokenizer.heading(n)) {
  1543. n = n.substring(t.raw.length), e.push(t);
  1544. continue;
  1545. }
  1546. if (t = this.tokenizer.hr(n)) {
  1547. n = n.substring(t.raw.length), e.push(t);
  1548. continue;
  1549. }
  1550. if (t = this.tokenizer.blockquote(n)) {
  1551. n = n.substring(t.raw.length), e.push(t);
  1552. continue;
  1553. }
  1554. if (t = this.tokenizer.list(n)) {
  1555. n = n.substring(t.raw.length), e.push(t);
  1556. continue;
  1557. }
  1558. if (t = this.tokenizer.html(n)) {
  1559. n = n.substring(t.raw.length), e.push(t);
  1560. continue;
  1561. }
  1562. if (t = this.tokenizer.def(n)) {
  1563. n = n.substring(t.raw.length), i = e[e.length - 1], i && (i.type === "paragraph" || i.type === "text") ? (i.raw += `
  1564. ` + t.raw, i.text += `
  1565. ` + t.raw, this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : this.tokens.links[t.tag] || (this.tokens.links[t.tag] = {
  1566. href: t.href,
  1567. title: t.title
  1568. });
  1569. continue;
  1570. }
  1571. if (t = this.tokenizer.table(n)) {
  1572. n = n.substring(t.raw.length), e.push(t);
  1573. continue;
  1574. }
  1575. if (t = this.tokenizer.lheading(n)) {
  1576. n = n.substring(t.raw.length), e.push(t);
  1577. continue;
  1578. }
  1579. if (s = n, this.options.extensions && this.options.extensions.startBlock) {
  1580. let r = 1 / 0;
  1581. const c = n.slice(1);
  1582. let m;
  1583. this.options.extensions.startBlock.forEach(function(f) {
  1584. m = f.call({ lexer: this }, c), typeof m == "number" && m >= 0 && (r = Math.min(r, m));
  1585. }), r < 1 / 0 && r >= 0 && (s = n.substring(0, r + 1));
  1586. }
  1587. if (this.state.top && (t = this.tokenizer.paragraph(s))) {
  1588. i = e[e.length - 1], a && i.type === "paragraph" ? (i.raw += `
  1589. ` + t.raw, i.text += `
  1590. ` + t.text, this.inlineQueue.pop(), this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : e.push(t), a = s.length !== n.length, n = n.substring(t.raw.length);
  1591. continue;
  1592. }
  1593. if (t = this.tokenizer.text(n)) {
  1594. n = n.substring(t.raw.length), i = e[e.length - 1], i && i.type === "text" ? (i.raw += `
  1595. ` + t.raw, i.text += `
  1596. ` + t.text, this.inlineQueue.pop(), this.inlineQueue[this.inlineQueue.length - 1].src = i.text) : e.push(t);
  1597. continue;
  1598. }
  1599. if (n) {
  1600. const r = "Infinite loop on byte: " + n.charCodeAt(0);
  1601. if (this.options.silent) {
  1602. console.error(r);
  1603. break;
  1604. } else
  1605. throw new Error(r);
  1606. }
  1607. }
  1608. return this.state.top = !0, e;
  1609. }
  1610. inline(n, e = []) {
  1611. return this.inlineQueue.push({ src: n, tokens: e }), e;
  1612. }
  1613. /**
  1614. * Lexing/Compiling
  1615. */
  1616. inlineTokens(n, e = []) {
  1617. let t, i, s, a = n, r, c, m;
  1618. if (this.tokens.links) {
  1619. const f = Object.keys(this.tokens.links);
  1620. if (f.length > 0)
  1621. for (; (r = this.tokenizer.rules.inline.reflinkSearch.exec(a)) != null; )
  1622. f.includes(r[0].slice(r[0].lastIndexOf("[") + 1, -1)) && (a = a.slice(0, r.index) + "[" + H("a", r[0].length - 2) + "]" + a.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex));
  1623. }
  1624. for (; (r = this.tokenizer.rules.inline.blockSkip.exec(a)) != null; )
  1625. a = a.slice(0, r.index) + "[" + H("a", r[0].length - 2) + "]" + a.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);
  1626. for (; (r = this.tokenizer.rules.inline.escapedEmSt.exec(a)) != null; )
  1627. a = a.slice(0, r.index + r[0].length - 2) + "++" + a.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex), this.tokenizer.rules.inline.escapedEmSt.lastIndex--;
  1628. for (; n; )
  1629. if (c || (m = ""), c = !1, !(this.options.extensions && this.options.extensions.inline && this.options.extensions.inline.some((f) => (t = f.call({ lexer: this }, n, e)) ? (n = n.substring(t.raw.length), e.push(t), !0) : !1))) {
  1630. if (t = this.tokenizer.escape(n)) {
  1631. n = n.substring(t.raw.length), e.push(t);
  1632. continue;
  1633. }
  1634. if (t = this.tokenizer.tag(n)) {
  1635. n = n.substring(t.raw.length), i = e[e.length - 1], i && t.type === "text" && i.type === "text" ? (i.raw += t.raw, i.text += t.text) : e.push(t);
  1636. continue;
  1637. }
  1638. if (t = this.tokenizer.link(n)) {
  1639. n = n.substring(t.raw.length), e.push(t);
  1640. continue;
  1641. }
  1642. if (t = this.tokenizer.reflink(n, this.tokens.links)) {
  1643. n = n.substring(t.raw.length), i = e[e.length - 1], i && t.type === "text" && i.type === "text" ? (i.raw += t.raw, i.text += t.text) : e.push(t);
  1644. continue;
  1645. }
  1646. if (t = this.tokenizer.emStrong(n, a, m)) {
  1647. n = n.substring(t.raw.length), e.push(t);
  1648. continue;
  1649. }
  1650. if (t = this.tokenizer.codespan(n)) {
  1651. n = n.substring(t.raw.length), e.push(t);
  1652. continue;
  1653. }
  1654. if (t = this.tokenizer.br(n)) {
  1655. n = n.substring(t.raw.length), e.push(t);
  1656. continue;
  1657. }
  1658. if (t = this.tokenizer.del(n)) {
  1659. n = n.substring(t.raw.length), e.push(t);
  1660. continue;
  1661. }
  1662. if (t = this.tokenizer.autolink(n, J)) {
  1663. n = n.substring(t.raw.length), e.push(t);
  1664. continue;
  1665. }
  1666. if (!this.state.inLink && (t = this.tokenizer.url(n, J))) {
  1667. n = n.substring(t.raw.length), e.push(t);
  1668. continue;
  1669. }
  1670. if (s = n, this.options.extensions && this.options.extensions.startInline) {
  1671. let f = 1 / 0;
  1672. const d = n.slice(1);
  1673. let p;
  1674. this.options.extensions.startInline.forEach(function(o) {
  1675. p = o.call({ lexer: this }, d), typeof p == "number" && p >= 0 && (f = Math.min(f, p));
  1676. }), f < 1 / 0 && f >= 0 && (s = n.substring(0, f + 1));
  1677. }
  1678. if (t = this.tokenizer.inlineText(s, kt)) {
  1679. n = n.substring(t.raw.length), t.raw.slice(-1) !== "_" && (m = t.raw.slice(-1)), c = !0, i = e[e.length - 1], i && i.type === "text" ? (i.raw += t.raw, i.text += t.text) : e.push(t);
  1680. continue;
  1681. }
  1682. if (n) {
  1683. const f = "Infinite loop on byte: " + n.charCodeAt(0);
  1684. if (this.options.silent) {
  1685. console.error(f);
  1686. break;
  1687. } else
  1688. throw new Error(f);
  1689. }
  1690. }
  1691. return e;
  1692. }
  1693. }
  1694. class q {
  1695. constructor(n) {
  1696. this.options = n || A;
  1697. }
  1698. code(n, e, t) {
  1699. const i = (e || "").match(/\S*/)[0];
  1700. if (this.options.highlight) {
  1701. const s = this.options.highlight(n, i);
  1702. s != null && s !== n && (t = !0, n = s);
  1703. }
  1704. return n = n.replace(/\n$/, "") + `
  1705. `, i ? '<pre><code class="' + this.options.langPrefix + S(i) + '">' + (t ? n : S(n, !0)) + `</code></pre>
  1706. ` : "<pre><code>" + (t ? n : S(n, !0)) + `</code></pre>
  1707. `;
  1708. }
  1709. /**
  1710. * @param {string} quote
  1711. */
  1712. blockquote(n) {
  1713. return `<blockquote>
  1714. ${n}</blockquote>
  1715. `;
  1716. }
  1717. html(n) {
  1718. return n;
  1719. }
  1720. /**
  1721. * @param {string} text
  1722. * @param {string} level
  1723. * @param {string} raw
  1724. * @param {any} slugger
  1725. */
  1726. heading(n, e, t, i) {
  1727. if (this.options.headerIds) {
  1728. const s = this.options.headerPrefix + i.slug(t);
  1729. return `<h${e} id="${s}">${n}</h${e}>
  1730. `;
  1731. }
  1732. return `<h${e}>${n}</h${e}>
  1733. `;
  1734. }
  1735. hr() {
  1736. return this.options.xhtml ? `<hr/>
  1737. ` : `<hr>
  1738. `;
  1739. }
  1740. list(n, e, t) {
  1741. const i = e ? "ol" : "ul", s = e && t !== 1 ? ' start="' + t + '"' : "";
  1742. return "<" + i + s + `>
  1743. ` + n + "</" + i + `>
  1744. `;
  1745. }
  1746. /**
  1747. * @param {string} text
  1748. */
  1749. listitem(n) {
  1750. return `<li>${n}</li>
  1751. `;
  1752. }
  1753. checkbox(n) {
  1754. return "<input " + (n ? 'checked="" ' : "") + 'disabled="" type="checkbox"' + (this.options.xhtml ? " /" : "") + "> ";
  1755. }
  1756. /**
  1757. * @param {string} text
  1758. */
  1759. paragraph(n) {
  1760. return `<p>${n}</p>
  1761. `;
  1762. }
  1763. /**
  1764. * @param {string} header
  1765. * @param {string} body
  1766. */
  1767. table(n, e) {
  1768. return e && (e = `<tbody>${e}</tbody>`), `<table>
  1769. <thead>
  1770. ` + n + `</thead>
  1771. ` + e + `</table>
  1772. `;
  1773. }
  1774. /**
  1775. * @param {string} content
  1776. */
  1777. tablerow(n) {
  1778. return `<tr>
  1779. ${n}</tr>
  1780. `;
  1781. }
  1782. tablecell(n, e) {
  1783. const t = e.header ? "th" : "td";
  1784. return (e.align ? `<${t} align="${e.align}">` : `<${t}>`) + n + `</${t}>
  1785. `;
  1786. }
  1787. /**
  1788. * span level renderer
  1789. * @param {string} text
  1790. */
  1791. strong(n) {
  1792. return `<strong>${n}</strong>`;
  1793. }
  1794. /**
  1795. * @param {string} text
  1796. */
  1797. em(n) {
  1798. return `<em>${n}</em>`;
  1799. }
  1800. /**
  1801. * @param {string} text
  1802. */
  1803. codespan(n) {
  1804. return `<code>${n}</code>`;
  1805. }
  1806. br() {
  1807. return this.options.xhtml ? "<br/>" : "<br>";
  1808. }
  1809. /**
  1810. * @param {string} text
  1811. */
  1812. del(n) {
  1813. return `<del>${n}</del>`;
  1814. }
  1815. /**
  1816. * @param {string} href
  1817. * @param {string} title
  1818. * @param {string} text
  1819. */
  1820. link(n, e, t) {
  1821. if (n = B(this.options.sanitize, this.options.baseUrl, n), n === null)
  1822. return t;
  1823. let i = '<a href="' + n + '"';
  1824. return e && (i += ' title="' + e + '"'), i += ">" + t + "</a>", i;
  1825. }
  1826. /**
  1827. * @param {string} href
  1828. * @param {string} title
  1829. * @param {string} text
  1830. */
  1831. image(n, e, t) {
  1832. if (n = B(this.options.sanitize, this.options.baseUrl, n), n === null)
  1833. return t;
  1834. let i = `<img src="${n}" alt="${t}"`;
  1835. return e && (i += ` title="${e}"`), i += this.options.xhtml ? "/>" : ">", i;
  1836. }
  1837. text(n) {
  1838. return n;
  1839. }
  1840. }
  1841. class F {
  1842. // no need for block level renderers
  1843. strong(n) {
  1844. return n;
  1845. }
  1846. em(n) {
  1847. return n;
  1848. }
  1849. codespan(n) {
  1850. return n;
  1851. }
  1852. del(n) {
  1853. return n;
  1854. }
  1855. html(n) {
  1856. return n;
  1857. }
  1858. text(n) {
  1859. return n;
  1860. }
  1861. link(n, e, t) {
  1862. return "" + t;
  1863. }
  1864. image(n, e, t) {
  1865. return "" + t;
  1866. }
  1867. br() {
  1868. return "";
  1869. }
  1870. }
  1871. class Y {
  1872. constructor() {
  1873. this.seen = {};
  1874. }
  1875. /**
  1876. * @param {string} value
  1877. */
  1878. serialize(n) {
  1879. return n.toLowerCase().trim().replace(/<[!\/a-z].*?>/ig, "").replace(/[\u2000-\u206F\u2E00-\u2E7F\\'!"#$%&()*+,./:;<=>?@[\]^`{|}~]/g, "").replace(/\s/g, "-");
  1880. }
  1881. /**
  1882. * Finds the next safe (unique) slug to use
  1883. * @param {string} originalSlug
  1884. * @param {boolean} isDryRun
  1885. */
  1886. getNextSafeSlug(n, e) {
  1887. let t = n, i = 0;
  1888. if (this.seen.hasOwnProperty(t)) {
  1889. i = this.seen[n];
  1890. do
  1891. i++, t = n + "-" + i;
  1892. while (this.seen.hasOwnProperty(t));
  1893. }
  1894. return e || (this.seen[n] = i, this.seen[t] = 0), t;
  1895. }
  1896. /**
  1897. * Convert string to unique id
  1898. * @param {object} [options]
  1899. * @param {boolean} [options.dryrun] Generates the next unique slug without
  1900. * updating the internal accumulator.
  1901. */
  1902. slug(n, e = {}) {
  1903. const t = this.serialize(n);
  1904. return this.getNextSafeSlug(t, e.dryrun);
  1905. }
  1906. }
  1907. class E {
  1908. constructor(n) {
  1909. this.options = n || A, this.options.renderer = this.options.renderer || new q(), this.renderer = this.options.renderer, this.renderer.options = this.options, this.textRenderer = new F(), this.slugger = new Y();
  1910. }
  1911. /**
  1912. * Static Parse Method
  1913. */
  1914. static parse(n, e) {
  1915. return new E(e).parse(n);
  1916. }
  1917. /**
  1918. * Static Parse Inline Method
  1919. */
  1920. static parseInline(n, e) {
  1921. return new E(e).parseInline(n);
  1922. }
  1923. /**
  1924. * Parse Loop
  1925. */
  1926. parse(n, e = !0) {
  1927. let t = "", i, s, a, r, c, m, f, d, p, o, x, b, v, w, y, R, z, T, _;
  1928. const L = n.length;
  1929. for (i = 0; i < L; i++) {
  1930. if (o = n[i], this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[o.type] && (_ = this.options.extensions.renderers[o.type].call({ parser: this }, o), _ !== !1 || !["space", "hr", "heading", "code", "table", "blockquote", "list", "html", "paragraph", "text"].includes(o.type))) {
  1931. t += _ || "";
  1932. continue;
  1933. }
  1934. switch (o.type) {
  1935. case "space":
  1936. continue;
  1937. case "hr": {
  1938. t += this.renderer.hr();
  1939. continue;
  1940. }
  1941. case "heading": {
  1942. t += this.renderer.heading(
  1943. this.parseInline(o.tokens),
  1944. o.depth,
  1945. V(this.parseInline(o.tokens, this.textRenderer)),
  1946. this.slugger
  1947. );
  1948. continue;
  1949. }
  1950. case "code": {
  1951. t += this.renderer.code(
  1952. o.text,
  1953. o.lang,
  1954. o.escaped
  1955. );
  1956. continue;
  1957. }
  1958. case "table": {
  1959. for (d = "", f = "", r = o.header.length, s = 0; s < r; s++)
  1960. f += this.renderer.tablecell(
  1961. this.parseInline(o.header[s].tokens),
  1962. { header: !0, align: o.align[s] }
  1963. );
  1964. for (d += this.renderer.tablerow(f), p = "", r = o.rows.length, s = 0; s < r; s++) {
  1965. for (m = o.rows[s], f = "", c = m.length, a = 0; a < c; a++)
  1966. f += this.renderer.tablecell(
  1967. this.parseInline(m[a].tokens),
  1968. { header: !1, align: o.align[a] }
  1969. );
  1970. p += this.renderer.tablerow(f);
  1971. }
  1972. t += this.renderer.table(d, p);
  1973. continue;
  1974. }
  1975. case "blockquote": {
  1976. p = this.parse(o.tokens), t += this.renderer.blockquote(p);
  1977. continue;
  1978. }
  1979. case "list": {
  1980. for (x = o.ordered, b = o.start, v = o.loose, r = o.items.length, p = "", s = 0; s < r; s++)
  1981. y = o.items[s], R = y.checked, z = y.task, w = "", y.task && (T = this.renderer.checkbox(R), v ? y.tokens.length > 0 && y.tokens[0].type === "paragraph" ? (y.tokens[0].text = T + " " + y.tokens[0].text, y.tokens[0].tokens && y.tokens[0].tokens.length > 0 && y.tokens[0].tokens[0].type === "text" && (y.tokens[0].tokens[0].text = T + " " + y.tokens[0].tokens[0].text)) : y.tokens.unshift({
  1982. type: "text",
  1983. text: T
  1984. }) : w += T), w += this.parse(y.tokens, v), p += this.renderer.listitem(w, z, R);
  1985. t += this.renderer.list(p, x, b);
  1986. continue;
  1987. }
  1988. case "html": {
  1989. t += this.renderer.html(o.text);
  1990. continue;
  1991. }
  1992. case "paragraph": {
  1993. t += this.renderer.paragraph(this.parseInline(o.tokens));
  1994. continue;
  1995. }
  1996. case "text": {
  1997. for (p = o.tokens ? this.parseInline(o.tokens) : o.text; i + 1 < L && n[i + 1].type === "text"; )
  1998. o = n[++i], p += `
  1999. ` + (o.tokens ? this.parseInline(o.tokens) : o.text);
  2000. t += e ? this.renderer.paragraph(p) : p;
  2001. continue;
  2002. }
  2003. default: {
  2004. const O = 'Token with "' + o.type + '" type was not found.';
  2005. if (this.options.silent) {
  2006. console.error(O);
  2007. return;
  2008. } else
  2009. throw new Error(O);
  2010. }
  2011. }
  2012. }
  2013. return t;
  2014. }
  2015. /**
  2016. * Parse Inline Tokens
  2017. */
  2018. parseInline(n, e) {
  2019. e = e || this.renderer;
  2020. let t = "", i, s, a;
  2021. const r = n.length;
  2022. for (i = 0; i < r; i++) {
  2023. if (s = n[i], this.options.extensions && this.options.extensions.renderers && this.options.extensions.renderers[s.type] && (a = this.options.extensions.renderers[s.type].call({ parser: this }, s), a !== !1 || !["escape", "html", "link", "image", "strong", "em", "codespan", "br", "del", "text"].includes(s.type))) {
  2024. t += a || "";
  2025. continue;
  2026. }
  2027. switch (s.type) {
  2028. case "escape": {
  2029. t += e.text(s.text);
  2030. break;
  2031. }
  2032. case "html": {
  2033. t += e.html(s.text);
  2034. break;
  2035. }
  2036. case "link": {
  2037. t += e.link(s.href, s.title, this.parseInline(s.tokens, e));
  2038. break;
  2039. }
  2040. case "image": {
  2041. t += e.image(s.href, s.title, s.text);
  2042. break;
  2043. }
  2044. case "strong": {
  2045. t += e.strong(this.parseInline(s.tokens, e));
  2046. break;
  2047. }
  2048. case "em": {
  2049. t += e.em(this.parseInline(s.tokens, e));
  2050. break;
  2051. }
  2052. case "codespan": {
  2053. t += e.codespan(s.text);
  2054. break;
  2055. }
  2056. case "br": {
  2057. t += e.br();
  2058. break;
  2059. }
  2060. case "del": {
  2061. t += e.del(this.parseInline(s.tokens, e));
  2062. break;
  2063. }
  2064. case "text": {
  2065. t += e.text(s.text);
  2066. break;
  2067. }
  2068. default: {
  2069. const c = 'Token with "' + s.type + '" type was not found.';
  2070. if (this.options.silent) {
  2071. console.error(c);
  2072. return;
  2073. } else
  2074. throw new Error(c);
  2075. }
  2076. }
  2077. }
  2078. return t;
  2079. }
  2080. }
  2081. class N {
  2082. constructor(n) {
  2083. this.options = n || A;
  2084. }
  2085. /**
  2086. * Process markdown before marked
  2087. */
  2088. preprocess(n) {
  2089. return n;
  2090. }
  2091. /**
  2092. * Process HTML after marked is finished
  2093. */
  2094. postprocess(n) {
  2095. return n;
  2096. }
  2097. }
  2098. D(N, "passThroughHooks", /* @__PURE__ */ new Set([
  2099. "preprocess",
  2100. "postprocess"
  2101. ]));
  2102. function wt(l, n, e) {
  2103. return (t) => {
  2104. if (t.message += `
  2105. Please report this to https://github.com/markedjs/marked.`, l) {
  2106. const i = "<p>An error occurred:</p><pre>" + S(t.message + "", !0) + "</pre>";
  2107. if (n)
  2108. return Promise.resolve(i);
  2109. if (e) {
  2110. e(null, i);
  2111. return;
  2112. }
  2113. return i;
  2114. }
  2115. if (n)
  2116. return Promise.reject(t);
  2117. if (e) {
  2118. e(t);
  2119. return;
  2120. }
  2121. throw t;
  2122. };
  2123. }
  2124. function X(l, n) {
  2125. return (e, t, i) => {
  2126. typeof t == "function" && (i = t, t = null);
  2127. const s = { ...t };
  2128. t = { ...g.defaults, ...s };
  2129. const a = wt(t.silent, t.async, i);
  2130. if (typeof e > "u" || e === null)
  2131. return a(new Error("marked(): input parameter is undefined or null"));
  2132. if (typeof e != "string")
  2133. return a(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(e) + ", string expected"));
  2134. if (ft(t), t.hooks && (t.hooks.options = t), i) {
  2135. const r = t.highlight;
  2136. let c;
  2137. try {
  2138. t.hooks && (e = t.hooks.preprocess(e)), c = l(e, t);
  2139. } catch (d) {
  2140. return a(d);
  2141. }
  2142. const m = function(d) {
  2143. let p;
  2144. if (!d)
  2145. try {
  2146. t.walkTokens && g.walkTokens(c, t.walkTokens), p = n(c, t), t.hooks && (p = t.hooks.postprocess(p));
  2147. } catch (o) {
  2148. d = o;
  2149. }
  2150. return t.highlight = r, d ? a(d) : i(null, p);
  2151. };
  2152. if (!r || r.length < 3 || (delete t.highlight, !c.length))
  2153. return m();
  2154. let f = 0;
  2155. g.walkTokens(c, function(d) {
  2156. d.type === "code" && (f++, setTimeout(() => {
  2157. r(d.text, d.lang, function(p, o) {
  2158. if (p)
  2159. return m(p);
  2160. o != null && o !== d.text && (d.text = o, d.escaped = !0), f--, f === 0 && m();
  2161. });
  2162. }, 0));
  2163. }), f === 0 && m();
  2164. return;
  2165. }
  2166. if (t.async)
  2167. return Promise.resolve(t.hooks ? t.hooks.preprocess(e) : e).then((r) => l(r, t)).then((r) => t.walkTokens ? Promise.all(g.walkTokens(r, t.walkTokens)).then(() => r) : r).then((r) => n(r, t)).then((r) => t.hooks ? t.hooks.postprocess(r) : r).catch(a);
  2168. try {
  2169. t.hooks && (e = t.hooks.preprocess(e));
  2170. const r = l(e, t);
  2171. t.walkTokens && g.walkTokens(r, t.walkTokens);
  2172. let c = n(r, t);
  2173. return t.hooks && (c = t.hooks.postprocess(c)), c;
  2174. } catch (r) {
  2175. return a(r);
  2176. }
  2177. };
  2178. }
  2179. function g(l, n, e) {
  2180. return X($.lex, E.parse)(l, n, e);
  2181. }
  2182. g.options = g.setOptions = function(l) {
  2183. return g.defaults = { ...g.defaults, ...l }, nt(g.defaults), g;
  2184. };
  2185. g.getDefaults = W;
  2186. g.defaults = A;
  2187. g.use = function(...l) {
  2188. const n = g.defaults.extensions || { renderers: {}, childTokens: {} };
  2189. l.forEach((e) => {
  2190. const t = { ...e };
  2191. if (t.async = g.defaults.async || t.async || !1, e.extensions && (e.extensions.forEach((i) => {
  2192. if (!i.name)
  2193. throw new Error("extension name required");
  2194. if (i.renderer) {
  2195. const s = n.renderers[i.name];
  2196. s ? n.renderers[i.name] = function(...a) {
  2197. let r = i.renderer.apply(this, a);
  2198. return r === !1 && (r = s.apply(this, a)), r;
  2199. } : n.renderers[i.name] = i.renderer;
  2200. }
  2201. if (i.tokenizer) {
  2202. if (!i.level || i.level !== "block" && i.level !== "inline")
  2203. throw new Error("extension level must be 'block' or 'inline'");
  2204. n[i.level] ? n[i.level].unshift(i.tokenizer) : n[i.level] = [i.tokenizer], i.start && (i.level === "block" ? n.startBlock ? n.startBlock.push(i.start) : n.startBlock = [i.start] : i.level === "inline" && (n.startInline ? n.startInline.push(i.start) : n.startInline = [i.start]));
  2205. }
  2206. i.childTokens && (n.childTokens[i.name] = i.childTokens);
  2207. }), t.extensions = n), e.renderer) {
  2208. const i = g.defaults.renderer || new q();
  2209. for (const s in e.renderer) {
  2210. const a = i[s];
  2211. i[s] = (...r) => {
  2212. let c = e.renderer[s].apply(i, r);
  2213. return c === !1 && (c = a.apply(i, r)), c;
  2214. };
  2215. }
  2216. t.renderer = i;
  2217. }
  2218. if (e.tokenizer) {
  2219. const i = g.defaults.tokenizer || new P();
  2220. for (const s in e.tokenizer) {
  2221. const a = i[s];
  2222. i[s] = (...r) => {
  2223. let c = e.tokenizer[s].apply(i, r);
  2224. return c === !1 && (c = a.apply(i, r)), c;
  2225. };
  2226. }
  2227. t.tokenizer = i;
  2228. }
  2229. if (e.hooks) {
  2230. const i = g.defaults.hooks || new N();
  2231. for (const s in e.hooks) {
  2232. const a = i[s];
  2233. N.passThroughHooks.has(s) ? i[s] = (r) => {
  2234. if (g.defaults.async)
  2235. return Promise.resolve(e.hooks[s].call(i, r)).then((m) => a.call(i, m));
  2236. const c = e.hooks[s].call(i, r);
  2237. return a.call(i, c);
  2238. } : i[s] = (...r) => {
  2239. let c = e.hooks[s].apply(i, r);
  2240. return c === !1 && (c = a.apply(i, r)), c;
  2241. };
  2242. }
  2243. t.hooks = i;
  2244. }
  2245. if (e.walkTokens) {
  2246. const i = g.defaults.walkTokens;
  2247. t.walkTokens = function(s) {
  2248. let a = [];
  2249. return a.push(e.walkTokens.call(this, s)), i && (a = a.concat(i.call(this, s))), a;
  2250. };
  2251. }
  2252. g.setOptions(t);
  2253. });
  2254. };
  2255. g.walkTokens = function(l, n) {
  2256. let e = [];
  2257. for (const t of l)
  2258. switch (e = e.concat(n.call(g, t)), t.type) {
  2259. case "table": {
  2260. for (const i of t.header)
  2261. e = e.concat(g.walkTokens(i.tokens, n));
  2262. for (const i of t.rows)
  2263. for (const s of i)
  2264. e = e.concat(g.walkTokens(s.tokens, n));
  2265. break;
  2266. }
  2267. case "list": {
  2268. e = e.concat(g.walkTokens(t.items, n));
  2269. break;
  2270. }
  2271. default:
  2272. g.defaults.extensions && g.defaults.extensions.childTokens && g.defaults.extensions.childTokens[t.type] ? g.defaults.extensions.childTokens[t.type].forEach(function(i) {
  2273. e = e.concat(g.walkTokens(t[i], n));
  2274. }) : t.tokens && (e = e.concat(g.walkTokens(t.tokens, n)));
  2275. }
  2276. return e;
  2277. };
  2278. g.parseInline = X($.lexInline, E.parseInline);
  2279. g.Parser = E;
  2280. g.parser = E.parse;
  2281. g.Renderer = q;
  2282. g.TextRenderer = F;
  2283. g.Lexer = $;
  2284. g.lexer = $.lex;
  2285. g.Tokenizer = P;
  2286. g.Slugger = Y;
  2287. g.Hooks = N;
  2288. g.parse = g;
  2289. g.options;
  2290. g.setOptions;
  2291. g.use;
  2292. g.walkTokens;
  2293. g.parseInline;
  2294. E.parse;
  2295. $.lex;
  2296. const xt = () => {
  2297. let l, n = null, e;
  2298. function t() {
  2299. if (n && !n.closed)
  2300. n.focus();
  2301. else {
  2302. if (n = window.open("about:blank", "reveal.js - Notes", "width=1100,height=700"), n.marked = g, n.document.write(et), !n) {
  2303. alert("Speaker view popup failed to open. Please make sure popups are allowed and reopen the speaker view.");
  2304. return;
  2305. }
  2306. s();
  2307. }
  2308. }
  2309. function i(d) {
  2310. n && !n.closed ? n.focus() : (n = d, window.addEventListener("message", m), f());
  2311. }
  2312. function s() {
  2313. const d = e.getConfig().url, p = typeof d == "string" ? d : window.location.protocol + "//" + window.location.host + window.location.pathname + window.location.search;
  2314. l = setInterval(function() {
  2315. n.postMessage(JSON.stringify({
  2316. namespace: "reveal-notes",
  2317. type: "connect",
  2318. state: e.getState(),
  2319. url: p
  2320. }), "*");
  2321. }, 500), window.addEventListener("message", m);
  2322. }
  2323. function a(d, p, o) {
  2324. let x = e[d].apply(e, p);
  2325. n.postMessage(JSON.stringify({
  2326. namespace: "reveal-notes",
  2327. type: "return",
  2328. result: x,
  2329. callId: o
  2330. }), "*");
  2331. }
  2332. function r(d) {
  2333. let p = e.getCurrentSlide(), o = p.querySelectorAll("aside.notes"), x = p.querySelector(".current-fragment"), b = {
  2334. namespace: "reveal-notes",
  2335. type: "state",
  2336. notes: "",
  2337. markdown: !1,
  2338. whitespace: "normal",
  2339. state: e.getState()
  2340. };
  2341. if (p.hasAttribute("data-notes") && (b.notes = p.getAttribute("data-notes"), b.whitespace = "pre-wrap"), x) {
  2342. let v = x.querySelector("aside.notes");
  2343. v ? (b.notes = v.innerHTML, b.markdown = typeof v.getAttribute("data-markdown") == "string", o = null) : x.hasAttribute("data-notes") && (b.notes = x.getAttribute("data-notes"), b.whitespace = "pre-wrap", o = null);
  2344. }
  2345. o && o.length && (o = Array.from(o).filter((v) => v.closest(".fragment") === null), b.notes = o.map((v) => v.innerHTML).join(`
  2346. `), b.markdown = o[0] && typeof o[0].getAttribute("data-markdown") == "string"), n.postMessage(JSON.stringify(b), "*");
  2347. }
  2348. function c(d) {
  2349. try {
  2350. return window.location.origin === d.source.location.origin;
  2351. } catch {
  2352. return !1;
  2353. }
  2354. }
  2355. function m(d) {
  2356. if (c(d))
  2357. try {
  2358. let p = JSON.parse(d.data);
  2359. p && p.namespace === "reveal-notes" && p.type === "connected" ? (clearInterval(l), f()) : p && p.namespace === "reveal-notes" && p.type === "call" && a(p.methodName, p.arguments, p.callId);
  2360. } catch {
  2361. }
  2362. }
  2363. function f() {
  2364. e.on("slidechanged", r), e.on("fragmentshown", r), e.on("fragmenthidden", r), e.on("overviewhidden", r), e.on("overviewshown", r), e.on("paused", r), e.on("resumed", r), r();
  2365. }
  2366. return {
  2367. id: "notes",
  2368. init: function(d) {
  2369. e = d, /receiver/i.test(window.location.search) || (window.location.search.match(/(\?|\&)notes/gi) !== null ? t() : window.addEventListener("message", (p) => {
  2370. if (!n && typeof p.data == "string") {
  2371. let o;
  2372. try {
  2373. o = JSON.parse(p.data);
  2374. } catch {
  2375. }
  2376. o && o.namespace === "reveal-notes" && o.type === "heartbeat" && i(p.source);
  2377. }
  2378. }), e.addKeyBinding({ keyCode: 83, key: "S", description: "Speaker notes view" }, function() {
  2379. t();
  2380. }));
  2381. },
  2382. open: t
  2383. };
  2384. };
  2385. export {
  2386. xt as default
  2387. };