Debian Codegraph @

texmf-dist/source/generic/markdown/markdown.dtx

raw
1 % \iffalse
2 %<*driver>
3 \documentclass{ltxdockit}
4 \usepackage[american]{babel}
5 \usepackage{amsmath,btxdockit,doc,fancyvrb,graphicx,hologo,microtype,minted}
6
7 % Set up the style.
8 \usepackage{xcolor}
9 \definecolor{spot}{rgb}{0,0.2,0.6}
10 \usepackage{fontspec}
11 \defaultfontfeatures[\rmfamily,\sffamily,\ttfamily]{}
12 \emergencystretch=1em
13 \fvset{gobble=0,frame=single}
14 \setcounter{secnumdepth}{4}
15 \addtokomafont{title}{\sffamily}
16 \addtokomafont{paragraph}{\spotcolor}
17 \addtokomafont{section}{\spotcolor}
18 \addtokomafont{subsection}{\spotcolor}
19 \addtokomafont{subsubsection}{\spotcolor}
20 \addtokomafont{descriptionlabel}{\spotcolor}
21 \setkomafont{caption}{\bfseries\sffamily\spotcolor}
22 \setkomafont{captionlabel}{\bfseries\sffamily\spotcolor}
23 \hypersetup{citecolor=spot}
24 \let\oldCodelineNo\theCodelineNo
25 \def\theCodelineNo{\textcolor[gray]{0.5}{\oldCodelineNo}}
26 \makeatletter\renewcommand\fps@figure{htbp}\makeatother
27 \setkeys{Gin}{
28 width = \columnwidth,
29 height = 0.65\paperheight,
30 keepaspectratio,
31 }
32
33 % Define some markup.
34 \let\pkg\relax % A package name
35 \def\inline#1{% Inline code
36 \textcolor{spot}{\text{\texttt{#1}}}}
37 \newcommand\acro[1]{% An acronym
38 \markdownRendererAcronymPrototype{#1}}
39
40 % Set up index.
41 \DisableCrossrefs
42 \usepackage{makeidx}
43 \usepackage[columns=1, totoc]{idxlayout}
44 \makeindex
45
46 \ExplSyntaxOn
47 \seq_new:N
48 \g__markdown_techdoc_seen_options_seq
49 \newcommand\mdef[1]{% A TeX macro definition
50 \index{#1@\cs{#1}|textit}%
51 \phantomsection
52 \label{macro:#1}
53 \__markdown_csname_to_option_str:nNT
54 { #1 }
55 \l_tmpa_tl
56 {
57 \seq_if_in:NVF
58 \g__markdown_techdoc_seen_options_seq
59 \l_tmpa_tl
60 {
61 % For `\mdef{markdownOption...}`, also do `\label{opt:...}`, unless
62 % such label was previously defined by `\Optitem` or `\Valitem`.
63 \tl_put_left:Nn
64 \l_tmpa_tl
65 { opt: }
66 \exp_args:NV
67 \label
68 \l_tmpa_tl
69 }
70 }
71 \textcolor{spot}{\cs{#1}}}
72 \ExplSyntaxOff
73 \newcommand\mref[1]{% A TeX macro reference
74 \index{#1@\cs{#1}}%
75 \hyperref[macro:#1]{\textcolor{spot}{\cs{#1}}}}
76
77 \newcommand\envmdef[1]{% A LaTeX environment definition
78 \index{#1@\texttt{#1}|textit}%
79 \phantomsection\label{environment:#1}\inline{#1}}
80 \newcommand\envmref[1]{% A LaTeX environment reference
81 \index{#1@\texttt{#1}}%
82 \hyperref[environment:#1]{\inline{#1}}}
83
84 \newcommand\luamdef[1]{% A Lua object / method definition
85 \index{#1@\texttt{#1}|textit}%
86 \phantomsection\label{lua:#1}\inline{#1}}
87 \newcommand\luamref[1]{% A Lua object / method reference
88 \index{#1@\texttt{#1}}%
89 \hyperref[lua:#1]{\inline{#1}}}
90
91 \ExplSyntaxOn
92 \newcommand\Optitem[2][]{\penalty -1000\relax % An option item definition
93 \index{#2@\texttt{#2}|textit}%
94 \phantomsection\label{opt:#2}%
95 \str_set:Nn
96 \l_tmpa_str
97 { #2 }
98 \seq_gput_right:NV
99 \g__markdown_techdoc_seen_options_seq
100 \l_tmpa_str
101 \optitem[#1]{#2}}
102 \newcommand\Valitem[2][]{\penalty -1000\relax % A value item definition
103 \index{#2@\texttt{#2}}%
104 \phantomsection\label{opt:#2}%
105 \str_set:Nn
106 \l_tmpa_str
107 { #2 }
108 \seq_gput_right:NV
109 \g__markdown_techdoc_seen_options_seq
110 \l_tmpa_str
111 \valitem[#1]{#2}}
112 \ExplSyntaxOff
113 \newcommand\Opt[1]{% An option / value item reference
114 \index{#1@\texttt{#1}}%
115 \hyperref[opt:#1]{\inline{#1}}}
116
117 % Set up markdown.
118 \usepackage[
119 citations,
120 definitionLists,
121 experimental,
122 notes,
123 headerAttributes,
124 hybrid,
125 inlineNotes,
126 jekyllData,
127 linkAttributes,
128 relativeReferences,
129 stripPercentSigns,
130 underscores = false,
131 ]{markdown}
132 \markdownSetup{
133 import = {
134 witiko/diagrams@v2,
135 witiko/graphicx/http,
136 witiko/markdown/techdoc = {
137 options as lua-options
138 },
139 },
140 }
141
142 % Set up Unicode characters.
143 \usepackage{newunicodechar}
144 \newunicodechar{☒}{\markdownRendererTickedBox}
145 \newunicodechar{⌛}{\markdownRendererHalfTickedBox}
146 \newunicodechar{☐}{\markdownRendererUntickedBox}
147 \usepackage{emoji}
148 \makeatletter
149 \@ifpackagelater{emoji}{2020/03/16}{
150 \newunicodechar{😉}{\emoji{winking-face}}
151 }{
152 \newunicodechar{😉}{;-)}
153 }
154 \makeatother
155
156 % Set up the catcodes.
157 \catcode`\_=12 % We won't be typesetting much math and Lua contains lots of `_`.
158 \catcode`\^^B=8 % When we occasionally need subscripts, we will use `^^B` (STX).
159
160 % Set up the title page.
161 \begin{markdown}
162 ---
163 title: A Markdown Interpreter for \TeX
164 url: https://github.com/witiko/markdown
165 authors: [Vít Starý Novotný, Andrej Genčur]
166 email: [email protected]
167 revision: \markdownVersion
168 date: \markdownLastModified
169 ---
170 \end{markdown}
171 \CodelineIndex
172
173 % Set up the figures.
174 \usepackage{tikz}
175 \usepackage{mathabx,pgf-umlsd,tikz}
176 \usetikzlibrary{automata,arrows.meta,positioning,shapes.geometric}
177
178 % Set up the bibliography.
179 \usepackage[
180 backend=biber,
181 style=numeric,
182 sorting=none,
183 autolang=other,
184 sortlocale=auto]{biblatex}
185 \addbibresource{markdown.bib}
186
187 \begin{document}
188 \DocInput{markdown.dtx}
189 \printbibliography[heading=bibintoc]
190 \printindex
191 \end{document}
192 %</driver>
193 %<*manual-css>
194
195 html {
196 font-size: 100%;
197 overflow-y: scroll;
198 -webkit-text-size-adjust: 100%;
199 -ms-text-size-adjust: 100%;
200 }
201
202 body {
203 color: #444;
204 font-family: Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
205 font-size: 12px;
206 line-height: 1.7;
207 padding: 1em;
208 margin: auto;
209 max-width: 42em;
210 background: #fefefe;
211 }
212
213 a {
214 color: #0645ad;
215 }
216
217 a:visited {
218 color: #0b0080;
219 }
220
221 a:hover {
222 color: #06e;
223 }
224
225 a:active {
226 color: #faa700;
227 }
228
229 a:focus {
230 outline: thin dotted;
231 }
232
233 *::-moz-selection {
234 background: rgba(255, 255, 0, 0.3);
235 color: #000;
236 }
237
238 *::selection {
239 background: rgba(255, 255, 0, 0.3);
240 color: #000;
241 }
242
243 a::-moz-selection {
244 background: rgba(255, 255, 0, 0.3);
245 color: #0645ad;
246 }
247
248 a::selection {
249 background: rgba(255, 255, 0, 0.3);
250 color: #0645ad;
251 }
252
253 p {
254 margin: 1em 0;
255 }
256
257 img {
258 max-width: 100%;
259 }
260
261 h1, h2, h3, h4, h5, h6 {
262 color: #111;
263 line-height: 125%;
264 margin-top: 2em;
265 font-weight: normal;
266 }
267
268 h4, h5, h6 {
269 font-weight: bold;
270 }
271
272 h1 {
273 font-size: 2.5em;
274 }
275
276 h2 {
277 font-size: 2em;
278 }
279
280 h3 {
281 font-size: 1.5em;
282 }
283
284 h4 {
285 font-size: 1.2em;
286 }
287
288 h5 {
289 font-size: 1em;
290 }
291
292 h6 {
293 font-size: 0.9em;
294 }
295
296 blockquote {
297 color: #666666;
298 margin: 0;
299 padding-left: 3em;
300 border-left: 0.5em #EEE solid;
301 }
302
303 hr {
304 display: block;
305 height: 2px;
306 border: 0;
307 border-top: 1px solid #aaa;
308 border-bottom: 1px solid #eee;
309 margin: 1em 0;
310 padding: 0;
311 }
312
313 pre, code, kbd, samp {
314 color: #000;
315 font-family: monospace, monospace;
316 _font-family: 'courier new', monospace;
317 font-size: 0.98em;
318 }
319
320 pre {
321 white-space: pre;
322 white-space: pre-wrap;
323 word-wrap: break-word;
324 counter-reset: line;
325 }
326
327 .sourceCode.linenos > span {
328 counter-increment: line;
329 }
330
331 .sourceCode.linenos > span:before{
332 content: counter(line) " ";
333 }
334
335 b, strong {
336 font-weight: bold;
337 }
338
339 dfn {
340 font-style: italic;
341 }
342
343 ins {
344 background: #ff9;
345 color: #000;
346 text-decoration: none;
347 }
348
349 mark {
350 background: #ff0;
351 color: #000;
352 font-style: italic;
353 font-weight: bold;
354 }
355
356 sub, sup {
357 font-size: 75%;
358 line-height: 0;
359 position: relative;
360 vertical-align: baseline;
361 }
362
363 sup {
364 top: -0.5em;
365 }
366
367 sub {
368 bottom: -0.25em;
369 }
370
371 ul, ol {
372 margin: 1em 0;
373 padding: 0 0 0 2em;
374 }
375
376 li p:last-child {
377 margin-bottom: 0;
378 }
379
380 ul ul, ol ol {
381 margin: .3em 0;
382 }
383
384 dl {
385 margin-bottom: 1em;
386 }
387
388 dt {
389 font-weight: bold;
390 margin-bottom: .8em;
391 }
392
393 dd {
394 margin: 0 0 .8em 2em;
395 }
396
397 dd:last-child {
398 margin-bottom: 0;
399 }
400
401 img {
402 border: 0;
403 -ms-interpolation-mode: bicubic;
404 vertical-align: middle;
405 }
406
407 figure {
408 display: block;
409 text-align: center;
410 margin: 1em 0;
411 }
412
413 figure img {
414 border: none;
415 margin: 0 auto;
416 }
417
418 figcaption {
419 font-size: 0.8em;
420 font-style: italic;
421 margin: 0 0 .8em;
422 }
423
424 table {
425 margin-bottom: 2em;
426 border-bottom: 1px solid #ddd;
427 border-right: 1px solid #ddd;
428 border-spacing: 0;
429 border-collapse: collapse;
430 }
431
432 table th {
433 padding: .2em 1em;
434 background-color: #eee;
435 border-top: 1px solid #ddd;
436 border-left: 1px solid #ddd;
437 }
438
439 table td {
440 padding: .2em 1em;
441 border-top: 1px solid #ddd;
442 border-left: 1px solid #ddd;
443 vertical-align: top;
444 }
445
446 .author {
447 font-size: 1.2em;
448 text-align: center;
449 }
450
451 @media only screen and (min-width: 480px) {
452 body {
453 font-size: 14px;
454 }
455 }
456 @media only screen and (min-width: 768px) {
457 body {
458 font-size: 16px;
459 }
460 }
461 @media print {
462 * {
463 background: transparent !important;
464 color: black !important;
465 filter: none !important;
466 -ms-filter: none !important;
467 }
468
469 body {
470 font-size: 12pt;
471 max-width: 100%;
472 }
473
474 a, a:visited {
475 text-decoration: underline;
476 }
477
478 hr {
479 height: 1px;
480 border: 0;
481 border-bottom: 1px solid black;
482 }
483
484 a[href]:after {
485 content: " (" attr(href) ")";
486 }
487
488 abbr[title]:after {
489 content: " (" attr(title) ")";
490 }
491
492 .ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after {
493 content: "";
494 }
495
496 pre, blockquote {
497 border: 1px solid #999;
498 padding-right: 1em;
499 page-break-inside: avoid;
500 }
501
502 tr, img {
503 page-break-inside: avoid;
504 }
505
506 img {
507 max-width: 100% !important;
508 }
509
510 @page :left {
511 margin: 15mm 20mm 15mm 10mm;
512 }
513
514 @page :right {
515 margin: 15mm 10mm 15mm 20mm;
516 }
517
518 p, h2, h3 {
519 orphans: 3;
520 widows: 3;
521 }
522
523 h2, h3 {
524 page-break-after: avoid;
525 }
526 }
527
528 .tex sub, .latex sub, .latex sup {
529 text-transform: uppercase;
530 }
531
532 .tex sub, .latex sub {
533 vertical-align: -0.1ex;
534 margin-left: -0.1667em;
535 margin-right: -0.125em;
536 }
537
538 .tex, .latex, .tex sub, .latex sub {
539 font-size: 1em;
540 }
541
542 .latex sup {
543 font-size: 0.85em;
544 vertical-align: -0.35em;
545 margin-left: -0.36em;
546 margin-right: -0.15em;
547 }
548
549 abbr {
550 text-transform: lowercase;
551 font-variant: small-caps;
552 }
553
554 %</manual-css>
555 %<*techdoc-block-diagram>
556 \begingroup
557 \ifx\du\undefined\newlength{\du}\fi
558 \setlength{\du}{15\unitlength}
559 \begin{tikzpicture}
560 \pgftransformxscale{1.000000}
561 \pgftransformyscale{-1.23800}
562 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
563 \pgfsetstrokecolor{dialinecolor}
564 \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
565 \pgfsetfillcolor{dialinecolor}
566 \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
567 \pgfsetfillcolor{dialinecolor}
568 \fill (4.282853\du,-3.750000\du)--(4.282853\du,-1.850000\du)--(11.971656\du,-1.850000\du)--(11.971656\du,-3.750000\du)--cycle;
569 \pgfsetlinewidth{0.040000\du}
570 \pgfsetdash{}{0pt}
571 \pgfsetdash{}{0pt}
572 \pgfsetmiterjoin
573 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
574 \pgfsetstrokecolor{dialinecolor}
575 \draw (4.282853\du,-3.750000\du)--(4.282853\du,-1.850000\du)--(11.971656\du,-1.850000\du)--(11.971656\du,-3.750000\du)--cycle;
576 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
577 \pgfsetstrokecolor{dialinecolor}
578 \node at (8.127254\du,-2.705000\du){\LaTeX{} layer};
579 \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
580 \pgfsetfillcolor{dialinecolor}
581 \fill (-5.055135\du,-3.788555\du)--(-5.055135\du,-1.888555\du)--(2.894865\du,-1.888555\du)--(2.894865\du,-3.788555\du)--cycle;
582 \pgfsetlinewidth{0.040000\du}
583 \pgfsetdash{}{0pt}
584 \pgfsetdash{}{0pt}
585 \pgfsetmiterjoin
586 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
587 \pgfsetstrokecolor{dialinecolor}
588 \draw (-5.055135\du,-3.788555\du)--(-5.055135\du,-1.888555\du)--(2.894865\du,-1.888555\du)--(2.894865\du,-3.788555\du)--cycle;
589 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
590 \pgfsetstrokecolor{dialinecolor}
591 \node at (-1.080135\du,-2.743555\du){\Hologo{ConTeXt} layer};
592 \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
593 \pgfsetfillcolor{dialinecolor}
594 \fill (-8.200000\du,-0.224996\du)--(-8.200000\du,1.675004\du)--(11.870000\du,1.675004\du)--(11.870000\du,-0.224996\du)--cycle;
595 \pgfsetlinewidth{0.040000\du}
596 \pgfsetdash{}{0pt}
597 \pgfsetdash{}{0pt}
598 \pgfsetmiterjoin
599 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
600 \pgfsetstrokecolor{dialinecolor}
601 \draw (-8.200000\du,-0.224996\du)--(-8.200000\du,1.675004\du)--(11.870000\du,1.675004\du)--(11.870000\du,-0.224996\du)--cycle;
602 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
603 \pgfsetstrokecolor{dialinecolor}
604 \node at (1.835000\du,0.820004\du){Plain \TeX{} layer};
605 \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
606 \pgfsetfillcolor{dialinecolor}
607 \fill (-11.150000\du,3.325006\du)--(-11.150000\du,5.225006\du)--(11.800000\du,5.225006\du)--(11.800000\du,3.325006\du)--cycle;
608 \pgfsetlinewidth{0.040000\du}
609 \pgfsetdash{}{0pt}
610 \pgfsetdash{}{0pt}
611 \pgfsetmiterjoin
612 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
613 \pgfsetstrokecolor{dialinecolor}
614 \draw (-11.150000\du,3.325006\du)--(-11.150000\du,5.225006\du)--(11.800000\du,5.225006\du)--(11.800000\du,3.325006\du)--cycle;
615 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
616 \pgfsetstrokecolor{dialinecolor}
617 \node at (0.325000\du,4.370006\du){Lua layer};
618 \pgfsetlinewidth{0.040000\du}
619 \pgfsetdash{}{0pt}
620 \pgfsetdash{}{0pt}
621 \pgfsetbuttcap
622 {
623 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
624 \pgfsetfillcolor{dialinecolor}
625 \pgfsetarrowsstart{stealth}
626 \pgfsetarrowsend{stealth}
627 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
628 \pgfsetstrokecolor{dialinecolor}
629 \draw (-9.906400\du,-5.181570\du)--(-9.937836\du,3.024193\du);
630 }
631 \pgfsetlinewidth{0.040000\du}
632 \pgfsetdash{}{0pt}
633 \pgfsetdash{}{0pt}
634 \pgfsetbuttcap
635 {
636 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
637 \pgfsetfillcolor{dialinecolor}
638 \pgfsetarrowsstart{stealth}
639 \pgfsetarrowsend{stealth}
640 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
641 \pgfsetstrokecolor{dialinecolor}
642 \draw (-6.919693\du,-5.181570\du)--(-6.938734\du,-0.450800\du);
643 }
644 \pgfsetlinewidth{0.040000\du}
645 \pgfsetdash{}{0pt}
646 \pgfsetdash{}{0pt}
647 \pgfsetbuttcap
648 {
649 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
650 \pgfsetfillcolor{dialinecolor}
651 \pgfsetarrowsstart{stealth}
652 \pgfsetarrowsend{stealth}
653 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
654 \pgfsetstrokecolor{dialinecolor}
655 \draw (-1.063746\du,-5.175791\du)--(-1.063746\du,-3.975793\du);
656 }
657 \definecolor{dialinecolor}{rgb}{1.000000, 1.000000, 1.000000}
658 \pgfsetfillcolor{dialinecolor}
659 \fill (-10.972500\du,-7.267480\du)--(-10.972500\du,-5.367480\du)--(11.977500\du,-5.367480\du)--(11.977500\du,-7.267480\du)--cycle;
660 \pgfsetlinewidth{0.040000\du}
661 \pgfsetdash{}{0pt}
662 \pgfsetdash{}{0pt}
663 \pgfsetmiterjoin
664 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
665 \pgfsetstrokecolor{dialinecolor}
666 \draw (-10.972500\du,-7.267480\du)--(-10.972500\du,-5.367480\du)--(11.977500\du,-5.367480\du)--(11.977500\du,-7.267480\du)--cycle;
667 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
668 \pgfsetstrokecolor{dialinecolor}
669 \node at (0.502500\du,-6.322480\du){User code};
670 \pgfsetlinewidth{0.040000\du}
671 \pgfsetdash{}{0pt}
672 \pgfsetdash{}{0pt}
673 \pgfsetbuttcap
674 {
675 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
676 \pgfsetfillcolor{dialinecolor}
677 \pgfsetarrowsstart{stealth}
678 \pgfsetarrowsend{stealth}
679 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
680 \pgfsetstrokecolor{dialinecolor}
681 \draw (8.149986\du,-5.159541\du)--(8.149986\du,-3.959543\du);
682 }
683 \pgfsetlinewidth{0.040000\du}
684 \pgfsetdash{}{0pt}
685 \pgfsetdash{}{0pt}
686 \pgfsetbuttcap
687 {
688 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
689 \pgfsetfillcolor{dialinecolor}
690 \pgfsetarrowsstart{stealth}
691 \pgfsetarrowsend{stealth}
692 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
693 \pgfsetstrokecolor{dialinecolor}
694 \draw (-1.074995\du,-1.634548\du)--(-1.074995\du,-0.434550\du);
695 }
696 \pgfsetlinewidth{0.040000\du}
697 \pgfsetdash{}{0pt}
698 \pgfsetdash{}{0pt}
699 \pgfsetbuttcap
700 {
701 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
702 \pgfsetfillcolor{dialinecolor}
703 \pgfsetarrowsstart{stealth}
704 \pgfsetarrowsend{stealth}
705 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
706 \pgfsetstrokecolor{dialinecolor}
707 \draw (8.138736\du,-1.618298\du)--(8.138736\du,-0.418300\du);
708 }
709 \pgfsetlinewidth{0.040000\du}
710 \pgfsetdash{}{0pt}
711 \pgfsetdash{}{0pt}
712 \pgfsetbuttcap
713 {
714 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
715 \pgfsetfillcolor{dialinecolor}
716 \pgfsetarrowsstart{stealth}
717 \pgfsetarrowsend{stealth}
718 \definecolor{dialinecolor}{rgb}{0.000000, 0.000000, 0.000000}
719 \pgfsetstrokecolor{dialinecolor}
720 \draw (1.689638\du,1.881695\du)--(1.689638\du,3.081693\du);
721 }
722 \end{tikzpicture}
723 \endgroup
724 %</techdoc-block-diagram>
725 %<*techdoc-bibliography>
726 @online{starynovotny24,
727 author = {Starý Novotný, Vít and Enrico Gregorio and Max Chernoff and P. Spratte, Jonathan},
728 title = {Convert control sequence with a variable number of undelimited parameters into a token list},
729 url = {https://tex.stackexchange.com/q/716362/70941},
730 urldate = {2024-04-28},
731 }
732 @online{starynovotny25,
733 author = {Starý Novotný, Vít},
734 title = {Routing \acro{YAML} metadata to expl3 key–values},
735 titleaddon = {Markdown Enhancement Proposal},
736 url = {https://github.com/witiko/markdown/discussions/517},
737 date = {2024-10-14},
738 urldate = {2025-01-06},
739 }
740 @book{tantau21,
741 author = {Till Tantau and Joseph Wright and Vedran Miletić},
742 title = {The Beamer class},
743 date = {2021-02-10},
744 url = {https://mirrors.ctan.org/macros/latex/contrib/beamer/doc/beameruserguide.pdf},
745 urldate = {2021-02-11}}
746 @online{sotkov17,
747 author = {Sotkov, Anton},
748 title = {File transclusion syntax for Markdown},
749 date = {2017-01-19},
750 url = {https://github.com/iainc/Markdown-Content-Blocks},
751 urldate = {2018-01-08}}
752 @book{luatex25,
753 author = {{Lua\TeX{} development team}},
754 title = {Lua\TeX{} reference manual},
755 date = {2025-02-01},
756 note = {Version 1.21},
757 url = {http://mirrors.ctan.org/systems/doc/luatex/luatex.pdf},
758 urldate = {2025-05-12}}
759 @book{latex17,
760 author = {Braams, Johannes and Carlisle, David and Jeffrey, Alan and
761 Lamport, Leslie and Mittelbach, Frank and Rowley, Chris and
762 Schöpf, Rainer},
763 title = {The \Hologo{LaTeX2e} Sources},
764 date = {2017-04-15},
765 url = {https://mirrors.ctan.org/macros/latex/base/source2e.pdf},
766 urldate = {2018-01-08}}
767 @book{mittelbach17,
768 author = {Mittelbach, Frank},
769 title = {The \texttt{doc} and \texttt{shortvrb} Packages},
770 date = {2017-04-15},
771 url = {https://mirrors.ctan.org/macros/latex/base/doc.pdf},
772 urldate = {2018-02-19}}
773 @book{mittelbach24,
774 author = {Mittelbach, Frank},
775 title = {\LaTeX's hook management},
776 date = {2024-06-26},
777 url = {https://mirrors.ctan.org/macros/latex/base/lthooks-code.pdf},
778 urldate = {2024-10-02}}
779 @book{poore17,
780 author = {Poore, Geoffrey M.},
781 title = {The \texttt{minted} Package},
782 subtitle = {Highlighted source code in \LaTeX},
783 date = {2017-07-19},
784 version = {v2.5},
785 url = {https://mirrors.ctan.org/macros/latex/contrib/minted/minted.pdf},
786 urldate = {2020-09-01}}
787 @online{macfarlane22,
788 title = {Pandoc},
789 subtitle = {a universal document converter},
790 author = {John MacFarlane},
791 year = {2022},
792 url = {https://pandoc.org/},
793 urldate = {2022-10-05}}
794 @online{novotny15,
795 author = {Novotný, Vít},
796 year = {2015},
797 title = {TeXový interpret jazyka Markdown (markdown.sty)},
798 location = {Brno, Czech Republic},
799 publisher = {Masaryk University},
800 url = {https://www.muni.cz/en/research/projects/32984},
801 urldate = {2018-02-19}}
802 @book{ierusalimschy13,
803 author = {Ierusalimschy, Roberto},
804 year = {2013},
805 title = {Programming in Lua},
806 edition = {3},
807 isbn = {978-85-903798-5-0},
808 pagetotal = {xviii, 347},
809 location = {Rio de Janeiro},
810 publisher = {PUC-Rio}}
811 @book{knuth86a,
812 author = {Knuth, Donald Ervin},
813 year = {1986},
814 title = {The \TeX{}book},
815 edition = {3},
816 isbn = {0-201-13447-0},
817 pagetotal = {ix, 479},
818 series = {Computers \& Typesetting},
819 volume = {A},
820 location = {Reading, MA},
821 publisher = {Addison-Wesley}}
822 @book{knuth86b,
823 author = {Knuth, Donald Ervin},
824 year = {1986},
825 title = {\TeX: The Program},
826 isbn = {978-0-201-13437-7},
827 pagetotal = {xvi, 594},
828 series = {Computers \& Typesetting},
829 volume = {B},
830 location = {Reading, MA},
831 publisher = {Addison-Wesley}}
832 @book{eijkhout92,
833 author = {Victor Eijkhout},
834 title = {\TeX{} by Topic},
835 subtitle = {A \TeX nician's Reference},
836 isbn = {978-0-201-56882-0},
837 pagetotal = {307},
838 date = {1992-02-01},
839 location = {Wokingham, England},
840 publisher = {Addison-Wesley}}
841 @inproceedings{sharif10,
842 author = {Sharif, Bonita and Maletic, Jonathan I.},
843 booktitle = {2010 IEEE 18th International Conference on Program Comprehension},
844 title = {An Eye Tracking Study on camelCase and under\_score Identifier Styles},
845 year = {2010},
846 pages = {196-205},
847 doi = {10.1109/ICPC.2010.41}}
848 @online{novotny24,
849 author = {Starý Novotný, Vít},
850 title = {Versioned Themes},
851 titleaddon = {Markdown Enhancement Proposal},
852 date = {2024-10-13},
853 urldate = {2024-10-21},
854 url = {https://github.com/Witiko/markdown/discussions/514}}
855 @book{latex24,
856 author = {Frank Mittelbach and Ulrike Fischer and {\LaTeX{} Project}},
857 title = {The \texttt{documentmetadata-support} code},
858 date = {2024-06-01},
859 url = {https://mirrors.ctan.org/macros/latex/required/latex-lab/documentmetadata-support-code.pdf},
860 urldate = {2024-10-21}}
861 @online{latex25,
862 author = {{\LaTeX{} Project}},
863 title = {l3kernel},
864 subtitle = {\LaTeX3 programming conventions},
865 date = {2024-12-25},
866 url = {https://ctan.org/pkg/l3kernel},
867 urldate = {2025-01-06}}
868 @online{latex26,
869 author = {{\LaTeX{} Project}},
870 title = {The \LaTeX3 Interfaces},
871 date = {2026-01-19},
872 url = {https://mirrors.ctan.org/macros/latex/required/l3kernel/interface3.pdf},
873 urldate = {2026-02-18}}
874 @online{unicode24,
875 author = {{Unicode Consortium}},
876 title = {The Unicode Standard},
877 subtitle = {Version 16.0 -- Core Specification},
878 date = {2024-09-10},
879 url = {https://www.unicode.org/versions/Unicode16.0.0/UnicodeStandard-16.0.pdf},
880 urldate = {2025-05-07}}
881 @online{context23,
882 author = {Hans Hagen},
883 title = {\Hologo{ConTeXt} Lua Documents},
884 date = {2023-07-08},
885 url = {https://www.pragma-ade.nl/general/manuals/cld-mkiv.pdf},
886 urldate = {2025-09-22}}
887 %</techdoc-bibliography>
888 %<@@=markdown>
889 %<*themes-witiko-markdown-techdoc>
890 \ProvidesPackage{markdownthemewitiko_markdown_techdoc}[2022/12/13]
891 \RequirePackage{etoolbox}
892 \gdef\ltd@title@author{\@gobble}%
893 \markdownSetup{
894 acronyms += {
895 API,
896 ASCII,
897 CDATA,
898 CLI,
899 CSV,
900 cURL,
901 GNU,
902 HTML,
903 HTTP, HTTPS,
904 JSON,
905 MD5,
906 NFC, NFD, NFKS, NFKD,
907 OS,
908 PCDATA,
909 PEG, PEGs,
910 PHP,
911 SVG,
912 UML, PlantUML,
913 UNIX,
914 URI,
915 URL,
916 UTF8,
917 YAML,
918 },
919 renderers = {
920 head*Four = {\paragraph{#1}\leavevmode},
921 },
922 rendererPrototypes = {
923 codeSpan = {\inline{#1}},
924 jekyllData(End) = {%
925 \AfterEndPreamble{%
926 \hypersetup{pdfauthor=\ltd@title@author}%
927 \printtitlepage
928 \tableofcontents
929 {\def\addcontentsline##1##2##3{}\listoffigures}%
930 }%
931 },
932 },
933 }
934 \ExplSyntaxOn
935 \keys_define:nn
936 { markdown / techdoc }
937 {
938 authors / unknown .code:n = {
939 \tl_gput_right:Nn
940 \ltd@title@author
941 { ,~#1 }
942 },
943 title .code:n = {
944 \tl_gset:Nn
945 \ltd@title@title
946 { #1 }
947 \tl_gset:Nn
948 \ltd@title@subtitle
949 { }
950 \hypersetup
951 { pdftitle = { #1 } }
952 },
953 date .tl_gset:N = \ltd@title@date,
954 email .tl_gset:N = \ltd@title@email,
955 revision .tl_gset:N = \ltd@title@revision,
956 url .tl_gset:N = \ltd@title@url,
957 }
958 \cs_generate_variant:Nn
959 \cs_gset:Npn
960 { NpV }
961 \yamlSetup
962 { jekyllDataKeyValue = markdown / techdoc }
963 \markdownSetup
964 {
965 rendererPrototypes = {
966 headerAttributeContextEnd = {
967 \seq_map_inline:Nn
968 \g_@@_header_identifiers_seq
969 { \label { sec:##1 } }
970 \seq_gclear:N
971 \g_@@_header_identifiers_seq
972 },
973 },
974 }
975 \ExplSyntaxOff
976 \renewcommand\markdownLaTeXRendererDirectOrIndirectLink[4]{%
977 #1\footnote{See \url{#3}.}}
978 \RequirePackage{varioref}
979 \vrefwarning
980 \markdownSetupSnippet{options}{
981 rendererPrototypes = {
982 dlBegin = {\begin{optionlist}},
983 dlItem = {
984 #1
985 \begingroup
986 \markdownSetup{
987 renderers = {
988 dlBegin = {
989 \begingroup
990 \markdownSetup{
991 renderers = {
992 dlItem = {\item[####1]},
993 dlItemEnd = {}}}
994 \begin{valuelist}
995 },
996 dlEnd = {
997 \end{valuelist}
998 \endgroup
999 },
1000 },
1001 }%
1002 },
1003 dlItemEnd = {\endgroup},
1004 dlEnd = {\end{optionlist}},
1005 }
1006 }
1007 %</themes-witiko-markdown-techdoc>
1008 %<*manual>
1009
1010 ---
1011 title: Markdown Package User Manual
1012 author: Vít Starý Novotný, Andrej Genčur
1013 date: \markdownVersion{} \markdownLastModified{}
1014 ---
1015
1016 <link href="https://afeld.github.io/emoji-css/emoji.css" rel="stylesheet" />
1017
1018 % \fi
1019 % \begin{markdown}
1020
1021 Introduction
1022 ============
1023 The [Markdown package][pkg] converts [CommonMark][] markup to \TeX{} commands. The
1024 functionality is provided both as a Lua module and as plain \TeX{}, \LaTeX{}, and
1025 \Hologo{ConTeXt} macro packages that can be used to directly typeset \TeX{} documents
1026 containing markdown markup. Unlike other converters, the Markdown package
1027 does not require any external programs, and makes it easy to redefine how each
1028 and every markdown element is rendered. Creative abuse of the markdown
1029 syntax is encouraged. 😉
1030
1031 [commonmark]: https://commonmark.org/
1032 (CommonMark: A strongly defined, highly compatible specification of Markdown)
1033 [pkg]: https://ctan.org/pkg/markdown
1034 (CTAN: Package markdown)
1035
1036 % This document is a technical documentation for the \pkg{Markdown} package. It
1037 % consists of three sections. This section introduces the package and outlines
1038 % its prerequisites. Section <#sec:interfaces> describes the interfaces
1039 % exposed by the package. Section <#sec:implementation> describes the
1040 % implementation of the package. The technical documentation contains only a
1041 % limited number of tutorials and code examples. You can find more of these in
1042 % the [user manual.][manual]
1043 %
1044 % [manual]: http://mirrors.ctan.org/macros/generic/markdown/markdown.html
1045 %
1046 % \end{markdown}
1047 % \iffalse
1048
1049 This document is a user manual for the [Markdown package][pkg]. It provides
1050 tutorials and code examples. For an in-depth description of the package
1051 requirements, interfaces, and implementation, please refer to the [technical
1052 documentation][techdoc].
1053
1054 [techdoc]: http://mirrors.ctan.org/macros/generic/markdown/markdown.pdf
1055 (A Markdown Interpreter for TeX)
1056
1057 %</manual>
1058 %<*lua,lua-cli,lua-loader,lua-unicode-data>
1059 % \fi
1060 % \begin{macrocode}
1061 local metadata = {
1062 version = "(((VERSION)))",
1063 comment = "A module for the conversion from markdown "
1064 .. "to plain TeX",
1065 author = "John MacFarlane, Hans Hagen, Vít Starý Novotný, "
1066 .. "Andrej Genčur",
1067 copyright = {"2009-2016 John MacFarlane, Hans Hagen",
1068 "2016-2026 Vít Starý Novotný, Andrej Genčur"},
1069 license = "LPPL 1.3c"
1070 }
1071
1072 % \end{macrocode}
1073 % \iffalse
1074 %</lua,lua-cli,lua-loader,lua-unicode-data>
1075 %<*lua>
1076 % \fi
1077 % \begin{macrocode}
1078 if not modules then modules = { } end
1079 modules['markdown'] = metadata
1080 % \end{macrocode}
1081 % \iffalse
1082 %</lua>
1083 %<*manual>
1084
1085 Requirements
1086 ------------
1087
1088 The package requires either [our official Docker image][docker], which contains
1089 the latest development version of the Markdown package, or a \TeX{}
1090 distribution: [\TeX{} Live][tl] ≥ 2023 is known to work with the current
1091 version of the Markdown package and so are recent versions of [Mik\TeX{}][mik].
1092 If you are using an older, incomplete, or atypical \TeX{} distribution, please
1093 consult the [technical documentation][techdoc] for a detailed list of
1094 requirements.
1095
1096 You are also advised to use Lua\TeX{} with the Markdown Package for \TeX{}. Using
1097 pdf\TeX{}, \Hologo{XeTeX} and other \TeX{} engines comes with several limitations:
1098
1099 1. The filenames of your .tex files may not contain spaces, see also [#573][issue-573].
1100 2. If `-output-directory` is provided, it may not contain spaces and it won't be
1101 automatically detected by Mik\TeX{}, see also [miktex/miktex#1630][issue-1630].[^issue-1630]
1102
1103 [docker]: https://hub.docker.com/r/witiko/markdown/tags (witiko/markdown - Docker Image)
1104 [tl]: https://www.tug.org/texlive/ (TeX Live - TeX Users Group)
1105 [mik]: https://miktex.org/ (Home - MiKTeXorg)
1106
1107 [issue-573]: https://github.com/Witiko/markdown/issues/573 (Compilation fails if the file name contains spaces)
1108 [issue-1630]: https://github.com/MiKTeX/miktex/issues/1630 (Environmental variable TEXMF_OUTPUT_DIRECTORY not set by MikTeX binaries)
1109
1110 [^issue-1630]: To support `-output-directory` in MikTeX with engines other than Lua\TeX{}, you set either the environmental variable `TEXMF_OUTPUT_DIRECTORY` or the \TeX{} macro `\markdownOptionOutputDir` to the same value.
1111
1112 Installation
1113 ------------
1114
1115 If the Markdown package is not included in your \TeX{} distribution, you will
1116 need to install it.
1117
1118 From [Releases][], download [an archive `markdown.zip` for this version of the
1119 Markdown package (\markdownShortVersion{})][this-release] or a different version
1120 that you wish to install. Then, unzip the archive. If you downloaded an archive
1121 for a different version of the Markdown package, you should now locate a file
1122 named `markdown.html` with the user manual for that version, open it, and
1123 follow the installation steps in it rather than the steps from this manual.
1124
1125 [releases]: https://github.com/witiko/markdown/releases (Releases - witiko/markdown)
1126 [this-release]: https://github.com/witiko/markdown/releases/download/\markdownShortVersion{}/markdown.zip (Release \markdownShortVersion{} - witiko/markdown)
1127
1128 Alternatively, download the package from the repository using Git, enter the
1129 directory named `markdown` and run the `make base` command using GNU Make:
1130 ``` sh
1131 git clone https://github.com/witiko/markdown
1132 cd markdown
1133 make base
1134 ``````
1135
1136 Either of the two abovelisted approaches should produce the following files:
1137
1138 * `markdown.lua`, `markdown-parser.lua`, and `markdown-unicode-data.lua`: The Lua module
1139 * `markdown-cli.lua` and `markdown2tex.lua`: The Lua command-line interface
1140 * `markdown.tex`: The plain \TeX{} macro package
1141 * `markdown.sty`: The \LaTeX{} package
1142 * `markdownthemewitiko_markdown_defaults.tex`,
1143 `markdownthemewitiko_markdown_defaults.sty`, and
1144 `t-markdownthemewitiko_markdown_defaults.tex`: The `witiko/markdown/defaults`
1145 theme
1146 * `t-markdown.tex`: The \Hologo{ConTeXt} module
1147
1148 ### Local Installation
1149
1150 To perform a local installation, place the above files into your \TeX{}
1151 directory structure. This is generally where the individual files should be
1152 placed:
1153
1154 * `⟨TEXMF⟩/tex/luatex/markdown/markdown.lua`
1155 * `⟨TEXMF⟩/tex/luatex/markdown/markdown-parser.lua`
1156 * `⟨TEXMF⟩/tex/luatex/markdown/markdown-unicode-data.lua`
1157 * `⟨TEXMF⟩/scripts/markdown/markdown-cli.lua`
1158 * `⟨TEXMF⟩/scripts/markdown/markdown2tex.lua`
1159 * `⟨TEXMF⟩/tex/generic/markdown/markdown.tex`
1160 * `⟨TEXMF⟩/tex/generic/markdown/markdownthemewitiko_markdown_defaults.tex`
1161 * `⟨TEXMF⟩/tex/latex/markdown/markdown.sty`
1162 * `⟨TEXMF⟩/tex/latex/markdown/markdownthemewitiko_markdown_defaults.sty`
1163 * `⟨TEXMF⟩/tex/context/third/markdown/t-markdown.tex`
1164 * `⟨TEXMF⟩/tex/context/third/markdown/t-markdownthemewitiko_markdown_defaults.tex`
1165
1166 `⟨TEXMF⟩` corresponds to a root directory of one of your \TeX{} directory
1167 structure (TDS) trees. You may list the locations of all TDS trees using a command
1168 such as `kpsewhich -var-value=TEXMF` (in \TeX{} Live) or `mtxrun --resolve-path
1169 TEXMF` (in \Hologo{ConTeXt} Standalone). For more information, consult the
1170 manual of your \TeX{} distribution.
1171
1172 ### Portable Installation
1173
1174 Alternatively, you can also store the above files in the same folder as your
1175 \TeX{} document and distribute them together. This way your document can be
1176 portably typeset on legacy \TeX{} distributions.
1177
1178 This is where the individual files should be placed:
1179
1180 * `./markdown.lua`
1181 * `./markdown-parser.lua`
1182 * `./markdown-unicode-data.lua`
1183 * `./markdown-cli.lua`
1184 * `./markdown2tex.lua`
1185 * `./markdown/markdown.tex`
1186 * `./markdown.sty`
1187 * `./t-markdown.tex`
1188 * `./markdownthemewitiko_markdown_defaults.tex`
1189 * `./markdownthemewitiko_markdown_defaults.sty`
1190 * `./t-markdownthemewitiko_markdown_defaults.tex`
1191
1192 The file `markdown.tex` *must* be placed in a directory named `markdown`.
1193
1194 ### Installing Dependencies (\Hologo{ConTeXt} Standalone)
1195
1196 The Markdown package has a number of external dependencies. Here are the
1197 package names of these dependencies in the \TeX{} Live distribution:
1198
1199 ```
1200 /DEPENDS.txt
1201 ```
1202
1203 Some TeX distributions, such as \TeX{} Live installed with a scheme smaller
1204 than `scheme-full` or \Hologo{ConTeXt} Standalone, may lack some or all of
1205 these dependencies. To complete the installation of the Markdown package with
1206 such distributions, you should follow these steps:
1207
1208 1. For each package that is a hard dependency of the Markdown package (i.e. has
1209 the prefix `hard` in the above list), download an archive from the web address
1210 `https://mirror.ctan.org/systems/texlive/tlnet/archive/⟨package name⟩.tar.xz`.
1211
1212 2. Unpack the downloaded package archives to the directory `⟨TEXMF⟩`.
1213
1214 `⟨TEXMF⟩` corresponds to a root directory of one of your \TeX{} directory
1215 structure (TDS) trees. You may list the locations of all TDS trees using a
1216 command such as `kpsewhich -var-value=TEXMF` (in \TeX{} Live) or `mtxrun
1217 --resolve-path TEXMF` (in \Hologo{ConTeXt} Standalone). For more
1218 information, consult the manual of your \TeX{} distribution.
1219
1220 To unpack the package archive, you would use a command such as `tar xJf
1221 ⟨package name⟩.tar.xz -C ⟨TEXMF⟩` on GNU/Linux and other Un*x systems.
1222
1223 Some package archives may contain extra top-level directories such as
1224 `texmf-dist` and `tlpkg`. For these packages, you should only extract the
1225 contents of the directory `texmf-dist` to `⟨TEXMF⟩`. Here, you might use a
1226 command such as `tar xJf ⟨package name⟩.tar.xz -C ⟨TEXMF⟩ --wildcards
1227 'texmf-dist/*' --strip-components=1` on GNU/Linux and other Un*x systems.
1228
1229 3. Run a command such as `texhash` (in \TeX{} Live) or `mtxrun --generate` and
1230 `context --generate --luatex` (in \Hologo{ConTeXt} Standalone) to make the
1231 installed packages visible to \TeX{}. For more information, consult the
1232 manual of your \TeX{} distribution.
1233
1234 %</manual>
1235 %<*lua>
1236 % \fi
1237 % \begin{markdown}
1238 %
1239 % Requirements
1240 %-------------
1241 %
1242 % This section gives an overview of all resources required by the package.
1243 %
1244 %### Lua Requirements {#lua-prerequisites}
1245 %
1246 % The Lua part of the package requires that the following Lua modules are
1247 % available from within the Lua\TeX{} engine (though not necessarily in the
1248 % LuaMeta\TeX{} engine).
1249 %
1250 % \pkg{LPeg${}\geq{}$0.10}
1251 %
1252 %: A pattern-matching library for the writing of recursive descent parsers
1253 % via the Parsing Expression Grammars (PEGs). It is used by the
1254 % \pkg{Lunamark} library to parse the markdown input.
1255 % \pkg{LPeg${}\geq{}$0.10} is included in Lua\TeX${}\geq{}$0.72.0 (\TeX
1256 % Live${}\geq{}2013$).
1257 %
1258 % \end{markdown}
1259 % \iffalse
1260 %</lua>
1261 %<*lua,lua-unicode-data>
1262 % \fi
1263 % \begin{macrocode}
1264 local lpeg = require("lpeg")
1265 % \end{macrocode}
1266 % \begin{markdown}
1267 %
1268 % \pkg{MD5}
1269 %
1270 %: A library that provides MD5 crypto functions. It is used by the
1271 % \pkg{Lunamark} library to compute the digest of the input for caching
1272 % purposes. \pkg{MD5} is included in all releases of Lua\TeX{} (\TeX
1273 % Live${}\geq{}2008$).
1274 %
1275 % \end{markdown}
1276 % \iffalse
1277 %</lua,lua-unicode-data>
1278 %<*lua,lua-loader>
1279 % \fi
1280 % \begin{macrocode}
1281 local md5 = require("md5")
1282 % \end{macrocode}
1283 % \iffalse
1284 %</lua,lua-loader>
1285 %<*lua,lua-unicode-data-generator>
1286 % \fi
1287 % \begin{markdown}
1288 %
1289 % \pkg{Kpathsea}
1290 %
1291 %: A package that implements the loading of third-party Lua libraries
1292 % and looking up files in the \TeX{} directory structure.
1293 %
1294 % Only load the package outside the \Hologo{ConTeXt} format, where we can
1295 % use the resolvers API [@context23, Section 11.5].
1296 %
1297 % \end{markdown}
1298 % \begin{macrocode}
1299 if resolvers == nil then
1300 (function()
1301 % \end{macrocode}
1302 % \begin{markdown}
1303 %
1304 % If \pkg{Kpathsea} has not been loaded before or if Lua\TeX{} has not yet
1305 % been initialized, configure \pkg{Kpathsea} on top of loading it. Since
1306 % \Hologo{ConTeXt} MkIV provides a `kpse` global that acts as a
1307 % stub for \pkg{Kpathsea} and the \pkg{lua-uni-case} library expects that
1308 % `kpse` is a reference to the full \pkg{Kpathsea} library, we load
1309 % \pkg{Kpathsea} to the `kpse` global.
1310 %
1311 % \end{markdown}
1312 % \begin{macrocode}
1313 local should_initialize = package.loaded.kpse == nil
1314 or tex.initialize ~= nil
1315 kpse = require("kpse")
1316 if should_initialize then
1317 kpse.set_program_name("luatex")
1318 end
1319 end)()
1320 end
1321 % \end{macrocode}
1322 % \begin{markdown}
1323 %
1324 % All the abovelisted modules are statically linked into the current version of
1325 % the Lua\TeX{} engine~[@luatex25, Section 4.3]. Beside these, we also include
1326 % the following third-party Lua libraries:
1327 %
1328 % \pkg{api7/lua-tinyyaml}
1329 %
1330 %: A library that provides a regex-based recursive descent YAML
1331 % (subset) parser that is used to read YAML metadata when the
1332 % \Opt{jekyllData} option is enabled.
1333 %
1334 % \end{markdown}
1335 % \iffalse
1336 %</lua,lua-unicode-data-generator>
1337 %<*depends>
1338 % \fi
1339 % \begin{macrocode}
1340 hard lua-tinyyaml
1341 % \end{macrocode}
1342 % \iffalse
1343 %</depends>
1344 %<*tex>
1345 % \fi
1346 % \begin{markdown}
1347 %
1348 %### Plain \TeX{} Requirements {#tex-prerequisites}
1349 %
1350 % The plain \TeX{} part of the package requires that the plain \TeX{}
1351 % format (or its superset) is loaded, all the Lua prerequisites (see
1352 % Section <#sec:lua-prerequisites>), and the following packages:
1353 %
1354 % \pkg{expl3}
1355 %
1356 %: A package that enables the expl3 language [@latex25] from the \LaTeX3
1357 % kernel in \TeX{} Live${}\leq{}2019$. It is used to implement reflection
1358 % capabilities that allow us to enumerate and inspect high-level concepts
1359 % such as options, renderers, and renderer prototypes.
1360 %
1361 % \end{markdown}
1362 % \iffalse
1363 %</tex>
1364 %<*depends>
1365 % \fi
1366 % \begin{macrocode}
1367 hard l3kernel
1368 % \end{macrocode}
1369 % \iffalse
1370 %</depends>
1371 %<*context>
1372 % \fi
1373 % \begin{macrocode}
1374 \unprotect
1375 % \end{macrocode}
1376 % \iffalse
1377 %</context>
1378 %<*context,tex>
1379 % \fi
1380 % \begin{macrocode}
1381 \expandafter\ifx\csname ExplSyntaxOn\endcsname\relax
1382 \input expl3-generic
1383 \fi
1384 % \end{macrocode}
1385 % \iffalse
1386 %</context,tex>
1387 %<*tex>
1388 % \fi
1389 % \begin{markdown}
1390 %
1391 % \pkg{lt3luabridge}
1392 %
1393 %: A package that allows us to execute Lua code with Lua\TeX{} as well as
1394 % with other \TeX{} engines that provide the *shell escape* capability,
1395 % which allows them to execute code with the system's shell.
1396 %
1397 % Note that this support for \TeX{} engines other than Lua\TeX{} comes with
1398 % some limitations with respect to file and directory names. Specifically,
1399 % the filenames of your .tex files [may not contain spaces][1]. If
1400 % `-output-directory` is provided, it may not contain spaces either.
1401 %
1402 % [1]: https://github.com/Witiko/markdown/issues/573 (Compilation fails if the file name contains spaces)
1403 %
1404 % \end{markdown}
1405 % \iffalse
1406 %</tex>
1407 %<*depends>
1408 % \fi
1409 % \begin{macrocode}
1410 hard lt3luabridge
1411 % \end{macrocode}
1412 % \iffalse
1413 %</depends>
1414 %<*tex>
1415 % \fi
1416 % \begin{markdown}
1417 %
1418 % The plain \TeX{} part of the package also requires the following Lua module:
1419 %
1420 % \pkg{Lua File System}
1421 %
1422 %: A library that provides access to the filesystem via OS-specific
1423 % syscalls. It is used by the plain \TeX{} code to create the cache
1424 % directory specified by the \Opt{cacheDir} option before interfacing with
1425 % the \pkg{Lunamark} library. \pkg{Lua File System} is included in all
1426 % releases of Lua\TeX{} (\TeX Live${}\geq{}2008$).
1427 %
1428 % The plain \TeX{} code makes use of the `isdir` method that was added
1429 % to the \pkg{Lua File System} library by the Lua\TeX{} engine
1430 % developers~[@luatex25, Section 4.2.4].
1431 %
1432 % The \pkg{Lua File System} module is statically linked into the Lua\TeX{}
1433 % engine~[@luatex25, Section 4.3].
1434 %
1435 % Unless you convert markdown documents to \TeX{} manually using the Lua
1436 % command-line interface (see Section <#sec:lua-cli-interface>), the plain
1437 % \TeX{} part of the package will require that either the Lua\TeX{}
1438 % `\directlua` primitive or the shell access file stream 18 is available in
1439 % your \TeX{} engine. If only the shell access file stream is available in your
1440 % \TeX{} engine (as is the case with \hologo{pdfTeX} and \Hologo{XeTeX}), then
1441 % unless your \TeX{} engine is globally configured to enable shell access, you
1442 % will need to provide the `-shell-escape` parameter to your engine when
1443 % typesetting a document.
1444 %
1445 % \end{markdown}
1446 % \iffalse
1447 %</tex>
1448 %<*latex>
1449 % \fi
1450 % \begin{markdown}
1451 %
1452 %### \LaTeX{} Requirements {#latex-prerequisites}
1453 %
1454 % The \LaTeX{} part of the package requires that the \Hologo{LaTeX2e} format is
1455 % loaded, a \TeX{} engine that extends \Hologo{eTeX}, and all the plain \TeX{}
1456 % prerequisites (see Section <#sec:tex-prerequisites>).
1457 % \end{markdown}
1458 % \iffalse
1459 % \fi
1460 % \begin{macrocode}
1461 \NeedsTeXFormat{LaTeX2e}
1462 \RequirePackage{expl3}
1463 % \end{macrocode}
1464 % \iffalse
1465 %</latex>
1466 %<*depends>
1467 % \fi
1468 % \begin{markdown}
1469 %
1470 % The following packages are soft prerequisites. They are only used to provide
1471 % default token renderer prototypes (see sections
1472 % <#sec:texrendererprototypes> and
1473 % <#sec:latex-token-renderer-prototypes>) or \LaTeX{} themes (see Section
1474 % <#sec:latexthemes>) and will not be loaded if the option `plain` has been
1475 % enabled (see Section <#sec:plain>):
1476 %
1477 % \pkg{url}
1478 %
1479 %: A package that provides the `\url` macro for the typesetting of links.
1480 %
1481 % \end{markdown}
1482 % \begin{macrocode}
1483 soft url
1484 % \end{macrocode}
1485 % \begin{markdown}
1486 %
1487 % \pkg{graphicx}
1488 %
1489 %: A package that provides the `\includegraphics` macro for the typesetting
1490 % of images. Furthermore, it also provides a key--value interface that is
1491 % used in the default renderer prototypes for image attribute contexts.
1492 %
1493 % \end{markdown}
1494 % \begin{macrocode}
1495 soft graphics
1496 % \end{macrocode}
1497 % \begin{markdown}
1498 %
1499 % \pkg{enumitem} and \pkg{paralist}
1500 %
1501 %: Packages that provide macros for the default renderer prototypes for
1502 % tight and fancy lists.
1503 %
1504 % The package \pkg{paralist} will be used unless the option
1505 % \Opt{experimental} has been enabled, in which case, the package
1506 % \pkg{enumitem} will be used. Furthermore, enabling any test phase
1507 % [@latex24] will also cause \pkg{enumitem} to be used. In a future
1508 % major version, \pkg{enumitem} will replace \pkg{paralist} altogether.
1509 %
1510 % \end{markdown}
1511 % \begin{macrocode}
1512 soft enumitem
1513 soft paralist
1514 % \end{macrocode}
1515 % \begin{markdown}
1516 %
1517 % \pkg{fancyvrb}
1518 %
1519 %: A package that provides the `\VerbatimInput` macros for the verbatim
1520 % inclusion of files containing code.
1521 %
1522 % \end{markdown}
1523 % \begin{macrocode}
1524 soft fancyvrb
1525 % \end{macrocode}
1526 % \begin{markdown}
1527 %
1528 % \pkg{csvsimple}
1529 %
1530 %: A package that provides the `\csvautotabular` macro for typesetting
1531 % CSV files in the default renderer prototypes for iA\\,Writer
1532 % content blocks.
1533 %
1534 % \end{markdown}
1535 % \begin{macrocode}
1536 soft csvsimple
1537 soft pgf # required by `csvsimple`, which loads `pgfkeys.sty`
1538 soft tools # required by `csvsimple`, which loads `shellesc.sty`
1539 soft etoolbox # required by `csvsimple`, which loads `etoolbox.sty`
1540 % \end{macrocode}
1541 % \begin{markdown}
1542 %
1543 % \pkg{amsmath} and \pkg{amssymb}
1544 %
1545 %: Packages that provide symbols used for drawing ticked and unticked
1546 % boxes.
1547 %
1548 % \end{markdown}
1549 % \begin{macrocode}
1550 soft amsmath
1551 soft amsfonts
1552 % \end{macrocode}
1553 % \begin{markdown}
1554 %
1555 % \pkg{graphicx}
1556 %
1557 %: A package that provides extended support for graphics. It is used in
1558 % the `witiko/diagrams`, and `witiko/graphicx/http` plain \TeX{} themes,
1559 % see Section <#sec:themes>.
1560 %
1561 % \end{markdown}
1562 % \begin{macrocode}
1563 soft graphics
1564 soft epstopdf # required by `graphics` and `graphicx`, which load `epsopdf-base.sty`
1565 soft epstopdf-pkg # required by `graphics` and `graphicx`, which load `epsopdf-base.sty`
1566 % \end{macrocode}
1567 % \begin{markdown}
1568 %
1569 % \pkg{soul} and \pkg{xcolor}
1570 %
1571 %: Packages that are used in the default renderer prototypes for
1572 % strike-throughs and marked text in pdf\TeX.
1573 %
1574 % \end{markdown}
1575 % \begin{macrocode}
1576 soft soul
1577 soft xcolor
1578 % \end{macrocode}
1579 % \begin{markdown}
1580 %
1581 % \pkg{lua-ul} and \pkg{luacolor}
1582 %
1583 %: Packages that are used in the default renderer prototypes for
1584 % strike-throughs and marked text in Lua\TeX.
1585 %
1586 % \end{markdown}
1587 % \begin{macrocode}
1588 soft lua-ul
1589 soft luacolor
1590 % \end{macrocode}
1591 % \begin{markdown}
1592 %
1593 % \pkg{ltxcmds}
1594 %
1595 %: A package that is used to detect whether the \pkg{minted} and
1596 % \pkg{listings} packages are loaded in the default renderer prototype
1597 % for fenced code blocks.
1598 %
1599 % \end{markdown}
1600 % \begin{macrocode}
1601 soft ltxcmds
1602 % \end{macrocode}
1603 % \begin{markdown}
1604 %
1605 % \pkg{luaxml}
1606 %
1607 %: A package that is used to convert HTML to \LaTeX{} in the default
1608 % renderer prototypes for content blocks, raw blocks, and inline raw spans.
1609 %
1610 % \end{markdown}
1611 % \begin{macrocode}
1612 soft luaxml
1613 % \end{macrocode}
1614 % \begin{markdown}
1615 %
1616 % \pkg{verse}
1617 %
1618 %: A package that is used in the default renderer prototypes for
1619 % line blocks.
1620 %
1621 % \end{markdown}
1622 % \begin{macrocode}
1623 soft verse
1624 % \end{macrocode}
1625 % \begin{markdown}
1626 %
1627 % \end{markdown}
1628 % \iffalse
1629 %</depends>
1630 %<*context>
1631 % \fi
1632 % \begin{markdown}
1633 %
1634 %### \Hologo{ConTeXt} Prerequisites
1635 % The \Hologo{ConTeXt} part of the package requires that either the Mark II or
1636 % the Mark IV format is loaded, all the plain \TeX{} prerequisites (see
1637 % Section <#sec:tex-prerequisites>), and the following \Hologo{ConTeXt}
1638 % modules:
1639 %
1640 % \pkg{m-database}
1641 %
1642 %: A module that provides the default token renderer prototype for
1643 % iA\\,Writer content blocks with the CSV filename extension (see
1644 % Section <#sec:texrendererprototypes>).
1645 %
1646 % Feedback
1647 %---------
1648 % Please use the \pkg{Markdown} project page on
1649 % [GitHub](https://github.com/witiko/markdown/issues) to report bugs and submit
1650 % feature requests. If you do not want to report a bug or request a feature but
1651 % are simply in need of assistance, you might want to consider posting your
1652 % question to the [\TeX-\LaTeX{} Stack Exchange.](https://tex.stackexchange.com)
1653 % community question answering web site under the `markdown` tag.
1654 %
1655 % Acknowledgements
1656 %-----------------
1657 % The Lunamark Lua module provides speedy markdown parsing for the package. I
1658 % would like to thank John Macfarlane, the creator of Lunamark, for releasing
1659 % Lunamark under a permissive license, which enabled its use in the Markdown
1660 % package.
1661 %
1662 % Extensive user documentation for the Markdown package was kindly written by
1663 % Lian Tze Lim and published by Overleaf.
1664 %
1665 % Funding by the Faculty of Informatics at the Masaryk~University
1666 % in~Brno~[@novotny15] is gratefully acknowledged.
1667 %
1668 % Support for content slicing (Lua options \Opt{shiftHeadings} and \Opt{slice})
1669 % and pipe tables (Lua options \Opt{pipeTables} and \Opt{tableCaptions}) was
1670 % graciously sponsored by David Vins and Omedym.
1671 %
1672 % The \TeX{} implementation of the package draws inspiration from several
1673 % sources including the source code of \Hologo{LaTeX2e}, the \pkg{minted}
1674 % package by Geoffrey M. Poore, which likewise tackles the issue of
1675 % interfacing with an external interpreter from \TeX{}, the \pkg{filecontents}
1676 % package by Scott Pakin and others.
1677 %
1678 % Interfaces {#interfaces}
1679 %============
1680 %
1681 % This part of the documentation describes the interfaces exposed by the package
1682 % along with usage notes and examples. It is aimed at the user of the package.
1683 %
1684 % Since neither \TeX{} nor Lua provide interfaces as a language construct, the
1685 % separation to interfaces and implementations is a *gentlemen's agreement*. It
1686 % serves as a means of structuring this documentation and as a promise to the
1687 % user that if they only access the package through the interface, the future
1688 % minor versions of the package should remain backwards compatible.
1689 %
1690 % Figure <#fig:block-diagram> shows the high-level structure of the Markdown
1691 % package: The translation from markdown to \TeX{} *token renderers* is exposed
1692 % by the Lua layer. The plain \TeX{} layer exposes the conversion capabilities
1693 % of Lua as \TeX{} macros. The \LaTeX{} and \Hologo{ConTeXt} layers provide
1694 % syntactic sugar on top of plain \TeX{} macros. The user can interface with
1695 % any and all layers.
1696 %
1697 % \end{markdown}
1698 % \begin{figure}
1699 % \centering
1700 % \input markdown-figure-block-diagram
1701 % \caption{A block diagram of the \pkg{Markdown} package}
1702 % \label{fig:block-diagram}
1703 % \end{figure}
1704 % \iffalse
1705 %</context>
1706 %<*manual>
1707
1708 First Document
1709 --------------
1710
1711 In this section, we will take the necessary steps to typeset our first markdown
1712 document in \TeX{}. This will serve as our first hands-on experience with the
1713 package and also as a reassurance that the package has been correctly installed.
1714
1715 If you are using [our official Docker image][docker], you need to prefix all
1716 commands in this section with `docker run --rm -v "$PWD"/workdir:/workdir -w
1717 /workdir witiko/markdown`. For example, instead of `luatex document.tex`, you
1718 would execute the following command:
1719 ``` sh
1720 docker run --rm -v "$PWD"/workdir:/workdir -w /workdir witiko/markdown \
1721 luatex document.tex
1722 ``````
1723
1724 ### Using Lua
1725
1726 Using a text editor, create a text document named `document.tex` with the
1727 following content:
1728 ``` tex
1729 \input markdown
1730 \begingroup
1731 \catcode`\%=12
1732 \catcode`\#=12
1733 \input hello
1734 \endgroup
1735 \bye
1736 ```````
1737
1738 #### Using the Lua Module
1739
1740 Using a text editor, create a text document named `hello.lua` with the
1741 following content:
1742 ``` lua
1743 #!/usr/bin/env texlua
1744 local kpse = require("kpse")
1745 kpse.set_program_name("luatex")
1746 local markdown = require("markdown")
1747 local convert = markdown.new()
1748 print(convert("Hello *world*!"))
1749 ```````
1750 Next, invoke LuaTeX from the terminal:
1751 ``` sh
1752 texlua hello.lua > hello.tex
1753 luatex document.tex
1754 ``````
1755 A PDF document named `document.pdf` should be produced and contain the text
1756 “Hello *world*!” Invoking pdfTeX should have the same effect:
1757 ``` sh
1758 texlua hello.lua > hello.tex
1759 pdftex document.tex
1760 ``````
1761
1762 #### Using the Lua Command-Line Interface
1763
1764 Using a text editor, create a text document named `hello.md` with the
1765 following content:
1766 ``` md
1767 Hello *world*!
1768 ``````
1769 Next, invoke LuaTeX from the terminal:
1770 ``` sh
1771 markdown2tex -- hello.md hello.tex
1772 luatex document.tex
1773 ``````
1774
1775 A PDF document named `document.pdf` should be produced and contain the text “Hello
1776 *world*!” Invoking pdfTeX should have the same effect:
1777 ``` sh
1778 markdown2tex -- hello.md hello.tex
1779 pdftex document.tex
1780 ``````
1781
1782 ### Using Plain \TeX{}
1783
1784 Using a text editor, create a text document named `document.tex` with the
1785 following content:
1786 ``` tex
1787 \input markdown
1788 \markdownBegin
1789 Hello *world*!
1790 \markdownEnd
1791 \bye
1792 ```````
1793 Next, invoke LuaTeX from the terminal:
1794 ``` sh
1795 luatex document.tex
1796 ``````
1797 A PDF document named `document.pdf` should be produced and contain the text
1798 “Hello *world*!”
1799
1800 Instead of LuaTeX, you may also use pdfTeX:
1801 ``` sh
1802 pdftex --shell-escape document.tex
1803 ```````
1804 This should also produce a PDF document named `document.pdf` with the same content.
1805
1806 ***
1807
1808 Instead of writing your markdown document between `\markdownBegin` and
1809 `\markdownEnd`, you can also include markdown documents using the
1810 `\markdownInput` macro, similarly to how you might use the `\input` TeX
1811 primitive to include \TeX{} documents.
1812
1813 Using a text editor, create a text document named `hello.md` with the
1814 following content:
1815 ``` md
1816 Hello *world*!
1817 ``````
1818 Create also a text document named `document.tex` with the following content:
1819 ``` tex
1820 \input markdown
1821 \markdownInput{hello.md}
1822 \bye
1823 ```````
1824 Next, invoke LuaTeX or pdfTeX from the terminal like in the previous example.
1825 A PDF document named `document.pdf` should be produced and contain the text
1826 “Hello *world*!”
1827
1828 ### Using \LaTeX{}
1829
1830 Using a text editor, create a text document named `document.tex` with the
1831 following content:
1832 ``` tex
1833 \documentclass{article}
1834 \usepackage{markdown}
1835 \begin{document}
1836 \begin{markdown}
1837 Hello *world*!
1838 \end{markdown}
1839 \end{document}
1840 ```````
1841 Next, invoke LuaTeX from the terminal:
1842 ``` sh
1843 lualatex document.tex
1844 ``````
1845 A PDF document named `document.pdf` should be produced and contain the text “Hello
1846 *world*!”
1847
1848 Instead of LuaTeX, you may also use pdfTeX:
1849 ``` sh
1850 pdflatex --shell-escape document.tex
1851 ``````
1852 This should also produce a PDF document named `document.pdf` with the same content.
1853
1854 ***
1855
1856 Instead of writing your markdown document between `\begin{markdown}` and
1857 `\end{markdown}`, you can also include markdown documents using the
1858 `\markdownInput` macro, similarly to how you might use the `\input` TeX
1859 primitive to include \LaTeX{} documents.
1860
1861 Using a text editor, create a text document named `hello.md` with the
1862 following content:
1863 ``` md
1864 Hello *world*!
1865 ``````
1866 Create also a text document named `document.tex` with the following content:
1867 ``` tex
1868 \documentclass{article}
1869 \usepackage{markdown}
1870 \begin{document}
1871 \begin{markdown}
1872 \markdownInput{hello.md}
1873 \end{markdown}
1874 \end{document}
1875 ```````
1876 Next, invoke LuaTeX or pdfTeX from the terminal like in the previous example.
1877 A PDF document named `document.pdf` should be produced and contain the text
1878 “Hello *world*!”
1879
1880 ***
1881
1882 As the next step, try typesetting the example documents distributed along with
1883 the Markdown package:
1884 ``` sh
1885 git clone https://github.com/witiko/markdown
1886 cd markdown/examples
1887 lualatex latex-luatex.tex
1888 ``````
1889 A PDF document named `latex-luatex.pdf` should be produced. Open the text
1890 documents `latex-luatex.tex` and `example.md` in a text editor to see how the
1891 example documents are structured. Try changing the documents and typesetting
1892 them as follows:
1893 ``` sh
1894 lualatex latex-luatex.tex
1895 ``````
1896 to see the effect of your changes.
1897
1898 ### Using \Hologo{ConTeXt}
1899
1900 Using a text editor, create a text document named `document.tex` with the
1901 following content:
1902 ``` tex
1903 \usemodule[t][markdown]
1904 \starttext
1905 \startmarkdown
1906 Hello *world*!
1907 \stopmarkdown
1908 \stoptext
1909 ```````
1910 Next, invoke LuaTeX from the terminal:
1911 ``` sh
1912 context --luatex document.tex
1913 ``````
1914 A PDF document named `document.pdf` should be produced and contain the text “Hello
1915 *world*!”
1916
1917 ***
1918
1919 Instead of writing your markdown document between `\startmarkdown` and
1920 `\stopmarkdown`, you can also include markdown documents using the
1921 `\inputmarkdown` macro, similarly to how you might use the `\input` TeX
1922 primitive to include \Hologo{ConTeXt} documents.
1923
1924 Using a text editor, create a text document named `hello.md` with the
1925 following content:
1926 ``` md
1927 Hello *world*!
1928 ``````
1929 Create also a text document named `document.tex` with the following content:
1930 ``` tex
1931 \usemodule[t][markdown]
1932 \starttext
1933 \inputmarkdown{hello.md}
1934 \stoptext
1935 ```````
1936 Next, invoke LuaTeX from the terminal like in the previous example.
1937 A PDF document named `document.pdf` should be produced and contain the text
1938 “Hello *world*!”
1939
1940 ***
1941
1942 As the next step, try typesetting the example documents distributed along with
1943 the Markdown package:
1944 ``` sh
1945 git clone https://github.com/witiko/markdown
1946 cd markdown/examples
1947 context --luatex context.tex
1948 ``````
1949 A PDF document named `context.pdf` should be produced. Open the text documents
1950 `context.tex` and `example.md` in a text editor to see how the example documents
1951 are structured. Try changing the documents and typesetting them as follows:
1952 ``` sh
1953 context --luatex context.tex
1954 ``````
1955 to see the effect of your changes.
1956
1957 Examples
1958 ========
1959
1960 In this section, I will describe the individual parts of the Markdown package.
1961 Each part will be shown by example, leaving the implementation details to the
1962 [technical documentation][techdoc].
1963
1964 /markdown-interfaces.md
1965 /markdown-options.md
1966 /markdown-tokens.md
1967
1968 %</manual>
1969 %<*lua>
1970 % \fi
1971 % \begin{markdown}
1972 %
1973 % Lua Interface {#luainterface}
1974 %---------------
1975 %
1976 % \end{markdown}
1977 % \iffalse
1978 %</lua>
1979 %<*manual-interfaces>
1980
1981 Interfaces
1982 ----------
1983
1984 In this section, I will describe the individual interfaces exposed by the
1985 Markdown package starting with the low-level Lua interfaces and all the way up
1986 to the \LaTeX{} and \Hologo{ConTeXt} interfaces intended for the ordinary
1987 user.
1988
1989 ### Lua
1990
1991 The Lua programming language is what drives the conversion from markdown to
1992 \TeX{} in the Markdown package. Based on the [Lunamark][] Lua library by John
1993 MacFarlane, the Lua implementation is largely independent on \TeX{}, and can be
1994 used separately from typesetting a document. Lua provides two interfaces: a Lua
1995 module and a command-line interface (CLI).
1996
1997 [Lunamark]: https://github.com/jgm/lunamark
1998 (Lua library for conversion between markup formats)
1999
2000 %</manual-interfaces>
2001 %<*lua,lua-loader,lua-unicode-data>
2002 % \fi
2003 % \begin{markdown}
2004 %
2005 % The Lua interface provides the conversion from UTF8
2006 % encoded markdown to plain \TeX{}. This interface is used by the plain \TeX{}
2007 % implementation (see Section <#sec:teximplementation>) and will be of
2008 % interest to the developers of other packages and Lua modules.
2009 %
2010 % The Lua interface is implemented by the `markdown` Lua module.
2011 %
2012 % \end{markdown}
2013 % \begin{macrocode}
2014 local M = {metadata = metadata}
2015 % \end{macrocode}
2016 % \iffalse
2017 %</lua,lua-loader,lua-unicode-data>
2018 %<*lua>
2019 % \fi
2020 % \begin{markdown}
2021 %
2022 %### Conversion from Markdown to Plain \TeX{} {#lua-conversion}
2023 %
2024 % The Lua interface exposes the \luamdef{new}`(options)` function. This
2025 % function returns a conversion function from markdown to plain \TeX{} according
2026 % to the table `options` that contains options recognized by the Lua interface
2027 % (see Section <#sec:lua-options>). The `options` parameter is optional; when
2028 % unspecified, the behaviour will be the same as if `options` were an empty
2029 % table.
2030 %
2031 % The following example Lua code converts the markdown string `Hello
2032 % *world*!` to a \TeX{} output using the default options and prints the \TeX{}
2033 % output:
2034 % ``` lua
2035 % local md = require("markdown")
2036 % local convert = md.new()
2037 % print(convert("Hello *world*!"))
2038 % ```````
2039 %
2040 %### User-Defined Syntax Extensions {#lua-user-extensions}
2041 %
2042 % For the purpose of user-defined syntax extensions, the Lua interface also
2043 % exposes the \luamdef{reader} object, which performs the lexical and
2044 % syntactic analysis of markdown text and which exposes the
2045 % \luamdef{reader->insert_pattern} and \luamdef{reader->add_special_character}
2046 % methods for extending the PEG grammar of markdown.
2047 %
2048 % The read-only \luamdef{walkable_syntax} hash table stores those rules of the
2049 % PEG grammar of markdown that can be represented as an ordered choice
2050 % of terminal symbols. These rules can be modified by user-defined syntax
2051 % extensions.
2052 %
2053 % \end{markdown}
2054 % \begin{macrocode}
2055 local walkable_syntax = {
2056 Block = {
2057 "Blockquote",
2058 "Verbatim",
2059 "ThematicBreak",
2060 "BulletList",
2061 "OrderedList",
2062 "DisplayHtml",
2063 "Heading",
2064 },
2065 BlockOrParagraph = {
2066 "Block",
2067 "Paragraph",
2068 "Plain",
2069 },
2070 Inline = {
2071 "Str",
2072 "Space",
2073 "Endline",
2074 "EndlineBreak",
2075 "LinkAndEmph",
2076 "Code",
2077 "AutoLinkUrl",
2078 "AutoLinkEmail",
2079 "AutoLinkRelativeReference",
2080 "InlineHtml",
2081 "HtmlEntity",
2082 "EscapedChar",
2083 "Smart",
2084 "Symbol",
2085 },
2086 }
2087 % \end{macrocode}
2088 % \begin{markdown}
2089 %
2090 % The \luamref{reader->insert_pattern} method inserts a PEG pattern into
2091 % the grammar of markdown. The method receives two mandatory arguments: a
2092 % selector string in the form `"`\meta{left-hand side terminal symbol}
2093 % \meta{`before`, `after`, or `instead of`} \meta{right-hand side terminal
2094 % symbol}`"` and a PEG pattern to insert, and an optional third argument
2095 % with a name of the PEG pattern for debugging purposes (see the
2096 % \Opt{debugExtensions} option). The name does not need to be unique and shall
2097 % not be interpreted by the Markdown package; you can treat it as a comment.
2098 %
2099 % For example. if we'd like to insert `pattern` into the grammar between the
2100 % `Inline -> LinkAndEmph` and `Inline -> Code` rules, we would call
2101 % \luamref{reader->insert_pattern} with `"Inline after LinkAndEmph"` (or `"Inline
2102 % before Code"`) and `pattern` as the arguments.
2103 %
2104 % The \luamref{reader->add_special_character} method adds a new character with
2105 % special meaning to the grammar of markdown. The method receives the character
2106 % as its only argument.
2107 %
2108 % \end{markdown}
2109 % \iffalse
2110 %</lua>
2111 %<*manual-interfaces>
2112
2113 #### Lua Module
2114
2115 A Lua module is a software library that can be used from in other programs.
2116 The `markdown` Lua module makes it possible to convert markdown to \TeX{} from
2117 within Lua\TeX{} documents and Lua scripts.
2118
2119 The `markdown` Lua module exposes the `new(`\meta{options}`)` method, which
2120 creates a converter function from markdown to \TeX{}. The properties of the
2121 converter function are specified by the Lua table `options`. The parameter is
2122 optional; when unspecified, the behaviour will be the same as if \meta{options}
2123 were an empty table.
2124
2125 Using a text editor, create a text document named `document.tex` with the
2126 following content:
2127 ``` tex
2128 \input markdown
2129 \input lmfonts
2130 \begingroup
2131 \catcode`\%=12
2132 \catcode`\#=12
2133 \input example
2134 \endgroup
2135 \bye
2136 ```````
2137 Using a text editor, create a text document named `example.lua` with the
2138 following content:
2139 ``` lua
2140 #!/usr/bin/env texlua
2141 local kpse = require("kpse")
2142 kpse.set_program_name("luatex")
2143 local markdown = require("markdown")
2144 local input, convert_nomath, convert_math, paragraph
2145
2146 input = [[$\sqrt{-1}$ *equals* $i$.]]
2147 convert_nomath = markdown.new()
2148 convert_math = markdown.new({texMathDollars = true})
2149 paragraph = [[\par]]
2150
2151 print(
2152 convert_nomath(input) .. paragraph ..
2153 convert_math(input)
2154 )
2155 ```````
2156 Next, invoke LuaTeX from the terminal:
2157 ``` sh
2158 texlua example.lua > example.tex
2159 luatex document.tex
2160 ``````
2161 A PDF document named `document.pdf` should be produced and contain the
2162 following text:
2163
2164 > \$\\sqrt{-1}\$ *equals* \$i\$.
2165 >
2166 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
2167 > *equals*
2168 > <math><mi>i</mi></math>.
2169
2170 Invoking pdfTeX should have the same effect:
2171 ``` sh
2172 texlua example.lua > example.tex
2173 pdftex document.tex
2174 ``````
2175
2176 ***
2177
2178 Rather than use the `texlua` interpreter, we can also access the `markdown` Lua
2179 module directly from our document. Using a text editor, create a text document
2180 named `document.tex` with the following content:
2181 ``` tex
2182 \input markdown
2183 \input lmfonts
2184 \directlua{
2185 local markdown = require("markdown")
2186 local input, convert_nomath, convert_math, paragraph
2187
2188 input = [[$\string\sqrt{-1}$ *equals* $i$.]]
2189 convert_nomath = markdown.new()
2190 convert_math = markdown.new({texMathDollars = true})
2191 paragraph = [[\par]]
2192
2193 tex.sprint(
2194 convert_nomath(input) .. paragraph ..
2195 convert_math(input)
2196 )
2197 }
2198 \bye
2199 ```````
2200 Next, invoke LuaTeX from the terminal:
2201 ``` sh
2202 luatex document.tex
2203 ```````
2204 A PDF document named `document.pdf` should be produced and contain the
2205 following text:
2206
2207 > \$\\sqrt{-1}\$ *equals* \$i\$.
2208 >
2209 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
2210 > *equals*
2211 > <math><mi>i</mi></math>.
2212
2213 In this case, we cannot use pdfTeX, because pdfTeX does not define the
2214 `\directlua` \TeX{} command.
2215
2216 #### Lua Command-Line Interface
2217
2218 The Lua command-line interface (CLI) of the Markdown package makes the
2219 functionality of the Lua module accessible from the command line. This makes
2220 it possible to convert documents from markdown to \TeX{} manually without any
2221 knowledge of the Lua programming language.
2222
2223 The Lua command-line interface accepts the same options as the `markdown` Lua
2224 module, but now the options are specified as command-line parameters.
2225
2226 Using a text editor, create a text document named `document.tex` with the
2227 following content:
2228 ``` tex
2229 \input markdown
2230 \input lmfonts
2231 \begingroup
2232 \catcode`\%=12
2233 \catcode`\#=12
2234 \input nomath
2235 \par
2236 \input math
2237 \endgroup
2238 \bye
2239 ```````
2240 Using a text editor, create a text document named `example.md` with the
2241 following content:
2242 ``` md
2243 $\sqrt{-1}$ *equals* $i$.
2244 ``````
2245 Next, invoke LuaTeX from the terminal:
2246 ``` sh
2247 markdown2tex -- example.md nomath.tex
2248 markdown2tex tex_math_dollars=true -- example.md math.tex
2249 luatex document.tex
2250 ``````
2251
2252 A PDF document named `document.pdf` should be produced and contain the
2253 following text:
2254
2255 > \$\\sqrt{-1}\$ *equals* \$i\$.
2256 >
2257 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
2258 > *equals*
2259 > <math><mi>i</mi></math>.
2260
2261 Invoking pdfTeX should have the same effect:
2262 ``` sh
2263 markdown2tex -- example.md nomath.tex
2264 markdown2tex tex_math_dollars=true -- example.md math.tex
2265 pdftex document.tex
2266 ``````
2267
2268 %</manual-interfaces>
2269 %<*lua>
2270 % \fi
2271 % \begin{markdown}
2272 %
2273 %### Options {#lua-options}
2274 %
2275 % The Lua interface recognizes the following options. When unspecified, the
2276 % value of a key is taken from the \luamdef{defaultOptions} and
2277 % \luamdef{experimentalOptions} tables.
2278 %
2279 % \end{markdown}
2280 % \iffalse
2281 %</lua>
2282 %<*manual-options>
2283
2284 ## Options
2285
2286 In this section, I will describe all the options recognized by the Markdown
2287 package.
2288
2289 %</manual-options>
2290 %<*lua,lua-cli,lua-loader>
2291 % \fi
2292 % \begin{macrocode}
2293 local defaultOptions = {}
2294 local experimentalOptions = {}
2295 setmetatable(experimentalOptions, { __index = function (_, key)
2296 return defaultOptions[key] end })
2297 % \end{macrocode}
2298 % \begingroup
2299 % \markdownSetup{snippet=lua-options}
2300 % \iffalse
2301 %</lua,lua-cli,lua-loader>
2302 %<*manual-options>
2303
2304 ### Lua
2305
2306 Lua options control the conversion from markdown to \TeX{}. They are supported
2307 by all interfaces of the Markdown package starting with the low-level Lua
2308 interfaces and all the way up to the \LaTeX{} and \Hologo{ConTeXt} interfaces.
2309
2310 %</manual-options>
2311 %<*tex>
2312 % \fi
2313 % \begin{markdown}
2314 %
2315 % To enable the enumeration of Lua options, we will maintain the
2316 % \mdef{g_\@\@_lua_options_seq} sequence.
2317 %
2318 % \end{markdown}
2319 % \begin{macrocode}
2320 \ExplSyntaxOn
2321 \seq_new:N \g_@@_lua_options_seq
2322 % \end{macrocode}
2323 % \begin{markdown}
2324 %
2325 % To enable the reflection of default/experimental Lua options and their types,
2326 % we will maintain the \mdef{g_\@\@_default_lua_options_prop},
2327 % \mdef{g_\@\@_experimental_lua_options_seq} and
2328 % \mdef{g_\@\@_lua_option_types_prop} property lists and sequences,
2329 % respectively.
2330 %
2331 % \end{markdown}
2332 % \begin{macrocode}
2333 \prop_new:N \g_@@_lua_option_types_prop
2334 \prop_new:N \g_@@_default_lua_options_prop
2335 \seq_new:N \g_@@_experimental_lua_options_seq
2336 \seq_new:N \g_@@_option_layers_seq
2337 \tl_const:Nn \c_@@_option_layer_lua_tl { lua }
2338 \seq_gput_right:NV
2339 \g_@@_option_layers_seq
2340 \c_@@_option_layer_lua_tl
2341 \cs_new:Nn
2342 \@@_add_lua_option:nnn
2343 {
2344 \@@_add_option:Vnnn
2345 \c_@@_option_layer_lua_tl
2346 { #1 }
2347 { #2 }
2348 { #3 }
2349 }
2350 \cs_new:Nn
2351 \@@_add_option:nnnn
2352 {
2353 \seq_gput_right:cn
2354 { g_@@_ #1 _options_seq }
2355 { #2 }
2356 \prop_gput:cnn
2357 { g_@@_ #1 _option_types_prop }
2358 { #2 }
2359 { #3 }
2360 \prop_gput:cnn
2361 { g_@@_default_ #1 _options_prop }
2362 { #2 }
2363 { #4 }
2364 \@@_typecheck_option:n
2365 { #2 }
2366 }
2367 \cs_generate_variant:Nn
2368 \@@_add_option:nnnn
2369 { Vnnn }
2370 \cs_new:Nn
2371 \@@_add_experimental_lua_option:n
2372 {
2373 \@@_add_experimental_option:Vn
2374 \c_@@_option_layer_lua_tl
2375 { #1 }
2376 }
2377 \cs_new:Nn
2378 \@@_add_experimental_option:nn
2379 {
2380 \seq_gput_right:cn
2381 { g_@@_ #1 _options_seq }
2382 { #2 }
2383 \seq_gput_right:cn
2384 { g_@@_experimental_ #1 _options_seq }
2385 { #2 }
2386 \prop_gput:cnn
2387 { g_@@_ #1 _option_types_prop }
2388 { #2 }
2389 { boolean }
2390 }
2391 \cs_generate_variant:Nn
2392 \@@_add_experimental_option:nn
2393 { Vn }
2394 \tl_const:Nn \c_@@_option_value_true_tl { true }
2395 \tl_const:Nn \c_@@_option_value_false_tl { false }
2396 \cs_new:Nn \@@_typecheck_option:n
2397 {
2398 \@@_get_option_type:nN
2399 { #1 }
2400 \l_tmpa_tl
2401 \str_case_e:Vn
2402 \l_tmpa_tl
2403 {
2404 { \c_@@_option_type_boolean_tl }
2405 {
2406 \@@_get_option_value:nN
2407 { #1 }
2408 \l_tmpa_tl
2409 \bool_if:nF
2410 {
2411 \str_if_eq_p:eV
2412 { \l_tmpa_tl }
2413 \c_@@_option_value_true_tl ||
2414 \str_if_eq_p:eV
2415 { \l_tmpa_tl }
2416 \c_@@_option_value_false_tl
2417 }
2418 {
2419 \msg_error:nnne
2420 { markdown }
2421 { failed-typecheck-for-boolean-option }
2422 { #1 }
2423 { \l_tmpa_tl }
2424 }
2425 }
2426 }
2427 }
2428 \msg_new:nnn
2429 { markdown }
2430 { failed-typecheck-for-boolean-option }
2431 {
2432 Option~#1~has~value~#2,~
2433 but~a~boolean~(true~or~false)~was~expected.
2434 }
2435 \cs_generate_variant:Nn
2436 \str_case_e:nn
2437 { Vn }
2438 \cs_generate_variant:Nn
2439 \msg_error:nnnn
2440 { nnne }
2441 \prg_generate_conditional_variant:Nnn
2442 \str_if_eq:nn
2443 { eV }
2444 { p }
2445 \seq_new:N
2446 \g_@@_option_types_seq
2447 \tl_const:Nn
2448 \c_@@_option_type_clist_tl
2449 { clist }
2450 \seq_gput_right:NV
2451 \g_@@_option_types_seq
2452 \c_@@_option_type_clist_tl
2453 \tl_const:Nn
2454 \c_@@_option_type_counter_tl
2455 { counter }
2456 \seq_gput_right:NV
2457 \g_@@_option_types_seq
2458 \c_@@_option_type_counter_tl
2459 \tl_const:Nn
2460 \c_@@_option_type_boolean_tl
2461 { boolean }
2462 \seq_gput_right:NV
2463 \g_@@_option_types_seq
2464 \c_@@_option_type_boolean_tl
2465 \tl_const:Nn
2466 \c_@@_option_type_number_tl
2467 { number }
2468 \seq_gput_right:NV
2469 \g_@@_option_types_seq
2470 \c_@@_option_type_number_tl
2471 \tl_const:Nn
2472 \c_@@_option_type_path_tl
2473 { path }
2474 \seq_gput_right:NV
2475 \g_@@_option_types_seq
2476 \c_@@_option_type_path_tl
2477 \tl_const:Nn
2478 \c_@@_option_type_slice_tl
2479 { slice }
2480 \seq_gput_right:NV
2481 \g_@@_option_types_seq
2482 \c_@@_option_type_slice_tl
2483 \tl_const:Nn
2484 \c_@@_option_type_string_tl
2485 { string }
2486 \seq_gput_right:NV
2487 \g_@@_option_types_seq
2488 \c_@@_option_type_string_tl
2489 \cs_new:Nn
2490 \@@_get_option_type:nN
2491 {
2492 \bool_set_false:N
2493 \l_tmpa_bool
2494 \seq_map_inline:Nn
2495 \g_@@_option_layers_seq
2496 {
2497 \prop_get:cnNT
2498 { g_@@_ ##1 _option_types_prop }
2499 { #1 }
2500 \l_tmpa_tl
2501 {
2502 \bool_set_true:N
2503 \l_tmpa_bool
2504 \seq_map_break:
2505 }
2506 }
2507 \bool_if:NF
2508 \l_tmpa_bool
2509 {
2510 \msg_error:nnn
2511 { markdown }
2512 { undefined-option }
2513 { #1 }
2514 }
2515 \seq_if_in:NVF
2516 \g_@@_option_types_seq
2517 \l_tmpa_tl
2518 {
2519 \msg_error:nnnV
2520 { markdown }
2521 { unknown-option-type }
2522 { #1 }
2523 \l_tmpa_tl
2524 }
2525 \tl_set_eq:NN
2526 #2
2527 \l_tmpa_tl
2528 }
2529 \msg_new:nnn
2530 { markdown }
2531 { unknown-option-type }
2532 {
2533 Option~#1~has~unknown~type~#2.
2534 }
2535 \msg_new:nnn
2536 { markdown }
2537 { undefined-option }
2538 {
2539 Option~#1~is~undefined.
2540 }
2541 \cs_generate_variant:Nn
2542 \msg_error:nnnn
2543 { nnnV }
2544 \cs_new:Nn
2545 \@@_get_default_option_value:nN
2546 {
2547 \bool_set_false:N
2548 \l_tmpa_bool
2549 \seq_map_inline:Nn
2550 \g_@@_option_layers_seq
2551 {
2552 \seq_if_in:cnT
2553 { g__markdown_experimental_ ##1 _options_seq }
2554 { #1 }
2555 {
2556 \@@_get_option_value:nN
2557 { experimental }
2558 #2
2559 \bool_set_true:N
2560 \l_tmpa_bool
2561 \seq_map_break:
2562 }
2563 \prop_get:cnNT
2564 { g_@@_default_ ##1 _options_prop }
2565 { #1 }
2566 #2
2567 {
2568 \bool_set_true:N
2569 \l_tmpa_bool
2570 \seq_map_break:
2571 }
2572 }
2573 \bool_if:NF
2574 \l_tmpa_bool
2575 {
2576 \msg_error:nnn
2577 { markdown }
2578 { undefined-option }
2579 { #1 }
2580 }
2581 }
2582 \cs_new:Nn
2583 \@@_get_option_value:nN
2584 {
2585 \@@_option_tl_to_csname:nN
2586 { #1 }
2587 \l_tmpa_tl
2588 \cs_if_free:cTF
2589 { \l_tmpa_tl }
2590 {
2591 \@@_get_default_option_value:nN
2592 { #1 }
2593 #2
2594 }
2595 {
2596 \@@_get_option_type:nN
2597 { #1 }
2598 \l_tmpa_tl
2599 \str_if_eq:NNTF
2600 \c_@@_option_type_counter_tl
2601 \l_tmpa_tl
2602 {
2603 \@@_option_tl_to_csname:nN
2604 { #1 }
2605 \l_tmpa_tl
2606 \tl_set:Nx
2607 #2
2608 { \the \cs:w \l_tmpa_tl \cs_end: }
2609 }
2610 {
2611 \@@_option_tl_to_csname:nN
2612 { #1 }
2613 \l_tmpa_tl
2614 \tl_set:Nv
2615 #2
2616 { \l_tmpa_tl }
2617 }
2618 }
2619 }
2620 \cs_new:Nn \@@_option_tl_to_csname:nN
2621 {
2622 \tl_set:Nn
2623 \l_tmpa_tl
2624 { \str_uppercase:n { #1 } }
2625 \tl_set:Nx
2626 #2
2627 {
2628 markdownOption
2629 \tl_head:f { \l_tmpa_tl }
2630 \tl_tail:n { #1 }
2631 }
2632 }
2633 \regex_const:Nn
2634 \c_@@_option_regex
2635 { ^markdownOption }
2636 \prg_new_conditional:Nnn
2637 \@@_csname_to_option_str:nN
2638 { T }
2639 {
2640 \tl_if_regex_match:nNTF
2641 { #1 }
2642 \c_@@_option_regex
2643 {
2644 \tl_set:Nn
2645 \l_tmpa_tl
2646 { #1 }
2647 \tl_regex_replace_once:NNn
2648 \l_tmpa_tl
2649 \c_@@_option_regex
2650 { }
2651 \tl_set:Nn
2652 \l_tmpb_tl
2653 {
2654 \str_lowercase:f
2655 { \l_tmpa_tl }
2656 }
2657 \str_set:Nx
2658 #2
2659 {
2660 \tl_head:f { \l_tmpb_tl }
2661 \tl_tail:V \l_tmpa_tl
2662 }
2663 \prg_return_true:
2664 }
2665 { \prg_return_false: }
2666 }
2667 % \end{macrocode}
2668 % \begin{markdown}
2669 %
2670 % To make it easier to support different coding styles in the interface,
2671 % engines, we define the \mdef{\@\@_with_various_cases:nn} function
2672 % that allows us to generate different variants of a string using
2673 % different cases.
2674 %
2675 % \end{markdown}
2676 % \begin{macrocode}
2677 \cs_new:Nn \@@_with_various_cases:nn
2678 {
2679 \seq_clear:N
2680 \l_tmpa_seq
2681 \seq_map_inline:Nn
2682 \g_@@_cases_seq
2683 {
2684 \tl_set:Nn
2685 \l_tmpa_tl
2686 { #1 }
2687 \use:c { ##1 }
2688 \l_tmpa_tl
2689 \seq_put_right:NV
2690 \l_tmpa_seq
2691 \l_tmpa_tl
2692 }
2693 \seq_map_inline:Nn
2694 \l_tmpa_seq
2695 { #2 }
2696 }
2697 % \end{macrocode}
2698 % \begin{markdown}
2699 %
2700 % By default, camelCase and snake\\\_case are supported.
2701 % Additional cases can be added by adding functions to the
2702 % \mdef{g_\@\@_cases_seq} sequence.
2703 %
2704 % \end{markdown}
2705 % \begin{macrocode}
2706 \seq_new:N \g_@@_cases_seq
2707 \cs_new:Nn \@@_camel_case:N
2708 {
2709 \regex_replace_all:nnN
2710 { _ ([a-z]) }
2711 { \c { str_uppercase:n } \cB\{ \1 \cE\} }
2712 #1
2713 \tl_set:Nx
2714 #1
2715 { #1 }
2716 }
2717 \seq_gput_right:Nn \g_@@_cases_seq { @@_camel_case:N }
2718 \cs_new:Nn \@@_snake_case:N
2719 {
2720 \regex_replace_all:nnN
2721 { ([a-z])([A-Z]) }
2722 { \1 _ \c { str_lowercase:n } \cB\{ \2 \cE\} }
2723 #1
2724 \tl_set:Nx
2725 #1
2726 { #1 }
2727 }
2728 \seq_gput_right:Nn \g_@@_cases_seq { @@_snake_case:N }
2729 % \end{macrocode}
2730 % \iffalse
2731 %</tex>
2732 %<*manual-options>
2733 % \fi
2734 % \begin{markdown}
2735 %
2736 %### General Behavior
2737 %
2738 % \end{markdown}
2739 % \iffalse
2740
2741 #### Option `eagerCache`
2742
2743 `eagerCache` (default value: `true`)
2744
2745 % \fi
2746 % \begin{markdown}
2747 %
2748 % \Optitem[true]{eagerCache}{\opt{true}, \opt{false}}
2749 %
2750 : true
2751
2752 : Converted markdown documents will be cached in \Opt{cacheDir}. This can be
2753 useful for post-processing the converted documents and for recovering
2754 historical versions of the documents from the cache. Furthermore, it can
2755 also significantly improve the processing speed for documents that require
2756 multiple compilation runs, since each markdown document is only converted once.
2757 However, it also produces a large number of auxiliary files on the disk
2758 and obscures the output of the Lua command-line interface when it is
2759 used for plumbing.
2760
2761 This behavior will always be used if the \Opt{finalizeCache} option is
2762 enabled.
2763
2764 : false
2765
2766 : Converted markdown documents will not be cached. This decreases the number
2767 of auxiliary files that we produce and makes it easier to use the Lua
2768 command-line interface for plumbing. However, it makes it impossible to
2769 post-process the converted documents and recover historical versions of
2770 the documents from the cache. Furthermore, it can significantly reduce
2771 the processing speed for documents that require multiple compilation
2772 runs, since each markdown document is converted multiple times needlessly.
2773
2774 This behavior will only be used when the \Opt{finalizeCache} option is
2775 disabled.
2776
2777 % \end{markdown}
2778 % \iffalse
2779
2780 ##### Lua CLI Example {.unnumbered}
2781
2782 Using a text editor, create a text document named `hello.md` with the
2783 following content:
2784 ``` md
2785 Hello *world*!
2786 ``````
2787 Next, invoke LuaTeX from the terminal with the \Opt{eagerCache} option
2788 disabled:
2789 ``` sh
2790 markdown2tex eagerCache=false -- hello.md hello.tex
2791 ```````
2792
2793 A \TeX{} document named `hello.tex` should be produced and contain the
2794 following code:
2795 ``` tex
2796 Hello \markdownRendererEmphasis{world}!\relax
2797 ```
2798
2799 ***
2800
2801 Invoke LuaTeX from the terminal again, this time with the \Opt{eagerCache}
2802 option enabled:
2803
2804 ``` tex
2805 markdown2tex eagerCache=true -- hello.md hello.tex
2806 ```
2807
2808 A \TeX{} document named `hello.tex` should be produced and contain the
2809 following code:
2810
2811 ``` tex
2812 \input ./⟨hash⟩.md.tex\relax
2813 ```
2814
2815 Additionally, a \TeX{} document named `⟨hash⟩.md.tex` should be produced and
2816 contain the following code:
2817
2818 ``` tex
2819 Hello \markdownRendererEmphasis{world}!\relax
2820 ```
2821
2822 %</manual-options>
2823 %<*tex>
2824 % \fi
2825 % \begin{macrocode}
2826 \@@_add_lua_option:nnn
2827 { eagerCache }
2828 { boolean }
2829 { true }
2830 % \end{macrocode}
2831 % \iffalse
2832 %</tex>
2833 %<*lua,lua-cli,lua-loader>
2834 % \fi
2835 % \begin{macrocode}
2836 defaultOptions.eagerCache = true
2837 % \end{macrocode}
2838 % \iffalse
2839 %</lua,lua-cli,lua-loader>
2840 %<*manual-options>
2841
2842 #### Option `experimental`
2843
2844 `experimental` (default value: `false`)
2845
2846 % \fi
2847 % \begin{markdown}
2848 %
2849 % \Optitem[false]{experimental}{\opt{true}, \opt{false}}
2850 %
2851 : true
2852
2853 : Experimental features that are planned to be the new default in the
2854 next major release of the Markdown package will be enabled.
2855
2856 At the moment, this has the following effects:
2857
2858 1. The version `experimental` of the theme `witiko/markdown/defaults`
2859 will be loaded.
2860 2. Warnings for hard-deprecated features will become errors.
2861 3. The experimental option \Opt{htmlOverLinks} will be enabled.
2862
2863 In the future, the effects may extend to other areas as well.
2864
2865 : false
2866
2867 : Experimental features will be disabled.
2868
2869 % \end{markdown}
2870 % \iffalse
2871 %</manual-options>
2872 %<*tex>
2873 % \fi
2874 % \begin{macrocode}
2875 \@@_add_lua_option:nnn
2876 { experimental }
2877 { boolean }
2878 { false }
2879 % \end{macrocode}
2880 % \iffalse
2881 %</tex>
2882 %<*lua,lua-cli,lua-loader>
2883 % \fi
2884 % \begin{macrocode}
2885 defaultOptions.experimental = false
2886 % \end{macrocode}
2887 % \iffalse
2888 %</lua,lua-cli,lua-loader>
2889 %<*manual-options>
2890
2891 #### Option `singletonCache`
2892
2893 `singletonCache` (default value: `true`)
2894
2895 % \fi
2896 % \begin{markdown}
2897 %
2898 % \Optitem[true]{singletonCache}{\opt{true}, \opt{false}}
2899 %
2900 : true
2901
2902 : Conversion functions produced by the function \luamref{new}`(options)`
2903 will be cached in an LRU cache of size 1 keyed by `options`. This is
2904 more time- and space-efficient than always producing a new conversion
2905 function but may expose bugs related to the idempotence of conversion
2906 functions.
2907
2908 This has been the default behavior since version 3.0.0 of the Markdown
2909 package.
2910
2911 : false
2912
2913 : Every call to the function \luamref{new}`(options)` will produce a new
2914 conversion function that will not be cached. This is slower than
2915 caching conversion functions and may expose bugs related to memory
2916 leaks in the creation of conversion functions, see also [#226 (comment)][226-comment].
2917
2918 This was the default behavior until version 3.0.0 of the Markdown package.
2919
2920 [226-comment]: https://github.com/witiko/markdown/pull/226#issuecomment-1599641634
2921
2922 % \end{markdown}
2923 % \iffalse
2924 %</manual-options>
2925 %<*tex>
2926 % \fi
2927 % \begin{macrocode}
2928 \@@_add_lua_option:nnn
2929 { singletonCache }
2930 { boolean }
2931 { true }
2932 % \end{macrocode}
2933 % \iffalse
2934 %</tex>
2935 %<*lua,lua-cli,lua-loader>
2936 % \fi
2937 % \begin{macrocode}
2938 defaultOptions.singletonCache = true
2939 % \end{macrocode}
2940 % \iffalse
2941 %</lua,lua-cli,lua-loader>
2942 %<*lua>
2943 % \fi
2944 % \begin{macrocode}
2945 local singletonCache = {
2946 convert = nil,
2947 options = nil,
2948 }
2949 % \end{macrocode}
2950 % \iffalse
2951 %</lua>
2952 %<*manual-options>
2953
2954 #### Option `unicodeNormalization`
2955
2956 `unicodeNormalization` (default value: `true`)
2957
2958 % \fi
2959 % \begin{markdown}
2960 %
2961 % \Optitem[true]{unicodeNormalization}{\opt{true}, \opt{false}}
2962 %
2963 : true
2964
2965 : Markdown documents will be normalized using one of the four [Unicode
2966 normalization forms][unicode-normalization] before conversion. The
2967 Unicode normalization norm used is determined by option
2968 \Opt{unicodeNormalizationForm}.
2969
2970 : false
2971
2972 : Markdown documents will not be Unicode-normalized before conversion.
2973
2974 [unicode-normalization]: https://unicode.org/faq/normalization.html
2975
2976 % \end{markdown}
2977 % \iffalse
2978 %</manual-options>
2979 %<*tex>
2980 % \fi
2981 % \begin{macrocode}
2982 \@@_add_lua_option:nnn
2983 { unicodeNormalization }
2984 { boolean }
2985 { true }
2986 % \end{macrocode}
2987 % \iffalse
2988 %</tex>
2989 %<*lua,lua-cli,lua-loader>
2990 % \fi
2991 % \begin{macrocode}
2992 defaultOptions.unicodeNormalization = true
2993 % \end{macrocode}
2994 % \iffalse
2995 %</lua,lua-cli,lua-loader>
2996 %<*manual-options>
2997
2998 #### Option `unicodeNormalizationForm`
2999
3000 `unicodeNormalizationForm` (default value: `nfc`)
3001
3002 % \fi
3003 % \begin{markdown}
3004 %
3005 % \Optitem[nfc]{unicodeNormalizationForm}{\opt{nfc}, \opt{nfd}, \opt{nfkc}, \opt{nfkd}}
3006 %
3007 : nfc
3008
3009 : When option \Opt{unicodeNormalization} has been enabled, markdown documents
3010 will be normalized using Unicode Normalization Form C (NFC) before
3011 conversion.
3012
3013 : nfd
3014
3015 : When option \Opt{unicodeNormalization} has been enabled, markdown documents
3016 will be normalized using Unicode Normalization Form D (NFD) before
3017 conversion.
3018
3019 : nfkc
3020
3021 : When option \Opt{unicodeNormalization} has been enabled, markdown documents
3022 will be normalized using Unicode Normalization Form KC (NFKC) before
3023 conversion.
3024
3025 : nfkd
3026
3027 : When option \Opt{unicodeNormalization} has been enabled, markdown documents
3028 will be normalized using Unicode Normalization Form KD (NFKD) before
3029 conversion.
3030
3031 % \end{markdown}
3032 % \iffalse
3033 %</manual-options>
3034 %<*tex>
3035 % \fi
3036 % \begin{macrocode}
3037 \@@_add_lua_option:nnn
3038 { unicodeNormalizationForm }
3039 { string }
3040 { nfc }
3041 % \end{macrocode}
3042 % \iffalse
3043 %</tex>
3044 %<*lua,lua-cli,lua-loader>
3045 % \fi
3046 % \begin{macrocode}
3047 defaultOptions.unicodeNormalizationForm = "nfc"
3048 % \end{macrocode}
3049 % \iffalse
3050 %</lua,lua-cli,lua-loader>
3051 %<*manual-options>
3052 % \fi
3053 % \begin{markdown}
3054 %
3055 %### File and Directory Names
3056 %
3057 % \end{markdown}
3058 % \iffalse
3059
3060 #### Option `cacheDir`
3061
3062 `cacheDir` (default value: `"."`)
3063
3064 % \fi
3065 % \begin{markdown}
3066 %
3067 % \Valitem[.]{cacheDir}{path}
3068 %
3069 : A path to the directory containing auxiliary cache files. If the last
3070 segment of the path does not exist, it will be created by the Lua
3071 command-line and plain \TeX{} implementations. The Lua implementation
3072 expects that the entire path already exists.
3073
3074 When iteratively writing and typesetting a markdown document, the cache
3075 files are going to accumulate over time. You are advised to clean the
3076 cache directory every now and then, or to set it to a temporary filesystem
3077 (such as `/tmp` on UN*X systems), which gets periodically emptied.
3078
3079 % \end{markdown}
3080 % \iffalse
3081
3082 ##### Lua Module Example {.unnumbered}
3083
3084 Using a text editor, create a text document named `document.tex` with the
3085 following content:
3086 ``` tex
3087 \input markdown
3088 \begingroup
3089 \catcode`\%=12
3090 \catcode`\#=12
3091 \directlua{
3092 local markdown = require("markdown")
3093 local convert = markdown.new({cacheDir = "cache"})
3094 local input = "Hello *world*!"
3095 tex.sprint(convert(input)) }
3096 \endgroup
3097 \bye
3098 ```````
3099 Create an empty directory named `cache` next to our text document. Then, invoke
3100 LuaTeX from the terminal:
3101 ``` sh
3102 luatex document.tex
3103 ```````
3104 A PDF document named `document.pdf` should be produced and contain the text
3105 “Hello *world*!” Several cache files of the Markdown package will also be
3106 produced in the `cache` directory as we requested using the `cacheDir` option.
3107
3108 ##### Lua CLI Example {.unnumbered}
3109
3110 Using a text editor, create a text document named `document.tex` with the
3111 following content:
3112 ``` tex
3113 \input markdown
3114 \begingroup
3115 \catcode`\%=12
3116 \catcode`\#=12
3117 \input hello
3118 \endgroup
3119 \bye
3120 ```````
3121 Using a text editor, create a text document named `hello.md` with the
3122 following content:
3123 ``` md
3124 Hello *world*!
3125 ``````
3126 Next, invoke LuaTeX from the terminal:
3127 ``` sh
3128 markdown2tex cacheDir=cache -- hello.md hello.tex
3129 luatex document.tex
3130 ```````
3131
3132 A PDF document named `document.pdf` should be produced and contain the text
3133 “Hello *world*!” A directory named `cache` containing several cache files of
3134 the Markdown package will also be produced as we requested using the `cacheDir`
3135 option.
3136
3137 ##### Plain \TeX{} Example {.unnumbered}
3138
3139 Using a text editor, create a text document named `document.tex` with the
3140 following content:
3141 ``` tex
3142 \input markdown
3143 \def\markdownOptionCacheDir{cache}
3144 \markdownBegin
3145 Hello *world*!
3146 \markdownEnd
3147 \bye
3148 ```````
3149 Next, invoke LuaTeX from the terminal:
3150 ``` sh
3151 luatex document.tex
3152 ``````
3153 A PDF document named `document.pdf` should be produced and contain the text “Hello
3154 *world*!” A directory named `cache` containing several cache files of the
3155 Markdown package will also be produced as we requested using the `cacheDir`
3156 option.
3157
3158 ##### \LaTeX{} Example {.unnumbered}
3159
3160 Using a text editor, create a text document named `document.tex` with the
3161 following content:
3162 ``` tex
3163 \documentclass{article}
3164 \usepackage[cacheDir=cache]{markdown}
3165 \begin{document}
3166 \begin{markdown}
3167 Hello *world*!
3168 \end{markdown}
3169 \end{document}
3170 ```````
3171 Next, invoke LuaTeX from the terminal:
3172 ``` sh
3173 lualatex document.tex
3174 ``````
3175 A PDF document named `document.pdf` should be produced and contain the text “Hello
3176 *world*!” A directory named `cache` containing several cache files of the
3177 Markdown package will also be produced as we requested using the `cacheDir`
3178 option.
3179
3180 ##### \Hologo{ConTeXt} Example {.unnumbered}
3181
3182 Using a text editor, create a text document named `document.tex` with the
3183 following content:
3184 ``` tex
3185 \usemodule[t][markdown]
3186 \setupmarkdown[cacheDir = cache]
3187 \starttext
3188 \startmarkdown
3189 Hello *world*!
3190 \stopmarkdown
3191 \stoptext
3192 ```````
3193 Next, invoke LuaTeX from the terminal:
3194 ``` sh
3195 context --luatex document.tex
3196 ``````
3197 A PDF document named `document.pdf` should be produced and contain the text “Hello
3198 *world*!” A directory named `cache` containing several cache files of the
3199 Markdown package will also be produced as we requested using the `cacheDir`
3200 option.
3201
3202 %</manual-options>
3203 %<*tex>
3204 % \fi
3205 % \begin{macrocode}
3206 \str_new:N
3207 \g_@@_unquoted_jobname_str
3208 \str_gset:NV
3209 \g_@@_unquoted_jobname_str
3210 \c_sys_jobname_str
3211 \bool_new:N
3212 \g_@@_jobname_quoted_bool
3213 \regex_replace_all:nnNTF
3214 { \A ("|') ( .* ) ("|') \Z }
3215 { \2 }
3216 \g_@@_unquoted_jobname_str
3217 {
3218 \bool_gset_true:N
3219 \g_@@_jobname_quoted_bool
3220 }
3221 {
3222 \bool_gset_false:N
3223 \g_@@_jobname_quoted_bool
3224 }
3225 \@@_add_lua_option:nnn
3226 { cacheDir }
3227 { path }
3228 {
3229 \markdownOptionOutputDir
3230 / _markdown_
3231 \str_use:N
3232 \g_@@_unquoted_jobname_str
3233 }
3234 % \end{macrocode}
3235 % \iffalse
3236 %</tex>
3237 %<*lua,lua-cli,lua-loader>
3238 % \fi
3239 % \begin{macrocode}
3240 defaultOptions.cacheDir = "."
3241 % \end{macrocode}
3242 % \iffalse
3243 %</lua,lua-cli,lua-loader>
3244 %<*manual-options>
3245
3246 #### Option `contentBlocksLanguageMap`
3247
3248 `contentBlocksLanguageMap` (default value: `"markdown-languages.json"`)
3249
3250 % \fi
3251 % \begin{markdown}
3252 %
3253 % \Valitem[markdown-languages.json]{contentBlocksLanguageMap}{filename}
3254 %
3255 : The filename of the JSON file that maps filename extensions to
3256 programming language names in the iA\\,Writer content blocks when the
3257 \Opt{contentBlocks} option is enabled.
3258 % See Section <#sec:texcontentblockrenderers> for more information.
3259
3260 % \end{markdown}
3261 % \iffalse
3262
3263 ##### \LaTeX{} Example {.unnumbered}
3264
3265 Using a text editor, create a text document named `table.csv` with the
3266 following content:
3267 ``` csv
3268 Name,Surname,Born
3269 Albert,Einstein,1879
3270 Marie,Curie,1867
3271 Thomas,Edison,1847
3272 ```````
3273 Create also a text document named `language-map.json` with the following
3274 content:
3275 ``` js
3276 {
3277 "tex": "LaTeX"
3278 }
3279 ``````
3280 Create also a text document named `code.tex` with the following content:
3281 ``` tex
3282 This is an example code listing in \LaTeX.
3283 ```````
3284 Create also a text document named `part.md` with the following content:
3285 ``` md
3286 This is a *transcluded markdown document*.
3287 ``````
3288 Create also a text document named `document.tex` with the following content:
3289 ``` tex
3290 \documentclass{article}
3291 \usepackage{minted}
3292 \usepackage[contentBlocks]{markdown}
3293 \markdownSetup{
3294 contentBlocksLanguageMap = {language-map.json},
3295 }
3296 \begin{document}
3297 \begin{markdown}
3298 /table.csv (An example table)
3299 /code.tex (An example code listing)
3300 /part.md (A file transclusion example)
3301 \end{markdown}
3302 \end{document}
3303 ```````
3304 Next, invoke LuaTeX from the terminal:
3305 ``` sh
3306 lualatex --shell-escape document.tex
3307 ``````
3308 A PDF document named `document.pdf` should be produced and contain the
3309 following text:
3310
3311 > | Name | Surname | Born |
3312 > | ------ | ---------| ---- |
3313 > | Albert | Einstein | 1879 |
3314 > | Marie | Curie | 1867 |
3315 > | Thomas | Edison | 1847 |
3316 >
3317 > Table 1: An example table
3318 >
3319 > ``` tex
3320 > This is an example code listing in \LaTeX.
3321 > ```````
3322 >
3323 > This is a *transcluded markdown document*.
3324
3325 ##### \Hologo{ConTeXt} Example {.unnumbered}
3326
3327 Using a text editor, create a text document named `table.csv` with the
3328 following content:
3329 ``` csv
3330 Name,Surname,Born
3331 Albert,Einstein,1879
3332 Marie,Curie,1867
3333 Thomas,Edison,1847
3334 ```````
3335 Create also a text document named `language-map.json` with the following
3336 content:
3337 ``` js
3338 {
3339 "tex": "ConTeXt"
3340 }
3341 ``````
3342 Create also a text document named `code.tex` with the following content:
3343 ``` tex
3344 This is an example code listing in \ConTeXt.
3345 ```````
3346 Create also a text document named `part.md` with the following content:
3347 ``` md
3348 This is a *transcluded markdown document*.
3349 ``````
3350 Create also a text document named `document.tex` with the following content:
3351 ``` tex
3352 \usemodule[t][markdown]
3353 \setupmarkdown
3354 [
3355 contentBlocks = yes,
3356 contentBlocksLanguageMap = language-map.json,
3357 ]
3358 \definetyping [ConTeXt]
3359 \setuptyping [ConTeXt] [option=TEX]
3360 \starttext
3361 \startmarkdown
3362 /table.csv (An example table)
3363 /code.tex (An example code listing)
3364 /part.md (A file transclusion example)
3365 \stopmarkdown
3366 \stoptext
3367 ````````
3368 Next, invoke LuaTeX from the terminal:
3369 ``` sh
3370 context --luatex document.tex
3371 `````
3372 A PDF document named `document.pdf` should be produced and contain the
3373 following text:
3374
3375 > | Name | Surname | Born |
3376 > | ------ | ---------| ---- |
3377 > | Albert | Einstein | 1879 |
3378 > | Marie | Curie | 1867 |
3379 > | Thomas | Edison | 1847 |
3380 >
3381 > Table 1: An example table
3382 >
3383 > ``` tex
3384 > This is an example code listing in \ConTeXt.
3385 > ```````
3386 >
3387 > This is a *transcluded markdown document*.
3388
3389 %</manual-options>
3390 %<*tex>
3391 % \fi
3392 % \begin{macrocode}
3393 \@@_add_lua_option:nnn
3394 { contentBlocksLanguageMap }
3395 { path }
3396 { markdown-languages.json }
3397 % \end{macrocode}
3398 % \iffalse
3399 %</tex>
3400 %<*lua,lua-cli,lua-loader>
3401 % \fi
3402 % \begin{macrocode}
3403 defaultOptions.contentBlocksLanguageMap = "markdown-languages.json"
3404 % \end{macrocode}
3405 % \iffalse
3406 %</lua,lua-cli,lua-loader>
3407 %<*manual-options>
3408
3409 #### Option `debugExtensionsFileName`
3410
3411 `debugExtensionsFileName` (default value: `"debug-extensions.json"`)
3412
3413 % \fi
3414 % \begin{markdown}
3415 %
3416 % \Valitem[debug-extensions.json]{debugExtensionsFileName}{filename}
3417 %
3418 : The filename of the JSON file that will be produced when the
3419 \Opt{debugExtensions} option is enabled. This file will contain the
3420 extensible subset of the PEG grammar of markdown
3421 % (see the \luamref{walkable_syntax} hash table)
3422 after built-in syntax extensions
3423 % (see Section <#sec:lua-built-in-extensions>)
3424 % \iffalse
3425 (see options \Opt{citations}, \Opt{contentBlocks}, \Opt{definitionLists},
3426 etc.)
3427 % \fi
3428 and user-defined syntax extensions
3429 % (see Section <#sec:lua-user-extensions>)
3430 % \iffalse
3431 (see option \Opt{extensions})
3432 % \fi
3433 have been applied.
3434
3435 % \end{markdown}
3436 % \iffalse
3437 %</manual-options>
3438 %<*tex>
3439 % \fi
3440 % \begin{macrocode}
3441 \@@_add_lua_option:nnn
3442 { debugExtensionsFileName }
3443 { path }
3444 {
3445 \markdownOptionOutputDir
3446 /
3447 \str_use:N
3448 \g_@@_unquoted_jobname_str
3449 .debug-extensions.json
3450 }
3451 % \end{macrocode}
3452 % \iffalse
3453 %</tex>
3454 %<*lua,lua-cli,lua-loader>
3455 % \fi
3456 % \begin{macrocode}
3457 defaultOptions.debugExtensionsFileName = "debug-extensions.json"
3458 % \end{macrocode}
3459 % \iffalse
3460 %</lua,lua-cli,lua-loader>
3461 %<*manual-options>
3462
3463 #### Option `frozenCacheFileName`
3464
3465 `frozenCacheFileName` (default value: `"frozenCache.tex"`)
3466
3467 % \fi
3468 % \begin{markdown}
3469 %
3470 % \Valitem[frozenCache.tex]{frozenCacheFileName}{path}
3471 %
3472 : A path to an output file (frozen cache) that will be created when
3473 the \Opt{finalizeCache} option is enabled and will contain a mapping
3474 between an enumeration of markdown documents and their auxiliary cache
3475 files.
3476
3477 The frozen cache makes it possible to later typeset a plain \TeX{}
3478 document that contains markdown documents without invoking Lua using
3479 the \Opt{frozenCache} plain \TeX{} option. As a result, the
3480 plain \TeX{} document becomes more portable, but further changes in the
3481 order and the content of markdown documents will not be reflected.
3482
3483 % \end{markdown}
3484 % \iffalse
3485
3486 ##### Lua Module Example {.unnumbered}
3487
3488 Using a text editor, create a text document named `document.tex` with the
3489 following content:
3490 ``` tex
3491 \input markdown
3492 \begingroup
3493 \catcode`\%=12
3494 \catcode`\#=12
3495 \directlua{
3496 local markdown = require("markdown")
3497 local convert = markdown.new({finalizeCache = true, frozenCacheFileName = "cache.tex"})
3498 local input = "Hello *world*!"
3499 tex.sprint(convert(input)) }
3500 \endgroup
3501 \bye
3502 ```````
3503 Then, invoke LuaTeX from the terminal:
3504 ``` sh
3505 luatex document.tex
3506 ```````
3507 A PDF document named `document.pdf` should be produced and contain the text
3508 “Hello *world*!” A frozen cache will also be produced in the `cache.tex`
3509 output file as we requested using the `finalizeCache` and `frozenCacheFileName`
3510 options.
3511
3512 ##### Lua CLI Example {.unnumbered}
3513
3514 Using a text editor, create a text document named `document.tex` with the
3515 following content:
3516 ``` tex
3517 \input markdown
3518 \begingroup
3519 \catcode`\%=12
3520 \catcode`\#=12
3521 \input hello
3522 \endgroup
3523 \bye
3524 ```````
3525 Using a text editor, create a text document named `hello.md` with the
3526 following content:
3527 ``` md
3528 Hello *world*!
3529 ``````
3530 Next, invoke LuaTeX from the terminal:
3531 ``` sh
3532 markdown2tex finalizeCache=true frozenCacheFileName=cache.tex -- hello.md hello.tex
3533 luatex document.tex
3534 ```````
3535
3536 A PDF document named `document.pdf` should be produced and contain the text
3537 “Hello *world*!” A frozen cache will also be produced in the `cache.tex`
3538 output file as we requested using the `finalizeCache` and `frozenCacheFileName`
3539 options.
3540
3541 ##### Plain \TeX{} Example {.unnumbered}
3542
3543 Using a text editor, create a text document named `document.tex` with the
3544 following content:
3545 ``` tex
3546 \input markdown
3547 \def\markdownOptionFinalizeCache{true}
3548 \def\markdownOptionFrozenCacheFileName{cache.tex}
3549 \markdownBegin
3550 Hello *world*!
3551 \markdownEnd
3552 \bye
3553 ```````
3554 Next, invoke LuaTeX from the terminal:
3555 ``` sh
3556 luatex document.tex
3557 ``````
3558 A PDF document named `document.pdf` should be produced and contain the text
3559 “Hello *world*!” A frozen cache will also be produced in the `cache.tex`
3560 output file as we requested using the `finalizeCache` and `frozenCacheFileName`
3561 options.
3562
3563 Next, create a new text document `frozen-document.tex` with the following
3564 content:
3565 ``` tex
3566 \input markdown
3567 \def\markdownOptionFrozenCache{true}
3568 \def\markdownOptionFrozenCacheFileName{cache.tex}
3569 \markdownBegin
3570 Hi *world*!
3571 \markdownEnd
3572 \bye
3573 ```````
3574 Last, invoke pdfTeX without shell access from the terminal:
3575 ``` sh
3576 pdftex -no-shell-escape frozen-document.tex
3577 ``````
3578 A PDF document named `frozen-document.pdf` should be produced and contain the
3579 text “Hello *world*!” Since we used the contents of the frozen cache using
3580 the `\markdownOptionFrozenCache` option, we were able to typeset the
3581 document without accessing the shell or invoking Lua, but the change in the
3582 content of the markdown document from “Hello *world*!” to “Hi *world*!” was
3583 not reflected.
3584
3585 ##### \LaTeX{} Example {.unnumbered}
3586
3587 Using a text editor, create a text document named `document.tex` with the
3588 following content:
3589 ``` tex
3590 \documentclass[finalizecache]{article}
3591 \usepackage[frozenCacheFileName=cache.tex]{markdown}
3592 \begin{document}
3593 \begin{markdown}
3594 Hello *world*!
3595 \end{markdown}
3596 \end{document}
3597 ```````
3598 Next, invoke LuaTeX from the terminal:
3599 ``` sh
3600 lualatex document.tex
3601 ``````
3602 A PDF document named `document.pdf` should be produced and contain the text
3603 “Hello *world*!” A frozen cache will also be produced in the `cache.tex`
3604 output file as we requested using the `finalizecache` and `frozenCacheFileName`
3605 options.
3606
3607 Next, create a new text document `frozen-document.tex` with the following
3608 content:
3609 ``` tex
3610 \documentclass[frozencache]{article}
3611 \usepackage[frozenCacheFileName=cache.tex]{markdown}
3612 \begin{document}
3613 \begin{markdown}
3614 Hi *world*!
3615 \end{markdown}
3616 \end{document}
3617 ```````
3618 Last, invoke pdfTeX without shell access from the terminal:
3619 ``` sh
3620 pdflatex -no-shell-escape frozen-document.tex
3621 ``````
3622 A PDF document named `frozen-document.pdf` should be produced and contain the
3623 text “Hello *world*!” Since we used the contents of the frozen cache using
3624 the `frozencache` option, we were able to typeset the document without
3625 accessing the shell or invoking Lua, but the change in the content of the
3626 markdown document from “Hello *world*!” to “Hi *world*!” was not reflected.
3627
3628 ##### \Hologo{ConTeXt} Example {.unnumbered}
3629
3630 Using a text editor, create a text document named `document.tex` with the
3631 following content:
3632 ``` tex
3633 \usemodule[t][markdown]
3634 \setupmarkdown
3635 [
3636 finalizeCache = yes,
3637 frozenCacheFileName = cache.tex,
3638 ]
3639 \starttext
3640 \startmarkdown
3641 Hello *world*!
3642 \stopmarkdown
3643 \stoptext
3644 ```````
3645 Next, invoke LuaTeX from the terminal:
3646 ``` sh
3647 context --luatex document.tex
3648 ``````
3649 A PDF document named `document.pdf` should be produced and contain the text
3650 “Hello *world*!” A frozen cache will also be produced in the `cache.tex`
3651 output file as we requested using the `finalizeCache` and `frozenCacheFileName`
3652 options.
3653
3654 Next, create a new text document `frozen-document.tex` with the following
3655 content:
3656 ``` tex
3657 \usemodule[t][markdown]
3658 \setupmarkdown
3659 [
3660 frozenCache = yes,
3661 frozenCacheFileName = cache.tex,
3662 ]
3663 \starttext
3664 \startmarkdown
3665 Hi *world*!
3666 \stopmarkdown
3667 \stoptext
3668 ```````
3669 Last, invoke LuaTeX from the terminal:
3670 ``` sh
3671 context --luatex frozen-document.tex
3672 ``````
3673 A PDF document named `frozen-document.pdf` should be produced and contain the
3674 text “Hello *world*!” Since we used the contents of the frozen cache using
3675 the `\markdownOptionFrozenCache` option, we were able to typeset the document
3676 without accessing the shell or invoking Lua, but the change in the content of
3677 the markdown document from “Hello *world*!” to “Hi *world*!” was not reflected.
3678
3679 %</manual-options>
3680 %<*tex>
3681 % \fi
3682 % \begin{macrocode}
3683 \@@_add_lua_option:nnn
3684 { frozenCacheFileName }
3685 { path }
3686 { \markdownOptionCacheDir / frozenCache.tex }
3687 % \end{macrocode}
3688 % \iffalse
3689 %</tex>
3690 %<*lua,lua-cli,lua-loader>
3691 % \fi
3692 % \begin{macrocode}
3693 defaultOptions.frozenCacheFileName = "frozenCache.tex"
3694 % \end{macrocode}
3695 % \iffalse
3696 %</lua,lua-cli,lua-loader>
3697 %<*manual-options>
3698 % \fi
3699 % \begin{markdown}
3700 %
3701 %### Parser Options
3702 %
3703 % \end{markdown}
3704 % \iffalse
3705
3706 #### Option `acronyms`
3707
3708 `acronyms` (default value: `{}`)
3709
3710 % \fi
3711 % \begin{markdown}
3712 % \Valitem[\{\}]{acronyms}{acronyms}
3713 %
3714 : Acronyms, initialisms, and other all-caps sequences that will be
3715 recognized in markdown text and formatted accordingly.
3716 % \end{markdown}
3717 % \iffalse
3718
3719 ##### \LaTeX{} Example {.unnumbered}
3720
3721 Using a text editor, create a text document named `document.tex` with the
3722 following content:
3723 ```` tex
3724 \documentclass{article}
3725 \usepackage{markdown}
3726 \markdownSetup {
3727 % Format the following words as acronyms.
3728 acronyms = {HTML, YAML},
3729 renderers = {
3730 % Format acronyms as small caps.
3731 acronym = \textsc{\MakeLowercase{#1}},
3732 },
3733 }
3734 \begin{document}
3735 \begin{markdown}
3736
3737 HTML and YAML are two staples of modern tooling that often get mentioned
3738 in the same breath, even though they live in very different layers of the stack.
3739
3740 \end{markdown}
3741 \end{document}
3742 ```````
3743 Next, invoke LuaTeX from the terminal:
3744 ``` sh
3745 lualatex --shell-escape document.tex
3746 ``````
3747 A PDF document named `document.pdf` should be produced and contain the
3748 following text:
3749
3750 > <abbr>HTML</abbr> and <abbr>YAML</abbr> are two staples of modern tooling
3751 > that often get mentioned in the same breath, even though they live in very
3752 > different layers of the stack.
3753
3754 %</manual-options>
3755 %<*tex>
3756 % \fi
3757 % \begin{macrocode}
3758 \cs_generate_variant:Nn
3759 \@@_add_lua_option:nnn
3760 { nnV }
3761 \@@_add_lua_option:nnV
3762 { acronyms }
3763 { clist }
3764 \c_empty_clist
3765 % \end{macrocode}
3766 % \iffalse
3767 %</tex>
3768 %<*lua,lua-cli,lua-loader>
3769 % \fi
3770 % \begin{macrocode}
3771 defaultOptions.acronyms = {}
3772 % \end{macrocode}
3773 % \iffalse
3774 %</lua,lua-cli,lua-loader>
3775 %<*manual-options>
3776
3777 #### Option `autoIdentifiers`
3778
3779 `autoIdentifiers` (default value: `false`)
3780
3781 % \fi
3782 % \begin{markdown}
3783 % \Optitem[false]{autoIdentifiers}{\opt{true}, \opt{false}}
3784 %
3785 : true
3786
3787 : Enable the Pandoc [auto identifiers syntax extension][pandoc-auto-identifiers]:
3788
3789 ``` md
3790 The following heading received the identifier
3791 `sesame-street`:
3792
3793 # 123 Sesame Street
3794 ``````
3795
3796 : false
3797
3798 : Disable the Pandoc auto identifiers syntax extension.
3799
3800 See also the option \Opt{gfmAutoIdentifiers}.
3801
3802 [pandoc-auto-identifiers]: https://pandoc.org/MANUAL.html#extension-auto_identifiers
3803
3804 % \end{markdown}
3805 % \iffalse
3806 %</manual-options>
3807 %<*tex>
3808 % \fi
3809 % \begin{macrocode}
3810 \@@_add_lua_option:nnn
3811 { autoIdentifiers }
3812 { boolean }
3813 { false }
3814 % \end{macrocode}
3815 % \iffalse
3816 %</tex>
3817 %<*lua,lua-cli,lua-loader>
3818 % \fi
3819 % \begin{macrocode}
3820 defaultOptions.autoIdentifiers = false
3821 % \end{macrocode}
3822 % \iffalse
3823 %</lua,lua-cli,lua-loader>
3824 %<*manual-options>
3825
3826 #### Option `blankBeforeBlockquote`
3827
3828 `blankBeforeBlockquote` (default value: `false`)
3829
3830 % \fi
3831 % \begin{markdown}
3832 % \Optitem[false]{blankBeforeBlockquote}{\opt{true}, \opt{false}}
3833 %
3834 : true
3835
3836 : Require a blank line between a paragraph and the following blockquote.
3837
3838 : false
3839
3840 : Do not require a blank line between a paragraph and the following
3841 blockquote.
3842
3843 % \end{markdown}
3844 % \iffalse
3845
3846 ##### Lua Module Example {.unnumbered}
3847
3848 Using a text editor, create a text document named `document.tex` with the
3849 following content:
3850 ``` tex
3851 \input markdown
3852 \input lmfonts
3853 \begingroup
3854 \catcode`\%=12
3855 \catcode`\#=12
3856 \directlua{
3857 local markdown = require("markdown")
3858 local newline = [[^^J^^J]]
3859 local convert, input
3860
3861 convert = markdown.new()
3862 input = "A paragraph." .. newline ..
3863 "> A quote." .. newline
3864 tex.sprint(convert(input))
3865
3866 convert = markdown.new({blankBeforeBlockquote = true})
3867 input = "A paragraph." .. newline ..
3868 "> Not a quote." .. newline
3869 tex.sprint(convert(input)) }
3870 \endgroup
3871 \bye
3872 ```````
3873 Then, invoke LuaTeX from the terminal:
3874 ``` sh
3875 luatex document.tex
3876 ```````
3877 A PDF document named `document.pdf` should be produced and contain the
3878 following text:
3879
3880 > A paragraph.
3881 >
3882 > > A quote.
3883 >
3884 > A paragraph > Not a quote.
3885
3886 ##### Lua CLI Example {.unnumbered}
3887
3888 Using a text editor, create a text document named `document.tex` with the
3889 following content:
3890 ``` tex
3891 \input markdown
3892 \input lmfonts
3893 \begingroup
3894 \catcode`\%=12
3895 \catcode`\#=12
3896 \input optionfalse
3897 \input optiontrue
3898 \endgroup
3899 \bye
3900 ```````
3901 Using a text editor, create a text document named `content.md` with the
3902 following content:
3903 ``` md
3904 A paragraph.
3905 > A quote?
3906 ``````
3907 Next, invoke LuaTeX from the terminal:
3908 ``` sh
3909 markdown2tex -- content.md optionfalse.tex
3910 markdown2tex blankBeforeBlockquote=true -- content.md optiontrue.tex
3911 luatex document.tex
3912 ```````
3913
3914 A PDF document named `document.pdf` should be produced and contain the
3915 following text:
3916
3917 > A paragraph.
3918 >
3919 > > A quote?
3920 >
3921 > A paragraph. > A quote?
3922
3923 ##### Plain \TeX{} Example {.unnumbered}
3924
3925 Using a text editor, create a text document named `document.tex` with the
3926 following content:
3927 ``` tex
3928 \input markdown
3929
3930 \markdownBegin
3931 A paragraph.
3932 > A quote.
3933 \markdownEnd
3934
3935 \def\markdownOptionBlankBeforeBlockquote{true}
3936 \markdownBegin
3937 A paragraph.
3938 > Not a quote.
3939 \markdownEnd
3940
3941 \bye
3942 ```````
3943 Next, invoke LuaTeX from the terminal:
3944 ``` sh
3945 luatex document.tex
3946 ``````
3947 A PDF document named `document.pdf` should be produced and contain the
3948 following text:
3949
3950 > A paragraph.
3951 >
3952 > > A quote.
3953 >
3954 > A paragraph > Not a quote.
3955
3956 ##### \LaTeX{} Example {.unnumbered}
3957
3958 Using a text editor, create a text document named `document.tex` with the
3959 following content:
3960 ``` tex
3961 \documentclass{article}
3962 \usepackage{markdown}
3963 \begin{document}
3964
3965 \begin{markdown}
3966 A paragraph.
3967 > A quote.
3968 \end{markdown}
3969
3970 \begin{markdown}[blankBeforeBlockquote]
3971 A paragraph.
3972 > Not a quote.
3973 \end{markdown}
3974
3975 \end{document}
3976 ```````
3977 Next, invoke LuaTeX from the terminal:
3978 ``` sh
3979 lualatex document.tex
3980 ``````
3981 A PDF document named `document.pdf` should be produced and contain the
3982 following text:
3983
3984 > A paragraph.
3985 >
3986 > > A quote.
3987 >
3988 > A paragraph > Not a quote.
3989
3990 ##### \Hologo{ConTeXt} Example {.unnumbered}
3991
3992 Using a text editor, create a text document named `document.tex` with the
3993 following content:
3994 ``` tex
3995 \usemodule[t][markdown]
3996 \starttext
3997
3998 \startmarkdown
3999 A paragraph.
4000 > A quote.
4001 \stopmarkdown
4002
4003 \setupmarkdown[blankBeforeBlockquote = yes]
4004 \startmarkdown
4005 A paragraph.
4006 > Not a quote.
4007 \stopmarkdown
4008
4009 \stoptext
4010 ```````
4011 Next, invoke LuaTeX from the terminal:
4012 ``` sh
4013 context --luatex document.tex
4014 ``````
4015 A PDF document named `document.pdf` should be produced and contain the
4016 following text:
4017
4018 > A paragraph.
4019 >
4020 > > A quote.
4021 >
4022 > A paragraph > Not a quote.
4023
4024 %</manual-options>
4025 %<*tex>
4026 % \fi
4027 % \begin{macrocode}
4028 \@@_add_lua_option:nnn
4029 { blankBeforeBlockquote }
4030 { boolean }
4031 { false }
4032 % \end{macrocode}
4033 % \iffalse
4034 %</tex>
4035 %<*lua,lua-cli,lua-loader>
4036 % \fi
4037 % \begin{macrocode}
4038 defaultOptions.blankBeforeBlockquote = false
4039 % \end{macrocode}
4040 % \iffalse
4041 %</lua,lua-cli,lua-loader>
4042 %<*manual-options>
4043
4044 #### Option `blankBeforeCodeFence`
4045
4046 `blankBeforeCodeFence` (default value: `false`)
4047
4048 % \fi
4049 % \begin{markdown}
4050 %
4051 % \Optitem[false]{blankBeforeCodeFence}{\opt{true}, \opt{false}}
4052 %
4053 : true
4054
4055 : Require a blank line between a paragraph and the following fenced code
4056 block.
4057
4058 : false
4059
4060 : Do not require a blank line between a paragraph and the following
4061 fenced code block.
4062
4063 % \end{markdown}
4064 % \iffalse
4065
4066 ##### Lua Module Example {.unnumbered}
4067
4068 Using a text editor, create a text document named `document.tex` with the
4069 following content:
4070 ``` tex
4071 \input markdown
4072 \input lmfonts
4073 \begingroup
4074 \catcode`\%=12
4075 \catcode`\#=12
4076 \directlua{
4077 local markdown = require("markdown")
4078 local newline = [[^^J^^J]]
4079 local convert, input
4080
4081 convert = markdown.new({fencedCode = true})
4082 input = "A paragraph." .. newline ..
4083 "```" .. newline ..
4084 "A fenced code." .. newline ..
4085 "```" .. newline
4086 tex.sprint(convert(input))
4087
4088 convert = markdown.new({
4089 fencedCode = true, blankBeforeCodeFence = true})
4090 input = "A paragraph." .. newline ..
4091 "```" .. newline ..
4092 "Not a fenced code." .. newline ..
4093 "```" .. newline
4094 tex.sprint(convert(input)) }
4095 \endgroup
4096 \bye
4097 ```````
4098 Then, invoke LuaTeX from the terminal:
4099 ``` sh
4100 luatex document.tex
4101 ```````
4102 A PDF document named `document.pdf` should be produced and contain the
4103 following text:
4104
4105 > A paragraph.
4106 >
4107 > ```
4108 > A fenced code.
4109 > ```
4110 >
4111 > A paragraph. ``` Not a fenced code. ```
4112
4113 ##### Lua CLI Example {.unnumbered}
4114
4115 Using a text editor, create a text document named `document.tex` with the
4116 following content:
4117 ``` tex
4118 \input markdown
4119 \input lmfonts
4120 \begingroup
4121 \catcode`\%=12
4122 \catcode`\#=12
4123 \input optionfalse
4124 \input optiontrue
4125 \endgroup
4126 \bye
4127 ```````
4128 Using a text editor, create a text document named `content.md` with the
4129 following content:
4130 ```` md
4131 A paragraph.
4132 ```
4133 A code fence?
4134 ```
4135 ```````
4136 Next, invoke LuaTeX from the terminal:
4137 ``` sh
4138 markdown2tex fencedCode=true -- content.md optionfalse.tex
4139 markdown2tex fencedCode=true blankBeforeCodeFence=true -- content.md optiontrue.tex
4140 luatex document.tex
4141 ```````
4142
4143 A PDF document named `document.pdf` should be produced and contain the
4144 following text:
4145
4146 > A paragraph.
4147 >
4148 > ```
4149 > A code fence?
4150 > ```
4151 >
4152 > A paragraph. ``` A code fence? ```
4153
4154 ##### Plain \TeX{} Example {.unnumbered}
4155
4156 Using a text editor, create a text document named `document.tex` with the
4157 following content:
4158 ```` tex
4159 \input markdown
4160 \def\markdownOptionFencedCode{true}
4161
4162 \markdownBegin
4163 A paragraph.
4164 ```
4165 A fenced code.
4166 ```
4167 \markdownEnd
4168
4169 \def\markdownOptionBlankBeforeCodeFence{true}
4170 \markdownBegin
4171 A paragraph.
4172 ```
4173 Not a fenced code.
4174 ```
4175 \markdownEnd
4176
4177 \bye
4178 ````````
4179 Next, invoke LuaTeX from the terminal:
4180 ``` sh
4181 luatex document.tex
4182 ``````
4183 A PDF document named `document.pdf` should be produced and contain the
4184 following text:
4185
4186 > A paragraph.
4187 >
4188 > ```
4189 > A fenced code.
4190 > ```
4191 >
4192 > A paragraph. ``` Not a fenced code. ```
4193
4194 ##### \LaTeX{} Example {.unnumbered}
4195
4196 Using a text editor, create a text document named `document.tex` with the
4197 following content:
4198 ```` tex
4199 \documentclass{article}
4200 \usepackage[fencedCode]{markdown}
4201 \begin{document}
4202
4203 \begin{markdown}
4204 A paragraph.
4205 ```
4206 A fenced code.
4207 ```
4208 \end{markdown}
4209
4210 \begin{markdown}[blankBeforeCodeFence]
4211 A paragraph.
4212 ```
4213 Not a fenced code.
4214 ```
4215 \end{markdown}
4216
4217 \end{document}
4218 ````````
4219 Next, invoke LuaTeX from the terminal:
4220 ``` sh
4221 lualatex document.tex
4222 ``````
4223 A PDF document named `document.pdf` should be produced and contain the
4224 following text:
4225
4226 > A paragraph.
4227 >
4228 > ```
4229 > A fenced code.
4230 > ```
4231 >
4232 > A paragraph. ``` Not a fenced code. ```
4233
4234 ##### \Hologo{ConTeXt} Example {.unnumbered}
4235
4236 Using a text editor, create a text document named `document.tex` with the
4237 following content:
4238 ```` tex
4239 \usemodule[t][markdown]
4240 \setupmarkdown[fencedCode = yes]
4241 \starttext
4242
4243 \startmarkdown
4244 A paragraph.
4245 ```
4246 A fenced code.
4247 ```
4248 \stopmarkdown
4249
4250 \setupmarkdown[blankBeforeCodeFence = yes]
4251 \startmarkdown
4252 A paragraph.
4253 ```
4254 Not a fenced code.
4255 ```
4256 \stopmarkdown
4257
4258 \stoptext
4259 ````````
4260 Next, invoke LuaTeX from the terminal:
4261 ``` sh
4262 context --luatex document.tex
4263 ``````
4264 A PDF document named `document.pdf` should be produced and contain the
4265 following text:
4266
4267 > A paragraph.
4268 >
4269 > ```
4270 > A fenced code.
4271 > ```
4272 >
4273 > A paragraph. ``` Not a fenced code. ```
4274
4275 %</manual-options>
4276 %<*tex>
4277 % \fi
4278 % \begin{macrocode}
4279 \@@_add_lua_option:nnn
4280 { blankBeforeCodeFence }
4281 { boolean }
4282 { false }
4283 % \end{macrocode}
4284 % \iffalse
4285 %</tex>
4286 %<*lua,lua-cli,lua-loader>
4287 % \fi
4288 % \begin{macrocode}
4289 defaultOptions.blankBeforeCodeFence = false
4290 % \end{macrocode}
4291 % \iffalse
4292 %</lua,lua-cli,lua-loader>
4293 %<*manual-options>
4294
4295 #### Option `blankBeforeDivFence`
4296
4297 `blankBeforeDivFence` (default value: `false`)
4298
4299 % \fi
4300 % \begin{markdown}
4301 %
4302 % \Optitem[false]{blankBeforeDivFence}{\opt{true}, \opt{false}}
4303 %
4304 : true
4305
4306 : Require a blank line before the closing fence of a fenced div.
4307
4308 : false
4309
4310 : Do not require a blank line before the closing fence of a fenced div.
4311
4312 % \end{markdown}
4313 % \iffalse
4314
4315 ##### \LaTeX{} Example {.unnumbered}
4316
4317 Using a text editor, create a text document named `document.tex` with the
4318 following content:
4319 ```` tex
4320 \documentclass{article}
4321 \usepackage[fencedDivs]{markdown}
4322 \begin{document}
4323
4324 \begin{markdown}
4325 A paragraph.
4326
4327 ::: {.identifier}
4328 A fenced div.
4329 :::
4330 \end{markdown}
4331
4332 \begin{markdown}[blankBeforeDivFence]
4333 A paragraph.
4334
4335 ::: {.identifier}
4336 Not a fenced div.
4337 :::
4338 \end{markdown}
4339
4340 \end{document}
4341 ````````
4342 Next, invoke LuaTeX from the terminal:
4343 ``` sh
4344 lualatex document.tex
4345 ``````
4346 A PDF document named `document.pdf` should be produced and contain the
4347 following text:
4348
4349 > A paragraph.
4350 >
4351 > A fenced div.
4352 >
4353 > A paragraph.
4354 >
4355 > ::: {.identifier} Not a fenced div. :::
4356
4357 %</manual-options>
4358 %<*tex>
4359 % \fi
4360 % \begin{macrocode}
4361 \@@_add_lua_option:nnn
4362 { blankBeforeDivFence }
4363 { boolean }
4364 { false }
4365 % \end{macrocode}
4366 % \iffalse
4367 %</tex>
4368 %<*lua,lua-cli,lua-loader>
4369 % \fi
4370 % \begin{macrocode}
4371 defaultOptions.blankBeforeDivFence = false
4372 % \end{macrocode}
4373 % \iffalse
4374 %</lua,lua-cli,lua-loader>
4375 %<*manual-options>
4376
4377 #### Option `blankBeforeHeading`
4378
4379 `blankBeforeHeading` (default value: `false`)
4380
4381 % \fi
4382 % \begin{markdown}
4383 %
4384 % \Optitem[false]{blankBeforeHeading}{\opt{true}, \opt{false}}
4385 %
4386 : true
4387
4388 : Require a blank line between a paragraph and the following header.
4389
4390 : false
4391
4392 : Do not require a blank line between a paragraph and the following
4393 header.
4394
4395 % \end{markdown}
4396 % \iffalse
4397
4398 ##### Lua Module Example {.unnumbered}
4399
4400 Using a text editor, create a text document named `document.tex` with the
4401 following content:
4402 ``` tex
4403 \input markdown
4404 \input lmfonts
4405 \def\markdownRendererHeadingOne#1{{\bf #1}\par}
4406 \begingroup
4407 \catcode`\%=12
4408 \catcode`\#=12
4409 \directlua{
4410 local markdown = require("markdown")
4411 local newline = [[^^J^^J]]
4412 local convert, input
4413
4414 convert = markdown.new()
4415 input = "A paragraph." .. newline ..
4416 "A heading." .. newline ..
4417 "==========" .. newline
4418 tex.sprint(convert(input))
4419
4420 convert = markdown.new({blankBeforeHeading = true})
4421 input = "A paragraph." .. newline ..
4422 "Not a heading." .. newline ..
4423 "==============" .. newline
4424 tex.sprint(convert(input)) }
4425 \endgroup
4426 \bye
4427 ```````
4428 Then, invoke LuaTeX from the terminal:
4429 ``` sh
4430 luatex document.tex
4431 ```````
4432 A PDF document named `document.pdf` should be produced and contain the
4433 following text:
4434
4435 > A paragraph.
4436 >
4437 > A heading.
4438 > ==========
4439 >
4440 > A paragraph. Not a heading. ==============
4441
4442 ##### Lua CLI Example {.unnumbered}
4443
4444 Using a text editor, create a text document named `document.tex` with the
4445 following content:
4446 ``` tex
4447 \input markdown
4448 \input lmfonts
4449 \begingroup
4450 \catcode`\%=12
4451 \catcode`\#=12
4452 \input optionfalse
4453 \input optiontrue
4454 \endgroup
4455 \bye
4456 ```````
4457 Using a text editor, create a text document named `content.md` with the
4458 following content:
4459 ``` md
4460 A paragraph.
4461 A heading?
4462 ==========
4463 ``````
4464 Next, invoke LuaTeX from the terminal:
4465 ``` sh
4466 markdown2tex -- content.md optionfalse.tex
4467 markdown2tex blankBeforeHeading=true -- content.md optiontrue.tex
4468 luatex document.tex
4469 ```````
4470
4471 A PDF document named `document.pdf` should be produced and contain the
4472 following text:
4473
4474 > A paragraph.
4475 >
4476 > A heading?
4477 > ==========
4478 >
4479 > A paragraph. A heading? ==========
4480
4481 ##### Plain \TeX{} Example {.unnumbered}
4482
4483 Using a text editor, create a text document named `document.tex` with the
4484 following content:
4485 ``` tex
4486 \input markdown
4487
4488 \markdownBegin
4489 A paragraph.
4490 A heading.
4491 ==========
4492 \markdownEnd
4493
4494 \def\markdownOptionBlankBeforeHeading{true}
4495 \markdownBegin
4496 A paragraph.
4497 Not a heading.
4498 ==============
4499 \markdownEnd
4500
4501 \bye
4502 ```````
4503 Next, invoke LuaTeX from the terminal:
4504 ``` sh
4505 luatex document.tex
4506 ``````
4507 A PDF document named `document.pdf` should be produced and contain the
4508 following text:
4509
4510 > A paragraph.
4511 >
4512 > A heading.
4513 > ==========
4514 >
4515 > A paragraph. Not a heading. ==============
4516
4517 ##### \LaTeX{} Example {.unnumbered}
4518
4519 Using a text editor, create a text document named `document.tex` with the
4520 following content:
4521 ``` tex
4522 \documentclass{article}
4523 \usepackage{markdown}
4524 \begin{document}
4525
4526 \begin{markdown}
4527 A paragraph.
4528 A heading.
4529 ==========
4530 \end{markdown}
4531
4532 \begin{markdown}[blankBeforeHeading]
4533 A paragraph.
4534 Not a heading.
4535 ==============
4536 \end{markdown}
4537
4538 \end{document}
4539 ```````
4540 Next, invoke LuaTeX from the terminal:
4541 ``` sh
4542 lualatex document.tex
4543 ``````
4544 A PDF document named `document.pdf` should be produced and contain the
4545 following text:
4546
4547 > A paragraph.
4548 >
4549 > A heading.
4550 > ==========
4551 >
4552 > A paragraph. Not a heading. ==============
4553
4554 ##### \Hologo{ConTeXt} Example {.unnumbered}
4555
4556 Using a text editor, create a text document named `document.tex` with the
4557 following content:
4558 ``` tex
4559 \usemodule[t][markdown]
4560 \starttext
4561
4562 \startmarkdown
4563 A paragraph.
4564 A heading.
4565 ==========
4566 \stopmarkdown
4567
4568 \setupmarkdown[blankBeforeHeading = yes]
4569 \startmarkdown
4570 A paragraph.
4571 Not a heading.
4572 ==============
4573 \stopmarkdown
4574
4575 \stoptext
4576 ````````
4577 Next, invoke LuaTeX from the terminal:
4578 ``` sh
4579 context --luatex document.tex
4580 `````
4581 A PDF document named `document.pdf` should be produced and contain the
4582 following text:
4583
4584 > A paragraph.
4585 >
4586 > A heading.
4587 > ==========
4588 >
4589 > A paragraph. Not a heading. ==============
4590
4591 %</manual-options>
4592 %<*tex>
4593 % \fi
4594 % \begin{macrocode}
4595 \@@_add_lua_option:nnn
4596 { blankBeforeHeading }
4597 { boolean }
4598 { false }
4599 % \end{macrocode}
4600 % \iffalse
4601 %</tex>
4602 %<*lua,lua-cli,lua-loader>
4603 % \fi
4604 % \begin{macrocode}
4605 defaultOptions.blankBeforeHeading = false
4606 % \end{macrocode}
4607 % \iffalse
4608 %</lua,lua-cli,lua-loader>
4609 %<*manual-options>
4610
4611 #### Option `blankBeforeHtmlBlock`
4612
4613 `blankBeforeHtmlBlock` (default value: `false`)
4614
4615 % \fi
4616 % \begin{markdown}
4617 %
4618 % \Optitem[false]{blankBeforeHtmlBlock}{\opt{true}, \opt{false}}
4619 %
4620 : true
4621
4622 : Require a blank line between a paragraph and the following [CommonMark
4623 HTML block][html-block].
4624
4625 : false
4626
4627 : Do not require a blank line between a paragraph and the following
4628 CommonMark HTML block.
4629
4630 [html-block]: https://spec.commonmark.org/0.31.2/#html-blocks
4631
4632 % \end{markdown}
4633 % \iffalse
4634
4635 ##### \LaTeX{} Example {.unnumbered}
4636
4637 Using a text editor, create a text document named `document.tex` with the
4638 following content:
4639 ``` tex
4640 \documentclass{article}
4641 \usepackage[blankBeforeHtmlBlock]{markdown}
4642 \usepackage{marginnote}
4643 \markdownSetup{
4644 renderers = {
4645 inlineHtmlComment = \marginnote{#1},
4646 },
4647 }
4648 \begin{document}
4649 \begin{markdown}
4650 A useful use of block HTML comments are side notes.
4651 <!-- Side notes are displayed in the horizontal margins next to the relevant
4652 passages, which makes them *easier for the reader to find* than notes. -->
4653 \end{markdown}
4654 \end{document}
4655 ```````
4656 Next, invoke LuaTeX from the terminal:
4657 ``` sh
4658 lualatex document.tex
4659 lualatex document.tex
4660 ``````
4661 A PDF document named `document.pdf` should be produced and contain the
4662 following body text:
4663
4664 > A useful use of HTML comments are side notes.
4665
4666 The horizontal margins should contain the following text:
4667
4668 > Side notes are displayed in the horizontal margins next to the relevant
4669 > passages, which makes them *easier for the reader to find* than notes.
4670
4671 %</manual-options>
4672 %<*tex>
4673 % \fi
4674 % \begin{macrocode}
4675 \@@_add_lua_option:nnn
4676 { blankBeforeHtmlBlock }
4677 { boolean }
4678 { false }
4679 % \end{macrocode}
4680 % \iffalse
4681 %</tex>
4682 %<*lua,lua-cli,lua-loader>
4683 % \fi
4684 % \begin{macrocode}
4685 defaultOptions.blankBeforeHtmlBlock = false
4686 % \end{macrocode}
4687 % \iffalse
4688 %</lua,lua-cli,lua-loader>
4689 %<*manual-options>
4690
4691 #### Option `blankBeforeList`
4692
4693 `blankBeforeList` (default value: `false`)
4694
4695 % \fi
4696 % \begin{markdown}
4697 %
4698 % \Optitem[false]{blankBeforeList}{\opt{true}, \opt{false}}
4699 %
4700 : true
4701
4702 : Require a blank line between a paragraph and the following list.
4703
4704 : false
4705
4706 : Do not require a blank line between a paragraph and the following
4707 list.
4708
4709 % \end{markdown}
4710 % \iffalse
4711
4712 ##### Lua Module Example {.unnumbered}
4713
4714 Using a text editor, create a text document named `document.tex` with the
4715 following content:
4716 ``` tex
4717 \input markdown
4718 \input lmfonts
4719 \begingroup
4720 \catcode`\%=12
4721 \catcode`\#=12
4722 \directlua{
4723 local markdown = require("markdown")
4724 local newline = [[^^J^^J]]
4725 local convert, input
4726
4727 convert = markdown.new()
4728 input = "A paragraph." .. newline ..
4729 "- a list" .. newline
4730 tex.sprint(convert(input))
4731
4732 convert = markdown.new({
4733 blankBeforeList = true})
4734 input = "A paragraph." .. newline ..
4735 "- not a list" .. newline
4736 tex.sprint(convert(input)) }
4737 \endgroup
4738 \bye
4739 ```````
4740 Then, invoke LuaTeX from the terminal:
4741 ``` sh
4742 luatex document.tex
4743 ```````
4744 A PDF document named `document.pdf` should be produced and contain the
4745 following text:
4746
4747 > A paragraph.
4748 >
4749 > - a list
4750 >
4751 > A paragraph. - not a list
4752
4753 ##### Lua CLI Example {.unnumbered}
4754
4755 Using a text editor, create a text document named `document.tex` with the
4756 following content:
4757 ``` tex
4758 \input markdown
4759 \input lmfonts
4760 \begingroup
4761 \catcode`\%=12
4762 \catcode`\#=12
4763 \input optionfalse
4764 \input optiontrue
4765 \endgroup
4766 \bye
4767 ```````
4768 Using a text editor, create a text document named `content.md` with the
4769 following content:
4770 ```` md
4771 A paragraph.
4772 - a list?
4773 ```````
4774 Next, invoke LuaTeX from the terminal:
4775 ``` sh
4776 markdown2tex -- content.md optionfalse.tex
4777 markdown2tex blankBeforeList=true -- content.md optiontrue.tex
4778 luatex document.tex
4779 ```````
4780
4781 A PDF document named `document.pdf` should be produced and contain the
4782 following text:
4783
4784 > A paragraph.
4785 >
4786 > - a list?
4787 >
4788 > A paragraph. - a list?
4789
4790 ##### Plain \TeX{} Example {.unnumbered}
4791
4792 Using a text editor, create a text document named `document.tex` with the
4793 following content:
4794 ```` tex
4795 \input markdown
4796
4797 \markdownBegin
4798 A paragraph.
4799 - a list
4800 \markdownEnd
4801
4802 \def\markdownOptionBlankBeforeList{true}
4803 \markdownBegin
4804 A paragraph.
4805 - not a list
4806 \markdownEnd
4807
4808 \bye
4809 ````````
4810 Next, invoke LuaTeX from the terminal:
4811 ``` sh
4812 luatex document.tex
4813 ``````
4814 A PDF document named `document.pdf` should be produced and contain the
4815 following text:
4816
4817 > A paragraph.
4818 >
4819 > - a list
4820 >
4821 > A paragraph. - not a list
4822
4823 ##### \LaTeX{} Example {.unnumbered}
4824
4825 Using a text editor, create a text document named `document.tex` with the
4826 following content:
4827 ```` tex
4828 \documentclass{article}
4829 \usepackage{markdown}
4830 \begin{document}
4831
4832 \begin{markdown}
4833 A paragraph.
4834 - a list
4835 \end{markdown}
4836
4837 \begin{markdown}[blankBeforeList]
4838 A paragraph.
4839 - not a list
4840 \end{markdown}
4841
4842 \end{document}
4843 ````````
4844 Next, invoke LuaTeX from the terminal:
4845 ``` sh
4846 lualatex document.tex
4847 ``````
4848 A PDF document named `document.pdf` should be produced and contain the
4849 following text:
4850
4851 > A paragraph.
4852 >
4853 > - a list
4854 >
4855 > A paragraph. - not a list
4856
4857 ##### \Hologo{ConTeXt} Example {.unnumbered}
4858
4859 Using a text editor, create a text document named `document.tex` with the
4860 following content:
4861 ```` tex
4862 \usemodule[t][markdown]
4863 \starttext
4864
4865 \startmarkdown
4866 A paragraph.
4867 - a list
4868 \stopmarkdown
4869
4870 \setupmarkdown[blankBeforeList = yes]
4871 \startmarkdown
4872 A paragraph.
4873 - not a list
4874 \stopmarkdown
4875
4876 \stoptext
4877 ````````
4878 Next, invoke LuaTeX from the terminal:
4879 ``` sh
4880 context document.tex
4881 ``````
4882 A PDF document named `document.pdf` should be produced and contain the
4883 following text:
4884
4885 > A paragraph.
4886 >
4887 > - a list
4888 >
4889 > A paragraph. - not a list
4890
4891 %</manual-options>
4892 %<*tex>
4893 % \fi
4894 % \begin{macrocode}
4895 \@@_add_lua_option:nnn
4896 { blankBeforeList }
4897 { boolean }
4898 { false }
4899 % \end{macrocode}
4900 % \iffalse
4901 %</tex>
4902 %<*lua,lua-cli,lua-loader>
4903 % \fi
4904 % \begin{macrocode}
4905 defaultOptions.blankBeforeList = false
4906 % \end{macrocode}
4907 % \iffalse
4908 %</lua,lua-cli,lua-loader>
4909 %<*manual-options>
4910
4911 #### Option `bracketedSpans`
4912
4913 `bracketedSpans` (default value: `false`)
4914
4915 % \fi
4916 % \begin{markdown}
4917 %
4918 % \Optitem[false]{bracketedSpans}{\opt{true}, \opt{false}}
4919 %
4920 : true
4921
4922 : Enable the Pandoc [bracketed span syntax extension][pandoc-bracketed-spans]:
4923
4924 ``` md
4925 [This is *some text*]{.class key=val}
4926 ``````
4927
4928 : false
4929
4930 : Disable the Pandoc bracketed span syntax extension.
4931
4932 [pandoc-bracketed-spans]: https://pandoc.org/MANUAL.html#extension-bracketed_spans
4933
4934 % \end{markdown}
4935 % \iffalse
4936
4937 ##### \LaTeX{} Example {.unnumbered}
4938
4939 Using a text editor, create a text document named `document.tex` with the
4940 following content:
4941 ```` tex
4942 \documentclass{article}
4943 \usepackage[bracketedSpans]{markdown}
4944 \usepackage{expl3}
4945 \ExplSyntaxOn
4946 \markdownSetup{
4947 renderers = {
4948 bracketedSpanAttributeContextBegin = {
4949 \group_begin:
4950 \color_group_begin:
4951 \markdownSetup{
4952 renderers = {
4953 attributeKeyValue = {
4954 \str_if_eq:nnT
4955 { ##1 }
4956 { color }
4957 {
4958 \color_select:n { ##2 }
4959 }
4960 },
4961 },
4962 }
4963 },
4964 bracketedSpanAttributeContextEnd = {
4965 \color_group_end:
4966 \group_end:
4967 },
4968 },
4969 }
4970 \ExplSyntaxOff
4971 \begin{document}
4972 \begin{markdown}
4973 Here is some [colored text]{color=red}.
4974 \end{markdown}
4975 \end{document}
4976 ```````
4977 Next, invoke LuaTeX from the terminal:
4978 ``` sh
4979 lualatex document.tex
4980 ``````
4981 A PDF document named `document.pdf` should be produced and contain the
4982 following text:
4983
4984 > Here is some <span style="color: red">colored text</span>.
4985
4986 %</manual-options>
4987 %<*tex>
4988 % \fi
4989 % \begin{macrocode}
4990 \@@_add_lua_option:nnn
4991 { bracketedSpans }
4992 { boolean }
4993 { false }
4994 % \end{macrocode}
4995 % \iffalse
4996 %</tex>
4997 %<*lua,lua-cli,lua-loader>
4998 % \fi
4999 % \begin{macrocode}
5000 defaultOptions.bracketedSpans = false
5001 % \end{macrocode}
5002 % \iffalse
5003 %</lua,lua-cli,lua-loader>
5004 %<*manual-options>
5005
5006 #### Option `breakableBlockquotes`
5007
5008 `breakableBlockquotes` (default value: `true`)
5009
5010 % \fi
5011 % \begin{markdown}
5012 %
5013 % \Optitem[true]{breakableBlockquotes}{\opt{true}, \opt{false}}
5014 %
5015 : true
5016
5017 : A blank line separates block quotes.
5018
5019 : false
5020
5021 : Blank lines in the middle of a block quote are ignored.
5022
5023 % \end{markdown}
5024 % \iffalse
5025
5026 ##### Lua Module Example {.unnumbered}
5027
5028 Using a text editor, create a text document named `document.tex` with the
5029 following content:
5030 ``` tex
5031 \input markdown
5032 \input lmfonts
5033 \def\markdownRendererHeadingOne#1{{\bf #1}\par}
5034 \begingroup
5035 \catcode`\%=12
5036 \catcode`\#=12
5037 \directlua{
5038 local markdown = require("markdown")
5039 local newline = [[^^J^^J]]
5040 local convert, input
5041
5042 convert = markdown.new({breakableBlockquotes = false})
5043 input = "> A single" .. newline .. newline ..
5044 "> block quote." .. newline
5045 tex.sprint(convert(input))
5046
5047 convert = markdown.new()
5048 input = "> A block quote." .. newline .. newline ..
5049 "> Another block quote." .. newline
5050 tex.sprint(convert(input)) }
5051 \endgroup
5052 \bye
5053 ```````
5054 Then, invoke LuaTeX from the terminal:
5055 ``` sh
5056 luatex document.tex
5057 ```````
5058 A PDF document named `document.pdf` should be produced and contain the
5059 following text:
5060
5061 > > A single block quote.
5062 >
5063 > > A block quote.
5064 >
5065 > > Another block quote.
5066
5067 ##### Lua CLI Example {.unnumbered}
5068
5069 Using a text editor, create a text document named `document.tex` with the
5070 following content:
5071 ``` tex
5072 \input markdown
5073 \input lmfonts
5074 \begingroup
5075 \catcode`\%=12
5076 \catcode`\#=12
5077 \input optionfalse
5078 \input optiontrue
5079 \endgroup
5080 \bye
5081 ```````
5082 Using a text editor, create a text document named `content.md` with the
5083 following content:
5084 ``` md
5085 > A single block quote
5086
5087 > or two block quotes?
5088 ``````
5089 Next, invoke LuaTeX from the terminal:
5090 ``` sh
5091 markdown2tex breakableBlockquotes=false -- content.md optionfalse.tex
5092 markdown2tex -- content.md optiontrue.tex
5093 luatex document.tex
5094 ```````
5095
5096 A PDF document named `document.pdf` should be produced and contain the
5097 following text:
5098
5099 > > A single block quote or two block quotes?
5100 >
5101 > > A single block quote
5102 >
5103 > > or two block quotes?
5104
5105 ##### Plain \TeX{} Example {.unnumbered}
5106
5107 Using a text editor, create a text document named `document.tex` with the
5108 following content:
5109 ``` tex
5110 \input markdown
5111
5112 \def\markdownOptionBreakableBlockquotes{false}
5113 \markdownBegin
5114 > A single
5115
5116 > block quote.
5117 \markdownEnd
5118
5119 \def\markdownOptionBreakableBlockquotes{true}
5120 \markdownBegin
5121 > A block quote.
5122
5123 > Another block quote.
5124 \markdownEnd
5125
5126 \bye
5127 ```````
5128 Next, invoke LuaTeX from the terminal:
5129 ``` sh
5130 luatex document.tex
5131 ``````
5132 A PDF document named `document.pdf` should be produced and contain the
5133 following text:
5134
5135 > > A single block quote.
5136 >
5137 > > A block quote.
5138 >
5139 > > Another block quote.
5140
5141 ##### \LaTeX{} Example {.unnumbered}
5142
5143 Using a text editor, create a text document named `document.tex` with the
5144 following content:
5145 ``` tex
5146 \documentclass{article}
5147 \usepackage{markdown}
5148 \begin{document}
5149
5150 \begin{markdown}[breakableBlockquotes = false]
5151 > A single
5152
5153 > block quote.
5154 \end{markdown}
5155
5156 \begin{markdown}
5157 > A block quote.
5158
5159 > Another block quote.
5160 \end{markdown}
5161
5162 \end{document}
5163 ```````
5164 Next, invoke LuaTeX from the terminal:
5165 ``` sh
5166 lualatex document.tex
5167 ``````
5168 A PDF document named `document.pdf` should be produced and contain the
5169 following text:
5170
5171 > > A single block quote.
5172 >
5173 > > A block quote.
5174 >
5175 > > Another block quote.
5176
5177 ##### \Hologo{ConTeXt} Example {.unnumbered}
5178
5179 Using a text editor, create a text document named `document.tex` with the
5180 following content:
5181 ``` tex
5182 \usemodule[t][markdown]
5183 \starttext
5184
5185 \setupmarkdown[breakableBlockquotes = no]
5186 \startmarkdown
5187 > A single
5188
5189 > block quote.
5190 \stopmarkdown
5191
5192 \setupmarkdown[breakableBlockquotes = yes]
5193 \startmarkdown
5194 > A block quote.
5195
5196 > Another block quote.
5197 \stopmarkdown
5198
5199 \stoptext
5200 ````````
5201 Next, invoke LuaTeX from the terminal:
5202 ``` sh
5203 context --luatex document.tex
5204 `````
5205 A PDF document named `document.pdf` should be produced and contain the
5206 following text:
5207
5208 > > A single block quote.
5209 >
5210 > > A block quote.
5211 >
5212 > > Another block quote.
5213
5214 %</manual-options>
5215 %<*tex>
5216 % \fi
5217 % \begin{macrocode}
5218 \@@_add_lua_option:nnn
5219 { breakableBlockquotes }
5220 { boolean }
5221 { true }
5222 % \end{macrocode}
5223 % \iffalse
5224 %</tex>
5225 %<*lua,lua-cli,lua-loader>
5226 % \fi
5227 % \begin{macrocode}
5228 defaultOptions.breakableBlockquotes = true
5229 % \end{macrocode}
5230 % \iffalse
5231 %</lua,lua-cli,lua-loader>
5232 %<*manual-options>
5233
5234 #### Option `citationNbsps`
5235
5236 `citationNbsps` (default value: `true`)
5237
5238 % \fi
5239 % \begin{markdown}
5240 %
5241 % \Optitem[false]{citationNbsps}{\opt{true}, \opt{false}}
5242 %
5243 : true
5244
5245 : Replace regular spaces with non-breaking spaces inside the prenotes
5246 and postnotes of citations produced via the pandoc citation syntax
5247 extension.
5248
5249 : false
5250
5251 : Do not replace regular spaces with non-breaking spaces inside the
5252 prenotes and postnotes of citations produced via the pandoc citation
5253 syntax extension.
5254
5255 % \end{markdown}
5256 % \iffalse
5257
5258 ##### \LaTeX{} Example {.unnumbered}
5259
5260 Using a text editor, create a text document named `document.bib` with the
5261 following content:
5262 ``` bib
5263 @book{knuth:tex,
5264 author = "Knuth, Donald Ervin",
5265 title = "The \TeX book, volume A of Computers and typesetting",
5266 publisher = "Addison-Wesley",
5267 year = "1984"
5268 }
5269 ```````
5270 Using a text editor, create a text document named `document.tex` with the
5271 following content:
5272 ``` tex
5273 \documentclass{article}
5274 \usepackage[citations]{markdown}
5275 \begin{document}
5276
5277 \begin{markdown}
5278 The TeXbook [@knuth:tex, p. 123 and 130] is good.
5279 \end{markdown}
5280
5281 \begin{markdown}[citationNbsps = false]
5282 The TeXbook [@knuth:tex, p. 123 and 130] is good.
5283 \end{markdown}
5284
5285 \bibliographystyle{plain}
5286 \bibliography{document.bib}
5287 \end{document}
5288 ```````
5289 Next, invoke LuaTeX and BibTeX from the terminal:
5290 ``` sh
5291 lualatex document.tex
5292 bibtex document.aux
5293 lualatex document.tex
5294 lualatex document.tex
5295 ``````
5296 A PDF document named `document.pdf` should be produced and contain the
5297 following text, where the middot (`·`) denotes a non-breaking space:
5298
5299 > The TeXbook [1, p.·123·and·130] is good.
5300 >
5301 > The TeXbook [1, p. 123 and 130] is good.
5302 >
5303 > ### References
5304 > [1] Donald·Ervin Knuth. _The TeXbook, volume A of Computers and typesetting._
5305 > Addison-Wesley, 1984.
5306
5307 %</manual-options>
5308 %<*tex>
5309 % \fi
5310 % \begin{macrocode}
5311 \@@_add_lua_option:nnn
5312 { citationNbsps }
5313 { boolean }
5314 { true }
5315 % \end{macrocode}
5316 % \iffalse
5317 %</tex>
5318 %<*lua,lua-cli,lua-loader>
5319 % \fi
5320 % \begin{macrocode}
5321 defaultOptions.citationNbsps = true
5322 % \end{macrocode}
5323 % \iffalse
5324 %</lua,lua-cli,lua-loader>
5325 %<*manual-options>
5326
5327 #### Option `citations`
5328
5329 `citations` (default value: `false`)
5330
5331 % \fi
5332 % \begin{markdown}
5333 %
5334 % \Optitem[false]{citations}{\opt{true}, \opt{false}}
5335 %
5336 : true
5337
5338 : Enable the Pandoc [citation syntax extension][pandoc-citations]:
5339
5340 ``` md
5341 Here is a simple parenthetical citation [@doe99] and here
5342 is a string of several [see @doe99, pp. 33-35; also
5343 @smith04, chap. 1].
5344
5345 A parenthetical citation can have a [prenote @doe99] and
5346 a [@smith04 postnote]. The name of the author can be
5347 suppressed by inserting a dash before the name of an
5348 author as follows [-@smith04].
5349
5350 Here is a simple text citation @doe99 and here is
5351 a string of several @doe99 [pp. 33-35; also @smith04,
5352 chap. 1]. Here is one with the name of the author
5353 suppressed -@doe99.
5354 ``````
5355
5356 : false
5357
5358 : Disable the Pandoc citation syntax extension.
5359
5360 [pandoc-citations]: https://pandoc.org/MANUAL.html#extension-citations
5361
5362 % \end{markdown}
5363 % \iffalse
5364
5365 ##### \LaTeX{} Example {.unnumbered}
5366
5367 Using a text editor, create a text document named `document.bib` with the
5368 following content:
5369 ``` bib
5370 @book{knuth:tex,
5371 author = "Knuth, Donald Ervin",
5372 title = "The \TeX book, volume A of Computers and typesetting",
5373 publisher = "Addison-Wesley",
5374 year = "1984"
5375 }
5376 ```````
5377 Using a text editor, create a text document named `document.tex` with the
5378 following content:
5379 ``` tex
5380 \documentclass{article}
5381 \usepackage[backend=biber]{biblatex}
5382 \addbibresource{document.bib}
5383 \usepackage[citations]{markdown}
5384 \begin{document}
5385
5386 \begin{markdown}
5387 The TeXbook [@knuth:tex, p. 123 and 130] was written by @knuth:tex.
5388 \end{markdown}
5389
5390 \printbibliography
5391 \end{document}
5392 ```````
5393 Next, invoke LuaTeX and Biber from the terminal:
5394 ``` sh
5395 lualatex document.tex
5396 biber document.bcf
5397 lualatex document.tex
5398 lualatex document.tex
5399 ``````
5400 A PDF document named `document.pdf` should be produced and contain the
5401 following text:
5402
5403 > The TeXbook [1, p.·123 and 130] was written by Knuth [1].
5404 >
5405 > ### References
5406 > [1] Donald Ervin Knuth. _The \TeX{}book, volume A of Computers and typesetting._
5407 > Addison-Wesley, 1984.
5408
5409 %</manual-options>
5410 %<*tex>
5411 % \fi
5412 % \begin{macrocode}
5413 \@@_add_lua_option:nnn
5414 { citations }
5415 { boolean }
5416 { false }
5417 % \end{macrocode}
5418 % \iffalse
5419 %</tex>
5420 %<*lua,lua-cli,lua-loader>
5421 % \fi
5422 % \begin{macrocode}
5423 defaultOptions.citations = false
5424 % \end{macrocode}
5425 % \iffalse
5426 %</lua,lua-cli,lua-loader>
5427 %<*manual-options>
5428
5429 #### Option `codeSpans`
5430
5431 `codeSpans` (default value: `true`)
5432
5433 % \fi
5434 % \begin{markdown}
5435 %
5436 % \Optitem[true]{codeSpans}{\opt{true}, \opt{false}}
5437 %
5438 : true
5439
5440 : Enable the code span syntax:
5441
5442 ~~~ md
5443 Use the `printf()` function.
5444 ``There is a literal backtick (`) here.``
5445 ~~~
5446
5447 : false
5448
5449 : Disable the code span syntax. This allows you to easily
5450 use the quotation mark ligatures in texts that do not contain code
5451 spans:
5452
5453 ~~~
5454 ``This is a quote.''
5455 ~~~~~~
5456
5457 % \end{markdown}
5458 % \iffalse
5459
5460 ##### Lua Module Example {.unnumbered}
5461
5462 Using a text editor, create a text document named `document.tex` with the
5463 following content:
5464 ``` tex
5465 \input markdown
5466 \input lmfonts
5467 \begingroup
5468 \catcode`\%=12
5469 \catcode`\#=12
5470 \directlua{
5471 local markdown = require("markdown")
5472 local convert = markdown.new()
5473 local input =
5474 "``This is a code span.'' " ..
5475 "``This is no longer a code span.''"
5476 tex.sprint(convert(input)) }
5477 \par
5478 \directlua{
5479 local markdown = require("markdown")
5480 local convert = markdown.new({codeSpans = false})
5481 local input =
5482 "``This is a quote.'' " ..
5483 "``This is another quote.''"
5484 tex.sprint(convert(input)) }
5485 \endgroup
5486 \bye
5487 ```````
5488 Then, invoke LuaTeX from the terminal:
5489 ``` sh
5490 luatex document.tex
5491 ```````
5492 A PDF document named `document.pdf` should be produced and contain the
5493 following text:
5494
5495 > ``This is a code span.'' ``This is no longer a code span.''
5496 >
5497 > “This is a quote.” “This is another quote.”
5498
5499 ##### Lua CLI Example {.unnumbered}
5500
5501 Using a text editor, create a text document named `document.tex` with the
5502 following content:
5503 ``` tex
5504 \input markdown
5505 \input lmfonts
5506 \begingroup
5507 \catcode`\%=12
5508 \catcode`\#=12
5509 \input optionfalse
5510 \par
5511 \input optiontrue
5512 \endgroup
5513 \bye
5514 ```````
5515 Using a text editor, create a text document named `content.md` with the
5516 following content:
5517 ``` md
5518 ``Is this a code span?'' ``Or a quote?''
5519 ``````
5520 Next, invoke LuaTeX from the terminal:
5521 ``` sh
5522 markdown2tex codeSpans=false -- content.md optionfalse.tex
5523 markdown2tex -- content.md optiontrue.tex
5524 luatex document.tex
5525 ```````
5526
5527 A PDF document named `document.pdf` should be produced and contain the
5528 following text:
5529
5530 > “Is this a code span?” “Or a quote?”
5531 >
5532 > ``Is this a code span?'' ``Or a quote?''
5533
5534 ##### Plain \TeX{} Example {.unnumbered}
5535
5536 Using a text editor, create a text document named `document.tex` with the
5537 following content:
5538 ``` tex
5539 \input markdown
5540
5541 \markdownBegin
5542 ``This is a code span.''
5543 ``This is no longer a code span.''
5544 \markdownEnd
5545
5546 \def\markdownOptionCodeSpans{false}
5547 \markdownBegin
5548 ``This is a quote.''
5549 ``This is another quote.''
5550 \markdownEnd
5551
5552 \bye
5553 ```````
5554 Next, invoke LuaTeX from the terminal:
5555 ``` sh
5556 luatex document.tex
5557 ``````
5558 A PDF document named `document.pdf` should be produced and contain the
5559 following text:
5560
5561 > ``This is a code span.'' ``This is no longer a code span.''
5562 >
5563 > “This is a quote.” “This is another quote.”
5564
5565 ##### \LaTeX{} Example {.unnumbered}
5566
5567 Using a text editor, create a text document named `document.tex` with the
5568 following content:
5569 ``` tex
5570 \documentclass{article}
5571 \usepackage{markdown}
5572 \begin{document}
5573
5574 \begin{markdown}
5575 ``This is a code span.''
5576 ``This is no longer a code span.''
5577 \end{markdown}
5578
5579 \begin{markdown}[codeSpans=false]
5580 ``This is a quote.''
5581 ``This is another quote.''
5582 \end{markdown}
5583
5584 \end{document}
5585 ```````
5586 Next, invoke LuaTeX from the terminal:
5587 ``` sh
5588 lualatex document.tex
5589 ``````
5590 A PDF document named `document.pdf` should be produced and contain the
5591 following text:
5592
5593 > ``This is a code span.'' ``This is no longer a code span.''
5594 >
5595 > “This is a quote.” “This is another quote.”
5596
5597 ##### \Hologo{ConTeXt} Example {.unnumbered}
5598
5599 Using a text editor, create a text document named `document.tex` with the
5600 following content:
5601 ``` tex
5602 \usemodule[t][markdown]
5603 \starttext
5604
5605 \startmarkdown
5606 ``This is a code span.''
5607 ``This is no longer a code span.''
5608 \stopmarkdown
5609
5610 \setupmarkdown[codeSpans = no]
5611 \startmarkdown
5612 ``This is a quote.''
5613 ``This is another quote.''
5614 \stopmarkdown
5615
5616 \stoptext
5617 ````````
5618 Next, invoke LuaTeX from the terminal:
5619 ``` sh
5620 context --luatex document.tex
5621 `````
5622 A PDF document named `document.pdf` should be produced and contain the
5623 following text:
5624
5625 > ``This is a code span.'' ``This is no longer a code span.''
5626 >
5627 > “This is a quote.” “This is another quote.”
5628
5629 %</manual-options>
5630 %<*tex>
5631 % \fi
5632 % \begin{macrocode}
5633 \@@_add_lua_option:nnn
5634 { codeSpans }
5635 { boolean }
5636 { true }
5637 % \end{macrocode}
5638 % \iffalse
5639 %</tex>
5640 %<*lua,lua-cli,lua-loader>
5641 % \fi
5642 % \begin{macrocode}
5643 defaultOptions.codeSpans = true
5644 % \end{macrocode}
5645 % \iffalse
5646 %</lua,lua-cli,lua-loader>
5647 %<*manual-options>
5648
5649 #### Option `contentBlocks`
5650
5651 `contentBlocks` (default value: `false`)
5652
5653 % \fi
5654 % \begin{markdown}
5655 %
5656 % \Optitem[false]{contentBlocks}{\opt{true}, \opt{false}}
5657 %
5658 : true
5659
5660 : Enable the
5661 % iA\\,Writer content blocks syntax extension~[@sotkov17]:
5662 % \iffalse
5663 iA\\,Writer content blocks syntax extension:
5664 % \fi
5665
5666 ``` md
5667 http://example.com/minard.jpg (Napoleon's disastrous
5668 Russian campaign of 1812)
5669 /Flowchart.png "Engineering Flowchart"
5670 /Savings Account.csv 'Recent Transactions'
5671 /Example.swift
5672 /Lorem Ipsum.txt
5673 ``````
5674
5675 : false
5676
5677 : Disable the
5678 iA\\,Writer content blocks syntax extension.
5679
5680 % \end{markdown}
5681 % \iffalse
5682
5683 ##### \LaTeX{} Example {.unnumbered}
5684
5685 Using a text editor, create a text document named `table.csv` with the
5686 following content:
5687 ``` csv
5688 Name,Surname,Born
5689 Albert,Einstein,1879
5690 Marie,Curie,1867
5691 Thomas,Edison,1847
5692 ```````
5693 Create also a text document named `markdown-languages.json` with the following
5694 content:
5695 ``` js
5696 {
5697 "tex": "LaTeX"
5698 }
5699 ``````
5700 Create also a text document named `code.tex` with the following content:
5701 ``` tex
5702 This is an example code listing in \LaTeX.
5703 ```````
5704 Create also a text document named `part.md` with the following content:
5705 ``` md
5706 This is a *transcluded markdown document*.
5707 ``````
5708 Create also a text document named `document.tex` with the following content:
5709 ``` tex
5710 \documentclass{article}
5711 \usepackage{minted}
5712 \usepackage[contentBlocks]{markdown}
5713 \begin{document}
5714 \begin{markdown}
5715 /table.csv (An example table)
5716 /code.tex (An example code listing)
5717 /part.md (A file transclusion example)
5718 \end{markdown}
5719 \end{document}
5720 ```````
5721 Next, invoke LuaTeX from the terminal:
5722 ``` sh
5723 lualatex --shell-escape document.tex
5724 ``````
5725 A PDF document named `document.pdf` should be produced and contain the
5726 following text:
5727
5728 > | Name | Surname | Born |
5729 > | ------ | ---------| ---- |
5730 > | Albert | Einstein | 1879 |
5731 > | Marie | Curie | 1867 |
5732 > | Thomas | Edison | 1847 |
5733 >
5734 > Table 1: An example table
5735 >
5736 > ``` tex
5737 > This is an example code listing in \LaTeX.
5738 > ```````
5739 >
5740 > This is a *transcluded markdown document*.
5741
5742 ##### \Hologo{ConTeXt} Example {.unnumbered}
5743
5744 Using a text editor, create a text document named `table.csv` with the
5745 following content:
5746 ``` csv
5747 Name,Surname,Born
5748 Albert,Einstein,1879
5749 Marie,Curie,1867
5750 Thomas,Edison,1847
5751 ```````
5752 Create also a text document named `markdown-languages.json` with the following
5753 content:
5754 ``` js
5755 {
5756 "tex": "ConTeXt"
5757 }
5758 ``````
5759 Create also a text document named `code.tex` with the following content:
5760 ``` tex
5761 This is an example code listing in \ConTeXt.
5762 ```````
5763 Create also a text document named `part.md` with the following content:
5764 ``` md
5765 This is a *transcluded markdown document*.
5766 ``````
5767 Create also a text document named `document.tex` with the following content:
5768 ``` tex
5769 \usemodule[t][markdown]
5770 \setupmarkdown[contentBlocks = yes]
5771 \definetyping [ConTeXt]
5772 \setuptyping [ConTeXt] [option=TEX]
5773 \starttext
5774 \startmarkdown
5775 /table.csv (An example table)
5776 /code.tex (An example code listing)
5777 /part.md (A file transclusion example)
5778 \stopmarkdown
5779 \stoptext
5780 ````````
5781 Next, invoke LuaTeX from the terminal:
5782 ``` sh
5783 context --luatex document.tex
5784 `````
5785 A PDF document named `document.pdf` should be produced and contain the
5786 following text:
5787
5788 > | Name | Surname | Born |
5789 > | ------ | ---------| ---- |
5790 > | Albert | Einstein | 1879 |
5791 > | Marie | Curie | 1867 |
5792 > | Thomas | Edison | 1847 |
5793 >
5794 > Table 1: An example table
5795 >
5796 > ``` tex
5797 > This is an example code listing in \ConTeXt.
5798 > ```````
5799 >
5800 > This is a *transcluded markdown document*.
5801
5802 %</manual-options>
5803 %<*tex>
5804 % \fi
5805 % \begin{macrocode}
5806 \@@_add_lua_option:nnn
5807 { contentBlocks }
5808 { boolean }
5809 { false }
5810 % \end{macrocode}
5811 % \iffalse
5812 %</tex>
5813 %<*lua,lua-cli,lua-loader>
5814 % \fi
5815 % \begin{macrocode}
5816 defaultOptions.contentBlocks = false
5817 % \end{macrocode}
5818 % \iffalse
5819 %</lua,lua-cli,lua-loader>
5820 %<*manual-options>
5821
5822 #### Option `contentLevel`
5823
5824 `contentLevel` (default value: `block`)
5825
5826 % \fi
5827 % \begin{markdown}
5828 %
5829 % \Optitem[block]{contentLevel}{\opt{block}, \opt{inline}}
5830 %
5831 : block
5832
5833 : Treat content as a sequence of blocks.
5834 ``` md
5835 - this is a list
5836 - it contains two items
5837 ``````
5838
5839 : inline
5840
5841 : Treat all content as inline content.
5842 ``` md
5843 - this is a text
5844 - not a list
5845 ``````
5846
5847 % \end{markdown}
5848 % \iffalse
5849
5850 ##### Plain \TeX{} Example {.unnumbered}
5851
5852 Using a text editor, create a text document named `document.tex` with the
5853 following content:
5854 ``` tex
5855 \input markdown
5856 \def\markdownOptionContentLevel{inline}
5857 \markdownBegin
5858 - this is
5859 - a text
5860 \markdownEnd
5861 \bye
5862 ```````
5863 Next, invoke LuaTeX from the terminal:
5864 ``` sh
5865 luatex document.tex
5866 ``````
5867 A PDF document named `document.pdf` should be produced and contain the
5868 following text:
5869
5870 > \- this is - a text
5871
5872 ##### \LaTeX{} Example {.unnumbered}
5873
5874 Using a text editor, create a text document named `document.tex` with the
5875 following content:
5876 ``` tex
5877 \documentclass{article}
5878 \usepackage{markdown}
5879 \begin{document}
5880
5881 \begin{markdown}
5882 - this is
5883 - a list
5884 \end{markdown}
5885
5886 \begin{markdown}[contentLevel=inline]
5887 - this is
5888 - a text
5889 \end{markdown}
5890
5891 \end{document}
5892 ```````
5893 Next, invoke LuaTeX from the terminal:
5894 ``` sh
5895 lualatex document.tex
5896 ``````
5897 A PDF document named `document.pdf` should be produced and contain the
5898 following text:
5899
5900 > - this is
5901 > - a list
5902 >
5903 > \- this is - a text
5904
5905 ##### \Hologo{ConTeXt} Example {.unnumbered}
5906
5907 Using a text editor, create a text document named `document.tex` with the
5908 following content:
5909 ``` tex
5910 \usemodule[t][markdown]
5911 \starttext
5912
5913 \startmarkdown
5914 - this is
5915 - a list
5916 \stopmarkdown
5917
5918 \setupmarkdown[contentLevel = inline]
5919 \startmarkdown
5920 - this is
5921 - a text
5922 \stopmarkdown
5923
5924 \stoptext
5925 ````````
5926 Next, invoke LuaTeX from the terminal:
5927 ``` sh
5928 context --luatex document.tex
5929 `````
5930 A PDF document named `document.pdf` should be produced and contain the
5931 following text:
5932
5933 > - this is
5934 > - a list
5935 >
5936 > \- this is - a text
5937
5938 %</manual-options>
5939 %<*tex>
5940 % \fi
5941 % \begin{macrocode}
5942 \@@_add_lua_option:nnn
5943 { contentLevel }
5944 { string }
5945 { block }
5946 % \end{macrocode}
5947 % \iffalse
5948 %</tex>
5949 %<*lua,lua-cli,lua-loader>
5950 % \fi
5951 % \begin{macrocode}
5952 defaultOptions.contentLevel = "block"
5953 % \end{macrocode}
5954 % \iffalse
5955 %</lua,lua-cli,lua-loader>
5956 %<*manual-options>
5957
5958 #### Option `debugExtensions`
5959
5960 `debugExtensions` (default value: `false`)
5961
5962 % \fi
5963 % \begin{markdown}
5964 %
5965 % \Optitem[false]{debugExtensions}{\opt{true}, \opt{false}}
5966 %
5967 : true
5968
5969 : Produce a JSON file that will contain the
5970 extensible subset of the PEG grammar of markdown
5971 % (see the \luamref{walkable_syntax} hash table)
5972 after built-in syntax extensions
5973 % (see Section <#sec:lua-built-in-extensions>)
5974 % \iffalse
5975 (see options \Opt{citations}, \Opt{contentBlocks},
5976 \Opt{definitionLists}, etc.)
5977 % \fi
5978 and user-defined syntax extensions
5979 % (see Section <#sec:lua-user-extensions>)
5980 % \iffalse
5981 (see option \Opt{extensions})
5982 % \fi
5983 have been applied. This helps you to see how the different
5984 extensions interact. The name of the produced JSON file is
5985 controlled by the \Opt{debugExtensionsFileName} option.
5986
5987 : false
5988
5989 : Do not produce a JSON file with the PEG grammar of
5990 markdown.
5991
5992 % \end{markdown}
5993 % \iffalse
5994
5995 ##### \LaTeX{} Example {.unnumbered}
5996
5997 Using a text editor, create a text document named `strike-through.lua` with the
5998 following content:
5999 ``` lua
6000 local strike_through = {
6001 api_version = 2,
6002 grammar_version = 4,
6003 finalize_grammar = function(reader)
6004 local nonspacechar = lpeg.P(1) - lpeg.S("\t ")
6005 local doubleslashes = lpeg.P("//")
6006 local function between(p, starter, ender)
6007 ender = lpeg.B(nonspacechar) * ender
6008 return (starter * #nonspacechar
6009 * lpeg.Ct(p * (p - ender)^0) * ender)
6010 end
6011
6012 local read_strike_through = between(
6013 lpeg.V("Inline"), doubleslashes, doubleslashes
6014 ) / function(s) return {"\\st{", s, "}"} end
6015
6016 reader.insert_pattern("Inline after LinkAndEmph",
6017 read_strike_through,
6018 "StrikeThrough")
6019 reader.add_special_character("/")
6020 end
6021 }
6022
6023 return strike_through
6024 ```````
6025 Using a text editor, create also a text document named `document.tex` with the
6026 following content:
6027 ``` tex
6028 \documentclass{article}
6029 \usepackage{soul}
6030 \usepackage[extension = strike-through.lua,
6031 debugExtensions]{markdown}
6032 \begin{document}
6033 \begin{markdown}
6034 This is //a lunar roving vehicle// strike-through text.
6035 \end{markdown}
6036 \end{document}
6037 ```````
6038 Next, invoke LuaTeX from the terminal:
6039 ``` sh
6040 lualatex document.tex
6041 ``````
6042 A PDF document named `document.pdf` should be produced and contain the
6043 following text:
6044
6045 > This is ~~a lunar roving vehicle~~ strike-through text.
6046
6047 Furthermore, a JSON document named `document.debug-extensions.json` should also
6048 be produced and contain the following text:
6049
6050 ``` json
6051 {
6052 "Block": [
6053 "Blockquote",
6054 "Verbatim",
6055 "FencedCode (built-in fenced_code syntax extension)",
6056 "ThematicBreak",
6057 "BulletList",
6058 "OrderedList",
6059 "DisplayHtml",
6060 "Heading"
6061 ],
6062 "BlockOrParagraph": [
6063 "Block",
6064 "Paragraph",
6065 "Plain"
6066 ],
6067 "EndlineExceptions": [
6068 "EndlineExceptions (built-in fenced_code syntax extension)"
6069 ],
6070 "Inline": [
6071 "Str",
6072 "Space",
6073 "Endline",
6074 "EndlineBreak",
6075 "LinkAndEmph",
6076 "StrikeThrough (user-defined \"./strike-through.lua\" syntax extension)",
6077 "Code",
6078 "AutoLinkUrl",
6079 "AutoLinkEmail",
6080 "AutoLinkRelativeReference",
6081 "InlineHtml",
6082 "HtmlEntity",
6083 "EscapedChar",
6084 "Smart",
6085 "Symbol"
6086 ]
6087 }
6088 ````````
6089
6090 This output shows us that our user-defined syntax extension has been correctly
6091 inserted to the grammar of markdown.
6092
6093 %</manual-options>
6094 %<*tex>
6095 % \fi
6096 % \begin{macrocode}
6097 \@@_add_lua_option:nnn
6098 { debugExtensions }
6099 { boolean }
6100 { false }
6101 % \end{macrocode}
6102 % \iffalse
6103 %</tex>
6104 %<*lua,lua-cli,lua-loader>
6105 % \fi
6106 % \begin{macrocode}
6107 defaultOptions.debugExtensions = false
6108 % \end{macrocode}
6109 % \iffalse
6110 %</lua,lua-cli,lua-loader>
6111 %<*manual-options>
6112
6113 #### Option `definitionLists`
6114
6115 `definitionLists` (default value: `false`)
6116
6117 % \fi
6118 % \begin{markdown}
6119 %
6120 % \Optitem[false]{definitionLists}{\opt{true}, \opt{false}}
6121 %
6122 : true
6123
6124 : Enable the pandoc definition list syntax extension:
6125
6126 ``` md
6127 Term 1
6128
6129 : Definition 1
6130
6131 Term 2 with *inline markup*
6132
6133 : Definition 2
6134
6135 { some code, part of Definition 2 }
6136
6137 Third paragraph of definition 2.
6138 `````
6139
6140 : false
6141
6142 : Disable the pandoc definition list syntax extension.
6143
6144 % \end{markdown}
6145 % \iffalse
6146
6147 ##### \LaTeX{} Example {.unnumbered}
6148
6149 Using a text editor, create a text document named `document.tex` with the
6150 following content:
6151 ``` tex
6152 \documentclass{article}
6153 \usepackage[definitionLists]{markdown}
6154 \begin{document}
6155 \begin{markdown}
6156 Term 1
6157
6158 : Definition 1
6159
6160 Term 2 with *inline markup*
6161
6162 : Definition 2
6163
6164 { some code, part of Definition 2 }
6165
6166 Third paragraph of definition 2.
6167 \end{markdown}
6168 \end{document}
6169 ```````
6170 Next, invoke LuaTeX from the terminal:
6171 ``` sh
6172 lualatex document.tex
6173 ``````
6174 A PDF document named `document.pdf` should be produced and contain the
6175 following text:
6176
6177 > Term 1
6178 >
6179 > : Definition 1
6180 >
6181 > Term 2 with *inline markup*
6182 >
6183 > : Definition 2
6184 >
6185 > { some code, part of Definition 2 }
6186 >
6187 > Third paragraph of definition 2.
6188
6189 ##### \Hologo{ConTeXt} Example {.unnumbered}
6190
6191 Using a text editor, create a text document named `document.tex` with the
6192 following content:
6193 ``` tex
6194 \usemodule[t][markdown]
6195 \setupmarkdown[definitionLists = yes]
6196 \starttext
6197 \startmarkdown
6198 Term 1
6199
6200 : Definition 1
6201
6202 Term 2 with *inline markup*
6203
6204 : Definition 2
6205
6206 { some code, part of Definition 2 }
6207
6208 Third paragraph of definition 2.
6209 \stopmarkdown
6210 \stoptext
6211 ````````
6212 Next, invoke LuaTeX from the terminal:
6213 ``` sh
6214 context --luatex document.tex
6215 `````
6216 A PDF document named `document.pdf` should be produced and contain the
6217 following text:
6218
6219 > Term 1
6220 >
6221 > : Definition 1
6222 >
6223 > Term 2 with *inline markup*
6224 >
6225 > : Definition 2
6226 >
6227 > { some code, part of Definition 2 }
6228 >
6229 > Third paragraph of definition 2.
6230
6231 %</manual-options>
6232 %<*tex>
6233 % \fi
6234 % \begin{macrocode}
6235 \@@_add_lua_option:nnn
6236 { definitionLists }
6237 { boolean }
6238 { false }
6239 % \end{macrocode}
6240 % \iffalse
6241 %</tex>
6242 %<*lua,lua-cli,lua-loader>
6243 % \fi
6244 % \begin{macrocode}
6245 defaultOptions.definitionLists = false
6246 % \end{macrocode}
6247 % \iffalse
6248 %</lua,lua-cli,lua-loader>
6249 %<*manual-options>
6250
6251 #### Option `ensureJekyllData`
6252
6253 `ensureJekyllData` (default value: `false`)
6254
6255 % \fi
6256 % \begin{markdown}
6257 %
6258 % \Optitem[false]{ensureJekyllData}{\opt{true}, \opt{false}}
6259 %
6260 : true
6261
6262 : When the \Opt{jekyllData} and \Opt{expectJekyllData} options are
6263 enabled, then a markdown document must begin directly with YAML
6264 metadata and must contain nothing but YAML metadata. Otherwise,
6265 an error is produced.
6266
6267 : false
6268
6269 : When the \Opt{jekyllData} and \Opt{expectJekyllData} options are
6270 enabled, then a markdown document may begin directly with YAML
6271 metadata and may contain nothing but YAML metadata. Otherwise,
6272 the markdown document is processed as markdown text.
6273
6274 % See also the plain \TeX{} macros \mref{yamlBegin}, \mref{yamlEnd}, and
6275 % \mref{yamlInput} in Section <#sec:tex-typesetting>, the \LaTeX{} environment
6276 % \envmref{yaml} in Section <#sec:latex-typesetting>, and the \Hologo{ConTeXt}
6277 % macros \mref{startyaml}, \mref{stopyaml}, and \mref{inputyaml} in Section
6278 % <#sec:context-typesetting> to see how the options \Opt{jekyllData},
6279 % \Opt{expectJekyllData}, and \Opt{ensureJekyllData} can be used together to
6280 % implement high-level interfaces for processing YAML documents.
6281 %
6282 % \end{markdown}
6283 % \iffalse
6284 %</manual-options>
6285 %<*tex>
6286 % \fi
6287 % \begin{macrocode}
6288 \@@_add_lua_option:nnn
6289 { ensureJekyllData }
6290 { boolean }
6291 { false }
6292 % \end{macrocode}
6293 % \iffalse
6294 %</tex>
6295 %<*lua,lua-cli,lua-loader>
6296 % \fi
6297 % \begin{macrocode}
6298 defaultOptions.ensureJekyllData = false
6299 % \end{macrocode}
6300 % \iffalse
6301 %</lua,lua-cli,lua-loader>
6302 %<*manual-options>
6303
6304 #### Option `expectJekyllData`
6305
6306 `expectJekyllData` (default value: `false`)
6307
6308 % \fi
6309 % \markdownBegin
6310 %
6311 % \Optitem[false]{expectJekyllData}{\opt{true}, \opt{false}}
6312 %
6313 : true
6314
6315 : When the \Opt{jekyllData} option is enabled, then a markdown document may
6316 begin directly with YAML metadata and may contain nothing but
6317 YAML metadata.
6318
6319 ~~~~~ latex
6320 \documentclass{article}
6321 \usepackage[jekyllData, expectJekyllData]{markdown}
6322 \begin{document}
6323 \begin{markdown}
6324 - this
6325 - is
6326 - YAML
6327 ...
6328 - followed
6329 - by
6330 - Markdown
6331 \end{markdown}
6332 \begin{markdown}
6333 - this
6334 - is
6335 - YAML
6336 \end{markdown}
6337 \end{document}
6338 ~~~~~~~~~~~
6339
6340 : false
6341
6342 : When the \Opt{jekyllData} option is enabled, then a markdown document
6343 may begin with YAML metadata if and only if the metadata begin
6344 with the end-of-directives marker (`---`) and they end with either the
6345 end-of-directives or the end-of-document marker (`...`):
6346
6347 ~~~~~ latex
6348 \documentclass{article}
6349 \usepackage[jekyllData]{markdown}
6350 \begin{document}
6351 \begin{markdown}
6352 ---
6353 - this
6354 - is
6355 - YAML
6356 ...
6357 - followed
6358 - by
6359 - Markdown
6360 \end{markdown}
6361 \begin{markdown}
6362 - this
6363 - is
6364 - Markdown
6365 \end{markdown}
6366 \end{document}
6367 ~~~~~~~~~~~
6368
6369 % See also the plain \TeX{} macros \mref{yamlBegin}, \mref{yamlEnd}, and
6370 % \mref{yamlInput} in Section <#sec:tex-typesetting>, the \LaTeX{} environment
6371 % \envmref{yaml} in Section <#sec:latex-typesetting>, and the \Hologo{ConTeXt}
6372 % macros \mref{startyaml}, \mref{stopyaml}, and \mref{inputyaml} in Section
6373 % <#sec:context-typesetting> to see how the options \Opt{jekyllData},
6374 % \Opt{expectJekyllData}, and \Opt{ensureJekyllData} can be used together to
6375 % implement high-level interfaces for processing YAML documents.
6376 %
6377 % \markdownEnd
6378 % \iffalse
6379
6380 ##### \LaTeX{} Example {.unnumbered}
6381
6382 Using a text editor, create a text document named `jane-doe.yml` with the
6383 following content:
6384 ``` yaml
6385 name: Jane Doe
6386 age: 99
6387 ```
6388 Using a text editor, create also a text document named `document.tex` with the
6389 following content:
6390 ``` tex
6391 \documentclass{article}
6392 \usepackage[jekyllData]{markdown}
6393 \markdownSetup{
6394 jekyllDataRenderers = {
6395 name = {\gdef\name{#1}},
6396 code = {\gdef\age{#1}},
6397 },
6398 renderers = {
6399 jekyllDataEnd = {\name{} is \age{} years old.},
6400 }
6401 }
6402 \begin{document}
6403 \markdownInput[expectJekyllData]{jane-doe.yml}
6404 \end{document}
6405 ```````
6406 Next, invoke LuaTeX from the terminal:
6407 ``` sh
6408 lualatex document.tex
6409 ``````
6410 A PDF document named `document.pdf` should be produced and contain the
6411 following text:
6412
6413 > Jane Doe is 99 years old.
6414
6415 %</manual-options>
6416 %<*tex>
6417 % \fi
6418 % \begin{macrocode}
6419 \@@_add_lua_option:nnn
6420 { expectJekyllData }
6421 { boolean }
6422 { false }
6423 % \end{macrocode}
6424 % \iffalse
6425 %</tex>
6426 %<*lua,lua-cli,lua-loader>
6427 % \fi
6428 % \begin{macrocode}
6429 defaultOptions.expectJekyllData = false
6430 % \end{macrocode}
6431 % \iffalse
6432 %</lua,lua-cli,lua-loader>
6433 %<*manual-options>
6434
6435 #### Option `extensions`
6436
6437 `extensions` (default value: `{}`)
6438
6439 % \fi
6440 % \begin{markdown}
6441 %
6442 % \Valitem[\{\}]{extensions}{filenames}
6443 %
6444 : The filenames of user-defined syntax extensions that will be applied to the
6445 markdown reader. If the \pkg{kpathsea} library is available, files will be
6446 searched for not only in the current working directory but also in the
6447 \TeX{} directory structure.
6448
6449 % A user-defined syntax extension is a Lua file in the following format:
6450 %
6451 % ``` lua
6452 % local strike_through = {
6453 % api_version = 2,
6454 % grammar_version = 4,
6455 % finalize_grammar = function(reader)
6456 % local nonspacechar = lpeg.P(1) - lpeg.S("\t ")
6457 % local doubleslashes = lpeg.P("//")
6458 % local function between(p, starter, ender)
6459 % ender = lpeg.B(nonspacechar) * ender
6460 % return (starter * #nonspacechar
6461 % * lpeg.Ct(p * (p - ender)^0) * ender)
6462 % end
6463 %
6464 % local read_strike_through = between(
6465 % lpeg.V("Inline"), doubleslashes, doubleslashes
6466 % ) / function(s) return {"\\st{", s, "}"} end
6467 %
6468 % reader.insert_pattern("Inline after LinkAndEmph",
6469 % read_strike_through,
6470 % "StrikeThrough")
6471 % reader.add_special_character("/")
6472 % end
6473 % }
6474 %
6475 % return strike_through
6476 % ```````
6477 %
6478 % The `api_version` and `grammar_version` fields specify the version of the
6479 % user-defined syntax extension API and the markdown grammar for which
6480 % the extension was written. See the current API and grammar versions
6481 % below:
6482 %
6483 % \end{markdown}
6484 % \iffalse
6485 %</manual-options>
6486 %<*lua>
6487 % \fi
6488 % \begin{macrocode}
6489 metadata.user_extension_api_version = 2
6490 metadata.grammar_version = 4
6491 % \end{macrocode}
6492 % \iffalse
6493 %</lua>
6494 %<*manual-options>
6495 % \fi
6496 % \begin{markdown}
6497 %
6498 % Any changes to the syntax extension API or grammar will cause the
6499 % corresponding current version to be incremented. After Markdown 3.0.0,
6500 % any changes to the API and the grammar will be either backwards-compatible
6501 % or constitute a breaking change that will cause the major version of the
6502 % Markdown package to increment (to 4.0.0).
6503 %
6504 % The `finalize_grammar` field is a function that finalizes the grammar of
6505 % markdown using the interface of a Lua \luamref{reader} object, such as
6506 % the \luamref{reader->insert_pattern} and
6507 % \luamref{reader->add_special_character} methods,
6508 % see Section <#sec:lua-user-extensions>.
6509 %
6510 % \end{markdown}
6511 % \iffalse
6512
6513 ##### \LaTeX{} Example {.unnumbered}
6514
6515 Using a text editor, create a text document named `strike-through.lua` with the
6516 following content:
6517 ``` lua
6518 local strike_through = {
6519 api_version = 2,
6520 grammar_version = 4,
6521 finalize_grammar = function(reader)
6522 local nonspacechar = lpeg.P(1) - lpeg.S("\t ")
6523 local doubleslashes = lpeg.P("//")
6524 local function between(p, starter, ender)
6525 ender = lpeg.B(nonspacechar) * ender
6526 return (starter * #nonspacechar
6527 * lpeg.Ct(p * (p - ender)^0) * ender)
6528 end
6529
6530 local read_strike_through = between(
6531 lpeg.V("Inline"), doubleslashes, doubleslashes
6532 ) / function(s) return {"\\st{", s, "}"} end
6533
6534 reader.insert_pattern("Inline after LinkAndEmph",
6535 read_strike_through,
6536 "StrikeThrough")
6537 reader.add_special_character("/")
6538 end
6539 }
6540
6541 return strike_through
6542 ```````
6543 Using a text editor, create also a text document named `document.tex` with the
6544 following content:
6545 ``` tex
6546 \documentclass{article}
6547 \usepackage{soul}
6548 \usepackage[extension = strike-through.lua]{markdown}
6549 \begin{document}
6550 \begin{markdown}
6551 This is //a lunar roving vehicle// strike-through text.
6552 \end{markdown}
6553 \end{document}
6554 ```````
6555 Next, invoke LuaTeX from the terminal:
6556 ``` sh
6557 lualatex document.tex
6558 ``````
6559 A PDF document named `document.pdf` should be produced and contain the
6560 following text:
6561
6562 > This is ~~a lunar roving vehicle~~ strike-through text.
6563
6564 %</manual-options>
6565 %<*tex>
6566 % \fi
6567 % \begin{macrocode}
6568 \@@_add_lua_option:nnV
6569 { extensions }
6570 { clist }
6571 \c_empty_clist
6572 % \end{macrocode}
6573 % \iffalse
6574 %</tex>
6575 %<*lua,lua-cli,lua-loader>
6576 % \fi
6577 % \begin{macrocode}
6578 defaultOptions.extensions = {}
6579 % \end{macrocode}
6580 % \iffalse
6581 %</lua,lua-cli,lua-loader>
6582 %<*manual-options>
6583
6584 #### Option `fancyLists`
6585
6586 `fancyLists` (default value: `false`)
6587
6588 % \fi
6589 % \begin{markdown}
6590 %
6591 % \Optitem[false]{fancyLists}{\opt{true}, \opt{false}}
6592 %
6593 : true
6594
6595 : Enable the Pandoc [fancy list syntax extension][pandoc-fancy-lists]:
6596
6597 ``` md
6598 a) first item
6599 b) second item
6600 c) third item
6601 ``````
6602
6603 : false
6604
6605 : Disable the Pandoc fancy list syntax extension.
6606
6607 [pandoc-fancy-lists]: https://pandoc.org/MANUAL.html#org-fancy-lists
6608
6609 % \end{markdown}
6610 % \iffalse
6611
6612 ##### \LaTeX{} Example {.unnumbered}
6613
6614 Using a text editor, create a text document named `document.tex` with the
6615 following content:
6616 ```` tex
6617 \documentclass{article}
6618 \usepackage{minted}
6619 \usepackage[fancyLists]{markdown}
6620 \begin{document}
6621 \begin{markdown}
6622 a) first item
6623 b) second item
6624 c) third item
6625 \end{markdown}
6626 \end{document}
6627 ```````
6628 Next, invoke LuaTeX from the terminal:
6629 ``` sh
6630 lualatex --shell-escape document.tex
6631 ``````
6632 A PDF document named `document.pdf` should be produced and contain the
6633 following text:
6634
6635 > a) first item
6636 > b) second item
6637 > c) third item
6638
6639 ##### \Hologo{ConTeXt} Example {.unnumbered}
6640
6641 Using a text editor, create a text document named `document.tex` with the
6642 following content:
6643 ```` tex
6644 \usemodule[t][markdown]
6645 \setupmarkdown[fancyLists = yes]
6646 \starttext
6647 \startmarkdown
6648 a) first item
6649 b) second item
6650 c) third item
6651 \stopmarkdown
6652 \stoptext
6653 ````````
6654 Next, invoke LuaTeX from the terminal:
6655 ``` sh
6656 context --luatex document.tex
6657 `````
6658 A PDF document named `document.pdf` should be produced and contain the
6659 following text:
6660
6661 > a) first item
6662 > b) second item
6663 > c) third item
6664
6665 %</manual-options>
6666 %<*tex>
6667 % \fi
6668 % \begin{macrocode}
6669 \@@_add_lua_option:nnn
6670 { fancyLists }
6671 { boolean }
6672 { false }
6673 % \end{macrocode}
6674 % \iffalse
6675 %</tex>
6676 %<*lua,lua-cli,lua-loader>
6677 % \fi
6678 % \begin{macrocode}
6679 defaultOptions.fancyLists = false
6680 % \end{macrocode}
6681 % \iffalse
6682 %</lua,lua-cli,lua-loader>
6683 %<*manual-options>
6684
6685 #### Option `fencedCode`
6686
6687 `fencedCode` (default value: `true`)
6688
6689 % \fi
6690 % \begin{markdown}
6691 %
6692 % \Optitem[true]{fencedCode}{\opt{true}, \opt{false}}
6693 %
6694 : true
6695
6696 : Enable the commonmark fenced code block extension:
6697
6698 ~~~~~~~~ md
6699 ~~~ js
6700 if (a > 3) {
6701 moveShip(5 * gravity, DOWN);
6702 }
6703 ~~~~~~
6704
6705 ``` html
6706 <pre>
6707 <code>
6708 // Some comments
6709 line 1 of code
6710 line 2 of code
6711 line 3 of code
6712 </code>
6713 </pre>
6714 ```
6715 ~~~~~~~~~~~
6716
6717 : false
6718
6719 : Disable the commonmark fenced code block extension.
6720
6721 % \end{markdown}
6722 % \iffalse
6723
6724 ##### \LaTeX{} Example {.unnumbered}
6725
6726 Using a text editor, create a text document named `document.tex` with the
6727 following content:
6728 ```` tex
6729 \documentclass{article}
6730 \usepackage{minted}
6731 \usepackage{markdown}
6732 \begin{document}
6733 \begin{markdown}
6734 ~~~ js
6735 if (a > 3) {
6736 moveShip(5 * gravity, DOWN);
6737 }
6738 ~~~~~~
6739
6740 ``` html
6741 <pre>
6742 <code>
6743 // Some comments
6744 line 1 of code
6745 line 2 of code
6746 line 3 of code
6747 </code>
6748 </pre>
6749 ```
6750 \end{markdown}
6751 \end{document}
6752 ```````
6753 Next, invoke LuaTeX from the terminal:
6754 ``` sh
6755 lualatex --shell-escape document.tex
6756 ``````
6757 A PDF document named `document.pdf` should be produced and contain the
6758 following text:
6759
6760 > ``` js
6761 > if (a > 3) {
6762 > moveShip(5 * gravity, DOWN);
6763 > }
6764 > ```
6765 >
6766 > ``` html
6767 > <pre>
6768 > <code>
6769 > // Some comments
6770 > line 1 of code
6771 > line 2 of code
6772 > line 3 of code
6773 > </code>
6774 > </pre>
6775 > ```
6776
6777 ##### \Hologo{ConTeXt} Example {.unnumbered}
6778
6779 Using a text editor, create a text document named `document.tex` with the
6780 following content:
6781 ```` tex
6782 \usemodule[t][markdown]
6783 \definetyping [js]
6784 \definetyping [html]
6785 \setuptyping [html] [option=XML]
6786 \starttext
6787 \startmarkdown
6788 ~~~ js
6789 if (a > 3) {
6790 moveShip(5 * gravity, DOWN);
6791 }
6792 ~~~~~~
6793
6794 ``` html
6795 <pre>
6796 <code>
6797 // Some comments
6798 line 1 of code
6799 line 2 of code
6800 line 3 of code
6801 </code>
6802 </pre>
6803 ```
6804 \stopmarkdown
6805 \stoptext
6806 ````````
6807 Next, invoke LuaTeX from the terminal:
6808 ``` sh
6809 context --luatex document.tex
6810 `````
6811 A PDF document named `document.pdf` should be produced and contain the
6812 following text:
6813
6814 > ``` js
6815 > if (a > 3) {
6816 > moveShip(5 * gravity, DOWN);
6817 > }
6818 > ```
6819 >
6820 > ``` html
6821 > <pre>
6822 > <code>
6823 > // Some comments
6824 > line 1 of code
6825 > line 2 of code
6826 > line 3 of code
6827 > </code>
6828 > </pre>
6829 > ```
6830
6831 %</manual-options>
6832 %<*tex>
6833 % \fi
6834 % \begin{macrocode}
6835 \@@_add_lua_option:nnn
6836 { fencedCode }
6837 { boolean }
6838 { true }
6839 % \end{macrocode}
6840 % \iffalse
6841 %</tex>
6842 %<*lua,lua-cli,lua-loader>
6843 % \fi
6844 % \begin{macrocode}
6845 defaultOptions.fencedCode = true
6846 % \end{macrocode}
6847 % \iffalse
6848 %</lua,lua-cli,lua-loader>
6849 %<*manual-options>
6850
6851 #### Option `fencedCodeAttributes`
6852
6853 `fencedCodeAttributes` (default value: `false`)
6854
6855 % \fi
6856 % \begin{markdown}
6857 %
6858 % \Optitem[false]{fencedCodeAttributes}{\opt{true}, \opt{false}}
6859 %
6860 : true
6861
6862 : Enable the Pandoc [fenced code attribute syntax extension][pandoc-fenced-code-attributes]:
6863
6864 ```````` md
6865 ~~~~ {#mycode .haskell .numberLines startFrom=100}
6866 qsort [] = []
6867 qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++
6868 qsort (filter (>= x) xs)
6869 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6870 ```````````
6871
6872 : false
6873
6874 : Disable the Pandoc fenced code attribute syntax extension.
6875
6876 [pandoc-fenced-code-attributes]: https://pandoc.org/MANUAL.html#extension-fenced_code_attributes
6877
6878 % \end{markdown}
6879 % \iffalse
6880
6881 ##### \LaTeX{} Example {.unnumbered}
6882
6883 Using a text editor, create a text document named `document.tex` with the
6884 following content:
6885 ```` tex
6886 \documentclass{article}
6887 \usepackage[fencedCode,
6888 fencedCodeAttributes]{markdown}
6889 \usepackage{minted}
6890 \markdownSetup{
6891 renderers = {
6892 fencedCodeAttributeContextBegin = {%
6893 \begingroup
6894 \markdownSetup{
6895 renderers = {
6896 attributeKeyValue = {%
6897 \setminted{{#1} = {#2}}%
6898 },
6899 },
6900 }%
6901 },
6902 fencedCodeAttributeContextEnd = {%
6903 \endgroup
6904 },
6905 },
6906 }
6907 \begin{document}
6908 \begin{markdown}
6909 ~~~ js {linenos=true}
6910 if (a > 3) {
6911 moveShip(5 * gravity, DOWN);
6912 }
6913 ~~~~~~
6914 \end{markdown}
6915 \end{document}
6916 ```````
6917 Next, invoke LuaTeX from the terminal:
6918 ``` sh
6919 lualatex --shell-escape document.tex
6920 ``````
6921 A PDF document named `document.pdf` should be produced and contain the
6922 following text:
6923
6924 > ``` js {.linenos}
6925 > 1. if (a > 3) {
6926 > 2. moveShip(5 * gravity, DOWN);
6927 > 3. }
6928 > ``````
6929
6930 %</manual-options>
6931 %<*tex>
6932 % \fi
6933 % \begin{macrocode}
6934 \@@_add_lua_option:nnn
6935 { fencedCodeAttributes }
6936 { boolean }
6937 { false }
6938 % \end{macrocode}
6939 % \iffalse
6940 %</tex>
6941 %<*lua,lua-cli,lua-loader>
6942 % \fi
6943 % \begin{macrocode}
6944 defaultOptions.fencedCodeAttributes = false
6945 % \end{macrocode}
6946 % \iffalse
6947 %</lua,lua-cli,lua-loader>
6948 %<*manual-options>
6949
6950 #### Option `fencedDivs` {#fenced-divs}
6951
6952 `fencedDivs` (default value: `false`)
6953
6954 % \fi
6955 % \begin{markdown}
6956 %
6957 % \Optitem[false]{fencedDivs}{\opt{true}, \opt{false}}
6958 %
6959 : true
6960
6961 : Enable the Pandoc [fenced div syntax extension][pandoc-fenced-divs]:
6962
6963 ``` md
6964 ::::: {#special .sidebar}
6965 Here is a paragraph.
6966
6967 And another.
6968 :::::
6969 ``````
6970
6971 : false
6972
6973 : Disable the Pandoc fenced div syntax extension.
6974
6975 [pandoc-fenced-divs]: https://pandoc.org/MANUAL.html#extension-fenced_divs
6976
6977 % \end{markdown}
6978 % \iffalse
6979
6980 ##### \LaTeX{} Example {.unnumbered}
6981
6982 Using a text editor, create a text document named `document.tex` with the
6983 following content:
6984 ```` tex
6985 \documentclass{article}
6986 \usepackage[fencedDivs]{markdown}
6987 \begin{document}
6988 \begin{markdown}{slice=special}
6989 Here is a regular paragraph.
6990
6991 ::::: {#special}
6992 Here is a special paragraph.
6993 :::::
6994
6995 And here is another regular paragraph.
6996 \end{markdown}
6997 \end{document}
6998 ```````
6999 Next, invoke LuaTeX from the terminal:
7000 ``` sh
7001 lualatex --shell-escape document.tex
7002 ``````
7003 A PDF document named `document.pdf` should be produced and contain the
7004 following text:
7005
7006 > Here is a special paragraph.
7007
7008 %</manual-options>
7009 %<*tex>
7010 % \fi
7011 % \begin{macrocode}
7012 \@@_add_lua_option:nnn
7013 { fencedDivs }
7014 { boolean }
7015 { false }
7016 % \end{macrocode}
7017 % \iffalse
7018 %</tex>
7019 %<*lua,lua-cli,lua-loader>
7020 % \fi
7021 % \begin{macrocode}
7022 defaultOptions.fencedDivs = false
7023 % \end{macrocode}
7024 % \iffalse
7025 %</lua,lua-cli,lua-loader>
7026 %<*manual-options>
7027
7028 #### Option `finalizeCache`
7029
7030 `finalizeCache` (default value: `false`)
7031
7032 % \fi
7033 % \begin{markdown}
7034 %
7035 % \Optitem[false]{finalizeCache}{\opt{true}, \opt{false}}
7036 %
7037 : Whether an output file specified with the \Opt{frozenCacheFileName} option
7038 (frozen cache) that contains a mapping between an enumeration of markdown
7039 documents and their auxiliary cache files will be created.
7040
7041 The frozen cache makes it possible to later typeset a plain \TeX{}
7042 document that contains markdown documents without invoking Lua using
7043 the \Opt{frozenCache} plain \TeX{} option. As a result, the
7044 plain \TeX{} document becomes more portable, but further changes in the
7045 order and the content of markdown documents will not be reflected.
7046
7047 % \end{markdown}
7048 % \iffalse
7049
7050 ##### Plain \TeX{} Example {.unnumbered}
7051
7052 Using a text editor, create a text document named `document.tex` with the
7053 following content:
7054 ``` tex
7055 \input markdown
7056 \def\markdownOptionFinalizeCache{true}
7057 \markdownBegin
7058 Hello *world*!
7059 \markdownEnd
7060 \bye
7061 ```````
7062 Next, invoke LuaTeX from the terminal:
7063 ``` sh
7064 luatex document.tex
7065 ``````
7066 A PDF document named `document.pdf` should be produced and contain the text
7067 “Hello *world*!” A frozen cache will also be produced as we requested using the
7068 `finalizeCache` option.
7069
7070 Next, change the content of `document.tex` as follows:
7071 ``` tex
7072 \input markdown
7073 \def\markdownOptionFrozenCache{true}
7074 \markdownBegin
7075 Hi *world*!
7076 \markdownEnd
7077 \bye
7078 ```````
7079 Last, invoke pdfTeX without shell access from the terminal:
7080 ``` sh
7081 pdftex -no-shell-escape document.tex
7082 ``````
7083 A new PDF document named `document.pdf` should be produced and contain the
7084 same text “Hello *world*!” Since we used the contents of the frozen cache using
7085 the `\markdownOptionFrozenCache` option, we were able to typeset the document
7086 without accessing the shell or invoking Lua, but the change in the content of
7087 the markdown document from “Hello *world*!” to “Hi *world*!” was not reflected.
7088
7089 ##### \LaTeX{} Example {.unnumbered}
7090
7091 Using a text editor, create a text document named `document.tex` with the
7092 following content:
7093 ``` tex
7094 \documentclass[finalizecache]{article}
7095 \usepackage{markdown}
7096 \begin{document}
7097 \begin{markdown}
7098 Hello *world*!
7099 \end{markdown}
7100 \end{document}
7101 ```````
7102 Next, invoke LuaTeX from the terminal:
7103 ``` sh
7104 lualatex document.tex
7105 ``````
7106 A PDF document named `document.pdf` should be produced and contain the text
7107 “Hello *world*!” A frozen cache will also be produced as we requested using the
7108 `finalizecache` option.
7109
7110 Next, change the content of `document.tex` as follows:
7111 ``` tex
7112 \documentclass[frozencache]{article}
7113 \usepackage{markdown}
7114 \begin{document}
7115 \begin{markdown}
7116 Hi *world*!
7117 \end{markdown}
7118 \end{document}
7119 ```````
7120 Last, invoke pdfTeX without shell access from the terminal:
7121 ``` sh
7122 pdflatex -no-shell-escape document.tex
7123 ``````
7124 A new PDF document named `document.pdf` should be produced and contain the
7125 same text “Hello *world*!” Since we used the contents of the frozen cache using
7126 the `\markdownOptionFrozenCache` option, we were able to typeset the document
7127 without accessing the shell or invoking Lua, but the change in the content of
7128 the markdown document from “Hello *world*!” to “Hi *world*!” was not reflected.
7129
7130 ##### \Hologo{ConTeXt} Example {.unnumbered}
7131
7132 Using a text editor, create a text document named `document.tex` with the
7133 following content:
7134 ``` tex
7135 \usemodule[t][markdown]
7136 \setupmarkdown[finalizeCache = yes]
7137 \starttext
7138 \startmarkdown
7139 Hello *world*!
7140 \stopmarkdown
7141 \stoptext
7142 ```````
7143 Next, invoke LuaTeX from the terminal:
7144 ``` sh
7145 context --luatex document.tex
7146 ``````
7147 A PDF document named `document.pdf` should be produced and contain the text
7148 “Hello *world*!” A frozen cache will also be produced in the `cache.tex`
7149 output file as we requested using the `finalizeCache` option.
7150
7151 Next, change the content of `document.tex` as follows:
7152 ``` tex
7153 \usemodule[t][markdown]
7154 \setupmarkdown[frozenCache = yes]
7155 \starttext
7156 \startmarkdown
7157 Hi *world*!
7158 \stopmarkdown
7159 \stoptext
7160 ```````
7161 Last, invoke LuaTeX from the terminal:
7162 ``` sh
7163 context --luatex document.tex
7164 ``````
7165 A new PDF document named `document.pdf` should be produced and contain the
7166 same text “Hello *world*!” Since we used the contents of the frozen cache using
7167 the `\markdownOptionFrozenCache` option, we were able to typeset the document
7168 without accessing the shell or invoking Lua, but the change in the content of
7169 the markdown document from “Hello *world*!” to “Hi *world*!” was not reflected.
7170
7171 %</manual-options>
7172 %<*tex>
7173 % \fi
7174 % \begin{macrocode}
7175 \@@_add_lua_option:nnn
7176 { finalizeCache }
7177 { boolean }
7178 { false }
7179 % \end{macrocode}
7180 % \iffalse
7181 %</tex>
7182 %<*lua,lua-cli,lua-loader>
7183 % \fi
7184 % \begin{macrocode}
7185 defaultOptions.finalizeCache = false
7186 % \end{macrocode}
7187 % \iffalse
7188 %</lua,lua-cli,lua-loader>
7189 %<*manual-options>
7190
7191 #### Option `frozenCacheCounter`
7192
7193 `frozenCacheCounter` (default value: `0`)
7194
7195 % \fi
7196 % \begin{markdown}
7197 %
7198 % \Valitem[0]{frozenCacheCounter}{number}
7199 %
7200 : The number of the current markdown document that will be stored in
7201 an output file (frozen cache) when the \Opt{finalizeCache} is enabled.
7202 When the document number is 0, then a new frozen cache will be created.
7203 Otherwise, the frozen cache will be appended.
7204
7205 Each frozen cache entry will define a \TeX{} macro
7206 `\markdownFrozenCache`\meta{number} that will typeset markdown document
7207 number \meta{number}.
7208
7209 % \end{markdown}
7210 % \iffalse
7211
7212 ##### Lua Module Example {.unnumbered}
7213
7214 Using a text editor, create a text document named `document.tex` with the
7215 following content:
7216 ``` tex
7217 \input markdown
7218 \begingroup
7219 \catcode`\%=12
7220 \catcode`\#=12
7221 \directlua{
7222 local markdown = require("markdown")
7223 local firstConvert = markdown.new({finalizeCache = true, frozenCacheCounter = 0})
7224 local firstInput = "Hello"
7225 local secondConvert = markdown.new({finalizeCache = true, frozenCacheCounter = 1})
7226 local secondInput = "*world*!"
7227 tex.sprint(firstConvert(firstInput) .. [[ ]] .. secondConvert(secondInput)) }
7228 \endgroup
7229 \bye
7230 ```````
7231 Then, invoke LuaTeX from the terminal:
7232 ``` sh
7233 luatex document.tex
7234 ```````
7235 A PDF document named `document.pdf` should be produced and contain the text
7236 “Hello *world*!” A frozen cache with two entries will also be produced as we
7237 requested using the `frozenCacheCounter` option.
7238
7239 %</manual-options>
7240 %<*tex>
7241 % \fi
7242 % \begin{macrocode}
7243 \@@_add_lua_option:nnn
7244 { frozenCacheCounter }
7245 { counter }
7246 { 0 }
7247 % \end{macrocode}
7248 % \iffalse
7249 %</tex>
7250 %<*lua,lua-cli,lua-loader>
7251 % \fi
7252 % \begin{macrocode}
7253 defaultOptions.frozenCacheCounter = 0
7254 % \end{macrocode}
7255 % \iffalse
7256 %</lua,lua-cli,lua-loader>
7257 %<*manual-options>
7258
7259 #### Option `gfmAutoIdentifiers`
7260
7261 `gfmAutoIdentifiers` (default value: `false`)
7262
7263 % \fi
7264 % \begin{markdown}
7265 % \Optitem[false]{gfmAutoIdentifiers}{\opt{true}, \opt{false}}
7266 %
7267 : true
7268
7269 : Enable the Pandoc [GitHub-flavored auto identifiers syntax extension][pandoc-gfm-auto-identifiers]:
7270
7271 ``` md
7272 The following heading received the identifier
7273 `123-sesame-street`:
7274
7275 # 123 Sesame Street
7276 ``````
7277
7278 : false
7279
7280 : Disable the Pandoc GitHub-flavored auto identifiers syntax extension.
7281
7282 See also the option \Opt{autoIdentifiers}.
7283
7284 [pandoc-gfm-auto-identifiers]: https://pandoc.org/MANUAL.html#extension-gfm_auto_identifiers
7285
7286 % \end{markdown}
7287 % \iffalse
7288 %</manual-options>
7289 %<*tex>
7290 % \fi
7291 % \begin{macrocode}
7292 \@@_add_lua_option:nnn
7293 { gfmAutoIdentifiers }
7294 { boolean }
7295 { false }
7296 % \end{macrocode}
7297 % \iffalse
7298 %</tex>
7299 %<*lua,lua-cli,lua-loader>
7300 % \fi
7301 % \begin{macrocode}
7302 defaultOptions.gfmAutoIdentifiers = false
7303 % \end{macrocode}
7304 % \iffalse
7305 %</lua,lua-cli,lua-loader>
7306 %<*manual-options>
7307
7308 #### Option `hashEnumerators`
7309
7310 `hashEnumerators` (default value: `false`)
7311
7312 % \fi
7313 % \begin{markdown}
7314 %
7315 % \Optitem[false]{hashEnumerators}{\opt{true}, \opt{false}}
7316 %
7317 : true
7318
7319 : Enable the use of hash symbols (`#`) as ordered item list
7320 markers:
7321
7322 ``` md
7323 #. Bird
7324 #. McHale
7325 #. Parish
7326 ``````
7327
7328 : false
7329
7330 : Disable the use of hash symbols (`#`) as ordered item list
7331 markers.
7332
7333 % \end{markdown}
7334 % \iffalse
7335
7336 ##### \LaTeX{} Example {.unnumbered}
7337
7338 Using a text editor, create a text document named `document.tex` with the
7339 following content:
7340 ``` tex
7341 \documentclass{article}
7342 \usepackage{markdown}
7343 \begin{document}
7344
7345 \begin{markdown}
7346 #. Bird
7347 #. McHale
7348 #. Parish
7349 \end{markdown}
7350
7351 \begin{markdown}[hashEnumerators]
7352 #. Bird
7353 #. McHale
7354 #. Parish
7355 \end{markdown}
7356
7357 \end{document}
7358 ```````
7359 Next, invoke LuaTeX from the terminal:
7360 ``` sh
7361 lualatex document.tex
7362 ``````
7363 A PDF document named `document.pdf` should be produced and contain the
7364 following text:
7365
7366 > . Bird
7367 > ========
7368 > . McHale
7369 > ========
7370 > . Parish
7371 > ========
7372 >
7373 > #. Bird
7374 > #. McHale
7375 > #. Parish
7376
7377 ##### \Hologo{ConTeXt} Example {.unnumbered}
7378
7379 Using a text editor, create a text document named `document.tex` with the
7380 following content:
7381 ``` tex
7382 \usemodule[t][markdown]
7383 \starttext
7384
7385 \startmarkdown
7386 #. Bird
7387 #. McHale
7388 #. Parish
7389 \stopmarkdown
7390
7391 \setupmarkdown[hashEnumerators = yes]
7392 \startmarkdown
7393 #. Bird
7394 #. McHale
7395 #. Parish
7396 \stopmarkdown
7397
7398 \stoptext
7399 ````````
7400 Next, invoke LuaTeX from the terminal:
7401 ``` sh
7402 context --luatex document.tex
7403 `````
7404 A PDF document named `document.pdf` should be produced and contain the
7405 following text:
7406
7407 > . Bird
7408 > ========
7409 > . McHale
7410 > ========
7411 > . Parish
7412 > ========
7413 >
7414 > #. Bird
7415 > #. McHale
7416 > #. Parish
7417
7418 %</manual-options>
7419 %<*tex>
7420 % \fi
7421 % \begin{macrocode}
7422 \@@_add_lua_option:nnn
7423 { hashEnumerators }
7424 { boolean }
7425 { false }
7426 % \end{macrocode}
7427 % \iffalse
7428 %</tex>
7429 %<*lua,lua-cli,lua-loader>
7430 % \fi
7431 % \begin{macrocode}
7432 defaultOptions.hashEnumerators = false
7433 % \end{macrocode}
7434 % \iffalse
7435 %</lua,lua-cli,lua-loader>
7436 %<*manual-options>
7437
7438 #### Option `headerAttributes` {#header-attributes}
7439
7440 `headerAttributes` (default value: `false`)
7441
7442 % \fi
7443 % \begin{markdown}
7444 %
7445 % \Optitem[false]{headerAttributes}{\opt{true}, \opt{false}}
7446 %
7447 : true
7448
7449 : Enable the assignment of HTML attributes to headings:
7450
7451 ``` md
7452 # My first heading {#foo}
7453
7454 ## My second heading ## {#bar .baz}
7455
7456 Yet another heading {key=value}
7457 ===================
7458 ``````
7459
7460 : false
7461
7462 : Disable the assignment of HTML attributes to headings.
7463
7464 % \end{markdown}
7465 % \iffalse
7466 %</manual-options>
7467 %<*tex>
7468 % \fi
7469 % \begin{macrocode}
7470 \@@_add_lua_option:nnn
7471 { headerAttributes }
7472 { boolean }
7473 { false }
7474 % \end{macrocode}
7475 % \iffalse
7476 %</tex>
7477 %<*lua,lua-cli,lua-loader>
7478 % \fi
7479 % \begin{macrocode}
7480 defaultOptions.headerAttributes = false
7481 % \end{macrocode}
7482 % \iffalse
7483 %</lua,lua-cli,lua-loader>
7484 %<*manual-options>
7485
7486 #### Option `html`
7487
7488 `html` (default value: `true`)
7489
7490 % \fi
7491 % \begin{markdown}
7492 %
7493 % \Optitem[true]{html}{\opt{true}, \opt{false}}
7494 %
7495 : true
7496
7497 : Enable the recognition of HTML entities, inline HTML tags,
7498 and block HTML elements, comments, declarations, processing
7499 instructions, and CDATA sections in the input.
7500
7501 HTML entities will be replaced with the corresponding Unicode
7502 codepoints and other HTML content will be ignored by default.
7503
7504 : false
7505
7506 : Disable the recognition of HTML markup. Any recognized HTML
7507 content in the input will be rendered as plain text.
7508
7509 % \end{markdown}
7510 % \iffalse
7511
7512 ##### Lua Module Example {.unnumbered}
7513
7514 Using a text editor, create a text document named `document.tex` with the
7515 following content:
7516 ``` tex
7517 \input markdown
7518 \input lmfonts
7519 \begingroup
7520 \catcode`\%=12
7521 \catcode`\#=12
7522 \directlua{
7523 local markdown = require("markdown")
7524 local convert = markdown.new({html = false})
7525 local newline = [[^^J^^J]]
7526 local input =
7527 "<div>*There is no block tag support.*</div>" .. newline ..
7528 "*There is no <inline tag="tag"></inline> support.*" .. newline ..
7529 "_There is no <!-- comment --> support._" .. newline ..
7530 "_There is no <? HTML instruction ?> support._"
7531 tex.sprint(convert(input)) }
7532 \par
7533 \directlua{
7534 local markdown = require("markdown")
7535 local convert = markdown.new()
7536 local input =
7537 "<div>*There is block tag support.*</div>" .. newline ..
7538 "*There is <inline tag="tag"></inline> support.*" .. newline ..
7539 "_There is <!-- comment --> support._" .. newline ..
7540 "_There is <? HTML instruction ?> support._"
7541 tex.sprint(convert(input)) }
7542 \endgroup
7543 \bye
7544 ```````
7545 Then, invoke LuaTeX from the terminal:
7546 ``` sh
7547 luatex document.tex
7548 ```````
7549 A PDF document named `document.pdf` should be produced and contain the
7550 following text:
7551
7552 > \<div>There is no block tag support.\</div>
7553 > There is no \<inline tag=”tag”>\</inline> support.
7554 > There is no \<!-- comment --> support.
7555 > There is no <? HTML instruction ?> support.
7556 >
7557 > There is support. There is support. There is support.
7558
7559 ##### Lua CLI Example {.unnumbered}
7560
7561 Using a text editor, create a text document named `document.tex` with the
7562 following content:
7563 ``` tex
7564 \input markdown
7565 \input lmfonts
7566 \begingroup
7567 \catcode`\%=12
7568 \catcode`\#=12
7569 \input optionfalse
7570 \par
7571 \input optiontrue
7572 \endgroup
7573 \bye
7574 ```````
7575 Using a text editor, create a text document named `content.md` with the
7576 following content:
7577 ``` html
7578 <div>
7579 *Is there block tag support?*
7580 </div>
7581 *Is there <inline tag="tag"></inline> support?*
7582 _Is there <!-- comment --> support?_
7583 _Is there <? HTML instruction ?> support?_
7584 ````````
7585 Next, invoke LuaTeX from the terminal:
7586 ``` sh
7587 markdown2tex html=false -- content.md optionfalse.tex
7588 markdown2tex -- content.md optiontrue.tex
7589 luatex document.tex
7590 ```````
7591
7592 A PDF document named `document.pdf` should be produced and contain the
7593 following text:
7594
7595 > \<div>Is there block tag support?\</div>
7596 > Is there \<inline tag=”tag”>\</inline> support?
7597 > Is there \<!-- comment --> support?
7598 > Is there <? HTML instruction ?> support?
7599 >
7600 > Is there support? Is there support? Is there support?
7601
7602 ##### Plain \TeX{} Example {.unnumbered}
7603
7604 Using a text editor, create a text document named `document.tex` with the
7605 following content:
7606 ``` tex
7607 \input markdown
7608 \input lmfonts
7609
7610 \def\markdownOptionHtml{false}
7611 \markdownBegin
7612 <div>
7613 *There is no block tag support.*
7614 </div>
7615 *There is no <inline tag="tag"></inline> support.*
7616 _There is no <!-- comment --> support._
7617 _There is no <? HTML instruction ?> support._
7618 \markdownEnd
7619
7620 \def\markdownOptionHtml{true}
7621 \markdownBegin
7622 <div>
7623 *There is block tag support.*
7624 </div>
7625 *There is <inline tag="tag"></inline> support.*
7626 _There is <!-- comment --> support._
7627 _There is <? HTML instruction ?> support._
7628 \markdownEnd
7629
7630 \bye
7631 ```````
7632 Next, invoke LuaTeX from the terminal:
7633 ``` sh
7634 luatex document.tex
7635 ``````
7636 A PDF document named `document.pdf` should be produced and contain the
7637 following text:
7638
7639 > \<div>There is no block tag support.\</div>
7640 > There is no \<inline tag=”tag”>\</inline> support.
7641 > There is no \<!-- comment --> support.
7642 > There is no <? HTML instruction ?> support.
7643 >
7644 > There is support. There is support. There is support.
7645
7646 ##### \LaTeX{} Example {.unnumbered}
7647
7648 Using a text editor, create a text document named `document.tex` with the
7649 following content:
7650 ``` tex
7651 \documentclass{article}
7652 \usepackage{markdown}
7653 \begin{document}
7654
7655 \begin{markdown}[html = false]
7656 <div>
7657 *There is no block tag support.*
7658 </div>
7659 *There is no <inline tag="tag"></inline> support.*
7660 _There is no <!-- comment --> support._
7661 _There is no <? HTML instruction ?> support._
7662 \end{markdown}
7663
7664 \begin{markdown}
7665 <div>
7666 *There is block tag support.*
7667 </div>
7668 *There is <inline tag="tag"></inline> support.*
7669 _There is <!-- comment --> support._
7670 _There is <? HTML instruction ?> support._
7671 \end{markdown}
7672
7673 \end{document}
7674 ```````
7675 Next, invoke LuaTeX from the terminal:
7676 ``` sh
7677 lualatex document.tex
7678 ``````
7679 A PDF document named `document.pdf` should be produced and contain the
7680 following text:
7681
7682 > \<div>There is no block tag support.\</div>
7683 > There is no \<inline tag=”tag”>\</inline> support.
7684 > There is no \<!-- comment --> support.
7685 > There is no <? HTML instruction ?> support.
7686 >
7687 > There is support. There is support. There is support.
7688
7689 ##### \Hologo{ConTeXt} Example {.unnumbered}
7690
7691 Using a text editor, create a text document named `document.tex` with the
7692 following content:
7693 ``` tex
7694 \usemodule[t][markdown]
7695 \starttext
7696
7697 \setupmarkdown[html = no]
7698 \startmarkdown
7699 <div>
7700 *There is no block tag support.*
7701 </div>
7702 *There is no <inline tag="tag"></inline> support.*
7703 _There is no <!-- comment --> support._
7704 _There is no <? HTML instruction ?> support._
7705 \stopmarkdown
7706
7707 \setupmarkdown[html = yes]
7708 \startmarkdown
7709 <div>
7710 *There is block tag support.*
7711 </div>
7712 *There is <inline tag="tag"></inline> support.*
7713 _There is <!-- comment --> support._
7714 _There is <? HTML instruction ?> support._
7715 \stopmarkdown
7716
7717 \stoptext
7718 ````````
7719 Next, invoke LuaTeX from the terminal:
7720 ``` sh
7721 context --luatex document.tex
7722 `````
7723 A PDF document named `document.pdf` should be produced and contain the
7724 following text:
7725
7726 > \<div>There is no block tag support.\</div>
7727 > There is no \<inline tag=”tag”>\</inline> support.
7728 > There is no \<!-- comment --> support.
7729 > There is no <? HTML instruction ?> support.
7730 >
7731 > There is support. There is support. There is support.
7732
7733 %</manual-options>
7734 %<*tex>
7735 % \fi
7736 % \begin{macrocode}
7737 \@@_add_lua_option:nnn
7738 { html }
7739 { boolean }
7740 { true }
7741 % \end{macrocode}
7742 % \iffalse
7743 %</tex>
7744 %<*lua,lua-cli,lua-loader>
7745 % \fi
7746 % \begin{macrocode}
7747 defaultOptions.html = true
7748 % \end{macrocode}
7749 % \iffalse
7750 %</lua,lua-cli,lua-loader>
7751 %<*manual-options>
7752
7753 #### Option `htmlOutput`
7754
7755 `htmlOutput` (default value: `basic`)
7756
7757 % \fi
7758 % \begin{markdown}
7759 %
7760 % \Optitem[basic]{htmlOutput}{\opt{basic}, \opt{commonmark}}
7761 %
7762 : basic
7763
7764 : When the \Opt{html} option is enabled, produce
7765 % \iffalse
7766 basic coarse-grained renderers for all HTML.
7767 % \fi
7768 % basic coarse-grained renderers for all HTML, see
7769 % Section <#sec:basic-html-renderers>.
7770
7771 : commonmark
7772
7773 : When the \Opt{html} option is enabled, produce fine-grained renderers
7774 for each top-level non-terminal element of CommonMark's grammar for
7775 % \iffalse
7776 [HTML blocks][html-blocks] and [raw HTML][raw-html].
7777 % \fi
7778 % [HTML blocks][html-blocks] and [raw HTML][raw-html], see sections
7779 % <#sec:commonmark-block-html-renderers> and
7780 % <#sec:commonmark-raw-html-renderers>, respectively.
7781
7782 [html-blocks]: https://spec.commonmark.org/0.31.2/#html-blocks
7783 [raw-html]: https://spec.commonmark.org/0.31.2/#raw-html
7784
7785 % \end{markdown}
7786 % \iffalse
7787 %</manual-options>
7788 %<*tex>
7789 % \fi
7790 % \begin{macrocode}
7791 \@@_add_lua_option:nnn
7792 { htmlOutput }
7793 { string }
7794 { basic }
7795 % \end{macrocode}
7796 % \iffalse
7797 %</tex>
7798 %<*lua,lua-cli,lua-loader>
7799 % \fi
7800 % \begin{macrocode}
7801 defaultOptions.htmlOutput = "basic"
7802 % \end{macrocode}
7803 % \iffalse
7804 %</lua,lua-cli,lua-loader>
7805 %<*manual-options>
7806
7807 #### Option `htmlOverLinks`
7808
7809 `htmlOverLinks` (default value: `false`)
7810
7811 % \fi
7812 % \begin{markdown}
7813 %
7814 % \Optitem[false]{htmlOverLinks}{\opt{true}, \opt{false}}
7815 %
7816 : true
7817
7818 : When the option \Opt{html} is enabled and a text can be understood
7819 either as a hyperlink or HTML, interpret it as HTML.
7820
7821 This is especially relevant when the option \Opt{relativeReferences}
7822 is enabled, since it makes e.g. `</foo>` a valid hyperlink.
7823
7824 : false
7825
7826 : When the option \Opt{html} is enabled and a text can be understood
7827 either as a hyperlink or HTML, interpret it as a hyperlink.
7828
7829 This is an experimental option. Whenever the option \Opt{experimental} is
7830 enabled and this option is unspecified, it will be enabled. Like other
7831 experimental options, this option will be enabled by default and
7832 soft-deprecated in the next major release of the Markdown package.
7833
7834 % \end{markdown}
7835 % \iffalse
7836 %</manual-options>
7837 %<*tex>
7838 % \fi
7839 % \begin{macrocode}
7840 \@@_add_experimental_lua_option:n
7841 { htmlOverLinks }
7842 % \end{macrocode}
7843 % \iffalse
7844 %</tex>
7845 %<*lua,lua-cli,lua-loader>
7846 % \fi
7847 % \begin{macrocode}
7848 defaultOptions.htmlOverLinks = false
7849 experimentalOptions.htmlOverLinks = true
7850 % \end{macrocode}
7851 % \iffalse
7852 %</lua,lua-cli,lua-loader>
7853 %<*manual-options>
7854
7855 #### Option `hybrid`
7856
7857 `hybrid` (default value: `false`)
7858
7859 % \fi
7860 % \begin{markdown}
7861 %
7862 % \Optitem[false]{hybrid}{\opt{true}, \opt{false}}
7863 %
7864 : true
7865
7866 : Disable the escaping of special plain \TeX{} characters, which makes it
7867 possible to intersperse your markdown markup with \TeX{} code. The
7868 intended usage is in documents prepared manually by a human author.
7869 In such documents, it can often be desirable to mix \TeX{} and markdown
7870 markup freely.
7871
7872 : false
7873
7874 : Enable the escaping of special plain \TeX{} characters outside verbatim
7875 environments, so that they are not interpreted by \TeX{}. This is
7876 encouraged when typesetting automatically generated content or
7877 markdown documents that were not prepared with this package in mind.
7878
7879 The \Opt{hybrid} option makes it difficult to untangle \TeX{} input from
7880 markdown text, which makes documents written with the \Opt{hybrid} option
7881 less interoperable and more difficult to read for authors. Therefore, the
7882 option has been soft-deprecated in version 3.7.1 of the Markdown package:
7883 It will never be removed but using it prints a warning and is discouraged.
7884
7885 Consider one of the following better alternatives for mixing \TeX{} and
7886 markdown:
7887
7888 - With the \Opt{contentBlocks} option, authors can move large blocks of TeX
7889 code to separate files and include them in their markdown documents as
7890 external resources:
7891
7892 ``` md
7893 Here is a mathematical formula:
7894
7895 /math-formula.tex
7896 ```
7897
7898 - With the \Opt{rawAttribute} option, authors can denote raw text spans and
7899 code blocks that will be interpreted as \TeX{} code:
7900
7901 `````` md
7902 `$H_2 O$`{=tex} is a liquid.
7903
7904 Here is a mathematical formula:
7905 ``` {=tex}
7906 \[distance[i] =
7907 \begin{dcases}
7908 a & b \\
7909 c & d
7910 \end{dcases}
7911 \]
7912 ```
7913 ``````
7914
7915 - With options \Opt{texMathDollars}, \Opt{texMathSingleBackslash}, and
7916 \Opt{texMathDoubleBackslash}, authors can freely type \TeX{} commands between
7917 dollar signs or backslash-escaped brackets:
7918
7919 ``` md
7920 $H_2 O$ is a liquid.
7921
7922 Here is a mathematical formula:
7923 \[distance[i] =
7924 \begin{dcases}
7925 a & b \\
7926 c & d
7927 \end{dcases}
7928 \]
7929 ```
7930
7931 % \end{markdown}
7932 % \iffalse
7933
7934 ##### Lua Module Example {.unnumbered}
7935
7936 Using a text editor, create a text document named `document.tex` with the
7937 following content:
7938 ``` tex
7939 \input markdown
7940 \input lmfonts
7941 \begingroup
7942 \catcode`\%=12
7943 \catcode`\#=12
7944 \directlua{
7945 local markdown = require("markdown")
7946 local input, convert_safe, convert_unsafe, paragraph
7947
7948 input = [[$\string\sqrt{-1}$ *equals* $i$.]]
7949 convert_safe = markdown.new()
7950 convert_unsafe = markdown.new({hybrid = true})
7951 paragraph = [[\par]]
7952
7953 tex.sprint(
7954 convert_safe(input) .. paragraph ..
7955 convert_unsafe(input)
7956 )
7957 }
7958 \endgroup
7959 \bye
7960 ```````
7961 Then, invoke LuaTeX from the terminal:
7962 ``` sh
7963 luatex document.tex
7964 ```````
7965 A PDF document named `document.pdf` should be produced and contain the
7966 following text:
7967
7968 > \$\\sqrt {-1}\$ *equals* \$i\$.
7969 >
7970 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
7971 > *equals*
7972 > <math><mi>i</mi></math>.
7973
7974 ##### Lua CLI Example {.unnumbered}
7975
7976 Using a text editor, create a text document named `document.tex` with the
7977 following content:
7978 ``` tex
7979 \input markdown
7980 \input lmfonts
7981 \begingroup
7982 \catcode`\%=12
7983 \catcode`\#=12
7984 \input optionfalse
7985 \par
7986 \input optiontrue
7987 \endgroup
7988 \bye
7989 ```````
7990 Using a text editor, create a text document named `content.md` with the
7991 following content:
7992 ``` md
7993 $\sqrt{-1}$ *equals* $i$.
7994 ``````
7995 Next, invoke LuaTeX from the terminal:
7996 ``` sh
7997 markdown2tex -- content.md optionfalse.tex
7998 markdown2tex hybrid=true -- content.md optiontrue.tex
7999 luatex document.tex
8000 ```````
8001
8002 A PDF document named `document.pdf` should be produced and contain the
8003 following text:
8004
8005 > \$\\sqrt {-1}\$ *equals* \$i\$.
8006 >
8007 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
8008 > *equals*
8009 > <math><mi>i</mi></math>.
8010
8011 ##### Plain \TeX{} Example {.unnumbered}
8012
8013 Using a text editor, create a text document named `document.tex` with the
8014 following content:
8015 ``` tex
8016 \input markdown
8017 \input lmfonts
8018
8019 \markdownBegin
8020 $\sqrt{-1}$ *equals* $i$.
8021 \markdownEnd
8022
8023 \def\markdownOptionHybrid{true}
8024 \markdownBegin
8025 $\sqrt{-1}$ *equals* $i$.
8026 \markdownEnd
8027
8028 \bye
8029 ```````
8030 Next, invoke LuaTeX from the terminal:
8031 ``` sh
8032 luatex document.tex
8033 ``````
8034 A PDF document named `document.pdf` should be produced and contain the
8035 following text:
8036
8037 > \$\\sqrt {-1}\$ *equals* \$i\$.
8038 >
8039 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
8040 > *equals*
8041 > <math><mi>i</mi></math>.
8042
8043 ##### \LaTeX{} Example {.unnumbered}
8044
8045 Using a text editor, create a text document named `document.tex` with the
8046 following content:
8047 ``` tex
8048 \documentclass{article}
8049 \usepackage{markdown}
8050 \begin{document}
8051
8052 \begin{markdown}
8053 $\sqrt{-1}$ *equals* $i$.
8054 \end{markdown}
8055
8056 \begin{markdown}[hybrid]
8057 $\sqrt{-1}$ *equals* $i$.
8058 \end{markdown}
8059
8060 \end{document}
8061 ```````
8062 Next, invoke LuaTeX from the terminal:
8063 ``` sh
8064 lualatex document.tex
8065 ``````
8066 A PDF document named `document.pdf` should be produced and contain the
8067 following text:
8068
8069 > \$\\sqrt {-1}\$ *equals* \$i\$.
8070 >
8071 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
8072 > *equals*
8073 > <math><mi>i</mi></math>.
8074
8075 ##### \Hologo{ConTeXt} Example {.unnumbered}
8076
8077 Using a text editor, create a text document named `document.tex` with the
8078 following content:
8079 ``` tex
8080 \usemodule[t][markdown]
8081 \starttext
8082
8083 \startmarkdown
8084 $\sqrt{-1}$ *equals* $i$.
8085 \stopmarkdown
8086
8087 \setupmarkdown[hybrid = yes]
8088 \startmarkdown
8089 $\sqrt{-1}$ *equals* $i$.
8090 \stopmarkdown
8091
8092 \stoptext
8093 ````````
8094 Next, invoke LuaTeX from the terminal:
8095 ``` sh
8096 context --luatex document.tex
8097 `````
8098 A PDF document named `document.pdf` should be produced and contain the
8099 following text:
8100
8101 > \$\\sqrt {-1}\$ *equals* \$i\$.
8102 >
8103 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
8104 > *equals*
8105 > <math><mi>i</mi></math>.
8106
8107 %</manual-options>
8108 %<*tex>
8109 % \fi
8110 % \begin{macrocode}
8111 \@@_add_lua_option:nnn
8112 { hybrid }
8113 { boolean }
8114 { false }
8115 % \end{macrocode}
8116 % \iffalse
8117 %</tex>
8118 %<*lua,lua-cli,lua-loader>
8119 % \fi
8120 % \begin{macrocode}
8121 defaultOptions.hybrid = false
8122 % \end{macrocode}
8123 % \iffalse
8124 %</lua,lua-cli,lua-loader>
8125 %<*manual-options>
8126
8127 #### Option `inlineCodeAttributes`
8128
8129 `inlineCodeAttributes` (default value: `false`)
8130
8131 % \fi
8132 % \begin{markdown}
8133 %
8134 % \Optitem[false]{inlineCodeAttributes}{\opt{true}, \opt{false}}
8135 %
8136 : true
8137
8138 : Enable the Pandoc [inline code span attribute extension][pandoc-inline-code-attributes]:
8139
8140 ``` md
8141 `<$>`{.haskell}
8142 ``````
8143
8144 : false
8145
8146 : Enable the Pandoc inline code span attribute extension.
8147
8148 [pandoc-inline-code-attributes]: https://pandoc.org/MANUAL.html#extension-inline_code_attributes
8149
8150 % \end{markdown}
8151 % \iffalse
8152
8153 ##### \LaTeX{} Example {.unnumbered}
8154
8155 Using a text editor, create a text document named `document.tex` with the
8156 following content:
8157 ```` tex
8158 \documentclass{article}
8159 \usepackage[inlineCodeAttributes]{markdown}
8160 \usepackage{expl3}
8161 \ExplSyntaxOn
8162 \markdownSetup{
8163 renderers = {
8164 codeSpanAttributeContextBegin = {
8165 \group_begin:
8166 \color_group_begin:
8167 \markdownSetup{
8168 renderers = {
8169 attributeKeyValue = {
8170 \str_if_eq:nnT
8171 { ##1 }
8172 { color }
8173 {
8174 \color_select:n { ##2 }
8175 }
8176 },
8177 },
8178 }
8179 },
8180 codeSpanAttributeContextEnd = {
8181 \color_group_end:
8182 \group_end:
8183 },
8184 },
8185 }
8186 \ExplSyntaxOff
8187 \begin{document}
8188 \begin{markdown}
8189 Here is some `colored text`{color=red}.
8190 \end{markdown}
8191 \end{document}
8192 ```````
8193 Next, invoke LuaTeX from the terminal:
8194 ``` sh
8195 lualatex document.tex
8196 ``````
8197 A PDF document named `document.pdf` should be produced and contain the
8198 following text:
8199
8200 > Here is some <span style="color: red">`colored text`</span>.
8201
8202 %</manual-options>
8203 %<*tex>
8204 % \fi
8205 % \begin{macrocode}
8206 \@@_add_lua_option:nnn
8207 { inlineCodeAttributes }
8208 { boolean }
8209 { false }
8210 % \end{macrocode}
8211 % \iffalse
8212 %</tex>
8213 %<*lua,lua-cli,lua-loader>
8214 % \fi
8215 % \begin{macrocode}
8216 defaultOptions.inlineCodeAttributes = false
8217 % \end{macrocode}
8218 % \iffalse
8219 %</lua,lua-cli,lua-loader>
8220 %<*manual-options>
8221
8222 #### Option `inlineNotes`
8223
8224 `inlineNotes` (default value: `false`)
8225
8226 % \fi
8227 % \begin{markdown}
8228 %
8229 % \Optitem[false]{inlineNotes}{\opt{true}, \opt{false}}
8230 %
8231 : true
8232
8233 : Enable the Pandoc [inline note syntax extension][pandoc-inline-notes]:
8234
8235 ``` md
8236 Here is an inline note.^[Inline notes are easier to
8237 write, since you don't have to pick an identifier and
8238 move down to type the note.]
8239 ``````
8240
8241 : false
8242
8243 : Disable the Pandoc inline note syntax extension.
8244
8245 [pandoc-inline-notes]: https://pandoc.org/MANUAL.html#extension-inline_notes
8246
8247 % \end{markdown}
8248 % \iffalse
8249
8250 ##### \LaTeX{} Example {.unnumbered}
8251
8252 Using a text editor, create a text document named `document.tex` with the
8253 following content:
8254 ``` tex
8255 \documentclass{article}
8256 \usepackage[inlineNotes]{markdown}
8257 \begin{document}
8258 \begin{markdown}
8259 Here is an inline note.^[Inline notes are easier to
8260 write, since you don't have to pick an identifier and
8261 move down to type the note.]
8262 \end{markdown}
8263 \end{document}
8264 ```````
8265 Next, invoke LuaTeX from the terminal:
8266 ``` sh
8267 lualatex document.tex
8268 ``````
8269 A PDF document named `document.pdf` should be produced and contain the
8270 following text:
8271
8272 > Here is an inline note.^[Inline notes are easier to
8273 > write, since you don't have to pick an identifier and
8274 > move down to type the note.]
8275
8276 ##### \Hologo{ConTeXt} Example {.unnumbered}
8277
8278 Using a text editor, create a text document named `document.tex` with the
8279 following content:
8280 ``` tex
8281 \usemodule[t][markdown]
8282 \setupmarkdown[inlineNotes = yes]
8283 \starttext
8284 \startmarkdown
8285 Here is an inline note.^[Inline notes are easier to
8286 write, since you don't have to pick an identifier and
8287 move down to type the note.]
8288 \stopmarkdown
8289 \stoptext
8290 ````````
8291 Next, invoke LuaTeX from the terminal:
8292 ``` sh
8293 context --luatex document.tex
8294 `````
8295 A PDF document named `document.pdf` should be produced and contain the
8296 following text:
8297
8298 > Here is an inline note.^[Inline notes are easier to
8299 > write, since you don't have to pick an identifier and
8300 > move down to type the note.]
8301
8302 %</manual-options>
8303 %<*tex>
8304 % \fi
8305 % \begin{macrocode}
8306 \@@_add_lua_option:nnn
8307 { inlineNotes }
8308 { boolean }
8309 { false }
8310 % \end{macrocode}
8311 % \iffalse
8312 %</tex>
8313 %<*lua,lua-cli,lua-loader>
8314 % \fi
8315 % \begin{macrocode}
8316 defaultOptions.inlineNotes = false
8317 % \end{macrocode}
8318 % \iffalse
8319 %</lua,lua-cli,lua-loader>
8320 %<*manual-options>
8321
8322 #### Option `jekyllData`
8323
8324 `jekyllData` (default value: `false`)
8325
8326 % \fi
8327 % \begin{markdown}
8328 %
8329 % \Optitem[false]{jekyllData}{\opt{true}, \opt{false}}
8330 %
8331 : true
8332
8333 : Enable the Pandoc [YAML metadata block syntax
8334 extension][pandoc-yaml-metadata-block] for entering
8335 metadata in YAML:
8336
8337 ~~~~~~ yaml
8338 ---
8339 title: 'This is the title: it contains a colon'
8340 author:
8341 - Author One
8342 - Author Two
8343 keywords: [nothing, nothingness]
8344 abstract: |
8345 This is the abstract.
8346
8347 It consists of two paragraphs.
8348 ---
8349 ~~~~~~~~~~~
8350
8351 : false
8352
8353 : Disable the Pandoc YAML metadata block syntax extension
8354 for entering metadata in YAML.
8355
8356 [pandoc-yaml-metadata-block]: https://pandoc.org/MANUAL.html#extension-yaml_metadata_block
8357
8358 % See also the plain \TeX{} macros \mref{yamlBegin}, \mref{yamlEnd}, and
8359 % \mref{yamlInput} in Section <#sec:tex-typesetting>, the \LaTeX{} environment
8360 % \envmref{yaml} in Section <#sec:latex-typesetting>, and the \Hologo{ConTeXt}
8361 % macros \mref{startyaml}, \mref{stopyaml}, and \mref{inputyaml} in Section
8362 % <#sec:context-typesetting> to see how the options \Opt{jekyllData},
8363 % \Opt{expectJekyllData}, and \Opt{ensureJekyllData} can be used together to
8364 % implement high-level interfaces for processing YAML documents.
8365 %
8366 % \end{markdown}
8367 % \iffalse
8368
8369 ##### Plain \TeX{} Example {.unnumbered}
8370
8371 Using a text editor, create a text document named `document.tex` with the
8372 following content:
8373 ``` tex
8374 \input markdown
8375 \def\markdownOptionJekyllData{true}
8376 \ExplSyntaxOn
8377 \keys_define:nn
8378 { markdown/jekyllData }
8379 {
8380 name .code:n = { \gdef\name{#1} },
8381 age .code:n = { \gdef\age{#1} },
8382 }
8383 \ExplSyntaxOff
8384 \def\markdownRendererJekyllDataEnd{%
8385 \name{} is \age{} years old.}
8386 \markdownBegin
8387 ---
8388 name: Jane Doe
8389 age: 99
8390 ---
8391 \markdownEnd
8392 \bye
8393 ```````
8394 Next, invoke LuaTeX from the terminal:
8395 ``` sh
8396 luatex document.tex
8397 ``````
8398 A PDF document named `document.pdf` should be produced and contain the
8399 following text:
8400
8401 > Jane Doe is 99 years old.
8402
8403 ##### \LaTeX{} Example {.unnumbered}
8404
8405 Using a text editor, create a text document named `document.tex` with the
8406 following content:
8407 ``` tex
8408 \documentclass{article}
8409 \usepackage[jekyllData]{markdown}
8410 \markdownSetup{
8411 jekyllDataRenderers = {
8412 name = {\gdef\name{#1}},
8413 code = {\gdef\age{#1}},
8414 },
8415 renderers = {
8416 jekyllDataEnd = {\name{} is \age{} years old.},
8417 }
8418 }
8419 \begin{document}
8420
8421 \begin{markdown}
8422 ---
8423 name: Jane Doe
8424 age: 99
8425 ---
8426 \end{markdown}
8427
8428 \end{document}
8429 ```````
8430 Next, invoke LuaTeX from the terminal:
8431 ``` sh
8432 lualatex document.tex
8433 ``````
8434 A PDF document named `document.pdf` should be produced and contain the
8435 following text:
8436
8437 > Jane Doe is 99 years old.
8438
8439 ##### \Hologo{ConTeXt} Example {.unnumbered}
8440
8441 Using a text editor, create a text document named `document.tex` with the
8442 following content:
8443 ``` tex
8444 \usemodule[t][markdown]
8445 \setupmarkdown[jekyllData = yes]
8446 \ExplSyntaxOn
8447 \keys_define:nn
8448 { markdown/jekyllData }
8449 {
8450 name .code:n = { \gdef\name{#1} },
8451 age .code:n = { \gdef\age{#1} },
8452 }
8453 \ExplSyntaxOff
8454 \def\markdownRendererJekyllDataEnd{%
8455 \name{} is \age{} years old.}
8456 \starttext
8457
8458 \startmarkdown
8459 ---
8460 name: Jane Doe
8461 age: 99
8462 ---
8463 \stopmarkdown
8464
8465 \stoptext
8466 ```````
8467 Next, invoke LuaTeX from the terminal:
8468 ``` sh
8469 context --luatex document.tex
8470 ``````
8471 A PDF document named `document.pdf` should be produced and contain the
8472 following text:
8473
8474 > Jane Doe is 99 years old.
8475
8476 %</manual-options>
8477 %<*tex>
8478 % \fi
8479 % \begin{macrocode}
8480 \@@_add_lua_option:nnn
8481 { jekyllData }
8482 { boolean }
8483 { false }
8484 % \end{macrocode}
8485 % \iffalse
8486 %</tex>
8487 %<*lua,lua-cli,lua-loader>
8488 % \fi
8489 % \begin{macrocode}
8490 defaultOptions.jekyllData = false
8491 % \end{macrocode}
8492 % \iffalse
8493 %</lua,lua-cli,lua-loader>
8494 %<*manual-options>
8495
8496 #### Option `linkAttributes`
8497
8498 `linkAttributes` (default value: `false`)
8499
8500 % \fi
8501 % \begin{markdown}
8502 %
8503 % \Optitem[false]{linkAttributes}{\opt{true}, \opt{false}}
8504 %
8505 : true
8506
8507 : Enable the Pandoc [link and image attribute syntax
8508 extension][pandoc-link-attributes]:
8509
8510 ``` md
8511 An inline ![image](foo.jpg){#id .class height=20px}
8512 and a reference ![image][ref] with attributes.
8513
8514 [ref]: foo.jpg "optional title" {#id .class key=val}
8515 ``````
8516
8517 : false
8518
8519 : Enable the Pandoc link and image attribute syntax extension.
8520
8521 [pandoc-link-attributes]: https://pandoc.org/MANUAL.html#extension-link_attributes
8522
8523 % \end{markdown}
8524 % \iffalse
8525
8526 ##### \LaTeX{} Example {.unnumbered}
8527
8528 Using a text editor, create a text document named `document.tex` with the
8529 following content:
8530 ```` tex
8531 \documentclass{article}
8532 \usepackage[linkAttributes]{markdown}
8533 \usepackage{expl3, graphicx}
8534 \ExplSyntaxOn
8535 \markdownSetup{
8536 renderers = {
8537 imageAttributeContextBegin = {
8538 \group_begin:
8539 \markdownSetup{
8540 renderers = {
8541 attributeKeyValue = {
8542 \setkeys
8543 { Gin }
8544 { { ##1 } = { ##2 } }
8545 },
8546 },
8547 }
8548 },
8549 imageAttributeContextEnd = {
8550 \group_end:
8551 },
8552 },
8553 }
8554 \ExplSyntaxOff
8555 \begin{document}
8556 \begin{markdown}
8557 Here is an example image:
8558
8559 ![example image](example-image){width=5cm height=4cm}
8560 \end{markdown}
8561 \end{document}
8562 ```````
8563 Next, invoke LuaTeX from the terminal:
8564 ``` sh
8565 lualatex document.tex
8566 ``````
8567 A PDF document named `document.pdf` should be produced and contain an example
8568 image (from [Martin Scharrer's mwe package][mwe]) displayed at size 5cm × 4cm.
8569
8570 [mwe]: https://ctan.org/pkg/mwe (mwe – Packages and image files for MWEs)
8571
8572 %</manual-options>
8573 %<*tex>
8574 % \fi
8575 % \begin{macrocode}
8576 \@@_add_lua_option:nnn
8577 { linkAttributes }
8578 { boolean }
8579 { false }
8580 % \end{macrocode}
8581 % \iffalse
8582 %</tex>
8583 %<*lua,lua-cli,lua-loader>
8584 % \fi
8585 % \begin{macrocode}
8586 defaultOptions.linkAttributes = false
8587 % \end{macrocode}
8588 % \iffalse
8589 %</lua,lua-cli,lua-loader>
8590 %<*manual-options>
8591
8592 #### Option `lineBlocks`
8593
8594 `lineBlocks` (default value: `false`)
8595
8596 % \fi
8597 % \begin{markdown}
8598 %
8599 % \Optitem[false]{lineBlocks}{\opt{true}, \opt{false}}
8600 %
8601 : true
8602
8603 : Enable the Pandoc [line block syntax
8604 extension][pandoc-line-blocks]:
8605
8606 ``` md
8607 | this is a line block that
8608 | spans multiple
8609 | even
8610 discontinuous
8611 | lines
8612 ``````
8613
8614 : false
8615
8616 : Disable the Pandoc line block syntax extension.
8617
8618 [pandoc-line-blocks]: https://pandoc.org/MANUAL.html#extension-line_blocks
8619
8620 % \end{markdown}
8621 % \iffalse
8622
8623 ##### Plain \TeX{} Example {.unnumbered}
8624
8625 Using a text editor, create a text document named `document.tex` with the
8626 following content:
8627 ``` tex
8628 \input markdown
8629 \def\markdownOptionLineBlocks{true}
8630 \markdownBegin
8631 | I would spread the cloths under your feet:
8632 | But I, being poor, have only my dreams;
8633 | I have spread my dreams under your feet;
8634 | Tread softly because you tread on my dreams.
8635 \markdownEnd
8636 \bye
8637 ```````
8638 Next, invoke LuaTeX from the terminal:
8639 ``` sh
8640 luatex document.tex
8641 ``````
8642 A PDF document named `document.pdf` should be produced and contain the
8643 following text:
8644
8645 > | I would spread the cloths under your feet:
8646 > | But I, being poor, have only my dreams;
8647 > | I have spread my dreams under your feet;
8648 > | Tread softly because you tread on my dreams.
8649
8650 ##### \LaTeX{} Example {.unnumbered}
8651
8652 Using a text editor, create a text document named `document.tex` with the
8653 following content:
8654 ``` tex
8655 \documentclass{article}
8656 \usepackage[lineBlocks]{markdown}
8657 \begin{document}
8658 \begin{markdown}
8659 | I would spread the cloths under your feet:
8660 | But I, being poor, have only my dreams;
8661 | I have spread my dreams under your feet;
8662 | Tread softly because you tread on my dreams.
8663 \end{markdown}
8664 \end{document}
8665 ```````
8666 Next, invoke LuaTeX from the terminal:
8667 ``` sh
8668 lualatex document.tex
8669 ``````
8670 A PDF document named `document.pdf` should be produced and contain the
8671 following text:
8672
8673 > | I would spread the cloths under your feet:
8674 > | But I, being poor, have only my dreams;
8675 > | I have spread my dreams under your feet;
8676 > | Tread softly because you tread on my dreams.
8677
8678 ##### \Hologo{ConTeXt} Example {.unnumbered}
8679
8680 Using a text editor, create a text document named `document.tex` with the
8681 following content:
8682 ``` tex
8683 \usemodule[t][markdown]
8684 \setupmarkdown[lineBlocks = yes]
8685 \starttext
8686 \startmarkdown
8687 | I would spread the cloths under your feet:
8688 | But I, being poor, have only my dreams;
8689 | I have spread my dreams under your feet;
8690 | Tread softly because you tread on my dreams.
8691 \stopmarkdown
8692 \stoptext
8693 ```````
8694 Next, invoke LuaTeX from the terminal:
8695 ``` sh
8696 context --luatex document.tex
8697 ``````
8698 A PDF document named `document.pdf` should be produced and contain the
8699 following text:
8700
8701 > | I would spread the cloths under your feet:
8702 > | But I, being poor, have only my dreams;
8703 > | I have spread my dreams under your feet;
8704 > | Tread softly because you tread on my dreams.
8705
8706 %</manual-options>
8707 %<*tex>
8708 % \fi
8709 % \begin{macrocode}
8710 \@@_add_lua_option:nnn
8711 { lineBlocks }
8712 { boolean }
8713 { false }
8714 % \end{macrocode}
8715 % \iffalse
8716 %</tex>
8717 %<*lua,lua-cli,lua-loader>
8718 % \fi
8719 % \begin{macrocode}
8720 defaultOptions.lineBlocks = false
8721 % \end{macrocode}
8722 % \iffalse
8723 %</lua,lua-cli,lua-loader>
8724 %<*manual-options>
8725
8726 #### Option `mark`
8727
8728 `mark` (default value: `false`)
8729
8730 % \fi
8731 % \begin{markdown}
8732 %
8733 % \Optitem[false]{mark}{\opt{true}, \opt{false}}
8734 %
8735 : true
8736
8737 : Enable the Pandoc [mark syntax extension][pandoc-mark]:
8738
8739 ``` md
8740 This ==is highlighted text.==
8741 ``````
8742
8743 : false
8744
8745 : Disable the Pandoc mark syntax extension.
8746
8747 [pandoc-mark]: https://pandoc.org/MANUAL.html#extension-mark
8748
8749 % \end{markdown}
8750 % \iffalse
8751
8752 ##### \LaTeX{} Example {.unnumbered}
8753
8754 Using a text editor, create a text document named `document.tex` with the
8755 following content:
8756 ``` tex
8757 \documentclass{article}
8758 \usepackage[mark]{markdown}
8759 \begin{document}
8760 \begin{markdown}
8761
8762 This ==is highlighted text.==
8763
8764 \end{markdown}
8765 \end{document}
8766 ```````
8767 Next, invoke LuaTeX from the terminal:
8768 ``` sh
8769 lualatex document.tex
8770 ``````
8771 A PDF document named `document.pdf` should be produced and contain the
8772 following text:
8773
8774 > This <mark>is highlighted text.</mark>
8775
8776 %</manual-options>
8777 %<*tex>
8778 % \fi
8779 % \begin{macrocode}
8780 \@@_add_lua_option:nnn
8781 { mark }
8782 { boolean }
8783 { false }
8784 % \end{macrocode}
8785 % \iffalse
8786 %</tex>
8787 %<*lua,lua-cli,lua-loader>
8788 % \fi
8789 % \begin{macrocode}
8790 defaultOptions.mark = false
8791 % \end{macrocode}
8792 % \iffalse
8793 %</lua,lua-cli,lua-loader>
8794 %<*manual-options>
8795
8796 #### Option `notes`
8797
8798 `notes` (default value: `false`)
8799
8800 % \fi
8801 % \begin{markdown}
8802 %
8803 % \Optitem[false]{notes}{\opt{true}, \opt{false}}
8804 %
8805 : true
8806
8807 : Enable the Pandoc [note syntax extension][pandoc-footnotes]:
8808
8809 ``` md
8810 Here is a note reference,[^1] and another.[^longnote]
8811
8812 [^1]: Here is the note.
8813
8814 [^longnote]: Here's one with multiple blocks.
8815
8816 Subsequent paragraphs are indented to show that they
8817 belong to the previous note.
8818
8819 { some.code }
8820
8821 The whole paragraph can be indented, or just the
8822 first line. In this way, multi-paragraph notes
8823 work like multi-paragraph list items.
8824
8825 This paragraph won't be part of the note, because it
8826 isn't indented.
8827 ``````
8828
8829 : false
8830
8831 : Disable the Pandoc note syntax extension.
8832
8833 [pandoc-footnotes]: https://pandoc.org/MANUAL.html#extension-footnotes
8834
8835 % \end{markdown}
8836 % \iffalse
8837
8838 ##### \LaTeX{} Example {.unnumbered}
8839
8840 Using a text editor, create a text document named `document.tex` with the
8841 following content:
8842 ``` tex
8843 \documentclass{article}
8844 \usepackage[notes]{markdown}
8845 \begin{document}
8846 \begin{markdown}
8847 Here is a note reference,[^1] and another.[^longnote]
8848
8849 [^1]: Here is the note.
8850
8851 [^longnote]: Here's one with multiple blocks.
8852
8853 Subsequent paragraphs are indented to show that they
8854 belong to the previous note.
8855
8856 { some.code }
8857
8858 The whole paragraph can be indented, or just the
8859 first line. In this way, multi-paragraph notes
8860 work like multi-paragraph list items.
8861
8862 This paragraph won't be part of the note, because it
8863 isn't indented.
8864 \end{markdown}
8865 \end{document}
8866 ```````
8867 Next, invoke LuaTeX from the terminal:
8868 ``` sh
8869 lualatex document.tex
8870 ``````
8871 A PDF document named `document.pdf` should be produced and contain the
8872 following text:
8873
8874 > Here is a note reference,[^1] and another.[^longnote]
8875 >
8876 > Subsequent paragraphs are indented to show that they
8877 > belong to the previous note.
8878 >
8879 > { some.code }
8880 >
8881 > The whole paragraph can be indented, or just the
8882 > first line. In this way, multi-paragraph notes
8883 > work like multi-paragraph list items.
8884 >
8885 > This paragraph won't be part of the note, because it
8886 > isn't indented.
8887
8888 ##### \Hologo{ConTeXt} Example {.unnumbered}
8889
8890 Using a text editor, create a text document named `document.tex` with the
8891 following content:
8892 ``` tex
8893 \usemodule[t][markdown]
8894 \setupmarkdown[notes = yes]
8895 \starttext
8896 \startmarkdown
8897 Here is a note reference,[^1] and another.[^longnote]
8898
8899 [^1]: Here is the note.
8900
8901 [^longnote]: Here's one with multiple blocks.
8902
8903 Subsequent paragraphs are indented to show that they
8904 belong to the previous note.
8905
8906 { some.code }
8907
8908 The whole paragraph can be indented, or just the
8909 first line. In this way, multi-paragraph notes
8910 work like multi-paragraph list items.
8911
8912 This paragraph won't be part of the note, because it
8913 isn't indented.
8914 \stopmarkdown
8915 \stoptext
8916 ````````
8917 Next, invoke LuaTeX from the terminal:
8918 ``` sh
8919 context --luatex document.tex
8920 `````
8921 A PDF document named `document.pdf` should be produced and contain the
8922 following text:
8923
8924 > Here is a note reference,[^1] and another.[^longnote]
8925 >
8926 > Subsequent paragraphs are indented to show that they
8927 > belong to the previous note.
8928 >
8929 > { some.code }
8930 >
8931 > The whole paragraph can be indented, or just the
8932 > first line. In this way, multi-paragraph notes
8933 > work like multi-paragraph list items.
8934 >
8935 > This paragraph won't be part of the note, because it
8936 > isn't indented.
8937
8938 %</manual-options>
8939 %<*tex>
8940 % \fi
8941 % \begin{macrocode}
8942 \@@_add_lua_option:nnn
8943 { notes }
8944 { boolean }
8945 { false }
8946 % \end{macrocode}
8947 % \iffalse
8948 %</tex>
8949 %<*lua,lua-cli,lua-loader>
8950 % \fi
8951 % \begin{macrocode}
8952 defaultOptions.notes = false
8953 % \end{macrocode}
8954 % \iffalse
8955 %</lua,lua-cli,lua-loader>
8956 %<*manual-options>
8957
8958 #### Option `pipeTables` {#pipe-tables}
8959
8960 `pipeTables` (default value: `false`)
8961
8962 % \fi
8963 % \begin{markdown}
8964 %
8965 % \Optitem[false]{pipeTables}{\opt{true}, \opt{false}}
8966 %
8967 : true
8968
8969 : Enable the PHP Markdown pipe table syntax extension:
8970
8971 ``` md
8972 | Right | Left | Default | Center |
8973 |------:|:-----|---------|:------:|
8974 | 12 | 12 | 12 | 12 |
8975 | 123 | 123 | 123 | 123 |
8976 | 1 | 1 | 1 | 1 |
8977 ``````
8978
8979 : false
8980
8981 : Disable the PHP Markdown pipe table syntax extension.
8982
8983 % \end{markdown}
8984 % \iffalse
8985
8986 ##### \LaTeX{} Example {.unnumbered}
8987
8988 Using a text editor, create a text document named `document.tex` with the
8989 following content:
8990 ``` tex
8991 \documentclass{article}
8992 \usepackage[pipeTables]{markdown}
8993 \begin{document}
8994 \begin{markdown}
8995 | Right | Left | Default | Center |
8996 |------:|:-----|---------|:------:|
8997 | 12 | 12 | 12 | 12 |
8998 | 123 | 123 | 123 | 123 |
8999 | 1 | 1 | 1 | 1 |
9000 \end{markdown}
9001 \end{document}
9002 ```````
9003 Next, invoke LuaTeX from the terminal:
9004 ``` sh
9005 lualatex document.tex
9006 ``````
9007 A PDF document named `document.pdf` should be produced and contain the
9008 following text:
9009
9010 > | Right | Left | Default | Center |
9011 > |------:|:-----|---------|:------:|
9012 > | 12 | 12 | 12 | 12 |
9013 > | 123 | 123 | 123 | 123 |
9014 > | 1 | 1 | 1 | 1 |
9015
9016 ##### \Hologo{ConTeXt} Example {.unnumbered}
9017
9018 Using a text editor, create a text document named `document.tex` with the
9019 following content:
9020 ``` tex
9021 \usemodule[t][markdown]
9022 \setupmarkdown[pipeTables = yes]
9023 \starttext
9024 \startmarkdown
9025 | Right | Left | Default | Center |
9026 |------:|:-----|---------|:------:|
9027 | 12 | 12 | 12 | 12 |
9028 | 123 | 123 | 123 | 123 |
9029 | 1 | 1 | 1 | 1 |
9030 \stopmarkdown
9031 \stoptext
9032 ````````
9033 Next, invoke LuaTeX from the terminal:
9034 ``` sh
9035 context --luatex document.tex
9036 `````
9037 A PDF document named `document.pdf` should be produced and contain the
9038 following text:
9039
9040 > | Right | Left | Default | Center |
9041 > |------:|:-----|---------|:------:|
9042 > | 12 | 12 | 12 | 12 |
9043 > | 123 | 123 | 123 | 123 |
9044 > | 1 | 1 | 1 | 1 |
9045
9046 %</manual-options>
9047 %<*tex>
9048 % \fi
9049 % \begin{macrocode}
9050 \@@_add_lua_option:nnn
9051 { pipeTables }
9052 { boolean }
9053 { false }
9054 % \end{macrocode}
9055 % \iffalse
9056 %</tex>
9057 %<*lua,lua-cli,lua-loader>
9058 % \fi
9059 % \begin{macrocode}
9060 defaultOptions.pipeTables = false
9061 % \end{macrocode}
9062 % \iffalse
9063 %</lua,lua-cli,lua-loader>
9064 %<*manual-options>
9065
9066 #### Option `preserveTabs`
9067
9068 `preserveTabs` (default value: `true`)
9069
9070 % \fi
9071 % \begin{markdown}
9072 %
9073 % \Optitem[true]{preserveTabs}{\opt{true}, \opt{false}}
9074 %
9075 : true
9076
9077 : Preserve tabs in code block and fenced code blocks.
9078
9079 : false
9080
9081 : Convert any tabs in the input to spaces.
9082
9083 % \end{markdown}
9084 % \iffalse
9085 %</manual-options>
9086 %<*tex>
9087 % \fi
9088 % \begin{macrocode}
9089 \@@_add_lua_option:nnn
9090 { preserveTabs }
9091 { boolean }
9092 { true }
9093 % \end{macrocode}
9094 % \iffalse
9095 %</tex>
9096 %<*lua,lua-cli,lua-loader>
9097 % \fi
9098 % \begin{macrocode}
9099 defaultOptions.preserveTabs = true
9100 % \end{macrocode}
9101 % \iffalse
9102 %</lua,lua-cli,lua-loader>
9103 %<*manual-options>
9104
9105 #### Option `rawAttribute`
9106
9107 `rawAttribute` (default value: `false`)
9108
9109 % \fi
9110 % \begin{markdown}
9111 %
9112 % \Optitem[false]{rawAttribute}{\opt{true}, \opt{false}}
9113 %
9114 : true
9115
9116 : Enable the Pandoc [raw attribute syntax
9117 extension][pandoc-raw-attribute]:
9118
9119 ``` md
9120 `$H_2 O$`{=tex} is a liquid.
9121 ```
9122
9123 To enable raw blocks, the \Opt{fencedCode} option must also
9124 be enabled:
9125
9126 ~~~~~~~~ md
9127 Here is a mathematical formula:
9128 ``` {=tex}
9129 \[distance[i] =
9130 \begin{dcases}
9131 a & b \\
9132 c & d
9133 \end{dcases}
9134 \]
9135 ```
9136 ~~~~~~~~~~~
9137
9138 The \Opt{rawAttribute} option is a good alternative to the \Opt{hybrid}
9139 option. Unlike the \Opt{hybrid} option, which affects the entire
9140 document, the \Opt{rawAttribute} option allows you to isolate the parts
9141 of your documents that use \TeX.
9142
9143 : false
9144
9145 : Disable the Pandoc raw attribute syntax extension.
9146
9147 [pandoc-raw-attribute]: https://pandoc.org/MANUAL.html#extension-raw_attribute
9148
9149 % \end{markdown}
9150 % \iffalse
9151
9152 ##### \LaTeX{} Example {.unnumbered}
9153
9154 Using a text editor, create a text document named `document.tex` with the
9155 following content:
9156 ```` tex
9157 \documentclass{article}
9158 \usepackage[rawAttribute, fencedCode]{markdown}
9159 \usepackage{expl3}
9160 \begin{document}
9161 \begin{markdown}
9162 `$H_2 O$`{=tex} is a liquid.
9163
9164 ``` {=html}
9165 <p>Here is some HTML content that will be ignored.</p>
9166 ```
9167 \end{markdown}
9168 \end{document}
9169 ````````
9170 Next, invoke LuaTeX from the terminal:
9171 ``` sh
9172 lualatex document.tex
9173 ``````
9174 A PDF document named `document.pdf` should be produced and contain the
9175 following text:
9176
9177 > H~2~O is a liquid.
9178
9179 %</manual-options>
9180 %<*tex>
9181 % \fi
9182 % \begin{macrocode}
9183 \@@_add_lua_option:nnn
9184 { rawAttribute }
9185 { boolean }
9186 { false }
9187 % \end{macrocode}
9188 % \iffalse
9189 %</tex>
9190 %<*lua,lua-cli,lua-loader>
9191 % \fi
9192 % \begin{macrocode}
9193 defaultOptions.rawAttribute = false
9194 % \end{macrocode}
9195 % \iffalse
9196 %</lua,lua-cli,lua-loader>
9197 %<*manual-options>
9198
9199 #### Option `relativeReferences`
9200
9201 `relativeReferences` (default value: `false`)
9202
9203 % \fi
9204 % \begin{markdown}
9205 %
9206 % \Optitem[false]{relativeReferences}{\opt{true}, \opt{false}}
9207 %
9208 : true
9209
9210 : Enable [relative references][rfc3986] in autolinks:
9211
9212 ``` md
9213 I conclude in Section <#conclusion>.
9214
9215 Conclusion {#conclusion}
9216 ==========
9217 In this paper, we have discovered that most
9218 grandmas would rather eat dinner with their
9219 grandchildren than get eaten. Begone, wolf!
9220 ```
9221
9222 : false
9223
9224 : Disable relative references in autolinks.
9225
9226 [rfc3986]: https://datatracker.ietf.org/doc/html/rfc3986#section-4.2
9227
9228 % \end{markdown}
9229 % \iffalse
9230
9231 ##### \LaTeX{} Example {.unnumbered}
9232
9233 Using a text editor, create a text document named `document.tex` with the
9234 following content:
9235 ``` tex
9236 \documentclass{article}
9237 \usepackage[headerAttributes, relativeReferences]{markdown}
9238 \begin{document}
9239 \begin{markdown}
9240
9241 I conclude in Section <#conclusion>.
9242
9243 Conclusion {#conclusion}
9244 ==========
9245 In this paper, we have discovered that most
9246 grandmas would rather eat dinner with their
9247 grandchildren than get eaten. Begone, wolf!
9248
9249 \end{markdown}
9250 \end{document}
9251 ```````
9252 Next, invoke LuaTeX twice from the terminal:
9253 ``` sh
9254 lualatex document.tex
9255 lualatex document.tex
9256 ``````
9257 A PDF document named `document.pdf` should be produced and contain the
9258 following text:
9259
9260 > I conclude in Section 1.
9261 >
9262 > # 1. Conclusion
9263 >
9264 > In this paper, we have discovered that most grandmas would rather eat dinner
9265 > with their grandchildren than get eaten. Begone, wolf!
9266
9267 %</manual-options>
9268 %<*tex>
9269 % \fi
9270 % \begin{macrocode}
9271 \@@_add_lua_option:nnn
9272 { relativeReferences }
9273 { boolean }
9274 { false }
9275 % \end{macrocode}
9276 % \iffalse
9277 %</tex>
9278 %<*lua,lua-cli,lua-loader>
9279 % \fi
9280 % \begin{macrocode}
9281 defaultOptions.relativeReferences = false
9282 % \end{macrocode}
9283 % \iffalse
9284 %</lua,lua-cli,lua-loader>
9285 %<*manual-options>
9286
9287 #### Option `shiftHeadings`
9288
9289 `shiftHeadings` (default value: `0`)
9290
9291 % \fi
9292 % \begin{markdown}
9293 %
9294 % \Valitem[0]{shiftHeadings}{shift amount}
9295 %
9296 : All headings will be shifted by \meta{shift amount}, which can be both
9297 positive and negative. Headings will not be shifted beyond level 6 or
9298 below level 1.
9299
9300 % \end{markdown}
9301 % \iffalse
9302
9303 ##### Plain \TeX{} Example {.unnumbered}
9304
9305 Using a text editor, create a text document named `example.md` with the
9306 following content:
9307
9308 ``` md
9309 ## A section
9310 ```
9311
9312 Using a text editor, create a text document named `document.tex` with the
9313 following content:
9314 ``` tex
9315 \input markdown
9316
9317 \font\normal=cmr10\normal
9318 \font\big=cmr10 at 12pt
9319 \def\markdownRendererHeadingTwo#1{{\big #1\par}}
9320 \font\bigger=cmr10 scaled 1440
9321 \def\markdownRendererHeadingOne#1{{\bigger #1\par}}
9322
9323 \def\markdownOptionShiftHeadings{-1}
9324 \markdownInput{example.md}
9325
9326 \def\markdownOptionShiftHeadings{0}
9327 \markdownInput{example.md}
9328
9329 \def\markdownOptionShiftHeadings{+1}
9330 \markdownInput{example.md}
9331
9332 \bye
9333 ```````
9334 Next, invoke LuaTeX from the terminal:
9335 ``` sh
9336 luatex document.tex
9337 ``````
9338 A PDF document named `document.pdf` should be produced and contain the
9339 following text:
9340
9341 > # A section
9342 > ## A section
9343 > ### A section
9344
9345 ##### \LaTeX{} Example {.unnumbered}
9346
9347 Using a text editor, create a text document named `document.tex` with the
9348 following content:
9349 ``` tex
9350 \documentclass{article}
9351 \usepackage{markdown}
9352 \begin{filecontents}[overwrite,nosearch,noheader]{example.md}
9353 ## A section
9354 \end{filecontents}
9355 \begin{document}
9356 \markdownInput[shiftHeadings=-1]{example.md}
9357 \markdownInput{example.md}
9358 \markdownInput[shiftHeadings=+1]{example.md}
9359 \end{document}
9360 ```````
9361 Next, invoke LuaTeX from the terminal:
9362 ``` sh
9363 lualatex document.tex
9364 ``````
9365 A PDF document named `document.pdf` should be produced and contain the
9366 following text:
9367
9368 > # A section
9369 > ## A section
9370 > ### A section
9371
9372 ##### \Hologo{ConTeXt} Example {.unnumbered}
9373
9374 Using a text editor, create a text document named `example.md` with the
9375 following content:
9376
9377 ``` md
9378 ## A section
9379 ```
9380
9381 Using a text editor, create a text document named `document.tex` with the
9382 following content:
9383 ``` tex
9384 \usemodule[t][markdown]
9385 \starttext
9386
9387 \inputmarkdown[shiftHeadings = -1]{example.md}
9388 \inputmarkdown[shiftHeadings = 0]{example.md}
9389 \inputmarkdown[shiftHeadings = +1]{example.md}
9390
9391 \stoptext
9392 ````````
9393 Next, invoke LuaTeX from the terminal:
9394 ``` sh
9395 context --luatex document.tex
9396 `````
9397 A PDF document named `document.pdf` should be produced and contain the
9398 following text:
9399
9400 > # A section
9401 > ## A section
9402 > ### A section
9403
9404 %</manual-options>
9405 %<*tex>
9406 % \fi
9407 % \begin{macrocode}
9408 \@@_add_lua_option:nnn
9409 { shiftHeadings }
9410 { number }
9411 { 0 }
9412 % \end{macrocode}
9413 % \iffalse
9414 %</tex>
9415 %<*lua,lua-cli,lua-loader>
9416 % \fi
9417 % \begin{macrocode}
9418 defaultOptions.shiftHeadings = 0
9419 % \end{macrocode}
9420 % \iffalse
9421 %</lua,lua-cli,lua-loader>
9422 %<*manual-options>
9423
9424 #### Option `slice`
9425
9426 `slice` (default value: `^ $`)
9427
9428 % \fi
9429 % \begin{markdown}
9430 %
9431 % \Valitem[\textasciicircum{} \\$]{slice}{the beginning and the end of a slice}
9432 %
9433 : Two space-separated selectors that specify the slice of a document that
9434 will be processed, whereas the remainder of the document will be ignored.
9435 The following selectors are recognized:
9436
9437 - The circumflex (`^`) selects the beginning of a document.
9438 - The dollar sign (`$`) selects the end of a document.
9439 - `^`\meta{identifier} selects the beginning of
9440 % a section (see the \Opt{headerAttributes} option)
9441 % \iffalse
9442 a [section](#header-attributes)
9443 % \fi
9444 % or a fenced div (see the \Opt{fencedDivs} option) with the HTML
9445 % attribute `#`\meta{identifier}.
9446 % \iffalse
9447 or a [fenced div](#fenced-divs)
9448 with the HTML attribute `#`\meta{identifier}.
9449 % \fi
9450 - `$`\meta{identifier} selects the end of a section with the HTML
9451 attribute `#`\meta{identifier}.
9452 - \meta{identifier} corresponds to `^`\meta{identifier} for the first
9453 selector and to `$`\meta{identifier} for the second selector.
9454
9455 Specifying only a single selector, \meta{identifier}, is equivalent
9456 to specifying the two selectors \meta{identifier} \meta{identifier},
9457 which is equivalent to `^`\meta{identifier} `$`\meta{identifier}, i.e.
9458 the entire section with the HTML attribute `#`\meta{identifier} will be
9459 selected.
9460
9461 % \end{markdown}
9462 % \iffalse
9463
9464 ##### Plain \TeX{} Example {.unnumbered}
9465
9466 Using a text editor, create a text document named `hamlet.md` with the
9467 following content:
9468
9469 ``` md
9470 # The Tragedy of Hamlet
9471 Shakespeare's longest play.
9472
9473 ## Act III {#act-3}
9474 Hamlet kills Polonius.
9475
9476 ## Act V {#act-5}
9477 Hamlet dies.
9478
9479 ## Act I {#act-1}
9480 Hamlet talks to ghost.
9481 ```
9482
9483 Using a text editor, create a text document named `document.tex` with the
9484 following content:
9485 ``` tex
9486 \input markdown
9487 \def\markdownOptionHeaderAttributes{true}
9488
9489 \font\normal=cmr10\normal
9490 \font\big=cmr10 at 12pt
9491 \def\markdownRendererHeadingTwo#1{{\big #1\par}}
9492 \font\bigger=cmr10 scaled 1440
9493 \def\markdownRendererHeadingOne#1{{\bigger #1\par}}
9494
9495 \def\markdownOptionSlice{^ ^act-3}
9496 \markdownInput{hamlet.md}
9497
9498 \def\markdownOptionSlice{act-1}
9499 \markdownInput{hamlet.md}
9500
9501 \def\markdownOptionSlice{act-3 act-5}
9502 \markdownInput{hamlet.md}
9503
9504 \bye
9505 ```````
9506 Next, invoke LuaTeX from the terminal:
9507 ``` sh
9508 luatex document.tex
9509 ``````
9510 A PDF document named `document.pdf` should be produced and contain the
9511 following text:
9512
9513 > # The Tragedy of Hamlet
9514 > Shakespeare's longest play.
9515 >
9516 > ## Act I
9517 > Hamlet talks to ghost.
9518 >
9519 > ## Act III
9520 > Hamlet kills Polonius.
9521 >
9522 > ## Act V
9523 > Hamlet dies.
9524
9525 ##### \LaTeX{} Example {.unnumbered}
9526
9527 Using a text editor, create a text document named `document.tex` with the
9528 following content:
9529 ``` tex
9530 \documentclass{article}
9531 \usepackage[headerAttributes]{markdown}
9532 \begin{filecontents}[overwrite,nosearch,noheader]{hamlet.md}
9533 # The Tragedy of Hamlet
9534 Shakespeare's longest play.
9535
9536 ## Act III {#act-3}
9537 Hamlet kills Polonius.
9538
9539 ## Act V {#act-5}
9540 Hamlet dies.
9541
9542 ## Act I {#act-1}
9543 Hamlet talks to ghost.
9544 \end{filecontents}
9545 \begin{document}
9546 \markdownInput[slice=^ ^act-3]{hamlet.md}
9547 \markdownInput[slice=act-1]{hamlet.md}
9548 \markdownInput[slice=act-3 act-5]{hamlet.md}
9549 \end{document}
9550 ```````
9551 Next, invoke LuaTeX from the terminal:
9552 ``` sh
9553 lualatex document.tex
9554 ``````
9555 A PDF document named `document.pdf` should be produced and contain the
9556 following text:
9557
9558 > # The Tragedy of Hamlet
9559 > Shakespeare's longest play.
9560 >
9561 > ## Act I
9562 > Hamlet talks to ghost.
9563 >
9564 > ## Act III
9565 > Hamlet kills Polonius.
9566 >
9567 > ## Act V
9568 > Hamlet dies.
9569
9570 ##### \Hologo{ConTeXt} Example {.unnumbered}
9571
9572 Using a text editor, create a text document named `hamlet.md` with the
9573 following content:
9574
9575 ``` md
9576 # The Tragedy of Hamlet
9577 Shakespeare's longest play.
9578
9579 ## Act III {#act-3}
9580 Hamlet kills Polonius.
9581
9582 ## Act V {#act-5}
9583 Hamlet dies.
9584
9585 ## Act I {#act-1}
9586 Hamlet talks to ghost.
9587 ```
9588
9589 Using a text editor, create a text document named `document.tex` with the
9590 following content:
9591 ``` tex
9592 \usemodule[t][markdown]
9593 \setupmarkdown[headerAttributes = yes]
9594 \starttext
9595
9596 \inputmarkdown[slice = ^ ^act-3]{example.md}
9597 \inputmarkdown[slice = act-1]{example.md}
9598 \inputmarkdown[slice = act-3 act-5]{example.md}
9599
9600 \stoptext
9601 ````````
9602 Next, invoke LuaTeX from the terminal:
9603 ``` sh
9604 context --luatex document.tex
9605 `````
9606 A PDF document named `document.pdf` should be produced and contain the
9607 following text:
9608
9609 > # The Tragedy of Hamlet
9610 > Shakespeare's longest play.
9611 >
9612 > ## Act I
9613 > Hamlet talks to ghost.
9614 >
9615 > ## Act III
9616 > Hamlet kills Polonius.
9617 >
9618 > ## Act V
9619 > Hamlet dies.
9620
9621 %</manual-options>
9622 %<*tex>
9623 % \fi
9624 % \begin{macrocode}
9625 \@@_add_lua_option:nnn
9626 { slice }
9627 { slice }
9628 { ^~$ }
9629 % \end{macrocode}
9630 % \iffalse
9631 %</tex>
9632 %<*lua,lua-cli,lua-loader>
9633 % \fi
9634 % \begin{macrocode}
9635 defaultOptions.slice = "^ $"
9636 % \end{macrocode}
9637 % \iffalse
9638 %</lua,lua-cli,lua-loader>
9639 %<*manual-options>
9640
9641 #### Option `smartEllipses`
9642
9643 `smartEllipses` (default value: `false`)
9644
9645 % \fi
9646 % \begin{markdown}
9647 %
9648 % \Optitem[false]{smartEllipses}{\opt{true}, \opt{false}}
9649 %
9650 : true
9651
9652 : Convert any ellipses in the input to the
9653 \mref{markdownRendererEllipsis} \TeX{} macro.
9654
9655 : false
9656
9657 : Preserve all ellipses in the input.
9658
9659 % \end{markdown}
9660 % \iffalse
9661
9662 ##### Lua Module Example {.unnumbered}
9663
9664 Using a text editor, create a text document named `document.tex` with the
9665 following content:
9666 ``` tex
9667 \input markdown
9668 \input lmfonts
9669 \def\markdownRendererEllipsis{. . .}
9670 \begingroup
9671 \catcode`\%=12
9672 \catcode`\#=12
9673 \directlua{
9674 local markdown = require("markdown")
9675 local convert = markdown.new()
9676 local input = "These are just three regular dots ..."
9677 tex.sprint(convert(input)) }
9678 \par
9679 \directlua{
9680 local markdown = require("markdown")
9681 local convert = markdown.new({smartEllipses = true})
9682 local input = "... and this is a victorian ellipsis."
9683 tex.sprint(convert(input)) }
9684 \endgroup
9685 \bye
9686 ```````
9687 Then, invoke LuaTeX from the terminal:
9688 ``` sh
9689 luatex document.tex
9690 ```````
9691 A PDF document named `document.pdf` should be produced and contain the
9692 following text:
9693
9694 > These are just three regular dots ...
9695 >
9696 > . . . and this is a victorian ellipsis.
9697
9698 ##### Lua CLI Example {.unnumbered}
9699
9700 Using a text editor, create a text document named `document.tex` with the
9701 following content:
9702 ``` tex
9703 \input markdown
9704 \input lmfonts
9705 \def\markdownRendererEllipsis{. . .}
9706 \begingroup
9707 \catcode`\%=12
9708 \catcode`\#=12
9709 \input optionfalse
9710 \par
9711 \input optiontrue
9712 \endgroup
9713 \bye
9714 ```````
9715 Using a text editor, create a text document named `content.md` with the
9716 following content:
9717 ``` md
9718 Are these just three regular dots, a victorian ellipsis, or ... ?
9719 ``````
9720 Next, invoke LuaTeX from the terminal:
9721 ``` sh
9722 markdown2tex -- content.md optionfalse.tex
9723 markdown2tex smartEllipses=true -- content.md optiontrue.tex
9724 luatex document.tex
9725 ```````
9726
9727 A PDF document named `document.pdf` should be produced and contain the
9728 following text:
9729
9730 > Are these just three regular dots, a victorian ellipsis, or ... ?
9731 >
9732 > Are these just three regular dots, a victorian ellipsis, or . . . ?
9733
9734 ##### Plain \TeX{} Example {.unnumbered}
9735
9736 Using a text editor, create a text document named `document.tex` with the
9737 following content:
9738 ``` tex
9739 \input markdown
9740 \def\markdownRendererEllipsis{. . .}
9741
9742 \markdownBegin
9743 These are just three regular dots ...
9744 \markdownEnd
9745
9746 \def\markdownOptionSmartEllipses{true}
9747 \markdownBegin
9748 ... and this is a victorian ellipsis.
9749 \markdownEnd
9750
9751 \bye
9752 ```````
9753 Next, invoke LuaTeX from the terminal:
9754 ``` sh
9755 luatex document.tex
9756 ``````
9757 A PDF document named `document.pdf` should be produced and contain the
9758 following text:
9759
9760 > These are just three regular dots ...
9761 >
9762 > . . . and this is a victorian ellipsis.
9763
9764 ##### \LaTeX{} Example {.unnumbered}
9765
9766 Using a text editor, create a text document named `document.tex` with the
9767 following content:
9768 ``` tex
9769 \documentclass{article}
9770 \usepackage{markdown}
9771 \markdownSetup{
9772 renderers = {
9773 ellipsis = {. . .}
9774 }
9775 }
9776 \begin{document}
9777
9778 \begin{markdown}
9779 These are just three regular dots ...
9780 \end{markdown}
9781
9782 \begin{markdown}[smartEllipses]
9783 ... and this is a victorian ellipsis.
9784 \end{markdown}
9785
9786 \end{document}
9787 ```````
9788 Next, invoke LuaTeX from the terminal:
9789 ``` sh
9790 lualatex document.tex
9791 ``````
9792 A PDF document named `document.pdf` should be produced and contain the
9793 following text:
9794
9795 > These are just three regular dots ...
9796 >
9797 > . . . and this is a victorian ellipsis.
9798
9799 ##### \Hologo{ConTeXt} Example {.unnumbered}
9800
9801 Using a text editor, create a text document named `document.tex` with the
9802 following content:
9803 ``` tex
9804 \usemodule[t][markdown]
9805 \def\markdownRendererEllipsis{. . .}
9806 \starttext
9807
9808 \startmarkdown
9809 These are just three regular dots ...
9810 \stopmarkdown
9811
9812 \setupmarkdown[smartEllipses = yes]
9813 \startmarkdown
9814 ... and this is a victorian ellipsis.
9815 \stopmarkdown
9816
9817 \stoptext
9818 ````````
9819 Next, invoke LuaTeX from the terminal:
9820 ``` sh
9821 context --luatex document.tex
9822 `````
9823 A PDF document named `document.pdf` should be produced and contain the
9824 following text:
9825
9826 > These are just three regular dots ...
9827 >
9828 > . . . and this is a victorian ellipsis.
9829
9830 %</manual-options>
9831 %<*tex>
9832 % \fi
9833 % \begin{macrocode}
9834 \@@_add_lua_option:nnn
9835 { smartEllipses }
9836 { boolean }
9837 { false }
9838 % \end{macrocode}
9839 % \iffalse
9840 %</tex>
9841 %<*lua,lua-cli,lua-loader>
9842 % \fi
9843 % \begin{macrocode}
9844 defaultOptions.smartEllipses = false
9845 % \end{macrocode}
9846 % \iffalse
9847 %</lua,lua-cli,lua-loader>
9848 %<*manual-options>
9849
9850 #### Option `startNumber`
9851
9852 `startNumber` (default value: `true`)
9853
9854 % \fi
9855 % \begin{markdown}
9856 %
9857 % \Optitem[true]{startNumber}{\opt{true}, \opt{false}}
9858 %
9859 : true
9860
9861 : Make the number in the first item of an ordered lists significant. The
9862 item numbers will be passed to the
9863 \mref{markdownRendererOlItemWithNumber} \TeX{} macro.
9864
9865 : false
9866
9867 : Ignore the numbers in the ordered list items. Each item will only
9868 produce a \mref{markdownRendererOlItem} \TeX{} macro.
9869
9870 % \end{markdown}
9871 % \iffalse
9872
9873 ##### \LaTeX{} Example {.unnumbered}
9874
9875 Using a text editor, create a text document named `document.tex` with the
9876 following content:
9877 ``` tex
9878 \documentclass{article}
9879 \usepackage{markdown}
9880 \begin{document}
9881
9882 \begin{markdown}
9883 The following list respects the numbers specified in the markup:
9884
9885 3. third item
9886 4. fourth item
9887 5. fifth item
9888 \end{markdown}
9889
9890 \begin{markdown}[startNumber=false]
9891 The following list does not respect the numbers specified in the
9892 markup:
9893
9894 3. third item
9895 4. fourth item
9896 5. fifth item
9897 \end{markdown}
9898
9899 \end{document}
9900 ```````
9901 Next, invoke LuaTeX from the terminal:
9902 ``` sh
9903 lualatex document.tex
9904 ``````
9905 A PDF document named `document.pdf` should be produced and contain the
9906 following text:
9907
9908 > The following list respects the numbers specified in the markup:
9909 >
9910 > 3. third item
9911 > 4. fourth item
9912 > 5. fifth item
9913 >
9914 > The following list does not respect the numbers specified in the markup:
9915 >
9916 > 1. third item
9917 > 2. fourth item
9918 > 3. fifth item
9919
9920 ##### \Hologo{ConTeXt} Example {.unnumbered}
9921
9922 Using a text editor, create a text document named `document.tex` with the
9923 following content:
9924 ``` tex
9925 \usemodule[t][markdown]
9926 \starttext
9927
9928 \startmarkdown
9929 The following list respects the numbers specified in the markup:
9930
9931 3. third item
9932 4. fourth item
9933 5. fifth item
9934 \stopmarkdown
9935
9936 \setupmarkdown[startNumber = no]
9937 \startmarkdown
9938 The following list respects the numbers specified in the markup:
9939
9940 3. third item
9941 4. fourth item
9942 5. fifth item
9943 \stopmarkdown
9944 \stoptext
9945 ````````
9946 Next, invoke LuaTeX from the terminal:
9947 ``` sh
9948 context --luatex document.tex
9949 `````
9950 A PDF document named `document.pdf` should be produced and contain the
9951 following text:
9952
9953 > The following list respects the numbers specified in the markup:
9954 >
9955 > 3. third item
9956 > 4. fourth item
9957 > 5. fifth item
9958 >
9959 > The following list does not respect the numbers specified in the markup:
9960 >
9961 > 1. third item
9962 > 2. fourth item
9963 > 3. fifth item
9964
9965 %</manual-options>
9966 %<*tex>
9967 % \fi
9968 % \begin{macrocode}
9969 \@@_add_lua_option:nnn
9970 { startNumber }
9971 { boolean }
9972 { true }
9973 % \end{macrocode}
9974 % \iffalse
9975 %</tex>
9976 %<*lua,lua-cli,lua-loader>
9977 % \fi
9978 % \begin{macrocode}
9979 defaultOptions.startNumber = true
9980 % \end{macrocode}
9981 % \iffalse
9982 %</lua,lua-cli,lua-loader>
9983 %<*manual-options>
9984
9985 #### Option `strikeThrough`
9986
9987 `strikeThrough` (default value: `false`)
9988
9989 % \fi
9990 % \begin{markdown}
9991 %
9992 % \Optitem[false]{strikeThrough}{\opt{true}, \opt{false}}
9993 %
9994 : true
9995
9996 : Enable the Pandoc [strike-through syntax
9997 extension][pandoc-strikeout]:
9998
9999 ``` md
10000 This ~~is deleted text.~~
10001 ``````
10002
10003 : false
10004
10005 : Disable the Pandoc strike-through syntax extension.
10006
10007 [pandoc-strikeout]: https://pandoc.org/MANUAL.html#extension-strikeout
10008
10009 % \end{markdown}
10010 % \iffalse
10011
10012 ##### Plain \TeX{} Example {.unnumbered}
10013
10014 Using a text editor, create a text document named `document.tex` with the
10015 following content:
10016 ``` tex
10017 \input markdown
10018 \def\markdownOptionStrikeThrough{true}
10019 \input soul.sty
10020 \def\markdownRendererStrikeThrough#1{\st{#1}}
10021 \markdownBegin
10022 This is ~~a lunar roving vehicle~~ strike-through text.
10023 \markdownEnd
10024 \bye
10025 ```````
10026 Next, invoke LuaTeX from the terminal:
10027 ``` sh
10028 luatex document.tex
10029 ``````
10030 A PDF document named `document.pdf` should be produced and contain the
10031 following text:
10032
10033 > This is ~~a lunar roving vehicle~~ strike-through text.
10034
10035 ##### \LaTeX{} Example {.unnumbered}
10036
10037 Using a text editor, create a text document named `document.tex` with the
10038 following content:
10039 ``` tex
10040 \documentclass{article}
10041 \usepackage[strikeThrough]{markdown}
10042 \usepackage{soul}
10043 \markdownSetup{
10044 renderers = {
10045 strikeThrough = {\st{#1}},
10046 },
10047 }
10048 \begin{document}
10049 \begin{markdown}
10050 This is ~~a lunar roving vehicle~~ strike-through text.
10051 \end{markdown}
10052 \end{document}
10053 ```````
10054 Next, invoke LuaTeX from the terminal:
10055 ``` sh
10056 lualatex document.tex
10057 ``````
10058 A PDF document named `document.pdf` should be produced and contain the
10059 following text:
10060
10061 > This is ~~a lunar roving vehicle~~ strike-through text.
10062
10063 ##### \Hologo{ConTeXt} Example {.unnumbered}
10064
10065 Using a text editor, create a text document named `document.tex` with the
10066 following content:
10067 ``` tex
10068 \usemodule[t][markdown]
10069 \setupmarkdown[strikeThrough = yes]
10070 \def\markdownRendererStrikeThrough#1{\overstrikes{#1}}
10071 \starttext
10072 \startmarkdown
10073 This is ~~a lunar roving vehicle~~ strike-through text.
10074 \stopmarkdown
10075 \stoptext
10076 ```````
10077 Next, invoke LuaTeX from the terminal:
10078 ``` sh
10079 context --luatex document.tex
10080 ``````
10081 A PDF document named `document.pdf` should be produced and contain the
10082 following text:
10083
10084 > This is ~~a lunar roving vehicle~~ strike-through text.
10085
10086 %</manual-options>
10087 %<*tex>
10088 % \fi
10089 % \begin{macrocode}
10090 \@@_add_lua_option:nnn
10091 { strikeThrough }
10092 { boolean }
10093 { false }
10094 % \end{macrocode}
10095 % \iffalse
10096 %</tex>
10097 %<*lua,lua-cli,lua-loader>
10098 % \fi
10099 % \begin{macrocode}
10100 defaultOptions.strikeThrough = false
10101 % \end{macrocode}
10102 % \iffalse
10103 %</lua,lua-cli,lua-loader>
10104 %<*manual-options>
10105
10106 #### Option `stripIndent`
10107
10108 `stripIndent` (default value: `false`)
10109
10110 % \fi
10111 % \markdownBegin
10112 %
10113 % \Optitem[false]{stripIndent}{\opt{true}, \opt{false}}
10114 %
10115 : true
10116
10117 : Strip the minimal indentation of non-blank lines from all
10118 lines in a markdown document. Requires that the
10119 \Opt{preserveTabs} Lua option is disabled:
10120
10121 ``` tex
10122 \documentclass{article}
10123 \usepackage[stripIndent]{markdown}
10124 \begin{document}
10125 \begin{markdown}
10126 Hello *world*!
10127 \end{markdown}
10128 \end{document}
10129 ```````
10130
10131 : false
10132
10133 : Do not strip any indentation from the lines in a markdown
10134 document.
10135
10136 % \markdownEnd
10137 % \iffalse
10138
10139 ##### Plain \TeX{} Example {.unnumbered}
10140
10141 Using a text editor, create a text document named `document.tex` with the
10142 following content:
10143 ``` tex
10144 \input markdown
10145 \def\markdownOptionStripIndent{true}
10146 \markdownBegin
10147 Hello *world*!
10148 \markdownEnd
10149 \bye
10150 ```````
10151 Next, invoke LuaTeX from the terminal:
10152 ``` sh
10153 luatex document.tex
10154 ``````
10155 A PDF document named `document.pdf` should be produced and contain the text
10156 “Hello *world*!”
10157
10158 ##### \LaTeX{} Example {.unnumbered}
10159
10160 Using a text editor, create a text document named `document.tex` with the
10161 following content:
10162 ``` tex
10163 \documentclass{article}
10164 \usepackage[stripIndent]{markdown}
10165 \begin{document}
10166 \begin{markdown}
10167 Hello *world*!
10168 \end{markdown}
10169 \end{document}
10170 ```````
10171 Next, invoke LuaTeX from the terminal:
10172 ``` sh
10173 lualatex document.tex
10174 ``````
10175 A PDF document named `document.pdf` should be produced and contain the
10176 text “Hello *world*!”
10177
10178 ##### \Hologo{ConTeXt} Example {.unnumbered}
10179
10180 Using a text editor, create a text document named `document.tex` with the
10181 following content:
10182 ``` tex
10183 \usemodule[t][markdown]
10184 \setupmarkdown[stripIndent = yes]
10185 \starttext
10186 \startmarkdown
10187 Hello *world*!
10188 \stopmarkdown
10189 \stoptext
10190 ````````
10191 Next, invoke LuaTeX from the terminal:
10192 ``` sh
10193 context --luatex document.tex
10194 `````
10195 A PDF document named `document.pdf` should be produced and contain the
10196 text “Hello *world*!”
10197
10198 %</manual-options>
10199 %<*tex>
10200 % \fi
10201 % \begin{macrocode}
10202 \@@_add_lua_option:nnn
10203 { stripIndent }
10204 { boolean }
10205 { false }
10206 % \end{macrocode}
10207 % \iffalse
10208 %</tex>
10209 %<*lua,lua-cli,lua-loader>
10210 % \fi
10211 % \begin{macrocode}
10212 defaultOptions.stripIndent = false
10213 % \end{macrocode}
10214 % \iffalse
10215 %</lua,lua-cli,lua-loader>
10216 %<*manual-options>
10217
10218 #### Option `subscripts`
10219
10220 `subscripts` (default value: `false`)
10221
10222 % \fi
10223 % \begin{markdown}
10224 %
10225 % \Optitem[false]{subscripts}{\opt{true}, \opt{false}}
10226 %
10227 : true
10228
10229 : Enable the Pandoc [subscript syntax
10230 extension][pandoc-subscript]:
10231
10232 ``` md
10233 H~2~O is a liquid.
10234 ``````
10235
10236 : false
10237
10238 : Disable the Pandoc subscript syntax extension.
10239
10240 [pandoc-subscript]: https://pandoc.org/MANUAL.html#extension-superscript-subscript
10241
10242 % \end{markdown}
10243 % \iffalse
10244
10245 ##### \LaTeX{} Example {.unnumbered}
10246
10247 Using a text editor, create a text document named `document.tex` with the
10248 following content:
10249 ``` tex
10250 \documentclass{article}
10251 \usepackage[subscripts]{markdown}
10252 \begin{document}
10253 \begin{markdown}
10254 H~2~O is a liquid.
10255 \end{markdown}
10256 \end{document}
10257 ```````
10258 Next, invoke LuaTeX from the terminal:
10259 ``` sh
10260 lualatex document.tex
10261 ``````
10262 A PDF document named `document.pdf` should be produced and contain the
10263 following text:
10264
10265 > H~2~O is a liquid.
10266
10267 ##### \Hologo{ConTeXt} Example {.unnumbered}
10268
10269 Using a text editor, create a text document named `document.tex` with the
10270 following content:
10271 ``` tex
10272 \usemodule[t][markdown]
10273 \setupmarkdown[subscripts = yes]
10274 \starttext
10275 \startmarkdown
10276 H~2~O is a liquid.
10277 \stopmarkdown
10278 \stoptext
10279 ```````
10280 Next, invoke LuaTeX from the terminal:
10281 ``` sh
10282 context --luatex document.tex
10283 ``````
10284 A PDF document named `document.pdf` should be produced and contain the
10285 following text:
10286
10287 > H~2~O is a liquid.
10288
10289 %</manual-options>
10290 %<*tex>
10291 % \fi
10292 % \begin{macrocode}
10293 \@@_add_lua_option:nnn
10294 { subscripts }
10295 { boolean }
10296 { false }
10297 % \end{macrocode}
10298 % \iffalse
10299 %</tex>
10300 %<*lua,lua-cli,lua-loader>
10301 % \fi
10302 % \begin{macrocode}
10303 defaultOptions.subscripts = false
10304 % \end{macrocode}
10305 % \iffalse
10306 %</lua,lua-cli,lua-loader>
10307 %<*manual-options>
10308
10309 #### Option `superscripts`
10310
10311 `superscripts` (default value: `false`)
10312
10313 % \fi
10314 % \begin{markdown}
10315 %
10316 % \Optitem[false]{superscripts}{\opt{true}, \opt{false}}
10317 %
10318 : true
10319
10320 : Enable the Pandoc [superscript syntax
10321 extension][pandoc-superscript]:
10322
10323 ``` md
10324 2^10^ is 1024.
10325 ``````
10326
10327 : false
10328
10329 : Disable the Pandoc superscript syntax extension.
10330
10331 [pandoc-superscript]: https://pandoc.org/MANUAL.html#extension-superscript-subscript
10332
10333 % \end{markdown}
10334 % \iffalse
10335
10336 ##### \LaTeX{} Example {.unnumbered}
10337
10338 Using a text editor, create a text document named `document.tex` with the
10339 following content:
10340 ``` tex
10341 \documentclass{article}
10342 \usepackage[superscripts]{markdown}
10343 \begin{document}
10344 \begin{markdown}
10345 2^10^ is 1024.
10346 \end{markdown}
10347 \end{document}
10348 ```````
10349 Next, invoke LuaTeX from the terminal:
10350 ``` sh
10351 lualatex document.tex
10352 ``````
10353 A PDF document named `document.pdf` should be produced and contain the
10354 following text:
10355
10356 > 2^10^ is 1024.
10357
10358 ##### \Hologo{ConTeXt} Example {.unnumbered}
10359
10360 Using a text editor, create a text document named `document.tex` with the
10361 following content:
10362 ``` tex
10363 \usemodule[t][markdown]
10364 \setupmarkdown[superscripts = yes]
10365 \starttext
10366 \startmarkdown
10367 2^10^ is 1024.
10368 \stopmarkdown
10369 \stoptext
10370 ```````
10371 Next, invoke LuaTeX from the terminal:
10372 ``` sh
10373 context --luatex document.tex
10374 ``````
10375 A PDF document named `document.pdf` should be produced and contain the
10376 following text:
10377
10378 > 2^10^ is 1024.
10379
10380 %</manual-options>
10381 %<*tex>
10382 % \fi
10383 % \begin{macrocode}
10384 \@@_add_lua_option:nnn
10385 { superscripts }
10386 { boolean }
10387 { false }
10388 % \end{macrocode}
10389 % \iffalse
10390 %</tex>
10391 %<*lua,lua-cli,lua-loader>
10392 % \fi
10393 % \begin{macrocode}
10394 defaultOptions.superscripts = false
10395 % \end{macrocode}
10396 % \iffalse
10397 %</lua,lua-cli,lua-loader>
10398 %<*manual-options>
10399
10400 #### Option `tableAttributes`
10401
10402 `tableAttributes` (default value: `false`)
10403
10404 % \fi
10405 % \begin{markdown}
10406 %
10407 % \Optitem[false]{tableAttributes}{\opt{true}, \opt{false}}
10408 %
10409 : true
10410
10411 : Enable the assignment of HTML attributes to
10412 % table captions (see the \Opt{tableCaptions} option):
10413 % \iffalse
10414 [table captions](#table-captions):
10415 % \fi
10416
10417 ``` md
10418 | Right | Left | Default | Center |
10419 |------:|:-----|---------|:------:|
10420 | 12 | 12 | 12 | 12 |
10421 | 123 | 123 | 123 | 123 |
10422 | 1 | 1 | 1 | 1 |
10423
10424 : Demonstration of pipe table syntax. {#example-table}
10425 ```
10426
10427 : false
10428
10429 : Disable the assignment of HTML attributes to table captions.
10430
10431 % \end{markdown}
10432 % \iffalse
10433
10434 ##### \LaTeX{} Example {.unnumbered}
10435
10436 Using a text editor, create a text document named `document.tex` with the
10437 following content:
10438 ``` tex
10439 \documentclass{article}
10440 \usepackage[
10441 pipeTables,
10442 tableCaptions,
10443 tableAttributes,
10444 relativeReferences,
10445 ]{markdown}
10446 \usepackage{expl3}
10447 \ExplSyntaxOn
10448 \markdownSetup{
10449 renderers = {
10450 tableAttributeContextBegin = {
10451 \group_begin:
10452 \markdownSetup{
10453 renderers = {
10454 attributeIdentifier = {
10455 \markdownSetup{
10456 renderers = {
10457 tableAttributeContextEnd = {
10458 \label{##1}
10459 \group_end:
10460 },
10461 },
10462 }
10463 },
10464 },
10465 }
10466 },
10467 tableAttributeContextEnd = {
10468 \group_end:
10469 },
10470 },
10471 }
10472 \ExplSyntaxOff
10473 \begin{document}
10474 \begin{markdown}
10475 See Table <#example-table>.
10476
10477 | Right | Left | Default | Center |
10478 |------:|:-----|---------|:------:|
10479 | 12 | 12 | 12 | 12 |
10480 | 123 | 123 | 123 | 123 |
10481 | 1 | 1 | 1 | 1 |
10482
10483 : Demonstration of pipe table syntax. {#example-table}
10484 \end{markdown}
10485 \end{document}
10486 ```````
10487 Next, invoke LuaTeX from the terminal:
10488 ``` sh
10489 lualatex document.tex
10490 ``````
10491 A PDF document named `document.pdf` should be produced and contain the
10492 following text:
10493
10494 > See Table 1.
10495 >
10496 > | Right | Left | Default | Center |
10497 > |------:|:-----|---------|:------:|
10498 > | 12 | 12 | 12 | 12 |
10499 > | 123 | 123 | 123 | 123 |
10500 > | 1 | 1 | 1 | 1 |
10501 >
10502 > : Table 1. Demonstration of pipe table syntax.
10503
10504 %</manual-options>
10505 %<*tex>
10506 % \fi
10507 % \begin{macrocode}
10508 \@@_add_lua_option:nnn
10509 { tableAttributes }
10510 { boolean }
10511 { false }
10512 % \end{macrocode}
10513 % \iffalse
10514 %</tex>
10515 %<*lua,lua-cli,lua-loader>
10516 % \fi
10517 % \begin{macrocode}
10518 defaultOptions.tableAttributes = false
10519 % \end{macrocode}
10520 % \iffalse
10521 %</lua,lua-cli,lua-loader>
10522 %<*manual-options>
10523
10524 #### Option `tableCaptions` {#table-captions}
10525
10526 `tableCaptions` (default value: `false`)
10527
10528 % \fi
10529 % \begin{markdown}
10530 %
10531 % \Optitem[false]{tableCaptions}{\opt{true}, \opt{false}}
10532 %
10533 : true
10534
10535 : Enable the Pandoc [table caption syntax
10536 extension][pandoc-table-captions] for
10537 % pipe tables (see the \Opt{pipeTables} option):
10538 % \iffalse
10539 [pipe tables](#pipe-tables):
10540 % \fi
10541
10542
10543 ``` md
10544 | Right | Left | Default | Center |
10545 |------:|:-----|---------|:------:|
10546 | 12 | 12 | 12 | 12 |
10547 | 123 | 123 | 123 | 123 |
10548 | 1 | 1 | 1 | 1 |
10549
10550 : Demonstration of pipe table syntax.
10551 ``````
10552
10553 : false
10554
10555 : Disable the Pandoc table caption syntax extension.
10556
10557 [pandoc-table-captions]: https://pandoc.org/MANUAL.html#extension-table_captions
10558
10559 % \end{markdown}
10560 % \iffalse
10561
10562 ##### \LaTeX{} Example {.unnumbered}
10563
10564 Using a text editor, create a text document named `document.tex` with the
10565 following content:
10566 ``` tex
10567 \documentclass{article}
10568 \usepackage[pipeTables, tableCaptions]{markdown}
10569 \begin{document}
10570 \begin{markdown}
10571 | Right | Left | Default | Center |
10572 |------:|:-----|---------|:------:|
10573 | 12 | 12 | 12 | 12 |
10574 | 123 | 123 | 123 | 123 |
10575 | 1 | 1 | 1 | 1 |
10576
10577 : Demonstration of pipe table syntax.
10578 \end{markdown}
10579 \end{document}
10580 ```````
10581 Next, invoke LuaTeX from the terminal:
10582 ``` sh
10583 lualatex document.tex
10584 ``````
10585 A PDF document named `document.pdf` should be produced and contain the
10586 following text:
10587
10588 > | Right | Left | Default | Center |
10589 > |------:|:-----|---------|:------:|
10590 > | 12 | 12 | 12 | 12 |
10591 > | 123 | 123 | 123 | 123 |
10592 > | 1 | 1 | 1 | 1 |
10593 >
10594 > : Demonstration of pipe table syntax.
10595
10596 ##### \Hologo{ConTeXt} Example {.unnumbered}
10597
10598 Using a text editor, create a text document named `document.tex` with the
10599 following content:
10600 ``` tex
10601 \usemodule[t][markdown]
10602 \setupmarkdown
10603 [
10604 pipeTables = yes,
10605 tableCaptions = yes,
10606 ]
10607 \starttext
10608 \startmarkdown
10609 | Right | Left | Default | Center |
10610 |------:|:-----|---------|:------:|
10611 | 12 | 12 | 12 | 12 |
10612 | 123 | 123 | 123 | 123 |
10613 | 1 | 1 | 1 | 1 |
10614
10615 : Demonstration of pipe table syntax.
10616 \stopmarkdown
10617 \stoptext
10618 ````````
10619 Next, invoke LuaTeX from the terminal:
10620 ``` sh
10621 context --luatex document.tex
10622 `````
10623 A PDF document named `document.pdf` should be produced and contain the
10624 following text:
10625
10626 > | Right | Left | Default | Center |
10627 > |------:|:-----|---------|:------:|
10628 > | 12 | 12 | 12 | 12 |
10629 > | 123 | 123 | 123 | 123 |
10630 > | 1 | 1 | 1 | 1 |
10631 >
10632 > : Demonstration of pipe table syntax.
10633
10634 %</manual-options>
10635 %<*tex>
10636 % \fi
10637 % \begin{macrocode}
10638 \@@_add_lua_option:nnn
10639 { tableCaptions }
10640 { boolean }
10641 { false }
10642 % \end{macrocode}
10643 % \iffalse
10644 %</tex>
10645 %<*lua,lua-cli,lua-loader>
10646 % \fi
10647 % \begin{macrocode}
10648 defaultOptions.tableCaptions = false
10649 % \end{macrocode}
10650 % \iffalse
10651 %</lua,lua-cli,lua-loader>
10652 %<*manual-options>
10653
10654 #### Option `taskLists`
10655
10656 `taskLists` (default value: `false`)
10657
10658 % \fi
10659 % \begin{markdown}
10660 %
10661 % \Optitem[false]{taskLists}{\opt{true}, \opt{false}}
10662 %
10663 : true
10664
10665 : Enable the Pandoc [task list syntax extension][pandoc-task-lists]:
10666
10667
10668 ``` md
10669 - [ ] an unticked task list item
10670 - [X] a ticked task list item
10671 ``````
10672
10673 Our implementation also supports half-ticked task list items:
10674
10675 ``` md
10676 - [/] a half-checked task list item
10677 - [.] another half-checked task list item
10678 ``````
10679
10680 : false
10681
10682 : Disable the Pandoc task list syntax extension.
10683
10684 [pandoc-task-lists]: https://pandoc.org/MANUAL.html#extension-task_lists
10685
10686 % \end{markdown}
10687 % \iffalse
10688
10689 ##### \LaTeX{} Example {.unnumbered}
10690
10691 Using a text editor, create a text document named `document.tex` with the
10692 following content:
10693 ``` tex
10694 \documentclass{article}
10695 \usepackage[taskLists]{markdown}
10696 \markdownSetup{
10697 renderers = {
10698 untickedBox = No,
10699 halfTickedBox = Maybe,
10700 tickedBox = Yes,
10701 },
10702 }
10703 \begin{document}
10704 \begin{markdown}
10705 - [ ] you can't.
10706 - [/] I can?
10707 - [X] I can!
10708 \end{markdown}
10709 \end{document}
10710 ```````
10711 Next, invoke LuaTeX from the terminal:
10712 ``` sh
10713 lualatex document.tex
10714 ``````
10715 A PDF document named `document.pdf` should be produced and contain the
10716 following text:
10717
10718 > - No you can't.
10719 > - Maybe I can?
10720 > - Yes I can!
10721
10722 ##### \Hologo{ConTeXt} Example {.unnumbered}
10723
10724 Using a text editor, create a text document named `document.tex` with the
10725 following content:
10726 ``` tex
10727 \usemodule[t][markdown]
10728 \setupmarkdown[taskLists = yes]
10729 \def\markdownRendererUntickedBox{No}
10730 \def\markdownRendererHalftickedBox{Maybe}
10731 \def\markdownRendererTickedBox{Yes}
10732 \starttext
10733 \startmarkdown
10734 - [ ] you can't.
10735 - [/] I can?
10736 - [X] I can!
10737 \stopmarkdown
10738 \stoptext
10739 ````````
10740 Next, invoke LuaTeX from the terminal:
10741 ``` sh
10742 context --luatex document.tex
10743 `````
10744 A PDF document named `document.pdf` should be produced and contain the
10745 following text:
10746
10747 > - No you can't.
10748 > - Maybe I can?
10749 > - Yes I can!
10750
10751 %</manual-options>
10752 %<*tex>
10753 % \fi
10754 % \begin{macrocode}
10755 \@@_add_lua_option:nnn
10756 { taskLists }
10757 { boolean }
10758 { false }
10759 % \end{macrocode}
10760 % \iffalse
10761 %</tex>
10762 %<*lua,lua-cli,lua-loader>
10763 % \fi
10764 % \begin{macrocode}
10765 defaultOptions.taskLists = false
10766 % \end{macrocode}
10767 % \iffalse
10768 %</lua,lua-cli,lua-loader>
10769 %<*manual-options>
10770
10771 #### Option `texComments`
10772
10773 `texComments` (default value: `false`)
10774
10775 % \fi
10776 % \markdownBegin
10777 %
10778 % \Optitem[false]{texComments}{\opt{true}, \opt{false}}
10779 %
10780 : true
10781
10782 : Strip \TeX{}-style comments.
10783
10784 ``` tex
10785 \documentclass{article}
10786 \usepackage[texComments]{markdown}
10787 \begin{document}
10788 \begin{markdown}
10789 Hel% this is a comment
10790 lo *world*!
10791 \end{markdown}
10792 \end{document}
10793 ```````
10794
10795 Always enabled when \Opt{hybrid} is enabled.
10796
10797 : false
10798
10799 : Do not strip \TeX{}-style comments.
10800
10801 % \markdownEnd
10802 % \iffalse
10803
10804 ##### Plain \TeX{} Example {.unnumbered}
10805
10806 Using a text editor, create a text document named `document.tex` with the
10807 following content:
10808 ``` tex
10809 \input markdown
10810 \def\markdownOptionTexComments{true}
10811 \markdownBegin
10812 Hel% this is a comment
10813 lo *world*!
10814 \markdownEnd
10815 \bye
10816 ```````
10817 Next, invoke LuaTeX from the terminal:
10818 ``` sh
10819 luatex document.tex
10820 ``````
10821 A PDF document named `document.pdf` should be produced and contain the text
10822 “Hello *world*!”
10823
10824 ##### \LaTeX{} Example {.unnumbered}
10825
10826 Using a text editor, create a text document named `document.tex` with the
10827 following content:
10828 ``` tex
10829 \documentclass{article}
10830 \usepackage[texComments]{markdown}
10831 \begin{document}
10832 \begin{markdown}
10833 Hel% this is a comment
10834 lo *world*!
10835 \end{markdown}
10836 \end{document}
10837 ```````
10838 Next, invoke LuaTeX from the terminal:
10839 ``` sh
10840 lualatex document.tex
10841 ``````
10842 A PDF document named `document.pdf` should be produced and contain the
10843 text “Hello *world*!”
10844
10845 ##### \Hologo{ConTeXt} Example {.unnumbered}
10846
10847 Using a text editor, create a text document named `document.tex` with the
10848 following content:
10849 ``` tex
10850 \usemodule[t][markdown]
10851 \setupmarkdown[texComments = yes]
10852 \starttext
10853 \startmarkdown
10854 Hel% this is a comment
10855 lo *world*!
10856 \stopmarkdown
10857 \stoptext
10858 ````````
10859 Next, invoke LuaTeX from the terminal:
10860 ``` sh
10861 context --luatex document.tex
10862 `````
10863 A PDF document named `document.pdf` should be produced and contain the
10864 text “Hello *world*!”
10865
10866 %</manual-options>
10867 %<*tex>
10868 % \fi
10869 % \begin{macrocode}
10870 \@@_add_lua_option:nnn
10871 { texComments }
10872 { boolean }
10873 { false }
10874 % \end{macrocode}
10875 % \iffalse
10876 %</tex>
10877 %<*lua,lua-cli,lua-loader>
10878 % \fi
10879 % \begin{macrocode}
10880 defaultOptions.texComments = false
10881 % \end{macrocode}
10882 % \iffalse
10883 %</lua,lua-cli,lua-loader>
10884 %<*manual-options>
10885
10886 #### Option `texMathDollars`
10887
10888 `texMathDollars` (default value: `false`)
10889
10890 % \fi
10891 % \begin{markdown}
10892 %
10893 % \Optitem[false]{texMathDollars}{\opt{true}, \opt{false}}
10894 %
10895 : true
10896
10897 : Enable the Pandoc [dollar math syntax
10898 extension][pandoc-tex-math-dollars]:
10899
10900 ``` md
10901 inline math: $E=mc^2$
10902
10903 display math: $$E=mc^2$$
10904 ```
10905
10906 : false
10907
10908 : Disable the Pandoc dollar math syntax extension.
10909
10910 [pandoc-tex-math-dollars]: https://pandoc.org/MANUAL.html#extension-tex_math_dollars
10911
10912 % \end{markdown}
10913 % \iffalse
10914
10915 ##### Lua Module Example {.unnumbered}
10916
10917 Using a text editor, create a text document named `document.tex` with the
10918 following content:
10919 ``` tex
10920 \input markdown
10921 \input lmfonts
10922 \begingroup
10923 \catcode`\%=12
10924 \catcode`\#=12
10925 \directlua{
10926 local markdown = require("markdown")
10927 local newline = [[^^J^^J]]
10928 local convert = markdown.new({texMathDollars = true})
10929 local input =
10930 [[$E=mc^2$]] .. newline .. newline ..
10931 [[$$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$]]
10932 tex.sprint(convert(input)) }
10933 \endgroup
10934 \bye
10935 ```````
10936 Then, invoke LuaTeX from the terminal:
10937 ``` sh
10938 luatex document.tex
10939 ```````
10940 A PDF document named `document.pdf` should be produced and contain the
10941 following text:
10942
10943 > $E=mc^2$
10944 >
10945 > $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
10946
10947 ##### Lua CLI Example {.unnumbered}
10948
10949 Using a text editor, create a text document named `document.tex` with the
10950 following content:
10951 ``` tex
10952 \input markdown
10953 \input lmfonts
10954 \begingroup
10955 \catcode`\%=12
10956 \catcode`\#=12
10957 \input optionfalse
10958 \par
10959 \input optiontrue
10960 \endgroup
10961 \bye
10962 ```````
10963 Using a text editor, create a text document named `content.md` with the
10964 following content:
10965 ``` md
10966 $E=mc^2$
10967
10968 $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
10969 ``````
10970 Next, invoke LuaTeX from the terminal:
10971 ``` sh
10972 markdown2tex -- content.md optionfalse.tex
10973 markdown2tex texMathDollars=true -- content.md optiontrue.tex
10974 luatex document.tex
10975 ```````
10976
10977 A PDF document named `document.pdf` should be produced and contain the
10978 following text:
10979
10980 > \$E=mc^2\$
10981 >
10982 > \$\$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\$\$
10983 >
10984 > $E=mc^2$
10985 >
10986 > $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
10987
10988 ##### Plain \TeX{} Example {.unnumbered}
10989
10990 Using a text editor, create a text document named `document.tex` with the
10991 following content:
10992 ``` tex
10993 \input markdown
10994
10995 \def\markdownOptionTexMathDollars{true}
10996 \markdownBegin
10997 $E=mc^2$
10998
10999 $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
11000 \markdownEnd
11001
11002 \bye
11003 ```````
11004 Next, invoke LuaTeX from the terminal:
11005 ``` sh
11006 luatex document.tex
11007 ``````
11008 A PDF document named `document.pdf` should be produced and contain the
11009 following text:
11010
11011 > $E=mc^2$
11012 >
11013 > $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
11014
11015 ##### \LaTeX{} Example {.unnumbered}
11016
11017 Using a text editor, create a text document named `document.tex` with the
11018 following content:
11019 ``` tex
11020 \documentclass{article}
11021 \usepackage[texMathDollars]{markdown}
11022 \begin{document}
11023
11024 \begin{markdown}
11025 $E=mc^2$
11026
11027 $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
11028 \end{markdown}
11029
11030 \end{document}
11031 ```````
11032 Next, invoke LuaTeX from the terminal:
11033 ``` sh
11034 lualatex document.tex
11035 ``````
11036 A PDF document named `document.pdf` should be produced and contain the
11037 following text:
11038
11039 > $E=mc^2$
11040 >
11041 > $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
11042
11043 ##### \Hologo{ConTeXt} Example {.unnumbered}
11044
11045 Using a text editor, create a text document named `document.tex` with the
11046 following content:
11047 ``` tex
11048 \usemodule[t][markdown]
11049 \setupmarkdown[texMathDollars = yes]
11050 \starttext
11051
11052 \startmarkdown
11053 $E=mc^2$
11054
11055 $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
11056 \stopmarkdown
11057
11058 \stoptext
11059 ````````
11060 Next, invoke LuaTeX from the terminal:
11061 ``` sh
11062 context --luatex document.tex
11063 `````
11064 A PDF document named `document.pdf` should be produced and contain the
11065 following text:
11066
11067 > $E=mc^2$
11068 >
11069 > $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
11070
11071 %</manual-options>
11072 %<*tex>
11073 % \fi
11074 % \begin{macrocode}
11075 \@@_add_lua_option:nnn
11076 { texMathDollars }
11077 { boolean }
11078 { false }
11079 % \end{macrocode}
11080 % \iffalse
11081 %</tex>
11082 %<*lua,lua-cli,lua-loader>
11083 % \fi
11084 % \begin{macrocode}
11085 defaultOptions.texMathDollars = false
11086 % \end{macrocode}
11087 % \iffalse
11088 %</lua,lua-cli,lua-loader>
11089 %<*manual-options>
11090
11091 #### Option `texMathDoubleBackslash`
11092
11093 `texMathDoubleBackslash` (default value: `false`)
11094
11095 % \fi
11096 % \begin{markdown}
11097 %
11098 % \Optitem[false]{texMathDoubleBackslash}{\opt{true}, \opt{false}}
11099 %
11100 : true
11101
11102 : Enable the Pandoc [double backslash math syntax
11103 extension][pandoc-tex-math-double-backslash]:
11104
11105 ``` md
11106 inline math: \\(E=mc^2\\)
11107
11108 display math: \\[E=mc^2\\]
11109 ```
11110
11111 : false
11112
11113 : Disable the Pandoc double backslash math syntax extension.
11114
11115 [pandoc-tex-math-double-backslash]: https://pandoc.org/MANUAL.html#extension-tex_math_double_backslash
11116
11117 % \end{markdown}
11118 % \iffalse
11119
11120 ##### Lua Module Example {.unnumbered}
11121
11122 Using a text editor, create a text document named `document.tex` with the
11123 following content:
11124 ``` tex
11125 \input markdown
11126 \input lmfonts
11127 \begingroup
11128 \catcode`\%=12
11129 \catcode`\#=12
11130 \directlua{
11131 local markdown = require("markdown")
11132 local newline = [[^^J^^J]]
11133 local convert = markdown.new({texMathDoubleBackslash = true})
11134 local input =
11135 [[\\(E=mc^2\\)]] .. newline .. newline ..
11136 [[\\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\]]]
11137 tex.sprint(convert(input)) }
11138 \endgroup
11139 \bye
11140 ```````
11141 Then, invoke LuaTeX from the terminal:
11142 ``` sh
11143 luatex document.tex
11144 ```````
11145 A PDF document named `document.pdf` should be produced and contain the
11146 following text:
11147
11148 > \(E=mc^2\)
11149 >
11150 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11151
11152 ##### Lua CLI Example {.unnumbered}
11153
11154 Using a text editor, create a text document named `document.tex` with the
11155 following content:
11156 ``` tex
11157 \input markdown
11158 \input lmfonts
11159 \begingroup
11160 \catcode`\%=12
11161 \catcode`\#=12
11162 \input optionfalse
11163 \par
11164 \input optiontrue
11165 \endgroup
11166 \bye
11167 ```````
11168 Using a text editor, create a text document named `content.md` with the
11169 following content:
11170 ``` md
11171 \\(E=mc^2\\)
11172
11173 \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\]
11174 ``````
11175 Next, invoke LuaTeX from the terminal:
11176 ``` sh
11177 markdown2tex -- content.md optionfalse.tex
11178 markdown2tex texMathDoubleBackslash=true -- content.md optiontrue.tex
11179 luatex document.tex
11180 ```````
11181
11182 A PDF document named `document.pdf` should be produced and contain the
11183 following text:
11184
11185 > \\(E=mc^2\\)
11186 >
11187 > \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\]
11188 >
11189 > \(E=mc^2\)
11190 >
11191 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11192
11193 ##### Plain \TeX{} Example {.unnumbered}
11194
11195 Using a text editor, create a text document named `document.tex` with the
11196 following content:
11197 ``` tex
11198 \input markdown
11199
11200 \def\markdownOptionTexMathDoubleBackslash{true}
11201 \markdownBegin
11202 \\(E=mc^2\\)
11203
11204 \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\]
11205 \markdownEnd
11206
11207 \bye
11208 ```````
11209 Next, invoke LuaTeX from the terminal:
11210 ``` sh
11211 luatex document.tex
11212 ``````
11213 A PDF document named `document.pdf` should be produced and contain the
11214 following text:
11215
11216 > \(E=mc^2\)
11217 >
11218 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11219
11220 ##### \LaTeX{} Example {.unnumbered}
11221
11222 Using a text editor, create a text document named `document.tex` with the
11223 following content:
11224 ``` tex
11225 \documentclass{article}
11226 \usepackage[texMathDoubleBackslash]{markdown}
11227 \begin{document}
11228
11229 \begin{markdown}
11230 \\(E=mc^2\\)
11231
11232 \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\]
11233 \end{markdown}
11234
11235 \end{document}
11236 ```````
11237 Next, invoke LuaTeX from the terminal:
11238 ``` sh
11239 lualatex document.tex
11240 ``````
11241 A PDF document named `document.pdf` should be produced and contain the
11242 following text:
11243
11244 > \(E=mc^2\)
11245 >
11246 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11247
11248 ##### \Hologo{ConTeXt} Example {.unnumbered}
11249
11250 Using a text editor, create a text document named `document.tex` with the
11251 following content:
11252 ``` tex
11253 \usemodule[t][markdown]
11254 \setupmarkdown[texMathDoubleBackslash = yes]
11255 \starttext
11256
11257 \startmarkdown
11258 \\(E=mc^2\\)
11259
11260 \\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\\]
11261 \stopmarkdown
11262
11263 \stoptext
11264 ````````
11265 Next, invoke LuaTeX from the terminal:
11266 ``` sh
11267 context --luatex document.tex
11268 `````
11269 A PDF document named `document.pdf` should be produced and contain the
11270 following text:
11271
11272 > \(E=mc^2\)
11273 >
11274 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11275
11276 %</manual-options>
11277 %<*tex>
11278 % \fi
11279 % \begin{macrocode}
11280 \@@_add_lua_option:nnn
11281 { texMathDoubleBackslash }
11282 { boolean }
11283 { false }
11284 % \end{macrocode}
11285 % \iffalse
11286 %</tex>
11287 %<*lua,lua-cli,lua-loader>
11288 % \fi
11289 % \begin{macrocode}
11290 defaultOptions.texMathDoubleBackslash = false
11291 % \end{macrocode}
11292 % \iffalse
11293 %</lua,lua-cli,lua-loader>
11294 %<*manual-options>
11295
11296 #### Option `texMathSingleBackslash`
11297
11298 `texMathSingleBackslash` (default value: `false`)
11299
11300 % \fi
11301 % \begin{markdown}
11302 %
11303 % \Optitem[false]{texMathSingleBackslash}{\opt{true}, \opt{false}}
11304 %
11305 : true
11306
11307 : Enable the Pandoc [single backslash math syntax
11308 extension][pandoc-tex-math-single-backslash]:
11309
11310 ``` md
11311 inline math: \(E=mc^2\)
11312
11313 display math: \[E=mc^2\]
11314 ```
11315
11316 : false
11317
11318 : Disable the Pandoc single backslash math syntax extension.
11319
11320 [pandoc-tex-math-single-backslash]: https://pandoc.org/MANUAL.html#extension-tex_math_single_backslash
11321
11322 % \end{markdown}
11323 % \iffalse
11324
11325 ##### Lua Module Example {.unnumbered}
11326
11327 Using a text editor, create a text document named `document.tex` with the
11328 following content:
11329 ``` tex
11330 \input markdown
11331 \input lmfonts
11332 \begingroup
11333 \catcode`\%=12
11334 \catcode`\#=12
11335 \directlua{
11336 local markdown = require("markdown")
11337 local newline = [[^^J^^J]]
11338 local convert = markdown.new({texMathSingleBackslash = true})
11339 local input =
11340 [[\(E=mc^2\)]] .. newline .. newline ..
11341 [[\[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]]]
11342 tex.sprint(convert(input)) }
11343 \endgroup
11344 \bye
11345 ```````
11346 Then, invoke LuaTeX from the terminal:
11347 ``` sh
11348 luatex document.tex
11349 ```````
11350 A PDF document named `document.pdf` should be produced and contain the
11351 following text:
11352
11353 > \(E=mc^2\)
11354 >
11355 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11356
11357 ##### Lua CLI Example {.unnumbered}
11358
11359 Using a text editor, create a text document named `document.tex` with the
11360 following content:
11361 ``` tex
11362 \input markdown
11363 \input lmfonts
11364 \begingroup
11365 \catcode`\%=12
11366 \catcode`\#=12
11367 \input optionfalse
11368 \par
11369 \input optiontrue
11370 \endgroup
11371 \bye
11372 ```````
11373 Using a text editor, create a text document named `content.md` with the
11374 following content:
11375 ``` md
11376 \(E=mc^2\)
11377
11378 \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11379 ``````
11380 Next, invoke LuaTeX from the terminal:
11381 ``` sh
11382 markdown2tex -- content.md optionfalse.tex
11383 markdown2tex texMathSingleBackslash=true -- content.md optiontrue.tex
11384 luatex document.tex
11385 ```````
11386
11387 A PDF document named `document.pdf` should be produced and contain the
11388 following text:
11389
11390 > (E=mc^2)
11391 >
11392 > [\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx]
11393 >
11394 > \(E=mc^2\)
11395 >
11396 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11397
11398 ##### Plain \TeX{} Example {.unnumbered}
11399
11400 Using a text editor, create a text document named `document.tex` with the
11401 following content:
11402 ``` tex
11403 \input markdown
11404
11405 \def\markdownOptionTexMathSingleBackslash{true}
11406 \markdownBegin
11407 \(E=mc^2\)
11408
11409 \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11410 \markdownEnd
11411
11412 \bye
11413 ```````
11414 Next, invoke LuaTeX from the terminal:
11415 ``` sh
11416 luatex document.tex
11417 ``````
11418 A PDF document named `document.pdf` should be produced and contain the
11419 following text:
11420
11421 > \(E=mc^2\)
11422 >
11423 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11424
11425 ##### \LaTeX{} Example {.unnumbered}
11426
11427 Using a text editor, create a text document named `document.tex` with the
11428 following content:
11429 ``` tex
11430 \documentclass{article}
11431 \usepackage[texMathSingleBackslash]{markdown}
11432 \begin{document}
11433
11434 \begin{markdown}
11435 \(E=mc^2\)
11436
11437 \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11438 \end{markdown}
11439
11440 \end{document}
11441 ```````
11442 Next, invoke LuaTeX from the terminal:
11443 ``` sh
11444 lualatex document.tex
11445 ``````
11446 A PDF document named `document.pdf` should be produced and contain the
11447 following text:
11448
11449 > \(E=mc^2\)
11450 >
11451 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11452
11453 ##### \Hologo{ConTeXt} Example {.unnumbered}
11454
11455 Using a text editor, create a text document named `document.tex` with the
11456 following content:
11457 ``` tex
11458 \usemodule[t][markdown]
11459 \setupmarkdown[texMathSingleBackslash = yes]
11460 \starttext
11461
11462 \startmarkdown
11463 \(E=mc^2\)
11464
11465 \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11466 \stopmarkdown
11467
11468 \stoptext
11469 ````````
11470 Next, invoke LuaTeX from the terminal:
11471 ``` sh
11472 context --luatex document.tex
11473 `````
11474 A PDF document named `document.pdf` should be produced and contain the
11475 following text:
11476
11477 > \(E=mc^2\)
11478 >
11479 > \[\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\]
11480
11481 %</manual-options>
11482 %<*tex>
11483 % \fi
11484 % \begin{macrocode}
11485 \@@_add_lua_option:nnn
11486 { texMathSingleBackslash }
11487 { boolean }
11488 { false }
11489 % \end{macrocode}
11490 % \iffalse
11491 %</tex>
11492 %<*lua,lua-cli,lua-loader>
11493 % \fi
11494 % \begin{macrocode}
11495 defaultOptions.texMathSingleBackslash = false
11496 % \end{macrocode}
11497 % \iffalse
11498 %</lua,lua-cli,lua-loader>
11499 %<*manual-options>
11500
11501 #### Option `tightLists`
11502
11503 `tightLists` (default value: `true`)
11504
11505 % \fi
11506 % \begin{markdown}
11507 %
11508 % \Optitem[true]{tightLists}{\opt{true}, \opt{false}}
11509 %
11510 : true
11511
11512 : Unordered and ordered lists whose items do not consist of multiple
11513 paragraphs will be considered *tight*. Tight lists will produce tight
11514 renderers that may produce different output than lists that are not
11515 tight:
11516
11517 ``` md
11518 - This is
11519 - a tight
11520 - unordered list.
11521
11522 - This is
11523
11524 not a tight
11525
11526 - unordered list.
11527 ```
11528
11529 : false
11530
11531 : Unordered and ordered lists whose items consist of multiple paragraphs
11532 will be treated the same way as lists that consist of multiple paragraphs.
11533
11534 % \end{markdown}
11535 % \iffalse
11536
11537 ##### \LaTeX{} Example {.unnumbered}
11538
11539 Using a text editor, create a text document named `document.tex` with the
11540 following content:
11541 ``` tex
11542 \documentclass{article}
11543 \usepackage{markdown}
11544 \begin{document}
11545
11546 \begin{markdown}
11547 The following list is tight:
11548
11549 - first item
11550 - second item
11551 - third item
11552
11553 The following list is loose:
11554
11555 - first item
11556 - second item that spans
11557
11558 multiple paragraphs
11559 - third item
11560 \end{markdown}
11561
11562 \begin{markdown}[tightLists=false]
11563 The following list is now also loose:
11564
11565 - first item
11566 - second item
11567 - third item
11568 \end{markdown}
11569
11570 \end{document}
11571 ```````
11572 Next, invoke LuaTeX from the terminal:
11573 ``` sh
11574 lualatex document.tex
11575 ``````
11576 A PDF document named `document.pdf` should be produced and contain the
11577 following text:
11578
11579 > The following list is tight:
11580 >
11581 > - first item
11582 > - second item
11583 > - third item
11584 >
11585 > The following list is loose:
11586 >
11587 > - first item
11588 > - second item that spans
11589 >
11590 > multiple paragraphs
11591 > - third item
11592 >
11593 > The following list is now also loose:
11594 >
11595 > - first item
11596 >
11597 > - second item
11598 >
11599 > - third item
11600
11601 %</manual-options>
11602 %<*tex>
11603 % \fi
11604 % \begin{macrocode}
11605 \@@_add_lua_option:nnn
11606 { tightLists }
11607 { boolean }
11608 { true }
11609 % \end{macrocode}
11610 % \iffalse
11611 %</tex>
11612 %<*lua,lua-cli,lua-loader>
11613 % \fi
11614 % \begin{macrocode}
11615 defaultOptions.tightLists = true
11616 % \end{macrocode}
11617 % \iffalse
11618 %</lua,lua-cli,lua-loader>
11619 %<*manual-options>
11620
11621 #### Option `underscores`
11622
11623 `underscores` (default value: `true`)
11624
11625 % \fi
11626 % \begin{markdown}
11627 %
11628 % \Optitem[true]{underscores}{\opt{true}, \opt{false}}
11629 %
11630 : true
11631
11632 : Both underscores and asterisks can be used to denote emphasis and
11633 strong emphasis:
11634
11635 ``` md
11636 *single asterisks*
11637 _single underscores_
11638 **double asterisks**
11639 __double underscores__
11640 ``````
11641
11642 : false
11643
11644 : Only asterisks can be used to denote emphasis and strong emphasis.
11645 This makes it easy to write math with the \Opt{hybrid} option
11646 without the need to constantly escape subscripts.
11647
11648 % \end{markdown}
11649 % \iffalse
11650
11651 ##### Plain \TeX{} Example {.unnumbered}
11652
11653 Using a text editor, create a text document named `document.tex` with the
11654 following content:
11655 ``` tex
11656 \input markdown
11657 \def\markdownOptionHybrid{true}
11658
11659 \markdownBegin
11660 This is _emphasized text_ and this is a math subscript: $m\_n$.
11661 \markdownEnd
11662
11663 \def\markdownOptionUnderscores{false}
11664 \markdownBegin
11665 This is *emphasized text* and this is a math subscript: $m_n$.
11666 \markdownEnd
11667
11668 \bye
11669 ```````
11670 Next, invoke LuaTeX from the terminal:
11671 ``` sh
11672 luatex document.tex
11673 ``````
11674 A PDF document named `document.pdf` should be produced and contain the
11675 following text:
11676
11677 > This is _emphasized text_ and this is a math subscript: *mₙ*.
11678 >
11679 > This is _emphasized text_ and this is a math subscript: *mₙ*.
11680
11681 ##### \LaTeX{} Example {.unnumbered}
11682
11683 Using a text editor, create a text document named `document.tex` with the
11684 following content:
11685 ``` tex
11686 \documentclass{article}
11687 \usepackage[hybrid]{markdown}
11688 \begin{document}
11689
11690 \begin{markdown}
11691 This is _emphasized text_ and this is a math subscript: $m\_n$.
11692 \end{markdown}
11693
11694 \begin{markdown}[underscores=false]
11695 This is *emphasized text* and this is a math subscript: $m_n$.
11696 \end{markdown}
11697
11698 \end{document}
11699 ```````
11700 Next, invoke LuaTeX from the terminal:
11701 ``` sh
11702 lualatex document.tex
11703 ``````
11704 A PDF document named `document.pdf` should be produced and contain the
11705 following text:
11706
11707 > This is _emphasized text_ and this is a math subscript: *mₙ*.
11708 >
11709 > This is _emphasized text_ and this is a math subscript: *mₙ*.
11710
11711 ##### \Hologo{ConTeXt} Example {.unnumbered}
11712
11713 Using a text editor, create a text document named `document.tex` with the
11714 following content:
11715 ``` tex
11716 \usemodule[t][markdown]
11717 \setupmarkdown[hybrid = yes]
11718 \starttext
11719
11720 \startmarkdown
11721 This is _emphasized text_ and this is a math subscript: $m\_n$.
11722 \stopmarkdown
11723
11724 \setupmarkdown[underscores = yes]
11725 \startmarkdown
11726 This is *emphasized text* and this is a math subscript: $m_n$.
11727 \stopmarkdown
11728
11729 \stoptext
11730 ````````
11731 Next, invoke LuaTeX from the terminal:
11732 ``` sh
11733 context --luatex document.tex
11734 `````
11735 A PDF document named `document.pdf` should be produced and contain the
11736 following text:
11737
11738 > This is _emphasized text_ and this is a math subscript: *mₙ*.
11739 >
11740 > This is _emphasized text_ and this is a math subscript: *mₙ*.
11741
11742 %</manual-options>
11743 %<*tex>
11744 % \fi
11745 % \begin{macrocode}
11746 \@@_add_lua_option:nnn
11747 { underscores }
11748 { boolean }
11749 { true }
11750 \ExplSyntaxOff
11751 % \end{macrocode}
11752 % \iffalse
11753 %</tex>
11754 %<*lua,lua-cli,lua-loader>
11755 % \fi
11756 % \begin{macrocode}
11757 defaultOptions.underscores = true
11758 % \end{macrocode}
11759 % \endgroup
11760 % \iffalse
11761 %</lua,lua-cli,lua-loader>
11762 %<*lua-cli-manpage>
11763 % \fi
11764 % \begin{markdown}
11765 %
11766 %### Command-Line Interface {#lua-cli-interface}
11767 %
11768 % The high-level operation of the Markdown package involves the communication
11769 % between several programming layers: the plain \TeX{} layer hands markdown
11770 % documents to the Lua layer. Lua converts the documents to \TeX{}, and hands
11771 % the converted documents back to plain \TeX{} layer for typesetting, see
11772 % Figure <#fig:sequence-diagram-tex-interface>.
11773 %
11774 % This procedure has the advantage of being fully automated. However, it also
11775 % has several important disadvantages: The converted \TeX{} documents are
11776 % cached on the file system, taking up increasing amount of space. Unless the
11777 % \TeX{} engine includes a Lua interpreter, the package also requires shell
11778 % access, which opens the door for a malicious actor to access the system.
11779 % Last, but not least, the complexity of the procedure impedes debugging.
11780 %
11781 % A solution to the above problems is to decouple the conversion from the
11782 % typesetting. For this reason, a command-line Lua interface for converting a
11783 % markdown document to \TeX{} is also provided, see
11784 % Figure <#fig:sequence-diagram-lua-cli>.
11785 %
11786 % \end{markdown}
11787 % \begin{figure}
11788 % \centering
11789 % \begin{sequencediagram}
11790 % \newthread{user}{User}{}
11791 % \newinst[4]{tex}{\TeX{}}{}
11792 % \newinst[4]{lua}{Lua}{}
11793 % \begin{call}{user}{\footnotesize\cs{jobname.tex}}{tex}{\footnotesize\cs{jobname.pdf}}
11794 % \begin{call}{tex}{\footnotesize\cs{jobname.markdown.in}}{lua}{\footnotesize\cs{jobname.markdown.out}}
11795 % \end{call}
11796 % \begin{call}{tex}{\footnotesize\cs{input}\cs{jobname.markdown.out}}{tex}{}
11797 % \end{call}
11798 % \end{call}
11799 % \end{sequencediagram}
11800 % \caption[A sequence diagram of typesetting a document using the \TeX{}
11801 % interface]{A sequence diagram of the Markdown package typesetting a
11802 % markdown document using the \TeX{} interface}
11803 % \label{fig:sequence-diagram-tex-interface}
11804 % \end{figure}
11805 % \begin{figure}
11806 % \centering
11807 % \begin{sequencediagram}
11808 % \newthread{user}{User}{}
11809 % \newinst[4]{tex}{\TeX{}}{}
11810 % \newinst[4]{lua}{Lua}{}
11811 % \begin{call}{user}{\footnotesize$\langle$\textit{document}$\rangle$\texttt{.md}}{lua}{\footnotesize$\langle$\textit{document}$\rangle$\texttt{.tex}}
11812 % \end{call}
11813 % \begin{call}{user}{\footnotesize\cs{jobname.tex}}{tex}{\footnotesize\cs{jobname.pdf}}
11814 % \begin{call}{tex}{\footnotesize\cs{input} $\langle$\textit{document}$\rangle$}{tex}{}
11815 % \end{call}
11816 % \end{call}
11817 % \end{sequencediagram}
11818 % \caption[A sequence diagram of typesetting a document using the Lua CLI]%
11819 % {A sequence diagram of the Markdown package typesetting a markdown document
11820 % using the Lua command-line interface}
11821 % \label{fig:sequence-diagram-lua-cli}
11822 % \end{figure}
11823 % \begin{macrocode}
11824 .TH MARKDOWN2TEX 1 "(((LASTMODIFIED)))"
11825 .SH NAME
11826 markdown2tex \- convert .md files to .tex
11827 .SH SYNOPSIS
11828 % \end{macrocode}
11829 % \iffalse
11830 %</lua-cli-manpage>
11831 %<*lua-cli>
11832 % \fi
11833 % \begin{macrocode}
11834 local HELP_STRING = "Usage: " .. [[
11835 % \end{macrocode}
11836 % \iffalse
11837 %</lua-cli>
11838 %<*lua-cli,lua-cli-manpage>
11839 % \fi
11840 % \begin{macrocode}
11841 markdown2tex [OPTIONS] -- [INPUT_FILE] [OUTPUT_FILE]
11842
11843 % \end{macrocode}
11844 % \iffalse
11845 %</lua-cli,lua-cli-manpage>
11846 %<*lua-cli-manpage>
11847 % \fi
11848 % \begin{macrocode}
11849 .SH DESCRIPTION
11850 % \end{macrocode}
11851 % \iffalse
11852 %</lua-cli-manpage>
11853 %<*lua-cli,lua-cli-manpage>
11854 % \fi
11855 % \begin{macrocode}
11856 OPTIONS are documented in Section 2.2.1 of the Markdown Package User
11857 Manual (https://ctan.org/pkg/markdown).
11858
11859 When OUTPUT_FILE is unspecified, the result of the conversion will be
11860 written to the standard output. When INPUT_FILE is also unspecified, the
11861 result of the conversion will be read from the standard input.
11862 % \end{macrocode}
11863 % \iffalse
11864 %</lua-cli,lua-cli-manpage>
11865 %<*lua-cli>
11866 % \fi
11867 % \begin{macrocode}
11868
11869 Report bugs to: [email protected]
11870 Markdown package home page: <https://github.com/witiko/markdown>]]
11871
11872 local VERSION_STRING = [[
11873 markdown2tex (Markdown) ]] .. metadata.version .. [[
11874
11875 Copyright (C) ]] .. table.concat(metadata.copyright,
11876 "\nCopyright (C) ") .. [[
11877
11878 License: ]] .. metadata.license
11879
11880 local function warn(s)
11881 io.stderr:write("Warning: " .. s .. "\n")
11882 end
11883
11884 local function error(s)
11885 io.stderr:write("Error: " .. s .. "\n")
11886 os.exit(1)
11887 end
11888 % \end{macrocode}
11889 % \begin{markdown}
11890 %
11891 % To make it easier to copy-and-paste options from Pandoc [@macfarlane22] such
11892 % as `fancy_lists`, `header_attributes`, and `pipe_tables`, we accept
11893 % snake\\\_case in addition to camelCase variants of options. As a bonus,
11894 % studies [@sharif10] also show that snake\\\_case is faster to read than
11895 % camelCase.
11896 %
11897 % \end{markdown}
11898 % \begin{macrocode}
11899 local function camel_case(option_name)
11900 local cased_option_name = option_name:gsub("_(%l)", function(match)
11901 return match:sub(2, 2):upper()
11902 end)
11903 return cased_option_name
11904 end
11905
11906 local function snake_case(option_name)
11907 local cased_option_name = option_name:gsub("%l%u", function(match)
11908 return match:sub(1, 1) .. "_" .. match:sub(2, 2):lower()
11909 end)
11910 return cased_option_name
11911 end
11912
11913 local cases = {camel_case, snake_case}
11914 local various_case_options = {}
11915 for option_name, _ in pairs(defaultOptions) do
11916 for _, case in ipairs(cases) do
11917 various_case_options[case(option_name)] = option_name
11918 end
11919 end
11920
11921 local process_options = true
11922 local options = {}
11923 local input_filename
11924 local output_filename
11925 for i = 1, #arg do
11926 if process_options then
11927 % \end{macrocode}
11928 % \begin{markdown}
11929 % After the optional `-`{}`-` argument has been specified, the remaining
11930 % arguments are assumed to be input and output filenames. This argument is
11931 % optional, but encouraged, because it helps resolve ambiguities when
11932 % deciding whether an option or a filename has been specified.
11933 % \end{markdown}
11934 % \begin{macrocode}
11935 if arg[i] == "--" then
11936 process_options = false
11937 goto continue
11938 % \end{macrocode}
11939 % \begin{markdown}
11940 % Unless the `-`{}`-` argument has been specified before, an argument
11941 % containing the equals sign (`=`) is assumed to be an option specification in
11942 % a \meta{key}`=`\meta{value} format. The available options are listed in
11943 % Section <#sec:lua-options>.
11944 % \end{markdown}
11945 % \begin{macrocode}
11946 elseif arg[i]:match("=") then
11947 local key, value = arg[i]:match("(.-)=(.*)")
11948 if defaultOptions[key] == nil and
11949 various_case_options[key] ~= nil then
11950 key = various_case_options[key]
11951 end
11952 % \end{macrocode}
11953 % \begin{markdown}
11954 % The \luamref{defaultOptions} table is consulted to identify whether \meta{value}
11955 % should be parsed as a string, number, table, or boolean.
11956 % \end{markdown}
11957 % \begin{macrocode}
11958 local default_type = type(defaultOptions[key])
11959 if default_type == "boolean" then
11960 options[key] = (value == "true")
11961 elseif default_type == "number" then
11962 options[key] = tonumber(value)
11963 elseif default_type == "table" then
11964 options[key] = {}
11965 for item in value:gmatch("[^ ,]+") do
11966 table.insert(options[key], item)
11967 end
11968 else
11969 if default_type ~= "string" then
11970 if default_type == "nil" then
11971 warn('Option "' .. key .. '" not recognized.')
11972 else
11973 warn('Option "' .. key .. '" type not recognized, ' ..
11974 'please file a report to the package maintainer.')
11975 end
11976 warn('Parsing the ' .. 'value "' .. value ..'" of option "' ..
11977 key .. '" as a string.')
11978 end
11979 options[key] = value
11980 end
11981 goto continue
11982 % \end{macrocode}
11983 % \begin{markdown}
11984 % Unless the `-`{}`-` argument has been specified before, an argument
11985 % `-`{}`-help`, or `-h` causes a brief documentation for how to invoke the
11986 % program to be printed to the standard output.
11987 % \end{markdown}
11988 % \begin{macrocode}
11989 elseif arg[i] == "--help" or arg[i] == "-h" then
11990 print(HELP_STRING)
11991 os.exit()
11992 % \end{macrocode}
11993 % \begin{markdown}
11994 % Unless the `-`{}`-` argument has been specified before, an argument
11995 % `-`{}`-version`, or `-v` causes the program to print information about its
11996 % name, version, origin and legal status, all on standard output.
11997 % \end{markdown}
11998 % \begin{macrocode}
11999 elseif arg[i] == "--version" or arg[i] == "-v" then
12000 print(VERSION_STRING)
12001 os.exit()
12002 end
12003 end
12004 % \end{macrocode}
12005 % \begin{markdown}
12006 % The first argument that matches none of the above patterns is assumed to be
12007 % the input filename. The input filename should correspond to the Markdown
12008 % document that is going to be converted to a \TeX{} document.
12009 % \end{markdown}
12010 % \begin{macrocode}
12011 if input_filename == nil then
12012 input_filename = arg[i]
12013 % \end{macrocode}
12014 % \begin{markdown}
12015 % The first argument that matches none of the above patterns is assumed to be
12016 % the output filename. The output filename should correspond to the \TeX{}
12017 % document that will result from the conversion.
12018 % \end{markdown}
12019 % \begin{macrocode}
12020 elseif output_filename == nil then
12021 output_filename = arg[i]
12022 else
12023 error('Unexpected argument: "' .. arg[i] .. '".')
12024 end
12025 ::continue::
12026 end
12027 % \end{macrocode}
12028 % \begin{markdown}
12029 %
12030 % The command-line Lua interface is implemented by the files `markdown-cli.lua`
12031 % and `markdown2tex.lua`, which can be invoked from the command line as follows:
12032 % ``` sh
12033 % markdown2tex cacheDir=. -- hello.md hello.tex
12034 % ``````
12035 % \noindent to convert the Markdown document `hello.md` to a \TeX{} document
12036 % `hello.tex`. After the Markdown package for our \TeX{} format has been
12037 % loaded, the converted document can be typeset as follows:
12038 % ``` tex
12039 % \input hello
12040 % ```````
12041 %
12042 % \end{markdown}
12043 % \iffalse
12044 %</lua-cli>
12045 %<*tex>
12046 % \fi
12047 % \begin{markdown}
12048 %
12049 % Plain \TeX{} Interface {#texinterface}
12050 %------------------------
12051 %
12052 % \end{markdown}
12053 % \iffalse
12054 %</tex>
12055 %<*manual-interfaces>
12056
12057 ### Plain \TeX{}
12058
12059 The plain \TeX{} interface provides \TeX{} commands that typeset markdown
12060 documents by using the Lua interface behind the scenes. Unlike the Lua
12061 interface, the plain TeX interface does not provide low-level tools for
12062 converting markdown to \TeX{}. Instead, its goal is to provide high-level
12063 typesetting capabilities.
12064
12065 The plain \TeX{} interface accepts the same options as the `markdown` Lua
12066 module, in addition to its own options, but now the options are specified as
12067 \TeX{} commands.
12068
12069 Using a text editor, create a text document named `document.tex` with the
12070 following content:
12071 ``` tex
12072 \input markdown
12073 \input lmfonts
12074
12075 \markdownBegin
12076 $\sqrt{-1}$ *equals* $i$.
12077 \markdownEnd
12078
12079 \def\markdownOptionTexMathDollars{true}
12080 \markdownBegin
12081 $\sqrt{-1}$ *equals* $i$.
12082 \markdownEnd
12083
12084 \bye
12085 ```````
12086 Next, invoke LuaTeX from the terminal:
12087 ``` sh
12088 luatex document.tex
12089 ``````
12090 A PDF document named `document.pdf` should be produced and contain the
12091 following text:
12092
12093 > \$\\sqrt{-1}\$ *equals* \$i\$.
12094 >
12095 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
12096 > *equals*
12097 > <math><mi>i</mi></math>.
12098
12099 Invoking pdfTeX should have the same effect:
12100 ``` sh
12101 pdftex --shell-escape document.tex
12102 ``````
12103
12104 %</manual-interfaces>
12105 %<*tex>
12106 % \fi
12107 % \begin{markdown}
12108 %
12109 % The plain \TeX{} interface provides macros for the typesetting of markdown
12110 % input from within plain \TeX{}, for setting the Lua interface options (see
12111 % Section <#sec:lua-options>) used during the conversion from markdown to
12112 % plain \TeX{} and for changing the way markdown the tokens are rendered.
12113 %
12114 % \end{markdown}
12115 % \begin{macrocode}
12116 \def\markdownLastModified{(((LASTMODIFIED)))}%
12117 \def\markdownVersion{(((VERSION)))}%
12118 % \end{macrocode}
12119 % \begin{markdown}
12120 %
12121 % The plain \TeX{} interface is implemented by the `markdown.tex` file that can
12122 % be loaded as follows:
12123 % ``` tex
12124 % \input markdown
12125 % ```````
12126 % \noindent It is expected that the special plain \TeX{} characters have the
12127 % expected category codes, when `\input`ting the file.
12128 %
12129 %### Typesetting Markdown and YAML {#tex-typesetting}
12130 %
12131 % The interface exposes the \mdef{markdownBegin}, \mdef{markdownEnd},
12132 % \mdef{yamlBegin}, \mdef{yamlEnd}, \mdef{markinline}, \mdef{markdownInput},
12133 % \mdef{yamlInput}, and \mdef{markdownEscape} macros.
12134 %
12135 %#### Typesetting Markdown and YAML directly
12136 %
12137 % The \mref{markdownBegin} macro marks the beginning of a markdown document
12138 % fragment and the \mref{markdownEnd} macro marks its end.
12139 %
12140 % \end{markdown}
12141 % \begin{macrocode}
12142 \let\markdownBegin\relax
12143 \let\markdownEnd\relax
12144 % \end{macrocode}
12145 % \begin{markdown}
12146 %
12147 % You may prepend your own code to the \mref{markdownBegin} macro and redefine the
12148 % \mref{markdownEnd} macro to produce special effects before and after the
12149 % markdown block.
12150 %
12151 % There are several limitations to the macros you need to be aware of:
12152 %
12153 % The first limitation concerns the \mref{markdownEnd} macro, which must be
12154 % visible directly from the input line buffer (it may not be produced as a
12155 % result of input expansion). Otherwise, it will not be recognized as the end
12156 % of the markdown string. As a corrolary, the \mref{markdownEnd} string
12157 % may not appear anywhere inside the markdown input.
12158 %
12159 % Another limitation concerns spaces at the right end of an input line. In
12160 % markdown, these are used to produce a forced line break. However, any such
12161 % spaces are removed before the lines enter the input buffer of
12162 % \TeX{}~[@knuth86a, p. 46]. As a corrolary, the \mref{markdownBegin} macro also
12163 % ignores them.
12164 %
12165 % The \mref{markdownBegin} and \mref{markdownEnd} macros will also consume the rest
12166 % of the lines at which they appear. In the following example plain \TeX{}
12167 % code, the characters `c`, `e`, and `f` will not appear in the output.
12168 %
12169 % ``` tex
12170 % \input markdown
12171 % a
12172 % b \markdownBegin c
12173 % d
12174 % e \markdownEnd f
12175 % g
12176 % \bye
12177 % ```````
12178 %
12179 % Note that you may also not nest the \mref{markdownBegin} and \mref{markdownEnd}
12180 % macros.
12181 %
12182 % The following example plain \TeX{} code showcases the usage of the
12183 % \mref{markdownBegin} and \mref{markdownEnd} macros:
12184 %
12185 % ``` tex
12186 % \input markdown
12187 % \markdownBegin
12188 % _Hello_ **world** ...
12189 % \markdownEnd
12190 % \bye
12191 % ```````
12192 %
12193 % The \mref{yamlBegin} macro marks the beginning of an YAML document
12194 % fragment and the \mref{yamlEnd} macro marks its end.
12195 %
12196 % \end{markdown}
12197 % \begin{macrocode}
12198 \let\yamlBegin\relax
12199 \def\yamlEnd{\markdownEnd\endgroup}
12200 % \end{macrocode}
12201 % \begin{markdown}
12202 %
12203 % The \mref{yamlBegin} and \mref{yamlEnd} macros are subject to the same
12204 % limitations as the \mref{markdownBegin} and \mref{markdownEnd} macros.
12205 %
12206 % The following example plain \TeX{} code showcases the usage of the
12207 % \mref{markdownBegin} and \mref{markdownEnd} macros:
12208 %
12209 % ``` tex
12210 % \input markdown
12211 % \yamlBegin
12212 % title: _Hello_ **world** ...
12213 % author: John Doe
12214 % \yamlEnd
12215 % \bye
12216 % ```````
12217 %
12218 % The above code has the same effect as the below code:
12219 %
12220 % ``` tex
12221 % \input markdown
12222 % \yamlSetup{jekyllData, expectJekyllData, ensureJekyllData}
12223 % \markdownBegin
12224 % title: _Hello_ **world** ...
12225 % author: John Doe
12226 % \markdownEnd
12227 % \bye
12228 % ```````
12229 %
12230 % You can use the \mref{markinline} macro to input inline markdown content.
12231 %
12232 % \end{markdown}
12233 % \begin{macrocode}
12234 \let\markinline\relax
12235 % \end{macrocode}
12236 % \begin{markdown}
12237 %
12238 % The following example plain \TeX{} code showcases the usage of the
12239 % \mref{markinline} macro:
12240 %
12241 % ``` tex
12242 % \input markdown
12243 % \markinline{_Hello_ **world**}
12244 % \bye
12245 % ```````
12246 %
12247 % The above code has the same effect as the below code:
12248 %
12249 % ``` tex
12250 % \input markdown
12251 % \markdownSetup{contentLevel=inline}
12252 % \markdownBegin
12253 % _Hello_ **world** ...
12254 % \markdownEnd
12255 % \bye
12256 % ```````
12257 %
12258 % The \mref{markinline} macro is subject to the same limitations as the
12259 % \mref{markdownBegin} and \mref{markdownEnd} macros.
12260 %
12261 %#### Typesetting Markdown and YAML from external documents
12262 %
12263 % You can use the \mref{markdownInput} macro to include markdown documents,
12264 % similarly to how you might use the `\input` \TeX{} primitive to include
12265 % \TeX{} documents. The \mref{markdownInput} macro accepts a single parameter
12266 % with the filename of a markdown document and expands to the result of the
12267 % conversion of the input markdown document to plain \TeX{}.
12268 %
12269 % \end{markdown}
12270 % \begin{macrocode}
12271 \let\markdownInput\relax
12272 % \end{macrocode}
12273 % \begin{markdown}
12274 %
12275 % The macro \mref{markdownInput} is not subject to the limitations of the
12276 % \mref{markdownBegin} and \mref{markdownEnd} macros.
12277 %
12278 % The following example plain \TeX{} code showcases the usage of the
12279 % \mref{markdownInput} macro:
12280 %
12281 % ``` tex
12282 % \input markdown
12283 % \markdownInput{hello.md}
12284 % \bye
12285 % ```````
12286 %
12287 % You can use the \mref{yamlInput} macro to include YAML documents.
12288 % similarly to how you might use the `\input` \TeX{} primitive to include
12289 % \TeX{} documents. The \mref{yamlInput} macro accepts a single parameter with
12290 % the filename of a YAML document and expands to the result of the
12291 % conversion of the input YAML document to plain \TeX{}.
12292 %
12293 % \end{markdown}
12294 % \begin{macrocode}
12295 \def\yamlInput#1{%
12296 \begingroup
12297 \yamlSetup{jekyllData, expectJekyllData, ensureJekyllData}%
12298 \markdownInput{#1}%
12299 \endgroup
12300 }%
12301 % \end{macrocode}
12302 % \begin{markdown}
12303 %
12304 % The macro \mref{yamlInput} is also not subject to the limitations of the
12305 % \mref{markdownBegin} and \mref{markdownEnd} macros.
12306 %
12307 % The following example plain \TeX{} code showcases the usage of the
12308 % \mref{markdownInput} macro:
12309 %
12310 % ``` tex
12311 % \input markdown
12312 % \yamlInput{hello.yml}
12313 % \bye
12314 % ```````
12315 %
12316 % The above code has the same effect as the below code:
12317 %
12318 % ``` tex
12319 % \input markdown
12320 % \yamlSetup{jekyllData, expectJekyllData, ensureJekyllData}
12321 % \markdownInput{hello.yml}
12322 % \bye
12323 % ```````
12324 %
12325 %#### Typesetting TeX from inside Markdown and YAML documents
12326 %
12327 % The \mref{markdownEscape} macro accepts a single parameter with the filename
12328 % of a \TeX{} document and executes the \TeX{} document in the middle of a
12329 % markdown document fragment. Unlike the `\input` built-in of \TeX,
12330 % \mref{markdownEscape} guarantees that the standard catcode regime of your
12331 % \TeX{} format will be used.
12332 %
12333 % \end{markdown}
12334 % \begin{macrocode}
12335 \let\markdownEscape\relax
12336 % \end{macrocode}
12337 % \begin{markdown}
12338 %
12339 %### Options {#tex-options}
12340 %
12341 % The plain \TeX{} options are represented by \TeX{} commands. Some of them map
12342 % directly to the options recognized by the Lua interface (see
12343 % Section <#sec:lua-options>), while some of them are specific to the plain
12344 % \TeX{} interface.
12345 %
12346 % To determine whether plain \TeX{} is the top layer or if there are other
12347 % layers above plain \TeX{}, we take a look on whether the
12348 % \mdef{c_@@_top_layer_tl} token list has already been defined. If not,
12349 % we will assume that plain \TeX{} is the top layer.
12350 %
12351 % \end{markdown}
12352 % \begin{macrocode}
12353 \ExplSyntaxOn
12354 \tl_const:Nn \c_@@_option_layer_plain_tex_tl { plain_tex }
12355 \cs_generate_variant:Nn
12356 \tl_const:Nn
12357 { NV }
12358 \tl_if_exist:NF
12359 \c_@@_top_layer_tl
12360 {
12361 \tl_const:NV
12362 \c_@@_top_layer_tl
12363 \c_@@_option_layer_plain_tex_tl
12364 }
12365 % \end{macrocode}
12366 % \begin{markdown}
12367 %
12368 % To enable the enumeration of plain \TeX{} options, we will maintain the
12369 % \mdef{g_\@\@_plain_tex_options_seq} sequence.
12370 %
12371 % \end{markdown}
12372 % \begin{macrocode}
12373 \seq_new:N \g_@@_plain_tex_options_seq
12374 % \end{macrocode}
12375 % \begin{markdown}
12376 %
12377 % To enable the reflection of default/experimental plain \TeX{} options and
12378 % their types, we will maintain the
12379 % \mdef{g_\@\@_default_plain_tex_options_prop},
12380 % \mdef{g_\@\@_experimental_plain_tex_options_seq} and
12381 % \mdef{g_\@\@_plain_tex_option_types_prop} property lists and sequences,
12382 % respectively.
12383 %
12384 % \end{markdown}
12385 % \begin{macrocode}
12386 \prop_new:N \g_@@_plain_tex_option_types_prop
12387 \prop_new:N \g_@@_default_plain_tex_options_prop
12388 \seq_new:N \g_@@_experimental_plain_tex_options_seq
12389 \seq_gput_right:NV
12390 \g_@@_option_layers_seq
12391 \c_@@_option_layer_plain_tex_tl
12392 \cs_new:Nn
12393 \@@_add_plain_tex_option:nnn
12394 {
12395 \@@_add_option:Vnnn
12396 \c_@@_option_layer_plain_tex_tl
12397 { #1 }
12398 { #2 }
12399 { #3 }
12400 }
12401 % \end{macrocode}
12402 % \iffalse
12403 %</tex>
12404 %<*manual-options>
12405
12406 ### Plain \TeX{}
12407
12408 Plain \TeX{} options control the communication between the \TeX{} interface and
12409 the `markdown` Lua module. They are supported by all higher-level interfaces of
12410 the Markdown package, i.e. the plain \TeX{}, \LaTeX{} and \Hologo{ConTeXt}
12411 interfaces.
12412
12413 #### Setting Lua options from plain \TeX{}
12414
12415 As a rule of thumb, you can set all Lua options directly from plain \TeX{}. For
12416 example, to set the \Opt{taskLists} Lua option to `true`, you would include the
12417 following code in your plain \TeX{} document:
12418
12419 ``` tex
12420 \def\markdownOptionTaskLists{true}
12421 ```
12422
12423 %</manual-options>
12424 %<*tex>
12425 % \fi
12426 % \begin{markdown}
12427 %
12428 % The plain \TeX{} options may be also be specified via the \mdef{markdownSetup}
12429 % macro. Here, the plain \TeX{} options are represented by a comma-delimited
12430 % list of \meta{key}`=`\meta{value} pairs. For boolean options, the
12431 % `=`\meta{value} part is optional, and \meta{key} will be interpreted as
12432 % \meta{key}`=true` if the `=`\meta{value} part has been omitted.
12433 % The \mref{markdownSetup} macro receives the options to set up as its only
12434 % argument.
12435 %
12436 % \end{markdown}
12437 % \begin{macrocode}
12438 \cs_new:Nn
12439 \@@_setup:n
12440 {
12441 \keys_set:nn
12442 { markdown/options }
12443 { #1 }
12444 }
12445 \cs_gset_eq:NN
12446 \markdownSetup
12447 \@@_setup:n
12448 % \end{macrocode}
12449 % \begin{markdown}
12450 %
12451 % The command \mdef{yamlSetup} is also available as an alias for the command
12452 % \mref{markdownSetup}.
12453 %
12454 % \end{markdown}
12455 % \begin{macrocode}
12456 \cs_gset_eq:NN
12457 \yamlSetup
12458 \markdownSetup
12459 % \end{macrocode}
12460 %
12461 % \iffalse
12462 %</tex>
12463 %<*manual-options>
12464
12465 Alternatively, you can also set plain \TeX{} options using the `\markdownSetup`
12466 \TeX{} macro. For example, to set the \Opt{taskLists} Lua option to `true`,
12467 you would include the following code in your plain \TeX{} document:
12468
12469 ``` tex
12470 \markdownSetup{taskLists = true}
12471 ```
12472
12473 %</manual-options>
12474 %<*tex>
12475 % \fi
12476 % \begin{markdown}
12477 %
12478 % The
12479 % \mdef{markdownIfOption}`{`\meta{name}`}{`\meta{iftrue}`}{`\meta{iffalse}`}`
12480 % macro is provided for testing, whether the value of
12481 % `\markdownOption`\meta{name} is `true`. If the value is `true`, then
12482 % \meta{iftrue} is expanded, otherwise \meta{iffalse} is expanded.
12483 %
12484 % \end{markdown}
12485 % \begin{macrocode}
12486 \prg_new_conditional:Nnn
12487 \@@_if_option:n
12488 { TF, T, F }
12489 {
12490 \@@_get_option_type:nN
12491 { #1 }
12492 \l_tmpa_tl
12493 \str_if_eq:NNF
12494 \l_tmpa_tl
12495 \c_@@_option_type_boolean_tl
12496 {
12497 \msg_error:nnxx
12498 { markdown }
12499 { expected-boolean-option }
12500 { #1 }
12501 { \l_tmpa_tl }
12502 }
12503 \@@_get_option_value:nN
12504 { #1 }
12505 \l_tmpa_tl
12506 \str_if_eq:NNTF
12507 \l_tmpa_tl
12508 \c_@@_option_value_true_tl
12509 { \prg_return_true: }
12510 { \prg_return_false: }
12511 }
12512 \msg_new:nnn
12513 { markdown }
12514 { expected-boolean-option }
12515 {
12516 Option~#1~has~type~#2,~
12517 but~a~boolean~was~expected.
12518 }
12519 \let
12520 \markdownIfOption
12521 \@@_if_option:nTF
12522 % \end{macrocode}
12523 % \begin{markdown}
12524 %
12525 %#### Finalizing and Freezing the Cache
12526 % The \mdef{markdownOptionFinalizeCache} option corresponds to the Lua
12527 % interface \Opt{finalizeCache} option, which creates an output file
12528 % \Opt{frozenCacheFileName} (frozen cache) that contains a mapping
12529 % between an enumeration of the markdown documents in the plain \TeX{} document
12530 % and their auxiliary files cached in the \Opt{cacheDir} directory.
12531 %
12532 % \iffalse
12533 %</tex>
12534 %<*manual-options>
12535
12536 #### Finalizing and Freezing the Cache
12537
12538 % \fi
12539 %
12540 The \mdef{markdownOptionFrozenCache} option uses the mapping previously
12541 % created by the \Opt{finalizeCache} option,
12542 % \iffalse
12543 created by the Lua interface \Opt{finalizeCache} option,
12544 % \fi
12545 and uses it to typeset the plain \TeX{} document without invoking Lua. As a
12546 result, the plain \TeX{} document becomes more portable, but further changes
12547 in the order and the content of markdown documents will not be reflected. It
12548 defaults to `false`.
12549
12550 % \end{markdown}
12551 % \iffalse
12552 %</manual-options>
12553 %<*tex>
12554 % \fi
12555 % \begin{macrocode}
12556 \@@_add_plain_tex_option:nnn
12557 { frozenCache }
12558 { boolean }
12559 { false }
12560 % \end{macrocode}
12561 % \iffalse
12562 %</tex>
12563 %<*manual-options>
12564 % \fi
12565 % \begin{markdown}
12566 %
12567 % The standard usage of the above two options is as follows:
12568 % \iffalse
12569 The standard usage of the \Opt{finalizeCache} and \Opt{frozenCache}
12570 options is as follows:
12571 % \fi
12572
12573 1. Remove the \Opt{cacheDir} cache directory with stale auxiliary cache
12574 files.
12575 % 2. Enable the \Opt{finalizeCache} option.
12576 % \iffalse
12577 2. Enable the \Opt{finalizeCache} option.
12578 % \fi
12579 3. Typeset the plain \TeX{} document to populate and finalize the cache.
12580 4. Enable the \Opt{frozenCache} option.
12581 5. Publish the source code of the plain \TeX{} document and the
12582 \Opt{cacheDir} directory.
12583
12584 % \iffalse
12585 For more information, see the examples for the \Opt{finalizeCache} option.
12586 % \fi
12587
12588 #### File and Directory Names
12589
12590 % \end{markdown}
12591 % \iffalse
12592 %</manual-options>
12593 %<*tex>
12594 % \fi
12595 % \begin{markdown}
12596 %
12597 % The \mdef{markdownOptionInputTempFileName} macro sets the filename of the
12598 % temporary input file that is created during the buffering of markdown text
12599 % from a \TeX{} source. It defaults to `\jobname.markdown.in`.
12600 %
12601 % The expansion of this macro must not contain quotation marks (`"`) or
12602 % backslash symbols (`\`).
12603 %
12604 % \end{markdown}
12605 % \begin{macrocode}
12606 \tl_set:Nn
12607 \l_tmpa_tl
12608 {
12609 \str_use:N
12610 \g_@@_unquoted_jobname_str
12611 .markdown.in
12612 }
12613 \bool_if:NT
12614 \g_@@_jobname_quoted_bool
12615 {
12616 \tl_put_left:Nn
12617 \l_tmpa_tl
12618 { " }
12619 \tl_put_right:Nn
12620 \l_tmpa_tl
12621 { " }
12622 }
12623 \cs_generate_variant:Nn
12624 \@@_add_plain_tex_option:nnn
12625 { nnV }
12626 \@@_add_plain_tex_option:nnV
12627 { inputTempFileName }
12628 { path }
12629 \l_tmpa_tl
12630 % \end{macrocode}
12631 % \begin{markdown}
12632 %
12633 % The \mdef{markdownOptionOutputDir} macro sets the path to the directory that
12634 % will contain the auxiliary cache files produced by the Lua implementation and
12635 % also the auxiliary files produced by the plain \TeX{} implementation. The
12636 % option defaults to `.` or, since \TeX{} Live 2024, to the value of the
12637 % `-output-directory` option of your \TeX{} engine.
12638 %
12639 % In Mik\TeX{}, this automatic detection is [currently only supported with
12640 % Lua\TeX{}][1]. If you need to use Mik\TeX{} and cannot use Lua\TeX{}, you can
12641 % either a) fix the automatic detection by setting the environmental variable
12642 % `TEXMF_OUTPUT_DIRECTORY` manually or by setting the
12643 % \mref{markdownOptionOutputDir} option manually.
12644 %
12645 % The path must be set to the same value as the `-output-directory` option of
12646 % your \TeX{} engine for the package to function correctly. We need this macro
12647 % to make the Lua implementation aware where it should store the helper files.
12648 % The same limitations apply here as in the case of the
12649 % \Opt{inputTempFileName} macro.
12650 %
12651 % [1]: https://github.com/MiKTeX/miktex/issues/1630 (Environmental variable TEXMF_OUTPUT_DIRECTORY not set by MikTeX binaries)
12652 %
12653 % \end{markdown}
12654 % \begin{macrocode}
12655 \@@_add_plain_tex_option:nnn
12656 { outputDir }
12657 { path }
12658 { . }
12659 % \end{macrocode}
12660 % \iffalse
12661 %</tex>
12662 %<*manual-options>
12663
12664 The plain \TeX{} interface provides the following commands that you can use to
12665 specify the location of temporary files produced during the conversion from
12666 Markdown to \TeX{}:
12667
12668 - `\markdownOptionInputTempFileName`,
12669 - `\markdownOptionOutputDir`,
12670 - `\markdownOptionCacheDir`, and
12671 - `\markdownOptionFrozenCacheFileName`.
12672
12673 The `\markdownOptionCacheDir` and `\markdownOptionFrozenCacheFileName` commands
12674 correspond to the `cacheDir` and `frozenCacheFileName` Lua options.
12675
12676 Using a text editor, create a folder named `output-directory` and a text
12677 document named `document.tex` with the following content:
12678 ``` tex
12679 \input lmfonts
12680 \input markdown
12681 \def\markdownOptionInputTempFileName{temporary-input.md}
12682 \def\markdownOptionOutputDir{output-directory}
12683 \def\markdownOptionCacheDir{output-directory/cache-directory}
12684 \def\markdownOptionEagerCache{true}
12685 \def\markdownOptionFinalizeCache{true}
12686 \def\markdownOptionFrozenCacheFileName{output-directory/cache-directory/frozen-cache.tex}
12687 \markdownBegin
12688 Hello *world*!
12689 \markdownEnd
12690 \bye
12691 ```````
12692 Next, invoke LuaTeX from the terminal:
12693 ``` sh
12694 luatex --output-directory output-directory document.tex
12695 ``````
12696 A text document named `temporary-input.md` should be produced in the folder
12697 named `output-directory` and contain the following text:
12698
12699 > Hello \*world\*!
12700
12701 A folder named `output-directory/cache-directory` should also be produced and
12702 contain fragments of the converted markdown document. LuaTeX does not need
12703 other temporary files to perform the conversion from markdown to \TeX{}. To
12704 produce the remaining temporary files, invoke pdfTeX from the terminal:
12705 ``` sh
12706 pdftex --output-directory output-directory --shell-escape document.tex
12707 ``````
12708 Text document named `temporary-output.md` should be produced in the folder
12709 named `output-directory`. The document will contain the input markdown
12710 document converted to \TeX{}.
12711
12712 % \fi
12713 % \begin{markdown}
12714
12715 #### No default token renderer prototypes {#plain}
12716
12717 The Markdown package provides default definitions for token renderer prototypes
12718 using the `witiko/markdown/defaults`
12719 % theme (see Section~<#sec:themes>).
12720 % \iffalse
12721 theme.
12722 % \fi
12723 Although these default definitions provide a useful starting point for authors,
12724 they use extra resources, especially with higher-level \TeX{} formats such as
12725 \LaTeX{} and \Hologo{ConTeXt}. Furthermore, the default definitions may change
12726 at any time, which may pose a problem for maintainers of Markdown themes and
12727 templates who may require a stable output.
12728
12729 The \mdef{markdownOptionPlain} macro specifies whether higher-level \TeX{}
12730 formats should only use the plain \TeX{} default definitions or whether they
12731 should also use the format-specific default definitions. Whereas plain \TeX{}
12732 default definitions only provide definitions for simple elements such as
12733 emphasis, strong emphasis, and paragraph separators, format-specific default
12734 definitions add support for more complex elements such as lists, tables, and
12735 citations. On the flip side, plain \TeX{} default definitions load no extra
12736 resources and are rather stable, whereas format-specific default definitions
12737 load extra resources and are subject to a more rapid change.
12738
12739 Here is how you would enable the macro in a \LaTeX{} document:
12740
12741 ``` tex
12742 \usepackage[plain]{markdown}
12743 ```````
12744
12745 Here is how you would enable the macro in a \Hologo{ConTeXt} document:
12746
12747 ``` tex
12748 \def\markdownOptionPlain{true}
12749 \usemodule[t][markdown]
12750 ```````
12751
12752 The macro must be set before or during the loading of the package. Setting the
12753 macro after loading the package has no effect.
12754
12755 % \end{markdown}
12756 % \iffalse
12757 %</manual-options>
12758 %<*tex>
12759 % \fi
12760 % \begin{macrocode}
12761 \@@_add_plain_tex_option:nnn
12762 { plain }
12763 { boolean }
12764 { false }
12765 % \end{macrocode}
12766 % \iffalse
12767 %</tex>
12768 %<*manual-options>
12769 % \fi
12770 % \begin{markdown}
12771
12772 The \mdef{markdownOptionNoDefaults} macro specifies whether we should prevent
12773 the loading of default definitions or not. This is useful in contexts, where
12774 we want to have total control over how all elements are rendered.
12775
12776 Here is how you would enable the macro in a \LaTeX{} document:
12777
12778 ``` tex
12779 \usepackage[noDefaults]{markdown}
12780 ```````
12781
12782 Here is how you would enable the macro in a \Hologo{ConTeXt} document:
12783
12784 ``` tex
12785 \def\markdownOptionNoDefaults{true}
12786 \usemodule[t][markdown]
12787 ```````
12788
12789 The macro must be set before or during the loading of the package. Setting the
12790 macro after loading the package has no effect.
12791
12792 % \end{markdown}
12793 % \iffalse
12794 %</manual-options>
12795 %<*tex>
12796 % \fi
12797 % \begin{macrocode}
12798 \@@_add_plain_tex_option:nnn
12799 { noDefaults }
12800 { boolean }
12801 { false }
12802 % \end{macrocode}
12803 % \begin{markdown}
12804 %
12805 %#### Miscellaneous Options
12806 %
12807 % The \mdef{markdownOptionStripPercentSigns} macro controls whether a percent
12808 % sign (`\%`) at the beginning of a line will be discarded when buffering
12809 % Markdown input (see sections <#sec:buffering-block> and
12810 % <#sec:buffering-inline>) or not. Notably, this enables the use of markdown
12811 % when writing \TeX{} package documentation using the \pkg{Doc}
12812 % \LaTeX{}~package~[@mittelbach17] or similar. The recognized values of the
12813 % macro are `true` (discard) and `false` (retain). It defaults to `false`.
12814 %
12815 % \end{markdown}
12816 % \begin{macrocode}
12817 \seq_gput_right:Nn
12818 \g_@@_plain_tex_options_seq
12819 { stripPercentSigns }
12820 \prop_gput:Nnn
12821 \g_@@_plain_tex_option_types_prop
12822 { stripPercentSigns }
12823 { boolean }
12824 \prop_gput:Nnx
12825 \g_@@_default_plain_tex_options_prop
12826 { stripPercentSigns }
12827 { false }
12828 % \end{macrocode}
12829 % \iffalse
12830 %</tex>
12831 %<*manual-options>
12832
12833 #### Package Documentation
12834
12835 The \mdef{markdownOptionStripPercentSigns} macro controls whether a percent
12836 sign (`\%`) at the beginning of a line will be discarded when reading Markdown
12837 input from a \TeX{} document. This enables the use of markdown when writing
12838 \TeX{} package documentation using the [Doc \LaTeX{} package][doc] by Frank
12839 Mittelbach. The recognized values of the macro are `true` (discard) and `false`
12840 (retain). It defaults to `false`.
12841
12842 [doc]: https://ctan.org/pkg/doc (doc – Format LaTeX documentation)
12843
12844 Using a text editor, create a text document named `document.dtx` with the
12845 following content:
12846
12847 ``` tex
12848 % \iffalse
12849 \documentclass{ltxdoc}
12850 \usepackage[stripPercentSigns]{markdown}
12851 \begin{document}
12852 \DocInput{document.dtx}
12853 \end{document}
12854 % \fi
12855 %
12856 % \begin{markdown}
12857 % Hello *world*!
12858 % \end{markdown}
12859 ```````
12860
12861 Next, invoke LuaTeX from the terminal:
12862 ``` sh
12863 lualatex document.dtx
12864 ``````
12865 A PDF document named `document.pdf` should be produced and contain the text
12866 “Hello *world*!”
12867
12868 %</manual-options>
12869 %<*tex>
12870 % \fi
12871 % \begin{markdown}
12872 %
12873 %#### Generating Plain \TeX{} Option Macros and Key-Values
12874 %
12875 % We define the command \mdef{@@_define_option_commands_and_keyvals:} that
12876 % defines plain \TeX{} macros and the key--value interface
12877 % of the \mref{markdownSetup} macro for the above plain \TeX{} options.
12878 %
12879 % The command also defines macros and key--values that map
12880 % directly to the options recognized by the Lua interface, such as
12881 % `\markdownOptionHybrid` for the \Opt{hybrid} Lua option (see Section
12882 % <#sec:lua-options>), which are not processed by the plain \TeX{}
12883 % implementation, only passed along to Lua.
12884 %
12885 % Furthermore, the command also defines options and key--values
12886 % for subsequently loaded layers that correspond to higher-level \TeX{} formats
12887 % such as \LaTeX{} and \Hologo{ConTeXt}.
12888 %
12889 % For the macros that correspond to the non-boolean options recognized by the
12890 % Lua interface, the same limitations apply here in the case of the
12891 % \Opt{inputTempFileName} macro.
12892 %
12893 % \end{markdown}
12894 % \begin{macrocode}
12895 \cs_new:Nn
12896 \@@_define_option_commands_and_keyvals:
12897 {
12898 \seq_map_inline:Nn
12899 \g_@@_option_layers_seq
12900 {
12901 \seq_map_inline:cn
12902 { g_@@_ ##1 _options_seq }
12903 {
12904 \@@_define_option_command:n
12905 { ####1 }
12906 % \end{macrocode}
12907 % \begin{markdown}
12908 %
12909 % To make it easier to copy-and-paste options from Pandoc [@macfarlane22] such
12910 % as `fancy_lists`, `header_attributes`, and `pipe_tables`, we accept
12911 % snake\\\_case in addition to camelCase variants of options. As a bonus,
12912 % studies [@sharif10] also show that snake\\\_case is faster to read than
12913 % camelCase.
12914 %
12915 % \end{markdown}
12916 % \begin{macrocode}
12917 \@@_with_various_cases:nn
12918 { ####1 }
12919 {
12920 \@@_define_option_keyval:nnn
12921 { ##1 }
12922 { ####1 }
12923 { ########1 }
12924 }
12925 }
12926 }
12927 }
12928 \cs_new:Nn
12929 \@@_define_option_command:n
12930 {
12931 % \end{macrocode}
12932 % \begin{markdown}
12933 %
12934 % For experimental options, redirect the option command to the option command
12935 % \mdef{markdownOptionExperimental}.
12936 %
12937 % \end{markdown}
12938 % \begin{macrocode}
12939 \bool_set_false:N
12940 \l_tmpa_bool
12941 \seq_map_inline:Nn
12942 \g_@@_option_layers_seq
12943 {
12944 \seq_if_in:cnT
12945 { g_@@_experimental_ ##1 _options_seq }
12946 { #1 }
12947 {
12948 \bool_set_true:N
12949 \l_tmpa_bool
12950 \seq_map_break:
12951 }
12952 }
12953 \bool_if:NTF
12954 \l_tmpa_bool
12955 {
12956 \_@@_option_tl_to_csname:nN
12957 { #1 }
12958 \l_tmpa_tl
12959 \cs_if_exist:cF
12960 { \l_tmpa_tl }
12961 {
12962 \cs_gset:cpn
12963 { \l_tmpa_tl }
12964 { \markdownOptionExperimental }
12965 }
12966 }
12967 {
12968 % \end{macrocode}
12969 % \begin{markdown}
12970 %
12971 % Use the \pkg{lt3luabridge} library to determine the default value of the
12972 % \mref{markdownOptionOutputDir} macro.
12973 %
12974 % \end{markdown}
12975 % \begin{macrocode}
12976 \str_if_eq:nnTF
12977 { #1 }
12978 { outputDir }
12979 { \@@_define_option_command_output_dir: }
12980 {
12981 % \end{macrocode}
12982 % \begin{markdown}
12983 %
12984 % Do not override options defined before loading the package.
12985 %
12986 % \end{markdown}
12987 % \begin{macrocode}
12988 \@@_option_tl_to_csname:nN
12989 { #1 }
12990 \l_tmpa_tl
12991 \cs_if_exist:cF
12992 { \l_tmpa_tl }
12993 {
12994 \@@_get_default_option_value:nN
12995 { #1 }
12996 \l_tmpa_tl
12997 \@@_set_option_value:nV
12998 { #1 }
12999 \l_tmpa_tl
13000 }
13001 }
13002 }
13003 }
13004 \ExplSyntaxOff
13005 \input lt3luabridge.tex
13006 % \end{macrocode}
13007 % \begin{markdown}
13008 %
13009 % Use the \pkg{lt3luabridge} library to determine the default value of the
13010 % \mref{markdownOptionOutputDir} macro by using one of the following:
13011 %
13012 % 1. The `status.output_directory` variable~[@luatex25, Section 10.2], which is
13013 % available since Lua\TeX{} 1.18.0 from TeX~Live 2024 and in other \TeX{}
13014 % distributions like Mik\TeX{} since ca March 2024. We are only able to read
13015 % this variable in Lua\TeX{} and not other \TeX{} engines.
13016 %
13017 % 2. The `TEXMF_OUTPUT_DIRECTORY` environmental variable, which is available
13018 % since \TeX{}~Live 2024. We are only able to read this variable in \TeX{} Live
13019 % and not some other \TeX{} distributions like Mik\TeX{}.
13020 %
13021 % \end{markdown}
13022 % \begin{macrocode}
13023 \ExplSyntaxOn
13024 \cs_new:Nn
13025 \@@_define_option_command_output_dir:
13026 {
13027 \cs_if_free:NT
13028 \markdownOptionOutputDir
13029 {
13030 \bool_if:nTF
13031 {
13032 \cs_if_exist_p:N
13033 \luabridge_tl_set:Nn &&
13034 (
13035 \int_compare_p:nNn
13036 { \g_luabridge_method_int }
13037 =
13038 { \c_luabridge_method_directlua_int } ||
13039 \sys_if_shell_unrestricted_p:
13040 )
13041 }
13042 {
13043 % \end{macrocode}
13044 % \begin{markdown}
13045 %
13046 % Set most catcodes to category 12 (other) to ensure that special characters in
13047 % the output directory name such as backslashes (`\`) are not interpreted as
13048 % control sequences.
13049 %
13050 % \end{markdown}
13051 % \begin{macrocode}
13052 \group_begin:
13053 \cctab_select:N
13054 \c_str_cctab
13055 \luabridge_tl_set:Nn
13056 \l_tmpa_tl
13057 {
13058 print(
13059 (status.output_directory)
13060 or~os.getenv("TEXMF_OUTPUT_DIRECTORY")
13061 or~"."
13062 )
13063 }
13064 \tl_gset:NV
13065 \markdownOptionOutputDir
13066 \l_tmpa_tl
13067 \group_end:
13068 }
13069 {
13070 \tl_gset:Nn
13071 \markdownOptionOutputDir
13072 { . }
13073 }
13074 }
13075 }
13076 \cs_new:Nn
13077 \@@_set_option_value:nn
13078 {
13079 \@@_define_option:n
13080 { #1 }
13081 \@@_get_option_type:nN
13082 { #1 }
13083 \l_tmpa_tl
13084 \str_if_eq:NNTF
13085 \c_@@_option_type_counter_tl
13086 \l_tmpa_tl
13087 {
13088 \@@_option_tl_to_csname:nN
13089 { #1 }
13090 \l_tmpa_tl
13091 \int_gset:cn
13092 { \l_tmpa_tl }
13093 { #2 }
13094 }
13095 {
13096 \@@_option_tl_to_csname:nN
13097 { #1 }
13098 \l_tmpa_tl
13099 \cs_set:cpn
13100 { \l_tmpa_tl }
13101 { #2 }
13102 }
13103 }
13104 \cs_new:Nn
13105 \@@_prepend_option_value:nn
13106 {
13107 \@@_get_option_value:nN
13108 { #1 }
13109 \l_tmpa_clist
13110 \clist_put_left:Nn
13111 \l_tmpa_clist
13112 { #2 }
13113 \@@_set_option_value:nV
13114 { #1 }
13115 \l_tmpa_clist
13116 }
13117 \cs_new:Nn
13118 \@@_append_option_value:nn
13119 {
13120 \@@_get_option_value:nN
13121 { #1 }
13122 \l_tmpa_clist
13123 \clist_put_right:Nn
13124 \l_tmpa_clist
13125 { #2 }
13126 \@@_set_option_value:nV
13127 { #1 }
13128 \l_tmpa_clist
13129 }
13130 \cs_generate_variant:Nn
13131 \@@_set_option_value:nn
13132 { nV }
13133 \cs_new:Nn
13134 \@@_define_option:n
13135 {
13136 \@@_option_tl_to_csname:nN
13137 { #1 }
13138 \l_tmpa_tl
13139 \cs_if_free:cT
13140 { \l_tmpa_tl }
13141 {
13142 \@@_get_option_type:nN
13143 { #1 }
13144 \l_tmpb_tl
13145 \str_if_eq:NNT
13146 \c_@@_option_type_counter_tl
13147 \l_tmpb_tl
13148 {
13149 \@@_option_tl_to_csname:nN
13150 { #1 }
13151 \l_tmpa_tl
13152 \int_new:c
13153 { \l_tmpa_tl }
13154 }
13155 }
13156 }
13157 \cs_new:Nn
13158 \@@_define_option_keyval:nnn
13159 {
13160 \prop_get:cnN
13161 { g_@@_ #1 _option_types_prop }
13162 { #2 }
13163 \l_tmpa_tl
13164 \str_if_eq:VVTF
13165 \l_tmpa_tl
13166 \c_@@_option_type_boolean_tl
13167 {
13168 \keys_define:nn
13169 { markdown/options }
13170 {
13171 % \end{macrocode}
13172 % \begin{markdown}
13173 %
13174 % For boolean options, we also accept `yes` as an alias for
13175 % `true` and `no` as an alias for `false`.
13176 %
13177 % \end{markdown}
13178 % \begin{macrocode}
13179 #3 .code:n = {
13180 \tl_set:Nx
13181 \l_tmpa_tl
13182 {
13183 \str_case:nnF
13184 { ##1 }
13185 {
13186 { yes } { true }
13187 { no } { false }
13188 }
13189 { ##1 }
13190 }
13191 \@@_set_option_value:nV
13192 { #2 }
13193 \l_tmpa_tl
13194 },
13195 #3 .value_required:n = { false },
13196 #3 .default:n = { true },
13197 }
13198 }
13199 {
13200 \keys_define:nn
13201 { markdown/options }
13202 {
13203 #3 .value_required:n = { true },
13204 #3 .code:n = {
13205 \@@_set_option_value:nn
13206 { #2 }
13207 { ##1 }
13208 },
13209 }
13210 }
13211 % \end{macrocode}
13212 % \begin{markdown}
13213 %
13214 % For comma-list options, we assume that \meta{key} is a regular English
13215 % noun in plural (such as `extensions`) and we also define the
13216 % \meta{singular key}`=`\meta{value} interface, where \meta{singular key} is
13217 % \meta{key} after stripping the trailing -s (such as `extension`). Rather
13218 % than setting the option to \meta{value}, this interface appends \meta{value}
13219 % to the current value as the rightmost item in the list.
13220 %
13221 % \end{markdown}
13222 % \begin{macrocode}
13223 \str_if_eq:VVT
13224 \l_tmpa_tl
13225 \c_@@_option_type_clist_tl
13226 {
13227 \tl_set:Nn
13228 \l_tmpa_tl
13229 { #3 }
13230 \tl_reverse:N
13231 \l_tmpa_tl
13232 \str_if_eq:enF
13233 {
13234 \tl_head:V
13235 \l_tmpa_tl
13236 }
13237 { s }
13238 {
13239 \msg_error:nnn
13240 { markdown }
13241 { malformed-name-for-clist-option }
13242 { #3 }
13243 }
13244 \tl_set:Nx
13245 \l_tmpa_tl
13246 {
13247 \tl_tail:V
13248 \l_tmpa_tl
13249 }
13250 \tl_reverse:N
13251 \l_tmpa_tl
13252 \tl_set_eq:NN
13253 \l_tmpb_tl
13254 \l_tmpa_tl
13255 \tl_put_right:Nn
13256 \l_tmpa_tl
13257 { .value_required:n = { true } }
13258 \tl_put_right:Nn
13259 \l_tmpb_tl
13260 {
13261 .code:n = {
13262 \@@_append_option_value:nn
13263 { #2 }
13264 { ##1 }
13265 }
13266 }
13267 \keys_define:nV
13268 { markdown/options }
13269 \l_tmpa_tl
13270 \keys_define:nV
13271 { markdown/options }
13272 \l_tmpb_tl
13273 % \end{macrocode}
13274 % \begin{markdown}
13275 %
13276 % To achieve parity with token renderers and renderer prototypes (see sections
13277 % <#sec:plain-tex-renderers> and <#sec:plain-tex-renderer-prototypes>,
13278 % respectively) the syntax
13279 % \meta{key}`+=`\meta{value} and
13280 % \meta{key}`$=`\meta{value} with the same appending semantics as
13281 % \meta{singular key}`=`\meta{value} is also supported.
13282 %
13283 % \end{markdown}
13284 % \begin{macrocode}
13285 \keys_define:nn
13286 { markdown/options }
13287 {
13288 #3~+ .value_required:n = { true },
13289 #3~+ .code:n = {
13290 \@@_append_option_value:nn
13291 { #2 }
13292 { ##1 }
13293 },
13294 #3 + .value_required:n = { true },
13295 #3 + .code:n = {
13296 \@@_append_option_value:nn
13297 { #2 }
13298 { ##1 }
13299 },
13300 #3~$ .value_required:n = { true },
13301 #3~$ .code:n = {
13302 \@@_append_option_value:nn
13303 { #2 }
13304 { ##1 }
13305 },
13306 #3 $ .value_required:n = { true },
13307 #3 $ .code:n = {
13308 \@@_append_option_value:nn
13309 { #2 }
13310 { ##1 }
13311 },
13312 % \end{macrocode}
13313 % \begin{markdown}
13314 %
13315 % Furthermore, similar to token renderers and renderer prototypes, the syntax
13316 % \meta{key}`^=`\meta{value} is also supported. This syntax prepends
13317 % \meta{value} to the current value as the leftmost item in the list.
13318 %
13319 % \end{markdown}
13320 % \begin{macrocode}
13321 #3~^ .value_required:n = { true },
13322 #3~^ .code:n = {
13323 \@@_prepend_option_value:nn
13324 { #2 }
13325 { ##1 }
13326 },
13327 #3 ^ .value_required:n = { true },
13328 #3 ^ .code:n = {
13329 \@@_prepend_option_value:nn
13330 { #2 }
13331 { ##1 }
13332 },
13333 }
13334 }
13335 }
13336 \cs_generate_variant:Nn
13337 \clist_set:Nn
13338 { NV }
13339 \cs_generate_variant:Nn
13340 \keys_define:nn
13341 { nV }
13342 \prg_generate_conditional_variant:Nnn
13343 \str_if_eq:nn
13344 { en }
13345 { p, F }
13346 \msg_new:nnn
13347 { markdown }
13348 { malformed-name-for-clist-option }
13349 {
13350 Clist~option~name~#1~does~not~end~with~-s.
13351 }
13352 % \end{macrocode}
13353 % \begin{markdown}
13354 %
13355 % If plain \TeX{} is the top layer, we use the
13356 % \mref{@@_define_option_commands_and_keyvals:} macro to define plain \TeX{}
13357 % option macros and key--values immediately. Otherwise, we
13358 % postpone the definition until the upper layers have been loaded.
13359 %
13360 % \end{markdown}
13361 % \begin{macrocode}
13362 \str_if_eq:VVT
13363 \c_@@_top_layer_tl
13364 \c_@@_option_layer_plain_tex_tl
13365 {
13366 \@@_define_option_commands_and_keyvals:
13367 }
13368 \ExplSyntaxOff
13369 % \end{macrocode}
13370 % \iffalse
13371 %</tex>
13372 %<*manual-options>
13373 % \fi
13374 % \begin{markdown}
13375
13376 %### Themes {#themes}
13377 % \iffalse
13378 #### Themes {#themes}
13379 % \fi
13380
13381 User-defined themes for the Markdown package provide a domain-specific
13382 interpretation of Markdown tokens. Themes allow the authors to achieve
13383 a specific look and other high-level goals without low-level programming.
13384
13385 % The key--values `theme`=\meta{theme name} and `import`=\meta{theme name},
13386 % optionally followed by `@`\meta{theme version}, load a \TeX{} document
13387 % (further referred to as *a theme*) named `markdowntheme`\meta{munged theme
13388 % name}`.tex`, where the *munged theme name* is the *theme name* after the
13389 % substitution of all forward slashes (`/`) for an underscore (`_`).
13390 % The theme name must be *qualified* and contain no underscores or at signs
13391 % (`@`). Themes are inspired by the Beamer \LaTeX{} package, which provides
13392 % similar functionality with its `\usetheme` macro [@tantau21, Section 15.1].
13393 %
13394 % A theme name is qualified if and only if it contains at least one forward
13395 % slash. Theme names must be qualified to minimize naming conflicts between
13396 % different themes with a similar purpose. The preferred format of a theme name
13397 % is \meta{theme author}`/`\meta{theme purpose}`/`\meta{private naming scheme},
13398 % where the *private naming scheme* may contain additional forward slashes. For
13399 % example, a theme by a user `witiko` for the MU theme of the Beamer document
13400 % class may have the name `witiko/beamer/MU`.
13401 %
13402 % Theme names are munged to allow structure inside theme names without
13403 % dictating where the themes should be located inside the \TeX{} directory
13404 % structure. For example, loading a theme named `witiko/beamer/MU` would
13405 % load a \TeX{} document package named `markdownthemewitiko_beamer_MU.tex`.
13406 %
13407 % If `@`\meta{theme version} is specified after \meta{theme name}, then the
13408 % text *theme version* will be available in the macro
13409 % \mdef{markdownThemeVersion} when the theme is loaded. If `@`\meta{theme
13410 % version} is not specified, the macro \mref{markdownThemeVersion} will
13411 % contain the text `latest` [@novotny24].
13412 %
13413 % \end{markdown}
13414 % \iffalse
13415 %</manual-options>
13416 %<*tex>
13417 % \fi
13418 % \begin{macrocode}
13419 \ExplSyntaxOn
13420 \keys_define:nn
13421 { markdown/options }
13422 {
13423 theme .value_required:n = { true },
13424 theme .code:n = {
13425 \@@_set_theme:n
13426 { #1 }
13427 },
13428 import .value_required:n = { true },
13429 import .code:n = {
13430 \tl_set:Nn
13431 \l_tmpa_tl
13432 { #1 }
13433 % \end{macrocode}
13434 % \begin{markdown}
13435 %
13436 % To ensure that keys containing forward slashes get passed correctly, we
13437 % replace all forward slashes in the input with backslash tokens with category
13438 % code letter and then undo the replacement. This means that if any unbraced
13439 % backslash tokens with category code letter exist in the input, they will be
13440 % replaced with forward slashes. However, this should be extremely rare.
13441 %
13442 % \end{markdown}
13443 % \begin{macrocode}
13444 \tl_replace_all:NnV
13445 \l_tmpa_tl
13446 { / }
13447 \c_backslash_str
13448 \keys_set:nV
13449 { markdown/options/import }
13450 \l_tmpa_tl
13451 },
13452 }
13453 % \end{macrocode}
13454 % \begin{markdown}
13455 %
13456 % To keep track of the current theme when themes are nested, we will
13457 % maintain the stacks \mdef{g_\@\@_theme_names_seq} and
13458 % \mdef{g_\@\@_theme_versions_seq} stack of theme names and versions,
13459 % respectively. For convenience, the name of the current theme and version is
13460 % also available in the macros \mdef{g_@@_current_theme_tl} and
13461 % \mref{markdownThemeVersion}, respectively.
13462 %
13463 % \end{markdown}
13464 % \begin{macrocode}
13465 \seq_new:N
13466 \g_@@_theme_names_seq
13467 \seq_new:N
13468 \g_@@_theme_versions_seq
13469 \tl_new:N
13470 \g_@@_current_theme_tl
13471 \tl_gset:Nn
13472 \g_@@_current_theme_tl
13473 { }
13474 \seq_gput_right:NV
13475 \g_@@_theme_names_seq
13476 \g_@@_current_theme_tl
13477 \cs_new:Npn
13478 \markdownThemeVersion
13479 { }
13480 \seq_gput_right:NV
13481 \g_@@_theme_versions_seq
13482 \g_@@_current_theme_tl
13483 \cs_new:Nn
13484 \@@_set_theme:n
13485 {
13486 % \end{macrocode}
13487 % \begin{markdown}
13488 %
13489 % First, we validate the theme name.
13490 %
13491 % \end{markdown}
13492 % \begin{macrocode}
13493 \str_if_in:nnF
13494 { #1 }
13495 { / }
13496 {
13497 \msg_error:nnn
13498 { markdown }
13499 { unqualified-theme-name }
13500 { #1 }
13501 }
13502 \str_if_in:nnT
13503 { #1 }
13504 { _ }
13505 {
13506 \msg_error:nnn
13507 { markdown }
13508 { underscores-in-theme-name }
13509 { #1 }
13510 }
13511 % \end{macrocode}
13512 % \begin{markdown}
13513 %
13514 % Next, we extract the theme version.
13515 %
13516 % \end{markdown}
13517 % \begin{macrocode}
13518 \str_if_in:nnTF
13519 { #1 }
13520 { @ }
13521 {
13522 \regex_extract_once:nnN
13523 { (.*) @ (.*) }
13524 { #1 }
13525 \l_tmpa_seq
13526 \seq_gpop_left:NN
13527 \l_tmpa_seq
13528 \l_tmpa_tl
13529 \seq_gpop_left:NN
13530 \l_tmpa_seq
13531 \l_tmpa_tl
13532 \tl_gset:NV
13533 \g_@@_current_theme_tl
13534 \l_tmpa_tl
13535 \seq_gpop_left:NN
13536 \l_tmpa_seq
13537 \l_tmpa_tl
13538 \cs_gset:Npe
13539 \markdownThemeVersion
13540 {
13541 \tl_use:N
13542 \l_tmpa_tl
13543 }
13544 }
13545 {
13546 \tl_gset:Nn
13547 \g_@@_current_theme_tl
13548 { #1 }
13549 \cs_gset:Npn
13550 \markdownThemeVersion
13551 { latest }
13552 }
13553 % \end{macrocode}
13554 % \begin{markdown}
13555 %
13556 % Next, we strip a leading slash, if present, for consistency with snippets,
13557 % where a leading slash distinguishes absolute snippet names from relative
13558 % ones. Theme names, however, are currently always absolute, so stripping the
13559 % slash is only a syntactic normalization and has no semantic effect.
13560 %
13561 % \end{markdown}
13562 % \begin{macrocode}
13563 \str_if_eq:enT
13564 {
13565 \tl_head:V
13566 \g_@@_current_theme_tl
13567 }
13568 { / }
13569 {
13570 \tl_gset:Ne
13571 \g_@@_current_theme_tl
13572 {
13573 \tl_tail:V
13574 \g_@@_current_theme_tl
13575 }
13576 }
13577 % \end{macrocode}
13578 % \begin{markdown}
13579 %
13580 % Next, we munge the theme name.
13581 %
13582 % \end{markdown}
13583 % \begin{macrocode}
13584 \str_set:NV
13585 \l_tmpa_str
13586 \g_@@_current_theme_tl
13587 \str_replace_all:Nnn
13588 \l_tmpa_str
13589 { / }
13590 { _ }
13591 % \end{macrocode}
13592 % \begin{markdown}
13593 %
13594 % Finally, we load the theme. Before loading the theme, we push down the
13595 % current name and version of the theme on the stack.
13596 %
13597 % \end{markdown}
13598 % \begin{macrocode}
13599 \tl_set:NV
13600 \l_tmpa_tl
13601 \g_@@_current_theme_tl
13602 \tl_put_right:Nn
13603 \g_@@_current_theme_tl
13604 { / }
13605 \seq_gput_right:NV
13606 \g_@@_theme_names_seq
13607 \g_@@_current_theme_tl
13608 \seq_gput_right:NV
13609 \g_@@_theme_versions_seq
13610 \markdownThemeVersion
13611 \@@_load_theme:VeV
13612 \l_tmpa_tl
13613 { \markdownThemeVersion }
13614 \l_tmpa_str
13615 % \end{macrocode}
13616 % \begin{markdown}
13617 %
13618 % After the theme has been loaded, we recover the name and version of the
13619 % previous theme from the stack.
13620 %
13621 % \end{markdown}
13622 % \begin{macrocode}
13623 \seq_gpop_right:NN
13624 \g_@@_theme_names_seq
13625 \l_tmpa_tl
13626 \seq_get_right:NN
13627 \g_@@_theme_names_seq
13628 \l_tmpa_tl
13629 \tl_gset:NV
13630 \g_@@_current_theme_tl
13631 \l_tmpa_tl
13632 \seq_gpop_right:NN
13633 \g_@@_theme_versions_seq
13634 \l_tmpa_tl
13635 \seq_get_right:NN
13636 \g_@@_theme_versions_seq
13637 \l_tmpa_tl
13638 \cs_gset:Npe
13639 \markdownThemeVersion
13640 {
13641 \tl_use:N
13642 \l_tmpa_tl
13643 }
13644 }
13645 \msg_new:nnnn
13646 { markdown }
13647 { unqualified-theme-name }
13648 { Won't~load~theme~with~unqualified~name~#1 }
13649 { Theme~names~must~contain~at~least~one~forward~slash }
13650 \msg_new:nnnn
13651 { markdown }
13652 { underscores-in-theme-name }
13653 { Won't~load~theme~with~an~underscore~in~its~name~#1 }
13654 { Theme~names~must~not~contain~underscores~in~their~names }
13655 \cs_generate_variant:Nn
13656 \tl_replace_all:Nnn
13657 { NnV }
13658 \cs_generate_variant:Nn
13659 \cs_gset:Npn
13660 { Npe }
13661 \prg_generate_conditional_variant:Nnn
13662 \str_if_eq:nn
13663 { en }
13664 { T }
13665 % \end{macrocode}
13666 % \begin{markdown}
13667 %
13668 % We also define the prop \mdef{g_@@_plain_tex_built_in_themes_prop} that
13669 % contains the code of built-in themes. This is a packaging optimization,
13670 % so that built-in themes does not need to be distributed in many small files.
13671 %
13672 % \end{markdown}
13673 % \begin{macrocode}
13674 \prop_new:N
13675 \g_@@_plain_tex_built_in_themes_prop
13676 % \end{macrocode}
13677 % \iffalse
13678 %</tex>
13679 %<*manual-options>
13680 % \fi
13681 % \markdownBegin
13682
13683 Built-in plain \TeX{} themes provided with the Markdown package include:
13684
13685 \pkg{witiko/diagrams}
13686
13687 : A theme that typesets fenced code blocks with the infostrings
13688 `dot`, `mermaid`, and `plantuml` as figures with diagrams produced with
13689 the command `dot` from Graphviz tools, the command `mmdc` from the npm
13690 package `@mermaid-js/mermaid-cli`, and the command `plantuml` from the
13691 package PlantUML, respectively.
13692
13693 The key-value attribute `caption` can be used to specify the caption of
13694 the figure and for the infostrings `dot` and `plantuml`, the key-value
13695 attribute `format` can be used to specify the output image format. The
13696 remaining attributes are treated as image attributes.
13697
13698 % ```` tex
13699 % \documentclass{article}
13700 % \usepackage[relativeReferences, texComments]{markdown}
13701 % \markdownSetup{import=witiko/diagrams@v2}
13702 % \begin{document}
13703 % \begin{markdown}
13704 % ``` dot {caption="An example directed graph" \%
13705 format=svg width=12cm #dot}
13706 % digraph tree {
13707 % margin = 0;
13708 % rankdir = "LR";
13709 %
13710 % latex -> pmml;
13711 % latex -> cmml;
13712 % pmml -> slt;
13713 % cmml -> opt;
13714 % cmml -> prefix;
13715 % cmml -> infix;
13716 % pmml -> mterms [style=dashed];
13717 % cmml -> mterms;
13718 %
13719 % latex [label = "LaTeX"];
13720 % pmml [label = "Presentation MathML"];
13721 % cmml [label = "Content MathML"];
13722 % slt [label = "Symbol Layout Tree"];
13723 % opt [label = "Operator Tree"];
13724 % prefix [label = "Prefix"];
13725 % infix [label = "Infix"];
13726 % mterms [label = "M-Terms"];
13727 % }
13728 % ```
13729 %
13730 % ``` mermaid {caption="An example mindmap" \%
13731 width=9cm #mermaid}
13732 % mindmap
13733 % root )base-idea(
13734 % sub<br/>idea 1
13735 % ((?))
13736 % sub<br/>idea 2
13737 % ((?))
13738 % sub<br/>idea 3
13739 % ((?))
13740 % sub<br/>idea 4
13741 % ((?))
13742 % ```
13743 %
13744 % ``` plantuml {caption="An example UML sequence diagram" \%
13745 width=7cm #plantuml}
13746 % @startuml
13747 % ' Define participants (actors)
13748 % participant "Client" as C
13749 % participant "Server" as S
13750 % participant "Database" as DB
13751 %
13752 % ' Diagram title
13753 % title Simple Request-Response Flow
13754 %
13755 % ' Messages
13756 % C -> S: Send Request
13757 % note over S: Process request
13758 %
13759 % alt Request is valid
13760 % S -> DB: Query Data
13761 % DB -> S: Return Data
13762 % S -> C: Respond with Data
13763 % else Request is invalid
13764 % S -> C: Return Error
13765 % end
13766 % @enduml
13767 % ```
13768 %
13769 % See the diagrams in figures <#dot>, <#mermaid>, and <#plantuml>.
13770 % \end{markdown}
13771 % \end{document}
13772 % ````````
13773 %
13774 % Typesetting the above document produces the output shown in
13775 % figures <#fig:witiko-diagrams-dot>, <#fig:witiko-diagrams-mermaid>, and
13776 % <#fig:witiko-diagrams-plantuml>.
13777 %
13778 % ``` dot {caption="An example directed graph" format=svg #fig:witiko-diagrams-dot}
13779 % digraph tree {
13780 % margin = 0;
13781 % rankdir = "LR";
13782 %
13783 % latex -> pmml;
13784 % latex -> cmml;
13785 % pmml -> slt;
13786 % cmml -> opt;
13787 % cmml -> prefix;
13788 % cmml -> infix;
13789 % pmml -> mterms [style=dashed];
13790 % cmml -> mterms;
13791 %
13792 % latex [label = "LaTeX"];
13793 % pmml [label = "Presentation MathML"];
13794 % cmml [label = "Content MathML"];
13795 % slt [label = "Symbol Layout Tree"];
13796 % opt [label = "Operator Tree"];
13797 % prefix [label = "Prefix"];
13798 % infix [label = "Infix"];
13799 % mterms [label = "M-Terms"];
13800 % }
13801 % ```
13802 %
13803 % ``` mermaid {caption="An example mindmap" #fig:witiko-diagrams-mermaid}
13804 % mindmap
13805 % root )base-idea(
13806 % sub<br/>idea 1
13807 % ((?))
13808 % sub<br/>idea 2
13809 % ((?))
13810 % sub<br/>idea 3
13811 % ((?))
13812 % sub<br/>idea 4
13813 % ((?))
13814 % ```
13815 %
13816 % ``` plantuml {caption="An example UML sequence diagram" #fig:witiko-diagrams-plantuml}
13817 % @startuml
13818 % ' Define participants (actors)
13819 % participant "Client" as C
13820 % participant "Server" as S
13821 % participant "Database" as DB
13822 %
13823 % ' Diagram title
13824 % title Simple Request-Response Flow
13825 %
13826 % ' Messages
13827 % C -> S: Send Request
13828 % note over S: Process request
13829 %
13830 % alt Request is valid
13831 % S -> DB: Query Data
13832 % DB -> S: Return Data
13833 % S -> C: Respond with Data
13834 % else Request is invalid
13835 % S -> C: Return Error
13836 % end
13837 % @enduml
13838 % ```
13839
13840 The theme requires a Unix-like operating system with GNU Diffutils,
13841 Graphviz, the npm package `@mermaid-js/mermaid-cli`, and PlantUML
13842 installed. All these packages are already included in the Docker image
13843 `witiko/markdown`; consult `Dockerfile` to see how they are installed.
13844 The theme also requires shell access unless the \Opt{frozenCache} plain
13845 \TeX{} option is enabled.
13846
13847 % \markdownEnd
13848 % \iffalse
13849
13850 ##### \LaTeX{} Example {.unnumbered}
13851
13852 Using a text editor, create a text document named `document.tex` with the
13853 following content:
13854 ```` tex
13855 \documentclass{article}
13856 \usepackage[import=witiko/diagrams@v2, relativeReferences]{markdown}
13857 \begin{document}
13858 \begin{markdown}
13859 ``` dot {caption="An example directed graph" width=12cm #dot}
13860 digraph tree {
13861 margin = 0;
13862 rankdir = "LR";
13863
13864 latex -> pmml;
13865 latex -> cmml;
13866 pmml -> slt;
13867 cmml -> opt;
13868 cmml -> prefix;
13869 cmml -> infix;
13870 pmml -> mterms [style=dashed];
13871 cmml -> mterms;
13872
13873 latex [label = "LaTeX"];
13874 pmml [label = "Presentation MathML"];
13875 cmml [label = "Content MathML"];
13876 slt [label = "Symbol Layout Tree"];
13877 opt [label = "Operator Tree"];
13878 prefix [label = "Prefix"];
13879 infix [label = "Infix"];
13880 mterms [label = "M-Terms"];
13881 }
13882 ```
13883
13884 ``` mermaid {caption="An example mindmap" width=9cm #mermaid}
13885 mindmap
13886 root )base-idea(
13887 sub<br/>idea 1
13888 ((?))
13889 sub<br/>idea 2
13890 ((?))
13891 sub<br/>idea 3
13892 ((?))
13893 sub<br/>idea 4
13894 ((?))
13895 ```
13896
13897 ``` plantuml {caption="An example UML sequence diagram" width=7cm #plantuml}
13898 @startuml
13899 ' Define participants (actors)
13900 participant "Client" as C
13901 participant "Server" as S
13902 participant "Database" as DB
13903
13904 ' Diagram title
13905 title Simple Request-Response Flow
13906
13907 ' Messages
13908 C -> S: Send Request
13909 note over S: Process request
13910
13911 alt Request is valid
13912 S -> DB: Query Data
13913 DB -> S: Return Data
13914 S -> C: Respond with Data
13915 else Request is invalid
13916 S -> C: Return Error
13917 end
13918 @enduml
13919 ```
13920
13921 See the diagrams in figures <#dot>, <#mermaid>, and <#plantuml>.
13922 \end{markdown}
13923 \end{document}
13924 ````````
13925 Next, invoke LuaTeX from the terminal:
13926 ``` sh
13927 lualatex --shell-escape document.tex
13928 ``````
13929 A PDF document named `document.pdf` should be produced and contain
13930 three diagrams.
13931
13932 % \fi
13933 % \begin{markdown}
13934
13935 \pkg{witiko/glossaries}
13936
13937 : A theme that defines snippets with integrations for the \LaTeX{} package
13938 % \pkg{glossaries}. See Section <#sec:latexsnippets> for more details.
13939 % \iffalse
13940 \pkg{glossaries}.
13941 % \fi
13942
13943 % \end{markdown}
13944 % \markdownBegin
13945
13946 \pkg{witiko/graphicx/http}
13947
13948 : A theme that adds support for downloading images whose URL has the
13949 HTTP or HTTPS protocol.
13950 % ``` tex
13951 % \documentclass{article}
13952 % \usepackage[import=witiko/graphicx/http]{markdown}
13953 % \begin{document}
13954 % \begin{markdown}
13955 % ![img](https://github.com/witiko/markdown/raw/main/markdown.png
13956 % "The banner of the Markdown package")
13957 % \end{markdown}
13958 % \end{document}
13959 % ```````
13960 % Typesetting the above document produces the output shown in
13961 % Figure <#fig:witiko-graphicx-http>.
13962 % ![img](https://github.com/witiko/markdown/raw/main/markdown.png
13963 % "The banner of the Markdown package"){#fig:witiko-graphicx-http}
13964 The theme requires the \pkg{catchfile} \LaTeX{} package and a Unix-like
13965 operating system with GNU Coreutils `md5sum` and either GNU Wget or cURL
13966 installed. The theme also requires shell access unless the
13967 \Opt{frozenCache} plain \TeX{} option is enabled.
13968
13969 % \markdownEnd
13970 % \iffalse
13971
13972 ##### \LaTeX{} Example {.unnumbered}
13973
13974 Using a text editor, create a text document named `document.tex` with the
13975 following content:
13976 ``` tex
13977 \documentclass{article}
13978 \usepackage[import=witiko/graphicx/http, link_attributes]{markdown}
13979 \begin{document}
13980 \begin{markdown}
13981 ![img](https://github.com/witiko/markdown/raw/main/markdown.png
13982 "The banner of the Markdown package"){width=5in}
13983 \end{markdown}
13984 \end{document}
13985 ```````
13986 Next, invoke LuaTeX from the terminal:
13987 ``` sh
13988 lualatex --shell-escape document.tex
13989 ``````
13990 A PDF document named `document.pdf` should be produced and contain the
13991 following image:
13992
13993 > ![Figure 1: The banner of the Markdown package](https://github.com/witiko/markdown/raw/main/markdown.png)
13994
13995 % \fi
13996 % \begin{markdown}
13997
13998 \pkg{witiko/tilde}
13999
14000 : A theme that makes tilde (`~`) always typeset the non-breaking space even
14001 when the \Opt{hybrid} Lua option is disabled.
14002 % ``` tex
14003 % \input markdown
14004 % \markdownSetup{import=witiko/tilde}
14005 % \markdownBegin
14006 % Bartel~Leendert van~der~Waerden
14007 % \markdownEnd
14008 % \bye
14009 % ```````
14010 % Typesetting the above document produces the following text:
14011 % “Bartel~Leendert van~der~Waerden”.
14012 %
14013 % \end{markdown}
14014 % \iffalse
14015
14016 ##### Plain \TeX{} Example {.unnumbered}
14017
14018 Using a text editor, create a text document named `document.tex` with the
14019 following content:
14020 ``` tex
14021 \input markdown
14022 \markdownSetup{import=witiko/tilde}
14023 \markdownBegin
14024 Bartel~Leendert van~der~Waerden
14025 \markdownEnd
14026 \bye
14027 ```````
14028 Next, invoke LuaTeX from the terminal:
14029 ``` sh
14030 luatex document.tex
14031 ``````
14032 A PDF document named `document.pdf` should be produced and contain the
14033 following text, where the middot (`·`) denotes a non-breaking space:
14034
14035 > Bartel·Leendert van·der·Waerden
14036
14037 % \fi
14038 % \begin{markdown}
14039
14040 \pkg{witiko/markdown/defaults}
14041
14042 : A plain \TeX{} theme with the default definitions of token renderer
14043 prototypes for plain \TeX{}. This theme is loaded automatically together
14044 with the package and explicitly loading it has no effect.
14045
14046 % See Section <#sec:themes-implementation> for implementation details of the
14047 % built-in plain \TeX{} themes.
14048 %
14049 %### Snippets {#snippets}
14050 % \iffalse
14051 #### Snippets {#snippets}
14052 % \fi
14053
14054 % \end{markdown}
14055 % \iffalse
14056
14057 User-defined themes provide global control over high-level goals.
14058 However, it is often desirable to change only some local aspects of a document.
14059 Snippets provide syntactic sugar for defining and invoking various
14060 options locally.
14061
14062 %</manual-options>
14063 %<*tex>
14064 % \fi
14065 % \begin{markdown}
14066 %
14067 % We may set up options as *snippets* using the
14068 % \mdef{markdownSetupSnippet} macro and invoke them later. The
14069 % \mref{markdownSetupSnippet} macro receives two arguments: the name
14070 % of the snippet and the options to store.
14071 %
14072 % \end{markdown}
14073 % \begin{macrocode}
14074 \prop_new:N
14075 \g_@@_snippets_prop
14076 \cs_new:Nn
14077 \@@_setup_snippet:nn
14078 {
14079 \tl_if_empty:nT
14080 { #1 }
14081 {
14082 \msg_error:nnn
14083 { markdown }
14084 { empty-snippet-name }
14085 { #1 }
14086 }
14087 \@@_resolve_snippet_name:nN
14088 { #1 }
14089 \l_tmpa_tl
14090 \@@_if_snippet_exists:nT
14091 { #1 }
14092 {
14093 \msg_warning:nnV
14094 { markdown }
14095 { redefined-snippet }
14096 \l_tmpa_tl
14097 }
14098 \keys_precompile:nnN
14099 { markdown/options }
14100 { #2 }
14101 \l_tmpb_tl
14102 \prop_gput:NVV
14103 \g_@@_snippets_prop
14104 \l_tmpa_tl
14105 \l_tmpb_tl
14106 }
14107 \cs_gset_eq:NN
14108 \markdownSetupSnippet
14109 \@@_setup_snippet:nn
14110 \msg_new:nnnn
14111 { markdown }
14112 { empty-snippet-name }
14113 { Empty~snippet~name~#1 }
14114 { Pick~a~non-empty~name~for~your~snippet }
14115 \msg_new:nnn
14116 { markdown }
14117 { redefined-snippet }
14118 { Redefined~snippet~#1 }
14119 % \end{macrocode}
14120 % \begin{markdown}
14121 %
14122 % To decide whether a snippet exists, we can use the
14123 % \mdef{markdownIfSnippetExists} macro.
14124 %
14125 % \end{markdown}
14126 % \begin{macrocode}
14127 \tl_new:N
14128 \l_@@_current_snippet_tl
14129 \prg_new_conditional:Nnn
14130 \@@_if_snippet_exists:n
14131 { TF, T }
14132 {
14133 \@@_resolve_snippet_name:nN
14134 { #1 }
14135 \l_@@_current_snippet_tl
14136 \prop_if_in:NVTF
14137 \g_@@_snippets_prop
14138 \l_@@_current_snippet_tl
14139 { \prg_return_true: }
14140 { \prg_return_false: }
14141 }
14142 \cs_gset_eq:NN
14143 \markdownIfSnippetExists
14144 \@@_if_snippet_exists:nTF
14145 \cs_new:Nn
14146 \@@_resolve_snippet_name:nN
14147 {
14148 % \end{macrocode}
14149 % \begin{markdown}
14150 %
14151 % If the provided snippet name starts with a slash (`/`), consider it as
14152 % *absolute* and take the rest of the name as the full name of the defined
14153 % snippet, regardless of the currently processed theme.
14154 %
14155 % \end{markdown}
14156 % \begin{macrocode}
14157 \str_if_eq:enTF
14158 {
14159 \tl_head:n
14160 { #1 }
14161 }
14162 { / }
14163 {
14164 \tl_set:Ne
14165 #2
14166 {
14167 \tl_tail:n
14168 { #1 }
14169 }
14170 }
14171 {
14172 % \end{macrocode}
14173 % \begin{markdown}
14174 %
14175 % Otherwise, consider the provided snippet name as *relative* and
14176 % prepend the name of the currently processed theme to it, if any.
14177 % The result is then the full name of the defined snippet.
14178 %
14179 % \end{markdown}
14180 % \begin{macrocode}
14181 \tl_set:NV
14182 #2
14183 \g_@@_current_theme_tl
14184 \tl_put_right:Nn
14185 #2
14186 { #1 }
14187 }
14188 }
14189 \prg_generate_conditional_variant:Nnn
14190 \str_if_eq:nn
14191 { en }
14192 { TF }
14193 % \end{macrocode}
14194 % \begin{markdown}
14195 %
14196 % The option with key `snippet` invokes a snippet named \meta{value}.
14197 %
14198 % \end{markdown}
14199 % \begin{macrocode}
14200 \keys_define:nn
14201 { markdown/options }
14202 {
14203 snippet .value_required:n = { true },
14204 snippet .code:n = {
14205 \@@_resolve_snippet_name:nN
14206 { #1 }
14207 \l_tmpa_tl
14208 \@@_if_snippet_exists:nTF
14209 { #1 }
14210 {
14211 \prop_get:NVN
14212 \g_@@_snippets_prop
14213 \l_tmpa_tl
14214 \l_tmpb_tl
14215 \tl_use:N
14216 \l_tmpb_tl
14217 }
14218 {
14219 \msg_error:nnV
14220 { markdown }
14221 { undefined-snippet }
14222 \l_tmpa_tl
14223 }
14224 },
14225 }
14226 \msg_new:nnn
14227 { markdown }
14228 { undefined-snippet }
14229 { Can't~invoke~undefined~snippet~#1 }
14230 \ExplSyntaxOff
14231 % \end{macrocode}
14232 % \iffalse
14233 %</tex>
14234 %<*manual-options>
14235 % \fi
14236 % \markdownBegin
14237
14238 Here is how we can use snippets to store options and invoke them later
14239 in \LaTeX{}:
14240
14241 ``` tex
14242 \markdownSetupSnippet{romanNumerals}{
14243 renderers = {
14244 olItemWithNumber = {%
14245 \item[\romannumeral#1\relax.]%
14246 },
14247 },
14248 }
14249 \begin{markdown}
14250
14251 The following ordered list will be preceded by arabic numerals:
14252
14253 1. wahid
14254 2. aithnayn
14255
14256 \end{markdown}
14257 \begin{markdown}[snippet=romanNumerals]
14258
14259 The following ordered list will be preceded by roman numerals:
14260
14261 3. tres
14262 4. quattuor
14263
14264 \end{markdown}
14265 ```````
14266
14267 If the `romanNumerals` snippet were defined in the `jdoe/lists` theme,
14268 we could import the `jdoe/lists` theme and use the qualified name
14269 `jdoe/lists/romanNumerals` to invoke the snippet:
14270
14271 ``` tex
14272 \markdownSetup{import=jdoe/lists}
14273 \begin{markdown}[snippet=jdoe/lists/romanNumerals]
14274
14275 The following ordered list will be preceded by roman numerals:
14276
14277 3. tres
14278 4. quattuor
14279
14280 \end{markdown}
14281 ```````
14282
14283 Alternatively, we can use the extended variant of the `import` \LaTeX{}
14284 option that allows us to import the `romanNumerals` snippet to the
14285 current namespace for easier access:
14286
14287 ``` tex
14288 \markdownSetup{
14289 import = {
14290 jdoe/lists = romanNumerals,
14291 },
14292 }
14293 \begin{markdown}[snippet=romanNumerals]
14294
14295 The following ordered list will be preceded by roman numerals:
14296
14297 3. tres
14298 4. quattuor
14299
14300 \end{markdown}
14301 ```````
14302
14303 Furthermore, we can also specify the name of the snippet in the current
14304 namespace, which can be different from the name of the snippet in the
14305 `jdoe/lists` theme. For example, we can make the snippet
14306 `jdoe/lists/romanNumerals` available under the name `roman`.
14307
14308 ``` tex
14309 \markdownSetup{
14310 import = {
14311 jdoe/lists = romanNumerals as roman,
14312 },
14313 }
14314 \begin{markdown}[snippet=roman]
14315
14316 The following ordered list will be preceded by roman numerals:
14317
14318 3. tres
14319 4. quattuor
14320
14321 \end{markdown}
14322 ```````
14323
14324 Several themes and/or snippets can be loaded at once using the extended
14325 variant of the `import` \LaTeX{} option:
14326
14327 ``` tex
14328 \markdownSetup{
14329 import = {
14330 jdoe/longpackagename/lists = {
14331 arabic as arabic1,
14332 roman,
14333 alphabetic,
14334 },
14335 jdoe/anotherlongpackagename/lists = {
14336 arabic as arabic2,
14337 },
14338 jdoe/yetanotherlongpackagename,
14339 },
14340 }
14341 ```````
14342
14343 % \markdownEnd
14344 % \iffalse
14345 %</manual-options>
14346 %<*tex>
14347 % \fi
14348 % \begin{macrocode}
14349 \ExplSyntaxOn
14350 \tl_new:N
14351 \l_@@_import_current_theme_tl
14352 \keys_define:nn
14353 { markdown/options/import }
14354 {
14355 % \end{macrocode}
14356 % \begin{markdown}
14357 %
14358 % If a theme name is given without a list of snippets to import,
14359 % we assume that an empty list was given.
14360 %
14361 % \end{markdown}
14362 % \begin{macrocode}
14363 unknown .value_required:n = { false },
14364 unknown .default:n = {},
14365 unknown .code:n = {
14366 % \end{macrocode}
14367 % \begin{markdown}
14368 %
14369 % To ensure that keys containing forward slashes get passed correctly, we
14370 % replace all forward slashes in the input with backslash tokens with category
14371 % code letter and then undo the replacement. This means that if any unbraced
14372 % backslash tokens with category code letter exist in the input, they will be
14373 % replaced with forward slashes. However, this should be extremely rare.
14374 %
14375 % \end{markdown}
14376 % \begin{macrocode}
14377 \tl_set_eq:NN
14378 \l_@@_import_current_theme_tl
14379 \l_keys_key_str
14380 \tl_replace_all:NVn
14381 \l_@@_import_current_theme_tl
14382 \c_backslash_str
14383 { / }
14384 % \end{macrocode}
14385 % \begin{markdown}
14386 %
14387 % Here, we import the snippets.
14388 %
14389 % \end{markdown}
14390 % \begin{macrocode}
14391 \clist_map_inline:nn
14392 { #1 }
14393 {
14394 \regex_extract_once:nnNTF
14395 { ^(.*?)\s+as\s+(.*?)$ }
14396 { ##1 }
14397 \l_tmpa_seq
14398 {
14399 \seq_pop:NN
14400 \l_tmpa_seq
14401 \l_tmpa_tl
14402 \seq_pop:NN
14403 \l_tmpa_seq
14404 \l_tmpa_tl
14405 \seq_pop:NN
14406 \l_tmpa_seq
14407 \l_tmpb_tl
14408 }
14409 {
14410 \tl_set:Nn
14411 \l_tmpa_tl
14412 { ##1 }
14413 \tl_set:Nn
14414 \l_tmpb_tl
14415 { ##1 }
14416 }
14417 \tl_put_left:Nn
14418 \l_tmpa_tl
14419 { / }
14420 \tl_put_left:NV
14421 \l_tmpa_tl
14422 \l_@@_import_current_theme_tl
14423 \@@_setup_snippet:Vx
14424 \l_tmpb_tl
14425 { snippet = { \l_tmpa_tl } }
14426 }
14427 % \end{macrocode}
14428 % \begin{markdown}
14429 %
14430 % Here, we load the theme.
14431 %
14432 % \end{markdown}
14433 % \begin{macrocode}
14434 \@@_set_theme:V
14435 \l_@@_import_current_theme_tl
14436 },
14437 }
14438 \cs_generate_variant:Nn
14439 \tl_replace_all:Nnn
14440 { NVn }
14441 \cs_generate_variant:Nn
14442 \@@_set_theme:n
14443 { V }
14444 \cs_generate_variant:Nn
14445 \@@_setup_snippet:nn
14446 { Vx }
14447 % \end{macrocode}
14448 % \iffalse
14449 %</tex>
14450 %<*manual-tokens>
14451
14452 ## Markdown Tokens
14453
14454 A key feature of the Markdown package is the support for manipulating markdown
14455 tokens, such as headings, emphasized text, links, and lists, in \TeX{}. Instead
14456 of reducing \TeX{} to a PDF document producer, the Markdown package allows the
14457 user to specify how every markdown token should be processed and rendered.
14458
14459 % \fi
14460 % \begin{markdown}
14461
14462 ### Token Renderers {#texrenderersuser}
14463
14464 % \end{markdown}
14465 % \iffalse
14466
14467 Token renderers are user-defined \TeX{} macros, which render markdown tokens.
14468 In this section, I will describe the individual token renderers.
14469
14470 % \fi
14471 % \begin{markdown}
14472 %
14473 % The following \TeX{} macros may occur inside the output of the
14474 % converter functions exposed by the Lua interface (see Section
14475 % <#sec:lua-conversion>) and represent the parsed markdown tokens. These
14476 % macros are intended to be redefined by the user who is typesetting a
14477 % document. By default, they point to the corresponding prototypes (see Section
14478 % <#sec:texrendererprototypes>).
14479 %
14480 % \end{markdown}
14481 %
14482 % \iffalse
14483 %</manual-tokens>
14484 %<*tex>
14485 % \fi
14486 % \begin{markdown}
14487 %
14488 % To enable the enumeration of token renderers, we will maintain the
14489 % \mdef{g_\@\@_renderers_seq} sequence.
14490 %
14491 % \end{markdown}
14492 % \begin{macrocode}
14493 \seq_new:N \g_@@_renderers_seq
14494 % \end{macrocode}
14495 % \begin{markdown}
14496 %
14497 % To enable the reflection of token renderers and their parameters, we will
14498 % maintain the \mdef{g_\@\@_renderer_arities_prop} property list.
14499 %
14500 % \end{markdown}
14501 % \begin{macrocode}
14502 \prop_new:N \g_@@_renderer_arities_prop
14503 \ExplSyntaxOff
14504 % \end{macrocode}
14505 %
14506 % \iffalse
14507 %</tex>
14508 %<*manual-tokens>
14509 % \fi
14510 %
14511 % \begin{markdown}
14512
14513 #### Acronym Renderers
14514 The following macro is only produced when the option \Opt{acronyms} is
14515 non-empty.
14516
14517 \mdef{markdownRendererAcronym} represents an acronym, initialism, or another
14518 all-caps sequence. The macro receives a single attribute that corresponds
14519 to the sequence.
14520
14521 % \end{markdown}
14522 %
14523 % \iffalse
14524
14525 ##### \LaTeX{} Example {.unnumbered}
14526
14527 Using a text editor, create a text document named `document.tex` with the
14528 following content:
14529 ```` tex
14530 \documentclass{article}
14531 \usepackage{markdown}
14532 \markdownSetup {
14533 % Format the following words as acronyms.
14534 acronyms = {HTML, YAML},
14535 renderers = {
14536 % Format acronyms as small caps.
14537 acronym = \textsc{\MakeLowercase{#1}},
14538 },
14539 }
14540 \begin{document}
14541 \begin{markdown}
14542
14543 HTML and YAML are two staples of modern tooling that often get mentioned
14544 in the same breath, even though they live in very different layers of the stack.
14545
14546 \end{markdown}
14547 \end{document}
14548 ```````
14549 Next, invoke LuaTeX from the terminal:
14550 ``` sh
14551 lualatex --shell-escape document.tex
14552 ``````
14553 A PDF document named `document.pdf` should be produced and contain the
14554 following text:
14555
14556 > <abbr>HTML</abbr> and <abbr>YAML</abbr> are two staples of modern tooling
14557 > that often get mentioned in the same breath, even though they live in very
14558 > different layers of the stack.
14559
14560 %</manual-tokens>
14561 %<*tex>
14562 % \fi
14563 %
14564 % \begin{macrocode}
14565 \ExplSyntaxOn
14566 \cs_gset_protected:Npn
14567 \markdownRendererAcronym
14568 {
14569 \markdownRendererAcronymPrototype
14570 }
14571 \seq_gput_right:Nn
14572 \g_@@_renderers_seq
14573 { acronym }
14574 \prop_gput:Nnn
14575 \g_@@_renderer_arities_prop
14576 { acronym }
14577 { 1 }
14578 \ExplSyntaxOff
14579 % \end{macrocode}
14580 %
14581 % \iffalse
14582 %</tex>
14583 %<*manual-tokens>
14584 % \fi
14585 %
14586 % \begin{markdown}
14587
14588 #### Attribute Renderers
14589 The following macros are only produced, when at least one of the following
14590 options for markdown attributes on different elements is enabled:
14591
14592 - \Opt{autoIdentifiers}
14593 - \Opt{fencedCodeAttributes}
14594 - \Opt{gfmAutoIdentifiers}
14595 - \Opt{headerAttributes}
14596 - \Opt{inlineCodeAttributes}
14597 - \Opt{linkAttributes}
14598
14599 \mdef{markdownRendererAttributeIdentifier} represents the \meta{identifier} of
14600 a markdown element (`id="`\meta{identifier}`"` in HTML and `#`\meta{identifier}
14601 in markdown attributes). The macro receives a single attribute that corresponds
14602 to the \meta{identifier}.
14603
14604 \mdef{markdownRendererAttributeClassName} represents the \meta{class name} of a
14605 markdown element (`class="`\meta{class name} ...`"` in HTML and
14606 `.`\meta{class name} in markdown attributes). The macro receives a single
14607 attribute that corresponds to the \meta{class name}.
14608
14609 \mdef{markdownRendererAttributeKeyValue} represents an HTML attribute in the form
14610 \meta{key}`=`\meta{value} that is neither an identifier nor a class name.
14611 The macro receives two attributes that correspond to the \meta{key} and the
14612 \meta{value}, respectively.
14613
14614 % \end{markdown}
14615 %
14616 % \iffalse
14617
14618 ##### \LaTeX{} Example {.unnumbered}
14619
14620 Using a text editor, create a text document named `document.tex` with the
14621 following content:
14622 ``` tex
14623 \documentclass{article}
14624 \usepackage[headerAttributes, underscores=false]{markdown}
14625 \markdownSetup{
14626 renderers = {
14627 attributeIdentifier = {%
14628 \par
14629 \emph{(Identifier: #1)}
14630 \par
14631 },
14632 attributeClassName = {%
14633 \par
14634 \emph{(Class name: #1)}
14635 \par
14636 },
14637 attributeKeyValue = {%
14638 \par
14639 \emph{(Key: #1, Value: #2)}
14640 \par
14641 },
14642 },
14643 }
14644 \begin{document}
14645 \begin{markdown}
14646
14647 # First top-level heading {jane=doe}
14648
14649 ## A subheading {#identifier}
14650
14651 # Second top-level heading {.class_name}
14652
14653 \end{markdown}
14654 \end{document}
14655 ```````
14656 Next, invoke LuaTeX from the terminal:
14657 ``` sh
14658 lualatex document.tex
14659 ``````
14660 A PDF document named `document.pdf` should be produced and contain the
14661 following text:
14662
14663 > # First top-level heading
14664 >
14665 > *(Key: Jane, Value: Doe)*
14666 >
14667 > ## A subheading
14668 >
14669 > *(Identifier: identifier)*
14670 >
14671 > # Second top-level heading
14672 >
14673 > *(Class name: class\_name)*
14674
14675 %</manual-tokens>
14676 %<*tex>
14677 % \fi
14678 %
14679 % \begin{macrocode}
14680 \ExplSyntaxOn
14681 \cs_gset_protected:Npn
14682 \markdownRendererAttributeIdentifier
14683 {
14684 \markdownRendererAttributeIdentifierPrototype
14685 }
14686 \seq_gput_right:Nn
14687 \g_@@_renderers_seq
14688 { attributeIdentifier }
14689 \prop_gput:Nnn
14690 \g_@@_renderer_arities_prop
14691 { attributeIdentifier }
14692 { 1 }
14693 \cs_gset_protected:Npn
14694 \markdownRendererAttributeClassName
14695 {
14696 \markdownRendererAttributeClassNamePrototype
14697 }
14698 \seq_gput_right:Nn
14699 \g_@@_renderers_seq
14700 { attributeClassName }
14701 \prop_gput:Nnn
14702 \g_@@_renderer_arities_prop
14703 { attributeClassName }
14704 { 1 }
14705 \cs_gset_protected:Npn
14706 \markdownRendererAttributeKeyValue
14707 {
14708 \markdownRendererAttributeKeyValuePrototype
14709 }
14710 \seq_gput_right:Nn
14711 \g_@@_renderers_seq
14712 { attributeKeyValue }
14713 \prop_gput:Nnn
14714 \g_@@_renderer_arities_prop
14715 { attributeKeyValue }
14716 { 2 }
14717 \ExplSyntaxOff
14718 % \end{macrocode}
14719 %
14720 % \iffalse
14721 %</tex>
14722 %<*manual-tokens>
14723 % \fi
14724 %
14725 % \begin{markdown}
14726
14727 #### Basic HTML Renderers {#basic-html-renderers}
14728
14729 The \mdef{markdownRendererInlineHtmlComment} macro represents the contents of an
14730 inline HTML comment. The macro receives a single argument that corresponds to
14731 the contents of the HTML comment.
14732
14733 The \mdef{markdownRendererInlineHtmlTag} macro represents an opening, closing,
14734 or empty inline HTML tag. The macro receives a single argument that corresponds
14735 to the contents of the HTML tag.
14736
14737 The \mdef{markdownRendererInputBlockHtmlElement} macro represents a block
14738 HTML element. This macro will only be produced, when the \Opt{html}
14739 option is enabled. The macro receives a single argument that filename of a file
14740 containing the contents of the HTML element.
14741
14742 These macros will only be produced when the \Opt{html} option is enabled and
14743 the \Opt{htmlOutput} option is set to `basic`.
14744
14745 % \end{markdown}
14746 %
14747 % \iffalse
14748
14749 ##### \LaTeX{} Example {.unnumbered}
14750
14751 Using a text editor, create a text document named `document.tex` with the
14752 following content:
14753 ``` tex
14754 \documentclass{article}
14755 \usepackage{markdown}
14756 \usepackage[blankBeforeHtmlBlock]{marginnote}
14757 \usepackage{verbatim}
14758 \markdownSetup{
14759 renderers = {
14760 inlineHtmlComment = \marginnote{#1},
14761 inlineHtmlTag = \textbf{#1},
14762 inputBlockHtmlElement = \verbatiminput{#1},
14763 },
14764 }
14765 \begin{document}
14766 \begin{markdown}
14767 A useful use of inline HTML comments are side notes.
14768 <!-- Side notes are displayed in the horizontal margins next to the relevant
14769 passages, which makes them *easier for the reader to find* than notes. -->
14770
14771 <b>_Hello,_ world!</b><br/>
14772
14773 <div>_Hello,_ world!</div>
14774 \end{markdown}
14775 \end{document}
14776 ```````
14777 Next, invoke LuaTeX from the terminal:
14778 ``` sh
14779 lualatex document.tex
14780 lualatex document.tex
14781 ``````
14782 A PDF document named `document.pdf` should be produced and contain the
14783 following body text:
14784
14785 > A useful use of HTML comments are side notes.
14786 >
14787 > **&lt;b&gt;**<i>Hello,</i> world!**&lt;/b&gt;&lt;br/&gt;**
14788 >
14789 > <div>_Hello,_ world!</div>
14790
14791 The horizontal margins should contain the following text:
14792
14793 > Side notes are displayed in the horizontal margins next to the relevant
14794 > passages, which makes them *easier for the reader to find* than notes.
14795
14796 %</manual-tokens>
14797 %<*tex>
14798 % \fi
14799 %
14800 % \begin{macrocode}
14801 \ExplSyntaxOn
14802 \cs_gset_protected:Npn
14803 \markdownRendererInlineHtmlComment
14804 {
14805 \markdownRendererInlineHtmlCommentPrototype
14806 }
14807 \seq_gput_right:Nn
14808 \g_@@_renderers_seq
14809 { inlineHtmlComment }
14810 \prop_gput:Nnn
14811 \g_@@_renderer_arities_prop
14812 { inlineHtmlComment }
14813 { 1 }
14814 \cs_gset_protected:Npn
14815 \markdownRendererInlineHtmlTag
14816 {
14817 \markdownRendererInlineHtmlTagPrototype
14818 }
14819 \seq_gput_right:Nn
14820 \g_@@_renderers_seq
14821 { inlineHtmlTag }
14822 \prop_gput:Nnn
14823 \g_@@_renderer_arities_prop
14824 { inlineHtmlTag }
14825 { 1 }
14826 \cs_gset_protected:Npn
14827 \markdownRendererInputBlockHtmlElement
14828 {
14829 \markdownRendererInputBlockHtmlElementPrototype
14830 }
14831 \seq_gput_right:Nn
14832 \g_@@_renderers_seq
14833 { inputBlockHtmlElement }
14834 \prop_gput:Nnn
14835 \g_@@_renderer_arities_prop
14836 { inputBlockHtmlElement }
14837 { 1 }
14838 \ExplSyntaxOff
14839 % \end{macrocode}
14840 %
14841 % \iffalse
14842 %</tex>
14843 %<*manual-tokens>
14844 % \fi
14845 %
14846 % \begin{markdown}
14847
14848 #### Block Quote Renderers
14849 The \mdef{markdownRendererBlockQuoteBegin} macro represents the beginning of
14850 a block quote. The macro receives no arguments.
14851
14852 % \end{markdown}
14853 %
14854 % \iffalse
14855 %</manual-tokens>
14856 %<*tex>
14857 % \fi
14858 %
14859 % \begin{macrocode}
14860 \ExplSyntaxOn
14861 \cs_gset_protected:Npn
14862 \markdownRendererBlockQuoteBegin
14863 {
14864 \markdownRendererBlockQuoteBeginPrototype
14865 }
14866 \seq_gput_right:Nn
14867 \g_@@_renderers_seq
14868 { blockQuoteBegin }
14869 \prop_gput:Nnn
14870 \g_@@_renderer_arities_prop
14871 { blockQuoteBegin }
14872 { 0 }
14873 \ExplSyntaxOff
14874 % \end{macrocode}
14875 %
14876 % \iffalse
14877 %</tex>
14878 %<*manual-tokens>
14879 % \fi
14880 %
14881 % \begin{markdown}
14882
14883 The \mdef{markdownRendererBlockQuoteEnd} macro represents the end of a block
14884 quote. The macro receives no arguments.
14885
14886 % \end{markdown}
14887 %
14888 % \iffalse
14889
14890 ##### Plain \TeX{} Example {.unnumbered}
14891
14892 Using a text editor, create a text document named `document.tex` with the
14893 following content:
14894 ``` tex
14895 \input markdown
14896 \def\markdownRendererBlockQuoteBegin{%
14897 \begingroup
14898 \vskip\parindent
14899 \leftskip=2\parindent
14900 \parindent=0pt
14901 }
14902 \def\markdownRendererBlockQuoteEnd{%
14903 \par
14904 \vskip\parindent
14905 \endgroup
14906 }
14907 \markdownBegin
14908 A quote from William Shakespeare's King Lear:
14909
14910 > This is the excellent foppery of the world that when we are
14911 > sick in fortune---often the surfeit of our own behavior---we
14912 > make guilty of our disasters the sun, the moon, and the
14913 > stars [...]
14914 \markdownEnd
14915 \bye
14916 ```````
14917 Next, invoke LuaTeX from the terminal:
14918 ``` sh
14919 luatex document.tex
14920 ``````
14921 A PDF document named `document.pdf` should be produced and contain the
14922 following text:
14923
14924 > A quote from William Shakespeare's King Lear:
14925 >
14926 > > This is the excellent foppery of the world that when we are
14927 > > sick in fortune—often the surfeit of our own behavior—we
14928 > > make guilty of our disasters the sun, the moon, and the
14929 > > stars [...]
14930
14931 ##### \LaTeX{} Example {.unnumbered}
14932
14933 Using a text editor, create a text document named `document.tex` with the
14934 following content:
14935 ``` tex
14936 \documentclass{article}
14937 \usepackage{markdown}
14938 \markdownSetup{
14939 renderers = {
14940 blockQuoteBegin = {\begin{quote}},
14941 blockQuoteEnd = {\end{quote}},
14942 },
14943 }
14944 \begin{document}
14945 \begin{markdown}
14946 A quote from William Shakespeare's King Lear:
14947
14948 > This is the excellent foppery of the world that when we are
14949 > sick in fortune---often the surfeit of our own behavior---we
14950 > make guilty of our disasters the sun, the moon, and the
14951 > stars [...]
14952 \end{markdown}
14953 \end{document}
14954 ```````
14955 Next, invoke LuaTeX from the terminal:
14956 ``` sh
14957 lualatex document.tex
14958 ``````
14959 A PDF document named `document.pdf` should be produced and contain the
14960 following text:
14961
14962 > A quote from William Shakespeare's King Lear:
14963 >
14964 > > This is the excellent foppery of the world that when we are
14965 > > sick in fortune—often the surfeit of our own behavior—we
14966 > > make guilty of our disasters the sun, the moon, and the
14967 > > stars [...]
14968
14969 ##### \Hologo{ConTeXt} Example {.unnumbered}
14970
14971 Using a text editor, create a text document named `document.tex` with the
14972 following content:
14973 ``` tex
14974 \usemodule[t][markdown]
14975 \def\markdownRendererBlockQuoteBegin{\startquotation}
14976 \def\markdownRendererBlockQuoteEnd{\stopquotation}
14977 \starttext
14978 \startmarkdown
14979 A quote from William Shakespeare's King Lear:
14980
14981 > This is the excellent foppery of the world that when we are
14982 > sick in fortune---often the surfeit of our own behavior---we
14983 > make guilty of our disasters the sun, the moon, and the
14984 > stars [...]
14985 \stopmarkdown
14986 \stoptext
14987 ```````
14988 Next, invoke LuaTeX from the terminal:
14989 ``` sh
14990 context --luatex document.tex
14991 ``````
14992 A PDF document named `document.pdf` should be produced and contain the
14993 following text:
14994
14995 > A quote from William Shakespeare's King Lear:
14996 >
14997 > > This is the excellent foppery of the world that when we are
14998 > > sick in fortune—often the surfeit of our own behavior—we
14999 > > make guilty of our disasters the sun, the moon, and the
15000 > > stars [...]
15001
15002 %</manual-tokens>
15003 %<*tex>
15004 % \fi
15005 %
15006 % \begin{macrocode}
15007 \ExplSyntaxOn
15008 \cs_gset_protected:Npn
15009 \markdownRendererBlockQuoteEnd
15010 {
15011 \markdownRendererBlockQuoteEndPrototype
15012 }
15013 \seq_gput_right:Nn
15014 \g_@@_renderers_seq
15015 { blockQuoteEnd }
15016 \prop_gput:Nnn
15017 \g_@@_renderer_arities_prop
15018 { blockQuoteEnd }
15019 { 0 }
15020 \ExplSyntaxOff
15021 % \end{macrocode}
15022 %
15023 % \iffalse
15024 %</tex>
15025 %<*manual-tokens>
15026 % \fi
15027 %
15028 % \begin{markdown}
15029
15030 #### Bracketed Spans
15031 The following macros are only produced, when the \Opt{bracketedSpans} option is
15032 enabled.
15033
15034 The \mdef{markdownRendererBracketedSpan} macro represents an inline bracketed
15035 span. It receives a single argument that corresponds to the inline bracketed
15036 span.
15037
15038 % \end{markdown}
15039 %
15040 % \iffalse
15041
15042 ##### \LaTeX{} Example {.unnumbered}
15043
15044 Using a text editor, create a text document named `document.tex` with the
15045 following content:
15046 ``` tex
15047 \documentclass{article}
15048 \usepackage[bracketedSpans]{markdown}
15049 \markdownSetup{
15050 renderers = {
15051 bracketedSpan = {(#1)},
15052 },
15053 }
15054 \begin{document}
15055 \begin{markdown}
15056
15057 [foo [bar]{#identifier}]{key=value} [baz]{.class_name}
15058
15059 \end{markdown}
15060 \end{document}
15061 ```````
15062 Next, invoke LuaTeX from the terminal:
15063 ``` sh
15064 lualatex document.tex
15065 ``````
15066 A PDF document named `document.pdf` should be produced and contain the
15067 following text:
15068
15069 > (foo (bar)) (baz)
15070
15071 %</manual-tokens>
15072 %<*tex>
15073 % \fi
15074 %
15075 % \begin{macrocode}
15076 \ExplSyntaxOn
15077 \cs_gset_protected:Npn
15078 \markdownRendererBracketedSpan
15079 {
15080 \markdownRendererBracketedSpanPrototype
15081 }
15082 \seq_gput_right:Nn
15083 \g_@@_renderers_seq
15084 { bracketedSpan }
15085 \prop_gput:Nnn
15086 \g_@@_renderer_arities_prop
15087 { bracketedSpan }
15088 { 1 }
15089 \ExplSyntaxOff
15090 % \end{macrocode}
15091 %
15092 % \iffalse
15093 %</tex>
15094 %<*manual-tokens>
15095 % \fi
15096 %
15097 % \begin{markdown}
15098
15099 #### Bracketed Span Attribute Context Renderers
15100 The following macros are only produced, when the \Opt{bracketedSpans} option is
15101 enabled.
15102
15103 The \mdef{markdownRendererBracketedSpanAttributeContextBegin} and
15104 \mdef{markdownRendererBracketedSpanAttributeContextEnd} macros represent the
15105 beginning and the end of a context in which the attributes of
15106 an inline bracketed span apply. The macros receive no arguments.
15107
15108 % \end{markdown}
15109 %
15110 % \iffalse
15111
15112 ##### \LaTeX{} Example {.unnumbered}
15113
15114 Using a text editor, create a text document named `document.tex` with the
15115 following content:
15116 ``` tex
15117 \documentclass{article}
15118 \usepackage[bracketedSpans]{markdown}
15119 \markdownSetup{
15120 renderers = {
15121 bracketedSpanAttributeContextBegin = {(},
15122 bracketedSpanAttributeContextEnd = {)},
15123 },
15124 }
15125 \begin{document}
15126 \begin{markdown}
15127
15128 [foo [bar]{#identifier}]{key=value} [baz]{.class_name}
15129
15130 \end{markdown}
15131 \end{document}
15132 ```````
15133 Next, invoke LuaTeX from the terminal:
15134 ``` sh
15135 lualatex document.tex
15136 ``````
15137 A PDF document named `document.pdf` should be produced and contain the
15138 following text:
15139
15140 > (foo (bar)) (baz)
15141
15142 %</manual-tokens>
15143 %<*tex>
15144 % \fi
15145 %
15146 % \begin{macrocode}
15147 \ExplSyntaxOn
15148 \cs_gset_protected:Npn
15149 \markdownRendererBracketedSpanAttributeContextBegin
15150 {
15151 \markdownRendererBracketedSpanAttributeContextBeginPrototype
15152 }
15153 \seq_gput_right:Nn
15154 \g_@@_renderers_seq
15155 { bracketedSpanAttributeContextBegin }
15156 \prop_gput:Nnn
15157 \g_@@_renderer_arities_prop
15158 { bracketedSpanAttributeContextBegin }
15159 { 0 }
15160 \cs_gset_protected:Npn
15161 \markdownRendererBracketedSpanAttributeContextEnd
15162 {
15163 \markdownRendererBracketedSpanAttributeContextEndPrototype
15164 }
15165 \seq_gput_right:Nn
15166 \g_@@_renderers_seq
15167 { bracketedSpanAttributeContextEnd }
15168 \prop_gput:Nnn
15169 \g_@@_renderer_arities_prop
15170 { bracketedSpanAttributeContextEnd }
15171 { 0 }
15172 \ExplSyntaxOff
15173 % \end{macrocode}
15174 %
15175 % \iffalse
15176 %</tex>
15177 %<*manual-tokens>
15178 % \fi
15179 %
15180 % \begin{markdown}
15181
15182 #### Bullet List Renderers
15183 The \mdef{markdownRendererUlBegin} macro represents the beginning of a
15184 bulleted list that contains an item with several paragraphs of text (the
15185 list is not tight). The macro receives no arguments.
15186
15187 % \end{markdown}
15188 %
15189 % \iffalse
15190 %</manual-tokens>
15191 %<*tex>
15192 % \fi
15193 %
15194 % \begin{macrocode}
15195 \ExplSyntaxOn
15196 \cs_gset_protected:Npn
15197 \markdownRendererUlBegin
15198 {
15199 \markdownRendererUlBeginPrototype
15200 }
15201 \seq_gput_right:Nn
15202 \g_@@_renderers_seq
15203 { ulBegin }
15204 \prop_gput:Nnn
15205 \g_@@_renderer_arities_prop
15206 { ulBegin }
15207 { 0 }
15208 \ExplSyntaxOff
15209 % \end{macrocode}
15210 %
15211 % \iffalse
15212 %</tex>
15213 %<*manual-tokens>
15214 % \fi
15215 %
15216 % \begin{markdown}
15217
15218 The \mdef{markdownRendererUlBeginTight} macro represents the beginning of a
15219 bulleted list that contains no item with several paragraphs of text (the list
15220 is tight). This macro will only be produced, when the \Opt{tightLists} option
15221 is disabled. The macro receives no arguments.
15222
15223 % \end{markdown}
15224 %
15225 % \iffalse
15226 %</manual-tokens>
15227 %<*tex>
15228 % \fi
15229 %
15230 % \begin{macrocode}
15231 \ExplSyntaxOn
15232 \cs_gset_protected:Npn
15233 \markdownRendererUlBeginTight
15234 {
15235 \markdownRendererUlBeginTightPrototype
15236 }
15237 \seq_gput_right:Nn
15238 \g_@@_renderers_seq
15239 { ulBeginTight }
15240 \prop_gput:Nnn
15241 \g_@@_renderer_arities_prop
15242 { ulBeginTight }
15243 { 0 }
15244 \ExplSyntaxOff
15245 % \end{macrocode}
15246 %
15247 % \iffalse
15248 %</tex>
15249 %<*manual-tokens>
15250 % \fi
15251 %
15252 % \begin{markdown}
15253
15254 The \mdef{markdownRendererUlItem} macro represents an item in a bulleted
15255 list. The macro receives no arguments.
15256
15257 % \end{markdown}
15258 %
15259 % \iffalse
15260 %</manual-tokens>
15261 %<*tex>
15262 % \fi
15263 %
15264 % \begin{macrocode}
15265 \ExplSyntaxOn
15266 \cs_gset_protected:Npn
15267 \markdownRendererUlItem
15268 {
15269 \markdownRendererUlItemPrototype
15270 }
15271 \seq_gput_right:Nn
15272 \g_@@_renderers_seq
15273 { ulItem }
15274 \prop_gput:Nnn
15275 \g_@@_renderer_arities_prop
15276 { ulItem }
15277 { 0 }
15278 \ExplSyntaxOff
15279 % \end{macrocode}
15280 %
15281 % \iffalse
15282 %</tex>
15283 %<*manual-tokens>
15284 % \fi
15285 %
15286 % \begin{markdown}
15287
15288 The \mdef{markdownRendererUlItemEnd} macro represents the end of an item in a
15289 bulleted list. The macro receives no arguments.
15290
15291 % \end{markdown}
15292 %
15293 % \iffalse
15294 %</manual-tokens>
15295 %<*tex>
15296 % \fi
15297 %
15298 % \begin{macrocode}
15299 \ExplSyntaxOn
15300 \cs_gset_protected:Npn
15301 \markdownRendererUlItemEnd
15302 {
15303 \markdownRendererUlItemEndPrototype
15304 }
15305 \seq_gput_right:Nn
15306 \g_@@_renderers_seq
15307 { ulItemEnd }
15308 \prop_gput:Nnn
15309 \g_@@_renderer_arities_prop
15310 { ulItemEnd }
15311 { 0 }
15312 \ExplSyntaxOff
15313 % \end{macrocode}
15314 %
15315 % \iffalse
15316 %</tex>
15317 %<*manual-tokens>
15318 % \fi
15319 %
15320 % \begin{markdown}
15321
15322 The \mdef{markdownRendererUlEnd} macro represents the end of a bulleted list
15323 that contains an item with several paragraphs of text (the list is not
15324 tight). The macro receives no arguments.
15325
15326 % \end{markdown}
15327 %
15328 % \iffalse
15329 %</manual-tokens>
15330 %<*tex>
15331 % \fi
15332 %
15333 % \begin{macrocode}
15334 \ExplSyntaxOn
15335 \cs_gset_protected:Npn
15336 \markdownRendererUlEnd
15337 {
15338 \markdownRendererUlEndPrototype
15339 }
15340 \seq_gput_right:Nn
15341 \g_@@_renderers_seq
15342 { ulEnd }
15343 \prop_gput:Nnn
15344 \g_@@_renderer_arities_prop
15345 { ulEnd }
15346 { 0 }
15347 \ExplSyntaxOff
15348 % \end{macrocode}
15349 %
15350 % \iffalse
15351 %</tex>
15352 %<*manual-tokens>
15353 % \fi
15354 %
15355 % \begin{markdown}
15356
15357 The \mdef{markdownRendererUlEndTight} macro represents the end of a bulleted
15358 list that contains no item with several paragraphs of text (the list is
15359 tight). This macro will only be produced, when the \Opt{tightLists} option is
15360 disabled. The macro receives no arguments.
15361
15362 % \end{markdown}
15363 %
15364 % \iffalse
15365
15366 ##### Plain \TeX{} Example {.unnumbered}
15367
15368 Using a text editor, create a text document named `document.tex` with the
15369 following content:
15370 ``` tex
15371 \input markdown
15372 \def\markdownOptionTightLists{true}
15373
15374 \def\markdownRendererInterblockSeparator{}
15375 \def\markdownRendererUlBeginTight{ (}
15376 \def\markdownRendererUlItem{%
15377 \def\markdownRendererUlItem{%
15378 ,
15379 \def\markdownRendererUlItem{, and }%
15380 }%
15381 }
15382 \def\markdownRendererUlItemEnd{}
15383 \def\markdownRendererUlEndTight{).}
15384
15385 \markdownBegin
15386 This is a tight list
15387
15388 - the first item
15389 - the second item
15390 - the third item
15391 \markdownEnd
15392
15393 \def\markdownRendererInterblockSeparator{%
15394 :\par
15395 \def\markdownRendererInterblockSeparator{\par}%
15396 }
15397 \def\markdownRendererUlBegin{}
15398 \def\markdownRendererUlItem{--\kern 0.5em}
15399 \def\markdownRendererUlItemEnd{.\par}
15400 \def\markdownRendererUlEnd{}
15401
15402 \markdownBegin
15403 This is a loose list
15404
15405 - This is the first item
15406
15407 - This is the second item
15408
15409 - This is the third item
15410 \markdownEnd
15411
15412 \bye
15413 ```````
15414 Next, invoke LuaTeX from the terminal:
15415 ``` sh
15416 luatex document.tex
15417 ``````
15418 A PDF document named `document.pdf` should be produced and contain the
15419 following text:
15420
15421 > This is a tight list (the first item, the second item, and the third item).
15422 >
15423 > This is a loose list:
15424 >
15425 > - This is the first item.
15426 >
15427 > - This is the second item.
15428 >
15429 > - This is the third item.
15430
15431 ##### \LaTeX{} Example {.unnumbered}
15432
15433 Using a text editor, create a text document named `document.tex` with the
15434 following content:
15435 ``` tex
15436 \documentclass{article}
15437 \usepackage[tightLists]{markdown}
15438 \begin{document}
15439
15440 \begin{markdown}[
15441 renderers = {
15442 interblockSeparator = {},
15443 ulBeginTight = { (},
15444 ulItem = {%
15445 \def\markdownRendererUlItem{%
15446 ,
15447 \def\markdownRendererUlItem{, and }%
15448 }%
15449 },
15450 ulItemEnd = {},
15451 ulEndTight = {).},
15452 },
15453 ]
15454 This is a tight list
15455
15456 - the first item
15457 - the second item
15458 - the third item
15459 \end{markdown}
15460
15461 \begin{markdown}[
15462 renderers = {
15463 interblockSeparator = {%
15464 :\par
15465 \def\markdownRendererInterblockSeparator{\par}%
15466 },
15467 ulBeginTight = {\begin{itemize}},
15468 ulItem = {\item},
15469 ulItemEnd = {.},
15470 ulEnd = {\end{itemize}},
15471 },
15472 ]
15473 This is a loose list
15474
15475 - This is the first item
15476
15477 - This is the second item
15478
15479 - This is the third item
15480 \end{markdown}
15481
15482 \end{document}
15483 ```````
15484 Next, invoke LuaTeX from the terminal:
15485 ``` sh
15486 lualatex document.tex
15487 ``````
15488 A PDF document named `document.pdf` should be produced and contain the
15489 following text:
15490
15491 > This is a tight list (the first item, the second item, and the third item).
15492 >
15493 > This is a loose list:
15494 >
15495 > - This is the first item.
15496 >
15497 > - This is the second item.
15498 >
15499 > - This is the third item.
15500
15501 ##### \Hologo{ConTeXt} Example {.unnumbered}
15502
15503 Using a text editor, create a text document named `document.tex` with the
15504 following content:
15505 ``` tex
15506 \usemodule[t][markdown]
15507 \setupmarkdown[tightLists = yes]
15508 \starttext
15509
15510 \def\markdownRendererInterblockSeparator{}
15511 \def\markdownRendererUlBeginTight{ (}
15512 \def\markdownRendererUlItem{%
15513 \def\markdownRendererUlItem{%
15514 ,
15515 \def\markdownRendererUlItem{, and }%
15516 }%
15517 }
15518 \def\markdownRendererUlItemEnd{}
15519 \def\markdownRendererUlEndTight{).}
15520
15521 \startmarkdown
15522 This is a tight list
15523
15524 - the first item
15525 - the second item
15526 - the third item
15527 \stopmarkdown
15528
15529 \def\markdownRendererInterblockSeparator{%
15530 :\par
15531 \def\markdownRendererInterblockSeparator{\par}%
15532 }
15533 \def\markdownRendererUlBegin{\startitemize}
15534 \def\markdownRendererUlItem{\item}
15535 \def\markdownRendererUlItemEnd{.}
15536 \def\markdownRendererUlEnd{\stopitemize}
15537
15538 \startmarkdown
15539 This is a loose list
15540
15541 - This is the first item
15542
15543 - This is the second item
15544
15545 - This is the third item
15546 \stopmarkdown
15547
15548 \stoptext
15549 ```````
15550 Next, invoke LuaTeX from the terminal:
15551 ``` sh
15552 context --luatex document.tex
15553 ``````
15554 A PDF document named `document.pdf` should be produced and contain the
15555 following text:
15556
15557 > This is a tight list (the first item, the second item, and the third item).
15558 >
15559 > This is a loose list:
15560 >
15561 > - This is the first item.
15562 >
15563 > - This is the second item.
15564 >
15565 > - This is the third item.
15566
15567 %</manual-tokens>
15568 %<*tex>
15569 % \fi
15570 %
15571 % \begin{macrocode}
15572 \ExplSyntaxOn
15573 \cs_gset_protected:Npn
15574 \markdownRendererUlEndTight
15575 {
15576 \markdownRendererUlEndTightPrototype
15577 }
15578 \seq_gput_right:Nn
15579 \g_@@_renderers_seq
15580 { ulEndTight }
15581 \prop_gput:Nnn
15582 \g_@@_renderer_arities_prop
15583 { ulEndTight }
15584 { 0 }
15585 \ExplSyntaxOff
15586 % \end{macrocode}
15587 %
15588 % \iffalse
15589 %</tex>
15590 %<*manual-tokens>
15591 % \fi
15592 %
15593 % \begin{markdown}
15594
15595 #### Citation Renderers
15596 The \mdef{markdownRendererCite} macro represents a string of one or more
15597 parenthetical citations. This macro will only be produced, when the
15598 \Opt{citations} option is enabled. The macro receives the parameter
15599 `{`\meta{number of citations}`}` followed by \meta{suppress author}
15600 `{`\meta{prenote}`}{`\meta{postnote}`}{`\meta{name}`}` repeated
15601 \meta{number of citations} times. The \meta{suppress author} parameter is
15602 either the token `-`, when the author's name is to be suppressed, or `+`
15603 otherwise.
15604
15605 % \end{markdown}
15606 %
15607 % \iffalse
15608
15609 ##### \LaTeX{} Example {.unnumbered}
15610
15611 Using a text editor, create a text document named `document.tex` with the
15612 following content:
15613 ``` tex
15614 \documentclass{article}
15615 \usepackage[citations]{markdown}
15616 \newcount\citationsCounter
15617 \newcount\citationsTotal
15618 \makeatletter
15619 \def\citations#1#2#3#4{%
15620 a parenthesized citation \emph{#4}
15621 \advance\citationsCounter by 1\relax
15622 \ifx\relax#2\relax
15623 \ifx\relax#3\relax\else
15624 with a postfix \emph{#3}%
15625 \fi
15626 \else
15627 with a prefix \emph{#2}%
15628 \ifx\relax#3\relax\else
15629 \ and a postfix \emph{#3}%
15630 \fi
15631 \fi
15632 \ifnum\citationsCounter>\citationsTotal\relax
15633 .%
15634 \expandafter\@gobble
15635 \else
15636 , and
15637 \fi\citations}
15638 \makeatother
15639 \markdownSetup{
15640 renderers = {
15641 cite = {%
15642 \citationsCounter=1%
15643 \citationsTotal=#1%
15644 This is
15645 \expandafter\citations
15646 },
15647 },
15648 }
15649 \begin{document}
15650 \begin{markdown}
15651 [see @abrahams90, pp. 12; @eijkhout91, pp. 34]
15652 \end{markdown}
15653 \end{document}
15654 ```````
15655 Next, invoke LuaTeX from the terminal:
15656 ``` sh
15657 lualatex document.tex
15658 ``````
15659 A PDF document named `document.pdf` should be produced and contain the
15660 following text:
15661
15662 > This is a parenthesized citation *abrahams90* with a prefix see
15663 > and a postfix *pp. 12*, and a citation *eijkhout91* with a
15664 > postfix *pp. 34*.
15665
15666 %</manual-tokens>
15667 %<*tex>
15668 % \fi
15669 %
15670 % \begin{macrocode}
15671 \ExplSyntaxOn
15672 \cs_gset_protected:Npn
15673 \markdownRendererCite
15674 {
15675 \markdownRendererCitePrototype
15676 }
15677 \seq_gput_right:Nn
15678 \g_@@_renderers_seq
15679 { cite }
15680 \prop_gput:Nnn
15681 \g_@@_renderer_arities_prop
15682 { cite }
15683 { 1 }
15684 \ExplSyntaxOff
15685 % \end{macrocode}
15686 %
15687 % \iffalse
15688 %</tex>
15689 %<*manual-tokens>
15690 % \fi
15691 %
15692 % \begin{markdown}
15693
15694 The \mdef{markdownRendererTextCite} macro represents a string of one or more
15695 text citations. This macro will only be produced, when the
15696 \Opt{citations} option is enabled. The macro receives parameters in the same
15697 format as the \mref{markdownRendererCite} macro.
15698
15699 % \end{markdown}
15700 %
15701 % \iffalse
15702
15703 ##### \LaTeX{} Example {.unnumbered}
15704
15705 Using a text editor, create a text document named `document.tex` with the
15706 following content:
15707 ``` tex
15708 \documentclass{article}
15709 \usepackage[citations]{markdown}
15710 \newcount\citationsCounter
15711 \newcount\citationsTotal
15712 \makeatletter
15713 \def\citations#1#2#3#4{%
15714 a text citation \emph{#4}
15715 \advance\citationsCounter by 1\relax
15716 \ifx\relax#2\relax
15717 \ifx\relax#3\relax\else
15718 with a postfix \emph{#3}%
15719 \fi
15720 \else
15721 with a prefix \emph{#2}%
15722 \ifx\relax#3\relax\else
15723 \ and a postfix \emph{#3}%
15724 \fi
15725 \fi
15726 \ifnum\citationsCounter>\citationsTotal\relax
15727 .%
15728 \expandafter\@gobble
15729 \else
15730 , and
15731 \fi\citations}
15732 \makeatother
15733 \markdownSetup{
15734 renderers = {
15735 textCite = {%
15736 \citationsCounter=1%
15737 \citationsTotal=#1%
15738 This is
15739 \expandafter\citations
15740 },
15741 },
15742 }
15743 \begin{document}
15744 \begin{markdown}
15745 @abrahams90 [pp. 12; also @eijkhout91]
15746 \end{markdown}
15747 \end{document}
15748 ```````
15749 Next, invoke LuaTeX from the terminal:
15750 ``` sh
15751 lualatex document.tex
15752 ``````
15753 A PDF document named `document.pdf` should be produced and contain the
15754 following text:
15755
15756 > This is a text citation *abrahams90* with a postfix *pp. 12*,
15757 > and a citation *eijkhout91* with a prefix *also*.
15758
15759 %</manual-tokens>
15760 %<*tex>
15761 % \fi
15762 %
15763 % \begin{macrocode}
15764 \ExplSyntaxOn
15765 \cs_gset_protected:Npn
15766 \markdownRendererTextCite
15767 {
15768 \markdownRendererTextCitePrototype
15769 }
15770 \seq_gput_right:Nn
15771 \g_@@_renderers_seq
15772 { textCite }
15773 \prop_gput:Nnn
15774 \g_@@_renderer_arities_prop
15775 { textCite }
15776 { 1 }
15777 \ExplSyntaxOff
15778 % \end{macrocode}
15779 %
15780 % \iffalse
15781 %</tex>
15782 %<*manual-tokens>
15783 % \fi
15784 %
15785 % \begin{markdown}
15786
15787 #### Code Block Renderers
15788 The \mdef{markdownRendererInputVerbatim} macro represents a code
15789 block. The macro receives a single argument that corresponds to the
15790 filename of a file containing the code block contents.
15791
15792 % \end{markdown}
15793 %
15794 % \iffalse
15795 %</manual-tokens>
15796 %<*tex>
15797 % \fi
15798 %
15799 % \begin{macrocode}
15800 \ExplSyntaxOn
15801 \cs_gset_protected:Npn
15802 \markdownRendererInputVerbatim
15803 {
15804 \markdownRendererInputVerbatimPrototype
15805 }
15806 \seq_gput_right:Nn
15807 \g_@@_renderers_seq
15808 { inputVerbatim }
15809 \prop_gput:Nnn
15810 \g_@@_renderer_arities_prop
15811 { inputVerbatim }
15812 { 1 }
15813 \ExplSyntaxOff
15814 % \end{macrocode}
15815 %
15816 % \iffalse
15817 %</tex>
15818 %<*manual-tokens>
15819 % \fi
15820 %
15821 % \begin{markdown}
15822
15823 The \mdef{markdownRendererInputFencedCode} macro represents a fenced code
15824 block. This macro will only be produced, when the \Opt{fencedCode} option is
15825 enabled. The macro receives three arguments that correspond to the filename of
15826 a file containing the code block contents, the fully escaped code fence infostring
15827 that can be directly typeset, and the raw code fence infostring that can be used
15828 outside typesetting.
15829
15830 % \end{markdown}
15831 %
15832 % \iffalse
15833
15834 ##### \LaTeX{} Example {.unnumbered}
15835
15836 Using a text editor, create a text document named `document.tex` with the
15837 following content:
15838 ``` tex
15839 \documentclass{article}
15840 \usepackage{verbatim}
15841 \usepackage[hyphens]{url}
15842 \usepackage[fencedCode]{markdown}
15843 \markdownSetup{
15844 renderers = {
15845 interblockSeparator = {
15846 \def\markdownRendererInterblockSeparator{%
15847 \par
15848 \def\markdownRendererInterblockSeparator{%
15849 \def\markdownRendererInterblockSeparator{%
15850 \par
15851 }%
15852 }%
15853 }%
15854 },
15855 inputVerbatim = {
15856 is contained in file \url{#1}:%
15857 \verbatiminput{#1}%
15858 },
15859 inputFencedCode = {
15860 in #2 \markdownRendererInputVerbatim{#1}%
15861 },
15862 },
15863 }
15864 \begin{document}
15865 \begin{markdown}
15866 The following code
15867
15868 def foo(bar):
15869 if len(bar) <= 1:
15870 return bar[0]
15871 elif len(bar) == 2:
15872 return sorted(bar)
15873 else:
15874 baz = len(bar) // 2
15875 return foo(bar[baz:], bar[:baz])
15876
15877 The following code
15878
15879 ~~~ Python
15880 >>> foo([4, 2, 1, 3])
15881 [1, 2, 3, 4]
15882 ~~~~~~~~~~
15883 \end{markdown}
15884 \end{document}
15885 ```````
15886 Next, invoke LuaTeX from the terminal:
15887 ``` sh
15888 lualatex document.tex
15889 ``````
15890 A PDF document named `document.pdf` should be produced and contain the
15891 following text except for the filename, which may differ:
15892
15893 > The following code is contained in file
15894 > `./_markdown_document/882453149edcf288976647f6fe147ada.verbatim`:
15895 > ``` py
15896 > def foo(bar):
15897 > if len(bar) <= 1:
15898 > return bar[:1]
15899 > elif len(bar) == 2:
15900 > return sorted(bar)
15901 > else:
15902 > baz = bar[len(bar) // 2]
15903 > return (
15904 > foo([qux for qux in bar if qux < baz]) + [baz] +
15905 > foo([qux for qux in bar if qux > baz])
15906 > )
15907 > ``````
15908 > The following code in Python contained in file
15909 > `./_markdown_document/cf2a96e2120cef5b1fae5fea36fcc27b.verbatim`:
15910 > ``` py
15911 > >>> foo([4, 2, 1, 3])
15912 > [1, 2, 3, 4]
15913 > ``````
15914
15915 %</manual-tokens>
15916 %<*tex>
15917 % \fi
15918 %
15919 % \begin{macrocode}
15920 \ExplSyntaxOn
15921 \cs_gset_protected:Npn
15922 \markdownRendererInputFencedCode
15923 {
15924 \markdownRendererInputFencedCodePrototype
15925 }
15926 \seq_gput_right:Nn
15927 \g_@@_renderers_seq
15928 { inputFencedCode }
15929 \prop_gput:Nnn
15930 \g_@@_renderer_arities_prop
15931 { inputFencedCode }
15932 { 3 }
15933 \ExplSyntaxOff
15934 % \end{macrocode}
15935 %
15936 % \iffalse
15937 %</tex>
15938 %<*manual-tokens>
15939 % \fi
15940 % \begin{markdown}
15941
15942 #### Code Span Renderer
15943 The \mdef{markdownRendererCodeSpan} macro represents inline code span in the
15944 input text. It receives a single argument that corresponds to the inline
15945 code span.
15946
15947 % \end{markdown}
15948 %
15949 % \iffalse
15950
15951 ##### Plain \TeX{} Example {.unnumbered}
15952
15953 Using a text editor, create a text document named `document.tex` with the
15954 following content:
15955 ``` tex
15956 \input markdown
15957 \input lmfonts
15958
15959 \def\markdownRendererCodeSpan#1{#1}
15960
15961 \markdownBegin
15962 `$\sqrt{-1}$ *equals* $i$`
15963
15964 $\sqrt{-1}$ *equals* $i$
15965 \markdownEnd
15966
15967 \def\markdownOptionHybrid{true}
15968 \markdownBegin
15969 $\sqrt{-1}$ *equals* $i$
15970 \markdownEnd
15971
15972 \bye
15973 ```````
15974 Next, invoke LuaTeX from the terminal:
15975 ``` sh
15976 luatex document.tex
15977 ``````
15978 A PDF document named `document.pdf` should be produced and contain the
15979 following text:
15980
15981 > \$\\sqrt{-1}\$ \*equals\* \$i\$.
15982 >
15983 > \$\\sqrt{-1}\$ *equals* \$i\$.
15984 >
15985 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
15986 > *equals*
15987 > <math><mi>i</mi></math>.
15988
15989 ##### \LaTeX{} Example {.unnumbered}
15990
15991 Using a text editor, create a text document named `document.tex` with the
15992 following content:
15993 ``` tex
15994 \documentclass{article}
15995 \usepackage[smartEllipses]{markdown}
15996 \markdownSetup{
15997 renderers = {
15998 codeSpan = {#1},
15999 },
16000 }
16001 \begin{document}
16002
16003 \begin{markdown}
16004 `$\sqrt{-1}$ *equals* $i$`
16005
16006 $\sqrt{-1}$ *equals* $i$
16007 \end{markdown}
16008
16009 \begin{markdown}[hybrid]
16010 $\sqrt{-1}$ *equals* $i$
16011 \end{markdown}
16012
16013 \end{document}
16014 ```````
16015 Next, invoke LuaTeX from the terminal:
16016 ``` sh
16017 lualatex document.tex
16018 ``````
16019 A PDF document named `document.pdf` should be produced and contain the
16020 following text:
16021
16022 > \$\\sqrt{-1}\$ \*equals\* \$i\$.
16023 >
16024 > \$\\sqrt{-1}\$ *equals* \$i\$.
16025 >
16026 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
16027 > *equals*
16028 > <math><mi>i</mi></math>.
16029
16030 ##### \Hologo{ConTeXt} Example {.unnumbered}
16031
16032 Using a text editor, create a text document named `document.tex` with the
16033 following content:
16034 ``` tex
16035 \usemodule[t][markdown]
16036 \def\markdownRendererCodeSpan#1{#1}
16037 \starttext
16038
16039 \startmarkdown
16040 `$\sqrt{-1}$ *equals* $i$`
16041
16042 $\sqrt{-1}$ *equals* $i$
16043 \stopmarkdown
16044
16045 \setupmarkdown[hybrid = yes]
16046 \startmarkdown
16047 $\sqrt{-1}$ *equals* $i$
16048 \stopmarkdown
16049
16050 \bye
16051 ```````
16052 Next, invoke LuaTeX from the terminal:
16053 ``` sh
16054 context --luatex document.tex
16055 ``````
16056 A PDF document named `document.pdf` should be produced and contain the
16057 following text:
16058
16059 > \$\\sqrt{-1}\$ \*equals\* \$i\$.
16060 >
16061 > \$\\sqrt{-1}\$ *equals* \$i\$.
16062 >
16063 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
16064 > *equals*
16065 > <math><mi>i</mi></math>.
16066
16067 %</manual-tokens>
16068 %<*tex>
16069 % \fi
16070 %
16071 % \begin{macrocode}
16072 \ExplSyntaxOn
16073 \cs_gset_protected:Npn
16074 \markdownRendererCodeSpan
16075 {
16076 \markdownRendererCodeSpanPrototype
16077 }
16078 \seq_gput_right:Nn
16079 \g_@@_renderers_seq
16080 { codeSpan }
16081 \prop_gput:Nnn
16082 \g_@@_renderer_arities_prop
16083 { codeSpan }
16084 { 1 }
16085 \ExplSyntaxOff
16086 % \end{macrocode}
16087 %
16088 % \iffalse
16089 %</tex>
16090 %<*manual-tokens>
16091 % \fi
16092 %
16093 % \begin{markdown}
16094
16095 #### Code Span Attribute Context Renderers
16096 The following macros are only produced, when the \Opt{inlineCodeAttributes}
16097 option is enabled.
16098
16099 The \mdef{markdownRendererCodeSpanAttributeContextBegin} and
16100 \mdef{markdownRendererCodeSpanAttributeContextEnd} macros represent the beginning
16101 and the end of a context in which the attributes of an inline code span apply.
16102 The macros receive no arguments.
16103
16104 % \end{markdown}
16105 %
16106 % \iffalse
16107
16108 ##### \LaTeX{} Example {.unnumbered}
16109
16110 Using a text editor, create a text document named `document.tex` with the
16111 following content:
16112 ``` tex
16113 \documentclass{article}
16114 \usepackage[inlineCodeAttributes]{markdown}
16115 \markdownSetup{
16116 renderers = {
16117 codeSpanAttributeContextBegin = {(},
16118 codeSpan = {#1},
16119 codeSpanAttributeContextEnd = {)},
16120 },
16121 }
16122 \begin{document}
16123 \begin{markdown}
16124
16125 foo `bar`{key=value} baz
16126
16127 \end{markdown}
16128 \end{document}
16129 ```````
16130 Next, invoke LuaTeX from the terminal:
16131 ``` sh
16132 lualatex document.tex
16133 ``````
16134 A PDF document named `document.pdf` should be produced and contain the
16135 following text:
16136
16137 > foo (bar) baz
16138
16139 %</manual-tokens>
16140 %<*tex>
16141 % \fi
16142 %
16143 % \begin{macrocode}
16144 \ExplSyntaxOn
16145 \cs_gset_protected:Npn
16146 \markdownRendererCodeSpanAttributeContextBegin
16147 {
16148 \markdownRendererCodeSpanAttributeContextBeginPrototype
16149 }
16150 \seq_gput_right:Nn
16151 \g_@@_renderers_seq
16152 { codeSpanAttributeContextBegin }
16153 \prop_gput:Nnn
16154 \g_@@_renderer_arities_prop
16155 { codeSpanAttributeContextBegin }
16156 { 0 }
16157 \cs_gset_protected:Npn
16158 \markdownRendererCodeSpanAttributeContextEnd
16159 {
16160 \markdownRendererCodeSpanAttributeContextEndPrototype
16161 }
16162 \seq_gput_right:Nn
16163 \g_@@_renderers_seq
16164 { codeSpanAttributeContextEnd }
16165 \prop_gput:Nnn
16166 \g_@@_renderer_arities_prop
16167 { codeSpanAttributeContextEnd }
16168 { 0 }
16169 \ExplSyntaxOff
16170 % \end{macrocode}
16171 %
16172 % \iffalse
16173 %</tex>
16174 %<*manual-tokens>
16175 % \fi
16176 %
16177 % \begin{markdown}
16178
16179 #### CommonMark Block HTML Renderers {#commonmark-block-html-renderers}
16180
16181 When the \Opt{html} option is enabled and \Opt{htmlOutput} is set to
16182 \opt{commonmark}, the following fine-grained renderers are produced instead of
16183 \mref{markdownRendererInputBlockHtmlElement} to distinguish between different
16184 top-level non-terminal elements of CommonMark's grammar for [raw
16185 HTML][html-blocks]:
16186
16187 1. \mdef{markdownRendererInputBlockHtmlCdataElement} -- A CDATA block-level HTML
16188 element such as `<script>`, `<pre>`, `<style>`, or `<textarea>` that starts
16189 on a line of its own
16190 2. \mdef{markdownRendererBlockHtmlComment} -- A comment that starts on a
16191 line of its own
16192 3. \mdef{markdownRendererInputBlockHtmlProcessingInstruction} -- A processing
16193 instruction that starts on a line of its own
16194 4. \mdef{markdownRendererInputBlockHtmlDeclaration} -- A declaration that starts
16195 on a line of its own
16196 5. \mdef{markdownRendererInputBlockHtmlCdataSection} -- A CDATA section that
16197 starts on a line of its own
16198 6. \mdef{markdownRendererInputBlockHtmlPcdataElement} -- A PCDATA block-level
16199 HTML element that starts on a line of its own
16200 7. \mdef{markdownRendererBlockHtmlStandaloneTag} -- A non-CDATA HTML tag
16201 on a line of its own
16202
16203 Each of these macros receive a single argument. For all macros except 2 and 7,
16204 it is the filename of a file containing the corresponding HTML text. In
16205 contrast, macros 2 and 7 receive the text within the HTML comment and the HTML
16206 text, respectively.
16207
16208 [html-blocks]: https://spec.commonmark.org/0.31.2/#html-blocks
16209
16210 % \end{markdown}
16211 %
16212 % \iffalse
16213
16214 ##### \LaTeX{} Example {.unnumbered}
16215
16216 Using a text editor, create a text document named `document.tex` with the
16217 following content:
16218 ``` tex
16219 \documentclass{article}
16220 \usepackage{markdown}
16221 \usepackage{marginnote}
16222 \usepackage{verbatim}
16223 \markdownSetup{
16224 htmlOutput = commonmark,
16225 renderers = {
16226 blockHtmlComment = \marginnote{#1},
16227 },
16228 }
16229 \begin{document}
16230 \begin{markdown}
16231 A useful use of block HTML comments are side notes.
16232
16233 <!-- Side notes are displayed in the horizontal margins next to the relevant
16234 passages, which makes them *easier for the reader to find* than notes. -->
16235 \end{markdown}
16236 \end{document}
16237 ```````
16238 Next, invoke LuaTeX from the terminal:
16239 ``` sh
16240 lualatex document.tex
16241 lualatex document.tex
16242 ``````
16243 A PDF document named `document.pdf` should be produced and contain the
16244 following body text:
16245
16246 > A useful use of HTML comments are side notes.
16247
16248 The horizontal margins should contain the following text:
16249
16250 > Side notes are displayed in the horizontal margins next to the relevant
16251 > passages, which makes them *easier for the reader to find* than notes.
16252
16253 %</manual-tokens>
16254 %<*tex>
16255 % \fi
16256 %
16257 % \begin{macrocode}
16258 \ExplSyntaxOn
16259 \cs_gset_protected:Npn
16260 \markdownRendererInputBlockHtmlCdataElement
16261 {
16262 \markdownRendererInputBlockHtmlCdataElementPrototype
16263 }
16264 \seq_gput_right:Nn
16265 \g_@@_renderers_seq
16266 { inputBlockHtmlCdataElement }
16267 \prop_gput:Nnn
16268 \g_@@_renderer_arities_prop
16269 { inputBlockHtmlCdataElement }
16270 { 1 }
16271 \cs_gset_protected:Npn
16272 \markdownRendererBlockHtmlComment
16273 {
16274 \markdownRendererBlockHtmlCommentPrototype
16275 }
16276 \seq_gput_right:Nn
16277 \g_@@_renderers_seq
16278 { blockHtmlComment }
16279 \prop_gput:Nnn
16280 \g_@@_renderer_arities_prop
16281 { blockHtmlComment }
16282 { 1 }
16283 \cs_gset_protected:Npn
16284 \markdownRendererInputBlockHtmlProcessingInstruction
16285 {
16286 \markdownRendererInputBlockHtmlProcessingInstructionPrototype
16287 }
16288 \seq_gput_right:Nn
16289 \g_@@_renderers_seq
16290 { inputBlockHtmlProcessingInstruction }
16291 \prop_gput:Nnn
16292 \g_@@_renderer_arities_prop
16293 { inputBlockHtmlProcessingInstruction }
16294 { 1 }
16295 \cs_gset_protected:Npn
16296 \markdownRendererInputBlockHtmlDeclaration
16297 {
16298 \markdownRendererInputBlockHtmlDeclarationPrototype
16299 }
16300 \seq_gput_right:Nn
16301 \g_@@_renderers_seq
16302 { inputBlockHtmlDeclaration }
16303 \prop_gput:Nnn
16304 \g_@@_renderer_arities_prop
16305 { inputBlockHtmlDeclaration }
16306 { 1 }
16307 \cs_gset_protected:Npn
16308 \markdownRendererInputBlockHtmlCdataSection
16309 {
16310 \markdownRendererInputBlockHtmlCdataSectionPrototype
16311 }
16312 \seq_gput_right:Nn
16313 \g_@@_renderers_seq
16314 { inputBlockHtmlCdataSection }
16315 \prop_gput:Nnn
16316 \g_@@_renderer_arities_prop
16317 { inputBlockHtmlCdataSection }
16318 { 1 }
16319 \cs_gset_protected:Npn
16320 \markdownRendererInputBlockHtmlPcdataElement
16321 {
16322 \markdownRendererInputBlockHtmlPcdataElementPrototype
16323 }
16324 \seq_gput_right:Nn
16325 \g_@@_renderers_seq
16326 { inputBlockHtmlPcdataElement }
16327 \prop_gput:Nnn
16328 \g_@@_renderer_arities_prop
16329 { inputBlockHtmlPcdataElement }
16330 { 1 }
16331 \cs_gset_protected:Npn
16332 \markdownRendererBlockHtmlStandaloneTag
16333 {
16334 \markdownRendererBlockHtmlStandaloneTagPrototype
16335 }
16336 \seq_gput_right:Nn
16337 \g_@@_renderers_seq
16338 { blockHtmlStandaloneTag }
16339 \prop_gput:Nnn
16340 \g_@@_renderer_arities_prop
16341 { blockHtmlStandaloneTag }
16342 { 1 }
16343 \ExplSyntaxOff
16344 % \end{macrocode}
16345 %
16346 % \iffalse
16347 %</tex>
16348 %<*manual-tokens>
16349 % \fi
16350 %
16351 % \begin{markdown}
16352
16353 #### CommonMark Raw HTML Renderers {#commonmark-raw-html-renderers}
16354
16355 When the \Opt{html} option is enabled and \Opt{htmlOutput} is set to
16356 \opt{commonmark}, the following renderers are produced instead of
16357 \mref{markdownRendererInlineHtmlTag} to distinguish between different top-level
16358 non-terminal elements of CommonMark's grammar for [raw HTML][raw-html]:
16359
16360 - \mdef{markdownRendererInlineHtmlProcessingInstruction} -- A processing
16361 instruction
16362 - \mdef{markdownRendererInlineHtmlDeclaration} -- A declaration
16363 - \mdef{markdownRendererInlineHtmlCdataSection} -- A CDATA section
16364 - \mdef{markdownRendererInlineHtmlOpenTag} -- An opening tag
16365 - \mdef{markdownRendererInlineHtmlCloseTag} -- A closing tag
16366 - \mdef{markdownRendererInlineHtmlEmptyTag} -- An empty tag
16367
16368 Each of these macros receives a single argument with the HTML text.
16369
16370 [raw-html]: https://spec.commonmark.org/0.31.2/#raw-html
16371
16372 % \end{markdown}
16373 %
16374 % \iffalse
16375
16376 ##### \LaTeX{} Example {.unnumbered}
16377
16378 Using a text editor, create a text document named `document.tex` with the
16379 following content:
16380 ``` tex
16381 \documentclass{article}
16382 \usepackage{markdown}
16383 \usepackage{verbatim}
16384 \markdownSetup{
16385 htmlOutput = commonmark,
16386 renderers = {
16387 inlineHtmlOpenTag = {\textit{#1}},
16388 inlineHtmlCloseTag = {\textbf{#1}},
16389 inlineHtmlEmptyTag = {\texttt{#1}},
16390 },
16391 }
16392 \begin{document}
16393 \begin{markdown}
16394 <b>_Hello,_ world!</b><br/>
16395 \end{markdown}
16396 \end{document}
16397 ```````
16398 Next, invoke LuaTeX from the terminal:
16399 ``` sh
16400 lualatex document.tex
16401 lualatex document.tex
16402 ``````
16403 A PDF document named `document.pdf` should be produced and contain the
16404 following body text:
16405
16406 > _&lt;b&gt;_*Hello,* world!**&lt;/b&gt;**`<br/>`
16407
16408 %</manual-tokens>
16409 %<*tex>
16410 % \fi
16411 %
16412 % \begin{macrocode}
16413 \ExplSyntaxOn
16414 \cs_gset_protected:Npn
16415 \markdownRendererInlineHtmlProcessingInstruction
16416 {
16417 \markdownRendererInlineHtmlProcessingInstructionPrototype
16418 }
16419 \seq_gput_right:Nn
16420 \g_@@_renderers_seq
16421 { inlineHtmlProcessingInstruction }
16422 \prop_gput:Nnn
16423 \g_@@_renderer_arities_prop
16424 { inlineHtmlProcessingInstruction }
16425 { 1 }
16426 \cs_gset_protected:Npn
16427 \markdownRendererInlineHtmlDeclaration
16428 {
16429 \markdownRendererInlineHtmlDeclarationPrototype
16430 }
16431 \seq_gput_right:Nn
16432 \g_@@_renderers_seq
16433 { inlineHtmlDeclaration }
16434 \prop_gput:Nnn
16435 \g_@@_renderer_arities_prop
16436 { inlineHtmlDeclaration }
16437 { 1 }
16438 \cs_gset_protected:Npn
16439 \markdownRendererInlineHtmlCdataSection
16440 {
16441 \markdownRendererInlineHtmlCdataSectionPrototype
16442 }
16443 \seq_gput_right:Nn
16444 \g_@@_renderers_seq
16445 { inlineHtmlCdataSection }
16446 \prop_gput:Nnn
16447 \g_@@_renderer_arities_prop
16448 { inlineHtmlCdataSection }
16449 { 1 }
16450 \cs_gset_protected:Npn
16451 \markdownRendererInlineHtmlOpenTag
16452 {
16453 \markdownRendererInlineHtmlOpenTagPrototype
16454 }
16455 \seq_gput_right:Nn
16456 \g_@@_renderers_seq
16457 { inlineHtmlOpenTag }
16458 \prop_gput:Nnn
16459 \g_@@_renderer_arities_prop
16460 { inlineHtmlOpenTag }
16461 { 1 }
16462 \cs_gset_protected:Npn
16463 \markdownRendererInlineHtmlCloseTag
16464 {
16465 \markdownRendererInlineHtmlCloseTagPrototype
16466 }
16467 \seq_gput_right:Nn
16468 \g_@@_renderers_seq
16469 { inlineHtmlCloseTag }
16470 \prop_gput:Nnn
16471 \g_@@_renderer_arities_prop
16472 { inlineHtmlCloseTag }
16473 { 1 }
16474 \cs_gset_protected:Npn
16475 \markdownRendererInlineHtmlEmptyTag
16476 {
16477 \markdownRendererInlineHtmlEmptyTagPrototype
16478 }
16479 \seq_gput_right:Nn
16480 \g_@@_renderers_seq
16481 { inlineHtmlEmptyTag }
16482 \prop_gput:Nnn
16483 \g_@@_renderer_arities_prop
16484 { inlineHtmlEmptyTag }
16485 { 1 }
16486 \ExplSyntaxOff
16487 % \end{macrocode}
16488 %
16489 % \iffalse
16490 %</tex>
16491 %<*manual-tokens>
16492 % \fi
16493 %
16494 % \begin{markdown}
16495
16496 #### Content Block Renderers {#texcontentblockrenderers}
16497
16498 The \mdef{markdownRendererContentBlock} macro represents an iA\\,Writer content
16499 block. It receives four arguments: the local file or online image filename
16500 extension cast to the lower case, the fully escaped URI that can be
16501 directly typeset, the raw URI that can be used outside typesetting,
16502 and the title of the content block.
16503
16504 % \end{markdown}
16505 %
16506 % \iffalse
16507 %</manual-tokens>
16508 %<*tex>
16509 % \fi
16510 %
16511 % \begin{macrocode}
16512 \ExplSyntaxOn
16513 \cs_gset_protected:Npn
16514 \markdownRendererContentBlock
16515 {
16516 \markdownRendererContentBlockPrototype
16517 }
16518 \seq_gput_right:Nn
16519 \g_@@_renderers_seq
16520 { contentBlock }
16521 \prop_gput:Nnn
16522 \g_@@_renderer_arities_prop
16523 { contentBlock }
16524 { 4 }
16525 \ExplSyntaxOff
16526 % \end{macrocode}
16527 %
16528 % \iffalse
16529 %</tex>
16530 %<*manual-tokens>
16531 % \fi
16532 %
16533 % \begin{markdown}
16534
16535 The \mdef{markdownRendererContentBlockOnlineImage} macro represents an
16536 iA\\,Writer online image content block. The macro receives the same arguments
16537 as \mref{markdownRendererContentBlock}.
16538
16539 % \end{markdown}
16540 %
16541 % \iffalse
16542 %</manual-tokens>
16543 %<*tex>
16544 % \fi
16545 %
16546 % \begin{macrocode}
16547 \ExplSyntaxOn
16548 \cs_gset_protected:Npn
16549 \markdownRendererContentBlockOnlineImage
16550 {
16551 \markdownRendererContentBlockOnlineImagePrototype
16552 }
16553 \seq_gput_right:Nn
16554 \g_@@_renderers_seq
16555 { contentBlockOnlineImage }
16556 \prop_gput:Nnn
16557 \g_@@_renderer_arities_prop
16558 { contentBlockOnlineImage }
16559 { 4 }
16560 \ExplSyntaxOff
16561 % \end{macrocode}
16562 %
16563 % \iffalse
16564 %</tex>
16565 %<*manual-tokens>
16566 % \fi
16567 %
16568 % \begin{markdown}
16569
16570 The \mdef{markdownRendererContentBlockCode} macro represents an iA\\,Writer
16571 content block that was recognized as a file in a known programming language
16572 by its filename extension $s$. If any `markdown-languages.json` file found
16573 by \pkg{kpathsea}^[Filenames other than `markdown-languages.json` may
16574 be specified using the `contentBlocksLanguageMap` Lua option.] contains a
16575 record $(k, v)$, then a non-online-image content block with the filename
16576 extension $s, s$`:lower()`${}=k$ is considered to be in a known programming
16577 language $v$.
16578 The macro receives five arguments: the local file name extension $s$ cast to
16579 the lower case, the language $v$, the fully escaped URI that can be
16580 directly typeset, the raw URI that can be used outside typesetting,
16581 and the title of the content block.
16582
16583 Note that you will need to place place a `markdown-languages.json` file
16584 inside your working directory or inside your local \TeX{} directory
16585 structure. In this file, you will define a mapping between filename
16586 extensions and the language names recognized by your favorite syntax
16587 highlighter; there may exist other creative uses beside syntax highlighting.
16588 % The `Languages.json` file provided by @sotkov17 is a good starting point.
16589 % \end{markdown}
16590 %
16591 % \iffalse
16592 [The `Languages.json` file provided by Anton Sotkov][sotkov17] is a good
16593 starting point.
16594
16595 [sotkov17]: https://github.com/iainc/Markdown-Content-Blocks
16596 (File transclusion syntax for Markdown)
16597
16598 ##### Plain \TeX{} Example {.unnumbered}
16599
16600 Using a text editor, create a text document named `document.tex` with the
16601 following content:
16602 ``` tex
16603 \input markdown
16604 \def\markdownOptionContentBlocks{true}
16605 \def\markdownRendererContentBlock#1#2#3#4{%
16606 This is {\tt #2}, #4.
16607 }
16608 \def\markdownRendererContentBlockOnlineImage#1#2#3#4{%
16609 This is the image {\tt #2}, #4.
16610 }
16611 \def\markdownRendererContentBlockCode#1#2#3#4#5{%
16612 This is the #2 (\uppercase{#1}) document {\tt #3}, #5.
16613 }
16614 \markdownBegin
16615 /document.tex (the document that we are currently typesetting)
16616 /markdown-languages.json (the mapping between filename extensions
16617 and programming language names)
16618 https://tug.org/tugboat/noword.jpg (the logotype of TUGboat)
16619 \markdownEnd
16620 \bye
16621 ```````
16622 Create also a text document named `markdown-languages.json` with the following
16623 content:
16624 ``` js
16625 {
16626 "json": "JavaScript Object Notation",
16627 }
16628 ``````
16629 Next, invoke LuaTeX from the terminal:
16630 ``` sh
16631 luatex document.tex
16632 ``````
16633 A PDF document named `document.pdf` should be produced and contain the
16634 following text:
16635
16636 > This is `document.tex`, the document that we are currently typesetting.
16637 >
16638 > This is the JavaScript Object Notation (JSON) document
16639 > `markdown-languages.json`, the mapping between filename extensions and
16640 > programming language names.
16641 >
16642 > This is the image `https://tug.org/tugboat/noword.jpg`, the logotype of
16643 > TUGboat.
16644
16645 ##### \LaTeX{} Example {.unnumbered}
16646
16647 Using a text editor, create a text document named `document.tex` with the
16648 following content:
16649 ``` tex
16650 \documentclass{article}
16651 \begin{filecontents}[overwrite,nosearch,noheader]{markdown-languages.json}
16652 {
16653 "json": "JavaScript Object Notation",
16654 }
16655 \end{filecontents}
16656 \usepackage[contentBlocks]{markdown}
16657 \markdownSetup{
16658 renderers = {
16659 contentBlock = {This is \texttt{#2}, #4.},
16660 contentBlockOnlineImage = {This is the image \texttt{#2}, #4.},
16661 contentBlockCode = {%
16662 This is the #2 (\MakeUppercase{#1}) document \texttt{#3}, #5.
16663 },
16664 },
16665 }
16666 \begin{document}
16667 \begin{markdown}
16668 /document.tex (the document that we are currently typesetting)
16669 /markdown-languages.json (the mapping between filename extensions
16670 and programming language names)
16671 https://tug.org/tugboat/noword.jpg (the logotype of TUGboat)
16672 \end{markdown}
16673 \end{document}
16674 ```````
16675 Next, invoke LuaTeX from the terminal:
16676 ``` sh
16677 lualatex document.tex
16678 ``````
16679 A PDF document named `document.pdf` should be produced and contain the
16680 following text:
16681
16682 > This is `document.tex`, the document that we are currently typesetting.
16683 >
16684 > This is the JavaScript Object Notation (JSON) document
16685 > `markdown-languages.json`, the mapping between filename extensions and
16686 > programming language names.
16687 >
16688 > This is the image `https://tug.org/tugboat/noword.jpg`, the logotype of
16689 > TUGboat.
16690
16691 ##### \Hologo{ConTeXt} Example {.unnumbered}
16692
16693 Using a text editor, create a text document named `document.tex` with the
16694 following content:
16695 ``` tex
16696 \usemodule[t][markdown]
16697 \setupmarkdown[contentBlocks = yes]
16698 \def\markdownRendererContentBlock#1#2#3#4{%
16699 This is {\tt #2}, #4.
16700 }
16701 \def\markdownRendererContentBlockOnlineImage#1#2#3#4{%
16702 This is the image {\tt #2}, #4.
16703 }
16704 \def\markdownRendererContentBlockCode#1#2#3#4#5{%
16705 This is the #2 (\uppercase{#1}) document {\tt #3}, #5.
16706 }
16707 \starttext
16708 \startmarkdown
16709 /document.tex (the document that we are currently typesetting)
16710 /markdown-languages.json (the mapping between filename extensions
16711 and programming language names)
16712 https://tug.org/tugboat/noword.jpg (the logotype of TUGboat)
16713 \stopmarkdown
16714 \stoptext
16715 ```````
16716 Create also a text document named `markdown-languages.json` with the following
16717 content:
16718 ``` js
16719 {
16720 "json": "JavaScript Object Notation",
16721 }
16722 ``````
16723 Next, invoke LuaTeX from the terminal:
16724 ``` sh
16725 context --luatex document.tex
16726 ``````
16727 A PDF document named `document.pdf` should be produced and contain the
16728 following text:
16729
16730 > This is `document.tex`, the document that we are currently typesetting.
16731 >
16732 > This is the JavaScript Object Notation (JSON) document
16733 > `markdown-languages.json`, the mapping between filename extensions and
16734 > programming language names.
16735 >
16736 > This is the image `https://tug.org/tugboat/noword.jpg`, the logotype of
16737 > TUGboat.
16738
16739 %</manual-tokens>
16740 %<*tex>
16741 % \fi
16742 %
16743 % \begin{macrocode}
16744 \ExplSyntaxOn
16745 \cs_gset_protected:Npn
16746 \markdownRendererContentBlockCode
16747 {
16748 \markdownRendererContentBlockCodePrototype
16749 }
16750 \seq_gput_right:Nn
16751 \g_@@_renderers_seq
16752 { contentBlockCode }
16753 \prop_gput:Nnn
16754 \g_@@_renderer_arities_prop
16755 { contentBlockCode }
16756 { 5 }
16757 \ExplSyntaxOff
16758 % \end{macrocode}
16759 %
16760 % \iffalse
16761 %</tex>
16762 %<*manual-tokens>
16763 % \fi
16764 %
16765 % \begin{markdown}
16766
16767 #### Definition List Renderers
16768 The following macros are only produced, when the \Opt{definitionLists} option
16769 is enabled.
16770
16771 The \mdef{markdownRendererDlBegin} macro represents the beginning of a
16772 definition list that contains an item with several paragraphs of text (the
16773 list is not tight). The macro receives no arguments.
16774
16775 % \end{markdown}
16776 %
16777 % \iffalse
16778 %</manual-tokens>
16779 %<*tex>
16780 % \fi
16781 %
16782 % \begin{macrocode}
16783 \ExplSyntaxOn
16784 \cs_gset_protected:Npn
16785 \markdownRendererDlBegin
16786 {
16787 \markdownRendererDlBeginPrototype
16788 }
16789 \seq_gput_right:Nn
16790 \g_@@_renderers_seq
16791 { dlBegin }
16792 \prop_gput:Nnn
16793 \g_@@_renderer_arities_prop
16794 { dlBegin }
16795 { 0 }
16796 \ExplSyntaxOff
16797 % \end{macrocode}
16798 %
16799 % \iffalse
16800 %</tex>
16801 %<*manual-tokens>
16802 % \fi
16803 %
16804 % \begin{markdown}
16805
16806 The \mdef{markdownRendererDlBeginTight} macro represents the beginning of a
16807 definition list that contains no item with several paragraphs of text (the
16808 list is tight). This macro will only be produced, when the
16809 \Opt{tightLists} option is disabled. The macro receives no arguments.
16810
16811 % \end{markdown}
16812 %
16813 % \iffalse
16814 %</manual-tokens>
16815 %<*tex>
16816 % \fi
16817 %
16818 % \begin{macrocode}
16819 \ExplSyntaxOn
16820 \cs_gset_protected:Npn
16821 \markdownRendererDlBeginTight
16822 {
16823 \markdownRendererDlBeginTightPrototype
16824 }
16825 \seq_gput_right:Nn
16826 \g_@@_renderers_seq
16827 { dlBeginTight }
16828 \prop_gput:Nnn
16829 \g_@@_renderer_arities_prop
16830 { dlBeginTight }
16831 { 0 }
16832 \ExplSyntaxOff
16833 % \end{macrocode}
16834 %
16835 % \iffalse
16836 %</tex>
16837 %<*manual-tokens>
16838 % \fi
16839 %
16840 % \begin{markdown}
16841
16842 The \mdef{markdownRendererDlItem} macro represents a term in a definition
16843 list. The macro receives a single argument that corresponds to the term
16844 being defined.
16845
16846 % \end{markdown}
16847 %
16848 % \iffalse
16849 %</manual-tokens>
16850 %<*tex>
16851 % \fi
16852 %
16853 % \begin{macrocode}
16854 \ExplSyntaxOn
16855 \cs_gset_protected:Npn
16856 \markdownRendererDlItem
16857 {
16858 \markdownRendererDlItemPrototype
16859 }
16860 \seq_gput_right:Nn
16861 \g_@@_renderers_seq
16862 { dlItem }
16863 \prop_gput:Nnn
16864 \g_@@_renderer_arities_prop
16865 { dlItem }
16866 { 1 }
16867 \ExplSyntaxOff
16868 % \end{macrocode}
16869 %
16870 % \iffalse
16871 %</tex>
16872 %<*manual-tokens>
16873 % \fi
16874 %
16875 % \begin{markdown}
16876
16877 The \mdef{markdownRendererDlItemEnd} macro represents the end of a list of
16878 definitions for a single term.
16879
16880 % \end{markdown}
16881 %
16882 % \iffalse
16883 %</manual-tokens>
16884 %<*tex>
16885 % \fi
16886 %
16887 % \begin{macrocode}
16888 \ExplSyntaxOn
16889 \cs_gset_protected:Npn
16890 \markdownRendererDlItemEnd
16891 {
16892 \markdownRendererDlItemEndPrototype
16893 }
16894 \seq_gput_right:Nn
16895 \g_@@_renderers_seq
16896 { dlItemEnd }
16897 \prop_gput:Nnn
16898 \g_@@_renderer_arities_prop
16899 { dlItemEnd }
16900 { 0 }
16901 \ExplSyntaxOff
16902 % \end{macrocode}
16903 %
16904 % \iffalse
16905 %</tex>
16906 %<*manual-tokens>
16907 % \fi
16908 %
16909 % \begin{markdown}
16910
16911 The \mdef{markdownRendererDlDefinitionBegin} macro represents the beginning
16912 of a definition in a definition list. There can be several definitions for
16913 a single term.
16914
16915 % \end{markdown}
16916 %
16917 % \iffalse
16918 %</manual-tokens>
16919 %<*tex>
16920 % \fi
16921 %
16922 % \begin{macrocode}
16923 \ExplSyntaxOn
16924 \cs_gset_protected:Npn
16925 \markdownRendererDlDefinitionBegin
16926 {
16927 \markdownRendererDlDefinitionBeginPrototype
16928 }
16929 \seq_gput_right:Nn
16930 \g_@@_renderers_seq
16931 { dlDefinitionBegin }
16932 \prop_gput:Nnn
16933 \g_@@_renderer_arities_prop
16934 { dlDefinitionBegin }
16935 { 0 }
16936 \ExplSyntaxOff
16937 % \end{macrocode}
16938 %
16939 % \iffalse
16940 %</tex>
16941 %<*manual-tokens>
16942 % \fi
16943 %
16944 % \begin{markdown}
16945
16946 The \mdef{markdownRendererDlDefinitionEnd} macro represents the end of a
16947 definition in a definition list. There can be several definitions for a
16948 single term.
16949
16950 % \end{markdown}
16951 %
16952 % \iffalse
16953 %</manual-tokens>
16954 %<*tex>
16955 % \fi
16956 %
16957 % \begin{macrocode}
16958 \ExplSyntaxOn
16959 \cs_gset_protected:Npn
16960 \markdownRendererDlDefinitionEnd
16961 {
16962 \markdownRendererDlDefinitionEndPrototype
16963 }
16964 \seq_gput_right:Nn
16965 \g_@@_renderers_seq
16966 { dlDefinitionEnd }
16967 \prop_gput:Nnn
16968 \g_@@_renderer_arities_prop
16969 { dlDefinitionEnd }
16970 { 0 }
16971 \ExplSyntaxOff
16972 % \end{macrocode}
16973 %
16974 % \iffalse
16975 %</tex>
16976 %<*manual-tokens>
16977 % \fi
16978 %
16979 % \begin{markdown}
16980
16981 The \mdef{markdownRendererDlEnd} macro represents the end of a definition
16982 list that contains an item with several paragraphs of text (the list is not
16983 tight). The macro receives no arguments.
16984
16985 % \end{markdown}
16986 %
16987 % \iffalse
16988 %</manual-tokens>
16989 %<*tex>
16990 % \fi
16991 %
16992 % \begin{macrocode}
16993 \ExplSyntaxOn
16994 \cs_gset_protected:Npn
16995 \markdownRendererDlEnd
16996 {
16997 \markdownRendererDlEndPrototype
16998 }
16999 \seq_gput_right:Nn
17000 \g_@@_renderers_seq
17001 { dlEnd }
17002 \prop_gput:Nnn
17003 \g_@@_renderer_arities_prop
17004 { dlEnd }
17005 { 0 }
17006 \ExplSyntaxOff
17007 % \end{macrocode}
17008 %
17009 % \iffalse
17010 %</tex>
17011 %<*manual-tokens>
17012 % \fi
17013 %
17014 % \begin{markdown}
17015
17016 The \mdef{markdownRendererDlEndTight} macro represents the end of a
17017 definition list that contains no item with several paragraphs of text (the
17018 list is tight). This macro will only be produced, when the \Opt{tightLists}
17019 option is disabled. The macro receives no arguments.
17020
17021 % \end{markdown}
17022 %
17023 % \iffalse
17024
17025 ##### Plain \TeX{} Example {.unnumbered}
17026
17027 Using a text editor, create a text document named `document.tex` with the
17028 following content:
17029 ``` tex
17030 \input markdown
17031 \def\markdownOptionDefinitionLists{true}
17032 \def\markdownOptionTightLists{true}
17033
17034 \def\markdownRendererInterblockSeparator{%
17035 :%
17036 \def\markdownRendererInterblockSeparator{\par}%
17037 }
17038 \def\markdownRendererDlBeginTight{%
17039 \begingroup
17040 \parindent=0pt
17041 }
17042 \def\markdownRendererDlItem#1{%
17043 \par{\bf#1}%
17044 \def\markdownRendererDlDefinitionEnd{%
17045 ,
17046 \def\markdownRendererDlDefinitionEnd{%
17047 , and
17048 \def\markdownRendererDlDefinitionEnd{.}%
17049 }%
17050 }%
17051 }
17052 \def\markdownRendererDlItemEnd{}
17053 \def\markdownRendererDlDefinitionBegin{\par--\kern 0.5em}
17054 \def\markdownRendererDlEndTight{\endgroup}
17055
17056 \markdownBegin
17057 This is a tight definition list
17058
17059 Coffee
17060 : black hot drink
17061 : prepared from roasted coffee beans
17062 : one of the most traded agricultural commodities in the world
17063
17064 Milk
17065 : white cold drink
17066 : nutrient-rich
17067 : produced on an industrial scale
17068 \markdownEnd
17069
17070 \def\markdownRendererInterblockSeparator{%
17071 \def\markdownRendererInterblockSeparator{\par}%
17072 }
17073 \def\markdownRendererDlBegin{}
17074 \def\markdownRendererDlItem#1{%
17075 . #1 is a
17076 \def\markdownRendererDlDefinitionBegin{%
17077 \def\markdownRendererDlDefinitionBegin{%
17078 ,
17079 \def\markdownRendererDlDefinitionBegin{, and }%
17080 }%
17081 }%
17082 }
17083 \def\markdownRendererDlItemEnd{}
17084 \def\markdownRendererDlDefinitionEnd{}
17085 \def\markdownRendererDlEnd{.}
17086
17087 \markdownBegin
17088 This is a loose definition list
17089
17090 Coffee
17091
17092 : black hot drink
17093
17094 : prepared from roasted coffee beans
17095
17096 : one of the most traded agricultural commodities in the world
17097
17098 Milk
17099
17100 : white cold drink
17101
17102 : nutrient-rich
17103
17104 : produced on an industrial scale
17105 \markdownEnd
17106
17107 \bye
17108 ```````
17109 Next, invoke LuaTeX from the terminal:
17110 ``` sh
17111 luatex document.tex
17112 ``````
17113 A PDF document named `document.pdf` should be produced and contain the
17114 following text:
17115
17116 > This is a tight definition list:
17117 >
17118 > **Coffee**
17119 >
17120 > - black hot drink,
17121 > - prepared from roasted coffee beans, and
17122 > - one of the most traded agricultural commodities in the world.
17123 >
17124 > **Milk**
17125 >
17126 > - white cold drink,
17127 > - nutrient-rich, and
17128 > - produced on an industrial scale.
17129 >
17130 > This is a loose definition list. Coffee is a black hot drink, prepared from
17131 > roasted coffee beans, and one of the most traded agricultural commodities in
17132 > the world. Milk is a white cold drink, nutrient-rich, and produced on an
17133 > industrial scale.
17134
17135 ##### \LaTeX{} Example {.unnumbered}
17136
17137 Using a text editor, create a text document named `document.tex` with the
17138 following content:
17139 ``` tex
17140 \documentclass{article}
17141 \usepackage[definitionLists, tightLists]{markdown}
17142 \begin{document}
17143
17144 \begin{markdown}[
17145 renderers = {
17146 interblockSeparator = {%
17147 :%
17148 \def\markdownRendererInterblockSeparator{\par}%
17149 },
17150 dlBeginTight = {\begin{description}},
17151 dlItem = {%
17152 \item[#1]
17153 \begin{itemize}
17154 \def\markdownRendererDlDefinitionEnd{%
17155 ,
17156 \def\markdownRendererDlDefinitionEnd{%
17157 , and
17158 \def\markdownRendererDlDefinitionEnd{.}%
17159 }%
17160 }%
17161 },
17162 dlItemEnd = {\end{itemize}},
17163 dlDefinitionBegin = \item,
17164 dlEndTight = {\end{description}},
17165 },
17166 ]
17167 This is a tight definition list
17168
17169 Coffee
17170 : black hot drink
17171 : prepared from roasted coffee beans
17172 : one of the most traded agricultural commodities in the world
17173
17174 Milk
17175 : white cold drink
17176 : nutrient-rich
17177 : produced on an industrial scale
17178 \end{markdown}
17179
17180 \begin{markdown}[
17181 renderers = {
17182 interblockSeparator = {%
17183 \def\markdownRendererInterblockSeparator{\par}%
17184 },
17185 dlBegin = {},
17186 dlItem = {%
17187 . #1 is a
17188 \def\markdownRendererDlDefinitionBegin{%
17189 \def\markdownRendererDlDefinitionBegin{%
17190 ,
17191 \def\markdownRendererDlDefinitionBegin{, and }%
17192 }%
17193 }%
17194 },
17195 dlItemEnd = {},
17196 dlDefinitionEnd = {},
17197 dlEnd = {.},
17198 },
17199 ]
17200 This is a loose definition list
17201
17202 Coffee
17203
17204 : black hot drink
17205
17206 : prepared from roasted coffee beans
17207
17208 : one of the most traded agricultural commodities in the world
17209
17210 Milk
17211
17212 : white cold drink
17213
17214 : nutrient-rich
17215
17216 : produced on an industrial scale
17217 \end{markdown}
17218
17219 \end{document}
17220 ```````
17221 Next, invoke LuaTeX from the terminal:
17222 ``` sh
17223 lualatex document.tex
17224 ``````
17225 A PDF document named `document.pdf` should be produced and contain the
17226 following text:
17227
17228 > This is a tight definition list:
17229 >
17230 > **Coffee**
17231 >
17232 > - black hot drink,
17233 > - prepared from roasted coffee beans, and
17234 > - one of the most traded agricultural commodities in the world.
17235 >
17236 > **Milk**
17237 >
17238 > - white cold drink,
17239 > - nutrient-rich, and
17240 > - produced on an industrial scale.
17241 >
17242 > This is a loose definition list. Coffee is a black hot drink, prepared from
17243 > roasted coffee beans, and one of the most traded agricultural commodities in
17244 > the world. Milk is a white cold drink, nutrient-rich, and produced on an
17245 > industrial scale.
17246
17247 ##### \Hologo{ConTeXt} Example {.unnumbered}
17248
17249 Using a text editor, create a text document named `document.tex` with the
17250 following content:
17251 ``` tex
17252 \usemodule[t][markdown]
17253 \setupmarkdown
17254 [
17255 definitionLists = yes,
17256 tightLists = yes,
17257 ]
17258 \starttext
17259
17260 \def\markdownRendererInterblockSeparator{%
17261 :%
17262 \def\markdownRendererInterblockSeparator{\par}%
17263 }
17264 \def\markdownRendererDlBeginTight{}
17265 \def\markdownRendererDlItem#1{%
17266 \par{\bf#1}%
17267 \startitemize
17268 \def\markdownRendererDlDefinitionEnd{%
17269 ,
17270 \def\markdownRendererDlDefinitionEnd{%
17271 , and
17272 \def\markdownRendererDlDefinitionEnd{.}%
17273 }%
17274 }%
17275 }
17276 \def\markdownRendererDlItemEnd{\stopitemize}
17277 \def\markdownRendererDlDefinitionBegin{\item}
17278 \def\markdownRendererDlEndTight{}
17279
17280 \startmarkdown
17281 This is a tight definition list
17282
17283 Coffee
17284 : black hot drink
17285 : prepared from roasted coffee beans
17286 : one of the most traded agricultural commodities in the world
17287
17288 Milk
17289 : white cold drink
17290 : nutrient-rich
17291 : produced on an industrial scale
17292 \stopmarkdown
17293
17294 \def\markdownRendererInterblockSeparator{%
17295 \def\markdownRendererInterblockSeparator{\par}%
17296 }
17297 \def\markdownRendererDlBegin{}
17298 \def\markdownRendererDlItem#1{%
17299 . #1 is a
17300 \def\markdownRendererDlDefinitionBegin{%
17301 \def\markdownRendererDlDefinitionBegin{%
17302 ,
17303 \def\markdownRendererDlDefinitionBegin{, and }%
17304 }%
17305 }%
17306 }
17307 \def\markdownRendererDlItemEnd{}
17308 \def\markdownRendererDlDefinitionEnd{}
17309 \def\markdownRendererDlEnd{.}
17310
17311 \startmarkdown
17312 This is a loose definition list
17313
17314 Coffee
17315
17316 : black hot drink
17317
17318 : prepared from roasted coffee beans
17319
17320 : one of the most traded agricultural commodities in the world
17321
17322 Milk
17323
17324 : white cold drink
17325
17326 : nutrient-rich
17327
17328 : produced on an industrial scale
17329 \stopmarkdown
17330
17331 \stoptext
17332 ```````
17333 Next, invoke LuaTeX from the terminal:
17334 ``` sh
17335 context --luatex document.tex
17336 ``````
17337 A PDF document named `document.pdf` should be produced and contain the
17338 following text:
17339
17340 > This is a tight definition list:
17341 >
17342 > **Coffee**
17343 >
17344 > - black hot drink,
17345 > - prepared from roasted coffee beans, and
17346 > - one of the most traded agricultural commodities in the world.
17347 >
17348 > **Milk**
17349 >
17350 > - white cold drink,
17351 > - nutrient-rich, and
17352 > - produced on an industrial scale.
17353 >
17354 > This is a loose definition list. Coffee is a black hot drink, prepared from
17355 > roasted coffee beans, and one of the most traded agricultural commodities in
17356 > the world. Milk is a white cold drink, nutrient-rich, and produced on an
17357 > industrial scale.
17358
17359 %</manual-tokens>
17360 %<*tex>
17361 % \fi
17362 %
17363 % \begin{macrocode}
17364 \ExplSyntaxOn
17365 \cs_gset_protected:Npn
17366 \markdownRendererDlEndTight
17367 {
17368 \markdownRendererDlEndTightPrototype
17369 }
17370 \seq_gput_right:Nn
17371 \g_@@_renderers_seq
17372 { dlEndTight }
17373 \prop_gput:Nnn
17374 \g_@@_renderer_arities_prop
17375 { dlEndTight }
17376 { 0 }
17377 \ExplSyntaxOff
17378 % \end{macrocode}
17379 %
17380 % \iffalse
17381 %</tex>
17382 %<*manual-tokens>
17383 % \fi
17384 %
17385 % \begin{markdown}
17386
17387 #### Ellipsis Renderer
17388 The \mdef{markdownRendererEllipsis} macro replaces any occurrence of ASCII
17389 ellipses in the input text. This macro will only be produced, when the
17390 \Opt{smartEllipses} option is enabled. The macro receives no arguments.
17391
17392 % \end{markdown}
17393 %
17394 % \iffalse
17395
17396 ##### Plain \TeX{} Example {.unnumbered}
17397
17398 Using a text editor, create a text document named `document.tex` with the
17399 following content:
17400 ``` tex
17401 \input markdown
17402 \def\markdownOptionSmartEllipses{true}
17403 \def\markdownRendererEllipsis{{\it SHAZAM}!}
17404 \markdownBegin
17405 The secret word is ...
17406 \markdownEnd
17407 \bye
17408 ```````
17409 Next, invoke LuaTeX from the terminal:
17410 ``` sh
17411 luatex document.tex
17412 ``````
17413 A PDF document named `document.pdf` should be produced and contain the
17414 following text:
17415
17416 > The secret word is *SHAZAM*!
17417
17418 ##### \LaTeX{} Example {.unnumbered}
17419
17420 Using a text editor, create a text document named `document.tex` with the
17421 following content:
17422 ``` tex
17423 \documentclass{article}
17424 \usepackage[smartEllipses]{markdown}
17425 \markdownSetup{
17426 renderers = {
17427 ellipsis = \emph{SHAZAM}!,
17428 },
17429 }
17430 \begin{document}
17431 \begin{markdown}
17432 The secret word is ...
17433 \end{markdown}
17434 \end{document}
17435 ```````
17436 Next, invoke LuaTeX from the terminal:
17437 ``` sh
17438 lualatex document.tex
17439 ``````
17440 A PDF document named `document.pdf` should be produced and contain the
17441 following text:
17442
17443 > The secret word is *SHAZAM*!
17444
17445 ##### \Hologo{ConTeXt} Example {.unnumbered}
17446
17447 Using a text editor, create a text document named `document.tex` with the
17448 following content:
17449 ``` tex
17450 \usemodule[t][markdown]
17451 \setupmarkdown[smartEllipses = yes]
17452 \def\markdownRendererEllipsis{\emph{SHAZAM}!}
17453 \starttext
17454 \startmarkdown
17455 The secret word is ...
17456 \stopmarkdown
17457 \stoptext
17458 ```````
17459 Next, invoke LuaTeX from the terminal:
17460 ``` sh
17461 context --luatex document.tex
17462 ``````
17463 A PDF document named `document.pdf` should be produced and contain the
17464 following text:
17465
17466 > Hello *world*!
17467 >
17468 > *(The end of a block)*
17469 >
17470 > _Foo_ bar!
17471
17472 %</manual-tokens>
17473 %<*tex>
17474 % \fi
17475 %
17476 % \begin{macrocode}
17477 \ExplSyntaxOn
17478 \cs_gset_protected:Npn
17479 \markdownRendererEllipsis
17480 {
17481 \markdownRendererEllipsisPrototype
17482 }
17483 \seq_gput_right:Nn
17484 \g_@@_renderers_seq
17485 { ellipsis }
17486 \prop_gput:Nnn
17487 \g_@@_renderer_arities_prop
17488 { ellipsis }
17489 { 0 }
17490 \ExplSyntaxOff
17491 % \end{macrocode}
17492 %
17493 % \iffalse
17494 %</tex>
17495 %<*manual-tokens>
17496 % \fi
17497 %
17498 % \begin{markdown}
17499
17500 #### Emphasis Renderers {#emphasis-renderers}
17501 The \mdef{markdownRendererEmphasis} macro represents an emphasized span of
17502 text. The macro receives a single argument that corresponds to the emphasized
17503 span of text.
17504
17505 % \end{markdown}
17506 %
17507 % \iffalse
17508 %</manual-tokens>
17509 %<*tex>
17510 % \fi
17511 %
17512 % \begin{macrocode}
17513 \ExplSyntaxOn
17514 \cs_gset_protected:Npn
17515 \markdownRendererEmphasis
17516 {
17517 \markdownRendererEmphasisPrototype
17518 }
17519 \seq_gput_right:Nn
17520 \g_@@_renderers_seq
17521 { emphasis }
17522 \prop_gput:Nnn
17523 \g_@@_renderer_arities_prop
17524 { emphasis }
17525 { 1 }
17526 \ExplSyntaxOff
17527 % \end{macrocode}
17528 %
17529 % \iffalse
17530 %</tex>
17531 %<*manual-tokens>
17532 % \fi
17533 %
17534 % \begin{markdown}
17535
17536 The \mdef{markdownRendererStrongEmphasis} macro represents a strongly
17537 emphasized span of text. The macro receives a single argument that
17538 corresponds to the emphasized span of text.
17539
17540 % \end{markdown}
17541 %
17542 % \iffalse
17543
17544 ##### Plain \TeX{} Example {.unnumbered}
17545
17546 Using a text editor, create a text document named `document.tex` with the
17547 following content:
17548 ``` tex
17549 \input markdown
17550 \def\markdownRendererEmphasis#1{{\it#1}}
17551 \def\markdownRendererStrongEmphasis#1{{\bf#1}}
17552 \markdownBegin
17553 This is *emphasis*.
17554
17555 This is **strong emphasis**.
17556 \markdownEnd
17557 \bye
17558 ```````
17559 Next, invoke LuaTeX from the terminal:
17560 ``` sh
17561 luatex document.tex
17562 ``````
17563 A PDF document named `document.pdf` should be produced and contain the
17564 following text:
17565
17566 > This is *emphasis*.
17567 >
17568 > This is **strong emphasis**.
17569
17570 ##### \LaTeX{} Example {.unnumbered}
17571
17572 Using a text editor, create a text document named `document.tex` with the
17573 following content:
17574 ``` tex
17575 \documentclass{article}
17576 \usepackage{markdown}
17577 \markdownSetup{
17578 renderers = {
17579 emphasis = {\emph{#1}},
17580 strongEmphasis = {\textbf{#1}},
17581 },
17582 }
17583 \begin{document}
17584 \begin{markdown}
17585 This is *emphasis*.
17586
17587 This is **strong emphasis**.
17588 \end{markdown}
17589 \end{document}
17590 ```````
17591 Next, invoke LuaTeX from the terminal:
17592 ``` sh
17593 lualatex document.tex
17594 ``````
17595 A PDF document named `document.pdf` should be produced and contain the
17596 following text:
17597
17598 > This is *emphasis*.
17599 >
17600 > This is **strong emphasis**.
17601
17602 ##### \Hologo{ConTeXt} Example {.unnumbered}
17603
17604 Using a text editor, create a text document named `document.tex` with the
17605 following content:
17606 ``` tex
17607 \usemodule[t][markdown]
17608 \def\markdownRendererEmphasis#1{\emph{#1}}
17609 \def\markdownRendererStrongEmphasis#1{\bold{#1}}
17610 \starttext
17611 \startmarkdown
17612 This is *emphasis*.
17613
17614 This is **strong emphasis**.
17615 \stopmarkdown
17616 \stoptext
17617 ```````
17618 Next, invoke LuaTeX from the terminal:
17619 ``` sh
17620 context --luatex document.tex
17621 ``````
17622 A PDF document named `document.pdf` should be produced and contain the
17623 following text:
17624
17625 > This is *emphasis*.
17626 >
17627 > This is **strong emphasis**.
17628
17629 %</manual-tokens>
17630 %<*tex>
17631 % \fi
17632 %
17633 % \begin{macrocode}
17634 \ExplSyntaxOn
17635 \cs_gset_protected:Npn
17636 \markdownRendererStrongEmphasis
17637 {
17638 \markdownRendererStrongEmphasisPrototype
17639 }
17640 \seq_gput_right:Nn
17641 \g_@@_renderers_seq
17642 { strongEmphasis }
17643 \prop_gput:Nnn
17644 \g_@@_renderer_arities_prop
17645 { strongEmphasis }
17646 { 1 }
17647 \ExplSyntaxOff
17648 % \end{macrocode}
17649 %
17650 % \iffalse
17651 %</tex>
17652 %<*manual-tokens>
17653 % \fi
17654 %
17655 % \begin{markdown}
17656
17657 #### Fenced Code Attribute Context Renderers
17658 The following macros are only produced, when the \Opt{fencedCode} and
17659 \Opt{fencedCodeAttributes} options are enabled.
17660
17661 The \mdef{markdownRendererFencedCodeAttributeContextBegin} and
17662 \mdef{markdownRendererFencedCodeAttributeContextEnd} macros represent the
17663 beginning and the end of a context in which the attributes of a fenced code
17664 apply. The macros receive no arguments.
17665
17666 % \end{markdown}
17667 %
17668 % \iffalse
17669
17670 ##### \LaTeX{} Example {.unnumbered}
17671
17672 Using a text editor, create a text document named `document.tex` with the
17673 following content:
17674 ```` tex
17675 \documentclass{article}
17676 \usepackage[fencedCode,
17677 fencedCodeAttributes]{markdown}
17678 \usepackage{minted}
17679 \markdownSetup{
17680 renderers = {
17681 fencedCodeAttributeContextBegin = {%
17682 \begingroup
17683 \markdownSetup{
17684 renderers = {
17685 attributeKeyValue = {%
17686 \setminted{{#1} = {#2}}%
17687 },
17688 },
17689 }%
17690 },
17691 fencedCodeAttributeContextEnd = {%
17692 \endgroup
17693 },
17694 },
17695 }
17696 \begin{document}
17697 \begin{markdown}
17698 ~~~ js {linenos=true}
17699 if (a > 3) {
17700 moveShip(5 * gravity, DOWN);
17701 }
17702 ~~~~~~
17703 \end{markdown}
17704 \end{document}
17705 ```````
17706 Next, invoke LuaTeX from the terminal:
17707 ``` sh
17708 lualatex --shell-escape document.tex
17709 ``````
17710 A PDF document named `document.pdf` should be produced and contain the
17711 following text:
17712
17713 > ``` js {.linenos}
17714 > 1. if (a > 3) {
17715 > 2. moveShip(5 * gravity, DOWN);
17716 > 3. }
17717 > ``````
17718
17719 %</manual-tokens>
17720 %<*tex>
17721 % \fi
17722 %
17723 % \begin{macrocode}
17724 \ExplSyntaxOn
17725 \cs_gset_protected:Npn
17726 \markdownRendererFencedCodeAttributeContextBegin
17727 {
17728 \markdownRendererFencedCodeAttributeContextBeginPrototype
17729 }
17730 \seq_gput_right:Nn
17731 \g_@@_renderers_seq
17732 { fencedCodeAttributeContextBegin }
17733 \prop_gput:Nnn
17734 \g_@@_renderer_arities_prop
17735 { fencedCodeAttributeContextBegin }
17736 { 0 }
17737 \cs_gset_protected:Npn
17738 \markdownRendererFencedCodeAttributeContextEnd
17739 {
17740 \markdownRendererFencedCodeAttributeContextEndPrototype
17741 }
17742 \seq_gput_right:Nn
17743 \g_@@_renderers_seq
17744 { fencedCodeAttributeContextEnd }
17745 \prop_gput:Nnn
17746 \g_@@_renderer_arities_prop
17747 { fencedCodeAttributeContextEnd }
17748 { 0 }
17749 \ExplSyntaxOff
17750 % \end{macrocode}
17751 %
17752 % \iffalse
17753 %</tex>
17754 %<*manual-tokens>
17755 % \fi
17756 %
17757 % \begin{markdown}
17758
17759 #### Fenced Div Attribute Context Renderers
17760 The following macros are only produced, when the \Opt{fencedDivs} option is
17761 enabled.
17762
17763 The \mdef{markdownRendererFencedDivAttributeContextBegin} and
17764 \mdef{markdownRendererFencedDivAttributeContextEnd} macros represent the beginning
17765 and the end of a context in which the attributes of a div apply. The macros
17766 receive no arguments.
17767
17768 % \end{markdown}
17769 %
17770 % \iffalse
17771
17772 ##### \LaTeX{} Example {.unnumbered}
17773
17774 Using a text editor, create a text document named `document.tex` with the
17775 following content:
17776 ``` tex
17777 \documentclass{article}
17778 \usepackage[fencedDivs]{markdown}
17779 \markdownSetup{
17780 renderers = {
17781 fencedDivAttributeContextBegin = {%
17782 \par
17783 \emph{(The beginning of a fenced div attribute context)}
17784 \par
17785 },
17786 fencedDivAttributeContextEnd = {%
17787 \par
17788 \emph{(The end of a fenced div attribute context)}
17789 \par
17790 },
17791 },
17792 }
17793 \begin{document}
17794 \begin{markdown}
17795
17796 ::: {key=value}
17797
17798 foo
17799
17800 :::: {#identifier}
17801
17802 bar
17803
17804 ::::
17805
17806 :::
17807
17808 ::: {.class_name}
17809
17810 baz
17811
17812 :::
17813
17814 \end{markdown}
17815 \end{document}
17816 ```````
17817 Next, invoke LuaTeX from the terminal:
17818 ``` sh
17819 lualatex document.tex
17820 ``````
17821 A PDF document named `document.pdf` should be produced and contain the
17822 following text:
17823
17824 > *(The beginning of a fenced div attribute context)*
17825 >
17826 > foo
17827 >
17828 > *(The beginning of a fenced div attribute context)*
17829 >
17830 > bar
17831 >
17832 > *(The end of a fenced div attribute context)*
17833 >
17834 > *(The end of a fenced div attribute context)*
17835 >
17836 > *(The beginning of a fenced div attribute context)*
17837 >
17838 > baz
17839 >
17840 > *(The end of a fenced div attribute context)*
17841
17842 %</manual-tokens>
17843 %<*tex>
17844 % \fi
17845 %
17846 % \begin{macrocode}
17847 \ExplSyntaxOn
17848 \cs_gset_protected:Npn
17849 \markdownRendererFencedDivAttributeContextBegin
17850 {
17851 \markdownRendererFencedDivAttributeContextBeginPrototype
17852 }
17853 \seq_gput_right:Nn
17854 \g_@@_renderers_seq
17855 { fencedDivAttributeContextBegin }
17856 \prop_gput:Nnn
17857 \g_@@_renderer_arities_prop
17858 { fencedDivAttributeContextBegin }
17859 { 0 }
17860 \cs_gset_protected:Npn
17861 \markdownRendererFencedDivAttributeContextEnd
17862 {
17863 \markdownRendererFencedDivAttributeContextEndPrototype
17864 }
17865 \seq_gput_right:Nn
17866 \g_@@_renderers_seq
17867 { fencedDivAttributeContextEnd }
17868 \prop_gput:Nnn
17869 \g_@@_renderer_arities_prop
17870 { fencedDivAttributeContextEnd }
17871 { 0 }
17872 \ExplSyntaxOff
17873 % \end{macrocode}
17874 %
17875 % \iffalse
17876 %</tex>
17877 %<*manual-tokens>
17878 % \fi
17879 %
17880 % \begin{markdown}
17881
17882 #### Header Attribute Context Renderers
17883 The following macros are only produced, when the \Opt{autoIdentifiers},
17884 \Opt{gfmAutoIdentifiers}, or \Opt{headerAttributes} options are enabled.
17885
17886 The \mdef{markdownRendererHeaderAttributeContextBegin} and
17887 \mdef{markdownRendererHeaderAttributeContextEnd} macros represent the beginning
17888 and the end of a context in which the attributes of a heading apply. The macros
17889 receive no arguments.
17890
17891 % \end{markdown}
17892 %
17893 % \iffalse
17894
17895 ##### \LaTeX{} Example {.unnumbered}
17896
17897 Using a text editor, create a text document named `document.tex` with the
17898 following content:
17899 ``` tex
17900 \documentclass{article}
17901 \usepackage[headerAttributes]{markdown}
17902 \markdownSetup{
17903 renderers = {
17904 headerAttributeContextBegin = {%
17905 \par
17906 \emph{(The beginning of a header attribute context)}
17907 \par
17908 },
17909 headerAttributeContextEnd = {%
17910 \par
17911 \emph{(The end of a header attribute context)}
17912 \par
17913 },
17914 },
17915 }
17916 \begin{document}
17917 \begin{markdown}
17918
17919 # First top-level heading
17920
17921 ## A subheading {#identifier}
17922
17923 # Second top-level heading {.class_name}
17924
17925 \end{markdown}
17926 \end{document}
17927 ```````
17928 Next, invoke LuaTeX from the terminal:
17929 ``` sh
17930 lualatex document.tex
17931 ``````
17932 A PDF document named `document.pdf` should be produced and contain the
17933 following text:
17934
17935 > # First top-level heading
17936 >
17937 > *(The beginning of a header attribute context)*
17938 >
17939 > ## A subheading
17940 >
17941 > *(The end of a header attribute context)*
17942 >
17943 > *(The beginning of a header attribute context)*
17944 >
17945 > # Second top-level heading
17946 >
17947 > *(The end of a header attribute context)*
17948
17949 %</manual-tokens>
17950 %<*tex>
17951 % \fi
17952 % \begin{macrocode}
17953 \ExplSyntaxOn
17954 \cs_gset_protected:Npn
17955 \markdownRendererHeaderAttributeContextBegin
17956 {
17957 \markdownRendererHeaderAttributeContextBeginPrototype
17958 }
17959 \seq_gput_right:Nn
17960 \g_@@_renderers_seq
17961 { headerAttributeContextBegin }
17962 \prop_gput:Nnn
17963 \g_@@_renderer_arities_prop
17964 { headerAttributeContextBegin }
17965 { 0 }
17966 \cs_gset_protected:Npn
17967 \markdownRendererHeaderAttributeContextEnd
17968 {
17969 \markdownRendererHeaderAttributeContextEndPrototype
17970 }
17971 \seq_gput_right:Nn
17972 \g_@@_renderers_seq
17973 { headerAttributeContextEnd }
17974 \prop_gput:Nnn
17975 \g_@@_renderer_arities_prop
17976 { headerAttributeContextEnd }
17977 { 0 }
17978 \ExplSyntaxOff
17979 % \end{macrocode}
17980 %
17981 % \iffalse
17982 %</tex>
17983 %<*manual-tokens>
17984 % \fi
17985 %
17986 % \begin{markdown}
17987
17988 #### Heading Renderers
17989 The \mdef{markdownRendererHeadingOne} macro represents a first level heading.
17990 The macro receives a single argument that corresponds to the heading text.
17991
17992 % \end{markdown}
17993 %
17994 % \iffalse
17995 %</manual-tokens>
17996 %<*tex>
17997 % \fi
17998 %
17999 % \begin{macrocode}
18000 \ExplSyntaxOn
18001 \cs_gset_protected:Npn
18002 \markdownRendererHeadingOne
18003 {
18004 \markdownRendererHeadingOnePrototype
18005 }
18006 \seq_gput_right:Nn
18007 \g_@@_renderers_seq
18008 { headingOne }
18009 \prop_gput:Nnn
18010 \g_@@_renderer_arities_prop
18011 { headingOne }
18012 { 1 }
18013 \ExplSyntaxOff
18014 % \end{macrocode}
18015 %
18016 % \iffalse
18017 %</tex>
18018 %<*manual-tokens>
18019 % \fi
18020 %
18021 % \begin{markdown}
18022
18023 The \mdef{markdownRendererHeadingTwo} macro represents a second level
18024 heading. The macro receives a single argument that corresponds to the heading
18025 text.
18026
18027 % \end{markdown}
18028 %
18029 % \iffalse
18030 %</manual-tokens>
18031 %<*tex>
18032 % \fi
18033 %
18034 % \begin{macrocode}
18035 \ExplSyntaxOn
18036 \cs_gset_protected:Npn
18037 \markdownRendererHeadingTwo
18038 {
18039 \markdownRendererHeadingTwoPrototype
18040 }
18041 \seq_gput_right:Nn
18042 \g_@@_renderers_seq
18043 { headingTwo }
18044 \prop_gput:Nnn
18045 \g_@@_renderer_arities_prop
18046 { headingTwo }
18047 { 1 }
18048 \ExplSyntaxOff
18049 % \end{macrocode}
18050 %
18051 % \iffalse
18052 %</tex>
18053 %<*manual-tokens>
18054 % \fi
18055 %
18056 % \begin{markdown}
18057
18058 The \mdef{markdownRendererHeadingThree} macro represents a third level
18059 heading. The macro receives a single argument that corresponds to the heading
18060 text.
18061
18062 % \end{markdown}
18063 %
18064 % \iffalse
18065 %</manual-tokens>
18066 %<*tex>
18067 % \fi
18068 %
18069 % \begin{macrocode}
18070 \ExplSyntaxOn
18071 \cs_gset_protected:Npn
18072 \markdownRendererHeadingThree
18073 {
18074 \markdownRendererHeadingThreePrototype
18075 }
18076 \seq_gput_right:Nn
18077 \g_@@_renderers_seq
18078 { headingThree }
18079 \prop_gput:Nnn
18080 \g_@@_renderer_arities_prop
18081 { headingThree }
18082 { 1 }
18083 \ExplSyntaxOff
18084 % \end{macrocode}
18085 %
18086 % \iffalse
18087 %</tex>
18088 %<*manual-tokens>
18089 % \fi
18090 %
18091 % \begin{markdown}
18092
18093 The \mdef{markdownRendererHeadingFour} macro represents a fourth level
18094 heading. The macro receives a single argument that corresponds to the heading
18095 text.
18096
18097 % \end{markdown}
18098 %
18099 % \iffalse
18100 %</manual-tokens>
18101 %<*tex>
18102 % \fi
18103 %
18104 % \begin{macrocode}
18105 \ExplSyntaxOn
18106 \cs_gset_protected:Npn
18107 \markdownRendererHeadingFour
18108 {
18109 \markdownRendererHeadingFourPrototype
18110 }
18111 \seq_gput_right:Nn
18112 \g_@@_renderers_seq
18113 { headingFour }
18114 \prop_gput:Nnn
18115 \g_@@_renderer_arities_prop
18116 { headingFour }
18117 { 1 }
18118 \ExplSyntaxOff
18119 % \end{macrocode}
18120 %
18121 % \iffalse
18122 %</tex>
18123 %<*manual-tokens>
18124 % \fi
18125 %
18126 % \begin{markdown}
18127
18128 The \mdef{markdownRendererHeadingFive} macro represents a fifth level
18129 heading. The macro receives a single argument that corresponds to the heading
18130 text.
18131
18132 % \end{markdown}
18133 %
18134 % \iffalse
18135 %</manual-tokens>
18136 %<*tex>
18137 % \fi
18138 %
18139 % \begin{macrocode}
18140 \ExplSyntaxOn
18141 \cs_gset_protected:Npn
18142 \markdownRendererHeadingFive
18143 {
18144 \markdownRendererHeadingFivePrototype
18145 }
18146 \seq_gput_right:Nn
18147 \g_@@_renderers_seq
18148 { headingFive }
18149 \prop_gput:Nnn
18150 \g_@@_renderer_arities_prop
18151 { headingFive }
18152 { 1 }
18153 \ExplSyntaxOff
18154 % \end{macrocode}
18155 %
18156 % \iffalse
18157 %</tex>
18158 %<*manual-tokens>
18159 % \fi
18160 %
18161 % \begin{markdown}
18162
18163 The \mdef{markdownRendererHeadingSix} macro represents a sixth level
18164 heading. The macro receives a single argument that corresponds to the heading
18165 text.
18166
18167 % \end{markdown}
18168 %
18169 % \iffalse
18170
18171 ##### Plain \TeX{} Example {.unnumbered}
18172
18173 Using a text editor, create a text document named `document.tex` with the
18174 following content:
18175 ``` tex
18176 \input markdown
18177 \def\markdownRendererInterblockSeparator{}
18178 \def\markdownRendererHeadingOne{1}
18179 \def\markdownRendererHeadingTwo{2}
18180 \def\markdownRendererHeadingThree{3}
18181 \def\markdownRendererHeadingFour{4}
18182 \def\markdownRendererHeadingFive{5}
18183 \def\markdownRendererHeadingSix{6}
18184 \markdownBegin
18185 ######
18186 #####
18187 #####
18188 ###
18189 ######
18190 \markdownEnd
18191 \bye
18192 ```````
18193 Next, invoke LuaTeX from the terminal:
18194 ``` sh
18195 luatex document.tex
18196 ``````
18197 A PDF document named `document.pdf` should be produced and contain the
18198 following text:
18199
18200 > 65536
18201
18202 ##### \LaTeX{} Example {.unnumbered}
18203
18204 Using a text editor, create a text document named `document.tex` with the
18205 following content:
18206 ``` tex
18207 \documentclass{article}
18208 \usepackage{markdown}
18209 \markdownSetup{
18210 renderers = {
18211 interblockSeparator = {},
18212 headingOne = 1,
18213 headingTwo = 2,
18214 headingThree = 3,
18215 headingFour = 4,
18216 headingFive = 5,
18217 headingSix = 6,
18218 },
18219 }
18220 \begin{document}
18221 \begin{markdown}
18222 ######
18223 #####
18224 #####
18225 ###
18226 ######
18227 \end{markdown}
18228 \end{document}
18229 ```````
18230 Next, invoke LuaTeX from the terminal:
18231 ``` sh
18232 lualatex document.tex
18233 ``````
18234 A PDF document named `document.pdf` should be produced and contain the
18235 following text:
18236
18237 > 65536
18238
18239 ##### \Hologo{ConTeXt} Example {.unnumbered}
18240
18241 Using a text editor, create a text document named `document.tex` with the
18242 following content:
18243 ``` tex
18244 \usemodule[t][markdown]
18245 \def\markdownRendererInterblockSeparator{}
18246 \def\markdownRendererHeadingOne{1}
18247 \def\markdownRendererHeadingTwo{2}
18248 \def\markdownRendererHeadingThree{3}
18249 \def\markdownRendererHeadingFour{4}
18250 \def\markdownRendererHeadingFive{5}
18251 \def\markdownRendererHeadingSix{6}
18252 \starttext
18253 \startmarkdown
18254 ######
18255 #####
18256 #####
18257 ###
18258 ######
18259 \stopmarkdown
18260 \stoptext
18261 ```````
18262 Next, invoke LuaTeX from the terminal:
18263 ``` sh
18264 context --luatex document.tex
18265 ``````
18266 A PDF document named `document.pdf` should be produced and contain the
18267 following text:
18268
18269 > 65536
18270
18271 %</manual-tokens>
18272 %<*tex>
18273 % \fi
18274 %
18275 % \begin{macrocode}
18276 \ExplSyntaxOn
18277 \cs_gset_protected:Npn
18278 \markdownRendererHeadingSix
18279 {
18280 \markdownRendererHeadingSixPrototype
18281 }
18282 \seq_gput_right:Nn
18283 \g_@@_renderers_seq
18284 { headingSix }
18285 \prop_gput:Nnn
18286 \g_@@_renderer_arities_prop
18287 { headingSix }
18288 { 1 }
18289 \ExplSyntaxOff
18290 % \end{macrocode}
18291 %
18292 % \iffalse
18293 %</tex>
18294 %<*manual-tokens>
18295 % \fi
18296 %
18297 % \begin{markdown}
18298
18299 #### Image Renderer
18300 The \mdef{markdownRendererImage} macro represents an image. It receives
18301 four arguments: the label, the fully escaped URI that can be directly
18302 typeset, the raw URI that can be used outside typesetting, and the
18303 title of the link.
18304
18305 % \end{markdown}
18306 %
18307 % \iffalse
18308
18309 ##### \LaTeX{} Example {.unnumbered}
18310
18311 Using a text editor, create a text document named `document.tex` with the
18312 following content:
18313 ``` tex
18314 \documentclass{article}
18315 \usepackage{markdown}
18316 \begingroup
18317 \catcode`\@=11
18318 \catcode`\%=12
18319 \catcode`\^^A=14
18320 \global\def\markdownRendererImage#1#2#3#4{^^A
18321 \immediate\write18{^^A
18322 ```
18323 ``` sh
18324 if printf '%s' "#3" | grep -q ^http; then
18325 OUTPUT="$(printf '%s' "#3" | md5sum | cut -d' ' -f1).^^A
18326 $(printf '%s' "#3" | sed 's/.*[.]//')";
18327 if ! [ -e "$OUTPUT" ]; then
18328 wget -O "$OUTPUT" '#3' || rm "$OUTPUT";
18329 convert "$OUTPUT" png:"$OUTPUT";
18330 fi;
18331 printf '%s%%' "$OUTPUT" > \jobname.fetched;
18332 else
18333 printf '%s%%' "#3" > \jobname.fetched;
18334 fi^^A
18335 ```
18336 ``` tex
18337 }^^A
18338 {^^A
18339 \everyeof={\noexpand}^^A
18340 \edef\filename{\@@@@input"\jobname.fetched" }^^A
18341 \includegraphics[width=\textwidth]{\filename}^^A
18342 }^^A
18343 }
18344 \endgroup
18345 \begin{document}
18346 \begin{markdown}
18347 ![TUGboat](https://tug.org/tugboat/noword.jpg)
18348 \end{markdown}
18349 \end{document}
18350 ``````
18351 Next, invoke LuaTeX from the terminal:
18352 ``` sh
18353 lualatex --shell-escape document.tex
18354 ``````
18355 A PDF document named `document.pdf` should be produced and contain the
18356 following content. This assumes that you use a Unix-like operating system with
18357 Bourne or Bourne again shell as the default shell of the current user. It also
18358 assumes that the `md5sum`, `wget`, and `convert` binaries are installed and
18359 that the \TeX{} engine has shell access.
18360
18361 > ![TUGboat](https://tug.org/tugboat/noword.jpg "The Communications of the TeX Users Group")
18362
18363 %</manual-tokens>
18364 %<*tex>
18365 % \fi
18366 %
18367 % \begin{macrocode}
18368 \ExplSyntaxOn
18369 \cs_gset_protected:Npn
18370 \markdownRendererImage
18371 {
18372 \markdownRendererImagePrototype
18373 }
18374 \seq_gput_right:Nn
18375 \g_@@_renderers_seq
18376 { image }
18377 \prop_gput:Nnn
18378 \g_@@_renderer_arities_prop
18379 { image }
18380 { 4 }
18381 \ExplSyntaxOff
18382 % \end{macrocode}
18383 %
18384 % \iffalse
18385 %</tex>
18386 %<*manual-tokens>
18387 % \fi
18388 %
18389 % \begin{markdown}
18390
18391 #### Image Attribute Context Renderers
18392 The following macros are only produced, when the \Opt{linkAttributes} option
18393 is enabled.
18394
18395 The \mdef{markdownRendererImageAttributeContextBegin} and
18396 \mdef{markdownRendererImageAttributeContextEnd} macros represent the beginning
18397 and the end of a context in which the attributes of an image apply. The macros
18398 receive no arguments.
18399
18400 % \end{markdown}
18401 %
18402 % \iffalse
18403
18404 ##### \LaTeX{} Example {.unnumbered}
18405
18406 Using a text editor, create a text document named `document.tex` with the
18407 following content:
18408 ``` tex
18409 \documentclass{article}
18410 \usepackage[linkAttributes]{markdown}
18411 \markdownSetup{
18412 renderers = {
18413 imageAttributeContextBegin = {(},
18414 image = {#1},
18415 imageAttributeContextEnd = {)},
18416 },
18417 }
18418 \begin{document}
18419 \begin{markdown}
18420
18421 foo ![bar](#bar){key=value} baz
18422
18423 \end{markdown}
18424 \end{document}
18425 ```````
18426 Next, invoke LuaTeX from the terminal:
18427 ``` sh
18428 lualatex document.tex
18429 ``````
18430 A PDF document named `document.pdf` should be produced and contain the
18431 following text:
18432
18433 > foo (bar) baz
18434
18435 %</manual-tokens>
18436 %<*tex>
18437 % \fi
18438 %
18439 % \begin{macrocode}
18440 \ExplSyntaxOn
18441 \cs_gset_protected:Npn
18442 \markdownRendererImageAttributeContextBegin
18443 {
18444 \markdownRendererImageAttributeContextBeginPrototype
18445 }
18446 \seq_gput_right:Nn
18447 \g_@@_renderers_seq
18448 { imageAttributeContextBegin }
18449 \prop_gput:Nnn
18450 \g_@@_renderer_arities_prop
18451 { imageAttributeContextBegin }
18452 { 0 }
18453 \cs_gset_protected:Npn
18454 \markdownRendererImageAttributeContextEnd
18455 {
18456 \markdownRendererImageAttributeContextEndPrototype
18457 }
18458 \seq_gput_right:Nn
18459 \g_@@_renderers_seq
18460 { imageAttributeContextEnd }
18461 \prop_gput:Nnn
18462 \g_@@_renderer_arities_prop
18463 { imageAttributeContextEnd }
18464 { 0 }
18465 \ExplSyntaxOff
18466 % \end{macrocode}
18467 %
18468 % \iffalse
18469 %</tex>
18470 %<*manual-tokens>
18471 % \fi
18472 %
18473 % \begin{markdown}
18474
18475 #### Interblock Separator Renderers
18476 The \mdef{markdownRendererInterblockSeparator} macro represents an interblock
18477 separator between two markdown block elements. The macro receives no
18478 arguments.
18479
18480 % \end{markdown}
18481 %
18482 % \iffalse
18483
18484 ##### Plain \TeX{} Example {.unnumbered}
18485
18486 Using a text editor, create a text document named `document.tex` with the
18487 following content:
18488 ``` tex
18489 \input markdown
18490 \def\markdownRendererInterblockSeparator{%
18491 \par
18492 {\it(The end of a block)}%
18493 \par
18494 }
18495 \markdownBegin
18496 - Hello *world*!
18497
18498 _Foo_ bar!
18499 \markdownEnd
18500 \bye
18501 ```````
18502 Next, invoke LuaTeX from the terminal:
18503 ``` sh
18504 luatex document.tex
18505 ``````
18506 A PDF document named `document.pdf` should be produced and contain the
18507 following text:
18508
18509 > - Hello *world*!
18510 >
18511 > *(The end of a block)*
18512 >
18513 > _Foo_ bar!
18514
18515 ##### \LaTeX{} Example {.unnumbered}
18516
18517 Using a text editor, create a text document named `document.tex` with the
18518 following content:
18519 ``` tex
18520 \documentclass{article}
18521 \usepackage{markdown}
18522 \markdownSetup{
18523 renderers = {
18524 interblockSeparator = {%
18525 \par
18526 \emph{(The end of a block)}%
18527 \par
18528 },
18529 },
18530 }
18531 \begin{document}
18532 \begin{markdown}
18533 - Hello *world*!
18534
18535 _Foo_ bar!
18536 \end{markdown}
18537 \end{document}
18538 ```````
18539 Next, invoke LuaTeX from the terminal:
18540 ``` sh
18541 lualatex document.tex
18542 ``````
18543 A PDF document named `document.pdf` should be produced and contain the
18544 following text:
18545
18546 > - Hello *world*!
18547 >
18548 > *(The end of a block)*
18549 >
18550 > _Foo_ bar!
18551
18552 ##### \Hologo{ConTeXt} Example {.unnumbered}
18553
18554 Using a text editor, create a text document named `document.tex` with the
18555 following content:
18556 ``` tex
18557 \usemodule[t][markdown]
18558 \def\markdownRendererInterblockSeparator{%
18559 \par
18560 \emph{(The end of a block)}%
18561 \par
18562 }
18563 \starttext
18564 \startmarkdown
18565 - Hello *world*!
18566
18567 _Foo_ bar!
18568 \stopmarkdown
18569 \stoptext
18570 ```````
18571 Next, invoke LuaTeX from the terminal:
18572 ``` sh
18573 context --luatex document.tex
18574 ``````
18575 A PDF document named `document.pdf` should be produced and contain the
18576 following text:
18577
18578 > - Hello *world*!
18579 >
18580 > *(The end of a block)*
18581 >
18582 > _Foo_ bar!
18583
18584 %</manual-tokens>
18585 %<*tex>
18586 % \fi
18587 %
18588 % \begin{macrocode}
18589 \ExplSyntaxOn
18590 \cs_gset_protected:Npn
18591 \markdownRendererInterblockSeparator
18592 {
18593 \markdownRendererInterblockSeparatorPrototype
18594 }
18595 \seq_gput_right:Nn
18596 \g_@@_renderers_seq
18597 { interblockSeparator }
18598 \prop_gput:Nnn
18599 \g_@@_renderer_arities_prop
18600 { interblockSeparator }
18601 { 0 }
18602 \ExplSyntaxOff
18603 % \end{macrocode}
18604 %
18605 % \iffalse
18606 %</tex>
18607 %<*manual-tokens>
18608 % \fi
18609 %
18610 % \begin{markdown}
18611
18612 Users can use more than one blank line to delimit two block to indicate the
18613 end of a series of blocks that make up a logical paragraph. This produces a
18614 paragraph separator instead of an interblock separator. Between some blocks,
18615 such as markdown paragraphs, a paragraph separator is always produced.
18616
18617 The \mdef{markdownRendererParagraphSeparator} macro represents a paragraph
18618 separator. The macro receives no arguments.
18619
18620 % \end{markdown}
18621 %
18622 % \iffalse
18623
18624 ##### \LaTeX{} Example {.unnumbered}
18625
18626 Using a text editor, create a text document named `document.tex` with the
18627 following content:
18628 ``` tex
18629 \documentclass{article}
18630 \usepackage{markdown}
18631 \markdownSetup{
18632 renderers = {
18633 paragraphSeparator = {%
18634 \par
18635 \emph{(The end of a paragraph)}%
18636 \par
18637 },
18638 },
18639 }
18640 \begin{document}
18641 \begin{markdown}
18642 Hello *world*!
18643
18644 _Foo_ bar!
18645 \end{markdown}
18646 \end{document}
18647 ```````
18648 Next, invoke LuaTeX from the terminal:
18649 ``` sh
18650 lualatex document.tex
18651 ``````
18652 A PDF document named `document.pdf` should be produced and contain the
18653 following text:
18654
18655 > Hello *world*!
18656 >
18657 > *(The end of a paragraph)*
18658 >
18659 > _Foo_ bar!
18660
18661 %</manual-tokens>
18662 %<*tex>
18663 % \fi
18664 %
18665 % \begin{macrocode}
18666 \ExplSyntaxOn
18667 \cs_gset_protected:Npn
18668 \markdownRendererParagraphSeparator
18669 {
18670 \markdownRendererParagraphSeparatorPrototype
18671 }
18672 \seq_gput_right:Nn
18673 \g_@@_renderers_seq
18674 { paragraphSeparator }
18675 \prop_gput:Nnn
18676 \g_@@_renderer_arities_prop
18677 { paragraphSeparator }
18678 { 0 }
18679 \ExplSyntaxOff
18680 % \end{macrocode}
18681 %
18682 % \iffalse
18683 %</tex>
18684 %<*manual-tokens>
18685 % \fi
18686 %
18687 % \begin{markdown}
18688
18689 #### Line Block Renderers
18690 The following macros are only produced, when the \Opt{lineBlocks} option
18691 is enabled.
18692
18693 The \mdef{markdownRendererLineBlockBegin} and \mdef{markdownRendererLineBlockEnd} macros
18694 represent the beginning and the end of a line block. The macros receive no arguments.
18695
18696 % \end{markdown}
18697 %
18698 % \iffalse
18699
18700 ##### Plain \TeX{} Example {.unnumbered}
18701
18702 Using a text editor, create a text document named `document.tex` with the
18703 following content:
18704 ``` tex
18705 \input markdown
18706 \def\markdownOptionLineBlocks{true}
18707 \markdownBegin
18708 | I would spread the cloths under your feet:
18709 | But I, being poor, have only my dreams;
18710 | I have spread my dreams under your feet;
18711 | Tread softly because you tread on my dreams.
18712 \markdownEnd
18713 \bye
18714 ```````
18715 Next, invoke LuaTeX from the terminal:
18716 ``` sh
18717 luatex document.tex
18718 ``````
18719 A PDF document named `document.pdf` should be produced and contain the
18720 following text:
18721
18722 > | I would spread the cloths under your feet:
18723 > | But I, being poor, have only my dreams;
18724 > | I have spread my dreams under your feet;
18725 > | Tread softly because you tread on my dreams.
18726
18727 ##### \LaTeX{} Example {.unnumbered}
18728
18729 Using a text editor, create a text document named `document.tex` with the
18730 following content:
18731 ``` tex
18732 \documentclass{article}
18733 \usepackage[lineBlocks]{markdown}
18734 \begin{document}
18735 \begin{markdown}
18736 | I would spread the cloths under your feet:
18737 | But I, being poor, have only my dreams;
18738 | I have spread my dreams under your feet;
18739 | Tread softly because you tread on my dreams.
18740 \end{markdown}
18741 \end{document}
18742 ```````
18743 Next, invoke LuaTeX from the terminal:
18744 ``` sh
18745 lualatex document.tex
18746 ``````
18747 A PDF document named `document.pdf` should be produced and contain the
18748 following text:
18749
18750 > | I would spread the cloths under your feet:
18751 > | But I, being poor, have only my dreams;
18752 > | I have spread my dreams under your feet;
18753 > | Tread softly because you tread on my dreams.
18754
18755 ##### \Hologo{ConTeXt} Example {.unnumbered}
18756
18757 Using a text editor, create a text document named `document.tex` with the
18758 following content:
18759 ``` tex
18760 \usemodule[t][markdown]
18761 \setupmarkdown[lineBlocks = yes]
18762 \starttext
18763 \startmarkdown
18764 | I would spread the cloths under your feet:
18765 | But I, being poor, have only my dreams;
18766 | I have spread my dreams under your feet;
18767 | Tread softly because you tread on my dreams.
18768 \stopmarkdown
18769 \stoptext
18770 ```````
18771 Next, invoke LuaTeX from the terminal:
18772 ``` sh
18773 context --luatex document.tex
18774 ``````
18775 A PDF document named `document.pdf` should be produced and contain the
18776 following text:
18777
18778 > | I would spread the cloths under your feet:
18779 > | But I, being poor, have only my dreams;
18780 > | I have spread my dreams under your feet;
18781 > | Tread softly because you tread on my dreams.
18782
18783 %</manual-tokens>
18784 %<*tex>
18785 % \fi
18786 %
18787 % \begin{macrocode}
18788 \ExplSyntaxOn
18789 \cs_gset_protected:Npn
18790 \markdownRendererLineBlockBegin
18791 {
18792 \markdownRendererLineBlockBeginPrototype
18793 }
18794 \seq_gput_right:Nn
18795 \g_@@_renderers_seq
18796 { lineBlockBegin }
18797 \prop_gput:Nnn
18798 \g_@@_renderer_arities_prop
18799 { lineBlockBegin }
18800 { 0 }
18801 \cs_gset_protected:Npn
18802 \markdownRendererLineBlockEnd
18803 {
18804 \markdownRendererLineBlockEndPrototype
18805 }
18806 \seq_gput_right:Nn
18807 \g_@@_renderers_seq
18808 { lineBlockEnd }
18809 \prop_gput:Nnn
18810 \g_@@_renderer_arities_prop
18811 { lineBlockEnd }
18812 { 0 }
18813 \ExplSyntaxOff
18814 % \end{macrocode}
18815 %
18816 % \iffalse
18817 %</tex>
18818 %<*manual-tokens>
18819 % \fi
18820 %
18821 % \begin{markdown}
18822
18823 #### Line Break Renderers
18824
18825 The \mdef{markdownRendererSoftLineBreak} macro represents a soft line break.
18826 The macro receives no arguments.
18827
18828 % \end{markdown}
18829 %
18830 % \iffalse
18831
18832 ##### Plain \TeX{} Example {.unnumbered}
18833
18834 Using a text editor, create a text document named `document.tex` with the
18835 following content:
18836 ``` tex
18837 \input markdown
18838 \def\markdownRendererSoftLineBreak{%
18839 \par
18840 {\it(A soft line break)}%
18841 \par
18842 }
18843 \markdownInput{example.md}
18844 \bye
18845 ```````
18846 Using a text editor, create a text document named `example.md` with the
18847 following content:
18848
18849 ``` md
18850 Hello world!
18851 _Foo_ bar!
18852 ``````
18853 Next, invoke LuaTeX from the terminal:
18854 ``` sh
18855 luatex document.tex
18856 ``````
18857 A PDF document named `document.pdf` should be produced and contain the
18858 following text:
18859
18860 > Hello *world*!
18861 >
18862 > *(A soft line break)*
18863 >
18864 > _Foo_ bar!
18865
18866 ##### \LaTeX{} Example {.unnumbered}
18867
18868 Using a text editor, create a text document named `document.tex` with the
18869 following content:
18870 ``` tex
18871 \documentclass{article}
18872 \usepackage{markdown}
18873 \markdownSetup{
18874 renderers = {
18875 softLineBreak = {%
18876 \par
18877 \emph{(A soft line break)}%
18878 \par
18879 },
18880 },
18881 }
18882 \begin{document}
18883 \markdownInput{example.md}
18884 \end{document}
18885 ```````
18886 Using a text editor, create a text document named `example.md` with the
18887 following content:
18888
18889 ``` md
18890 Hello world!
18891 _Foo_ bar!
18892 ``````
18893 Next, invoke LuaTeX from the terminal:
18894 ``` sh
18895 lualatex document.tex
18896 ``````
18897 A PDF document named `document.pdf` should be produced and contain the
18898 following text:
18899
18900 > Hello *world*!
18901 >
18902 > *(A soft line break)*
18903 >
18904 > _Foo_ bar!
18905
18906 %</manual-tokens>
18907 %<*tex>
18908 % \fi
18909 % \begin{macrocode}
18910 \ExplSyntaxOn
18911 \cs_gset_protected:Npn
18912 \markdownRendererSoftLineBreak
18913 {
18914 \markdownRendererSoftLineBreakPrototype
18915 }
18916 \seq_gput_right:Nn
18917 \g_@@_renderers_seq
18918 { softLineBreak }
18919 \prop_gput:Nnn
18920 \g_@@_renderer_arities_prop
18921 { softLineBreak }
18922 { 0 }
18923 \ExplSyntaxOff
18924 % \end{macrocode}
18925 %
18926 % \iffalse
18927 %</tex>
18928 %<*manual-tokens>
18929 % \fi
18930 %
18931 % \begin{markdown}
18932
18933 The \mdef{markdownRendererHardLineBreak} macro represents a hard line break.
18934 The macro receives no arguments.
18935
18936 % \end{markdown}
18937 %
18938 % \iffalse
18939
18940 ##### Plain \TeX{} Example {.unnumbered}
18941
18942 Using a text editor, create a text document named `document.tex` with the
18943 following content:
18944 ``` tex
18945 \input markdown
18946 \def\markdownRendererHardLineBreak{%
18947 \par
18948 {\it(A hard line break)}%
18949 \par
18950 }
18951 \markdownInput{example.md}
18952 \bye
18953 ```````
18954 Using a text editor, create a text document named `example.md` with the
18955 following content. Note the two spaces at the end of the first line, which
18956 specify a hard line break. Due to the limitations of the \TeX{} input
18957 processor, hard line breaks would be ignored if we typed them directly into the
18958 `document.tex` document.
18959
18960 <pre><code>Hello world! <br/>_Foo_ bar!</code></pre>
18961
18962 Next, invoke LuaTeX from the terminal:
18963 ``` sh
18964 luatex document.tex
18965 ``````
18966 A PDF document named `document.pdf` should be produced and contain the
18967 following text:
18968
18969 > Hello *world*!
18970 >
18971 > *(A hard line break)*
18972 >
18973 > _Foo_ bar!
18974
18975 ##### \LaTeX{} Example {.unnumbered}
18976
18977 Using a text editor, create a text document named `document.tex` with the
18978 following content:
18979 ``` tex
18980 \documentclass{article}
18981 \usepackage{markdown}
18982 \markdownSetup{
18983 renderers = {
18984 hardLineBreak = {%
18985 \par
18986 \emph{(A hard line break)}%
18987 \par
18988 },
18989 },
18990 }
18991 \begin{document}
18992 \markdownInput{example.md}
18993 \end{document}
18994 ```````
18995 Using a text editor, create a text document named `example.md` with the
18996 following content. Note the two spaces at the end of the first line, which
18997 specify a hard line break. Due to the limitations of the \TeX{} input
18998 processor, hard line breaks would be ignored if we typed them directly into the
18999 `document.tex` document.
19000
19001 <pre><code>Hello world! <br/>_Foo_ bar!</code></pre>
19002
19003 Next, invoke LuaTeX from the terminal:
19004 ``` sh
19005 lualatex document.tex
19006 ``````
19007 A PDF document named `document.pdf` should be produced and contain the
19008 following text:
19009
19010 > Hello *world*!
19011 >
19012 > *(A hard line break)*
19013 >
19014 > _Foo_ bar!
19015
19016 %</manual-tokens>
19017 %<*tex>
19018 % \fi
19019 % \begin{macrocode}
19020 \ExplSyntaxOn
19021 \cs_gset_protected:Npn
19022 \markdownRendererHardLineBreak
19023 {
19024 \markdownRendererHardLineBreakPrototype
19025 }
19026 \seq_gput_right:Nn
19027 \g_@@_renderers_seq
19028 { hardLineBreak }
19029 \prop_gput:Nnn
19030 \g_@@_renderer_arities_prop
19031 { hardLineBreak }
19032 { 0 }
19033 \ExplSyntaxOff
19034 % \end{macrocode}
19035 %
19036 % \iffalse
19037 %</tex>
19038 %<*manual-tokens>
19039 % \fi
19040 %
19041 % \begin{markdown}
19042
19043 #### Link Renderer
19044 The \mdef{markdownRendererLink} macro represents a hyperlink. It receives
19045 four arguments: the label, the fully escaped URI that can be directly
19046 typeset, the raw URI that can be used outside typesetting, and the
19047 title of the link.
19048
19049 % \end{markdown}
19050 %
19051 % \iffalse
19052
19053 ##### Plain \TeX{} Example {.unnumbered}
19054
19055 Using a text editor, create a text document named `document.tex` with the
19056 following content:
19057 ``` tex
19058 \input markdown
19059 \def\markdownRendererLink#1#2#3#4{%
19060 #1 {\tt#2} titled {\it#4}%
19061 }
19062 \markdownBegin
19063 Please visit [the link][ctan].
19064
19065 [ctan]: https://ctan.org/
19066 (the Comprehensive TeX Archive Network)
19067 \markdownEnd
19068 \bye
19069 ```````
19070 Next, invoke LuaTeX from the terminal:
19071 ``` sh
19072 luatex document.tex
19073 ``````
19074 A PDF document named `document.pdf` should be produced and contain the
19075 following text:
19076
19077 > Please visit the link <https://ctan.org/> titled *the Comprehensive TeX
19078 > Archive Network*.
19079
19080 ##### \LaTeX{} Example {.unnumbered}
19081
19082 Using a text editor, create a text document named `document.tex` with the
19083 following content:
19084 ``` tex
19085 \documentclass{article}
19086 \usepackage{markdown}
19087 \markdownSetup{
19088 renderers = {
19089 link = {%
19090 #1 \texttt{#2} titled \emph{#4}%
19091 },
19092 },
19093 }
19094 \begin{document}
19095 \begin{markdown}
19096 Please visit [the link][ctan].
19097
19098 [ctan]: https://ctan.org/
19099 (the Comprehensive TeX Archive Network)
19100 \end{markdown}
19101 \end{document}
19102 ```````
19103 Next, invoke LuaTeX from the terminal:
19104 ``` sh
19105 lualatex document.tex
19106 ``````
19107 A PDF document named `document.pdf` should be produced and contain the
19108 following text:
19109
19110 > Please visit the link <https://ctan.org/> titled *the Comprehensive TeX
19111 > Archive Network*.
19112
19113 ##### \Hologo{ConTeXt} Example {.unnumbered}
19114
19115 Using a text editor, create a text document named `document.tex` with the
19116 following content:
19117 ``` tex
19118 \usemodule[t][markdown]
19119 \def\markdownRendererLink#1#2#3#4{%
19120 #1 {\tt#2} titled \emph{#4}%
19121 }
19122 \starttext
19123 \startmarkdown
19124 Please visit [the link][ctan].
19125
19126 [ctan]: https://ctan.org/
19127 (the Comprehensive TeX Archive Network)
19128 \stopmarkdown
19129 \stoptext
19130 ```````
19131 Next, invoke LuaTeX from the terminal:
19132 ``` sh
19133 context --luatex document.tex
19134 ``````
19135 A PDF document named `document.pdf` should be produced and contain the
19136 following text:
19137
19138 > Please visit the link <https://ctan.org/> titled *the Comprehensive TeX
19139 > Archive Network*.
19140
19141 %</manual-tokens>
19142 %<*tex>
19143 % \fi
19144 %
19145 % \begin{macrocode}
19146 \ExplSyntaxOn
19147 \cs_gset_protected:Npn
19148 \markdownRendererLink
19149 {
19150 \markdownRendererLinkPrototype
19151 }
19152 \seq_gput_right:Nn
19153 \g_@@_renderers_seq
19154 { link }
19155 \prop_gput:Nnn
19156 \g_@@_renderer_arities_prop
19157 { link }
19158 { 4 }
19159 \ExplSyntaxOff
19160 % \end{macrocode}
19161 %
19162 % \iffalse
19163 %</tex>
19164 %<*manual-tokens>
19165 % \fi
19166 %
19167 % \begin{markdown}
19168
19169 #### Link Attribute Context Renderers
19170 The following macros are only produced, when the \Opt{linkAttributes} option
19171 is enabled.
19172
19173 The \mdef{markdownRendererLinkAttributeContextBegin} and
19174 \mdef{markdownRendererLinkAttributeContextEnd} macros represent the beginning
19175 and the end of a context in which the attributes of a hyperlink apply.
19176 The macros receive no arguments.
19177
19178 % \end{markdown}
19179 %
19180 % \iffalse
19181
19182 ##### \LaTeX{} Example {.unnumbered}
19183
19184 Using a text editor, create a text document named `document.tex` with the
19185 following content:
19186 ``` tex
19187 \documentclass{article}
19188 \usepackage[linkAttributes]{markdown}
19189 \markdownSetup{
19190 renderers = {
19191 linkAttributeContextBegin = {(},
19192 link = {#1},
19193 linkAttributeContextEnd = {)},
19194 },
19195 }
19196 \begin{document}
19197 \begin{markdown}
19198
19199 foo [bar](#bar){key=value} baz
19200
19201 \end{markdown}
19202 \end{document}
19203 ```````
19204 Next, invoke LuaTeX from the terminal:
19205 ``` sh
19206 lualatex document.tex
19207 ``````
19208 A PDF document named `document.pdf` should be produced and contain the
19209 following text:
19210
19211 > foo (bar) baz
19212
19213 %</manual-tokens>
19214 %<*tex>
19215 % \fi
19216 %
19217 % \begin{macrocode}
19218 \ExplSyntaxOn
19219 \cs_gset_protected:Npn
19220 \markdownRendererLinkAttributeContextBegin
19221 {
19222 \markdownRendererLinkAttributeContextBeginPrototype
19223 }
19224 \seq_gput_right:Nn
19225 \g_@@_renderers_seq
19226 { linkAttributeContextBegin }
19227 \prop_gput:Nnn
19228 \g_@@_renderer_arities_prop
19229 { linkAttributeContextBegin }
19230 { 0 }
19231 \cs_gset_protected:Npn
19232 \markdownRendererLinkAttributeContextEnd
19233 {
19234 \markdownRendererLinkAttributeContextEndPrototype
19235 }
19236 \seq_gput_right:Nn
19237 \g_@@_renderers_seq
19238 { linkAttributeContextEnd }
19239 \prop_gput:Nnn
19240 \g_@@_renderer_arities_prop
19241 { linkAttributeContextEnd }
19242 { 0 }
19243 \ExplSyntaxOff
19244 % \end{macrocode}
19245 %
19246 % \iffalse
19247 %</tex>
19248 %<*manual-tokens>
19249 % \fi
19250 %
19251 % \begin{markdown}
19252
19253 #### Marked Text Renderer
19254 The following macro is only produced, when the \Opt{mark} option is enabled.
19255
19256 The \mdef{markdownRendererMark} macro represents a span of marked or
19257 highlighted text. The macro receives a single argument that corresponds to
19258 the marked text.
19259
19260 % \end{markdown}
19261 %
19262 % \iffalse
19263
19264 ##### \LaTeX{} Example {.unnumbered}
19265
19266 Using a text editor, create a text document named `document.tex` with the
19267 following content:
19268 ``` tex
19269 \documentclass{article}
19270 \usepackage[mark]{markdown}
19271 \usepackage{soul}
19272 \markdownSetup{
19273 renderers = {
19274 mark = {\hl{#1}},
19275 },
19276 }
19277 \begin{document}
19278 \begin{markdown}
19279
19280 This ==is highlighted text.==
19281
19282 \end{markdown}
19283 \end{document}
19284 ```````
19285 Next, invoke LuaTeX from the terminal:
19286 ``` sh
19287 lualatex document.tex
19288 ``````
19289 A PDF document named `document.pdf` should be produced and contain the
19290 following text:
19291
19292 > This <mark>is highlighted text.</mark>
19293
19294 %</manual-tokens>
19295 %<*tex>
19296 % \fi
19297 %
19298 % \begin{macrocode}
19299 \ExplSyntaxOn
19300 \cs_gset_protected:Npn
19301 \markdownRendererMark
19302 {
19303 \markdownRendererMarkPrototype
19304 }
19305 \seq_gput_right:Nn
19306 \g_@@_renderers_seq
19307 { mark }
19308 \prop_gput:Nnn
19309 \g_@@_renderer_arities_prop
19310 { mark }
19311 { 1 }
19312 \ExplSyntaxOff
19313 % \end{macrocode}
19314 %
19315 % \iffalse
19316 %</tex>
19317 %<*manual-tokens>
19318 % \fi
19319 %
19320 % \begin{markdown}
19321
19322 #### Markdown Document Renderers
19323 The \mdef{markdownRendererDocumentBegin} and \mdef{markdownRendererDocumentEnd}
19324 macros represent the beginning and the end of a *markdown* document. The macros
19325 receive no arguments.
19326
19327 A \TeX{} document may contain any number of markdown documents. Additionally,
19328 markdown documents may appear not only in a sequence, but several markdown
19329 documents may also be *nested*. Redefinitions of the macros should take this
19330 into account.
19331
19332 % \end{markdown}
19333 %
19334 % \iffalse
19335
19336 ##### \LaTeX{} Example {.unnumbered}
19337
19338 Using a text editor, create a text document named `nested.md` with the
19339 following content:
19340 ``` md
19341 This is a *nested* markdown document.
19342 ```
19343
19344 Using a text editor, create a text document named `document.tex` with the
19345 following content:
19346 ``` tex
19347 \documentclass{article}
19348 \usepackage[contentBlocks]{markdown}
19349 \markdownSetup{
19350 renderers = {
19351 contentBlock = {%
19352 \markdownInput{#3}%
19353 },
19354 documentBegin = {%
19355 \par
19356 \emph{(The beginning of a document)}
19357 \par
19358 \begingroup
19359 \markdownSetup{snippet=first-nesting-level}%
19360 },
19361 documentEnd = {%
19362 \endgroup
19363 \par
19364 \emph{(The end of a document)}
19365 \par
19366 },
19367 },
19368 }
19369 \markdownSetupSnippet{first-nesting-level}{
19370 renderers = {
19371 documentBegin = {
19372 \par
19373 \emph{(The beginning of a nested document)}
19374 \par
19375 \begingroup
19376 \markdownSetup{snippet=second-nesting-level-and-below}
19377 },
19378 },
19379 }
19380 \markdownSetupSnippet{second-nesting-level-and-below}{
19381 renderers = {
19382 documentBegin = {
19383 \par
19384 \emph{(The beginning of a nested document)}
19385 \par
19386 \begingroup
19387 },
19388 documentEnd = {
19389 \endgroup
19390 \par
19391 \emph{(The end of a nested document)}
19392 \par
19393 },
19394 },
19395 }
19396 \begin{document}
19397 \begin{markdown}
19398 Hello *world*!
19399
19400 /nested.md
19401
19402 _Foo_ bar!
19403 \end{markdown}
19404 \begin{markdown}
19405
19406 Bar baz!
19407
19408 \end{markdown}
19409 \end{document}
19410 ```````
19411 Next, invoke LuaTeX from the terminal:
19412 ``` sh
19413 lualatex document.tex
19414 ``````
19415 A PDF document named `document.pdf` should be produced and contain the
19416 following text:
19417
19418 > *(The beginning of a document)*
19419 >
19420 > Hello *world*!
19421 >
19422 > *(The beginning of a nested document)*
19423 >
19424 > This is a *nested* markdown document.
19425 >
19426 > *(The end of a nested document)*
19427 >
19428 > _Foo_ bar!
19429 >
19430 > *(The end of a document)*
19431 >
19432 > *(The beginning of a document)*
19433 >
19434 > Bar baz!
19435 >
19436 > *(The end of a document)*
19437
19438 %</manual-tokens>
19439 %<*tex>
19440 % \fi
19441 %
19442 % \begin{macrocode}
19443 \ExplSyntaxOn
19444 \cs_gset_protected:Npn
19445 \markdownRendererDocumentBegin
19446 {
19447 \markdownRendererDocumentBeginPrototype
19448 }
19449 \seq_gput_right:Nn
19450 \g_@@_renderers_seq
19451 { documentBegin }
19452 \prop_gput:Nnn
19453 \g_@@_renderer_arities_prop
19454 { documentBegin }
19455 { 0 }
19456 \cs_gset_protected:Npn
19457 \markdownRendererDocumentEnd
19458 {
19459 \markdownRendererDocumentEndPrototype
19460 }
19461 \seq_gput_right:Nn
19462 \g_@@_renderers_seq
19463 { documentEnd }
19464 \prop_gput:Nnn
19465 \g_@@_renderer_arities_prop
19466 { documentEnd }
19467 { 0 }
19468 \ExplSyntaxOff
19469 % \end{macrocode}
19470 %
19471 % \iffalse
19472 %</tex>
19473 %<*manual-tokens>
19474 % \fi
19475 %
19476 % \begin{markdown}
19477
19478 #### Non-Breaking Space Renderer
19479 The \mdef{markdownRendererNbsp} macro represents a non-breaking space.
19480
19481 % \end{markdown}
19482 %
19483 % \iffalse
19484
19485 ##### \LaTeX{} Example {.unnumbered}
19486
19487 Using a text editor, create a text document named `document.bib` with the
19488 following content:
19489 ``` bib
19490 @book{knuth:tex,
19491 author = "Knuth, Donald Ervin",
19492 title = "The \TeX book, volume A of Computers and typesetting",
19493 publisher = "Addison-Wesley",
19494 year = "1984"
19495 }
19496 ```````
19497 Using a text editor, create a text document named `document.tex` with the
19498 following content:
19499 ``` tex
19500 \documentclass{article}
19501 \usepackage[
19502 citations,
19503 citationNbsps,
19504 ]{markdown}
19505 \markdownSetup{
19506 renderers = {
19507 nbsp = {$\cdot$},
19508 },
19509 }
19510 \begin{document}
19511
19512 \begin{markdown}
19513 The TeXbook [@knuth:tex, p. 123 and 130] is good.
19514 \end{markdown}
19515
19516 \bibliographystyle{plain}
19517 \bibliography{document.bib}
19518
19519 \end{document}
19520 ```````
19521 Next, invoke LuaTeX and BibTeX from the terminal:
19522 ``` sh
19523 lualatex document.tex
19524 bibtex document.aux
19525 lualatex document.tex
19526 lualatex document.tex
19527 ``````
19528 A PDF document named `document.pdf` should be produced and contain the
19529 following text:
19530
19531 > The TeXbook [1, p.·123·and·130] is good.
19532 >
19533 > ### References
19534 > [1] Donald Ervin Knuth. _The TeXbook, volume A of Computers and typesetting._
19535 > Addison-Wesley, 1984.
19536
19537 %</manual-tokens>
19538 %<*tex>
19539 % \fi
19540 %
19541 % \begin{macrocode}
19542 \ExplSyntaxOn
19543 \cs_gset_protected:Npn
19544 \markdownRendererNbsp
19545 {
19546 \markdownRendererNbspPrototype
19547 }
19548 \seq_gput_right:Nn
19549 \g_@@_renderers_seq
19550 { nbsp }
19551 \prop_gput:Nnn
19552 \g_@@_renderer_arities_prop
19553 { nbsp }
19554 { 0 }
19555 \ExplSyntaxOff
19556 % \end{macrocode}
19557 %
19558 % \iffalse
19559 %</tex>
19560 %<*manual-tokens>
19561 % \fi
19562 %
19563 % \begin{markdown}
19564
19565 #### Note Renderer
19566 The \mdef{markdownRendererNote} macro represents a note. This macro
19567 will only be produced, when the \Opt{notes} option is enabled. The
19568 macro receives a single argument that corresponds to the note text.
19569
19570 % \end{markdown}
19571 %
19572 % \iffalse
19573
19574 ##### Plain \TeX{} Example {.unnumbered}
19575
19576 Using a text editor, create a text document named `document.tex` with the
19577 following content:
19578 ``` tex
19579 \input markdown
19580 \def\markdownOptionNotes{true}
19581 \def\markdownRendererNote#1{ (and \lowercase{#1})}
19582 \markdownBegin
19583 This is some text[^1] and this is some other text[^2].
19584
19585 [^1]: this is a note
19586
19587 [^2]: this is some other note
19588 \markdownEnd
19589 \bye
19590 ```````
19591 Next, invoke LuaTeX from the terminal:
19592 ``` sh
19593 luatex document.tex
19594 ``````
19595 A PDF document named `document.pdf` should be produced and contain the
19596 following text:
19597
19598 > This is some text (and this is a note) and this is some other
19599 > text (and this is some other note).
19600
19601 ##### \LaTeX{} Example {.unnumbered}
19602
19603 Using a text editor, create a text document named `document.tex` with the
19604 following content:
19605 ``` tex
19606 \documentclass{article}
19607 \usepackage[notes]{markdown}
19608 \markdownSetup{
19609 renderers = {
19610 note = { (and \MakeLowercase{#1})},
19611 },
19612 }
19613 \begin{document}
19614 \begin{markdown}
19615 This is some text[^1] and this is some other text[^2].
19616
19617 [^1]: this is a note
19618
19619 [^2]: this is some other note
19620 \end{markdown}
19621 \end{document}
19622 ```````
19623 Next, invoke LuaTeX from the terminal:
19624 ``` sh
19625 lualatex document.tex
19626 ``````
19627 A PDF document named `document.pdf` should be produced and contain the
19628 following text:
19629
19630 > This is some text (and this is a note) and this is some other
19631 > text (and this is some other note).
19632
19633 ##### \Hologo{ConTeXt} Example {.unnumbered}
19634
19635 Using a text editor, create a text document named `document.tex` with the
19636 following content:
19637 ``` tex
19638 \usemodule[t][markdown]
19639 \setupmarkdown[notes = yes]
19640 \def\markdownRendererNote#1{ (and \lowercase{#1})}
19641 \starttext
19642 \startmarkdown
19643 This is some text[^1] and this is some other text[^2].
19644
19645 [^1]: this is a note
19646
19647 [^2]: this is some other note
19648 \stopmarkdown
19649 \stoptext
19650 ```````
19651 Next, invoke LuaTeX from the terminal:
19652 ``` sh
19653 context --luatex document.tex
19654 ``````
19655 A PDF document named `document.pdf` should be produced and contain the
19656 following text:
19657
19658 > This is some text (and this is a note) and this is some other
19659 > text (and this is some other note).
19660
19661 %</manual-tokens>
19662 %<*tex>
19663 % \fi
19664 % \begin{macrocode}
19665 \def\markdownRendererNote{%
19666 \markdownRendererNotePrototype}%
19667 \ExplSyntaxOn
19668 \seq_gput_right:Nn
19669 \g_@@_renderers_seq
19670 { note }
19671 \prop_gput:Nnn
19672 \g_@@_renderer_arities_prop
19673 { note }
19674 { 1 }
19675 \ExplSyntaxOff
19676 % \end{macrocode}
19677 %
19678 % \iffalse
19679 %</tex>
19680 %<*manual-tokens>
19681 % \fi
19682 %
19683 % \begin{markdown}
19684
19685 #### Ordered List Renderers
19686 The \mdef{markdownRendererOlBegin} macro represents the beginning of an
19687 ordered list that contains an item with several paragraphs of text (the
19688 list is not tight). This macro will only be produced, when the \Opt{fancyLists}
19689 option is disabled. The macro receives no arguments.
19690
19691 % \end{markdown}
19692 %
19693 % \iffalse
19694 %</manual-tokens>
19695 %<*tex>
19696 % \fi
19697 %
19698 % \begin{macrocode}
19699 \ExplSyntaxOn
19700 \cs_gset_protected:Npn
19701 \markdownRendererOlBegin
19702 {
19703 \markdownRendererOlBeginPrototype
19704 }
19705 \seq_gput_right:Nn
19706 \g_@@_renderers_seq
19707 { olBegin }
19708 \prop_gput:Nnn
19709 \g_@@_renderer_arities_prop
19710 { olBegin }
19711 { 0 }
19712 \ExplSyntaxOff
19713 % \end{macrocode}
19714 %
19715 % \iffalse
19716 %</tex>
19717 %<*manual-tokens>
19718 % \fi
19719 %
19720 % \begin{markdown}
19721
19722 The \mdef{markdownRendererOlBeginTight} macro represents the beginning of an
19723 ordered list that contains no item with several paragraphs of text (the
19724 list is tight). This macro will only be produced, when the \Opt{tightLists}
19725 option is enabled and the \Opt{fancyLists} option is disabled. The macro
19726 receives no arguments.
19727
19728 % \end{markdown}
19729 %
19730 % \iffalse
19731 %</manual-tokens>
19732 %<*tex>
19733 % \fi
19734 %
19735 % \begin{macrocode}
19736 \ExplSyntaxOn
19737 \cs_gset_protected:Npn
19738 \markdownRendererOlBeginTight
19739 {
19740 \markdownRendererOlBeginTightPrototype
19741 }
19742 \seq_gput_right:Nn
19743 \g_@@_renderers_seq
19744 { olBeginTight }
19745 \prop_gput:Nnn
19746 \g_@@_renderer_arities_prop
19747 { olBeginTight }
19748 { 0 }
19749 \ExplSyntaxOff
19750 % \end{macrocode}
19751 %
19752 % \iffalse
19753 %</tex>
19754 %<*manual-tokens>
19755 % \fi
19756 %
19757 % \begin{markdown}
19758
19759 The \mdef{markdownRendererFancyOlBegin} macro represents the beginning of a
19760 fancy ordered list that contains an item with several paragraphs of text (the
19761 list is not tight). This macro will only be produced, when the \Opt{fancyLists}
19762 option is enabled. The macro receives two arguments: the style of the list item
19763 labels (`Decimal`, `LowerRoman`, `UpperRoman`, `LowerAlpha`, and `UpperAlpha`),
19764 and the style of delimiters between list item labels and texts (`Default`,
19765 `OneParen`, and `Period`).
19766
19767 % \end{markdown}
19768 %
19769 % \iffalse
19770 %</manual-tokens>
19771 %<*tex>
19772 % \fi
19773 %
19774 % \begin{macrocode}
19775 \ExplSyntaxOn
19776 \cs_gset_protected:Npn
19777 \markdownRendererFancyOlBegin
19778 {
19779 \markdownRendererFancyOlBeginPrototype
19780 }
19781 \seq_gput_right:Nn
19782 \g_@@_renderers_seq
19783 { fancyOlBegin }
19784 \prop_gput:Nnn
19785 \g_@@_renderer_arities_prop
19786 { fancyOlBegin }
19787 { 2 }
19788 \ExplSyntaxOff
19789 % \end{macrocode}
19790 %
19791 % \iffalse
19792 %</tex>
19793 %<*manual-tokens>
19794 % \fi
19795 %
19796 % \begin{markdown}
19797
19798 The \mdef{markdownRendererFancyOlBeginTight} macro represents the beginning of
19799 a fancy ordered list that contains no item with several paragraphs of text (the
19800 list is tight). This macro will only be produced, when the \Opt{fancyLists}
19801 and \Opt{tightLists} options are enabled. The macro receives two arguments: the
19802 style of the list item labels, and the style of delimiters between list
19803 item labels and texts. See the \mref{markdownRendererFancyOlBegin} macro for
19804 the valid style values.
19805
19806 % \end{markdown}
19807 %
19808 % \iffalse
19809 %</manual-tokens>
19810 %<*tex>
19811 % \fi
19812 %
19813 % \begin{macrocode}
19814 \ExplSyntaxOn
19815 \cs_gset_protected:Npn
19816 \markdownRendererFancyOlBeginTight
19817 {
19818 \markdownRendererFancyOlBeginTightPrototype
19819 }
19820 \seq_gput_right:Nn
19821 \g_@@_renderers_seq
19822 { fancyOlBeginTight }
19823 \prop_gput:Nnn
19824 \g_@@_renderer_arities_prop
19825 { fancyOlBeginTight }
19826 { 2 }
19827 \ExplSyntaxOff
19828 % \end{macrocode}
19829 %
19830 % \iffalse
19831 %</tex>
19832 %<*manual-tokens>
19833 % \fi
19834 %
19835 % \begin{markdown}
19836
19837 The \mdef{markdownRendererOlItem} macro represents an item in an ordered list.
19838 This macro will only be produced, when the \Opt{startNumber} option is
19839 disabled and the \Opt{fancyLists} option is disabled. The macro receives no
19840 arguments.
19841
19842 % \end{markdown}
19843 %
19844 % \iffalse
19845 %</manual-tokens>
19846 %<*tex>
19847 % \fi
19848 %
19849 % \begin{macrocode}
19850 \ExplSyntaxOn
19851 \cs_gset_protected:Npn
19852 \markdownRendererOlItem
19853 {
19854 \markdownRendererOlItemPrototype
19855 }
19856 \seq_gput_right:Nn
19857 \g_@@_renderers_seq
19858 { olItem }
19859 \prop_gput:Nnn
19860 \g_@@_renderer_arities_prop
19861 { olItem }
19862 { 0 }
19863 \ExplSyntaxOff
19864 % \end{macrocode}
19865 %
19866 % \iffalse
19867 %</tex>
19868 %<*manual-tokens>
19869 % \fi
19870 %
19871 % \begin{markdown}
19872
19873 The \mdef{markdownRendererOlItemEnd} macro represents the end of an item in
19874 an ordered list. This macro will only be produced, when the \Opt{fancyLists}
19875 option is disabled. The macro receives no arguments.
19876
19877 % \end{markdown}
19878 %
19879 % \iffalse
19880 %</manual-tokens>
19881 %<*tex>
19882 % \fi
19883 %
19884 % \begin{macrocode}
19885 \ExplSyntaxOn
19886 \cs_gset_protected:Npn
19887 \markdownRendererOlItemEnd
19888 {
19889 \markdownRendererOlItemEndPrototype
19890 }
19891 \seq_gput_right:Nn
19892 \g_@@_renderers_seq
19893 { olItemEnd }
19894 \prop_gput:Nnn
19895 \g_@@_renderer_arities_prop
19896 { olItemEnd }
19897 { 0 }
19898 \ExplSyntaxOff
19899 % \end{macrocode}
19900 %
19901 % \iffalse
19902 %</tex>
19903 %<*manual-tokens>
19904 % \fi
19905 %
19906 % \begin{markdown}
19907
19908 The \mdef{markdownRendererOlItemWithNumber} macro represents an item in an
19909 ordered list. This macro will only be produced, when the \Opt{startNumber}
19910 option is enabled and the \Opt{fancyLists} option is disabled. The macro
19911 receives a single numeric argument that corresponds to the item number.
19912
19913 % \end{markdown}
19914 %
19915 % \iffalse
19916 %</manual-tokens>
19917 %<*tex>
19918 % \fi
19919 %
19920 % \begin{macrocode}
19921 \ExplSyntaxOn
19922 \cs_gset_protected:Npn
19923 \markdownRendererOlItemWithNumber
19924 {
19925 \markdownRendererOlItemWithNumberPrototype
19926 }
19927 \seq_gput_right:Nn
19928 \g_@@_renderers_seq
19929 { olItemWithNumber }
19930 \prop_gput:Nnn
19931 \g_@@_renderer_arities_prop
19932 { olItemWithNumber }
19933 { 1 }
19934 \ExplSyntaxOff
19935 % \end{macrocode}
19936 %
19937 % \iffalse
19938 %</tex>
19939 %<*manual-tokens>
19940 % \fi
19941 %
19942 % \begin{markdown}
19943
19944 The \mdef{markdownRendererFancyOlItem} macro represents an item in a fancy
19945 ordered list. This macro will only be produced, when the \Opt{startNumber}
19946 option is disabled and the \Opt{fancyLists} option is enabled. The macro receives
19947 no arguments.
19948
19949 % \end{markdown}
19950 %
19951 % \iffalse
19952 %</manual-tokens>
19953 %<*tex>
19954 % \fi
19955 %
19956 % \begin{macrocode}
19957 \ExplSyntaxOn
19958 \cs_gset_protected:Npn
19959 \markdownRendererFancyOlItem
19960 {
19961 \markdownRendererFancyOlItemPrototype
19962 }
19963 \seq_gput_right:Nn
19964 \g_@@_renderers_seq
19965 { fancyOlItem }
19966 \prop_gput:Nnn
19967 \g_@@_renderer_arities_prop
19968 { fancyOlItem }
19969 { 0 }
19970 \ExplSyntaxOff
19971 % \end{macrocode}
19972 %
19973 % \iffalse
19974 %</tex>
19975 %<*manual-tokens>
19976 % \fi
19977 %
19978 % \begin{markdown}
19979
19980 The \mdef{markdownRendererFancyOlItemEnd} macro represents the end of an item in
19981 a fancy ordered list. This macro will only be produced, when the \Opt{fancyLists}
19982 option is enabled. The macro receives no arguments.
19983
19984 % \end{markdown}
19985 %
19986 % \iffalse
19987 %</manual-tokens>
19988 %<*tex>
19989 % \fi
19990 %
19991 % \begin{macrocode}
19992 \ExplSyntaxOn
19993 \cs_gset_protected:Npn
19994 \markdownRendererFancyOlItemEnd
19995 {
19996 \markdownRendererFancyOlItemEndPrototype
19997 }
19998 \seq_gput_right:Nn
19999 \g_@@_renderers_seq
20000 { fancyOlItemEnd }
20001 \prop_gput:Nnn
20002 \g_@@_renderer_arities_prop
20003 { fancyOlItemEnd }
20004 { 0 }
20005 \ExplSyntaxOff
20006 % \end{macrocode}
20007 %
20008 % \iffalse
20009 %</tex>
20010 %<*manual-tokens>
20011 % \fi
20012 %
20013 % \begin{markdown}
20014
20015 The \mdef{markdownRendererFancyOlItemWithNumber} macro represents an item in a
20016 fancy ordered list. This macro will only be produced, when the \Opt{startNumber}
20017 and \Opt{fancyLists} options are enabled. The macro receives a single numeric
20018 argument that corresponds to the item number.
20019
20020 % \end{markdown}
20021 %
20022 % \iffalse
20023 %</manual-tokens>
20024 %<*tex>
20025 % \fi
20026 %
20027 % \begin{macrocode}
20028 \ExplSyntaxOn
20029 \cs_gset_protected:Npn
20030 \markdownRendererFancyOlItemWithNumber
20031 {
20032 \markdownRendererFancyOlItemWithNumberPrototype
20033 }
20034 \seq_gput_right:Nn
20035 \g_@@_renderers_seq
20036 { fancyOlItemWithNumber }
20037 \prop_gput:Nnn
20038 \g_@@_renderer_arities_prop
20039 { fancyOlItemWithNumber }
20040 { 1 }
20041 \ExplSyntaxOff
20042 % \end{macrocode}
20043 %
20044 % \iffalse
20045 %</tex>
20046 %<*manual-tokens>
20047 % \fi
20048 %
20049 % \begin{markdown}
20050
20051 The \mdef{markdownRendererOlEnd} macro represents the end of an ordered list
20052 that contains an item with several paragraphs of text (the list is not
20053 tight). This macro will only be produced, when the \Opt{fancyLists} option is
20054 disabled. The macro receives no arguments.
20055
20056 % \end{markdown}
20057 %
20058 % \iffalse
20059 %</manual-tokens>
20060 %<*tex>
20061 % \fi
20062 %
20063 % \begin{macrocode}
20064 \ExplSyntaxOn
20065 \cs_gset_protected:Npn
20066 \markdownRendererOlEnd
20067 {
20068 \markdownRendererOlEndPrototype
20069 }
20070 \seq_gput_right:Nn
20071 \g_@@_renderers_seq
20072 { olEnd }
20073 \prop_gput:Nnn
20074 \g_@@_renderer_arities_prop
20075 { olEnd }
20076 { 0 }
20077 \ExplSyntaxOff
20078 % \end{macrocode}
20079 %
20080 % \iffalse
20081 %</tex>
20082 %<*manual-tokens>
20083 % \fi
20084 %
20085 % \begin{markdown}
20086
20087 The \mdef{markdownRendererOlEndTight} macro represents the end of an ordered
20088 list that contains no item with several paragraphs of text (the list is
20089 tight). This macro will only be produced, when the \Opt{tightLists} option is
20090 enabled and the \Opt{fancyLists} option is disabled. The macro receives no
20091 arguments.
20092
20093 % \end{markdown}
20094 %
20095 % \iffalse
20096 %</manual-tokens>
20097 %<*tex>
20098 % \fi
20099 %
20100 % \begin{macrocode}
20101 \ExplSyntaxOn
20102 \cs_gset_protected:Npn
20103 \markdownRendererOlEndTight
20104 {
20105 \markdownRendererOlEndTightPrototype
20106 }
20107 \seq_gput_right:Nn
20108 \g_@@_renderers_seq
20109 { olEndTight }
20110 \prop_gput:Nnn
20111 \g_@@_renderer_arities_prop
20112 { olEndTight }
20113 { 0 }
20114 \ExplSyntaxOff
20115 % \end{macrocode}
20116 %
20117 % \iffalse
20118 %</tex>
20119 %<*manual-tokens>
20120 % \fi
20121 %
20122 % \begin{markdown}
20123
20124 The \mdef{markdownRendererFancyOlEnd} macro represents the end of a fancy
20125 ordered list that contains an item with several paragraphs of text (the list
20126 is not tight). This macro will only be produced, when the \Opt{fancyLists}
20127 option is enabled. The macro receives no arguments.
20128
20129 % \end{markdown}
20130 %
20131 % \iffalse
20132 %</manual-tokens>
20133 %<*tex>
20134 % \fi
20135 %
20136 % \begin{macrocode}
20137 \ExplSyntaxOn
20138 \cs_gset_protected:Npn
20139 \markdownRendererFancyOlEnd
20140 {
20141 \markdownRendererFancyOlEndPrototype
20142 }
20143 \seq_gput_right:Nn
20144 \g_@@_renderers_seq
20145 { fancyOlEnd }
20146 \prop_gput:Nnn
20147 \g_@@_renderer_arities_prop
20148 { fancyOlEnd }
20149 { 0 }
20150 \ExplSyntaxOff
20151 % \end{macrocode}
20152 %
20153 % \iffalse
20154 %</tex>
20155 %<*manual-tokens>
20156 % \fi
20157 %
20158 % \begin{markdown}
20159
20160 The \mdef{markdownRendererFancyOlEndTight} macro represents the end of a
20161 fancy ordered list that contains no item with several paragraphs of text (the
20162 list is tight). This macro will only be produced, when the \Opt{fancyLists}
20163 and \Opt{tightLists} options are enabled. The macro receives no arguments.
20164
20165 % \end{markdown}
20166 %
20167 % \iffalse
20168
20169 ##### Plain \TeX{} Example {.unnumbered}
20170
20171 Using a text editor, create a text document named `document.tex` with the
20172 following content:
20173 ``` tex
20174 \input markdown
20175 \def\markdownOptionTightLists{true}
20176 \def\markdownOptionStartNumber{true}
20177
20178 \def\markdownRendererInterblockSeparator{}
20179 \def\markdownRendererOlBeginTight{ (}
20180 \def\markdownRendererOlItemWithNumber#1{%
20181 \ifnum #1=1\relax
20182 the first
20183 \else
20184 \ifnum #1=2\relax
20185 , the second
20186 \else
20187 , and the third
20188 \fi
20189 \fi
20190 }
20191 \def\markdownRendererOlItemEnd{}
20192 \def\markdownRendererOlEndTight{).}
20193
20194 \markdownBegin
20195 This is a tight list
20196
20197 1. item
20198 2. item
20199 3. item
20200 \markdownEnd
20201
20202 \def\markdownRendererInterblockSeparator{%
20203 :\par
20204 \def\markdownRendererInterblockSeparator{\par}%
20205 }
20206 \def\markdownRendererOlBegin{}
20207 \def\markdownRendererOlItemWithNumber#1{%
20208 #1.\kern 0.5em%
20209 This is the
20210 \ifnum #1=1\relax
20211 first
20212 \else
20213 \ifnum #1=2\relax
20214 second
20215 \else
20216 third
20217 \fi
20218 \fi
20219 }
20220 \def\markdownRendererOlItemEnd{.\par}
20221 \def\markdownRendererOlEnd{}
20222
20223 \markdownBegin
20224 This is a loose list
20225
20226 1. item
20227
20228 2. item
20229
20230 3. item
20231 \markdownEnd
20232
20233 \bye
20234 ```````
20235 Next, invoke LuaTeX from the terminal:
20236 ``` sh
20237 luatex document.tex
20238 ``````
20239 A PDF document named `document.pdf` should be produced and contain the
20240 following text:
20241
20242 > This is a tight list (the first item, the second item, and the third item).
20243 >
20244 > This is a loose list:
20245 >
20246 > 1. This is the first item.
20247 >
20248 > 2. This is the second item.
20249 >
20250 > 3. This is the third item.
20251
20252 ##### \LaTeX{} Example {.unnumbered}
20253
20254 Using a text editor, create a text document named `document.tex` with the
20255 following content:
20256 ``` tex
20257 \documentclass{article}
20258 \usepackage[tightLists, startNumber]{markdown}
20259 \begin{document}
20260
20261 \begin{markdown}[
20262 renderers = {
20263 interblockSeparator = {},
20264 olBeginTight = { (},
20265 olItemWithNumber = {%
20266 \ifnum #1=1\relax
20267 the first
20268 \else
20269 \ifnum #1=2\relax
20270 , the second
20271 \else
20272 , and the third
20273 \fi
20274 \fi
20275 },
20276 olItemEnd = {},
20277 olEndTight = {).},
20278 },
20279 ]
20280 This is a tight list
20281
20282 1. item
20283 2. item
20284 3. item
20285 \end{markdown}
20286
20287 \begin{markdown}[
20288 renderers = {
20289 interblockSeparator = {%
20290 :\par
20291 \def\markdownRendererInterblockSeparator{\par}%
20292 },
20293 olBeginTight = {\begin{enumerate}},
20294 olItemWithNumber = {%
20295 \item This is the
20296 \ifnum #1=1\relax
20297 first
20298 \else
20299 \ifnum #1=2\relax
20300 second
20301 \else
20302 third
20303 \fi
20304 \fi
20305 },
20306 olItemEnd = {.},
20307 olEnd = {\end{enumerate}},
20308 },
20309 ]
20310 This is a loose list
20311
20312 1. item
20313
20314 2. item
20315
20316 3. item
20317 \end{markdown}
20318
20319 \end{document}
20320 ```````
20321 Next, invoke LuaTeX from the terminal:
20322 ``` sh
20323 lualatex document.tex
20324 ``````
20325 A PDF document named `document.pdf` should be produced and contain the
20326 following text:
20327
20328 > This is a tight list (the first item, the second item, and the third item).
20329 >
20330 > This is a loose list:
20331 >
20332 > 1. This is the first item.
20333 >
20334 > 2. This is the second item.
20335 >
20336 > 3. This is the third item.
20337
20338 ##### \Hologo{ConTeXt} Example {.unnumbered}
20339
20340 Using a text editor, create a text document named `document.tex` with the
20341 following content:
20342 ``` tex
20343 \usemodule[t][markdown]
20344 \setupmarkdown
20345 [
20346 tightLists = yes,
20347 startNumber = yes,
20348 ]
20349 \starttext
20350
20351 \def\markdownRendererInterblockSeparator{}
20352 \def\markdownRendererOlBeginTight{ (}
20353 \def\markdownRendererOlItemWithNumber#1{%
20354 \ifnum #1=1\relax
20355 the first
20356 \else
20357 \ifnum #1=2\relax
20358 , the second
20359 \else
20360 , and the third
20361 \fi
20362 \fi
20363 }
20364 \def\markdownRendererOlItemEnd{}
20365 \def\markdownRendererOlEndTight{).}
20366
20367 \startmarkdown
20368 This is a tight list
20369
20370 1. item
20371 2. item
20372 3. item
20373 \stopmarkdown
20374
20375 \def\markdownRendererInterblockSeparator{%
20376 :\par
20377 \def\markdownRendererInterblockSeparator{\par}%
20378 }
20379 \def\markdownRendererOlBegin{\startitemize}
20380 \def\markdownRendererOlItemWithNumber#1{%
20381 \sym{#1.}
20382 This is the
20383 \ifnum #1=1\relax
20384 first
20385 \else
20386 \ifnum #1=2\relax
20387 second
20388 \else
20389 third
20390 \fi
20391 \fi
20392 }
20393 \def\markdownRendererOlItemEnd{.\par}
20394 \def\markdownRendererOlEnd{\stopitemize}
20395
20396 \startmarkdown
20397 This is a loose list
20398
20399 1. item
20400
20401 2. item
20402
20403 3. item
20404 \stopmarkdown
20405
20406 \stoptext
20407 ```````
20408 Next, invoke LuaTeX from the terminal:
20409 ``` sh
20410 context --luatex document.tex
20411 ``````
20412 A PDF document named `document.pdf` should be produced and contain the
20413 following text:
20414
20415 > This is a tight list (the first item, the second item, and the third item).
20416 >
20417 > This is a loose list:
20418 >
20419 > 1. This is the first item.
20420 >
20421 > 2. This is the second item.
20422 >
20423 > 3. This is the third item.
20424
20425 %</manual-tokens>
20426 %<*tex>
20427 % \fi
20428 %
20429 % \begin{macrocode}
20430 \ExplSyntaxOn
20431 \cs_gset_protected:Npn
20432 \markdownRendererFancyOlEndTight
20433 {
20434 \markdownRendererFancyOlEndTightPrototype
20435 }
20436 \seq_gput_right:Nn
20437 \g_@@_renderers_seq
20438 { fancyOlEndTight }
20439 \prop_gput:Nnn
20440 \g_@@_renderer_arities_prop
20441 { fancyOlEndTight }
20442 { 0 }
20443 \ExplSyntaxOff
20444 % \end{macrocode}
20445 %
20446 % \iffalse
20447 %</tex>
20448 %<*manual-tokens>
20449 % \fi
20450 %
20451 % \begin{markdown}
20452
20453 #### Raw Content Renderers
20454 The \mdef{markdownRendererInputRawInline} macro represents an inline raw span.
20455 The macro receives two arguments: the filename of a file containing the inline
20456 raw span contents and the raw attribute that designates the format of the
20457 inline raw span. This macro will only be produced, when the \Opt{rawAttribute}
20458 option is enabled.
20459
20460 % \end{markdown}
20461 %
20462 % \iffalse
20463 %</manual-tokens>
20464 %<*tex>
20465 % \fi
20466 %
20467 % \begin{macrocode}
20468 \ExplSyntaxOn
20469 \cs_gset_protected:Npn
20470 \markdownRendererInputRawInline
20471 {
20472 \markdownRendererInputRawInlinePrototype
20473 }
20474 \seq_gput_right:Nn
20475 \g_@@_renderers_seq
20476 { inputRawInline }
20477 \prop_gput:Nnn
20478 \g_@@_renderer_arities_prop
20479 { inputRawInline }
20480 { 2 }
20481 \ExplSyntaxOff
20482 % \end{macrocode}
20483 %
20484 % \iffalse
20485 %</tex>
20486 %<*manual-tokens>
20487 % \fi
20488 %
20489 % \begin{markdown}
20490
20491 The \mdef{markdownRendererInputRawBlock} macro represents a raw block. The
20492 macro receives two arguments: the filename of a file containing the raw block
20493 and the raw attribute that designates the format of the raw block. This macro
20494 will only be produced, when the \Opt{rawAttribute} and \Opt{fencedCode} options
20495 are enabled.
20496
20497 % \end{markdown}
20498 %
20499 % \iffalse
20500
20501 ##### \LaTeX{} Example {.unnumbered}
20502
20503 Using a text editor, create a text document named `document.tex` with the
20504 following content:
20505 ```` tex
20506 \documentclass{article}
20507 \usepackage[rawAttribute, fencedCode]{markdown}
20508 \usepackage{expl3}
20509 \ExplSyntaxOn
20510 \cs_new:Nn
20511 \display_raw_content:nn
20512 {
20513 % If the raw attribute is TeX, execute the content as a TeX document.
20514 \str_if_eq:nnTF
20515 { #2 }
20516 { tex }
20517 { \markdownEscape { #1 } }
20518 % Otherwise, ignore the content.
20519 { }
20520 }
20521 \markdownSetup{
20522 renderers = {
20523 rawInline = { \display_raw_content:nn { #1 } { #2 } },
20524 rawBlock = { \display_raw_content:nn { #1 } { #2 } }
20525 },
20526 }
20527 \ExplSyntaxOff
20528 \begin{document}
20529 \begin{markdown}
20530 `$H_2 O$`{=tex} is a liquid.
20531
20532 ``` {=html}
20533 <p>Here is some HTML content that will be ignored.</p>
20534 ```
20535 \end{markdown}
20536 \end{document}
20537 ````
20538 Next, invoke LuaTeX from the terminal:
20539 ``` sh
20540 lualatex document.tex
20541 ``````
20542 A PDF document named `document.pdf` should be produced and contain the
20543 following text:
20544
20545 > H~2~O is a liquid.
20546
20547 %</manual-tokens>
20548 %<*tex>
20549 % \fi
20550 %
20551 % \begin{macrocode}
20552 \ExplSyntaxOn
20553 \cs_gset_protected:Npn
20554 \markdownRendererInputRawBlock
20555 {
20556 \markdownRendererInputRawBlockPrototype
20557 }
20558 \seq_gput_right:Nn
20559 \g_@@_renderers_seq
20560 { inputRawBlock }
20561 \prop_gput:Nnn
20562 \g_@@_renderer_arities_prop
20563 { inputRawBlock }
20564 { 2 }
20565 \ExplSyntaxOff
20566 % \end{macrocode}
20567 %
20568 % \iffalse
20569 %</tex>
20570 %<*manual-tokens>
20571 % \fi
20572 %
20573 % \begin{markdown}
20574
20575 #### Section Renderers
20576 The \mdef{markdownRendererSectionBegin} and \mdef{markdownRendererSectionEnd}
20577 macros represent the beginning and the end of a section based on headings.
20578
20579 % \end{markdown}
20580 %
20581 % \iffalse
20582 %</manual-tokens>
20583 %<*tex>
20584 % \fi
20585 %
20586 % \begin{macrocode}
20587 \ExplSyntaxOn
20588 \cs_gset_protected:Npn
20589 \markdownRendererSectionBegin
20590 {
20591 \markdownRendererSectionBeginPrototype
20592 }
20593 \seq_gput_right:Nn
20594 \g_@@_renderers_seq
20595 { sectionBegin }
20596 \prop_gput:Nnn
20597 \g_@@_renderer_arities_prop
20598 { sectionBegin }
20599 { 0 }
20600 \cs_gset_protected:Npn
20601 \markdownRendererSectionEnd
20602 {
20603 \markdownRendererSectionEndPrototype
20604 }
20605 \seq_gput_right:Nn
20606 \g_@@_renderers_seq
20607 { sectionEnd }
20608 \prop_gput:Nnn
20609 \g_@@_renderer_arities_prop
20610 { sectionEnd }
20611 { 0 }
20612 \ExplSyntaxOff
20613 % \end{macrocode}
20614 %
20615 % \iffalse
20616 %</tex>
20617 %<*manual-tokens>
20618 % \fi
20619 %
20620 % \begin{markdown}
20621
20622 #### Replacement Character Renderers
20623 The \mdef{markdownRendererReplacementCharacter} macro represents the U+0000
20624 and U+FFFD Unicode characters. The macro receives no arguments.
20625
20626 % \end{markdown}
20627 %
20628 % \iffalse
20629 %</manual-tokens>
20630 %<*tex>
20631 % \fi
20632 %
20633 % \begin{macrocode}
20634 \ExplSyntaxOn
20635 \cs_gset_protected:Npn
20636 \markdownRendererReplacementCharacter
20637 {
20638 \markdownRendererReplacementCharacterPrototype
20639 }
20640 \seq_gput_right:Nn
20641 \g_@@_renderers_seq
20642 { replacementCharacter }
20643 \prop_gput:Nnn
20644 \g_@@_renderer_arities_prop
20645 { replacementCharacter }
20646 { 0 }
20647 \ExplSyntaxOff
20648 % \end{macrocode}
20649 %
20650 % \iffalse
20651 %</tex>
20652 %<*manual-tokens>
20653 % \fi
20654 %
20655 % \begin{markdown}
20656
20657 #### Special Character Renderers
20658 The following macros replace any special plain \TeX{} characters, including
20659 % \iffalse
20660 the active pipe character (`|`) of \Hologo{ConTeXt}, in the input text:
20661
20662 - \mdef{markdownRendererAmpersand} replaces the ampersand (`&`).
20663 - \mdef{markdownRendererBackslash} replaces the backslash (`\`).
20664 - \mdef{markdownRendererCircumflex} replaces the circumflex (`^`).
20665 - \mdef{markdownRendererDollarSign} replaces the dollar sign (`$`).
20666 - \mdef{markdownRendererHash} replaces the hash sign (`#`).
20667 - \mdef{markdownRendererLeftBrace} replaces the left brace (`{`).
20668 - \mdef{markdownRendererPercentSign} replaces the percent sign (`%`).
20669 - \mdef{markdownRendererPipe} replaces the pipe character (`|`).
20670 - \mdef{markdownRendererRightBrace} replaces the right brace (`}`).
20671 - \mdef{markdownRendererTilde} replaces the tilde (`~`).
20672 - \mdef{markdownRendererUnderscore} replaces the underscore (`_`).
20673
20674 % \fi
20675 % the active pipe character (`|`) of \Hologo{ConTeXt}, in the input text.
20676 % These macros will only be produced, when the \Opt{hybrid} option is
20677 % `false`.
20678
20679 % \end{markdown}
20680 %
20681 % \iffalse
20682
20683 ##### Plain \TeX{} Example {.unnumbered}
20684
20685 Using a text editor, create a text document named `document.tex` with the
20686 following content. We will make the tilde behave as if it were written in
20687 \TeX{}, where it represents a non-breaking space.
20688 ``` tex
20689 \input markdown
20690 \def\markdownRendererTilde{~}
20691 \markdownBegin
20692 Bartel~Leendert van~der~Waerden
20693 \markdownEnd
20694 \bye
20695 ```````
20696 Next, invoke LuaTeX from the terminal:
20697 ``` sh
20698 luatex document.tex
20699 ``````
20700 A PDF document named `document.pdf` should be produced and contain the
20701 following text, where the middot (`·`) denotes a non-breaking space:
20702
20703 > Bartel·Leendert van·der·Waerden
20704
20705 ##### \LaTeX{} Example {.unnumbered}
20706
20707 Using a text editor, create a text document named `document.tex` with the
20708 following content. We will make the tilde behave as if it were written in
20709 \TeX{}, where it represents a non-breaking space.
20710 ``` tex
20711 \documentclass{article}
20712 \usepackage{markdown}
20713 \markdownSetup{
20714 renderers = {
20715 tilde = ~,
20716 },
20717 }
20718 \begin{document}
20719 \begin{markdown}
20720 Bartel~Leendert van~der~Waerden
20721 \end{markdown}
20722 \end{document}
20723 ```````
20724 Next, invoke LuaTeX from the terminal:
20725 ``` sh
20726 lualatex document.tex
20727 ``````
20728 A PDF document named `document.pdf` should be produced and contain the
20729 following text, where the middot (`·`) denotes a non-breaking space:
20730
20731 > Bartel·Leendert van·der·Waerden
20732
20733 ##### \Hologo{ConTeXt} Example {.unnumbered}
20734
20735 Using a text editor, create a text document named `document.tex` with the
20736 following content. We will make the tilde behave as if it were written in
20737 \TeX{}, where it represents a non-breaking space.
20738 ``` tex
20739 \usemodule[t][markdown]
20740 \def\markdownRendererTilde{~}
20741 \starttext
20742 \startmarkdown
20743 Bartel~Leendert van~der~Waerden
20744 \stopmarkdown
20745 \stoptext
20746 ```````
20747 Next, invoke LuaTeX from the terminal:
20748 ``` sh
20749 context --luatex document.tex
20750 ``````
20751 A PDF document named `document.pdf` should be produced and contain the
20752 following text, where the middot (`·`) denotes a non-breaking space:
20753
20754 > Bartel·Leendert van·der·Waerden
20755
20756 %</manual-tokens>
20757 %<*tex>
20758 % \fi
20759 %
20760 % \begin{macrocode}
20761 \ExplSyntaxOn
20762 \cs_gset_protected:Npn
20763 \markdownRendererLeftBrace
20764 {
20765 \markdownRendererLeftBracePrototype
20766 }
20767 \seq_gput_right:Nn
20768 \g_@@_renderers_seq
20769 { leftBrace }
20770 \prop_gput:Nnn
20771 \g_@@_renderer_arities_prop
20772 { leftBrace }
20773 { 0 }
20774 \cs_gset_protected:Npn
20775 \markdownRendererRightBrace
20776 {
20777 \markdownRendererRightBracePrototype
20778 }
20779 \seq_gput_right:Nn
20780 \g_@@_renderers_seq
20781 { rightBrace }
20782 \prop_gput:Nnn
20783 \g_@@_renderer_arities_prop
20784 { rightBrace }
20785 { 0 }
20786 \cs_gset_protected:Npn
20787 \markdownRendererDollarSign
20788 {
20789 \markdownRendererDollarSignPrototype
20790 }
20791 \seq_gput_right:Nn
20792 \g_@@_renderers_seq
20793 { dollarSign }
20794 \prop_gput:Nnn
20795 \g_@@_renderer_arities_prop
20796 { dollarSign }
20797 { 0 }
20798 \cs_gset_protected:Npn
20799 \markdownRendererPercentSign
20800 {
20801 \markdownRendererPercentSignPrototype
20802 }
20803 \seq_gput_right:Nn
20804 \g_@@_renderers_seq
20805 { percentSign }
20806 \prop_gput:Nnn
20807 \g_@@_renderer_arities_prop
20808 { percentSign }
20809 { 0 }
20810 \cs_gset_protected:Npn
20811 \markdownRendererAmpersand
20812 {
20813 \markdownRendererAmpersandPrototype
20814 }
20815 \seq_gput_right:Nn
20816 \g_@@_renderers_seq
20817 { ampersand }
20818 \prop_gput:Nnn
20819 \g_@@_renderer_arities_prop
20820 { ampersand }
20821 { 0 }
20822 \cs_gset_protected:Npn
20823 \markdownRendererUnderscore
20824 {
20825 \markdownRendererUnderscorePrototype
20826 }
20827 \seq_gput_right:Nn
20828 \g_@@_renderers_seq
20829 { underscore }
20830 \prop_gput:Nnn
20831 \g_@@_renderer_arities_prop
20832 { underscore }
20833 { 0 }
20834 \cs_gset_protected:Npn
20835 \markdownRendererHash
20836 {
20837 \markdownRendererHashPrototype
20838 }
20839 \seq_gput_right:Nn
20840 \g_@@_renderers_seq
20841 { hash }
20842 \prop_gput:Nnn
20843 \g_@@_renderer_arities_prop
20844 { hash }
20845 { 0 }
20846 \cs_gset_protected:Npn
20847 \markdownRendererCircumflex
20848 {
20849 \markdownRendererCircumflexPrototype
20850 }
20851 \seq_gput_right:Nn
20852 \g_@@_renderers_seq
20853 { circumflex }
20854 \prop_gput:Nnn
20855 \g_@@_renderer_arities_prop
20856 { circumflex }
20857 { 0 }
20858 \cs_gset_protected:Npn
20859 \markdownRendererBackslash
20860 {
20861 \markdownRendererBackslashPrototype
20862 }
20863 \seq_gput_right:Nn
20864 \g_@@_renderers_seq
20865 { backslash }
20866 \prop_gput:Nnn
20867 \g_@@_renderer_arities_prop
20868 { backslash }
20869 { 0 }
20870 \cs_gset_protected:Npn
20871 \markdownRendererTilde
20872 {
20873 \markdownRendererTildePrototype
20874 }
20875 \seq_gput_right:Nn
20876 \g_@@_renderers_seq
20877 { tilde }
20878 \prop_gput:Nnn
20879 \g_@@_renderer_arities_prop
20880 { tilde }
20881 { 0 }
20882 \cs_gset_protected:Npn
20883 \markdownRendererPipe
20884 {
20885 \markdownRendererPipePrototype
20886 }
20887 \seq_gput_right:Nn
20888 \g_@@_renderers_seq
20889 { pipe }
20890 \prop_gput:Nnn
20891 \g_@@_renderer_arities_prop
20892 { pipe }
20893 { 0 }
20894 \ExplSyntaxOff
20895 % \end{macrocode}
20896 %
20897 % \iffalse
20898 %</tex>
20899 %<*manual-tokens>
20900 % \fi
20901 %
20902 % \begin{markdown}
20903
20904 #### Strike-Through Renderer
20905 The \mdef{markdownRendererStrikeThrough} macro represents a strike-through span of
20906 text. The macro receives a single argument that corresponds to the striked-out
20907 span of text. This macro will only be produced, when the \Opt{strikeThrough}
20908 option is enabled.
20909
20910 % \end{markdown}
20911 %
20912 % \iffalse
20913
20914 ##### Plain \TeX{} Example {.unnumbered}
20915
20916 Using a text editor, create a text document named `document.tex` with the
20917 following content:
20918 ``` tex
20919 \input markdown
20920 \def\markdownOptionStrikeThrough{true}
20921 \input soul.sty
20922 \def\markdownRendererStrikeThrough#1{\st{#1}}
20923 \markdownBegin
20924 This is ~~a lunar roving vehicle~~ strike-through text.
20925 \markdownEnd
20926 \bye
20927 ```````
20928 Next, invoke LuaTeX from the terminal:
20929 ``` sh
20930 luatex document.tex
20931 ``````
20932 A PDF document named `document.pdf` should be produced and contain the
20933 following text:
20934
20935 > This is ~~a lunar roving vehicle~~ strike-through text.
20936
20937 ##### \LaTeX{} Example {.unnumbered}
20938
20939 Using a text editor, create a text document named `document.tex` with the
20940 following content:
20941 ``` tex
20942 \documentclass{article}
20943 \usepackage[strikeThrough]{markdown}
20944 \usepackage{soul}
20945 \markdownSetup{
20946 renderers = {
20947 strikeThrough = {\st{#1}},
20948 },
20949 }
20950 \begin{document}
20951 \begin{markdown}
20952 This is ~~a lunar roving vehicle~~ strike-through text.
20953 \end{markdown}
20954 \end{document}
20955 ```````
20956 Next, invoke LuaTeX from the terminal:
20957 ``` sh
20958 lualatex document.tex
20959 ``````
20960 A PDF document named `document.pdf` should be produced and contain the
20961 following text:
20962
20963 > This is ~~a lunar roving vehicle~~ strike-through text.
20964
20965 ##### \Hologo{ConTeXt} Example {.unnumbered}
20966
20967 Using a text editor, create a text document named `document.tex` with the
20968 following content:
20969 ``` tex
20970 \usemodule[t][markdown]
20971 \setupmarkdown[strikeThrough = yes]
20972 \def\markdownRendererStrikeThrough#1{\overstrikes{#1}}
20973 \starttext
20974 \startmarkdown
20975 This is ~~a lunar roving vehicle~~ strike-through text.
20976 \stopmarkdown
20977 \stoptext
20978 ```````
20979 Next, invoke LuaTeX from the terminal:
20980 ``` sh
20981 context --luatex document.tex
20982 ``````
20983 A PDF document named `document.pdf` should be produced and contain the
20984 following text:
20985
20986 > This is ~~a lunar roving vehicle~~ strike-through text.
20987
20988 %</manual-tokens>
20989 %<*tex>
20990 % \fi
20991 %
20992 % \begin{macrocode}
20993 \ExplSyntaxOn
20994 \cs_gset_protected:Npn
20995 \markdownRendererStrikeThrough
20996 {
20997 \markdownRendererStrikeThroughPrototype
20998 }
20999 \seq_gput_right:Nn
21000 \g_@@_renderers_seq
21001 { strikeThrough }
21002 \prop_gput:Nnn
21003 \g_@@_renderer_arities_prop
21004 { strikeThrough }
21005 { 1 }
21006 \ExplSyntaxOff
21007 % \end{macrocode}
21008 %
21009 % \iffalse
21010 %</tex>
21011 %<*manual-tokens>
21012 % \fi
21013 %
21014 % \begin{markdown}
21015
21016 #### Subscript Renderer
21017 The \mdef{markdownRendererSubscript} macro represents a subscript span of
21018 text. The macro receives a single argument that corresponds to the subscript
21019 span of text. This macro will only be produced, when the \Opt{subscripts}
21020 option is enabled.
21021
21022 % \end{markdown}
21023 %
21024 % \iffalse
21025
21026 ##### Plain \TeX{} Example {.unnumbered}
21027
21028 Using a text editor, create a text document named `document.tex` with the
21029 following content:
21030 ``` tex
21031 \input markdown
21032 \def\markdownOptionSubscripts{true}
21033 \def\markdownRendererSubscript#1{ (#1 moles) and }
21034 \markdownBegin
21035 H~2~O is a liquid.
21036 \markdownEnd
21037 \bye
21038 ```````
21039 Next, invoke LuaTeX from the terminal:
21040 ``` sh
21041 luatex document.tex
21042 ``````
21043 A PDF document named `document.pdf` should be produced and contain the
21044 following text:
21045
21046 > H (2 moles) and O is a liquid.
21047
21048 ##### \LaTeX{} Example {.unnumbered}
21049
21050 Using a text editor, create a text document named `document.tex` with the
21051 following content:
21052 ``` tex
21053 \documentclass{article}
21054 \usepackage[subscripts]{markdown}
21055 \markdownSetup{
21056 renderers = {
21057 subscript = { (#1 moles) and },
21058 },
21059 }
21060 \begin{document}
21061 \begin{markdown}
21062 H~2~O is a liquid.
21063 \end{markdown}
21064 \end{document}
21065 ```````
21066 Next, invoke LuaTeX from the terminal:
21067 ``` sh
21068 lualatex document.tex
21069 ``````
21070 A PDF document named `document.pdf` should be produced and contain the
21071 following text:
21072
21073 > H (2 moles) and O is a liquid.
21074
21075 ##### \Hologo{ConTeXt} Example {.unnumbered}
21076
21077 Using a text editor, create a text document named `document.tex` with the
21078 following content:
21079 ``` tex
21080 \usemodule[t][markdown]
21081 \setupmarkdown[subscripts = yes]
21082 \def\markdownRendererSubscript#1{ (#1 moles) and }
21083 \starttext
21084 \startmarkdown
21085 H~2~O is a liquid.
21086 \stopmarkdown
21087 \stoptext
21088 ```````
21089 Next, invoke LuaTeX from the terminal:
21090 ``` sh
21091 context --luatex document.tex
21092 ``````
21093 A PDF document named `document.pdf` should be produced and contain the
21094 following text:
21095
21096 > H (2 moles) and O is a liquid.
21097
21098 %</manual-tokens>
21099 %<*tex>
21100 % \fi
21101 %
21102 % \begin{macrocode}
21103 \ExplSyntaxOn
21104 \cs_gset_protected:Npn
21105 \markdownRendererSubscript
21106 {
21107 \markdownRendererSubscriptPrototype
21108 }
21109 \seq_gput_right:Nn
21110 \g_@@_renderers_seq
21111 { subscript }
21112 \prop_gput:Nnn
21113 \g_@@_renderer_arities_prop
21114 { subscript }
21115 { 1 }
21116 % \end{macrocode}
21117 %
21118 % \iffalse
21119 %</tex>
21120 %<*manual-tokens>
21121 % \fi
21122 %
21123 % \begin{markdown}
21124
21125 #### Superscript Renderer
21126 The \mdef{markdownRendererSuperscript} macro represents a superscript span of
21127 text. The macro receives a single argument that corresponds to the superscript
21128 span of text. This macro will only be produced, when the \Opt{superscripts}
21129 option is enabled.
21130
21131 % \end{markdown}
21132 %
21133 % \iffalse
21134
21135 ##### Plain \TeX{} Example {.unnumbered}
21136
21137 Using a text editor, create a text document named `document.tex` with the
21138 following content:
21139 ``` tex
21140 \input markdown
21141 \def\markdownOptionSuperscripts{true}
21142 \def\markdownRendererSuperscript#1{ taken to the power of #1}
21143 \markdownBegin
21144 2^10^ is 1024.
21145 \markdownEnd
21146 \bye
21147 ```````
21148 Next, invoke LuaTeX from the terminal:
21149 ``` sh
21150 luatex document.tex
21151 ``````
21152 A PDF document named `document.pdf` should be produced and contain the
21153 following text:
21154
21155 > 2 taken to the power of 10 is 1024.
21156
21157 ##### \LaTeX{} Example {.unnumbered}
21158
21159 Using a text editor, create a text document named `document.tex` with the
21160 following content:
21161 ``` tex
21162 \documentclass{article}
21163 \usepackage[superscripts]{markdown}
21164 \markdownSetup{
21165 renderers = {
21166 superscript = { taken to the power of #1},
21167 },
21168 }
21169 \begin{document}
21170 \begin{markdown}
21171 2^10^ is 1024.
21172 \end{markdown}
21173 \end{document}
21174 ```````
21175 Next, invoke LuaTeX from the terminal:
21176 ``` sh
21177 lualatex document.tex
21178 ``````
21179 A PDF document named `document.pdf` should be produced and contain the
21180 following text:
21181
21182 > 2 taken to the power of 10 is 1024.
21183
21184 ##### \Hologo{ConTeXt} Example {.unnumbered}
21185
21186 Using a text editor, create a text document named `document.tex` with the
21187 following content:
21188 ``` tex
21189 \usemodule[t][markdown]
21190 \setupmarkdown[superscripts = yes]
21191 \def\markdownRendererSuperscript#1{ taken to the power of #1}
21192 \starttext
21193 \startmarkdown
21194 2^10^ is 1024.
21195 \stopmarkdown
21196 \stoptext
21197 ```````
21198 Next, invoke LuaTeX from the terminal:
21199 ``` sh
21200 context --luatex document.tex
21201 ``````
21202 A PDF document named `document.pdf` should be produced and contain the
21203 following text:
21204
21205 > 2 taken to the power of 10 is 1024.
21206
21207 %</manual-tokens>
21208 %<*tex>
21209 % \fi
21210 %
21211 % \begin{macrocode}
21212 \cs_gset_protected:Npn
21213 \markdownRendererSuperscript
21214 {
21215 \markdownRendererSuperscriptPrototype
21216 }
21217 \seq_gput_right:Nn
21218 \g_@@_renderers_seq
21219 { superscript }
21220 \prop_gput:Nnn
21221 \g_@@_renderer_arities_prop
21222 { superscript }
21223 { 1 }
21224 \ExplSyntaxOff
21225 % \end{macrocode}
21226 %
21227 % \iffalse
21228 %</tex>
21229 %<*manual-tokens>
21230 % \fi
21231 %
21232 % \begin{markdown}
21233
21234 #### Table Attribute Context Renderers
21235 The following macros are only produced, when the \Opt{tableCaptions} and
21236 \Opt{tableAttributes} options are enabled.
21237
21238 The \mdef{markdownRendererTableAttributeContextBegin} and
21239 \mdef{markdownRendererTableAttributeContextEnd} macros represent the
21240 beginning and the end of a context in which the attributes of a table
21241 apply. The macros receive no arguments.
21242
21243 % \end{markdown}
21244 %
21245 % \iffalse
21246
21247 ##### \LaTeX{} Example {.unnumbered}
21248
21249 Using a text editor, create a text document named `document.tex` with the
21250 following content:
21251 ``` tex
21252 \documentclass{article}
21253 \usepackage[
21254 pipeTables,
21255 tableCaptions,
21256 tableAttributes,
21257 relativeReferences,
21258 ]{markdown}
21259 \usepackage{expl3}
21260 \ExplSyntaxOn
21261 \markdownSetup{
21262 renderers = {
21263 tableAttributeContextBegin = {
21264 \group_begin:
21265 \markdownSetup{
21266 renderers = {
21267 attributeIdentifier = {
21268 \markdownSetup{
21269 renderers = {
21270 tableAttributeContextEnd = {
21271 \label{##1}
21272 \group_end:
21273 },
21274 },
21275 }
21276 },
21277 },
21278 }
21279 },
21280 tableAttributeContextEnd = {
21281 \group_end:
21282 },
21283 },
21284 }
21285 \ExplSyntaxOff
21286 \begin{document}
21287 \begin{markdown}
21288 See Table <#example-table>.
21289
21290 | Right | Left | Default | Center |
21291 |------:|:-----|---------|:------:|
21292 | 12 | 12 | 12 | 12 |
21293 | 123 | 123 | 123 | 123 |
21294 | 1 | 1 | 1 | 1 |
21295
21296 : Demonstration of pipe table syntax. {#example-table}
21297 \end{markdown}
21298 \end{document}
21299 ```````
21300 Next, invoke LuaTeX from the terminal:
21301 ``` sh
21302 lualatex document.tex
21303 ``````
21304 A PDF document named `document.pdf` should be produced and contain the
21305 following text:
21306
21307 > See Table 1.
21308 >
21309 > | Right | Left | Default | Center |
21310 > |------:|:-----|---------|:------:|
21311 > | 12 | 12 | 12 | 12 |
21312 > | 123 | 123 | 123 | 123 |
21313 > | 1 | 1 | 1 | 1 |
21314 >
21315 > : Table 1. Demonstration of pipe table syntax.
21316
21317 %</manual-tokens>
21318 %<*tex>
21319 % \fi
21320 %
21321 % \begin{macrocode}
21322 \ExplSyntaxOn
21323 \cs_gset_protected:Npn
21324 \markdownRendererTableAttributeContextBegin
21325 {
21326 \markdownRendererTableAttributeContextBeginPrototype
21327 }
21328 \seq_gput_right:Nn
21329 \g_@@_renderers_seq
21330 { tableAttributeContextBegin }
21331 \prop_gput:Nnn
21332 \g_@@_renderer_arities_prop
21333 { tableAttributeContextBegin }
21334 { 0 }
21335 \cs_gset_protected:Npn
21336 \markdownRendererTableAttributeContextEnd
21337 {
21338 \markdownRendererTableAttributeContextEndPrototype
21339 }
21340 \seq_gput_right:Nn
21341 \g_@@_renderers_seq
21342 { tableAttributeContextEnd }
21343 \prop_gput:Nnn
21344 \g_@@_renderer_arities_prop
21345 { tableAttributeContextEnd }
21346 { 0 }
21347 \ExplSyntaxOff
21348 % \end{macrocode}
21349 %
21350 % \iffalse
21351 %</tex>
21352 %<*manual-tokens>
21353 % \fi
21354 %
21355 % \begin{markdown}
21356
21357 #### Table Renderer {#table-renderer}
21358 The \mdef{markdownRendererTable} macro represents a table. This macro will only
21359 be produced, when the \Opt{pipeTables} option is enabled. The macro receives the
21360 parameters `{`\meta{caption}`}{`\meta{number of rows}`}{`\meta{number of columns}`}`
21361 followed by `{`\meta{alignments}`}` and then by `{`\meta{row}`}` repeated
21362 \meta{number of rows} times, where \meta{row} is `{`\meta{column}`}` repeated
21363 \meta{number of columns} times, \meta{alignments} is \meta{alignment} repeated
21364 \meta{number of columns} times, and \meta{alignment} is one of the following:
21365
21366 - `d` -- The corresponding column has an unspecified (default) alignment.
21367 - `l` -- The corresponding column is left-aligned.
21368 - `c` -- The corresponding column is centered.
21369 - `r` -- The corresponding column is right-aligned.
21370
21371 % \end{markdown}
21372 %
21373 % \iffalse
21374
21375 ##### \LaTeX{} Example {.unnumbered}
21376
21377 Using a text editor, create a text document named `document.tex` with the
21378 following content:
21379 ``` tex
21380 \documentclass{article}
21381 \usepackage[pipeTables, tableCaptions]{markdown}
21382 \newcount\rowCounter
21383 \newcount\columnCounter
21384 \makeatletter
21385 \def\processRow#1{%
21386 \columnCounter=1%
21387 \ifnum\rowCounter=0\relax
21388 As for the alignment,
21389 \else
21390 In row \the\rowCounter,
21391 \fi
21392 \processColumn#1
21393 \advance\rowCounter by 1\relax
21394 \ifnum\rowCounter>\rowTotal\relax
21395 \expandafter\@gobble
21396 \fi\processRow}%
21397 \def\processColumn#1{%
21398 column number \the\columnCounter{}
21399 \ifnum\rowCounter=0\relax
21400 \if#1d{}has default alignment\fi
21401 \if#1l{}is left-aligned\fi
21402 \if#1c{}is centered\fi
21403 \if#1r{}is right-aligned\fi
21404 \else
21405 says \emph{#1}%
21406 \fi
21407 \advance\columnCounter by 1\relax
21408 \ifnum\columnCounter<\columnTotal\relax, \fi
21409 \ifnum\columnCounter=\columnTotal\relax, and \fi
21410 \ifnum\columnCounter>\columnTotal\relax
21411 .\expandafter\@gobble
21412 \fi\processColumn}%
21413 \makeatother
21414 \markdownSetup{
21415 renderers = {
21416 table = {%
21417 This is a table with caption \emph{#1} that is #3 columns wide
21418 and #2 rows long.
21419 \rowCounter=0%
21420 \def\rowTotal{#2}%
21421 \def\columnTotal{#3}%
21422 \processRow
21423 },
21424 },
21425 }
21426 \begin{document}
21427 \begin{markdown}
21428 | Right | Left | Default | Center |
21429 |------:|:-----|---------|:------:|
21430 | 12 | 12 | 12 | 12 |
21431 | 123 | 123 | 123 | 123 |
21432 | 1 | 1 | 1 | 1 |
21433
21434 : Demonstration of pipe table syntax
21435 \end{markdown}
21436 \end{document}
21437 ```````
21438 Next, invoke LuaTeX from the terminal:
21439 ``` sh
21440 lualatex document.tex
21441 ``````
21442 A PDF document named `document.pdf` should be produced and contain the
21443 following text:
21444
21445 > This is a table with caption *Demonstration of pipe table syntax* that is 4
21446 > columns wide and 4 rows long. As for the alignment, column number 1 is
21447 > right-aligned, column number 2 is left-aligned, column number 3 has default
21448 > alignment, and column number 4 is centered. In row 1, column number 1 says
21449 > *Right*, column number 2 says *Left*, column number 3 says *Default*, and
21450 > column number 4 says *Center*. In row 2, column number 1 says *12*, column
21451 > number 2 says *12*, column number 3 says *12*, and column number 4 says *12*.
21452 > In row 3, column number 1 says *123*, column number 2 says *123*, column
21453 > number 3 says *123*, and column number 4 says *123*. In row 4, column number
21454 > 1 says *1*, column number 2 says *1*, column number 3 says *1*, and column
21455 > number 4 says *1*.
21456
21457
21458 %</manual-tokens>
21459 %<*tex>
21460 % \fi
21461 %
21462 % \begin{macrocode}
21463 \ExplSyntaxOn
21464 \cs_gset_protected:Npn
21465 \markdownRendererTable
21466 {
21467 \markdownRendererTablePrototype
21468 }
21469 \seq_gput_right:Nn
21470 \g_@@_renderers_seq
21471 { table }
21472 \prop_gput:Nnn
21473 \g_@@_renderer_arities_prop
21474 { table }
21475 { 3 }
21476 \ExplSyntaxOff
21477 % \end{macrocode}
21478 %
21479 % \iffalse
21480 %</tex>
21481 %<*manual-tokens>
21482 % \fi
21483 %
21484 % \begin{markdown}
21485
21486 #### \TeX{} Math Renderers
21487 The \mdef{markdownRendererInlineMath} and \mdef{markdownRendererDisplayMath} macros
21488 represent inline and display \TeX{} math.
21489 Both macros receive a single argument that corresponds to the \TeX{} math content.
21490 These macros will only be produced, when the \Opt{texMathDollars},
21491 \Opt{texMathSingleBackslash}, or \Opt{texMathDoubleBackslash} option are enabled.
21492
21493 % \end{markdown}
21494 %
21495 % \iffalse
21496
21497 ##### Plain \TeX{} Example {.unnumbered}
21498
21499 Using a text editor, create a text document named `document.tex` with the
21500 following content:
21501 ``` tex
21502 \input markdown
21503 \def\markdownOptionTexMathDollars{true}
21504 \def\markdownRendererInlineMath#1{$#1\dots$}
21505 \def\markdownRendererDisplayMath#1{$$#1$$}
21506 \markdownBegin
21507 $E=mc^2$
21508
21509 $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
21510 \markdownEnd
21511 \bye
21512 ```````
21513 Next, invoke LuaTeX from the terminal:
21514 ``` sh
21515 luatex document.tex
21516 ``````
21517 A PDF document named `document.pdf` should be produced and contain the
21518 following text:
21519
21520 > $E=mc^2\dots$
21521 >
21522 > $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
21523
21524 ##### \LaTeX{} Example {.unnumbered}
21525
21526 Using a text editor, create a text document named `document.tex` with the
21527 following content:
21528 ``` tex
21529 \documentclass{article}
21530 \usepackage[texMathDollars]{markdown}
21531 \usepackage{amsmath}
21532 \def\markdownRendererInlineMath#1{\begin{math}#1\dots\end{math}}
21533 \def\markdownRendererDisplayMath#1{\begin{equation}#1\end{equation}}
21534 \begin{document}
21535 \begin{markdown}
21536 $E=mc^2$
21537
21538 $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
21539 \end{markdown}
21540 \end{document}
21541 ```````
21542 Next, invoke LuaTeX from the terminal:
21543 ``` sh
21544 lualatex document.tex
21545 ``````
21546 A PDF document named `document.pdf` should be produced and contain the
21547 following text:
21548
21549 > $E=mc^2\dots$
21550 >
21551 > $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\quad(1)$$
21552
21553 ##### \Hologo{ConTeXt} Example {.unnumbered}
21554
21555 Using a text editor, create a text document named `document.tex` with the
21556 following content:
21557 ``` tex
21558 \usemodule[t][markdown]
21559 \setupmarkdown[texMathDollars = yes]
21560 \def\markdownRendererInlineMath#1{$#1\dots$}%
21561 \def\markdownRendererDisplayMath#1{\placeformula\startformula#1\stopformula}%
21562 \starttext
21563 \startmarkdown
21564 $E=mc^2$
21565
21566 $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx$$
21567 \stopmarkdown
21568 \stoptext
21569 ```````
21570 Next, invoke LuaTeX from the terminal:
21571 ``` sh
21572 context --luatex document.tex
21573 ``````
21574 A PDF document named `document.pdf` should be produced and contain the
21575 following text:
21576
21577 > $E=mc^2\dots$
21578 >
21579 > $$\hat{f} \left ( \xi \right )= \int_{-\infty}^{\infty} f\left ( x \right ) e^{-i2\pi \xi x} dx\quad(1)$$
21580
21581 %</manual-tokens>
21582 %<*tex>
21583 % \fi
21584 %
21585 % \begin{macrocode}
21586 \ExplSyntaxOn
21587 \cs_gset_protected:Npn
21588 \markdownRendererInlineMath
21589 {
21590 \markdownRendererInlineMathPrototype
21591 }
21592 \seq_gput_right:Nn
21593 \g_@@_renderers_seq
21594 { inlineMath }
21595 \prop_gput:Nnn
21596 \g_@@_renderer_arities_prop
21597 { inlineMath }
21598 { 1 }
21599 \cs_gset_protected:Npn
21600 \markdownRendererDisplayMath
21601 {
21602 \markdownRendererDisplayMathPrototype
21603 }
21604 \seq_gput_right:Nn
21605 \g_@@_renderers_seq
21606 { displayMath }
21607 \prop_gput:Nnn
21608 \g_@@_renderer_arities_prop
21609 { displayMath }
21610 { 1 }
21611 \ExplSyntaxOff
21612 % \end{macrocode}
21613 %
21614 % \iffalse
21615 %</tex>
21616 %<*manual-tokens>
21617 % \fi
21618 %
21619 % \begin{markdown}
21620
21621 #### Thematic Break Renderer
21622 The \mdef{markdownRendererThematicBreak} macro represents a thematic break.
21623 The macro receives no arguments.
21624
21625 % \end{markdown}
21626 %
21627 % \iffalse
21628
21629 ##### Plain \TeX{} Example {.unnumbered}
21630
21631 Using a text editor, create a text document named `document.tex` with the
21632 following content:
21633 ``` tex
21634 \input markdown
21635 \def\markdownRendererThematicBreak{\vfil\break}
21636 \markdownBegin
21637 This is the first page.
21638
21639 ***
21640
21641 This is the second page.
21642 \markdownEnd
21643 \bye
21644 ```````
21645 Next, invoke LuaTeX from the terminal:
21646 ``` sh
21647 luatex document.tex
21648 ``````
21649 A PDF document named `document.pdf` should be produced and contain the
21650 following text:
21651
21652 > This is the first page.
21653 >
21654 > ***
21655 >
21656 > This is the second page.
21657
21658 ##### \LaTeX{} Example {.unnumbered}
21659
21660 Using a text editor, create a text document named `document.tex` with the
21661 following content:
21662 ``` tex
21663 \documentclass{article}
21664 \usepackage{markdown}
21665 \markdownSetup{
21666 renderers = {
21667 thematicBreak = \newpage,
21668 },
21669 }
21670 \begin{document}
21671 \begin{markdown}
21672 This is the first page.
21673
21674 ***
21675
21676 This is the second page.
21677 \end{markdown}
21678 \end{document}
21679 ```````
21680 Next, invoke LuaTeX from the terminal:
21681 ``` sh
21682 lualatex document.tex
21683 ``````
21684 A PDF document named `document.pdf` should be produced and contain the
21685 following text:
21686
21687 > This is the first page.
21688 >
21689 > ***
21690 >
21691 > This is the second page.
21692
21693 ##### \Hologo{ConTeXt} Example {.unnumbered}
21694
21695 Using a text editor, create a text document named `document.tex` with the
21696 following content:
21697 ``` tex
21698 \usemodule[t][markdown]
21699 \def\markdownRendererThematicBreak{\page[yes]}
21700 \starttext
21701 \startmarkdown
21702 This is the first page.
21703
21704 ***
21705
21706 This is the second page.
21707 \stopmarkdown
21708 \stoptext
21709 ```````
21710 Next, invoke LuaTeX from the terminal:
21711 ``` sh
21712 context --luatex document.tex
21713 ``````
21714 A PDF document named `document.pdf` should be produced and contain the
21715 following text:
21716
21717 > This is the first page.
21718 >
21719 > ***
21720 >
21721 > This is the second page.
21722
21723 %</manual-tokens>
21724 %<*tex>
21725 % \fi
21726 % \begin{macrocode}
21727 \ExplSyntaxOn
21728 \cs_gset_protected:Npn
21729 \markdownRendererThematicBreak
21730 {
21731 \markdownRendererThematicBreakPrototype
21732 }
21733 \seq_gput_right:Nn
21734 \g_@@_renderers_seq
21735 { thematicBreak }
21736 \prop_gput:Nnn
21737 \g_@@_renderer_arities_prop
21738 { thematicBreak }
21739 { 0 }
21740 \ExplSyntaxOff
21741 % \end{macrocode}
21742 %
21743 % \iffalse
21744 %</tex>
21745 %<*manual-tokens>
21746 % \fi
21747 %
21748 % \begin{markdown}
21749
21750 #### Tickbox Renderers
21751 The macros named \mdef{markdownRendererTickedBox},
21752 \mdef{markdownRendererHalfTickedBox}, and \mdef{markdownRendererUntickedBox}
21753 represent ticked and unticked boxes, respectively. These macros will either be
21754 produced, when the \Opt{taskLists} option is enabled, or when the Ballot Box
21755 with X (☒, U+2612), Hourglass (⌛, U+231B) or Ballot Box (☐, U+2610) Unicode
21756 characters are encountered in the markdown input, respectively.
21757
21758 % \end{markdown}
21759 %
21760 % \iffalse
21761
21762 ##### \LaTeX{} Example {.unnumbered}
21763
21764 Using a text editor, create a text document named `document.tex` with the
21765 following content:
21766 ``` tex
21767 \documentclass{article}
21768 \usepackage[taskLists]{markdown}
21769 \markdownSetup{
21770 renderers = {
21771 untickedBox = No,
21772 tickedBox = Yes,
21773 },
21774 }
21775 \begin{document}
21776 \begin{markdown}
21777 - [ ] you can't.
21778 - [x] I can!
21779 \end{markdown}
21780 \end{document}
21781 ```````
21782 Next, invoke LuaTeX from the terminal:
21783 ``` sh
21784 lualatex document.tex
21785 ``````
21786 A PDF document named `document.pdf` should be produced and contain the
21787 following text:
21788
21789 > - No you can't.
21790 > - Yes I can!
21791
21792 ##### \Hologo{ConTeXt} Example {.unnumbered}
21793
21794 Using a text editor, create a text document named `document.tex` with the
21795 following content:
21796 ``` tex
21797 \usemodule[t][markdown]
21798 \setupmarkdown[taskLists = yes]
21799 \def\markdownRendererUntickedBox{No}
21800 \def\markdownRendererTickedBox{Yes}
21801 \starttext
21802 \startmarkdown
21803 - [ ] you can't.
21804 - [x] I can!
21805 \stopmarkdown
21806 \stoptext
21807 ````````
21808 Next, invoke LuaTeX from the terminal:
21809 ``` sh
21810 context --luatex document.tex
21811 `````
21812 A PDF document named `document.pdf` should be produced and contain the
21813 following text:
21814
21815 > - No you can't.
21816 > - Yes I can!
21817
21818 %</manual-tokens>
21819 %<*tex>
21820 % \fi
21821 %
21822 % \begin{macrocode}
21823 \ExplSyntaxOn
21824 \cs_gset_protected:Npn
21825 \markdownRendererTickedBox
21826 {
21827 \markdownRendererTickedBoxPrototype
21828 }
21829 \seq_gput_right:Nn
21830 \g_@@_renderers_seq
21831 { tickedBox }
21832 \prop_gput:Nnn
21833 \g_@@_renderer_arities_prop
21834 { tickedBox }
21835 { 0 }
21836 \cs_gset_protected:Npn
21837 \markdownRendererHalfTickedBox
21838 {
21839 \markdownRendererHalfTickedBoxPrototype
21840 }
21841 \seq_gput_right:Nn
21842 \g_@@_renderers_seq
21843 { halfTickedBox }
21844 \prop_gput:Nnn
21845 \g_@@_renderer_arities_prop
21846 { halfTickedBox }
21847 { 0 }
21848 \cs_gset_protected:Npn
21849 \markdownRendererUntickedBox
21850 {
21851 \markdownRendererUntickedBoxPrototype
21852 }
21853 \seq_gput_right:Nn
21854 \g_@@_renderers_seq
21855 { untickedBox }
21856 \prop_gput:Nnn
21857 \g_@@_renderer_arities_prop
21858 { untickedBox }
21859 { 0 }
21860 \ExplSyntaxOff
21861 % \end{macrocode}
21862 %
21863 % \iffalse
21864 %</tex>
21865 %<*manual-tokens>
21866 % \fi
21867 %
21868 % \begin{markdown}
21869
21870 #### Warning and Error Renderers
21871
21872 The \mdef{markdownRendererWarning} and \mdef{markdownRendererError} macros
21873 represent warnings and errors produced by the markdown parser. Both macros
21874 receive four parameters:
21875
21876 1. The fully escaped text of the warning or error that can be directly typeset
21877 2. The raw text of the warning or error that can be used outside typesetting
21878 for e.g. logging the warning or error.
21879 3. The fully escaped text with more details about the warning or error that
21880 can be directly typeset. Can be empty, unlike the first two parameters.
21881 4. The raw text with more details about the warning or error that can be used
21882 outside typesetting for e.g. logging the warning or error. Can be empty,
21883 unlike the first two parameters.
21884
21885 % \end{markdown}
21886 %
21887 % \iffalse
21888 %</manual-tokens>
21889 %<*tex>
21890 % \fi
21891 %
21892 % \begin{macrocode}
21893 \ExplSyntaxOn
21894 \cs_gset_protected:Npn
21895 \markdownRendererWarning
21896 {
21897 \markdownRendererWarningPrototype
21898 }
21899 \cs_gset_protected:Npn
21900 \markdownRendererError
21901 {
21902 \markdownRendererErrorPrototype
21903 }
21904 \seq_gput_right:Nn
21905 \g_@@_renderers_seq
21906 { warning }
21907 \prop_gput:Nnn
21908 \g_@@_renderer_arities_prop
21909 { warning }
21910 { 4 }
21911 \seq_gput_right:Nn
21912 \g_@@_renderers_seq
21913 { error }
21914 \prop_gput:Nnn
21915 \g_@@_renderer_arities_prop
21916 { error }
21917 { 4 }
21918 \ExplSyntaxOff
21919 % \end{macrocode}
21920 %
21921 % \iffalse
21922 %</tex>
21923 %<*manual-tokens>
21924 % \fi
21925 %
21926 % \begin{markdown}
21927
21928 #### YAML Metadata Renderers {#yamlmetadatarenderers}
21929
21930 The \mdef{markdownRendererJekyllDataBegin} macro represents the beginning of a
21931 YAML document. This macro will only be produced when the \Opt{jekyllData}
21932 option is enabled. The macro receives no arguments.
21933
21934 % \end{markdown}
21935 %
21936 % \iffalse
21937 %</manual-tokens>
21938 %<*tex>
21939 % \fi
21940 %
21941 % \begin{macrocode}
21942 \ExplSyntaxOn
21943 \cs_gset_protected:Npn
21944 \markdownRendererJekyllDataBegin
21945 {
21946 \markdownRendererJekyllDataBeginPrototype
21947 }
21948 \seq_gput_right:Nn
21949 \g_@@_renderers_seq
21950 { jekyllDataBegin }
21951 \prop_gput:Nnn
21952 \g_@@_renderer_arities_prop
21953 { jekyllDataBegin }
21954 { 0 }
21955 \ExplSyntaxOff
21956 % \end{macrocode}
21957 %
21958 % \iffalse
21959 %</tex>
21960 %<*manual-tokens>
21961 % \fi
21962 %
21963 % \begin{markdown}
21964
21965 The \mdef{markdownRendererJekyllDataEnd} macro represents the end of a
21966 YAML document. This macro will only be produced when the
21967 \Opt{jekyllData} option is enabled. The macro receives no arguments.
21968
21969 % \end{markdown}
21970 %
21971 % \iffalse
21972 %</manual-tokens>
21973 %<*tex>
21974 % \fi
21975 %
21976 % \begin{macrocode}
21977 \ExplSyntaxOn
21978 \cs_gset_protected:Npn
21979 \markdownRendererJekyllDataEnd
21980 {
21981 \markdownRendererJekyllDataEndPrototype
21982 }
21983 \seq_gput_right:Nn
21984 \g_@@_renderers_seq
21985 { jekyllDataEnd }
21986 \prop_gput:Nnn
21987 \g_@@_renderer_arities_prop
21988 { jekyllDataEnd }
21989 { 0 }
21990 \ExplSyntaxOff
21991 % \end{macrocode}
21992 %
21993 % \iffalse
21994 %</tex>
21995 %<*manual-tokens>
21996 % \fi
21997 %
21998 % \begin{markdown}
21999
22000 The \mdef{markdownRendererJekyllDataMappingBegin} macro represents the
22001 beginning of a mapping in a YAML document. This macro will only be
22002 produced when the \Opt{jekyllData} option is enabled. The macro receives two
22003 arguments: the scalar key in the parent structure, cast to a string following
22004 YAML serialization rules, and the number of items in the mapping.
22005
22006 % \end{markdown}
22007 %
22008 % \iffalse
22009 %</manual-tokens>
22010 %<*tex>
22011 % \fi
22012 %
22013 % \begin{macrocode}
22014 \ExplSyntaxOn
22015 \cs_gset_protected:Npn
22016 \markdownRendererJekyllDataMappingBegin
22017 {
22018 \markdownRendererJekyllDataMappingBeginPrototype
22019 }
22020 \seq_gput_right:Nn
22021 \g_@@_renderers_seq
22022 { jekyllDataMappingBegin }
22023 \prop_gput:Nnn
22024 \g_@@_renderer_arities_prop
22025 { jekyllDataMappingBegin }
22026 { 2 }
22027 \ExplSyntaxOff
22028 % \end{macrocode}
22029 %
22030 % \iffalse
22031 %</tex>
22032 %<*manual-tokens>
22033 % \fi
22034 %
22035 % \begin{markdown}
22036
22037 The \mdef{markdownRendererJekyllDataMappingEnd} macro represents the
22038 end of a mapping in a YAML document. This macro will only be produced
22039 when the \Opt{jekyllData} option is enabled. The macro receives no arguments.
22040
22041 % \end{markdown}
22042 %
22043 % \iffalse
22044 %</manual-tokens>
22045 %<*tex>
22046 % \fi
22047 %
22048 % \begin{macrocode}
22049 \ExplSyntaxOn
22050 \cs_gset_protected:Npn
22051 \markdownRendererJekyllDataMappingEnd
22052 {
22053 \markdownRendererJekyllDataMappingEndPrototype
22054 }
22055 \seq_gput_right:Nn
22056 \g_@@_renderers_seq
22057 { jekyllDataMappingEnd }
22058 \prop_gput:Nnn
22059 \g_@@_renderer_arities_prop
22060 { jekyllDataMappingEnd }
22061 { 0 }
22062 \ExplSyntaxOff
22063 % \end{macrocode}
22064 %
22065 % \iffalse
22066 %</tex>
22067 %<*manual-tokens>
22068 % \fi
22069 %
22070 % \begin{markdown}
22071
22072 The \mdef{markdownRendererJekyllDataSequenceBegin} macro represents the
22073 beginning of a sequence in a YAML document. This macro will only be
22074 produced when the \Opt{jekyllData} option is enabled. The macro receives two
22075 arguments: the scalar key in the parent structure, cast to a string following
22076 YAML serialization rules, and the number of items in the sequence.
22077
22078 % \end{markdown}
22079 %
22080 % \iffalse
22081 %</manual-tokens>
22082 %<*tex>
22083 % \fi
22084 %
22085 % \begin{macrocode}
22086 \ExplSyntaxOn
22087 \cs_gset_protected:Npn
22088 \markdownRendererJekyllDataSequenceBegin
22089 {
22090 \markdownRendererJekyllDataSequenceBeginPrototype
22091 }
22092 \seq_gput_right:Nn
22093 \g_@@_renderers_seq
22094 { jekyllDataSequenceBegin }
22095 \prop_gput:Nnn
22096 \g_@@_renderer_arities_prop
22097 { jekyllDataSequenceBegin }
22098 { 2 }
22099 \ExplSyntaxOff
22100 % \end{macrocode}
22101 %
22102 % \iffalse
22103 %</tex>
22104 %<*manual-tokens>
22105 % \fi
22106 %
22107 % \begin{markdown}
22108
22109 The \mdef{markdownRendererJekyllDataSequenceEnd} macro represents the
22110 end of a sequence in a YAML document. This macro will only be produced
22111 when the \Opt{jekyllData} option is enabled. The macro receives no arguments.
22112
22113 % \end{markdown}
22114 %
22115 % \iffalse
22116 %</manual-tokens>
22117 %<*tex>
22118 % \fi
22119 %
22120 % \begin{macrocode}
22121 \ExplSyntaxOn
22122 \cs_gset_protected:Npn
22123 \markdownRendererJekyllDataSequenceEnd
22124 {
22125 \markdownRendererJekyllDataSequenceEndPrototype
22126 }
22127 \seq_gput_right:Nn
22128 \g_@@_renderers_seq
22129 { jekyllDataSequenceEnd }
22130 \prop_gput:Nnn
22131 \g_@@_renderer_arities_prop
22132 { jekyllDataSequenceEnd }
22133 { 0 }
22134 \ExplSyntaxOff
22135 % \end{macrocode}
22136 %
22137 % \iffalse
22138 %</tex>
22139 %<*manual-tokens>
22140 % \fi
22141 %
22142 % \begin{markdown}
22143
22144 The \mdef{markdownRendererJekyllDataBoolean} macro represents a boolean scalar
22145 value in a YAML document. This macro will only be produced when the
22146 \Opt{jekyllData} option is enabled. The macro receives two arguments: the
22147 scalar key in the parent structure, and the scalar value, both cast to a string
22148 following YAML serialization rules.
22149
22150 % \end{markdown}
22151 %
22152 % \iffalse
22153 %</manual-tokens>
22154 %<*tex>
22155 % \fi
22156 %
22157 % \begin{macrocode}
22158 \ExplSyntaxOn
22159 \cs_gset_protected:Npn
22160 \markdownRendererJekyllDataBoolean
22161 {
22162 \markdownRendererJekyllDataBooleanPrototype
22163 }
22164 \seq_gput_right:Nn
22165 \g_@@_renderers_seq
22166 { jekyllDataBoolean }
22167 \prop_gput:Nnn
22168 \g_@@_renderer_arities_prop
22169 { jekyllDataBoolean }
22170 { 2 }
22171 \ExplSyntaxOff
22172 % \end{macrocode}
22173 %
22174 % \iffalse
22175 %</tex>
22176 %<*manual-tokens>
22177 % \fi
22178 %
22179 % \begin{markdown}
22180
22181 The \mdef{markdownRendererJekyllDataNumber} macro represents a numeric scalar
22182 value in a YAML document. This macro will only be produced when the
22183 \Opt{jekyllData} option is enabled. The macro receives two arguments: the
22184 scalar key in the parent structure, and the scalar value, both cast to a string
22185 following YAML serialization rules.
22186
22187 % \end{markdown}
22188 %
22189 % \iffalse
22190 %</manual-tokens>
22191 %<*tex>
22192 % \fi
22193 %
22194 % \begin{macrocode}
22195 \ExplSyntaxOn
22196 \cs_gset_protected:Npn
22197 \markdownRendererJekyllDataNumber
22198 {
22199 \markdownRendererJekyllDataNumberPrototype
22200 }
22201 \seq_gput_right:Nn
22202 \g_@@_renderers_seq
22203 { jekyllDataNumber }
22204 \prop_gput:Nnn
22205 \g_@@_renderer_arities_prop
22206 { jekyllDataNumber }
22207 { 2 }
22208 \ExplSyntaxOff
22209 % \end{macrocode}
22210 %
22211 % \iffalse
22212 %</tex>
22213 %<*manual-tokens>
22214 % \fi
22215 %
22216 % \begin{markdown}
22217
22218 The \mdef{markdownRendererJekyllDataTypographicString} and
22219 \mdef{markdownRendererJekyllDataProgrammaticString} macros represent string
22220 scalar values in a YAML document. This macro will only be produced when
22221 the \Opt{jekyllData} option is enabled. The macro receives two arguments: the
22222 scalar key in the parent structure, cast to a string following YAML
22223 serialization rules, and the scalar value.
22224
22225 For each string scalar value, both macros are produced. Whereas
22226 \mref{markdownRendererJekyllDataTypographicString} receives the scalar value
22227 after all markdown markup and special \TeX{} characters in the string have been
22228 replaced by \TeX{} macros, \mref{markdownRendererJekyllDataProgrammaticString}
22229 receives the raw scalar value. Therefore, whereas the
22230 \mref{markdownRendererJekyllDataTypographicString} macro is more appropriate
22231 for texts that are supposed to be typeset with \TeX{}, such as document titles,
22232 author names, or exam questions, the
22233 \mref{markdownRendererJekyllDataProgrammaticString} macro is more appropriate
22234 for identifiers and other programmatic text that won't be typeset by \TeX{}.
22235
22236 % \end{markdown}
22237 %
22238 % \iffalse
22239 %</manual-tokens>
22240 %<*tex>
22241 % \fi
22242 %
22243 % \begin{macrocode}
22244 \ExplSyntaxOn
22245 \cs_gset_protected:Npn
22246 \markdownRendererJekyllDataTypographicString
22247 {
22248 \markdownRendererJekyllDataTypographicStringPrototype
22249 }
22250 \cs_gset_protected:Npn
22251 \markdownRendererJekyllDataProgrammaticString
22252 {
22253 \markdownRendererJekyllDataProgrammaticStringPrototype
22254 }
22255 \seq_gput_right:Nn
22256 \g_@@_renderers_seq
22257 { jekyllDataTypographicString }
22258 \prop_gput:Nnn
22259 \g_@@_renderer_arities_prop
22260 { jekyllDataTypographicString }
22261 { 2 }
22262 \seq_gput_right:Nn
22263 \g_@@_renderers_seq
22264 { jekyllDataProgrammaticString }
22265 \prop_gput:Nnn
22266 \g_@@_renderer_arities_prop
22267 { jekyllDataProgrammaticString }
22268 { 2 }
22269 \ExplSyntaxOff
22270 % \end{macrocode}
22271 %
22272 % \iffalse
22273 %</tex>
22274 %<*manual-tokens>
22275 % \fi
22276 %
22277 % \begin{markdown}
22278
22279 Before Markdown 3.7.0, the \mref{markdownRendererJekyllDataTypographicString}
22280 macro was named \mdef{markdownRendererJekyllDataString} and the
22281 \mref{markdownRendererJekyllDataProgrammaticString} macro was not produced.
22282 The \mref{markdownRendererJekyllDataString} macro has been deprecated and will
22283 be removed in Markdown 4.0.0.
22284
22285 % \end{markdown}
22286 %
22287 % \iffalse
22288 %</manual-tokens>
22289 %<*tex>
22290 % \fi
22291 %
22292 % \begin{macrocode}
22293 \ExplSyntaxOn
22294 \cs_gset:Npn
22295 \markdownRendererJekyllDataTypographicString
22296 {
22297 \cs_if_exist:NTF
22298 \markdownRendererJekyllDataString
22299 {
22300 \@@_if_option:nTF
22301 { experimental }
22302 {
22303 \markdownError
22304 {
22305 The~jekyllDataString~renderer~has~been~deprecated,~
22306 to~be~removed~in~Markdown~4.0.0
22307 }
22308 }
22309 {
22310 \markdownWarning
22311 {
22312 The~jekyllDataString~renderer~has~been~deprecated,~
22313 to~be~removed~in~Markdown~4.0.0
22314 }
22315 \markdownRendererJekyllDataString
22316 }
22317 }
22318 {
22319 \cs_if_exist:NTF
22320 \markdownRendererJekyllDataStringPrototype
22321 {
22322 \@@_if_option:nTF
22323 { experimental }
22324 {
22325 \markdownError
22326 {
22327 The~jekyllDataString~renderer~prototype~
22328 has~been~deprecated,~
22329 to~be~removed~in~Markdown~4.0.0
22330 }
22331 }
22332 {
22333 \markdownWarning
22334 {
22335 The~jekyllDataString~renderer~prototype~
22336 has~been~deprecated,~
22337 to~be~removed~in~Markdown~4.0.0
22338 }
22339 \markdownRendererJekyllDataStringPrototype
22340 }
22341 }
22342 {
22343 \markdownRendererJekyllDataTypographicStringPrototype
22344 }
22345 }
22346 }
22347 \seq_gput_right:Nn
22348 \g_@@_renderers_seq
22349 { jekyllDataString }
22350 \prop_gput:Nnn
22351 \g_@@_renderer_arities_prop
22352 { jekyllDataString }
22353 { 2 }
22354 \ExplSyntaxOff
22355 % \end{macrocode}
22356 %
22357 % \iffalse
22358 %</tex>
22359 %<*manual-tokens>
22360 % \fi
22361 %
22362 % \begin{markdown}
22363
22364 The \mdef{markdownRendererJekyllDataEmpty} macro represents an empty scalar
22365 value in a YAML document. This macro will only be produced when the
22366 \Opt{jekyllData} option is enabled. The macro receives one argument: the
22367 scalar key in the parent structure, cast to a string following YAML
22368 serialization rules.
22369
22370 % See also Section <#sec:expl3yamlmetadata> for the description of the
22371 % high-level expl3 interface that you can also use to react to YAML
22372 % metadata.
22373 %
22374 % \end{markdown}
22375 %
22376 % \iffalse
22377 %</manual-tokens>
22378 %<*tex>
22379 % \fi
22380 %
22381 % \begin{macrocode}
22382 \ExplSyntaxOn
22383 \cs_gset_protected:Npn
22384 \markdownRendererJekyllDataEmpty
22385 {
22386 \markdownRendererJekyllDataEmptyPrototype
22387 }
22388 \seq_gput_right:Nn
22389 \g_@@_renderers_seq
22390 { jekyllDataEmpty }
22391 \prop_gput:Nnn
22392 \g_@@_renderer_arities_prop
22393 { jekyllDataEmpty }
22394 { 1 }
22395 \ExplSyntaxOff
22396 % \end{macrocode}
22397 %
22398 % \iffalse
22399 %</tex>
22400 %<*manual-tokens>
22401
22402 ##### Plain \TeX{} Example {.unnumbered}
22403
22404 Using a text editor, create a text document named `document.tex` with the
22405 following content:
22406 ``` tex
22407 \input markdown
22408 \def\markdownOptionJekyllData{true}
22409 \def\markdownRendererJekyllDataTypographicString#1#2{\gdef\name{#2}}
22410 \def\markdownRendererJekyllDataNumber#1#2{\gdef\age{#2}}
22411 \def\markdownRendererJekyllDataEnd{%
22412 \name{} is \age{} years old.}
22413 \markdownBegin
22414 ---
22415 name: Jane Doe
22416 age: 99
22417 ---
22418 \markdownEnd
22419 \bye
22420 ```````
22421 Next, invoke LuaTeX from the terminal:
22422 ``` sh
22423 luatex document.tex
22424 ``````
22425 A PDF document named `document.pdf` should be produced and contain the
22426 following text:
22427
22428 > Jane Doe is 99 years old.
22429
22430 ##### \LaTeX{} Example {.unnumbered}
22431
22432 Using a text editor, create a text document named `document.tex` with the
22433 following content:
22434 ``` tex
22435 \documentclass{article}
22436 \usepackage[jekyllData]{markdown}
22437 \markdownSetup{
22438 renderers = {
22439 jekyllDataTypographicString = {\gdef\name{#2}},
22440 jekyllDataNumber = {\gdef\age{#2}},
22441 jekyllDataEnd = {\name{} is \age{} years old.},
22442 }
22443 }
22444 \begin{document}
22445
22446 \begin{markdown}
22447 ---
22448 name: Jane Doe
22449 age: 99
22450 ---
22451 \end{markdown}
22452
22453 \end{document}
22454 ```````
22455 Next, invoke LuaTeX from the terminal:
22456 ``` sh
22457 lualatex document.tex
22458 ``````
22459 A PDF document named `document.pdf` should be produced and contain the
22460 following text:
22461
22462 > Jane Doe is 99 years old.
22463
22464 ##### \Hologo{ConTeXt} Example {.unnumbered}
22465
22466 Using a text editor, create a text document named `document.tex` with the
22467 following content:
22468 ``` tex
22469 \usemodule[t][markdown]
22470 \setupmarkdown[jekyllData = yes]
22471 \def\markdownRendererJekyllDataTypographicString#1#2{\gdef\name{#2}}
22472 \def\markdownRendererJekyllDataNumber#1#2{\gdef\age{#2}}
22473 \def\markdownRendererJekyllDataEnd{%
22474 \name{} is \age{} years old.}
22475 \starttext
22476
22477 \startmarkdown
22478 ---
22479 name: Jane Doe
22480 age: 99
22481 ---
22482 \stopmarkdown
22483
22484 \stoptext
22485 ```````
22486 Next, invoke LuaTeX from the terminal:
22487 ``` sh
22488 context --luatex document.tex
22489 ``````
22490 A PDF document named `document.pdf` should be produced and contain the
22491 following text:
22492
22493 > Jane Doe is 99 years old.
22494
22495 %</manual-tokens>
22496 %<*tex>
22497 % \fi
22498 % \begin{markdown}
22499 %
22500 %#### Generating Plain \TeX{} Token Renderer Macros and Key-Values {#plain-tex-renderers}
22501 %
22502 % We define the command \mdef{@@_define_renderers:} that defines plain \TeX{}
22503 % macros for token renderers. Furthermore, the `\markdownSetup` macro also accepts
22504 % the `renderers` and `unprotectedRenderers` keys. The value for these keys
22505 % must be a list of key--values, where the keys correspond to the markdown token
22506 % renderer macros and the values are new definitions of these token renderers.
22507 %
22508 % Whereas the key `renderers` defines protected functions, which are usually
22509 % preferable for typesetting, the key `unprotectedRenderers` defines unprotected
22510 % functions, which are easier to expand and may be preferable for programming.
22511 %
22512 % \end{markdown}
22513 % \begin{macrocode}
22514 \ExplSyntaxOn
22515 \cs_new:Nn \@@_define_renderers:
22516 {
22517 \seq_map_inline:Nn
22518 \g_@@_renderers_seq
22519 {
22520 \@@_define_renderer:n
22521 { ##1 }
22522 }
22523 }
22524 \cs_new:Nn \@@_define_renderer:n
22525 {
22526 \@@_renderer_tl_to_csname:nN
22527 { #1 }
22528 \l_tmpa_tl
22529 \prop_get:NnN
22530 \g_@@_renderer_arities_prop
22531 { #1 }
22532 \l_tmpb_tl
22533 \@@_define_renderer:ncV
22534 { #1 }
22535 { \l_tmpa_tl }
22536 \l_tmpb_tl
22537 }
22538 \cs_new:Nn \@@_renderer_tl_to_csname:nN
22539 {
22540 \tl_set:Nn
22541 \l_tmpa_tl
22542 { \str_uppercase:n { #1 } }
22543 \tl_set:Nx
22544 #2
22545 {
22546 markdownRenderer
22547 \tl_head:f { \l_tmpa_tl }
22548 \tl_tail:n { #1 }
22549 }
22550 }
22551 \tl_new:N
22552 \l_@@_renderer_definition_tl
22553 \bool_new:N
22554 \g_@@_prepending_renderer_bool
22555 \bool_new:N
22556 \g_@@_appending_renderer_bool
22557 \bool_new:N
22558 \g_@@_unprotected_renderer_bool
22559 \cs_new:Nn \@@_define_renderer:nNn
22560 {
22561 \keys_define:nn
22562 { markdown/options/renderers }
22563 {
22564 #1 .value_required:n = { true },
22565 #1 .code:n = {
22566 \tl_set:Nn
22567 \l_@@_renderer_definition_tl
22568 { ##1 }
22569 \regex_replace_all:nnN
22570 { \cP\#0 }
22571 { #1 }
22572 \l_@@_renderer_definition_tl
22573 \bool_if:nT
22574 {
22575 \g_@@_prepending_renderer_bool ||
22576 \g_@@_appending_renderer_bool
22577 }
22578 {
22579 \@@_tl_set_from_cs:NNn
22580 \l_tmpa_tl
22581 #2
22582 { #3 }
22583 \bool_if:NTF
22584 \g_@@_prepending_renderer_bool
22585 {
22586 \tl_put_right:NV
22587 \l_@@_renderer_definition_tl
22588 \l_tmpa_tl
22589 }
22590 {
22591 \tl_put_left:NV
22592 \l_@@_renderer_definition_tl
22593 \l_tmpa_tl
22594 }
22595 }
22596 \bool_if:NTF
22597 \g_@@_unprotected_renderer_bool
22598 {
22599 \tl_set:Nn
22600 \l_tmpa_tl
22601 { \cs_set:Npn }
22602 }
22603 {
22604 \tl_set:Nn
22605 \l_tmpa_tl
22606 { \cs_set_protected:Npn }
22607 }
22608 \exp_last_unbraced:NNV
22609 \cs_generate_from_arg_count:NNnV
22610 #2
22611 \l_tmpa_tl
22612 { #3 }
22613 \l_@@_renderer_definition_tl
22614 },
22615 }
22616 % \end{macrocode}
22617 % \begin{markdown}
22618 %
22619 % If the token renderer macro has been deprecated, we undefine it.
22620 %
22621 % The \mref{markdownRendererJekyllDataString} macro has been deprecated and
22622 % will be removed in Markdown 4.0.0.
22623 %
22624 % \end{markdown}
22625 % \begin{macrocode}
22626 \str_if_eq:nnT
22627 { #1 }
22628 { jekyllDataString }
22629 {
22630 \cs_undefine:N
22631 #2
22632 }
22633 }
22634 % \end{macrocode}
22635 % \begin{markdown}
22636 %
22637 % We define the function \mdef{@@_tl_set_from_cs:NNn}
22638 % [@starynovotny24]. The function takes a token list, a control sequence with
22639 % undelimited parameters, and the number of parameters the control sequence
22640 % accepts, and locally assigns the replacement text of the control sequence
22641 % to the token list.
22642 %
22643 % \end{markdown}
22644 % \begin{macrocode}
22645 \cs_new_protected:Nn
22646 \@@_tl_set_from_cs:NNn
22647 {
22648 \tl_set:Nn
22649 \l_tmpa_tl
22650 { #2 }
22651 \int_step_inline:nn
22652 { #3 }
22653 {
22654 \exp_args:NNc
22655 \tl_put_right:Nn
22656 \l_tmpa_tl
22657 { @@_tl_set_from_cs_parameter_ ##1 }
22658 }
22659 \exp_args:NNV
22660 \tl_set:No
22661 \l_tmpb_tl
22662 \l_tmpa_tl
22663 \regex_replace_all:nnN
22664 { \cP. }
22665 { \0\0 }
22666 \l_tmpb_tl
22667 \int_step_inline:nn
22668 { #3 }
22669 {
22670 \regex_replace_all:nnN
22671 { \c { @@_tl_set_from_cs_parameter_ ##1 } }
22672 { \cP\# ##1 }
22673 \l_tmpb_tl
22674 }
22675 \tl_set:NV
22676 #1
22677 \l_tmpb_tl
22678 }
22679 \cs_generate_variant:Nn
22680 \@@_define_renderer:nNn
22681 { ncV }
22682 \cs_generate_variant:Nn
22683 \cs_generate_from_arg_count:NNnn
22684 { NNnV }
22685 \cs_generate_variant:Nn
22686 \tl_put_left:Nn
22687 { Nv }
22688 \keys_define:nn
22689 { markdown/options }
22690 {
22691 renderers .value_required:n = { true },
22692 renderers .code:n = {
22693 \bool_gset_false:N
22694 \g_@@_unprotected_renderer_bool
22695 \keys_set:nn
22696 { markdown/options/renderers }
22697 { #1 }
22698 },
22699 unprotectedRenderers .value_required:n = { true },
22700 unprotectedRenderers .code:n = {
22701 \bool_gset_true:N
22702 \g_@@_unprotected_renderer_bool
22703 \keys_set:nn
22704 { markdown/options/renderers }
22705 { #1 }
22706 },
22707 }
22708 % \end{macrocode}
22709 % \begin{markdown}
22710 %
22711 % The following example code showcases a possible configuration of the
22712 % \mref{markdownRendererLink} and \mref{markdownRendererEmphasis} token
22713 % renderer macros.
22714 % ``` tex
22715 % \markdownSetup{
22716 % renderers = {
22717 % link = {#4}, \% Render links as the link title.
22718 % emphasis = {{\it #1}}, \% Render emphasized text using italics.
22719 % }
22720 % }
22721 % ```````
22722 %
22723 % \end{markdown}
22724 % \begin{macrocode}
22725 \tl_new:N
22726 \l_@@_renderer_glob_definition_tl
22727 \seq_new:N
22728 \l_@@_renderer_glob_results_seq
22729 \regex_const:Nn
22730 \c_@@_prepending_key_regex
22731 { \^$ }
22732 \regex_const:Nn
22733 \c_@@_appending_key_regex
22734 { [\$+]$ }
22735 \regex_const:Nn
22736 \c_@@_prepending_or_appending_key_regex
22737 { [\^\$+]$ }
22738 \keys_define:nn
22739 { markdown/options/renderers }
22740 {
22741 unknown .value_required:n = { true },
22742 unknown .code:n = {
22743 % \end{macrocode}
22744 % \begin{markdown}
22745 %
22746 % Besides defining renderers at once, we can also define them incrementally
22747 % using the prepending (`^=`) and appending (`$=` or `+=`) operators. This
22748 % can be especially useful in defining rules for processing different
22749 % HTML class names and identifiers:
22750 % ``` tex
22751 % \markdownSetup{
22752 % renderers = {
22753 % \% Start with empty renderers.
22754 % headerAttributeContextBegin = \begingroup,
22755 % headerAttributeContextEnd = \endgroup,
22756 % attributeClassName = {},
22757 % attributeIdentifier = {},
22758 % \% Define the processing of a single specific HTML class name.
22759 % headerAttributeContextBegin += {
22760 % \markdownSetup{
22761 % renderers = {
22762 % attributeClassName += {...},
22763 % },
22764 % }
22765 % },
22766 % \% Define the processing of a single specific HTML identifier.
22767 % headerAttributeContextBegin += {
22768 % \markdownSetup{
22769 % renderers = {
22770 % attributeIdentifier += {...},
22771 % },
22772 % }
22773 % },
22774 % },
22775 % }
22776 % ```````
22777 %
22778 % \end{markdown}
22779 % \begin{macrocode}
22780 % TODO: Use `\regex_if_match` in TeX Live 2025.
22781 \regex_match:NVT
22782 \c_@@_prepending_key_regex
22783 \l_keys_key_str
22784 {
22785 \bool_gset_true:N
22786 \g_@@_prepending_renderer_bool
22787 }
22788 % TODO: Use `\regex_if_match` in TeX Live 2025.
22789 \regex_match:NVT
22790 \c_@@_appending_key_regex
22791 \l_keys_key_str
22792 {
22793 \bool_gset_true:N
22794 \g_@@_appending_renderer_bool
22795 }
22796 % TODO: Use `\regex_if_match` in TeX Live 2025.
22797 \regex_match:NVTF
22798 \c_@@_prepending_or_appending_key_regex
22799 \l_keys_key_str
22800 {
22801 \tl_set:NV
22802 \l_tmpa_tl
22803 \l_keys_key_str
22804 \regex_replace_once:NnN
22805 \c_@@_prepending_or_appending_key_regex
22806 { }
22807 \l_tmpa_tl
22808 \tl_set:Nx
22809 \l_tmpb_tl
22810 { { \l_tmpa_tl } = }
22811 \tl_put_right:Nn
22812 \l_tmpb_tl
22813 { { #1 } }
22814 \keys_set:nV
22815 { markdown/options/renderers }
22816 \l_tmpb_tl
22817 \bool_gset_false:N
22818 \g_@@_prepending_renderer_bool
22819 \bool_gset_false:N
22820 \g_@@_appending_renderer_bool
22821 }
22822 % \end{macrocode}
22823 % \begin{markdown}
22824 %
22825 % In addition to exact token renderer names, we also support wildcards (`*`)
22826 % and enumerations (`|`) that match multiple token renderer names:
22827 % ``` tex
22828 % \markdownSetup{
22829 % renderers = {
22830 % heading* = {{\bf #1}}, \% Render headings using the bold face.
22831 % jekyllData(String|Number) = {\% \% Render YAML string and numbers
22832 % {\it #2}\% \% using italics.
22833 % },
22834 % }
22835 % }
22836 % ```````
22837 %
22838 % Wildcards and enumerations can be combined:
22839 % ``` tex
22840 % \markdownSetup{
22841 % renderers = {
22842 % *lItem(|End) = {"}, \% Quote ordered/bullet list items.
22843 % }
22844 % }
22845 % ```````
22846 %
22847 % To determine the current token renderer, you can use the
22848 % pseudo-parameter `#0`:
22849 % ``` tex
22850 % \markdownSetup{
22851 % renderers = {
22852 % heading* = {#0: #1}, \% Render headings as the renderer name
22853 % } \% followed by the heading text.
22854 % }
22855 % ```````
22856 %
22857 % \end{markdown}
22858 % \begin{macrocode}
22859 {
22860 \@@_glob_seq:VnN
22861 \l_keys_key_str
22862 { g_@@_renderers_seq }
22863 \l_@@_renderer_glob_results_seq
22864 \seq_if_empty:NTF
22865 \l_@@_renderer_glob_results_seq
22866 {
22867 \msg_error:nnV
22868 { markdown }
22869 { undefined-renderer }
22870 \l_keys_key_str
22871 }
22872 {
22873 \tl_set:Nn
22874 \l_@@_renderer_glob_definition_tl
22875 { \exp_not:n { #1 } }
22876 \seq_map_inline:Nn
22877 \l_@@_renderer_glob_results_seq
22878 {
22879 \tl_set:Nn
22880 \l_tmpa_tl
22881 { { ##1 } = }
22882 \tl_put_right:Nx
22883 \l_tmpa_tl
22884 { { \l_@@_renderer_glob_definition_tl } }
22885 \keys_set:nV
22886 { markdown/options/renderers }
22887 \l_tmpa_tl
22888 }
22889 }
22890 }
22891 },
22892 }
22893 \msg_new:nnn
22894 { markdown }
22895 { undefined-renderer }
22896 {
22897 Renderer~#1~is~undefined.
22898 }
22899 \cs_generate_variant:Nn
22900 \@@_glob_seq:nnN
22901 { VnN }
22902 \cs_generate_variant:Nn
22903 \cs_generate_from_arg_count:NNnn
22904 { cNVV }
22905 \cs_generate_variant:Nn
22906 \msg_error:nnn
22907 { nnV }
22908 \prg_generate_conditional_variant:Nnn
22909 % TODO: Use `\regex_if_match` in TeX Live 2025.
22910 \regex_match:Nn % noqa: w202
22911 { NV }
22912 { T, TF }
22913 \prop_new:N
22914 \g_@@_glob_cache_prop
22915 \tl_new:N
22916 \l_@@_current_glob_tl
22917 \cs_new:Nn
22918 \@@_glob_seq:nnN
22919 {
22920 \tl_set:Nn
22921 \l_@@_current_glob_tl
22922 { ^ #1 $ }
22923 \prop_get:NeNTF
22924 \g_@@_glob_cache_prop
22925 { #2 / \l_@@_current_glob_tl }
22926 \l_tmpa_clist
22927 {
22928 \seq_set_from_clist:NN
22929 #3
22930 \l_tmpa_clist
22931 }
22932 {
22933 \seq_clear:N
22934 #3
22935 \regex_replace_all:nnN
22936 { \* }
22937 { .* }
22938 \l_@@_current_glob_tl
22939 \regex_set:NV
22940 \l_tmpa_regex
22941 \l_@@_current_glob_tl
22942 \seq_map_inline:cn
22943 { #2 }
22944 {
22945 % TODO: Use `\regex_if_match` in TeX Live 2025.
22946 \regex_match:NnT % noqa: w202
22947 \l_tmpa_regex
22948 { ##1 }
22949 {
22950 \seq_put_right:Nn
22951 #3
22952 { ##1 }
22953 }
22954 }
22955 \clist_set_from_seq:NN
22956 \l_tmpa_clist
22957 #3
22958 \prop_gput:NeV
22959 \g_@@_glob_cache_prop
22960 { #2 / \l_@@_current_glob_tl }
22961 \l_tmpa_clist
22962 }
22963 }
22964 \cs_generate_variant:Nn
22965 \regex_set:Nn
22966 { NV }
22967 \cs_generate_variant:Nn
22968 \prop_gput:Nnn
22969 { NeV }
22970 % \end{macrocode}
22971 % \begin{markdown}
22972 %
22973 % If plain \TeX{} is the top layer, we use the \mref{@@_define_renderers:}
22974 % macro to define plain \TeX{} token renderer macros and key--values
22975 % immediately. Otherwise, we postpone the definition until the upper layers
22976 % have been loaded.
22977 %
22978 % \end{markdown}
22979 % \begin{macrocode}
22980 \str_if_eq:VVT
22981 \c_@@_top_layer_tl
22982 \c_@@_option_layer_plain_tex_tl
22983 {
22984 \@@_define_renderers:
22985 }
22986 \ExplSyntaxOff
22987 % \end{macrocode}
22988 % \iffalse
22989 %</tex>
22990 %<*manual-tokens>
22991 % \fi
22992 % \begin{markdown}
22993
22994 ### Token Renderer Prototypes {#texrendererprototypes}
22995
22996 % \end{markdown}
22997 % \iffalse
22998
22999 By default, token renderers point to package-defined \TeX{} macros, further
23000 referred to as *prototypes*, which provide useful default definitions.
23001
23002 ##### Plain \TeX{} Example {.unnumbered}
23003
23004 Using a text editor, create a text document named `document.tex` with the
23005 following content:
23006 ``` tex
23007 \input markdown
23008 \def\markdownRendererTildePrototype{%
23009 Packages can specify token renderer prototypes.%
23010 }
23011 \markdownBegin
23012 ~
23013 \markdownEnd
23014
23015 \def\markdownRendererTilde{%
23016 User-defined token renderers take precedence.%
23017 }
23018 \markdownBegin
23019 ~
23020 \markdownEnd
23021 \bye
23022 ```````
23023 Next, invoke LuaTeX from the terminal:
23024 ``` sh
23025 luatex document.tex
23026 ``````
23027 A PDF document named `document.pdf` should be produced and contain the
23028 following text:
23029
23030 > Packages can specify token renderer prototypes.
23031 >
23032 > User-defined token renderers take precedence.
23033
23034 ##### \LaTeX{} Example {.unnumbered}
23035
23036 Using a text editor, create a text document named `document.tex` with the
23037 following content:
23038 ``` tex
23039 \documentclass{article}
23040 \usepackage{markdown}
23041 \markdownSetup{
23042 rendererPrototypes = {
23043 tilde = {Packages can specify token renderer prototypes.},
23044 },
23045 }
23046 \begin{document}
23047 \begin{markdown}
23048 ~
23049 \end{markdown}
23050
23051 \begin{markdown}[
23052 renderers = {
23053 tilde = {User-defined token renderers take precedence.},
23054 },
23055 ]
23056 ~
23057 \end{markdown}
23058 \end{document}
23059 ```````
23060 Next, invoke LuaTeX from the terminal:
23061 ``` sh
23062 lualatex document.tex
23063 ``````
23064 A PDF document named `document.pdf` should be produced and contain the
23065 following text:
23066
23067 > Packages can specify token renderer prototypes.
23068 >
23069 > User-defined token renderers take precedence.
23070
23071 ##### \Hologo{ConTeXt} Example {.unnumbered}
23072
23073 Using a text editor, create a text document named `document.tex` with the
23074 following content:
23075 ``` tex
23076 \usemodule[t][markdown]
23077 \def\markdownRendererTildePrototype{%
23078 Packages can specify token renderer prototypes.%
23079 }
23080 \starttext
23081 \startmarkdown
23082 ~
23083 \stopmarkdown
23084
23085 \def\markdownRendererTilde{%
23086 User-defined token renderers take precedence.%
23087 }
23088 \startmarkdown
23089 ~
23090 \stopmarkdown
23091 \stoptext
23092 ```````
23093 Next, invoke LuaTeX from the terminal:
23094 ``` sh
23095 context --luatex document.tex
23096 ``````
23097 A PDF document named `document.pdf` should be produced and contain the
23098 following text:
23099
23100 > Packages can specify token renderer prototypes.
23101 >
23102 > User-defined token renderers take precedence.
23103
23104 % \fi
23105 %
23106 % \begin{markdown}
23107
23108 #### YAML Metadata Renderer Prototypes {#expl3yamlmetadata}
23109
23110 For simple YAML metadata, a simple high-level interface is provided
23111 that can be programmed by setting the expl3 key--values [@latex25] for the
23112 module `markdown/jekyllData`.
23113
23114 % \end{markdown}
23115 % \iffalse
23116
23117 ##### Plain \TeX{} Example {.unnumbered}
23118
23119 Using a text editor, create a text document named `document.tex` with the
23120 following content:
23121 ``` tex
23122 \input markdown
23123 \def\markdownOptionJekyllData{true}
23124 \ExplSyntaxOn
23125 \keys_define:nn
23126 { markdown/jekyllData }
23127 {
23128 name .code:n = { \gdef\name{#1} },
23129 age .code:n = { \gdef\age{#1} },
23130 }
23131 \ExplSyntaxOff
23132 \def\markdownRendererJekyllDataEnd{%
23133 \name{} is \age{} years old.}
23134 \markdownBegin
23135 ---
23136 name: Jane Doe
23137 age: 99
23138 ---
23139 \markdownEnd
23140 \bye
23141 ```````
23142 Next, invoke LuaTeX from the terminal:
23143 ``` sh
23144 luatex document.tex
23145 ``````
23146 A PDF document named `document.pdf` should be produced and contain the
23147 following text:
23148
23149 > Jane Doe is 99 years old.
23150
23151 ##### \LaTeX{} Example {.unnumbered}
23152
23153 Using a text editor, create a text document named `document.tex` with the
23154 following content:
23155 ``` tex
23156 \documentclass{article}
23157 \usepackage[jekyllData]{markdown}
23158 \markdownSetup{
23159 jekyllDataRenderers = {
23160 name = {\gdef\name{#1}},
23161 code = {\gdef\age{#1}},
23162 },
23163 renderers = {
23164 jekyllDataEnd = {\name{} is \age{} years old.},
23165 }
23166 }
23167 \begin{document}
23168
23169 \begin{markdown}
23170 ---
23171 name: Jane Doe
23172 age: 99
23173 ---
23174 \end{markdown}
23175
23176 \end{document}
23177 ```````
23178 Next, invoke LuaTeX from the terminal:
23179 ``` sh
23180 lualatex document.tex
23181 ``````
23182 A PDF document named `document.pdf` should be produced and contain the
23183 following text:
23184
23185 > Jane Doe is 99 years old.
23186
23187 ##### \Hologo{ConTeXt} Example {.unnumbered}
23188
23189 Using a text editor, create a text document named `document.tex` with the
23190 following content:
23191 ``` tex
23192 \usemodule[t][markdown]
23193 \setupmarkdown[jekyllData = yes]
23194 \ExplSyntaxOn
23195 \keys_define:nn
23196 { markdown/jekyllData }
23197 {
23198 name .code:n = { \gdef\name{#1} },
23199 age .code:n = { \gdef\age{#1} },
23200 }
23201 \ExplSyntaxOff
23202 \def\markdownRendererJekyllDataEnd{%
23203 \name{} is \age{} years old.}
23204 \starttext
23205
23206 \startmarkdown
23207 ---
23208 name: Jane Doe
23209 age: 99
23210 ---
23211 \stopmarkdown
23212
23213 \stoptext
23214 ```````
23215 Next, invoke LuaTeX from the terminal:
23216 ``` sh
23217 context --luatex document.tex
23218 ``````
23219 A PDF document named `document.pdf` should be produced and contain the
23220 following text:
23221
23222 > Jane Doe is 99 years old.
23223
23224 %</manual-tokens>
23225 %<*tex>
23226 % \fi
23227 % \begin{macrocode}
23228 \ExplSyntaxOn
23229 \keys_define:nn
23230 { markdown/jekyllData }
23231 { }
23232 \ExplSyntaxOff
23233 % \end{macrocode}
23234 % \begin{markdown}
23235 %
23236 % The option `jekyllDataRenderers`=\meta{key--values} can be used to set the
23237 % \meta{key--values} for the module `markdown/jekyllData` without using the
23238 % expl3 syntax.
23239 %
23240 % \end{markdown}
23241 % \begin{macrocode}
23242 \ExplSyntaxOn
23243 \@@_with_various_cases:nn
23244 { jekyllDataRenderers }
23245 {
23246 \keys_define:nn
23247 { markdown/options }
23248 {
23249 #1 .value_required:n = { true },
23250 #1 .code:n = {
23251 \tl_set:Nn
23252 \l_tmpa_tl
23253 { ##1 }
23254 % \end{macrocode}
23255 % \begin{markdown}
23256 %
23257 % To ensure that keys containing forward slashes get passed correctly, we
23258 % replace all forward slashes in the input with backslash tokens with category
23259 % code letter and then undo the replacement. This means that if any unbraced
23260 % backslash tokens with category code letter exist in the input, they will be
23261 % replaced with forward slashes. However, this should be extremely rare.
23262 %
23263 % \end{markdown}
23264 % \begin{macrocode}
23265 \tl_replace_all:NnV
23266 \l_tmpa_tl
23267 { / }
23268 \c_backslash_str
23269 \keys_set:nV
23270 { markdown/options/jekyll-data-renderers }
23271 \l_tmpa_tl
23272 },
23273 }
23274 }
23275 \keys_define:nn
23276 { markdown/options/jekyll-data-renderers }
23277 {
23278 unknown .value_required:n = { true },
23279 unknown .code:n = {
23280 \tl_set_eq:NN
23281 \l_tmpa_tl
23282 \l_keys_key_str
23283 \tl_replace_all:NVn
23284 \l_tmpa_tl
23285 \c_backslash_str
23286 { / }
23287 \tl_put_right:Nn
23288 \l_tmpa_tl
23289 {
23290 .code:n = { #1 }
23291 }
23292 \keys_define:nV
23293 { markdown/jekyllData }
23294 \l_tmpa_tl
23295 }
23296 }
23297 \ExplSyntaxOff
23298 % \end{macrocode}
23299 % \begin{markdown}
23300 %
23301 % For complex YAML metadata, the option `jekyllDataKeyValue`=\meta{module}
23302 % [@starynovotny25] can be used to route the processing of all YAML
23303 % metadata in the current \TeX{} group to the key--values from \meta{module}.
23304 %
23305 % \end{markdown}
23306 % \iffalse
23307 %</tex>
23308 %<*manual-tokens>
23309
23310 ##### \LaTeX{} Example {.unnumbered}
23311
23312 Using a text editor, create a text document named `document.tex` with the
23313 following content:
23314 ``` tex
23315 \documentclass{article}
23316 \usepackage{markdown}
23317 \ExplSyntaxOn
23318 \str_new:N \g_markdown_example_title_str
23319 \seq_new:N \g_markdown_example_authors_seq
23320 \keys_define:nn
23321 { markdown / example / module }
23322 { % Define a key--value that processes YAML metadata.
23323 title / programmaticString .str_gset:N = \g_markdown_example_title_str, % Store the raw title in a variable.
23324 title .code:n = { \title { #1 } }, % Set the title. This is the same as writing `title / typographicString`.
23325 authors / unknown .code:n = { % Store a variable-length list of authors in an array variable.
23326 \seq_put_right:Nn
23327 \g_markdown_example_authors_seq
23328 { #1 }
23329 },
23330 }
23331 \markdownSetupSnippet
23332 { metadata }
23333 { % Define a snippet that routes YAML metadata to the above key key–value.
23334 jekyllDataKeyValue = markdown / example / module,
23335 renderers = {
23336 jekyllDataEnd = { % At the end of the YAML metadata, ...
23337 \clist_set_from_seq:NN % ... set the list of authors and
23338 \l_tmpa_clist
23339 \g_markdown_example_authors_seq
23340 \exp_args:Nx
23341 \author
23342 { \clist_use:Nn \l_tmpa_clist { ,~ } }
23343 \AtBeginDocument { \maketitle } % ... typeset the title page.
23344 },
23345 }
23346 }
23347 \ExplSyntaxOff
23348 % Process the YAML metadata.
23349 \begin{yaml}[snippet=metadata]
23350 title: Some title that includes _markup_
23351 authors: [Jane Doe, John Moe]
23352 \end{yaml}
23353 \begin{document}
23354 The raw title of the document is:
23355 \ExplSyntaxOn
23356 \str_use:N \g_markdown_example_title_str
23357 \ExplSyntaxOff
23358 \end{document}
23359 ```````
23360 Next, invoke LuaTeX from the terminal:
23361 ``` sh
23362 lualatex document.tex
23363 ``````
23364 A PDF document named `document.pdf` should be produced and contain the
23365 following text:
23366
23367 > ### Some title that includes _markup_
23368 > ##### Jane Doe, John Moe
23369 > ##### _⟨Current date⟩_
23370 >
23371 > The raw title of the document is:
23372 > Some title that includes \_markup\_
23373
23374 %</manual-tokens>
23375 %<*tex>
23376 % \fi
23377 % \begin{markdown}
23378 %
23379 %#### Generating Plain \TeX{} Token Renderer Prototype Macros and Key-Values {#plain-tex-renderer-prototypes}
23380 %
23381 % We define the command \mdef{@@_define_renderer_prototypes:} that defines plain \TeX{}
23382 % macros for token renderer prototypes. Furthermore, the `\markdownSetup` macro also accepts
23383 % the `rendererPrototypes` and `unprotectedRendererPrototypes` keys. The value
23384 % for these keys must be a list of key--values, where the keys correspond to the
23385 % markdown token renderer prototype macros and the values are new definitions
23386 % of these token renderer prototypes.
23387 %
23388 % Whereas the key `rendererPrototypes` defines protected functions, which are
23389 % usually preferable for typesetting, the key `unprotectedRendererPrototypes`
23390 % defines unprotected functions, which are easier to expand and may be
23391 % preferable for programming.
23392 %
23393 % \end{markdown}
23394 % \begin{macrocode}
23395 \ExplSyntaxOn
23396 \cs_new:Nn \@@_define_renderer_prototypes:
23397 {
23398 \seq_map_inline:Nn
23399 \g_@@_renderers_seq
23400 {
23401 \@@_define_renderer_prototype:n
23402 { ##1 }
23403 }
23404 }
23405 \cs_new:Nn \@@_define_renderer_prototype:n
23406 {
23407 \@@_renderer_prototype_tl_to_csname:nN
23408 { #1 }
23409 \l_tmpa_tl
23410 \prop_get:NnN
23411 \g_@@_renderer_arities_prop
23412 { #1 }
23413 \l_tmpb_tl
23414 \@@_define_renderer_prototype:ncV
23415 { #1 }
23416 { \l_tmpa_tl }
23417 \l_tmpb_tl
23418 }
23419 \cs_new:Nn \@@_renderer_prototype_tl_to_csname:nN
23420 {
23421 \tl_set:Nn
23422 \l_tmpa_tl
23423 { \str_uppercase:n { #1 } }
23424 \tl_set:Nx
23425 #2
23426 {
23427 markdownRenderer
23428 \tl_head:f { \l_tmpa_tl }
23429 \tl_tail:n { #1 }
23430 Prototype
23431 }
23432 }
23433 \tl_new:N
23434 \l_@@_renderer_prototype_definition_tl
23435 \bool_new:N
23436 \g_@@_prepending_renderer_prototype_bool
23437 \bool_new:N
23438 \g_@@_appending_renderer_prototype_bool
23439 \bool_new:N
23440 \g_@@_unprotected_renderer_prototype_bool
23441 \cs_new:Nn \@@_define_renderer_prototype:nNn
23442 {
23443 \keys_define:nn
23444 { markdown/options/renderer-prototypes }
23445 {
23446 #1 .value_required:n = { true },
23447 #1 .code:n = {
23448 \tl_set:Nn
23449 \l_@@_renderer_prototype_definition_tl
23450 { ##1 }
23451 \regex_replace_all:nnN
23452 { \cP\#0 }
23453 { #1 }
23454 \l_@@_renderer_prototype_definition_tl
23455 \bool_if:nT
23456 {
23457 \g_@@_prepending_renderer_prototype_bool ||
23458 \g_@@_appending_renderer_prototype_bool
23459 }
23460 {
23461 \@@_tl_set_from_cs:NNn
23462 \l_tmpa_tl
23463 #2
23464 { #3 }
23465 \bool_if:NTF
23466 \g_@@_prepending_renderer_prototype_bool
23467 {
23468 \tl_put_right:NV
23469 \l_@@_renderer_prototype_definition_tl
23470 \l_tmpa_tl
23471 }
23472 {
23473 \tl_put_left:NV
23474 \l_@@_renderer_prototype_definition_tl
23475 \l_tmpa_tl
23476 }
23477 }
23478 \bool_if:NTF
23479 \g_@@_unprotected_renderer_prototype_bool
23480 {
23481 \tl_set:Nn
23482 \l_tmpa_tl
23483 { \cs_set:Npn }
23484 }
23485 {
23486 \tl_set:Nn
23487 \l_tmpa_tl
23488 { \cs_set_protected:Npn }
23489 }
23490 \exp_last_unbraced:NNV
23491 \cs_generate_from_arg_count:NNnV
23492 #2
23493 \l_tmpa_tl
23494 { #3 }
23495 \l_@@_renderer_prototype_definition_tl
23496 },
23497 }
23498 % \end{macrocode}
23499 % \begin{markdown}
23500 %
23501 % Unless the token renderer prototype macro has already been defined or unless,
23502 % it has been deprecated, we provide an empty definition.
23503 %
23504 % The \mdef{markdownRendererJekyllDataStringPrototype} macro has been
23505 % deprecated and will be removed in Markdown 4.0.0.
23506 %
23507 % \end{markdown}
23508 % \begin{macrocode}
23509 \str_if_eq:nnF
23510 { #1 }
23511 { jekyllDataString }
23512 {
23513 \cs_if_free:NT
23514 #2
23515 {
23516 \cs_generate_from_arg_count:NNnn
23517 #2
23518 \cs_gset_protected:Npn
23519 { #3 }
23520 { }
23521 }
23522 }
23523 }
23524 \cs_generate_variant:Nn
23525 \@@_define_renderer_prototype:nNn
23526 { ncV }
23527 % \end{macrocode}
23528 % \begin{markdown}
23529 %
23530 % The following example code showcases a possible configuration of the
23531 % `\markdownRendererImagePrototype` and `\markdownRendererCodeSpanPrototype`
23532 % token renderer prototype macros.
23533 % ``` tex
23534 % \markdownSetup{
23535 % rendererPrototypes = {
23536 % image = {\pdfximage{#2}}, \% Embed PDF images in the document.
23537 % codeSpan = {{\tt #1}}, \% Render inline code using monospace.
23538 % }
23539 % }
23540 % ```````
23541 %
23542 % \end{markdown}
23543 % \begin{macrocode}
23544 \keys_define:nn
23545 { markdown/options/renderer-prototypes }
23546 {
23547 unknown .value_required:n = { true },
23548 unknown .code:n = {
23549 % \end{macrocode}
23550 % \begin{markdown}
23551 %
23552 % Besides defining renderer prototypes at once, we can also define them
23553 % incrementally using the prepending (`^=`) and appending (`$=` or `+=`)
23554 % operators. This can be especially useful in defining rules for processing
23555 % different HTML class names and identifiers:
23556 % ``` tex
23557 % \markdownSetup{
23558 % rendererPrototypes = {
23559 % \% Start with empty renderer prototypes.
23560 % headerAttributeContextBegin = \begingroup,
23561 % headerAttributeContextEnd = \endgroup,
23562 % attributeClassName = {},
23563 % attributeIdentifier = {},
23564 % \% Define the processing of a single specific HTML class name.
23565 % headerAttributeContextBegin += {
23566 % \markdownSetup{
23567 % rendererPrototypes = {
23568 % attributeClassName += {...},
23569 % },
23570 % }
23571 % },
23572 % \% Define the processing of a single specific HTML identifier.
23573 % headerAttributeContextBegin += {
23574 % \markdownSetup{
23575 % rendererPrototypes = {
23576 % attributeIdentifier += {...},
23577 % },
23578 % }
23579 % },
23580 % },
23581 % }
23582 % ```````
23583 %
23584 % \end{markdown}
23585 % \begin{macrocode}
23586 % TODO: Use `\regex_if_match` in TeX Live 2025.
23587 \regex_match:NVT
23588 \c_@@_prepending_key_regex
23589 \l_keys_key_str
23590 {
23591 \bool_gset_true:N
23592 \g_@@_prepending_renderer_prototype_bool
23593 }
23594 % TODO: Use `\regex_if_match` in TeX Live 2025.
23595 \regex_match:NVT
23596 \c_@@_appending_key_regex
23597 \l_keys_key_str
23598 {
23599 \bool_gset_true:N
23600 \g_@@_appending_renderer_prototype_bool
23601 }
23602 % TODO: Use `\regex_if_match` in TeX Live 2025.
23603 \regex_match:NVTF
23604 \c_@@_prepending_or_appending_key_regex
23605 \l_keys_key_str
23606 {
23607 \tl_set:NV
23608 \l_tmpa_tl
23609 \l_keys_key_str
23610 \regex_replace_once:NnN
23611 \c_@@_prepending_or_appending_key_regex
23612 { }
23613 \l_tmpa_tl
23614 \tl_set:Nx
23615 \l_tmpb_tl
23616 { { \l_tmpa_tl } = }
23617 \tl_put_right:Nn
23618 \l_tmpb_tl
23619 { { #1 } }
23620 \keys_set:nV
23621 { markdown/options/renderer-prototypes }
23622 \l_tmpb_tl
23623 \bool_gset_false:N
23624 \g_@@_prepending_renderer_prototype_bool
23625 \bool_gset_false:N
23626 \g_@@_appending_renderer_prototype_bool
23627 }
23628 % \end{macrocode}
23629 % \begin{markdown}
23630 %
23631 % In addition to exact token renderer prototype names, we also support
23632 % wildcards (`*`) and enumerations (`|`) that match multiple token renderer
23633 % prototype names:
23634 % ``` tex
23635 % \markdownSetup{
23636 % rendererPrototypes = {
23637 % heading* = {{\bf #1}}, \% Render headings using the bold face.
23638 % jekyllData(String|Number) = { \% Render YAML string and numbers
23639 % {\it #2}\% \% using italics.
23640 % },
23641 % }
23642 % }
23643 % ```````
23644 %
23645 % Wildcards and enumerations can be combined:
23646 % ``` tex
23647 % \markdownSetup{
23648 % rendererPrototypes = {
23649 % *lItem(|End) = {"}, \% Quote ordered/bullet list items.
23650 % }
23651 % }
23652 % ```````
23653 %
23654 % To determine the current token renderer prototype, you can use the
23655 % pseudo-parameter `#0`:
23656 % ``` tex
23657 % \markdownSetup{
23658 % rendererPrototypes = {
23659 % heading* = {#0: #1}, \% Render headings as the renderer prototype
23660 % } \% name followed by the heading text.
23661 % }
23662 % ```````
23663 %
23664 % \end{markdown}
23665 % \begin{macrocode}
23666 {
23667 \@@_glob_seq:VnN
23668 \l_keys_key_str
23669 { g_@@_renderers_seq }
23670 \l_@@_renderer_glob_results_seq
23671 \seq_if_empty:NTF
23672 \l_@@_renderer_glob_results_seq
23673 {
23674 \msg_error:nnV
23675 { markdown }
23676 { undefined-renderer-prototype }
23677 \l_keys_key_str
23678 }
23679 {
23680 \tl_set:Nn
23681 \l_@@_renderer_glob_definition_tl
23682 { \exp_not:n { #1 } }
23683 \seq_map_inline:Nn
23684 \l_@@_renderer_glob_results_seq
23685 {
23686 \tl_set:Nn
23687 \l_tmpa_tl
23688 { { ##1 } = }
23689 \tl_put_right:Nx
23690 \l_tmpa_tl
23691 { { \l_@@_renderer_glob_definition_tl } }
23692 \keys_set:nV
23693 { markdown/options/renderer-prototypes }
23694 \l_tmpa_tl
23695 }
23696 }
23697 }
23698 },
23699 }
23700 \msg_new:nnn
23701 { markdown }
23702 { undefined-renderer-prototype }
23703 {
23704 Renderer~prototype~#1~is~undefined.
23705 }
23706 \@@_with_various_cases:nn
23707 { rendererPrototypes }
23708 {
23709 \keys_define:nn
23710 { markdown/options }
23711 {
23712 #1 .value_required:n = { true },
23713 #1 .code:n = {
23714 \bool_gset_false:N
23715 \g_@@_unprotected_renderer_prototype_bool
23716 \keys_set:nn
23717 { markdown/options/renderer-prototypes }
23718 { ##1 }
23719 },
23720 }
23721 }
23722 \@@_with_various_cases:nn
23723 { unprotectedRendererPrototypes }
23724 {
23725 \keys_define:nn
23726 { markdown/options }
23727 {
23728 #1 .value_required:n = { true },
23729 #1 .code:n = {
23730 \bool_gset_true:N
23731 \g_@@_unprotected_renderer_prototype_bool
23732 \keys_set:nn
23733 { markdown/options/renderer-prototypes }
23734 { ##1 }
23735 },
23736 }
23737 }
23738 % \end{macrocode}
23739 % \begin{markdown}
23740 %
23741 % If plain \TeX{} is the top layer, we use the \mref{@@_define_renderer_prototypes:}
23742 % macro to define plain \TeX{} token renderer prototype macros and key--values
23743 % immediately. Otherwise, we postpone the definition until the upper layers
23744 % have been loaded.
23745 %
23746 % \end{markdown}
23747 % \begin{macrocode}
23748 \str_if_eq:VVT
23749 \c_@@_top_layer_tl
23750 \c_@@_option_layer_plain_tex_tl
23751 {
23752 \@@_define_renderer_prototypes:
23753 }
23754 \ExplSyntaxOff
23755 % \end{macrocode}
23756 % \begin{markdown}
23757 %
23758 %### Logging Facilities
23759 % The \mdef{markdownInfo}, \mdef{markdownWarning}, and \mdef{markdownError}
23760 % macros perform logging for the Markdown package. Their first argument
23761 % specifies the text of the info, warning, or error message.
23762 % The \mref{markdownError} macro receives a second argument that provides a help
23763 % text. You may redefine these macros to redirect and process the info,
23764 % warning, and error messages.
23765 %
23766 % The \mref{markdownInfo}, \mref{markdownWarning}, and \mref{markdownError}
23767 % macros have been deprecated and will be removed in the next major version of
23768 % the Markdown package.
23769 %
23770 %### Miscellanea
23771 % The \mdef{markdownMakeOther} macro is used by the package, when a \TeX{}
23772 % engine that does not support direct Lua access is starting to buffer a text.
23773 % The plain \TeX{} implementation changes the category code of plain \TeX{}
23774 % special characters to other, but there may be other active characters that
23775 % may break the output. This macro should temporarily change the category of
23776 % these to *other*.
23777 %
23778 % \end{markdown}
23779 % \begin{macrocode}
23780 \let\markdownMakeOther\relax
23781 % \end{macrocode}
23782 % \begin{markdown}
23783 %
23784 % The \mdef{markdownReadAndConvert} macro implements the \mref{markdownBegin}
23785 % and \mref{yamlBegin} macros. The first argument specifies the token sequence
23786 % that will terminate the markdown input when the plain \TeX{} special
23787 % characters have had their category changed to *other*: \mref{markdownEnd} for
23788 % the \mref{markdownBegin} macro and \mref{yamlEnd} for the \mref{yamlBegin}
23789 % macro. The second argument specifies the token sequence that will actually be
23790 % inserted into the document, when the ending token sequence has been found.
23791 %
23792 % \end{markdown}
23793 % \begin{macrocode}
23794 \let\markdownReadAndConvert\relax
23795 \begingroup
23796 % \end{macrocode}
23797 % \begin{markdown}
23798 % Locally swap the category code of the backslash symbol (`\`) with the pipe
23799 % symbol (`|`). This is required in order that all the special symbols in the
23800 % first argument of the `markdownReadAndConvert` macro have the category code
23801 % *other*.
23802 %
23803 % \end{markdown}
23804 % \begin{macrocode}
23805 \catcode`\|=0\catcode`\\=12%
23806 |gdef|markdownBegin{%
23807 |markdownReadAndConvert{\markdownEnd}%
23808 {|markdownEnd}}%
23809 |gdef|yamlBegin{%
23810 |begingroup
23811 |yamlSetup{jekyllData, expectJekyllData, ensureJekyllData}%
23812 |markdownReadAndConvert{\yamlEnd}%
23813 {|yamlEnd}}%
23814 |endgroup
23815 % \end{macrocode}
23816 % \begin{markdown}
23817 % The macro is exposed in the interface, so that users can create their own
23818 % markdown environments. Due to the way the arguments are passed to Lua, the
23819 % first argument may not contain the string `]]` (regardless of the category
23820 % code of the bracket symbol).
23821 %
23822 % The `code` key, which can be used to immediately expand and execute code.
23823 % \end{markdown}
23824 % \begin{macrocode}
23825 \ExplSyntaxOn
23826 \keys_define:nn
23827 { markdown/options }
23828 {
23829 code .value_required:n = { true },
23830 code .code:n = { #1 },
23831 }
23832 \ExplSyntaxOff
23833 % \end{macrocode}
23834 % \begin{markdown}
23835 % This can be especially useful in snippets.
23836 %
23837 % \end{markdown}
23838 % \iffalse
23839 %</tex>
23840 % \fi
23841 % \begin{markdown}
23842 %
23843 % \LaTeX{} Interface {#latexinterface}
23844 %--------------------
23845 %
23846 % \end{markdown}
23847 % \iffalse
23848 %<*manual-interfaces>
23849
23850 ### \LaTeX{}
23851
23852 The \LaTeX{} interface provides the same level of functionality as the plain
23853 \TeX{} interface by using the plain \TeX{} interface behind the scenes. Unlike
23854 the plain \TeX{} interface, the \LaTeX{} interface uses familiar \LaTeX{}
23855 idioms, such as package options and environments.
23856
23857 The \LaTeX{} interface accepts the same options as the plain \TeX{} interface,
23858 but now the options are specified as \meta{key}${}={}$\meta{value} pairs and
23859 they are passed either as package options, in the \mref{markdownSetup} command, or
23860 as parameters for the \envmref{markdown} \LaTeX{} environment.
23861
23862 Using a text editor, create a text document named `document.tex` with the
23863 following content:
23864 ``` tex
23865 \documentclass{article}
23866 \usepackage{markdown}
23867 \begin{document}
23868
23869 \begin{markdown}
23870 $\sqrt{-1}$ *equals* $i$
23871 \end{markdown}
23872
23873 \begin{markdown}[texMathDollars]
23874 $\sqrt{-1}$ *equals* $i$
23875 \end{markdown}
23876
23877 \end{document}
23878 ```````
23879 Next, invoke LuaTeX from the terminal:
23880 ``` sh
23881 lualatex document.tex
23882 ``````
23883 A PDF document named `document.pdf` should be produced and contain the
23884 following text:
23885
23886 > \$\\sqrt{-1}\$ *equals* \$i\$.
23887 >
23888 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
23889 > *equals*
23890 > <math><mi>i</mi></math>.
23891
23892 Invoking pdfTeX should have the same effect:
23893 ``` sh
23894 pdflatex --shell-escape document.tex
23895 ``````
23896
23897 %</manual-interfaces>
23898 %<*latex>
23899 % \fi
23900 % \begin{markdown}
23901 %
23902 % The \LaTeX{} interface provides \LaTeX{} environments for the typesetting of
23903 % markdown input from within \LaTeX{}, facilities for setting Lua, plain \TeX,
23904 % and \LaTeX{} options used during the conversion from markdown to plain
23905 % \TeX{}, and facilities for changing the way markdown tokens are rendered. The
23906 % rest of the interface is inherited from the plain \TeX{} interface (see
23907 % Section <#sec:texinterface>).
23908 %
23909 % To determine whether \LaTeX{} is the top layer or if there are other
23910 % layers above \LaTeX{}, we take a look on whether the
23911 % \mref{c_@@_top_layer_tl} token list has already been defined. If not,
23912 % we will assume that \LaTeX{} is the top layer.
23913 %
23914 % \end{markdown}
23915 % \begin{macrocode}
23916 \ExplSyntaxOn
23917 \tl_const:Nn \c_@@_option_layer_latex_tl { latex }
23918 \cs_generate_variant:Nn
23919 \tl_const:Nn
23920 { NV }
23921 \tl_if_exist:NF
23922 \c_@@_top_layer_tl
23923 {
23924 \tl_const:NV
23925 \c_@@_top_layer_tl
23926 \c_@@_option_layer_latex_tl
23927 }
23928 \ExplSyntaxOff
23929 \input markdown/markdown
23930 % \end{macrocode}
23931 % \begin{markdown}
23932 %
23933 % The \LaTeX{} interface is implemented by the `markdown.sty` file, which
23934 % can be loaded from the \LaTeX{} document preamble as follows:
23935 % \end{markdown}
23936 % \begin{Verbatim}[commandchars=\\\{\},gobble=2]
23937 % \textbackslash{}usepackage[\textrm{\meta{options}}]\{markdown\}
23938 % \end{Verbatim}
23939 % \begin{markdown}
23940 % where \meta{options} are the \LaTeX{} interface options (see Section
23941 % <#sec:latex-options>). Note that \meta{options} inside the `\usepackage`
23942 % macro may not set the `markdownRenderers` (see Section
23943 % <#sec:plain-tex-renderers>) and `markdownRendererPrototypes` (see Section
23944 % <#sec:plain-tex-renderer-prototypes>) keys. Furthermore, although the
23945 % base variant of the `import` key that loads a single \LaTeX{} theme
23946 % (see Section <#sec:latexthemes>) can be used, the extended variant
23947 % that can load multiple themes and import snippets from them (see
23948 % Section <#sec:snippets>) cannot. This limitation is due to the way
23949 % \Hologo{LaTeX2e} parses package options.
23950 %
23951 % \end{markdown}
23952 % \begin{markdown}
23953 %
23954 %### Typesetting Markdown and YAML {#latex-typesetting}
23955 %
23956 % The interface exposes the \envmdef{markdown}, \envmdef{markdown*}, and
23957 % \envmdef{yaml} \LaTeX{} environments, and redefines the \mref{markinline},
23958 % \mref{markdownInput}, and \mref{yamlInput} commands.
23959 %
23960 %#### Typesetting Markdown and YAML directly
23961 %
23962 % The \envmref{markdown} and \envmref{markdown*} \LaTeX{} environments are
23963 % aliases for the macros \mref{markdownBegin} and \mref{markdownEnd} exposed
23964 % by the plain \TeX{} interface.
23965 %
23966 % The \envmref{markdown*} environment has been deprecated and will be removed
23967 % in the next major version of the Markdown package.
23968 %
23969 % \end{markdown}
23970 % \begin{macrocode}
23971 \newenvironment{markdown}\relax\relax
23972 \newenvironment{markdown*}[1]\relax\relax
23973 % \end{macrocode}
23974 % \markdownBegin
23975 %
23976 % Furthermore, both environments accept \LaTeX{} interface options (see Section
23977 % <#sec:latex-options>) as the only argument. This argument is optional for the
23978 % \envmref{markdown} environment and mandatory for the \envmref{markdown*}
23979 % environment.
23980 %
23981 % The \envmref{markdown} and \envmref{markdown*} environments are
23982 % subject to the same limitations as the \mref{markdownBegin} and
23983 % \mref{markdownEnd} macros.
23984 %
23985 % The following example \LaTeX{} code showcases the usage of the
23986 % \envmref{markdown} and \envmref{markdown*} environments:
23987 %
23988 % ``` tex
23989 % \documentclass{article} \documentclass{article}
23990 % \usepackage{markdown} \usepackage{markdown}
23991 % \begin{document} \begin{document}
23992 % \begin{markdown}[smartEllipses] \begin{markdown*}{smartEllipses}
23993 % _Hello_ **world** ... _Hello_ **world** ...
23994 % \end{markdown} \end{markdown*}
23995 % \end{document} \end{document}
23996 % ```````
23997 %
23998 % You can't directly extend the \envmref{markdown} \LaTeX{} environment by
23999 % using it in other environments as follows:
24000 %
24001 % ``` tex
24002 % \newenvironment{foo}\%
24003 % {code before \begin{markdown}[some, options]}\%
24004 % {\end{markdown} code after}
24005 % ```
24006 %
24007 % This is because the implementation looks for the literal string
24008 % `\end{markdown}` to stop scanning the markdown text. However, you can work
24009 % around this limitation by using the \mdef{markdown} and \mref{markdownEnd}
24010 % macros directly in the definition as follows:
24011 %
24012 % \markdownEnd
24013 % \begin{markdown}
24014 %
24015 % ``` tex
24016 % \newenvironment{foo}\%
24017 % {code before \markdown[some, options]}\%
24018 % {\markdownEnd code after}
24019 % ```
24020 %
24021 % Specifically, the \mref{markdown} macro must appear at the end of the
24022 % replacement before-text and must be followed by text that has not yet been
24023 % ingested by \TeX's input processor.
24024 %
24025 % Furthermore, using the \mref{markdownEnd} macro in of after the replacement
24026 % after-text is optional and only makes a difference if you redefined it to
24027 % produce special effects before and after the \envmref{markdown} \LaTeX{}
24028 % environment.
24029 %
24030 % Lastly, you can't nest the other environments. For example, the following
24031 % definition would be incorrect:
24032 %
24033 % ``` tex
24034 % \newenvironment{bar}{\begin{foo}}{\end{foo}}
24035 % ```
24036 %
24037 % In this example, you should use the \mref{markdown} macro directly in the
24038 % definition of the environment `bar`:
24039 %
24040 % ``` tex
24041 % \newenvironment{bar}{\markdown[some, options]}{\markdownEnd}
24042 % ```
24043 %
24044 % The \envmref{yaml} \LaTeX{} environment is an alias for the macros
24045 % \mref{yamlBegin} and \mref{yamlEnd} exposed by the plain \TeX{} interface.
24046 %
24047 % \end{markdown}
24048 % \begin{macrocode}
24049 \newenvironment{yaml}\relax\relax
24050 % \end{macrocode}
24051 % \begin{markdown}
24052 %
24053 % Furthermore, the environment accepts \LaTeX{} interface options (see Section
24054 % <#sec:latex-options>) as the only optional argument.
24055 %
24056 % The \envmref{yaml} environment is subject to the same limitations as
24057 % the \mref{markdownBegin} and \mref{markdownEnd} macros.
24058 %
24059 % The following example \LaTeX{} code showcases the usage of the
24060 % \envmref{yaml} environment:
24061 %
24062 % ``` tex
24063 % \documentclass{article}
24064 % \usepackage{markdown}
24065 % \begin{document}
24066 % \begin{yaml}[smartEllipses]
24067 % title: _Hello_ **world** ...
24068 % author: John Doe
24069 % \end{yaml}
24070 % \end{document}
24071 % ```````
24072 %
24073 % \end{markdown}
24074 % \markdownBegin
24075 %
24076 % The above code has the same effect as the below code:
24077 %
24078 % ``` tex
24079 % \documentclass{article}
24080 % \usepackage{markdown}
24081 % \begin{document}
24082 % \begin{markdown}[
24083 % jekyllData,
24084 % expectJekyllData,
24085 % ensureJekyllData,
24086 % smartEllipses,
24087 % ]
24088 % title: _Hello_ **world** ...
24089 % author: John Doe
24090 % \end{markdown}
24091 % \end{document}
24092 % ```````
24093 %
24094 % You can't directly extend the \envmref{yaml} \LaTeX{} environment by using it
24095 % in other environments. However, you can work around this limitation by using
24096 % the \mdef{yaml} and \mref{yamlEnd} macros directly in the definition,
24097 % similarly to the \mref{markdown} and \mref{markdownEnd} macros described
24098 % previously. Unlike with the \mref{markdown} and \mref{markdownEnd} macros,
24099 % The \mref{yamlEnd} macro _must_ be used in or after the replacement after-text.
24100 %
24101 % The \mref{markinline} macro accepts a single mandatory parameter containing
24102 % inline markdown content and expands to the result of the conversion of the
24103 % input markdown document to plain \TeX{}. Unlike the \mref{markinline} macro
24104 % provided by the plain \TeX{} interface, this macro also accepts \LaTeX{}
24105 % interface options (see Section <#sec:latex-options>) as its optional
24106 % argument. These options will only influence this markdown content.
24107 %
24108 %#### Typesetting Markdown and YAML from external documents
24109 %
24110 % The \mref{markdownInput} macro accepts a single mandatory parameter containing
24111 % the filename of a markdown document and expands to the result of the
24112 % conversion of the input markdown document to plain \TeX{}. Unlike the
24113 % \mref{markdownInput} macro provided by the plain \TeX{} interface, this macro
24114 % also accepts \LaTeX{} interface options (see Section <#sec:latex-options>)
24115 % as its optional argument. These options will only influence this markdown
24116 % document.
24117 %
24118 % The following example \LaTeX{} code showcases the usage of the
24119 % \mref{markdownInput} macro:
24120 %
24121 % ``` tex
24122 % \documentclass{article}
24123 % \usepackage{markdown}
24124 % \begin{document}
24125 % \markdownInput[smartEllipses]{hello.md}
24126 % \end{document}
24127 % ```````
24128 %
24129 % The \mref{yamlInput} macro accepts a single mandatory parameter containing
24130 % the filename of a YAML document and expands to the result of the
24131 % conversion of the input YAML document to plain \TeX{}. Unlike the
24132 % \mref{yamlInput} macro provided by the plain \TeX{} interface, this macro
24133 % also accepts \LaTeX{} interface options (see Section <#sec:latex-options>)
24134 % as its optional argument. These options will only influence this YAML
24135 % document.
24136 %
24137 % The following example \LaTeX{} code showcases the usage of the
24138 % \mref{yamlInput} macro:
24139 %
24140 % ``` tex
24141 % \documentclass{article}
24142 % \usepackage{markdown}
24143 % \begin{document}
24144 % \yamlInput[smartEllipses]{hello.yml}
24145 % \end{document}
24146 % ```````
24147 %
24148 % The above code has the same effect as the below code:
24149 %
24150 % ``` tex
24151 % \documentclass{article}
24152 % \usepackage{markdown}
24153 % \begin{document}
24154 % \markdownInput[
24155 % jekyllData,
24156 % expectJekyllData,
24157 % ensureJekyllData,
24158 % smartEllipses,
24159 % ]{hello.yml}
24160 % \end{document}
24161 % ```````
24162 %
24163 %### Using \LaTeX{} hooks with the Markdown package
24164 %
24165 % \LaTeX{} provides an intricate hook management system that allows users to
24166 % insert extra material before and after certain \TeX{} macros and \LaTeX{}
24167 % environments, among other things. [@mittelbach24, Section 3.1.2]
24168 %
24169 % The Markdown package is compatible with hooks and allows the use of hooks
24170 % to insert extra material before \TeX{} commands and before/after \LaTeX{}
24171 % environments without restriction:
24172 %
24173 % ``` tex
24174 % \documentclass{article}
24175 % \usepackage{markdown}
24176 % \begin{document}
24177 % \AddToHook{cmd/markdownRendererEmphasis/before}{emphasis: }
24178 % \AddToHook{env/markdown/before}{<markdown>}
24179 % \AddToHook{env/markdown/after}{</markdown>}
24180 % \begin{markdown}
24181 % foo _bar_ baz!
24182 % \end{markdown}
24183 % \end{document}
24184 % ```
24185 %
24186 % Processing the above example with \LaTeX{} will produce the text
24187 % “<markdown>foo emphasis: _bar_ baz!</markdown>”, as expected.
24188 %
24189 % However, using hooks to insert extra material after \TeX{} commands only works
24190 % for commands with a fixed number of parameters that don't use currying.
24191 %
24192 % If, in the above example, you explicitly defined the renderer for emphasis
24193 % using \mref{markdownSetup} or another method that does not use currying, then
24194 % you would be able to insert extra material even after the renderer:
24195 %
24196 % ``` tex
24197 % \documentclass{article}
24198 % \usepackage{markdown}
24199 % \markdownSetup{renderers={emphasis={\emph{#1}}}}
24200 % \begin{document}
24201 % \AddToHook{cmd/markdownRendererEmphasis/before}{<emphasis>}
24202 % \AddToHook{cmd/markdownRendererEmphasis/after}{</emphasis>}
24203 % \AddToHook{env/markdown/before}{<markdown>}
24204 % \AddToHook{env/markdown/after}{</markdown>}
24205 % \begin{markdown}
24206 % foo _bar_ baz!
24207 % \end{markdown}
24208 % \end{document}
24209 % ```
24210 %
24211 % Processing the above example with \LaTeX{} will produce the text
24212 % “<markdown>foo <emphasis>_bar_</emphasis> baz!</markdown>”, as expected.
24213 %
24214 % However, the default renderer for emphasis uses currying and calls the
24215 % renderer prototype in a way that prevents the use of hooks to insert extra
24216 % material after the renderer, see Section~<#sec:emphasis-renderers>. In such
24217 % a case, you would need to redefine the renderer in a way that does not use
24218 % currying before you would be able to use hooks to insert extra material
24219 % after it.
24220 %
24221 % Hooks also cannot be used to insert extra material after renderers with a
24222 % variable number of parameters such as the renderer for tables, see
24223 % Section~<#sec:table-renderer>.
24224 %
24225 %### Options {#latex-options}
24226 %
24227 % The \LaTeX{} options are represented by a comma-delimited list of
24228 % \meta{key}`=`\meta{value} pairs. For boolean options, the `=`\meta{value}
24229 % part is optional, and \meta{key} will be interpreted as \meta{key}`=true`
24230 % if the `=`\meta{value} part has been omitted.
24231 %
24232 % \LaTeX{} options map directly to the options recognized by the plain
24233 % \TeX{} interface (see Section <#sec:tex-options>) and to the markdown token
24234 % renderers and their prototypes recognized by the plain \TeX{} interface (see
24235 % Sections <#sec:texrenderersuser> and <#sec:texrendererprototypes>).
24236 %
24237 % The \LaTeX{} options may be specified when loading the \LaTeX{} package, when
24238 % using the \envmref{markdown*} \LaTeX{} environment or the \mref{markdownInput}
24239 % macro (see Section <#sec:latexinterface>), or via the \mref{markdownSetup}
24240 % macro.
24241 %
24242 %#### Finalizing and Freezing the Cache
24243 %
24244 % To ensure compatibility with the `minted` package [@poore17, Section
24245 % 5.1], which supports the `finalizecache` and `frozencache` package options
24246 % with similar semantics to the \Opt{finalizeCache} and \Opt{frozenCache} plain
24247 % \TeX{} options, the Markdown package also recognizes these as aliases
24248 % and accepts them as document class options. By passing `finalizecache` and
24249 % `frozencache` as document class options, you may conveniently control the
24250 % behavior of both packages at once:
24251 %
24252 % ``` tex
24253 % \documentclass[frozencache]{article}
24254 % \usepackage{markdown,minted}
24255 % \begin{document}
24256 % % ...
24257 % \end{document}
24258 % ```````
24259 %
24260 % We hope that other packages will support the `finalizecache` and
24261 % `frozencache` package options in the future, so that they can become a
24262 % standard interface for preparing \LaTeX{} document sources for distribution.
24263 %
24264 % \markdownEnd
24265 % \begin{macrocode}
24266 \DeclareOption{finalizecache}{\markdownSetup{finalizeCache}}
24267 \DeclareOption{frozencache}{\markdownSetup{frozenCache}}
24268 % \end{macrocode}
24269 % \iffalse
24270 %</latex>
24271 %<*manual-options>
24272
24273 ### \LaTeX{}
24274
24275 \LaTeX{} options allow us to disable the redefinition of the default renderer
24276 prototypes from plain \TeX{}, load user-defined themes, and invoke user-defined
24277 set-up snippets.
24278
24279 #### Setting Lua and plain \TeX{} options from \LaTeX{}
24280
24281 As a rule of thumb, we can set all Lua options directly from \LaTeX{}. For
24282 example, to set the \Opt{taskLists} Lua option to `true`, we would include the
24283 following code in our \LaTeX{} document:
24284
24285 ``` tex
24286 \markdownSetup{
24287 taskLists = true,
24288 }
24289 ```
24290
24291 We can also set all plain \TeX{} options directly from \LaTeX{}. For example,
24292 to set the `\markdownOptionInputTempFileName` plain \TeX{} option to
24293 `helper-script.lua`, we would include the following code in our \LaTeX{}
24294 document:
24295
24296 ``` tex
24297 \markdownSetup{
24298 inputTempFileName = temporary-input.md,
24299 }
24300 ```
24301
24302 %</manual-options>
24303 %<*latex>
24304 % \fi
24305 % \begin{markdown}
24306 %
24307 %#### Generating Plain \TeX{} Option, Token Renderer, and Token Renderer Prototype Macros and Key-Values
24308 %
24309 % If \LaTeX{} is the top layer, we use the
24310 % \mref{@@_define_option_commands_and_keyvals:}, \mref{@@_define_renderers:},
24311 % and \mref{@@_define_renderer_prototypes:} macro to define plain \TeX{}
24312 % option, token renderer, and token renderer prototype macros and key--values
24313 % immediately. Otherwise, we postpone the definition until the upper layers
24314 % have been loaded.
24315 %
24316 % \end{markdown}
24317 % \begin{macrocode}
24318 \ExplSyntaxOn
24319 \str_if_eq:VVT
24320 \c_@@_top_layer_tl
24321 \c_@@_option_layer_latex_tl
24322 {
24323 \@@_define_option_commands_and_keyvals:
24324 \@@_define_renderers:
24325 \@@_define_renderer_prototypes:
24326 }
24327 \ExplSyntaxOff
24328 % \end{macrocode}
24329 % \begin{markdown}
24330 %
24331 % The following example \LaTeX{} code showcases a possible configuration of
24332 % plain \TeX{} interface options \Opt{hybrid}, \Opt{smartEllipses}, and
24333 % \Opt{cacheDir}.
24334 % ``` tex
24335 % \markdownSetup{
24336 % hybrid,
24337 % smartEllipses,
24338 % cacheDir = /tmp,
24339 % }
24340 % ```````
24341 %
24342 % \end{markdown}
24343 % \iffalse
24344 %</latex>
24345 %<*manual-options>
24346 % \fi
24347 % \begin{markdown}
24348
24349 %### Themes {#latexthemes}
24350 % \iffalse
24351 #### Themes {#latexthemes}
24352 % \fi
24353
24354 % In Section <#sec:themes>, we described the concept of themes.
24355 In \LaTeX{}, we expand on the concept of
24356 % themes\iffalse
24357 [themes](#themes)
24358 % \fi
24359 by allowing a theme to be a full-blown \LaTeX{} package. Specifically, the
24360 key--values `theme`=\meta{theme name} and `import`=\meta{theme name} load a
24361 \LaTeX{} package named `markdowntheme`\meta{munged theme name}`.sty` if it
24362 exists and a \TeX{} document named `markdowntheme`\meta{munged theme
24363 name}`.tex` otherwise.
24364
24365 Having the Markdown package automatically load either the generic `.tex`
24366 *theme file* or the \LaTeX{}-specific `.sty` theme file allows developers
24367 to have a single *theme file*, when the theme is small or the difference
24368 between \TeX{} formats is unimportant, and scale up to separate theme files
24369 native to different \TeX{} formats for large multi-format themes, where
24370 different code is needed for different \TeX{} formats. To enable code reuse,
24371 developers can load the `.tex` theme file from the `.sty` theme file using the
24372 \mdef{markdownLoadPlainTeXTheme} macro.
24373
24374 % If the \LaTeX{} option with keys `theme` or `import` is (repeatedly)
24375 % specified in the `\usepackage` macro, the loading of the theme(s) will be
24376 % postponed in first-in-first-out order until after the Markdown \LaTeX{}
24377 % package has been loaded. Otherwise, the theme(s) will be loaded immediately.
24378 % For example, the following code would first load the Markdown package, then
24379 % the theme `witiko/example/foo`, and finally the theme `witiko/example/bar`:
24380 % \end{markdown}
24381 % \iffalse
24382
24383 For example, to load themes named `witiko/example/foo` and `witiko/example/bar`,
24384 you would use the following code in the preamble of your document:
24385
24386 % \fi
24387 % \begin{markdown}
24388
24389 ``` tex
24390 \usepackage[
24391 import=witiko/example/foo,
24392 import=witiko/example/bar,
24393 ]{markdown}
24394 ```````
24395
24396 % \end{markdown}
24397 % \iffalse
24398 %</manual-options>
24399 %<*latex>
24400 % \fi
24401 % \begin{macrocode}
24402 \newif\ifmarkdownLaTeXLoaded
24403 \markdownLaTeXLoadedfalse
24404 % \end{macrocode}
24405 % \iffalse
24406 %</latex>
24407 %<*manual-options>
24408 % \fi
24409 % \begin{markdown}
24410
24411 Due to limitations of \LaTeX{}, themes may not be loaded after the
24412 beginning of a \LaTeX{} document.
24413
24414 % We also define the prop \mdef{g_@@_latex_built_in_themes_prop} that
24415 % contains the code of built-in themes. This is a packaging optimization,
24416 % so that built-in themes does not need to be distributed in many small files.
24417 %
24418 % \end{markdown}
24419 % \iffalse
24420 %</manual-options>
24421 %<*latex>
24422 % \fi
24423 % \begin{macrocode}
24424 \ExplSyntaxOn
24425 \prop_new:N
24426 \g_@@_latex_built_in_themes_prop
24427 \ExplSyntaxOff
24428 % \end{macrocode}
24429 % \iffalse
24430 %</latex>
24431 %<*manual-options>
24432 % \fi
24433 % \begin{markdown}
24434
24435 Built-in \LaTeX{} themes provided with the Markdown package include:
24436
24437 \pkg{witiko/markdown/defaults}
24438
24439 : A \LaTeX{} theme with the default definitions of token renderer prototypes
24440 for plain \TeX{}. This theme is loaded automatically together with the
24441 package and explicitly loading it has no effect.
24442
24443 % \end{markdown}
24444 % \iffalse
24445 %</manual-options>
24446 %<*latex>
24447 % \fi
24448 % \begin{macrocode}
24449 \AtEndOfPackage{\markdownLaTeXLoadedtrue}
24450 % \end{macrocode}
24451 % \begin{markdown}
24452 %
24453 % At the end of the \LaTeX{} module, we load the
24454 % `witiko/markdown/defaults` \LaTeX{} theme (see Section <#sec:themes>) with
24455 % the default definitions for token renderer prototypes unless the option
24456 % `noDefaults` has been enabled (see Section <#sec:plain>).
24457 %
24458 % \end{markdown}
24459 % \begin{macrocode}
24460 \ExplSyntaxOn
24461 \str_if_eq:VVT
24462 \c_@@_top_layer_tl
24463 \c_@@_option_layer_latex_tl
24464 {
24465 \use:c
24466 { ExplSyntaxOff }
24467 \AtEndOfPackage
24468 {
24469 \@@_if_option:nF
24470 { noDefaults }
24471 {
24472 \@@_if_option:nTF
24473 { experimental }
24474 {
24475 \@@_setup:n
24476 { theme = witiko/markdown/defaults@experimental }
24477 }
24478 {
24479 \@@_setup:n
24480 { theme = witiko/markdown/defaults }
24481 }
24482 }
24483 }
24484 \use:c
24485 { ExplSyntaxOn }
24486 }
24487 \ExplSyntaxOff
24488 % \end{macrocode}
24489 % \iffalse
24490 %</latex>
24491 %<*manual-options>
24492 % \fi
24493 % \begin{markdown}
24494 %
24495 % See Section <#sec:latex-themes-implementation> for implementation details of
24496 % the built-in \LaTeX{} themes.
24497
24498 %### Snippets {#latexsnippets}
24499 % \iffalse
24500 #### Snippets {#latexsnippets}
24501 % \fi
24502
24503 % In Section <#sec:snippets>, we described the concept of snippets.
24504
24505 Built-in \LaTeX{} snippets provided with the Markdown package include:
24506
24507 \pkg{witiko/glossaries/import-acronyms}
24508
24509 : Imports all acronyms from the \LaTeX{} package \pkg{glossaries}, appends
24510 them to the \Opt{acronyms} option and updates the corresponding renderers
24511 to recognize these acronyms in running text and link them to the
24512 corresponding glossary entries.
24513
24514 % This snippet is provided by the theme `witiko/glossaries@v1`.
24515
24516 % \end{markdown}
24517 % \iffalse
24518
24519 ##### \LaTeX{} Example {.unnumbered}
24520
24521 Using a text editor, create a text document named `document.tex` with the
24522 following content:
24523 ```` tex
24524 \documentclass{article}
24525 \usepackage{microtype, hyperref}
24526 \usepackage[acronym]{glossaries}
24527 \makeglossaries
24528 \newacronym{html}{HTML}{hypertext markup language}
24529 \newacronym{yaml}{YAML}{yet another markup language}
24530 \usepackage{markdown}
24531 \markdownSetup{
24532 import = witiko/glossaries@v1,
24533 snippet = witiko/glossaries/import-acronyms,
24534 }
24535 \begin{document}
24536 \begin{markdown}
24537
24538 HTML and YAML are two staples of modern tooling that often get mentioned
24539 in the same breath, even though they live in very different layers of the stack.
24540
24541 \end{markdown}
24542 \printacronyms
24543 \end{document}
24544 ````
24545 Next, invoke LuaTeX and the `makeglossaries` command from the terminal:
24546 ``` sh
24547 lualatex document.tex
24548 makeglossaries document
24549 lualatex document.tex
24550 ``````
24551
24552 A PDF document named `document.pdf` should be produced and contain the
24553 following text followed by a list of acronyms with HTML and YAML being
24554 correctly linked to the corresponding list entries.
24555
24556 %</manual-options>
24557 %<*context>
24558 % \fi
24559 % \begin{markdown}
24560 %
24561 % See Section <#sec:latex-snippets-implementation> for implementation details of
24562 % the built-in \LaTeX{} snippets.
24563 %
24564 % \Hologo{ConTeXt} Interface {#contextinterface}
24565 %-----------------------------------------------
24566 %
24567 % \end{markdown}
24568 % \iffalse
24569 %</context>
24570 %<*manual-interfaces>
24571
24572 ### \Hologo{ConTeXt}
24573
24574 The \Hologo{ConTeXt} interface provides the same level of functionality as the
24575 plain \TeX{} interface by using the plain \TeX{} interface behind the scenes.
24576 Unlike the plain \TeX{} interface, the \Hologo{ConTeXt} interface uses familiar
24577 \Hologo{ConTeXt} idioms as syntactic sugar.
24578
24579 The \Hologo{ConTeXt} interface accepts the same options as the plain \TeX{}
24580 interface.
24581
24582 Using a text editor, create a text document named `document.tex` with the
24583 following content:
24584 ``` tex
24585 \usemodule[t][markdown]
24586 \starttext
24587
24588 \startmarkdown
24589 $\sqrt{-1}$ *equals* $i$.
24590 \stopmarkdown
24591
24592 \setupmarkdown[texmathdollars = yes]
24593 \startmarkdown
24594 $\sqrt{-1}$ *equals* $i$.
24595 \stopmarkdown
24596
24597 \stoptext
24598 ```````
24599 Next, invoke LuaTeX from the terminal:
24600 ``` sh
24601 context --luatex document.tex
24602 ``````
24603 A PDF document named `document.pdf` should be produced and contain the
24604 following text:
24605
24606 > \$\\sqrt{-1}\$ *equals* \$i\$.
24607 >
24608 > <math><msqrt><mo>−</mo><mn>1</mn></msqrt></math>
24609 > *equals*
24610 > <math><mi>i</mi></math>.
24611
24612 %</manual-interfaces>
24613 %<*context>
24614 % \fi
24615 % \begin{markdown}
24616 %
24617 % To determine whether \Hologo{ConTeXt} is the top layer or if there are other
24618 % layers above \Hologo{ConTeXt}, we take a look on whether the
24619 % \mref{c_@@_top_layer_tl} token list has already been defined. If not,
24620 % we will assume that \Hologo{ConTeXt} is the top layer.
24621 %
24622 % \end{markdown}
24623 % \begin{macrocode}
24624 \ExplSyntaxOn
24625 \tl_const:Nn \c_@@_option_layer_context_tl { context }
24626 \cs_generate_variant:Nn
24627 \tl_const:Nn
24628 { NV }
24629 \tl_if_exist:NF
24630 \c_@@_top_layer_tl
24631 {
24632 \tl_const:NV
24633 \c_@@_top_layer_tl
24634 \c_@@_option_layer_context_tl
24635 }
24636 \ExplSyntaxOff
24637 % \end{macrocode}
24638 % \begin{markdown}
24639 %
24640 % The \Hologo{ConTeXt} interface provides a start-stop macro pair for the
24641 % typesetting of markdown input from within \Hologo{ConTeXt} and facilities for
24642 % setting Lua, plain \TeX, and \Hologo{ConTeXt} options used during the
24643 % conversion from markdown to plain \TeX{}. The rest of the interface is
24644 % inherited from the plain \TeX{} interface (see Section <#sec:texinterface>).
24645 %
24646 % \end{markdown}
24647 % \begin{macrocode}
24648 \writestatus{loading}{ConTeXt User Module / markdown}%
24649 \startmodule[markdown]
24650 \def\dospecials{\do\ \do\\\do\{\do\}\do\$\do\&%
24651 \do\#\do\^\do\_\do\%\do\~}%
24652 \input markdown/markdown
24653 % \end{macrocode}
24654 % \begin{markdown}
24655 %
24656 % The \Hologo{ConTeXt} interface is implemented by the
24657 % `t-markdown.tex` \Hologo{ConTeXt} module file that can be loaded as follows:
24658 % ``` tex
24659 % \usemodule[t][markdown]
24660 % ```````
24661 % \noindent It is expected that the special plain \TeX{} characters have the
24662 % expected category codes, when `\input`ting the file.
24663 %
24664 %### Typesetting Markdown and YAML {#context-typesetting}
24665 %
24666 % The interface exposes the \mdef{startmarkdown}, \mdef{stopmarkdown},
24667 % \mdef{startyaml}, \mdef{stopyaml}, \mdef{inputmarkdown}, and \mdef{inputyaml}
24668 % macros.
24669 %
24670 %#### Typesetting Markdown and YAML directly
24671 %
24672 % The \mref{startmarkdown} and \mref{stopmarkdown} macros are aliases for the
24673 % macros \mref{markdownBegin} and \mref{markdownEnd} exposed by the plain
24674 % \TeX{} interface.
24675 %
24676 % \end{markdown}
24677 % \begin{macrocode}
24678 \let\startmarkdown\relax
24679 \let\stopmarkdown\relax
24680 % \end{macrocode}
24681 % \begin{markdown}
24682 %
24683 % You may prepend your own code to the \mref{startmarkdown} macro and redefine the
24684 % \mref{stopmarkdown} macro to produce special effects before and after the
24685 % markdown block.
24686 %
24687 % The macros \mref{startmarkdown} and \mref{stopmarkdown} are subject to the
24688 % same limitations as the \mref{markdownBegin} and \mref{markdownEnd} macros.
24689 %
24690 % The following example \Hologo{ConTeXt} code showcases the usage of the
24691 % \mref{startmarkdown} and \mref{stopmarkdown} macros:
24692 %
24693 % ``` tex
24694 % \usemodule[t][markdown]
24695 % \starttext
24696 % \startmarkdown
24697 % _Hello_ **world** ...
24698 % \stopmarkdown
24699 % \stoptext
24700 % ```````
24701 %
24702 % The \mref{startyaml} and \mref{stopyaml} macros are aliases for the macros
24703 % \mref{yamlBegin} and \mref{yamlEnd} exposed by the plain \TeX{} interface.
24704 %
24705 % \end{markdown}
24706 % \begin{macrocode}
24707 \let\startyaml\relax
24708 \let\stopyaml\relax
24709 % \end{macrocode}
24710 % \begin{markdown}
24711 %
24712 % You may prepend your own code to the \mref{startyaml} macro and append your
24713 % own code to the \mref{stopyaml} macro to produce special effects before and
24714 % after the YAML document.
24715 %
24716 % The macros \mref{startyaml} and \mref{stopyaml} are subject to the same
24717 % limitations as the \mref{markdownBegin} and \mref{markdownEnd} macros.
24718 %
24719 % The following example \Hologo{ConTeXt} code showcases the usage of the
24720 % \mref{startyaml} and \mref{stopyaml} macros:
24721 %
24722 % ``` tex
24723 % \usemodule[t][markdown]
24724 % \starttext
24725 % \startyaml
24726 % title: _Hello_ **world** ...
24727 % author: John Doe
24728 % \stopyaml
24729 % \stoptext
24730 % ```````
24731 %
24732 % The above code has the same effect as the below code:
24733 %
24734 % ``` tex
24735 % \usemodule[t][markdown]
24736 % \starttext
24737 % \setupyaml[jekyllData, expectJekyllData, ensureJekyllData]
24738 % \startyaml
24739 % title: _Hello_ **world** ...
24740 % author: John Doe
24741 % \stopyaml
24742 % \stoptext
24743 % ```````
24744 %
24745 %#### Typesetting Markdown and YAML from external documents
24746 %
24747 % The \mref{inputmarkdown} macro aliases the macro \mref{markdownInput} exposed
24748 % by the plain \TeX{} interface.
24749 %
24750 % \end{markdown}
24751 % \begin{macrocode}
24752 \let\inputmarkdown\relax
24753 % \end{macrocode}
24754 % \begin{markdown}
24755 %
24756 % Furthermore, the \mref{inputmarkdown} macro also accepts \Hologo{ConTeXt}
24757 % interface options (see Section <#sec:context-options>) as its optional
24758 % argument. These options will only influence this markdown document.
24759 %
24760 % The following example \Hologo{ConTeXt} code showcases the usage of the
24761 % \mref{inputmarkdown} macro:
24762 %
24763 % ``` tex
24764 % \usemodule[t][markdown]
24765 % \starttext
24766 % \inputmarkdown[smartEllipses]{hello.md}
24767 % \stoptext
24768 % ```````
24769 %
24770 % The above code has the same effect as the below code:
24771 %
24772 % ``` tex
24773 % \usemodule[t][markdown]
24774 % \starttext
24775 % \setupmarkdown[smartEllipses]
24776 % \inputmarkdown{hello.md}
24777 % \stoptext
24778 % ```````
24779 %
24780 % The \mref{inputyaml} macro aliases the macro \mref{yamlInput} exposed by the
24781 % plain \TeX{} interface.
24782 %
24783 % \end{markdown}
24784 % \begin{macrocode}
24785 \let\inputyaml\relax
24786 % \end{macrocode}
24787 % \begin{markdown}
24788 %
24789 % Furthermore, the \mref{inputyaml} macro also accepts \Hologo{ConTeXt}
24790 % interface options (see Section <#sec:context-options>) as its optional
24791 % argument. These options will only influence this YAML document.
24792 %
24793 % The following example \Hologo{ConTeXt} code showcases the usage of the
24794 % \mref{inputyaml} macro:
24795 %
24796 % ``` tex
24797 % \usemodule[t][markdown]
24798 % \starttext
24799 % \inputyaml[smartEllipses]{hello.yml}
24800 % \stoptext
24801 % ```````
24802 %
24803 % The above code has the same effect as the below code:
24804 %
24805 % ``` tex
24806 % \usemodule[t][markdown]
24807 % \starttext
24808 % \setupyaml[smartEllipses]
24809 % \inputyaml{hello.yml}
24810 % \stoptext
24811 % ```````
24812 %
24813 %### Options {#context-options}
24814 %
24815 % The \Hologo{ConTeXt} options are represented by a comma-delimited list of
24816 % \meta{key}`=`\meta{value} pairs. For boolean options, the `=`\meta{value}
24817 % part is optional, and \meta{key} will be interpreted as \meta{key}`=true`
24818 % (or, equivalently, \meta{key}`=yes`) if the `=`\meta{value} part has been
24819 % omitted.
24820 %
24821 % \Hologo{ConTeXt} options map directly to the options recognized by the plain
24822 % \TeX{} interface (see Section <#sec:tex-options>).
24823 %
24824 % The \Hologo{ConTeXt} options may be specified when using the
24825 % \mref{inputmarkdown} macro (see Section <#sec:contextinterface>),
24826 % via the \mref{markdownSetup} macro, or via the \mdef{setupmarkdown}`[#1]`
24827 % macro, which is an alias for \mref{markdownSetup}`{#1}`.
24828 %
24829 % \end{markdown}
24830 % \begin{macrocode}
24831 \ExplSyntaxOn
24832 \cs_new:Npn
24833 \setupmarkdown
24834 [ #1 ]
24835 {
24836 \@@_setup:n
24837 { #1 }
24838 }
24839 % \end{macrocode}
24840 % \begin{markdown}
24841 %
24842 % The command \mdef{setupyaml} is also available as an alias for
24843 % the command \mref{setupmarkdown}.
24844 %
24845 % \end{markdown}
24846 % \begin{macrocode}
24847 \cs_gset_eq:NN
24848 \setupyaml
24849 \setupmarkdown
24850 % \end{macrocode}
24851 % \begin{markdown}
24852 %
24853 %#### Generating Plain \TeX{} Option Macros and Key-Values
24854 %
24855 % Unlike plain \TeX{}, we also accept caseless variants of options
24856 % in line with the style of \Hologo{ConTeXt}.
24857 %
24858 % \end{markdown}
24859 % \begin{macrocode}
24860 \cs_new:Nn \@@_caseless:N
24861 {
24862 \regex_replace_all:nnN
24863 { ([a-z])([A-Z]) }
24864 { \1 \c { str_lowercase:n } \cB\{ \2 \cE\} }
24865 #1
24866 \tl_set:Nx
24867 #1
24868 { #1 }
24869 }
24870 \seq_gput_right:Nn \g_@@_cases_seq { @@_caseless:N }
24871 % \end{macrocode}
24872 % \begin{markdown}
24873 %
24874 % If \Hologo{ConTeXt} is the top layer, we use the
24875 % \mref{@@_define_option_commands_and_keyvals:}, \mref{@@_define_renderers:},
24876 % and \mref{@@_define_renderer_prototypes:} macro to define plain \TeX{}
24877 % option, token renderer, and token renderer prototype macros and key--values
24878 % immediately. Otherwise, we postpone the definition until the upper layers
24879 % have been loaded.
24880 %
24881 % \end{markdown}
24882 % \begin{macrocode}
24883 \str_if_eq:VVT
24884 \c_@@_top_layer_tl
24885 \c_@@_option_layer_context_tl
24886 {
24887 \@@_define_option_commands_and_keyvals:
24888 \@@_define_renderers:
24889 \@@_define_renderer_prototypes:
24890 }
24891 % \end{macrocode}
24892 % \iffalse
24893 %</context>
24894 %<*manual-options>
24895 % \fi
24896 % \begin{markdown}
24897 %
24898 %### Themes {#contextthemes}
24899 % \iffalse
24900 ### \Hologo{ConTeXt}
24901 #### Themes {#contextthemes}
24902 % \fi
24903 %
24904 % In Section <#sec:themes>, we described the concept of themes.
24905 In \Hologo{ConTeXt}, we expand on the concept of
24906 % themes\iffalse
24907 [themes](#themes)
24908 % \fi
24909 by allowing a theme to be a full-blown \Hologo{ConTeXt} module. Specifically,
24910 the key--values `theme`=\meta{theme name} and `import`=\meta{theme name} load a
24911 \Hologo{ConTeXt} module named `t-markdowntheme`\meta{munged theme name}`.tex`
24912 if it exists and a \TeX{} document named `markdowntheme`\meta{munged theme
24913 name}`.tex` otherwise.
24914
24915 Having the Markdown package automatically load either the generic `.tex`
24916 *theme file* or the \Hologo{ConTeXt}-specific `t-*.tex` theme file allows
24917 developers to have a single *theme file*, when the theme is small or the
24918 difference between \TeX{} formats is unimportant, and scale up to separate
24919 theme files native to different \TeX{} formats for large multi-format themes,
24920 where different code is needed for different \TeX{} formats. To enable code
24921 reuse, developers can load the `.tex` theme file from the `t-*.tex` theme file
24922 using the \mref{markdownLoadPlainTeXTheme} macro.
24923
24924 For example, to load a theme named `witiko/tilde` in your document:
24925
24926 ``` tex
24927 \usemodule[t][markdown]
24928 \setupmarkdown[import=witiko/tilde]
24929 ```````
24930
24931 % We also define the prop \mdef{g_@@_context_built_in_themes_prop} that
24932 % contains the code of built-in themes. This is a packaging optimization,
24933 % so that built-in themes does not need to be distributed in many small files.
24934 %
24935 % \end{markdown}
24936 % \iffalse
24937 %</manual-options>
24938 %<*context>
24939 % \fi
24940 % \begin{macrocode}
24941 \prop_new:N
24942 \g_@@_context_built_in_themes_prop
24943 \ExplSyntaxOff
24944 % \end{macrocode}
24945 % \iffalse
24946 %</context>
24947 %<*manual-options>
24948 % \fi
24949 % \begin{markdown}
24950
24951 Built-in \Hologo{ConTeXt} themes provided with the Markdown package include:
24952
24953 \pkg{witiko/markdown/defaults}
24954
24955 : A \Hologo{ConTeXt} theme with the default definitions of token renderer
24956 prototypes for plain \TeX{}. This theme is loaded automatically together
24957 with the package and explicitly loading it has no effect.
24958
24959 % \end{markdown}
24960 % \iffalse
24961 %</manual-options>
24962 %<*themes-witiko-markdown-defaults-ctx>
24963 % \fi
24964 % \begin{macrocode}
24965 \startmodule[markdownthemewitiko_markdown_defaults]
24966 \unprotect
24967 % \end{macrocode}
24968 % \iffalse
24969 %</themes-witiko-markdown-defaults-ctx>
24970 %<*manual-options>
24971 % \fi
24972 % \begin{markdown}
24973 %
24974 % See Section <#sec:context-themes-implementation> for implementation details
24975 % of the built-in \Hologo{ConTeXt} themes.
24976 %
24977 % Implementation {#implementation}
24978 %================
24979 %
24980 % This part of the documentation describes the implementation of the interfaces
24981 % exposed by the package (see Section <#sec:interfaces>) and is aimed at the
24982 % developers of the package, as well as the curious users.
24983 %
24984 % Figure <#fig:block-diagram> shows the high-level structure of the Markdown
24985 % package: The translation from markdown to \TeX{} *token renderers* is
24986 % performed by the Lua layer. The plain \TeX{} layer provides default
24987 % definitions for the token renderers. The \LaTeX{} and \Hologo{ConTeXt} layers
24988 % correct idiosyncrasies of the respective \TeX{} formats, and provide
24989 % format-specific default definitions for the token renderers.
24990 %
24991 % \end{markdown}
24992 % \iffalse
24993 %</manual-options>
24994 %<*lua>
24995 % \fi
24996 % \begin{markdown}
24997 %
24998 % Lua Implementation {#luaimplementation}
24999 %--------------------
25000 %
25001 % The Lua implementation implements \luamdef{writer} and \luamref{reader}
25002 % objects, which provide the conversion from markdown to plain \TeX, and
25003 % \luamdef{extensions} objects, which provide syntax extensions for the
25004 % \luamref{writer} and \luamref{reader} objects.
25005 %
25006 % The Lunamark Lua module implements writers for the conversion to various
25007 % other formats, such as DocBook, Groff, or HTML. These were stripped
25008 % from the module and the remaining markdown reader and plain \TeX{} writer
25009 % were hidden behind the converter functions exposed by the Lua interface (see
25010 % Section <#sec:luainterface>).
25011 %
25012 % Furthermore, here are some abbreviations that we inherited from the Lunamark
25013 % library and which are used throughout the Lua implementation.
25014 %
25015 % \end{markdown}
25016 % \begin{macrocode}
25017 local upper, format, length =
25018 string.upper, string.format, string.len
25019 local P, R, S, V, C, Cg, Cb, Cmt, Cc, Ct, B, Cs, Cp, any =
25020 lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.C, lpeg.Cg, lpeg.Cb,
25021 lpeg.Cmt, lpeg.Cc, lpeg.Ct, lpeg.B, lpeg.Cs, lpeg.Cp, lpeg.P(1)
25022 % \end{macrocode}
25023 % \begin{markdown}
25024 %
25025 %### Unicode Support
25026 % To start off, we load a Lua file named `markdown-unicode-data.lua` that
25027 % contains our implementation of various Unicode algorithms.
25028 %
25029 % \end{markdown}
25030 % \begin{macrocode}
25031 local early_warnings = {}
25032 local unicode_data = require("markdown-unicode-data")
25033 if metadata.version ~= unicode_data.metadata.version then
25034 table.insert(
25035 early_warnings,
25036 "markdown.lua " .. metadata.version .. " used with " ..
25037 "markdown-unicode-data.lua " .. unicode_data.metadata.version .. "."
25038 )
25039 end
25040 % \end{macrocode}
25041 % \begin{markdown}
25042 %
25043 % In the following subsections, we'll write a second-order file named
25044 % `markdown-unicode-data-generator.lua`. The code from this file will be
25045 % executed during the compilation of the Markdown package and the standard
25046 % output will be stored in a generated file named `markdown-unicode-data.lua`.
25047 %
25048 % \end{markdown}
25049 % \iffalse
25050 %</lua>
25051 %<*lua,lua-unicode-data-generator>
25052 % \fi
25053 % \begin{markdown}
25054 %
25055 % First, let's define a couple helper functions.
25056 %
25057 % The function \luamdef{depth_first_search} performs the depth first search
25058 % algorithm on a tree with nodes being tables with the key `_type` equal to
25059 % either `intermediate` or `leaf` and with edges labeled with bytes.
25060 %
25061 % Since the algorithm is implemented using recursion, it should only be used
25062 % for the traversal of shallow trees to prevent exceeding the maximum recursion
25063 % depth (usually 100).
25064 %
25065 % \end{markdown}
25066 % \begin{macrocode}
25067 local function depth_first_search(node, path, visit, leave)
25068 assert(node._type == "intermediate")
25069 visit(node, path)
25070 for label, child in pairs(node) do
25071 if label == "_type" then
25072 goto continue
25073 end
25074 if child._type ~= "intermediate" then
25075 goto continue
25076 end
25077 depth_first_search(child, path .. label, visit, leave)
25078 ::continue::
25079 end
25080 for label, child in pairs(node) do
25081 if label == "_type" then
25082 goto continue
25083 end
25084 if child._type ~= "leaf" then
25085 goto continue
25086 end
25087 visit(child, path)
25088 ::continue::
25089 end
25090 leave(node, path)
25091 end
25092 % \end{macrocode}
25093 % \begin{markdown}
25094 %
25095 % This function is defined in the file `markdown-parser.lua` as well, so that
25096 % it can be used to define the \luamref{extensions.acronyms} built-in syntax
25097 % extension.
25098 %
25099 % \end{markdown}
25100 % \iffalse
25101 %</lua,lua-unicode-data-generator>
25102 %<*lua-unicode-data-generator>
25103 % \fi
25104 % \begin{markdown}
25105 %
25106 % The function \luamdef{serialize_byte_parser} produces the Lua code for a
25107 % PEG parser that matches a single byte.
25108 %
25109 % \end{markdown}
25110 % \begin{macrocode}
25111 local function serialize_byte_parser(byte)
25112 if byte == '"' then
25113 return "P('" .. byte .. "')"
25114 elseif byte == "\\" then
25115 return 'P("\\\\")'
25116 else
25117 return 'P("' .. byte .. '")'
25118 end
25119 end
25120 % \end{macrocode}
25121 % \begin{markdown}
25122 %
25123 % The function \luamdef{serialize_byte_range_parser} produces the Lua code for
25124 % a PEG parser that matches a contiguous range of bytes.
25125 %
25126 % \end{markdown}
25127 % \begin{macrocode}
25128 local function serialize_byte_range_parser(start_byte, end_byte)
25129 assert(start_byte <= end_byte)
25130 if start_byte == "\\" then
25131 start_byte = "\\\\"
25132 end
25133 if end_byte == "\\" then
25134 end_byte = "\\\\"
25135 end
25136 if start_byte == '"' or end_byte == '"' then
25137 return "R('" .. start_byte .. end_byte .. "')"
25138 else
25139 return 'R("' .. start_byte .. end_byte .. '")'
25140 end
25141 end
25142 % \end{macrocode}
25143 % \begin{markdown}
25144 %
25145 % The function \luamdef{serialize_replacement} produces the Lua code for a
25146 % string literal with one or more UTF-8-encoded Unicode characters.
25147 %
25148 % \end{markdown}
25149 % \begin{macrocode}
25150 local function serialize_replacement(codepoints)
25151 assert(#codepoints > 0)
25152 local buffer = {'"'}
25153 for _, codepoint in ipairs(codepoints) do
25154 local code = utf8.char(codepoint)
25155 for i = 1, #code do
25156 local byte = code:sub(i, i)
25157 if byte == '"' then
25158 table.insert(buffer, '\\\"')
25159 elseif byte == "\\" then
25160 table.insert(buffer, "\\\\")
25161 else
25162 table.insert(buffer, byte)
25163 end
25164 end
25165 end
25166 table.insert(buffer, '"')
25167 return table.concat(buffer)
25168 end
25169 % \end{macrocode}
25170 % \begin{markdown}
25171 %
25172 % The function \luamdef{read_decompositions} is an iterator that reads a file
25173 % `UnicodeData.txt` that has previously been opened for reading and yields
25174 % all canonical and compatibility decompositions from that file.
25175 %
25176 % \end{markdown}
25177 % \begin{macrocode}
25178 local function read_decompositions(file)
25179 return function()
25180 local from_codepoint, mapping
25181 for line in file:lines() do
25182 from_codepoint, mapping
25183 = line:match("^(%x+);[^;]*;%a*;%d+;%a*;([<%a>%x ]*)")
25184 assert(from_codepoint ~= nil)
25185 if #mapping > 0 then
25186 break
25187 end
25188 end
25189 if #mapping == 0 then
25190 return nil
25191 end
25192 from_codepoint = tonumber(from_codepoint, 16)
25193 local to_codepoints, decomposition_type = {}, "canonical"
25194 for raw_codepoint in mapping:gmatch("%S+") do
25195 assert(#raw_codepoint > 0)
25196 if raw_codepoint:sub(1, 1) == "<" then
25197 decomposition_type = "compatibility"
25198 else
25199 local codepoint = tonumber(raw_codepoint, 16)
25200 table.insert(to_codepoints, codepoint)
25201 end
25202 end
25203 assert(#to_codepoints > 0)
25204 return decomposition_type, from_codepoint, to_codepoints
25205 end
25206 end
25207 % \end{macrocode}
25208 % \begin{markdown}
25209 %
25210 % Next, let's define some aliases in the generated file.
25211 %
25212 % \end{markdown}
25213 % \begin{macrocode}
25214 print("local P, R, Cc, C = lpeg.P, lpeg.R, lpeg.Cc, lpeg.C")
25215 print("local fail = P(false)")
25216 print("-- luacheck: push no max line length")
25217 % \end{macrocode}
25218 % \begin{markdown}
25219 %
25220 %#### Canonical and Compatibility Decomposition {#unicode-decomposition}
25221 % Low-level parsers that decompose UTF-8-encoded Unicode characters using
25222 % either the canonical or the compatibility decomposition [@unicode24,
25223 % Section 3.7] are organized in table
25224 % \luamdef{unicode_data.decomposition_mapping} based on the number of bytes
25225 % they occupy after conversion to UTF-8.
25226 %
25227 % First, let's read the file `UnicodeData.txt`.
25228 %
25229 % \end{markdown}
25230 % \begin{macrocode}
25231 ;(function()
25232 local file = assert(io.open("UnicodeData.txt", "r"),
25233 [[Could not open file "UnicodeData.txt"]])
25234 % \end{macrocode}
25235 % \begin{markdown}
25236 %
25237 % In order to minimize the size and speed of the parser, we will first
25238 % construct prefix trees of UTF-8 encodings for all codepoints of a
25239 % given decomposition type and code length.
25240 %
25241 % \end{markdown}
25242 % \begin{macrocode}
25243 local decomposition_types = {"canonical", "compatibility"}
25244 local prefix_trees = {}
25245 for _, decomposition_type in ipairs(decomposition_types) do
25246 prefix_trees[decomposition_type] = {}
25247 for char_length = 1, 4 do
25248 prefix_trees[decomposition_type][char_length]
25249 = {_type = "intermediate"}
25250 end
25251 end
25252 for decomposition_type, from_codepoint, to_codepoints
25253 in read_decompositions(file) do
25254 local from_code = utf8.char(from_codepoint)
25255 local node = prefix_trees[decomposition_type][#from_code]
25256 for i = 1, #from_code do
25257 local from_byte = from_code:sub(i, i)
25258 if i < #from_code then
25259 if node[from_byte] == nil then
25260 node[from_byte] = {_type = "intermediate"}
25261 end
25262 node = node[from_byte]
25263 else
25264 table.insert(node, {from_byte, to_codepoints, _type = "leaf"})
25265 end
25266 end
25267 end
25268 assert(file:close())
25269 % \end{macrocode}
25270 % \begin{markdown}
25271 %
25272 % Next, we will construct parsers out of the prefix trees.
25273 %
25274 % \end{markdown}
25275 % \begin{macrocode}
25276 print("M.decomposition_mapping = {}")
25277 for _, decomposition_type in ipairs(decomposition_types) do
25278 print("M.decomposition_mapping." .. decomposition_type .. " = {}")
25279 for length, prefix_tree in pairs(prefix_trees[decomposition_type])
25280 do
25281 local subparsers = {}
25282 depth_first_search(prefix_tree, "", function(node, path)
25283 if node._type == "leaf" then
25284 local from_byte, to_codepoints = table.unpack(node)
25285 local suffix = serialize_byte_parser(from_byte)
25286 .. " / " .. serialize_replacement(to_codepoints)
25287 if subparsers[path] ~= nil then
25288 subparsers[path] = subparsers[path] .. " + " .. suffix
25289 else
25290 subparsers[path] = suffix
25291 end
25292 end
25293 end, function(_, path)
25294 if #path > 0 then
25295 local byte = path:sub(#path, #path)
25296 local parent_path = path:sub(1, #path-1)
25297 local prefix = serialize_byte_parser(byte)
25298 local suffix
25299 if subparsers[path]:find(" %+ ") then
25300 suffix = prefix .. " * (" .. subparsers[path] .. ")"
25301 else
25302 suffix = prefix .. " * " .. subparsers[path]
25303 end
25304 if subparsers[parent_path] ~= nil then
25305 subparsers[parent_path] = subparsers[parent_path]
25306 .. " + " .. suffix
25307 else
25308 subparsers[parent_path] = suffix
25309 end
25310 else
25311 print(
25312 "M.decomposition_mapping." .. decomposition_type
25313 .. "[" .. length .. "] = " .. (subparsers[path] or "fail")
25314 )
25315 end
25316 end)
25317 end
25318 end
25319 end)()
25320 % \end{macrocode}
25321 % \begin{markdown}
25322 %
25323 %#### Hangul Syllable Decomposition {#unicode-hangul-decomposition}
25324 % Low-level parsers that decompose UTF-8-encoded Unicode characters using
25325 % the Hangul syllable decomposition [@unicode24, Section 3.12.2] are also
25326 % organized in table \luamref{unicode_data.decomposition_mapping}, previously
25327 % defined in Section <#sec:unicode-decomposition> based on the
25328 % number of bytes they occupy after conversion to UTF-8.
25329 %
25330 % First, let's read the file `HangulSyllableType.txt`.
25331 %
25332 % \end{markdown}
25333 % \begin{macrocode}
25334 ;(function()
25335 local file = assert(io.open("HangulSyllableType.txt", "r"),
25336 [[Could not open file "HangulSyllableType.txt"]])
25337 % \end{macrocode}
25338 % \begin{markdown}
25339 %
25340 % In order to minimize the size and speed of the parser, we will first
25341 % construct prefix trees of UTF-8 encodings for all codepoints of a
25342 % given syllable type and code length.
25343 %
25344 % \end{markdown}
25345 % \begin{macrocode}
25346 local syllable_types = {"LV", "LVT"}
25347 local prefix_trees = {}
25348 for _, syllable_type in ipairs(syllable_types) do
25349 prefix_trees[syllable_type] = {}
25350 for char_length = 1, 4 do
25351 prefix_trees[syllable_type][char_length]
25352 = {_type = "intermediate"}
25353 end
25354 end
25355 for line in file:lines() do
25356 if #line == 0 or line:sub(1, 1) == "#" then
25357 goto continue
25358 end
25359 local codepoint, syllable_type = line:match("^([%x.]+)%s*;%s*(%a*)")
25360 assert(codepoint ~= nil)
25361 if prefix_trees[syllable_type] == nil then
25362 goto continue
25363 end
25364 local codepoint_start, codepoint_end
25365 if codepoint:find("%.%.") then
25366 codepoint_start, codepoint_end
25367 = codepoint:match("^(%x+)%.%.(%x+)$")
25368 else
25369 codepoint_start, codepoint_end = codepoint, codepoint
25370 end
25371 codepoint_start = tonumber(codepoint_start, 16)
25372 codepoint_end = tonumber(codepoint_end, 16)
25373 local prev_code, prev_leaf_node
25374 for codepoint = codepoint_start, codepoint_end do
25375 local code = utf8.char(codepoint)
25376 local node = prefix_trees[syllable_type][#code]
25377 for i = 1, #code do
25378 local byte = code:sub(i, i)
25379 if i < #code then
25380 if node[byte] == nil then
25381 node[byte] = {_type = "intermediate"}
25382 end
25383 node = node[byte]
25384 else
25385 local leaf_node
25386 if (
25387 prev_code ~= nil
25388 and #prev_code == #code
25389 and code:sub(1, #code - 1)
25390 == prev_code:sub(1, #code - 1)
25391 ) then
25392 assert(prev_leaf_node ~= nil)
25393 leaf_node = prev_leaf_node
25394 leaf_node[2] = byte
25395 else
25396 leaf_node = {byte, byte, _type = "leaf"}
25397 table.insert(node, leaf_node)
25398 end
25399 prev_code, prev_leaf_node = code, leaf_node
25400 end
25401 end
25402 end
25403 ::continue::
25404 end
25405 assert(file:close())
25406 % \end{macrocode}
25407 % \begin{markdown}
25408 %
25409 % Next, we will define constants and functions with the Hangul syllable
25410 % (de)composition algorithm.
25411 %
25412 % \end{markdown}
25413 % \begin{macrocode}
25414 print(string.format("local s_base = %d", tonumber("AC00", 16)))
25415 print(string.format("local l_base = %d", tonumber("1100", 16)))
25416 print(string.format("local v_base = %d", tonumber("1161", 16)))
25417 print(string.format("local t_base = %d", tonumber("11A7", 16)))
25418 print(string.format("local l_count = %d", 19))
25419 print(string.format("local v_count = %d", 21))
25420 print(string.format("local t_count = %d", 28))
25421 print("local n_count = v_count * t_count")
25422 print("local s_count = l_count * n_count")
25423
25424 print("local function hangul_decompose_LV(byte)")
25425 print(" local s = utf8.codepoint(byte)")
25426 print(" local s_index = s - s_base")
25427 print(" local l_index = s_index // n_count")
25428 print(" local v_index = (s_index % n_count) // t_count")
25429 print(" local l_part = l_base + l_index")
25430 print(" local v_part = v_base + v_index")
25431 print(" return utf8.char(l_part) .. utf8.char(v_part)")
25432 print("end")
25433
25434 print("local function hangul_decompose_LVT(byte)")
25435 print(" local s = utf8.codepoint(byte)")
25436 print(" local s_index = s - s_base")
25437 print(" local lv_index = (s_index // t_count) * t_count")
25438 print(" local t_index = s_index % t_count")
25439 print(" local lv_part = s_base + lv_index")
25440 print(" local t_part = t_base + t_index")
25441 print(" return utf8.char(lv_part) .. utf8.char(t_part)")
25442 print("end")
25443
25444 print("function M.hangul_compose(first_byte, second_byte)")
25445 print(" local last = utf8.codepoint(first_byte)")
25446 print(" local ch = utf8.codepoint(second_byte)")
25447 print(" local l_index = last - l_base")
25448 print(" if 0 <= l_index and l_index < l_count then")
25449 print(" local v_index = ch - v_base")
25450 print(" if 0 <= v_index and v_index < v_count then")
25451 print(" return utf8.char(")
25452 print(" s_base + (l_index * v_count + v_index) * t_count")
25453 print(" )")
25454 print(" end")
25455 print(" end")
25456 print(" local s_index = last - s_base")
25457 print(" if 0 <= s_index and s_index < s_count")
25458 print(" and s_index % t_count == 0 then")
25459 print(" local t_index = ch - t_base")
25460 print(" if 0 < t_index and t_index < t_count then")
25461 print(" return utf8.char(last + t_index)")
25462 print(" end")
25463 print(" end")
25464 print(" return nil")
25465 print("end")
25466 % \end{macrocode}
25467 % \begin{markdown}
25468 %
25469 % Next, we will construct parsers out of the prefix trees.
25470 %
25471 % \end{markdown}
25472 % \begin{macrocode}
25473 print("M.decomposition_mapping.hangul = {}")
25474 for _, syllable_type in ipairs(syllable_types) do
25475 print("M.decomposition_mapping.hangul." .. syllable_type .. " = {}")
25476 for length, prefix_tree in pairs(prefix_trees[syllable_type]) do
25477 local subparsers = {}
25478 depth_first_search(prefix_tree, "", function(node, path)
25479 if node._type == "leaf" then
25480 local start_byte, end_byte = table.unpack(node)
25481 local suffix
25482 if start_byte == end_byte then
25483 suffix = serialize_byte_parser(start_byte)
25484 else
25485 assert(start_byte < end_byte)
25486 suffix = serialize_byte_range_parser(start_byte, end_byte)
25487 end
25488 if subparsers[path] ~= nil then
25489 subparsers[path] = subparsers[path] .. " + " .. suffix
25490 else
25491 subparsers[path] = suffix
25492 end
25493 end
25494 end, function(_, path)
25495 if #path > 0 then
25496 local byte = path:sub(#path, #path)
25497 local parent_path = path:sub(1, #path-1)
25498 local prefix = serialize_byte_parser(byte)
25499 local suffix
25500 if subparsers[path]:find(" %+ ") then
25501 suffix = prefix .. " * (" .. subparsers[path] .. ")"
25502 else
25503 suffix = prefix .. " * " .. subparsers[path]
25504 end
25505 if subparsers[parent_path] ~= nil then
25506 subparsers[parent_path] = subparsers[parent_path]
25507 .. " + " .. suffix
25508 else
25509 subparsers[parent_path] = suffix
25510 end
25511 else
25512 if subparsers[path] then
25513 print(
25514 "M.decomposition_mapping.hangul." .. syllable_type
25515 .. "[" .. length .. "] = C(" .. subparsers[path] .. ")"
25516 .. " / hangul_decompose_" .. syllable_type
25517 )
25518 else
25519 print(
25520 "M.decomposition_mapping.hangul." .. syllable_type
25521 .. "[" .. length .. "] = fail"
25522 )
25523 end
25524 end
25525 end)
25526 end
25527 end
25528 end)()
25529 % \end{macrocode}
25530 % \begin{markdown}
25531 %
25532 %#### Canonical Composition {#unicode-canonical-composition}
25533 % Low-level parsers that map pairs of UTF-8-encoded Unicode characters from
25534 % a canonical or compatibility decomposition into their primary composites
25535 % [@unicode24, Section 3.11.6] are organized in table
25536 % \luamdef{unicode_data.composition_mapping} based on the number of bytes the
25537 % characters occupy after conversion to UTF-8.
25538 %
25539 % First, let's read the file `DerivedNormalizationProps.txt` and record all
25540 % canonical decomposable characters that are not full composition exclusions.
25541 %
25542 % \end{markdown}
25543 % \begin{macrocode}
25544 ;(function()
25545 local file = assert(io.open("DerivedNormalizationProps.txt", "r"),
25546 [[Could not open file "DerivedNormalizationProps.txt"]])
25547 local full_composition_exclusions = {}
25548 for line in file:lines() do
25549 if #line == 0 or line:sub(1, 1) == "#" then
25550 goto continue
25551 end
25552 local codepoint, property = line:match("^([%x.]+)%s*;%s*([%a_]+)")
25553 assert(codepoint ~= nil)
25554 if property ~= "Full_Composition_Exclusion" then
25555 goto continue
25556 end
25557 local codepoint_start, codepoint_end
25558 if codepoint:find("%.%.") then
25559 codepoint_start, codepoint_end
25560 = codepoint:match("^(%x+)%.%.(%x+)$")
25561 else
25562 codepoint_start, codepoint_end = codepoint, codepoint
25563 end
25564 codepoint_start = tonumber(codepoint_start, 16)
25565 codepoint_end = tonumber(codepoint_end, 16)
25566 for codepoint = codepoint_start, codepoint_end do
25567 full_composition_exclusions[codepoint] = true
25568 end
25569 ::continue::
25570 end
25571 assert(file:close())
25572 % \end{macrocode}
25573 % \begin{markdown}
25574 %
25575 % Next, let's also read the file `UnicodeData.txt`.
25576 %
25577 % \end{markdown}
25578 % \begin{macrocode}
25579 file = assert(io.open("UnicodeData.txt", "r"),
25580 [[Could not open file "UnicodeData.txt"]])
25581 % \end{macrocode}
25582 % \begin{markdown}
25583 %
25584 % In order to minimize the size and speed of the parser, we will first
25585 % construct prefix trees of UTF-8 encodings for all pairs of codepoints
25586 % of given code lengths.
25587 %
25588 % \end{markdown}
25589 % \begin{macrocode}
25590 local prefix_trees = {starters = {}, both = {}}
25591 for first_char_length = 1, 4 do
25592 prefix_trees.starters[first_char_length]
25593 = {_type = "intermediate"}
25594 prefix_trees.both[first_char_length] = {}
25595 for second_char_length = 1, 4 do
25596 prefix_trees.both[first_char_length][second_char_length]
25597 = {_type = "intermediate"}
25598 end
25599 end
25600 local seen_starter_codes = {}
25601 for decomposition_type, to_codepoint, from_codepoints
25602 in read_decompositions(file) do
25603 if (
25604 decomposition_type ~= "canonical"
25605 or #from_codepoints ~= 2
25606 or full_composition_exclusions[to_codepoint]
25607 ) then
25608 goto continue
25609 end
25610 local starter_code = utf8.char(from_codepoints[1])
25611 local combining_character_code = utf8.char(from_codepoints[2])
25612 local starter_node = prefix_trees.starters[#starter_code]
25613 local both_node
25614 = prefix_trees.both[#starter_code][#combining_character_code]
25615 for i = 1, #starter_code do
25616 local from_byte = starter_code:sub(i, i)
25617 if both_node[from_byte] == nil then
25618 both_node[from_byte] = {_type = "intermediate"}
25619 end
25620 both_node = both_node[from_byte]
25621 if i < #starter_code then
25622 if starter_node[from_byte] == nil then
25623 starter_node[from_byte] = {_type = "intermediate"}
25624 end
25625 starter_node = starter_node[from_byte]
25626 elseif seen_starter_codes[starter_code] == nil then
25627 seen_starter_codes[starter_code] = true
25628 table.insert(starter_node, {from_byte, _type = "leaf"})
25629 end
25630 end
25631 for i = 1, #combining_character_code do
25632 local from_byte = combining_character_code:sub(i, i)
25633 if i < #combining_character_code then
25634 if both_node[from_byte] == nil then
25635 both_node[from_byte] = {_type = "intermediate"}
25636 end
25637 both_node = both_node[from_byte]
25638 else
25639 table.insert(
25640 both_node,
25641 {from_byte, to_codepoint, _type = "leaf"}
25642 )
25643 end
25644 end
25645 ::continue::
25646 end
25647 assert(file:close())
25648 % \end{macrocode}
25649 % \begin{markdown}
25650 %
25651 % Next, we will construct parsers out of the prefix trees.
25652 %
25653 % \end{markdown}
25654 % \begin{macrocode}
25655 print("M.composition_mapping = {starters = {}, both = {}}")
25656 for first_char_length = 1, 4 do
25657 local prefix_tree = prefix_trees.starters[first_char_length]
25658 local subparsers = {}
25659 depth_first_search(prefix_tree, "", function(node, path)
25660 if node._type == "leaf" then
25661 local from_byte = table.unpack(node)
25662 local suffix = serialize_byte_parser(from_byte)
25663 if subparsers[path] ~= nil then
25664 subparsers[path] = subparsers[path] .. " + " .. suffix
25665 else
25666 subparsers[path] = suffix
25667 end
25668 end
25669 end, function(_, path)
25670 if #path > 0 then
25671 local byte = path:sub(#path, #path)
25672 local parent_path = path:sub(1, #path-1)
25673 local prefix = serialize_byte_parser(byte)
25674 local suffix
25675 if subparsers[path]:find(" %+ ") then
25676 suffix = prefix .. " * (" .. subparsers[path] .. ")"
25677 else
25678 suffix = prefix .. " * " .. subparsers[path]
25679 end
25680 if subparsers[parent_path] ~= nil then
25681 subparsers[parent_path] = subparsers[parent_path]
25682 .. " + " .. suffix
25683 else
25684 subparsers[parent_path] = suffix
25685 end
25686 else
25687 print(
25688 "M.composition_mapping.starters["
25689 .. first_char_length .. "] = " .. (subparsers[path] or "fail")
25690 )
25691 end
25692 end)
25693 print(
25694 string.format(
25695 "M.composition_mapping.both[%d] = {}",
25696 first_char_length
25697 )
25698 )
25699 for second_char_length = 1, 4 do
25700 prefix_tree
25701 = prefix_trees.both[first_char_length][second_char_length]
25702 subparsers = {}
25703 depth_first_search(prefix_tree, "", function(node, path)
25704 if node._type == "leaf" then
25705 local from_byte, to_codepoint = table.unpack(node)
25706 local suffix = serialize_byte_parser(from_byte)
25707 .. " / " .. serialize_replacement({to_codepoint})
25708 if subparsers[path] ~= nil then
25709 subparsers[path] = subparsers[path] .. " + " .. suffix
25710 else
25711 subparsers[path] = suffix
25712 end
25713 end
25714 end, function(_, path)
25715 if #path > 0 then
25716 local byte = path:sub(#path, #path)
25717 local parent_path = path:sub(1, #path-1)
25718 local prefix = serialize_byte_parser(byte)
25719 local suffix
25720 if subparsers[path]:find(" %+ ") then
25721 suffix = prefix .. " * (" .. subparsers[path] .. ")"
25722 else
25723 suffix = prefix .. " * " .. subparsers[path]
25724 end
25725 if subparsers[parent_path] ~= nil then
25726 subparsers[parent_path] = subparsers[parent_path]
25727 .. " + " .. suffix
25728 else
25729 subparsers[parent_path] = suffix
25730 end
25731 else
25732 print(
25733 "M.composition_mapping.both[" .. first_char_length .. "]["
25734 .. second_char_length .. "] = "
25735 .. (subparsers[path] or "fail")
25736 )
25737 end
25738 end)
25739 end
25740 end
25741 end)()
25742 % \end{macrocode}
25743 % \begin{markdown}
25744 %
25745 %#### Case Folding {#unicode-case-folding}
25746 % Low-level parsers that case-fold UTF-8-encoded Unicode characters using the
25747 % full mapping (C and F) [@unicode24, Section 3.13.3] are organized in table
25748 % \luamdef{unicode_data.casefold_mapping} based on the number of bytes they
25749 % occupy after conversion to UTF-8.
25750 %
25751 % First, let's read the file `CaseFolding.txt`.
25752 %
25753 % \end{markdown}
25754 % \begin{macrocode}
25755 ;(function()
25756 local file = assert(io.open("CaseFolding.txt", "r"),
25757 [[Could not open file "CaseFolding.txt"]])
25758 % \end{macrocode}
25759 % \begin{markdown}
25760 %
25761 % In order to minimize the size and speed of the parser, we will first
25762 % construct prefix trees of UTF-8 encodings for all codepoints of a
25763 % given code length.
25764 %
25765 % \end{markdown}
25766 % \begin{macrocode}
25767 local prefix_trees = {}
25768 for char_length = 1, 4 do
25769 prefix_trees[char_length] = {_type = "intermediate"}
25770 end
25771 for line in file:lines() do
25772 if #line == 0 or line:sub(1, 1) == "#" then
25773 goto continue
25774 end
25775 local raw_from_codepoint, status, raw_to_codepoints
25776 = line:match("^(%x+); ([CFST]); ([%x ]+);")
25777 assert(raw_from_codepoint ~= nil)
25778 assert(status ~= nil)
25779 assert(raw_to_codepoints ~= nil)
25780 if status ~= "C" and status ~= "F" then
25781 goto continue
25782 end
25783 local from_codepoint = tonumber(raw_from_codepoint, 16)
25784 local to_codepoints = {}
25785 for raw_codepoint in raw_to_codepoints:gmatch('%x+') do
25786 local codepoint = tonumber(raw_codepoint, 16)
25787 table.insert(to_codepoints, codepoint)
25788 end
25789 local from_code = utf8.char(from_codepoint)
25790 local node = prefix_trees[#from_code]
25791 for i = 1, #from_code do
25792 local from_byte = from_code:sub(i, i)
25793 if i < #from_code then
25794 if node[from_byte] == nil then
25795 node[from_byte] = {_type = "intermediate"}
25796 end
25797 node = node[from_byte]
25798 else
25799 table.insert(node, {from_byte, to_codepoints, _type = "leaf"})
25800 end
25801 end
25802 ::continue::
25803 end
25804 assert(file:close())
25805 % \end{macrocode}
25806 % \begin{markdown}
25807 %
25808 % Next, we will construct parsers out of the prefix trees.
25809 %
25810 % \end{markdown}
25811 % \begin{macrocode}
25812 print("M.casefold_mapping = {}")
25813 for length, prefix_tree in pairs(prefix_trees) do
25814 local subparsers = {}
25815 depth_first_search(prefix_tree, "", function(node, path)
25816 if node._type == "leaf" then
25817 local from_byte, to_codepoints = table.unpack(node)
25818 local suffix = serialize_byte_parser(from_byte)
25819 .. " / " .. serialize_replacement(to_codepoints)
25820 if subparsers[path] ~= nil then
25821 subparsers[path] = subparsers[path] .. " + " .. suffix
25822 else
25823 subparsers[path] = suffix
25824 end
25825 end
25826 end, function(_, path)
25827 if #path > 0 then
25828 local byte = path:sub(#path, #path)
25829 local parent_path = path:sub(1, #path-1)
25830 local prefix = serialize_byte_parser(byte)
25831 local suffix
25832 if subparsers[path]:find(" %+ ") then
25833 suffix = prefix .. " * (" .. subparsers[path] .. ")"
25834 else
25835 suffix = prefix .. " * " .. subparsers[path]
25836 end
25837 if subparsers[parent_path] ~= nil then
25838 subparsers[parent_path] = subparsers[parent_path]
25839 .. " + " .. suffix
25840 else
25841 subparsers[parent_path] = suffix
25842 end
25843 else
25844 print(
25845 "M.casefold_mapping[" .. length .. "] = "
25846 .. (subparsers[path] or "fail")
25847 )
25848 end
25849 end)
25850 end
25851 end)()
25852 % \end{macrocode}
25853 % \begin{markdown}
25854 %
25855 %#### Character Categories {#unicode-character-classes-and-categories}
25856 % Low-level parsers of UTF-8-encoded Unicode characters from different
25857 % general categories [@unicode24, Section 4.5] are organized in table
25858 % \luamdef{unicode_data.categories} based on the number of bytes they occupy
25859 % after conversion to UTF-8.
25860 %
25861 % First, let's read the file `UnicodeData.txt`.
25862 %
25863 % \end{markdown}
25864 % \begin{macrocode}
25865 ;(function()
25866 local file = assert(io.open("UnicodeData.txt", "r"),
25867 [[Could not open file "UnicodeData.txt"]])
25868 % \end{macrocode}
25869 % \begin{markdown}
25870 %
25871 % In order to minimize the size and speed of the parser, we will first
25872 % construct prefix trees of UTF-8 encodings for all codepoints of a
25873 % given Unicode category and code length.
25874 %
25875 % \end{markdown}
25876 % \begin{macrocode}
25877 local categories = {"L", "N", "P", "Pc", "S", "Z"}
25878 local prefix_trees = {}
25879 for _, category in ipairs(categories) do
25880 prefix_trees[category] = {}
25881 for char_length = 1, 4 do
25882 prefix_trees[category][char_length] = {_type = "intermediate"}
25883 end
25884 end
25885 for line in file:lines() do
25886 local codepoint, full_category = line:match("^(%x+);[^;]*;(%a*)")
25887 assert(#full_category >= 1)
25888 local major_category = full_category:sub(1, 1)
25889 for _, category in ipairs({full_category, major_category}) do
25890 if prefix_trees[category] == nil then
25891 goto continue
25892 end
25893 local code = utf8.char(tonumber(codepoint, 16))
25894 local node = prefix_trees[category][#code]
25895 for i = 1, #code do
25896 local byte = code:sub(i, i)
25897 if i < #code then
25898 if node[byte] == nil then
25899 node[byte] = {_type = "intermediate"}
25900 end
25901 node = node[byte]
25902 else
25903 table.insert(node, {byte, _type = "leaf"})
25904 end
25905 end
25906 ::continue::
25907 end
25908 end
25909 assert(file:close())
25910 % \end{macrocode}
25911 % \begin{markdown}
25912 %
25913 % Next, we will construct parsers out of the prefix trees.
25914 %
25915 % \end{markdown}
25916 % \begin{macrocode}
25917 print("M.categories = {}")
25918 for _, category in ipairs(categories) do
25919 print("M.categories." .. category .. " = {}")
25920 for length, prefix_tree in pairs(prefix_trees[category]) do
25921 local subparsers = {}
25922 depth_first_search(prefix_tree, "", function(node, path)
25923 if node._type == "leaf" then
25924 local byte = node[1]
25925 local suffix = serialize_byte_parser(byte)
25926 if subparsers[path] ~= nil then
25927 subparsers[path] = subparsers[path] .. " + " .. suffix
25928 else
25929 subparsers[path] = suffix
25930 end
25931 end
25932 end, function(_, path)
25933 if #path > 0 then
25934 local byte = path:sub(#path, #path)
25935 local parent_path = path:sub(1, #path-1)
25936 local prefix = serialize_byte_parser(byte)
25937 local suffix
25938 if subparsers[path]:find(" %+ ") then
25939 suffix = prefix .. " * (" .. subparsers[path] .. ")"
25940 else
25941 suffix = prefix .. " * " .. subparsers[path]
25942 end
25943 if subparsers[parent_path] ~= nil then
25944 subparsers[parent_path] = subparsers[parent_path]
25945 .. " + " .. suffix
25946 else
25947 subparsers[parent_path] = suffix
25948 end
25949 else
25950 print(
25951 "M.categories." .. category .. "[" .. length .. "] = "
25952 .. (subparsers[path] or "fail")
25953 )
25954 end
25955 end)
25956 end
25957 end
25958 end)()
25959 % \end{macrocode}
25960 % \begin{markdown}
25961 %
25962 %#### Canonical Ordering Classes {#unicode-canonical-ordering-classes}
25963 % Low-level parsers of UTF-8-encoded Unicode characters from different
25964 % character classes [@unicode24, Section 3.11] are organized in table
25965 % \luamdef{unicode_data.ccc} based on the number of bytes they occupy
25966 % after conversion to UTF-8.
25967 %
25968 % First, let's read the file `UnicodeData.txt`.
25969 %
25970 % \end{markdown}
25971 % \begin{macrocode}
25972 ;(function()
25973 local file = assert(io.open("UnicodeData.txt", "r"),
25974 [[Could not open file "UnicodeData.txt"]])
25975 % \end{macrocode}
25976 % \begin{markdown}
25977 %
25978 % In order to minimize the size and speed of the parser, we will first
25979 % construct prefix trees of UTF-8 encodings for all codepoints of a
25980 % given Unicode combining class and code length.
25981 %
25982 % \end{markdown}
25983 % \begin{macrocode}
25984 local prefix_trees = {}
25985 for char_length = 1, 4 do
25986 prefix_trees[char_length] = {_type = "intermediate"}
25987 end
25988 for line in file:lines() do
25989 local codepoint, combining_class
25990 = line:match("^(%x+);[^;]*;%a*;(%d+)")
25991 combining_class = tonumber(combining_class)
25992 if combining_class == 0 then
25993 goto continue
25994 end
25995 local code = utf8.char(tonumber(codepoint, 16))
25996 local node = prefix_trees[#code]
25997 for i = 1, #code do
25998 local byte = code:sub(i, i)
25999 if i < #code then
26000 if node[byte] == nil then
26001 node[byte] = {_type = "intermediate"}
26002 end
26003 node = node[byte]
26004 else
26005 table.insert(node, {byte, combining_class, _type = "leaf"})
26006 end
26007 end
26008 ::continue::
26009 end
26010 assert(file:close())
26011 % \end{macrocode}
26012 % \begin{markdown}
26013 %
26014 % Next, we will construct parsers out of the prefix trees.
26015 %
26016 % \end{markdown}
26017 % \begin{macrocode}
26018 print("M.ccc = {}")
26019 for length, prefix_tree in pairs(prefix_trees) do
26020 local subparsers = {}
26021 depth_first_search(prefix_tree, "", function(node, path)
26022 if node._type == "leaf" then
26023 local byte, combining_class = table.unpack(node)
26024 local suffix = serialize_byte_parser(byte)
26025 .. " * Cc(" .. tostring(combining_class) .. ")"
26026 if subparsers[path] ~= nil then
26027 subparsers[path] = subparsers[path] .. " + " .. suffix
26028 else
26029 subparsers[path] = suffix
26030 end
26031 end
26032 end, function(_, path)
26033 if #path > 0 then
26034 local byte = path:sub(#path, #path)
26035 local parent_path = path:sub(1, #path-1)
26036 local prefix = serialize_byte_parser(byte)
26037 local suffix
26038 if subparsers[path]:find(" %+ ") then
26039 suffix = prefix .. " * (" .. subparsers[path] .. ")"
26040 else
26041 suffix = prefix .. " * " .. subparsers[path]
26042 end
26043 if subparsers[parent_path] ~= nil then
26044 subparsers[parent_path] = subparsers[parent_path]
26045 .. " + " .. suffix
26046 else
26047 subparsers[parent_path] = suffix
26048 end
26049 else
26050 print(
26051 "M.ccc[" .. length .. "] = " .. (subparsers[path] or "fail")
26052 )
26053 end
26054 end)
26055 end
26056 end)()
26057 print("-- luacheck: pop")
26058 print("return M")
26059 % \end{macrocode}
26060 % \iffalse
26061 %</lua-unicode-data-generator>
26062 %<*lua>
26063 % \fi
26064 % \begin{markdown}
26065 %
26066 %### Utility Functions
26067 % This section documents the utility functions back in the file
26068 % `markdown-parser.lua` used by the plain \TeX{} writer and the markdown
26069 % reader. These functions are encapsulated in the `util` object. The functions
26070 % were originally located in the `lunamark/util.lua` file in the Lunamark Lua
26071 % module.
26072 %
26073 % \end{markdown}
26074 % \iffalse
26075 %</lua>
26076 %<*lua,lua-loader>
26077 % \fi
26078 % \begin{macrocode}
26079 local util = {}
26080 % \end{macrocode}
26081 % \iffalse
26082 %</lua,lua-loader>
26083 %<*lua>
26084 % \fi
26085 % \begin{markdown}
26086 %
26087 % The \luamdef{util.err} method prints an error message `msg` and exits.
26088 % If `exit_code` is provided, it specifies the exit code. Otherwise, the
26089 % exit code will be 1.
26090 %
26091 % \end{markdown}
26092 % \begin{macrocode}
26093 function util.err(msg, exit_code)
26094 io.stderr:write("markdown.lua: " .. msg .. "\n")
26095 os.exit(exit_code or 1)
26096 end
26097 % \end{macrocode}
26098 % \iffalse
26099 %</lua>
26100 %<*lua,lua-loader>
26101 % \fi
26102 % \begin{markdown}
26103 %
26104 % The \luamdef{util.cache} method used `dir`, `string`, `salt`, and `suffix`
26105 % to determine a pathname. If a file with such a pathname does not exists,
26106 % it gets created with `transform(string)` as its content and the result of
26107 % `transform(string)` is returned as the second return value in case it's
26108 % useful to the caller. Regardless, the pathname is always returned as the
26109 % first return value.
26110 %
26111 % \end{markdown}
26112 % \begin{macrocode}
26113 function util.cache(dir, string, salt, transform, suffix)
26114 local digest = md5.sumhexa(string .. (salt or ""))
26115 local name = util.pathname(dir, digest .. suffix)
26116 local file = io.open(name, "r")
26117 local result = nil
26118 if file == nil then -- If no cache entry exists, create a new one.
26119 file = assert(io.open(name, "w"),
26120 [[Could not open file "]] .. name .. [[" for writing]])
26121 result = string
26122 if transform ~= nil then
26123 result = transform(result)
26124 end
26125 assert(file:write(result))
26126 assert(file:close())
26127 end
26128 return name, result
26129 end
26130 % \end{macrocode}
26131 % \iffalse
26132 %</lua,lua-loader>
26133 %<*lua>
26134 % \fi
26135 % \begin{markdown}
26136 %
26137 % The \luamdef{util.cache_verbatim} method strips whitespaces from the
26138 % end of `string` and calls \luamref{util.cache} with `dir`, `string`,
26139 % no salt or transformations, and the `.verbatim` suffix.
26140 %
26141 % \end{markdown}
26142 % \begin{macrocode}
26143 function util.cache_verbatim(dir, string)
26144 local name = util.cache(dir, string, nil, nil, ".verbatim")
26145 return name
26146 end
26147 % \end{macrocode}
26148 % \begin{markdown}
26149 %
26150 % The \luamdef{util.table_copy} method creates a shallow copy of a table `t`
26151 % and its metatable.
26152 %
26153 % \end{markdown}
26154 % \begin{macrocode}
26155 function util.table_copy(t)
26156 local u = { }
26157 for k, v in pairs(t) do u[k] = v end
26158 return setmetatable(u, getmetatable(t))
26159 end
26160 % \end{macrocode}
26161 % \begin{markdown}
26162 %
26163 % The \luamdef{util.encode_json_string} method encodes a string `s` in
26164 % JSON.
26165 %
26166 % \end{markdown}
26167 % \begin{macrocode}
26168 function util.encode_json_string(s)
26169 s = s:gsub([[\]], [[\\]])
26170 s = s:gsub([["]], [[\"]])
26171 return [["]] .. s .. [["]]
26172 end
26173 % \end{macrocode}
26174 % \begin{markdown}
26175 %
26176 % The \luamdef{util.expand_tabs_in_line} expands tabs in string `s`. If
26177 % `tabstop` is specified, it is used as the tab stop width. Otherwise,
26178 % the tab stop width of 4 characters is used. The method is a copy of the tab
26179 % expansion algorithm from @ierusalimschy13 [Chapter 21].
26180 %
26181 % \end{markdown}
26182 % \begin{macrocode}
26183 function util.expand_tabs_in_line(s, tabstop)
26184 local tab = tabstop or 4
26185 local corr = 0
26186 return (s:gsub("()\t", function(p)
26187 local sp = tab - (p - 1 + corr) % tab
26188 corr = corr - 1 + sp
26189 return string.rep(" ", sp)
26190 end))
26191 end
26192 % \end{macrocode}
26193 % \begin{markdown}
26194 %
26195 % The \luamdef{util.walk} method walks a rope `t`, applying a function `f`
26196 % to each leaf element in order. A rope is an array whose elements may be
26197 % ropes, strings, numbers, or functions. If a leaf element is a function, call
26198 % it and get the return value before proceeding.
26199 %
26200 % \end{markdown}
26201 % \begin{macrocode}
26202 function util.walk(t, f)
26203 local typ = type(t)
26204 if typ == "string" then
26205 f(t)
26206 elseif typ == "table" then
26207 local i = 1
26208 local n
26209 n = t[i]
26210 while n do
26211 util.walk(n, f)
26212 i = i + 1
26213 n = t[i]
26214 end
26215 elseif typ == "function" then
26216 local ok, val = pcall(t)
26217 if ok then
26218 util.walk(val,f)
26219 end
26220 else
26221 f(tostring(t))
26222 end
26223 end
26224 % \end{macrocode}
26225 % \begin{markdown}
26226 %
26227 % The \luamdef{util.flatten} method flattens an array `ary` that does not
26228 % contain cycles and returns the result.
26229 %
26230 % \end{markdown}
26231 % \begin{macrocode}
26232 function util.flatten(ary)
26233 local new = {}
26234 for _,v in ipairs(ary) do
26235 if type(v) == "table" then
26236 for _,w in ipairs(util.flatten(v)) do
26237 new[#new + 1] = w
26238 end
26239 else
26240 new[#new + 1] = v
26241 end
26242 end
26243 return new
26244 end
26245 % \end{macrocode}
26246 % \begin{markdown}
26247 %
26248 % The \luamdef{util.rope_to_string} method converts a rope `rope` to a
26249 % string and returns it. For the definition of a rope, see the definition of
26250 % the \luamref{util.walk} method.
26251 %
26252 % \end{markdown}
26253 % \begin{macrocode}
26254 function util.rope_to_string(rope)
26255 local buffer = {}
26256 util.walk(rope, function(x) buffer[#buffer + 1] = x end)
26257 return table.concat(buffer)
26258 end
26259 % \end{macrocode}
26260 % \begin{markdown}
26261 %
26262 % The \luamdef{util.rope_last} method retrieves the last item in a rope. For
26263 % the definition of a rope, see the definition of the \luamref{util.walk} method.
26264 %
26265 % \end{markdown}
26266 % \begin{macrocode}
26267 function util.rope_last(rope)
26268 if #rope == 0 then
26269 return nil
26270 else
26271 local l = rope[#rope]
26272 if type(l) == "table" then
26273 return util.rope_last(l)
26274 else
26275 return l
26276 end
26277 end
26278 end
26279 % \end{macrocode}
26280 % \begin{markdown}
26281 %
26282 % Given an array `ary` and a string `x`, the \luamdef{util.intersperse}
26283 % method returns an array `new`, such that `ary[i] == new[2*(i-1)+1]` and
26284 % `new[2*i] == x` for all $1\leq`i`\leq`#ary`$.
26285 %
26286 % \end{markdown}
26287 % \begin{macrocode}
26288 function util.intersperse(ary, x)
26289 local new = {}
26290 local l = #ary
26291 for i,v in ipairs(ary) do
26292 local n = #new
26293 new[n + 1] = v
26294 if i ~= l then
26295 new[n + 2] = x
26296 end
26297 end
26298 return new
26299 end
26300 % \end{macrocode}
26301 % \begin{markdown}
26302 %
26303 % Given an array `ary` and a function `f`, the \luamdef{util.map} method
26304 % returns an array `new`, such that `new[i] == f(ary[i])` for all
26305 % $1\leq`i`\leq`#ary`$.
26306 %
26307 % \end{markdown}
26308 % \begin{macrocode}
26309 function util.map(ary, f)
26310 local new = {}
26311 for i,v in ipairs(ary) do
26312 new[i] = f(v)
26313 end
26314 return new
26315 end
26316 % \end{macrocode}
26317 % \begin{markdown}
26318 %
26319 % Given a table `char_escapes` mapping escapable characters to escaped
26320 % strings and optionally a table `string_escapes` mapping escapable strings
26321 % to escaped strings, the \luamdef{util.escaper} method returns an escaper
26322 % function that escapes all occurrences of escapable strings and characters (in
26323 % this order).
26324 %
26325 % The method uses \pkg{LPeg}, which is faster than the Lua `string.gsub`
26326 % built-in method.
26327 %
26328 % \end{markdown}
26329 % \begin{macrocode}
26330 function util.escaper(char_escapes, string_escapes)
26331 % \end{macrocode}
26332 % \begin{markdown}
26333 % Build a string of escapable characters.
26334 % \end{markdown}
26335 % \begin{macrocode}
26336 local char_escapes_list = ""
26337 for i,_ in pairs(char_escapes) do
26338 char_escapes_list = char_escapes_list .. i
26339 end
26340 % \end{macrocode}
26341 % \begin{markdown}
26342 % Create an \pkg{LPeg} capture `escapable` that produces the escaped string
26343 % corresponding to the matched escapable character.
26344 % \end{markdown}
26345 % \begin{macrocode}
26346 local escapable = S(char_escapes_list) / char_escapes
26347 % \end{macrocode}
26348 % \begin{markdown}
26349 % If `string_escapes` is provided, turn `escapable` into the
26350 % $$\sum^^B{(`k`, `v`)\in`string_escapes`}`P(k) / v` + `escapable`$$
26351 % capture that replaces any occurrence of the string `k` with the string
26352 % `v` for each $(`k`, `v`)\in`string_escapes`$. Note that the pattern
26353 % summation is not commutative and its operands are inspected in the
26354 % summation order during the matching. As a corrolary, the strings always
26355 % take precedence over the characters.
26356 %
26357 % \end{markdown}
26358 % \begin{macrocode}
26359 if string_escapes then
26360 for k,v in pairs(string_escapes) do
26361 escapable = P(k) / v + escapable
26362 end
26363 end
26364 % \end{macrocode}
26365 % \begin{markdown}
26366 % Create an \pkg{LPeg} capture `escape_string` that captures anything
26367 % `escapable` does and matches any other unmatched characters.
26368 % \end{markdown}
26369 % \begin{macrocode}
26370 local escape_string = Cs((escapable + any)^0)
26371 % \end{macrocode}
26372 % \begin{markdown}
26373 % Return a function that matches the input string `s` against the
26374 % `escape_string` capture.
26375 % \end{markdown}
26376 % \begin{macrocode}
26377 return function(s)
26378 return lpeg.match(escape_string, s)
26379 end
26380 end
26381 % \end{macrocode}
26382 % \iffalse
26383 %</lua>
26384 %<*lua,lua-loader>
26385 % \fi
26386 % \begin{markdown}
26387 %
26388 % The \luamdef{util.pathname} method produces a pathname out of a directory
26389 % name `dir` and a filename `file` and returns it.
26390 %
26391 % \end{markdown}
26392 % \begin{macrocode}
26393 function util.pathname(dir, file)
26394 if #dir == 0 then
26395 return file
26396 else
26397 return dir .. "/" .. file
26398 end
26399 end
26400 % \end{macrocode}
26401 % \begin{markdown}
26402 %
26403 % The \luamdef{util.salt} method produces cryptographic salt out of a table of
26404 % options `options`.
26405 %
26406 % \end{markdown}
26407 % \begin{macrocode}
26408 function util.salt(options)
26409 local opt_string = {}
26410 for k, _ in pairs(defaultOptions) do
26411 local v = options[k]
26412 if type(v) == "table" then
26413 for _, i in ipairs(v) do
26414 opt_string[#opt_string+1] = k .. "=" .. tostring(i)
26415 end
26416 % \end{macrocode}
26417 % \begin{markdown}
26418 %
26419 % The \Opt{cacheDir} option is disregarded.
26420 %
26421 % \end{markdown}
26422 % \begin{macrocode}
26423 elseif k ~= "cacheDir" then
26424 opt_string[#opt_string+1] = k .. "=" .. tostring(v)
26425 end
26426 end
26427 table.sort(opt_string)
26428 local salt = table.concat(opt_string, ",")
26429 .. "," .. metadata.version
26430 return salt
26431 end
26432 % \end{macrocode}
26433 % \begin{markdown}
26434 %
26435 % The \luamdef{util.warning} method produces a warning `s` that is unrelated to
26436 % any specific markdown text being processed. For warnings that are specific to
26437 % a markdown text, use \luamref{writer->warning} function.
26438 %
26439 % \end{markdown}
26440 % \begin{macrocode}
26441 util.warning = (function()
26442 local function warning(s)
26443 io.stderr:write("Warning: " .. s .. "\n")
26444 end
26445 % \end{macrocode}
26446 % \iffalse
26447 %</lua,lua-loader>
26448 %<*lua>
26449 % \fi
26450 % \begin{macrocode}
26451 for _, message in ipairs(early_warnings) do
26452 warning(message)
26453 end
26454 % \end{macrocode}
26455 % \iffalse
26456 %</lua>
26457 %<*lua,lua-loader>
26458 % \fi
26459 % \begin{macrocode}
26460 return warning
26461 end)()
26462 % \end{macrocode}
26463 % \iffalse
26464 %</lua,lua-loader>
26465 %<*lua>
26466 % \fi
26467 % \begin{markdown}
26468 %
26469 % The \luamdef{util.casefold} method performs a full case-folding of a
26470 % UTF-8-encoded Unicode string `s` based on the low-level parsers in
26471 % \luamref{unicode_data.casefold_mapping}, defined in Section
26472 % <#sec:unicode-case-folding>. Unlike the low-level parsers, the high-level
26473 % function is invariant to the number of bytes the Unicode characters occupy
26474 % after conversion to UTF-8.
26475 %
26476 % \end{markdown}
26477 % \begin{macrocode}
26478 util.casefold = (function()
26479 local fail, any = P(false), P(1)
26480 local eof = -any
26481 % \end{macrocode}
26482 % \begin{markdown}
26483 %
26484 % First, define a parser that will case-fold a character.
26485 %
26486 % \end{markdown}
26487 % \begin{macrocode}
26488 local fold_character = fail
26489 for n = 1, 4 do
26490 fold_character
26491 = fold_character
26492 + unicode_data.casefold_mapping[n]
26493 end
26494 fold_character
26495 = fold_character
26496 + C(any)
26497 % \end{macrocode}
26498 % \begin{markdown}
26499 %
26500 % Next, define a parser that will case-fold a string.
26501 %
26502 % \end{markdown}
26503 % \begin{macrocode}
26504 local fold_string = Ct(fold_character^0) * eof
26505 return function(s, form)
26506 local result = table.concat(lpeg.match(fold_string, s))
26507 assert(result ~= nil)
26508 % \end{macrocode}
26509 % \begin{markdown}
26510 %
26511 % For NFD and NFKD normalization forms, normalize the case-folded string
26512 % and then repeat the fold-and-normalize operation.
26513 %
26514 % \end{markdown}
26515 % \begin{macrocode}
26516 if form == "nfd" or form == "nfkd" then
26517 result = util.normalize(result, form)
26518 result = table.concat(lpeg.match(fold_string, result))
26519 assert(result ~= nil)
26520 result = util.normalize(result, form)
26521 end
26522 return result
26523 end
26524 end)()
26525 % \end{macrocode}
26526 % \begin{markdown}
26527 %
26528 % The \luamdef{util.canonically_order} method performs a Unicode canonical
26529 % ordering of a string UTF-8-encoded Unicode `s` based on the low-level parsers
26530 % in \luamref{unicode_data.ccc}, defined in Section
26531 % <#sec:unicode-canonical-ordering-classes>. Unlike the low-level parsers, the
26532 % high-level function is invariant to the number of bytes the Unicode
26533 % characters occupy after conversion to UTF-8.
26534 %
26535 % \end{markdown}
26536 % \begin{macrocode}
26537 util.canonically_order = (function()
26538 local fail, any = P(false), P(1)
26539 local eof = -any
26540 local cont = R("\128\191")
26541 local utf8_character
26542 = R("\0\127")
26543 + R("\194\223") * cont
26544 + R("\224\239") * cont * cont
26545 + R("\240\244") * cont * cont * cont
26546 % \end{macrocode}
26547 % \begin{markdown}
26548 %
26549 % First, define a parser that will determine the combining class of a
26550 % character.
26551 %
26552 % \end{markdown}
26553 % \begin{macrocode}
26554 local classify_character = fail
26555 for n = 1, 4 do
26556 classify_character
26557 = classify_character
26558 + unicode_data.ccc[n]
26559 end
26560 classify_character
26561 = classify_character
26562 + utf8_character * Cc(0)
26563 % \end{macrocode}
26564 % \begin{markdown}
26565 %
26566 % Next, define a parser that will determine the combining classes of all
26567 % characters in a string.
26568 %
26569 % \end{markdown}
26570 % \begin{macrocode}
26571 local classify_string = Ct(classify_character^0) * eof
26572 % \end{macrocode}
26573 % \begin{markdown}
26574 %
26575 % When the function is called, first check whether the string is trivially
26576 % ordered. If it is, return it without any changes.
26577 %
26578 % \end{markdown}
26579 % \begin{macrocode}
26580 return function(s)
26581 local s_len = utf8.len(s)
26582 if s == false or s_len <= 1 then
26583 return s
26584 end
26585 % \end{macrocode}
26586 % \begin{markdown}
26587 %
26588 % Otherwise, determine the combining classes of all characters in the string.
26589 % If the string cannot be decoded with UTF-8, return it unchanged.
26590 %
26591 % \end{markdown}
26592 % \begin{macrocode}
26593 local classes = lpeg.match(classify_string, s)
26594 if classes == nil then
26595 return s
26596 end
26597 assert(#classes == s_len)
26598 % \end{macrocode}
26599 % \begin{markdown}
26600 %
26601 % Again, check whether the string is trivially ordered. If it is, return it
26602 % without any changes. Otherwise, construct a list of ranges of non-starter
26603 % characters that must be ordered.
26604 %
26605 % \end{markdown}
26606 % \begin{macrocode}
26607 local non_starter_ranges = {}
26608 local first_non_starter, last_non_starter = nil, nil
26609 for i = 1, #classes do
26610 if first_non_starter == nil then
26611 if classes[i] ~= 0 then
26612 first_non_starter, last_non_starter = i, i
26613 end
26614 else
26615 if classes[i] == 0 then
26616 table.insert(
26617 non_starter_ranges,
26618 {first_non_starter, last_non_starter}
26619 )
26620 first_non_starter, last_non_starter = nil, nil
26621 else
26622 last_non_starter = i
26623 end
26624 end
26625 end
26626 if first_non_starter ~= nil then
26627 table.insert(
26628 non_starter_ranges,
26629 {first_non_starter, last_non_starter}
26630 )
26631 end
26632 if #non_starter_ranges == 0 then
26633 return s
26634 end
26635 local max_range_length = 0
26636 for _, range in ipairs(non_starter_ranges) do
26637 local range_start, range_end = table.unpack(range)
26638 local range_length = range_end - range_start + 1
26639 if range_length > max_range_length then
26640 max_range_length = range_length
26641 end
26642 end
26643 if max_range_length <= 1 then
26644 return s
26645 end
26646 % \end{macrocode}
26647 % \begin{markdown}
26648 %
26649 % Then, construct a buffer of all characters in the string.
26650 %
26651 % \end{markdown}
26652 % \begin{macrocode}
26653 local buffer = {}
26654 for _, code in utf8.codes(s) do
26655 local char = utf8.char(code)
26656 table.insert(buffer, char)
26657 end
26658 assert(#buffer == s_len)
26659 % \end{macrocode}
26660 % \begin{markdown}
26661 %
26662 % Next, perform a local bubble sort over the ranges of non-starter characters.
26663 %
26664 % \end{markdown}
26665 % \begin{macrocode}
26666 for _, range in ipairs(non_starter_ranges) do
26667 local range_start, range_end = table.unpack(range)
26668 local range_length = range_end - range_start + 1
26669 for _ = 1, range_length - 1 do
26670 local swapped = false
26671 for i = range_start, range_end - 1 do
26672 local j = i + 1
26673 if classes[i] > classes[j] then
26674 classes[i], classes[j] = classes[j], classes[i]
26675 buffer[i], buffer[j] = buffer[j], buffer[i]
26676 swapped = true
26677 end
26678 end
26679 if not swapped then
26680 break
26681 end
26682 end
26683 end
26684 % \end{macrocode}
26685 % \begin{markdown}
26686 %
26687 % Finally, concatenate the buffer and return an ordered string.
26688 %
26689 % \end{markdown}
26690 % \begin{macrocode}
26691 return table.concat(buffer, "")
26692 end
26693 end)()
26694 % \end{macrocode}
26695 % \begin{markdown}
26696 %
26697 % The \luamdef{util.decompose} method performs either the canonical or the
26698 % compatibility decomposition of a UTF-8-encoded Unicode string `s` based on
26699 % the low-level parsers in \luamref{unicode_data.decomposition_mapping},
26700 % defined in sections <#sec:unicode-decomposition> and
26701 % <#sec:unicode-hangul-decomposition>. Unlike the low-level parsers, the
26702 % high-level function is invariant to the number of bytes the Unicode
26703 % characters occupy after conversion to UTF-8.
26704 %
26705 % \end{markdown}
26706 % \begin{macrocode}
26707 util.decompose = (function()
26708 local fail, any = P(false), P(1)
26709 local eof = -any
26710 local decomposition_types = {"canonical", "compatibility"}
26711 % \end{macrocode}
26712 % \begin{markdown}
26713 %
26714 % First, define parsers that will decompose a character.
26715 %
26716 % \end{markdown}
26717 % \begin{macrocode}
26718 local decompose_character = {}
26719 for _, decomposition_type in ipairs(decomposition_types) do
26720 decompose_character[decomposition_type] = fail
26721 for n = 1, 4 do
26722 decompose_character[decomposition_type]
26723 = decompose_character[decomposition_type]
26724 + unicode_data.decomposition_mapping[decomposition_type][n]
26725 end
26726 decompose_character[decomposition_type]
26727 = decompose_character[decomposition_type]
26728 + C(any)
26729 end
26730 local hangul = unicode_data.decomposition_mapping.hangul
26731 decompose_character.hangul = {}
26732 for syllable_type, _ in pairs(hangul) do
26733 decompose_character.hangul[syllable_type] = fail
26734 for n = 1, 4 do
26735 decompose_character.hangul[syllable_type]
26736 = decompose_character.hangul[syllable_type]
26737 + hangul[syllable_type][n]
26738 end
26739 decompose_character.hangul[syllable_type]
26740 = decompose_character.hangul[syllable_type]
26741 + C(any)
26742 end
26743 % \end{macrocode}
26744 % \begin{markdown}
26745 %
26746 % Next, define a parser that will decompose a string.
26747 %
26748 % \end{markdown}
26749 % \begin{macrocode}
26750 local decompose_string = {}
26751 for _, decomposition_type in ipairs(decomposition_types) do
26752 decompose_string[decomposition_type]
26753 = Ct(decompose_character[decomposition_type]^0) * eof
26754 end
26755 decompose_string.hangul = {}
26756 for syllable_type, _ in pairs(hangul) do
26757 decompose_string.hangul[syllable_type]
26758 = Ct(decompose_character.hangul[syllable_type]^0) * eof
26759 end
26760 local function _decompose(s, parser)
26761 assert(s ~= nil)
26762 local result = table.concat(lpeg.match(parser, s), "")
26763 assert(result ~= nil)
26764 return result
26765 end
26766 return function(s, decomposition_type)
26767 assert(
26768 decomposition_type == "canonical"
26769 or decomposition_type == "compatibility"
26770 )
26771 local prev_s
26772 local next_s = s
26773 repeat
26774 prev_s = next_s
26775 local function decompose(...) next_s = _decompose(next_s, ...) end
26776 decompose(decompose_string.canonical)
26777 if decomposition_type == "compatibility" then
26778 decompose(decompose_string.compatibility)
26779 end
26780 decompose(decompose_string.hangul.LVT)
26781 decompose(decompose_string.hangul.LV)
26782 until prev_s == next_s
26783 return util.canonically_order(next_s)
26784 end
26785 end)()
26786 % \end{macrocode}
26787 % \begin{markdown}
26788 %
26789 % The \luamdef{util.compose} method performs the canonical composition of a
26790 % UTF-8-encoded canonically ordered Unicode string `s` based on the low-level
26791 % parsers in \luamref{unicode_data.composition_mapping},
26792 % defined in Section <#sec:unicode-canonical-composition>, and definitions
26793 % from the Hangul syllable (de)composition algorithm, defined in Section
26794 % <#sec:unicode-hangul-decomposition>. Unlike the low-level parsers, this
26795 % high-level function is invariant to the number of bytes the Unicode
26796 % characters occupy after conversion to UTF-8.
26797 %
26798 % \end{markdown}
26799 % \begin{macrocode}
26800 util.compose = (function()
26801 local fail, any = P(false), P(1)
26802 local eof = -any
26803 local cont = R("\128\191")
26804 local utf8_character
26805 = R("\0\127")
26806 + R("\194\223") * cont
26807 + R("\224\239") * cont * cont
26808 + R("\240\244") * cont * cont * cont
26809 % \end{macrocode}
26810 % \begin{markdown}
26811 %
26812 % First, define a parser that will determine the combining class of a
26813 % character.
26814 %
26815 % \end{markdown}
26816 % \begin{macrocode}
26817 local classify_character = fail
26818 for n = 1, 4 do
26819 classify_character
26820 = classify_character
26821 + unicode_data.ccc[n]
26822 end
26823 classify_character
26824 = classify_character
26825 + utf8_character * Cc(0)
26826 % \end{macrocode}
26827 % \begin{markdown}
26828 %
26829 % Next, define a parser that will determine the combining classes of all
26830 % characters in a string.
26831 %
26832 % \end{markdown}
26833 % \begin{macrocode}
26834 local classify_string = Ct(classify_character^0) * eof
26835 % \end{macrocode}
26836 % \begin{markdown}
26837 %
26838 % First, define parsers that will compose a pair of UTF-8-encoded Unicode
26839 % characters into their primary composite.
26840 %
26841 % \end{markdown}
26842 % \begin{macrocode}
26843 local compose_characters = fail
26844 for m = 1, 4 do
26845 local starter = #unicode_data.composition_mapping.starters[m]
26846 local both = fail
26847 for n = 1, 4 do
26848 both = (
26849 both
26850 + #unicode_data.composition_mapping.both[m][n]
26851 * unicode_data.composition_mapping.both[m][n]
26852 )
26853 end
26854 compose_characters = compose_characters + starter * both
26855 end
26856 % \end{macrocode}
26857 % \begin{markdown}
26858 %
26859 % When the function is called, first check whether the string is trivially
26860 % ordered. If it is, return it without any changes.
26861 %
26862 % \end{markdown}
26863 % \begin{macrocode}
26864 return function(s)
26865 local s_len = utf8.len(s)
26866 if s == false or s_len <= 1 then
26867 return s
26868 end
26869 % \end{macrocode}
26870 % \begin{markdown}
26871 %
26872 % Otherwise, determine the combining classes of all characters in the string.
26873 % If the string cannot be decoded with UTF-8, return it unchanged.
26874 %
26875 % \end{markdown}
26876 % \begin{macrocode}
26877 local classes = lpeg.match(classify_string, s)
26878 if classes == nil then
26879 return s
26880 end
26881 assert(#classes == s_len)
26882 % \end{macrocode}
26883 % \begin{markdown}
26884 %
26885 % Otherwise, construct a buffer of all characters in the string.
26886 %
26887 % \end{markdown}
26888 % \begin{macrocode}
26889 local buffer = {}
26890 for _, code in utf8.codes(s) do
26891 local char = utf8.char(code)
26892 table.insert(buffer, char)
26893 end
26894 assert(#buffer == s_len)
26895 % \end{macrocode}
26896 % \begin{markdown}
26897 %
26898 % Finally, implement the composition algorithm.
26899 %
26900 % First, find the first starter character in the string.
26901 %
26902 % \end{markdown}
26903 % \begin{macrocode}
26904 local starter = 1
26905 while starter <= s_len and classes[starter] ~= 0 do
26906 starter = starter + 1
26907 end
26908 local candidate_combining_mark = starter + 1
26909 % \end{macrocode}
26910 % \begin{markdown}
26911 %
26912 % Next, apply the composition rules until we reach the end of the string.
26913 %
26914 % \end{markdown}
26915 % \begin{macrocode}
26916 while candidate_combining_mark <= s_len do
26917 local L = buffer[starter]
26918 local C = buffer[candidate_combining_mark]
26919 local P = lpeg.match(compose_characters, L .. C)
26920 if P ~= nil then
26921 buffer[starter] = P
26922 buffer[candidate_combining_mark] = ""
26923 else
26924 if classes[candidate_combining_mark] == 0 then
26925 starter = candidate_combining_mark
26926 end
26927 candidate_combining_mark = candidate_combining_mark + 1
26928 end
26929 assert(starter <= s_len)
26930 end
26931 % \end{macrocode}
26932 % \begin{markdown}
26933 %
26934 % Next, iterate over the string once more and compose Hangul syllables.
26935 %
26936 % \end{markdown}
26937 % \begin{macrocode}
26938 for i = 1, s_len - 1 do
26939 local last, ch = buffer[i], buffer[i + 1]
26940 if last ~= "" and ch ~= "" then
26941 local composite = unicode_data.hangul_compose(last, ch)
26942 if composite ~= nil then
26943 buffer[i] = ""
26944 buffer[i + 1] = composite
26945 end
26946 end
26947 end
26948 % \end{macrocode}
26949 % \begin{markdown}
26950 %
26951 % Finally, concatenate the buffer and return an ordered string.
26952 %
26953 % \end{markdown}
26954 % \begin{macrocode}
26955 return table.concat(buffer, "")
26956 end
26957 end)()
26958 % \end{macrocode}
26959 % \begin{markdown}
26960 %
26961 % The \luamdef{util.normalize} method normalizes a UTF-8-encoded canonically
26962 % ordered Unicode string `s` using the normalization form `form`.
26963 %
26964 % \end{markdown}
26965 % \begin{macrocode}
26966 function util.normalize(s, form)
26967 if form == "nfd" then
26968 return util.decompose(s, "canonical")
26969 elseif form == "nfkd" then
26970 return util.decompose(s, "compatibility")
26971 elseif form == "nfc" then
26972 return util.compose(util.decompose(s, "canonical"))
26973 elseif form == "nfkc" then
26974 return util.compose(util.decompose(s, "compatibility"))
26975 else
26976 error(string.format('Unexpected normal form "%s"', form))
26977 end
26978 end
26979 % \end{macrocode}
26980 % \begin{markdown}
26981 %
26982 % The \luamdef{util.find_file} and \luamdef{util.find_files} method find the
26983 % first or all locations of a file, respectively, according to either the
26984 % resolvers API [@context23, Section 11.5] from the \Hologo{ConTeXt}
26985 % format or the \pkg{Kpathsea} library.
26986 %
26987 % \end{markdown}
26988 % \begin{macrocode}
26989 function util.find_file(filename)
26990 if resolvers ~= nil then
26991 return resolvers.findfile(filename)
26992 else
26993 return kpse.find_file(filename)
26994 end
26995 end
26996 function util.find_files(filename)
26997 if resolvers ~= nil then
26998 return resolvers.findfiles(filename)
26999 else
27000 return {kpse.lookup(filename, {all=true})}
27001 end
27002 end
27003 % \end{macrocode}
27004 % \begin{markdown}
27005 %
27006 %### HTML Entities
27007 % This section documents the HTML entities recognized by the
27008 % markdown reader. These functions are encapsulated in the `entities`
27009 % object. The functions were originally located in the
27010 % `lunamark/entities.lua` file in the Lunamark Lua module.
27011 %
27012 % \end{markdown}
27013 % \begin{macrocode}
27014 local entities = {}
27015
27016 local character_entities = {
27017 ["Tab"] = 9,
27018 ["NewLine"] = 10,
27019 ["excl"] = 33,
27020 ["QUOT"] = 34,
27021 ["quot"] = 34,
27022 ["num"] = 35,
27023 ["dollar"] = 36,
27024 ["percnt"] = 37,
27025 ["AMP"] = 38,
27026 ["amp"] = 38,
27027 ["apos"] = 39,
27028 ["lpar"] = 40,
27029 ["rpar"] = 41,
27030 ["ast"] = 42,
27031 ["midast"] = 42,
27032 ["plus"] = 43,
27033 ["comma"] = 44,
27034 ["period"] = 46,
27035 ["sol"] = 47,
27036 ["colon"] = 58,
27037 ["semi"] = 59,
27038 ["LT"] = 60,
27039 ["lt"] = 60,
27040 ["nvlt"] = {60, 8402},
27041 ["bne"] = {61, 8421},
27042 ["equals"] = 61,
27043 ["GT"] = 62,
27044 ["gt"] = 62,
27045 ["nvgt"] = {62, 8402},
27046 ["quest"] = 63,
27047 ["commat"] = 64,
27048 ["lbrack"] = 91,
27049 ["lsqb"] = 91,
27050 ["bsol"] = 92,
27051 ["rbrack"] = 93,
27052 ["rsqb"] = 93,
27053 ["Hat"] = 94,
27054 ["UnderBar"] = 95,
27055 ["lowbar"] = 95,
27056 ["DiacriticalGrave"] = 96,
27057 ["grave"] = 96,
27058 ["fjlig"] = {102, 106},
27059 ["lbrace"] = 123,
27060 ["lcub"] = 123,
27061 ["VerticalLine"] = 124,
27062 ["verbar"] = 124,
27063 ["vert"] = 124,
27064 ["rbrace"] = 125,
27065 ["rcub"] = 125,
27066 ["NonBreakingSpace"] = 160,
27067 ["nbsp"] = 160,
27068 ["iexcl"] = 161,
27069 ["cent"] = 162,
27070 ["pound"] = 163,
27071 ["curren"] = 164,
27072 ["yen"] = 165,
27073 ["brvbar"] = 166,
27074 ["sect"] = 167,
27075 ["Dot"] = 168,
27076 ["DoubleDot"] = 168,
27077 ["die"] = 168,
27078 ["uml"] = 168,
27079 ["COPY"] = 169,
27080 ["copy"] = 169,
27081 ["ordf"] = 170,
27082 ["laquo"] = 171,
27083 ["not"] = 172,
27084 ["shy"] = 173,
27085 ["REG"] = 174,
27086 ["circledR"] = 174,
27087 ["reg"] = 174,
27088 ["macr"] = 175,
27089 ["strns"] = 175,
27090 ["deg"] = 176,
27091 ["PlusMinus"] = 177,
27092 ["plusmn"] = 177,
27093 ["pm"] = 177,
27094 ["sup2"] = 178,
27095 ["sup3"] = 179,
27096 ["DiacriticalAcute"] = 180,
27097 ["acute"] = 180,
27098 ["micro"] = 181,
27099 ["para"] = 182,
27100 ["CenterDot"] = 183,
27101 ["centerdot"] = 183,
27102 ["middot"] = 183,
27103 ["Cedilla"] = 184,
27104 ["cedil"] = 184,
27105 ["sup1"] = 185,
27106 ["ordm"] = 186,
27107 ["raquo"] = 187,
27108 ["frac14"] = 188,
27109 ["frac12"] = 189,
27110 ["half"] = 189,
27111 ["frac34"] = 190,
27112 ["iquest"] = 191,
27113 ["Agrave"] = 192,
27114 ["Aacute"] = 193,
27115 ["Acirc"] = 194,
27116 ["Atilde"] = 195,
27117 ["Auml"] = 196,
27118 ["Aring"] = 197,
27119 ["angst"] = 197,
27120 ["AElig"] = 198,
27121 ["Ccedil"] = 199,
27122 ["Egrave"] = 200,
27123 ["Eacute"] = 201,
27124 ["Ecirc"] = 202,
27125 ["Euml"] = 203,
27126 ["Igrave"] = 204,
27127 ["Iacute"] = 205,
27128 ["Icirc"] = 206,
27129 ["Iuml"] = 207,
27130 ["ETH"] = 208,
27131 ["Ntilde"] = 209,
27132 ["Ograve"] = 210,
27133 ["Oacute"] = 211,
27134 ["Ocirc"] = 212,
27135 ["Otilde"] = 213,
27136 ["Ouml"] = 214,
27137 ["times"] = 215,
27138 ["Oslash"] = 216,
27139 ["Ugrave"] = 217,
27140 ["Uacute"] = 218,
27141 ["Ucirc"] = 219,
27142 ["Uuml"] = 220,
27143 ["Yacute"] = 221,
27144 ["THORN"] = 222,
27145 ["szlig"] = 223,
27146 ["agrave"] = 224,
27147 ["aacute"] = 225,
27148 ["acirc"] = 226,
27149 ["atilde"] = 227,
27150 ["auml"] = 228,
27151 ["aring"] = 229,
27152 ["aelig"] = 230,
27153 ["ccedil"] = 231,
27154 ["egrave"] = 232,
27155 ["eacute"] = 233,
27156 ["ecirc"] = 234,
27157 ["euml"] = 235,
27158 ["igrave"] = 236,
27159 ["iacute"] = 237,
27160 ["icirc"] = 238,
27161 ["iuml"] = 239,
27162 ["eth"] = 240,
27163 ["ntilde"] = 241,
27164 ["ograve"] = 242,
27165 ["oacute"] = 243,
27166 ["ocirc"] = 244,
27167 ["otilde"] = 245,
27168 ["ouml"] = 246,
27169 ["div"] = 247,
27170 ["divide"] = 247,
27171 ["oslash"] = 248,
27172 ["ugrave"] = 249,
27173 ["uacute"] = 250,
27174 ["ucirc"] = 251,
27175 ["uuml"] = 252,
27176 ["yacute"] = 253,
27177 ["thorn"] = 254,
27178 ["yuml"] = 255,
27179 ["Amacr"] = 256,
27180 ["amacr"] = 257,
27181 ["Abreve"] = 258,
27182 ["abreve"] = 259,
27183 ["Aogon"] = 260,
27184 ["aogon"] = 261,
27185 ["Cacute"] = 262,
27186 ["cacute"] = 263,
27187 ["Ccirc"] = 264,
27188 ["ccirc"] = 265,
27189 ["Cdot"] = 266,
27190 ["cdot"] = 267,
27191 ["Ccaron"] = 268,
27192 ["ccaron"] = 269,
27193 ["Dcaron"] = 270,
27194 ["dcaron"] = 271,
27195 ["Dstrok"] = 272,
27196 ["dstrok"] = 273,
27197 ["Emacr"] = 274,
27198 ["emacr"] = 275,
27199 ["Edot"] = 278,
27200 ["edot"] = 279,
27201 ["Eogon"] = 280,
27202 ["eogon"] = 281,
27203 ["Ecaron"] = 282,
27204 ["ecaron"] = 283,
27205 ["Gcirc"] = 284,
27206 ["gcirc"] = 285,
27207 ["Gbreve"] = 286,
27208 ["gbreve"] = 287,
27209 ["Gdot"] = 288,
27210 ["gdot"] = 289,
27211 ["Gcedil"] = 290,
27212 ["Hcirc"] = 292,
27213 ["hcirc"] = 293,
27214 ["Hstrok"] = 294,
27215 ["hstrok"] = 295,
27216 ["Itilde"] = 296,
27217 ["itilde"] = 297,
27218 ["Imacr"] = 298,
27219 ["imacr"] = 299,
27220 ["Iogon"] = 302,
27221 ["iogon"] = 303,
27222 ["Idot"] = 304,
27223 ["imath"] = 305,
27224 ["inodot"] = 305,
27225 ["IJlig"] = 306,
27226 ["ijlig"] = 307,
27227 ["Jcirc"] = 308,
27228 ["jcirc"] = 309,
27229 ["Kcedil"] = 310,
27230 ["kcedil"] = 311,
27231 ["kgreen"] = 312,
27232 ["Lacute"] = 313,
27233 ["lacute"] = 314,
27234 ["Lcedil"] = 315,
27235 ["lcedil"] = 316,
27236 ["Lcaron"] = 317,
27237 ["lcaron"] = 318,
27238 ["Lmidot"] = 319,
27239 ["lmidot"] = 320,
27240 ["Lstrok"] = 321,
27241 ["lstrok"] = 322,
27242 ["Nacute"] = 323,
27243 ["nacute"] = 324,
27244 ["Ncedil"] = 325,
27245 ["ncedil"] = 326,
27246 ["Ncaron"] = 327,
27247 ["ncaron"] = 328,
27248 ["napos"] = 329,
27249 ["ENG"] = 330,
27250 ["eng"] = 331,
27251 ["Omacr"] = 332,
27252 ["omacr"] = 333,
27253 ["Odblac"] = 336,
27254 ["odblac"] = 337,
27255 ["OElig"] = 338,
27256 ["oelig"] = 339,
27257 ["Racute"] = 340,
27258 ["racute"] = 341,
27259 ["Rcedil"] = 342,
27260 ["rcedil"] = 343,
27261 ["Rcaron"] = 344,
27262 ["rcaron"] = 345,
27263 ["Sacute"] = 346,
27264 ["sacute"] = 347,
27265 ["Scirc"] = 348,
27266 ["scirc"] = 349,
27267 ["Scedil"] = 350,
27268 ["scedil"] = 351,
27269 ["Scaron"] = 352,
27270 ["scaron"] = 353,
27271 ["Tcedil"] = 354,
27272 ["tcedil"] = 355,
27273 ["Tcaron"] = 356,
27274 ["tcaron"] = 357,
27275 ["Tstrok"] = 358,
27276 ["tstrok"] = 359,
27277 ["Utilde"] = 360,
27278 ["utilde"] = 361,
27279 ["Umacr"] = 362,
27280 ["umacr"] = 363,
27281 ["Ubreve"] = 364,
27282 ["ubreve"] = 365,
27283 ["Uring"] = 366,
27284 ["uring"] = 367,
27285 ["Udblac"] = 368,
27286 ["udblac"] = 369,
27287 ["Uogon"] = 370,
27288 ["uogon"] = 371,
27289 ["Wcirc"] = 372,
27290 ["wcirc"] = 373,
27291 ["Ycirc"] = 374,
27292 ["ycirc"] = 375,
27293 ["Yuml"] = 376,
27294 ["Zacute"] = 377,
27295 ["zacute"] = 378,
27296 ["Zdot"] = 379,
27297 ["zdot"] = 380,
27298 ["Zcaron"] = 381,
27299 ["zcaron"] = 382,
27300 ["fnof"] = 402,
27301 ["imped"] = 437,
27302 ["gacute"] = 501,
27303 ["jmath"] = 567,
27304 ["circ"] = 710,
27305 ["Hacek"] = 711,
27306 ["caron"] = 711,
27307 ["Breve"] = 728,
27308 ["breve"] = 728,
27309 ["DiacriticalDot"] = 729,
27310 ["dot"] = 729,
27311 ["ring"] = 730,
27312 ["ogon"] = 731,
27313 ["DiacriticalTilde"] = 732,
27314 ["tilde"] = 732,
27315 ["DiacriticalDoubleAcute"] = 733,
27316 ["dblac"] = 733,
27317 ["DownBreve"] = 785,
27318 ["Alpha"] = 913,
27319 ["Beta"] = 914,
27320 ["Gamma"] = 915,
27321 ["Delta"] = 916,
27322 ["Epsilon"] = 917,
27323 ["Zeta"] = 918,
27324 ["Eta"] = 919,
27325 ["Theta"] = 920,
27326 ["Iota"] = 921,
27327 ["Kappa"] = 922,
27328 ["Lambda"] = 923,
27329 ["Mu"] = 924,
27330 ["Nu"] = 925,
27331 ["Xi"] = 926,
27332 ["Omicron"] = 927,
27333 ["Pi"] = 928,
27334 ["Rho"] = 929,
27335 ["Sigma"] = 931,
27336 ["Tau"] = 932,
27337 ["Upsilon"] = 933,
27338 ["Phi"] = 934,
27339 ["Chi"] = 935,
27340 ["Psi"] = 936,
27341 ["Omega"] = 937,
27342 ["ohm"] = 937,
27343 ["alpha"] = 945,
27344 ["beta"] = 946,
27345 ["gamma"] = 947,
27346 ["delta"] = 948,
27347 ["epsi"] = 949,
27348 ["epsilon"] = 949,
27349 ["zeta"] = 950,
27350 ["eta"] = 951,
27351 ["theta"] = 952,
27352 ["iota"] = 953,
27353 ["kappa"] = 954,
27354 ["lambda"] = 955,
27355 ["mu"] = 956,
27356 ["nu"] = 957,
27357 ["xi"] = 958,
27358 ["omicron"] = 959,
27359 ["pi"] = 960,
27360 ["rho"] = 961,
27361 ["sigmaf"] = 962,
27362 ["sigmav"] = 962,
27363 ["varsigma"] = 962,
27364 ["sigma"] = 963,
27365 ["tau"] = 964,
27366 ["upsi"] = 965,
27367 ["upsilon"] = 965,
27368 ["phi"] = 966,
27369 ["chi"] = 967,
27370 ["psi"] = 968,
27371 ["omega"] = 969,
27372 ["thetasym"] = 977,
27373 ["thetav"] = 977,
27374 ["vartheta"] = 977,
27375 ["Upsi"] = 978,
27376 ["upsih"] = 978,
27377 ["phiv"] = 981,
27378 ["straightphi"] = 981,
27379 ["varphi"] = 981,
27380 ["piv"] = 982,
27381 ["varpi"] = 982,
27382 ["Gammad"] = 988,
27383 ["digamma"] = 989,
27384 ["gammad"] = 989,
27385 ["kappav"] = 1008,
27386 ["varkappa"] = 1008,
27387 ["rhov"] = 1009,
27388 ["varrho"] = 1009,
27389 ["epsiv"] = 1013,
27390 ["straightepsilon"] = 1013,
27391 ["varepsilon"] = 1013,
27392 ["backepsilon"] = 1014,
27393 ["bepsi"] = 1014,
27394 ["IOcy"] = 1025,
27395 ["DJcy"] = 1026,
27396 ["GJcy"] = 1027,
27397 ["Jukcy"] = 1028,
27398 ["DScy"] = 1029,
27399 ["Iukcy"] = 1030,
27400 ["YIcy"] = 1031,
27401 ["Jsercy"] = 1032,
27402 ["LJcy"] = 1033,
27403 ["NJcy"] = 1034,
27404 ["TSHcy"] = 1035,
27405 ["KJcy"] = 1036,
27406 ["Ubrcy"] = 1038,
27407 ["DZcy"] = 1039,
27408 ["Acy"] = 1040,
27409 ["Bcy"] = 1041,
27410 ["Vcy"] = 1042,
27411 ["Gcy"] = 1043,
27412 ["Dcy"] = 1044,
27413 ["IEcy"] = 1045,
27414 ["ZHcy"] = 1046,
27415 ["Zcy"] = 1047,
27416 ["Icy"] = 1048,
27417 ["Jcy"] = 1049,
27418 ["Kcy"] = 1050,
27419 ["Lcy"] = 1051,
27420 ["Mcy"] = 1052,
27421 ["Ncy"] = 1053,
27422 ["Ocy"] = 1054,
27423 ["Pcy"] = 1055,
27424 ["Rcy"] = 1056,
27425 ["Scy"] = 1057,
27426 ["Tcy"] = 1058,
27427 ["Ucy"] = 1059,
27428 ["Fcy"] = 1060,
27429 ["KHcy"] = 1061,
27430 ["TScy"] = 1062,
27431 ["CHcy"] = 1063,
27432 ["SHcy"] = 1064,
27433 ["SHCHcy"] = 1065,
27434 ["HARDcy"] = 1066,
27435 ["Ycy"] = 1067,
27436 ["SOFTcy"] = 1068,
27437 ["Ecy"] = 1069,
27438 ["YUcy"] = 1070,
27439 ["YAcy"] = 1071,
27440 ["acy"] = 1072,
27441 ["bcy"] = 1073,
27442 ["vcy"] = 1074,
27443 ["gcy"] = 1075,
27444 ["dcy"] = 1076,
27445 ["iecy"] = 1077,
27446 ["zhcy"] = 1078,
27447 ["zcy"] = 1079,
27448 ["icy"] = 1080,
27449 ["jcy"] = 1081,
27450 ["kcy"] = 1082,
27451 ["lcy"] = 1083,
27452 ["mcy"] = 1084,
27453 ["ncy"] = 1085,
27454 ["ocy"] = 1086,
27455 ["pcy"] = 1087,
27456 ["rcy"] = 1088,
27457 ["scy"] = 1089,
27458 ["tcy"] = 1090,
27459 ["ucy"] = 1091,
27460 ["fcy"] = 1092,
27461 ["khcy"] = 1093,
27462 ["tscy"] = 1094,
27463 ["chcy"] = 1095,
27464 ["shcy"] = 1096,
27465 ["shchcy"] = 1097,
27466 ["hardcy"] = 1098,
27467 ["ycy"] = 1099,
27468 ["softcy"] = 1100,
27469 ["ecy"] = 1101,
27470 ["yucy"] = 1102,
27471 ["yacy"] = 1103,
27472 ["iocy"] = 1105,
27473 ["djcy"] = 1106,
27474 ["gjcy"] = 1107,
27475 ["jukcy"] = 1108,
27476 ["dscy"] = 1109,
27477 ["iukcy"] = 1110,
27478 ["yicy"] = 1111,
27479 ["jsercy"] = 1112,
27480 ["ljcy"] = 1113,
27481 ["njcy"] = 1114,
27482 ["tshcy"] = 1115,
27483 ["kjcy"] = 1116,
27484 ["ubrcy"] = 1118,
27485 ["dzcy"] = 1119,
27486 ["ensp"] = 8194,
27487 ["emsp"] = 8195,
27488 ["emsp13"] = 8196,
27489 ["emsp14"] = 8197,
27490 ["numsp"] = 8199,
27491 ["puncsp"] = 8200,
27492 ["ThinSpace"] = 8201,
27493 ["thinsp"] = 8201,
27494 ["VeryThinSpace"] = 8202,
27495 ["hairsp"] = 8202,
27496 ["NegativeMediumSpace"] = 8203,
27497 ["NegativeThickSpace"] = 8203,
27498 ["NegativeThinSpace"] = 8203,
27499 ["NegativeVeryThinSpace"] = 8203,
27500 ["ZeroWidthSpace"] = 8203,
27501 ["zwnj"] = 8204,
27502 ["zwj"] = 8205,
27503 ["lrm"] = 8206,
27504 ["rlm"] = 8207,
27505 ["dash"] = 8208,
27506 ["hyphen"] = 8208,
27507 ["ndash"] = 8211,
27508 ["mdash"] = 8212,
27509 ["horbar"] = 8213,
27510 ["Verbar"] = 8214,
27511 ["Vert"] = 8214,
27512 ["OpenCurlyQuote"] = 8216,
27513 ["lsquo"] = 8216,
27514 ["CloseCurlyQuote"] = 8217,
27515 ["rsquo"] = 8217,
27516 ["rsquor"] = 8217,
27517 ["lsquor"] = 8218,
27518 ["sbquo"] = 8218,
27519 ["OpenCurlyDoubleQuote"] = 8220,
27520 ["ldquo"] = 8220,
27521 ["CloseCurlyDoubleQuote"] = 8221,
27522 ["rdquo"] = 8221,
27523 ["rdquor"] = 8221,
27524 ["bdquo"] = 8222,
27525 ["ldquor"] = 8222,
27526 ["dagger"] = 8224,
27527 ["Dagger"] = 8225,
27528 ["ddagger"] = 8225,
27529 ["bull"] = 8226,
27530 ["bullet"] = 8226,
27531 ["nldr"] = 8229,
27532 ["hellip"] = 8230,
27533 ["mldr"] = 8230,
27534 ["permil"] = 8240,
27535 ["pertenk"] = 8241,
27536 ["prime"] = 8242,
27537 ["Prime"] = 8243,
27538 ["tprime"] = 8244,
27539 ["backprime"] = 8245,
27540 ["bprime"] = 8245,
27541 ["lsaquo"] = 8249,
27542 ["rsaquo"] = 8250,
27543 ["OverBar"] = 8254,
27544 ["oline"] = 8254,
27545 ["caret"] = 8257,
27546 ["hybull"] = 8259,
27547 ["frasl"] = 8260,
27548 ["bsemi"] = 8271,
27549 ["qprime"] = 8279,
27550 ["MediumSpace"] = 8287,
27551 ["ThickSpace"] = {8287, 8202},
27552 ["NoBreak"] = 8288,
27553 ["ApplyFunction"] = 8289,
27554 ["af"] = 8289,
27555 ["InvisibleTimes"] = 8290,
27556 ["it"] = 8290,
27557 ["InvisibleComma"] = 8291,
27558 ["ic"] = 8291,
27559 ["euro"] = 8364,
27560 ["TripleDot"] = 8411,
27561 ["tdot"] = 8411,
27562 ["DotDot"] = 8412,
27563 ["Copf"] = 8450,
27564 ["complexes"] = 8450,
27565 ["incare"] = 8453,
27566 ["gscr"] = 8458,
27567 ["HilbertSpace"] = 8459,
27568 ["Hscr"] = 8459,
27569 ["hamilt"] = 8459,
27570 ["Hfr"] = 8460,
27571 ["Poincareplane"] = 8460,
27572 ["Hopf"] = 8461,
27573 ["quaternions"] = 8461,
27574 ["planckh"] = 8462,
27575 ["hbar"] = 8463,
27576 ["hslash"] = 8463,
27577 ["planck"] = 8463,
27578 ["plankv"] = 8463,
27579 ["Iscr"] = 8464,
27580 ["imagline"] = 8464,
27581 ["Ifr"] = 8465,
27582 ["Im"] = 8465,
27583 ["image"] = 8465,
27584 ["imagpart"] = 8465,
27585 ["Laplacetrf"] = 8466,
27586 ["Lscr"] = 8466,
27587 ["lagran"] = 8466,
27588 ["ell"] = 8467,
27589 ["Nopf"] = 8469,
27590 ["naturals"] = 8469,
27591 ["numero"] = 8470,
27592 ["copysr"] = 8471,
27593 ["weierp"] = 8472,
27594 ["wp"] = 8472,
27595 ["Popf"] = 8473,
27596 ["primes"] = 8473,
27597 ["Qopf"] = 8474,
27598 ["rationals"] = 8474,
27599 ["Rscr"] = 8475,
27600 ["realine"] = 8475,
27601 ["Re"] = 8476,
27602 ["Rfr"] = 8476,
27603 ["real"] = 8476,
27604 ["realpart"] = 8476,
27605 ["Ropf"] = 8477,
27606 ["reals"] = 8477,
27607 ["rx"] = 8478,
27608 ["TRADE"] = 8482,
27609 ["trade"] = 8482,
27610 ["Zopf"] = 8484,
27611 ["integers"] = 8484,
27612 ["mho"] = 8487,
27613 ["Zfr"] = 8488,
27614 ["zeetrf"] = 8488,
27615 ["iiota"] = 8489,
27616 ["Bernoullis"] = 8492,
27617 ["Bscr"] = 8492,
27618 ["bernou"] = 8492,
27619 ["Cayleys"] = 8493,
27620 ["Cfr"] = 8493,
27621 ["escr"] = 8495,
27622 ["Escr"] = 8496,
27623 ["expectation"] = 8496,
27624 ["Fouriertrf"] = 8497,
27625 ["Fscr"] = 8497,
27626 ["Mellintrf"] = 8499,
27627 ["Mscr"] = 8499,
27628 ["phmmat"] = 8499,
27629 ["order"] = 8500,
27630 ["orderof"] = 8500,
27631 ["oscr"] = 8500,
27632 ["alefsym"] = 8501,
27633 ["aleph"] = 8501,
27634 ["beth"] = 8502,
27635 ["gimel"] = 8503,
27636 ["daleth"] = 8504,
27637 ["CapitalDifferentialD"] = 8517,
27638 ["DD"] = 8517,
27639 ["DifferentialD"] = 8518,
27640 ["dd"] = 8518,
27641 ["ExponentialE"] = 8519,
27642 ["ee"] = 8519,
27643 ["exponentiale"] = 8519,
27644 ["ImaginaryI"] = 8520,
27645 ["ii"] = 8520,
27646 ["frac13"] = 8531,
27647 ["frac23"] = 8532,
27648 ["frac15"] = 8533,
27649 ["frac25"] = 8534,
27650 ["frac35"] = 8535,
27651 ["frac45"] = 8536,
27652 ["frac16"] = 8537,
27653 ["frac56"] = 8538,
27654 ["frac18"] = 8539,
27655 ["frac38"] = 8540,
27656 ["frac58"] = 8541,
27657 ["frac78"] = 8542,
27658 ["LeftArrow"] = 8592,
27659 ["ShortLeftArrow"] = 8592,
27660 ["larr"] = 8592,
27661 ["leftarrow"] = 8592,
27662 ["slarr"] = 8592,
27663 ["ShortUpArrow"] = 8593,
27664 ["UpArrow"] = 8593,
27665 ["uarr"] = 8593,
27666 ["uparrow"] = 8593,
27667 ["RightArrow"] = 8594,
27668 ["ShortRightArrow"] = 8594,
27669 ["rarr"] = 8594,
27670 ["rightarrow"] = 8594,
27671 ["srarr"] = 8594,
27672 ["DownArrow"] = 8595,
27673 ["ShortDownArrow"] = 8595,
27674 ["darr"] = 8595,
27675 ["downarrow"] = 8595,
27676 ["LeftRightArrow"] = 8596,
27677 ["harr"] = 8596,
27678 ["leftrightarrow"] = 8596,
27679 ["UpDownArrow"] = 8597,
27680 ["updownarrow"] = 8597,
27681 ["varr"] = 8597,
27682 ["UpperLeftArrow"] = 8598,
27683 ["nwarr"] = 8598,
27684 ["nwarrow"] = 8598,
27685 ["UpperRightArrow"] = 8599,
27686 ["nearr"] = 8599,
27687 ["nearrow"] = 8599,
27688 ["LowerRightArrow"] = 8600,
27689 ["searr"] = 8600,
27690 ["searrow"] = 8600,
27691 ["LowerLeftArrow"] = 8601,
27692 ["swarr"] = 8601,
27693 ["swarrow"] = 8601,
27694 ["nlarr"] = 8602,
27695 ["nleftarrow"] = 8602,
27696 ["nrarr"] = 8603,
27697 ["nrightarrow"] = 8603,
27698 ["nrarrw"] = {8605, 824},
27699 ["rarrw"] = 8605,
27700 ["rightsquigarrow"] = 8605,
27701 ["Larr"] = 8606,
27702 ["twoheadleftarrow"] = 8606,
27703 ["Uarr"] = 8607,
27704 ["Rarr"] = 8608,
27705 ["twoheadrightarrow"] = 8608,
27706 ["Darr"] = 8609,
27707 ["larrtl"] = 8610,
27708 ["leftarrowtail"] = 8610,
27709 ["rarrtl"] = 8611,
27710 ["rightarrowtail"] = 8611,
27711 ["LeftTeeArrow"] = 8612,
27712 ["mapstoleft"] = 8612,
27713 ["UpTeeArrow"] = 8613,
27714 ["mapstoup"] = 8613,
27715 ["RightTeeArrow"] = 8614,
27716 ["map"] = 8614,
27717 ["mapsto"] = 8614,
27718 ["DownTeeArrow"] = 8615,
27719 ["mapstodown"] = 8615,
27720 ["hookleftarrow"] = 8617,
27721 ["larrhk"] = 8617,
27722 ["hookrightarrow"] = 8618,
27723 ["rarrhk"] = 8618,
27724 ["larrlp"] = 8619,
27725 ["looparrowleft"] = 8619,
27726 ["looparrowright"] = 8620,
27727 ["rarrlp"] = 8620,
27728 ["harrw"] = 8621,
27729 ["leftrightsquigarrow"] = 8621,
27730 ["nharr"] = 8622,
27731 ["nleftrightarrow"] = 8622,
27732 ["Lsh"] = 8624,
27733 ["lsh"] = 8624,
27734 ["Rsh"] = 8625,
27735 ["rsh"] = 8625,
27736 ["ldsh"] = 8626,
27737 ["rdsh"] = 8627,
27738 ["crarr"] = 8629,
27739 ["cularr"] = 8630,
27740 ["curvearrowleft"] = 8630,
27741 ["curarr"] = 8631,
27742 ["curvearrowright"] = 8631,
27743 ["circlearrowleft"] = 8634,
27744 ["olarr"] = 8634,
27745 ["circlearrowright"] = 8635,
27746 ["orarr"] = 8635,
27747 ["LeftVector"] = 8636,
27748 ["leftharpoonup"] = 8636,
27749 ["lharu"] = 8636,
27750 ["DownLeftVector"] = 8637,
27751 ["leftharpoondown"] = 8637,
27752 ["lhard"] = 8637,
27753 ["RightUpVector"] = 8638,
27754 ["uharr"] = 8638,
27755 ["upharpoonright"] = 8638,
27756 ["LeftUpVector"] = 8639,
27757 ["uharl"] = 8639,
27758 ["upharpoonleft"] = 8639,
27759 ["RightVector"] = 8640,
27760 ["rharu"] = 8640,
27761 ["rightharpoonup"] = 8640,
27762 ["DownRightVector"] = 8641,
27763 ["rhard"] = 8641,
27764 ["rightharpoondown"] = 8641,
27765 ["RightDownVector"] = 8642,
27766 ["dharr"] = 8642,
27767 ["downharpoonright"] = 8642,
27768 ["LeftDownVector"] = 8643,
27769 ["dharl"] = 8643,
27770 ["downharpoonleft"] = 8643,
27771 ["RightArrowLeftArrow"] = 8644,
27772 ["rightleftarrows"] = 8644,
27773 ["rlarr"] = 8644,
27774 ["UpArrowDownArrow"] = 8645,
27775 ["udarr"] = 8645,
27776 ["LeftArrowRightArrow"] = 8646,
27777 ["leftrightarrows"] = 8646,
27778 ["lrarr"] = 8646,
27779 ["leftleftarrows"] = 8647,
27780 ["llarr"] = 8647,
27781 ["upuparrows"] = 8648,
27782 ["uuarr"] = 8648,
27783 ["rightrightarrows"] = 8649,
27784 ["rrarr"] = 8649,
27785 ["ddarr"] = 8650,
27786 ["downdownarrows"] = 8650,
27787 ["ReverseEquilibrium"] = 8651,
27788 ["leftrightharpoons"] = 8651,
27789 ["lrhar"] = 8651,
27790 ["Equilibrium"] = 8652,
27791 ["rightleftharpoons"] = 8652,
27792 ["rlhar"] = 8652,
27793 ["nLeftarrow"] = 8653,
27794 ["nlArr"] = 8653,
27795 ["nLeftrightarrow"] = 8654,
27796 ["nhArr"] = 8654,
27797 ["nRightarrow"] = 8655,
27798 ["nrArr"] = 8655,
27799 ["DoubleLeftArrow"] = 8656,
27800 ["Leftarrow"] = 8656,
27801 ["lArr"] = 8656,
27802 ["DoubleUpArrow"] = 8657,
27803 ["Uparrow"] = 8657,
27804 ["uArr"] = 8657,
27805 ["DoubleRightArrow"] = 8658,
27806 ["Implies"] = 8658,
27807 ["Rightarrow"] = 8658,
27808 ["rArr"] = 8658,
27809 ["DoubleDownArrow"] = 8659,
27810 ["Downarrow"] = 8659,
27811 ["dArr"] = 8659,
27812 ["DoubleLeftRightArrow"] = 8660,
27813 ["Leftrightarrow"] = 8660,
27814 ["hArr"] = 8660,
27815 ["iff"] = 8660,
27816 ["DoubleUpDownArrow"] = 8661,
27817 ["Updownarrow"] = 8661,
27818 ["vArr"] = 8661,
27819 ["nwArr"] = 8662,
27820 ["neArr"] = 8663,
27821 ["seArr"] = 8664,
27822 ["swArr"] = 8665,
27823 ["Lleftarrow"] = 8666,
27824 ["lAarr"] = 8666,
27825 ["Rrightarrow"] = 8667,
27826 ["rAarr"] = 8667,
27827 ["zigrarr"] = 8669,
27828 ["LeftArrowBar"] = 8676,
27829 ["larrb"] = 8676,
27830 ["RightArrowBar"] = 8677,
27831 ["rarrb"] = 8677,
27832 ["DownArrowUpArrow"] = 8693,
27833 ["duarr"] = 8693,
27834 ["loarr"] = 8701,
27835 ["roarr"] = 8702,
27836 ["hoarr"] = 8703,
27837 ["ForAll"] = 8704,
27838 ["forall"] = 8704,
27839 ["comp"] = 8705,
27840 ["complement"] = 8705,
27841 ["PartialD"] = 8706,
27842 ["npart"] = {8706, 824},
27843 ["part"] = 8706,
27844 ["Exists"] = 8707,
27845 ["exist"] = 8707,
27846 ["NotExists"] = 8708,
27847 ["nexist"] = 8708,
27848 ["nexists"] = 8708,
27849 ["empty"] = 8709,
27850 ["emptyset"] = 8709,
27851 ["emptyv"] = 8709,
27852 ["varnothing"] = 8709,
27853 ["Del"] = 8711,
27854 ["nabla"] = 8711,
27855 ["Element"] = 8712,
27856 ["in"] = 8712,
27857 ["isin"] = 8712,
27858 ["isinv"] = 8712,
27859 ["NotElement"] = 8713,
27860 ["notin"] = 8713,
27861 ["notinva"] = 8713,
27862 ["ReverseElement"] = 8715,
27863 ["SuchThat"] = 8715,
27864 ["ni"] = 8715,
27865 ["niv"] = 8715,
27866 ["NotReverseElement"] = 8716,
27867 ["notni"] = 8716,
27868 ["notniva"] = 8716,
27869 ["Product"] = 8719,
27870 ["prod"] = 8719,
27871 ["Coproduct"] = 8720,
27872 ["coprod"] = 8720,
27873 ["Sum"] = 8721,
27874 ["sum"] = 8721,
27875 ["minus"] = 8722,
27876 ["MinusPlus"] = 8723,
27877 ["mnplus"] = 8723,
27878 ["mp"] = 8723,
27879 ["dotplus"] = 8724,
27880 ["plusdo"] = 8724,
27881 ["Backslash"] = 8726,
27882 ["setminus"] = 8726,
27883 ["setmn"] = 8726,
27884 ["smallsetminus"] = 8726,
27885 ["ssetmn"] = 8726,
27886 ["lowast"] = 8727,
27887 ["SmallCircle"] = 8728,
27888 ["compfn"] = 8728,
27889 ["Sqrt"] = 8730,
27890 ["radic"] = 8730,
27891 ["Proportional"] = 8733,
27892 ["prop"] = 8733,
27893 ["propto"] = 8733,
27894 ["varpropto"] = 8733,
27895 ["vprop"] = 8733,
27896 ["infin"] = 8734,
27897 ["angrt"] = 8735,
27898 ["ang"] = 8736,
27899 ["angle"] = 8736,
27900 ["nang"] = {8736, 8402},
27901 ["angmsd"] = 8737,
27902 ["measuredangle"] = 8737,
27903 ["angsph"] = 8738,
27904 ["VerticalBar"] = 8739,
27905 ["mid"] = 8739,
27906 ["shortmid"] = 8739,
27907 ["smid"] = 8739,
27908 ["NotVerticalBar"] = 8740,
27909 ["nmid"] = 8740,
27910 ["nshortmid"] = 8740,
27911 ["nsmid"] = 8740,
27912 ["DoubleVerticalBar"] = 8741,
27913 ["par"] = 8741,
27914 ["parallel"] = 8741,
27915 ["shortparallel"] = 8741,
27916 ["spar"] = 8741,
27917 ["NotDoubleVerticalBar"] = 8742,
27918 ["npar"] = 8742,
27919 ["nparallel"] = 8742,
27920 ["nshortparallel"] = 8742,
27921 ["nspar"] = 8742,
27922 ["and"] = 8743,
27923 ["wedge"] = 8743,
27924 ["or"] = 8744,
27925 ["vee"] = 8744,
27926 ["cap"] = 8745,
27927 ["caps"] = {8745, 65024},
27928 ["cup"] = 8746,
27929 ["cups"] = {8746, 65024},
27930 ["Integral"] = 8747,
27931 ["int"] = 8747,
27932 ["Int"] = 8748,
27933 ["iiint"] = 8749,
27934 ["tint"] = 8749,
27935 ["ContourIntegral"] = 8750,
27936 ["conint"] = 8750,
27937 ["oint"] = 8750,
27938 ["Conint"] = 8751,
27939 ["DoubleContourIntegral"] = 8751,
27940 ["Cconint"] = 8752,
27941 ["cwint"] = 8753,
27942 ["ClockwiseContourIntegral"] = 8754,
27943 ["cwconint"] = 8754,
27944 ["CounterClockwiseContourIntegral"] = 8755,
27945 ["awconint"] = 8755,
27946 ["Therefore"] = 8756,
27947 ["there4"] = 8756,
27948 ["therefore"] = 8756,
27949 ["Because"] = 8757,
27950 ["becaus"] = 8757,
27951 ["because"] = 8757,
27952 ["ratio"] = 8758,
27953 ["Colon"] = 8759,
27954 ["Proportion"] = 8759,
27955 ["dotminus"] = 8760,
27956 ["minusd"] = 8760,
27957 ["mDDot"] = 8762,
27958 ["homtht"] = 8763,
27959 ["Tilde"] = 8764,
27960 ["nvsim"] = {8764, 8402},
27961 ["sim"] = 8764,
27962 ["thicksim"] = 8764,
27963 ["thksim"] = 8764,
27964 ["backsim"] = 8765,
27965 ["bsim"] = 8765,
27966 ["race"] = {8765, 817},
27967 ["ac"] = 8766,
27968 ["acE"] = {8766, 819},
27969 ["mstpos"] = 8766,
27970 ["acd"] = 8767,
27971 ["VerticalTilde"] = 8768,
27972 ["wr"] = 8768,
27973 ["wreath"] = 8768,
27974 ["NotTilde"] = 8769,
27975 ["nsim"] = 8769,
27976 ["EqualTilde"] = 8770,
27977 ["NotEqualTilde"] = {8770, 824},
27978 ["eqsim"] = 8770,
27979 ["esim"] = 8770,
27980 ["nesim"] = {8770, 824},
27981 ["TildeEqual"] = 8771,
27982 ["sime"] = 8771,
27983 ["simeq"] = 8771,
27984 ["NotTildeEqual"] = 8772,
27985 ["nsime"] = 8772,
27986 ["nsimeq"] = 8772,
27987 ["TildeFullEqual"] = 8773,
27988 ["cong"] = 8773,
27989 ["simne"] = 8774,
27990 ["NotTildeFullEqual"] = 8775,
27991 ["ncong"] = 8775,
27992 ["TildeTilde"] = 8776,
27993 ["ap"] = 8776,
27994 ["approx"] = 8776,
27995 ["asymp"] = 8776,
27996 ["thickapprox"] = 8776,
27997 ["thkap"] = 8776,
27998 ["NotTildeTilde"] = 8777,
27999 ["nap"] = 8777,
28000 ["napprox"] = 8777,
28001 ["ape"] = 8778,
28002 ["approxeq"] = 8778,
28003 ["apid"] = 8779,
28004 ["napid"] = {8779, 824},
28005 ["backcong"] = 8780,
28006 ["bcong"] = 8780,
28007 ["CupCap"] = 8781,
28008 ["asympeq"] = 8781,
28009 ["nvap"] = {8781, 8402},
28010 ["Bumpeq"] = 8782,
28011 ["HumpDownHump"] = 8782,
28012 ["NotHumpDownHump"] = {8782, 824},
28013 ["bump"] = 8782,
28014 ["nbump"] = {8782, 824},
28015 ["HumpEqual"] = 8783,
28016 ["NotHumpEqual"] = {8783, 824},
28017 ["bumpe"] = 8783,
28018 ["bumpeq"] = 8783,
28019 ["nbumpe"] = {8783, 824},
28020 ["DotEqual"] = 8784,
28021 ["doteq"] = 8784,
28022 ["esdot"] = 8784,
28023 ["nedot"] = {8784, 824},
28024 ["doteqdot"] = 8785,
28025 ["eDot"] = 8785,
28026 ["efDot"] = 8786,
28027 ["fallingdotseq"] = 8786,
28028 ["erDot"] = 8787,
28029 ["risingdotseq"] = 8787,
28030 ["Assign"] = 8788,
28031 ["colone"] = 8788,
28032 ["coloneq"] = 8788,
28033 ["ecolon"] = 8789,
28034 ["eqcolon"] = 8789,
28035 ["ecir"] = 8790,
28036 ["eqcirc"] = 8790,
28037 ["circeq"] = 8791,
28038 ["cire"] = 8791,
28039 ["wedgeq"] = 8793,
28040 ["veeeq"] = 8794,
28041 ["triangleq"] = 8796,
28042 ["trie"] = 8796,
28043 ["equest"] = 8799,
28044 ["questeq"] = 8799,
28045 ["NotEqual"] = 8800,
28046 ["ne"] = 8800,
28047 ["Congruent"] = 8801,
28048 ["bnequiv"] = {8801, 8421},
28049 ["equiv"] = 8801,
28050 ["NotCongruent"] = 8802,
28051 ["nequiv"] = 8802,
28052 ["le"] = 8804,
28053 ["leq"] = 8804,
28054 ["nvle"] = {8804, 8402},
28055 ["GreaterEqual"] = 8805,
28056 ["ge"] = 8805,
28057 ["geq"] = 8805,
28058 ["nvge"] = {8805, 8402},
28059 ["LessFullEqual"] = 8806,
28060 ["lE"] = 8806,
28061 ["leqq"] = 8806,
28062 ["nlE"] = {8806, 824},
28063 ["nleqq"] = {8806, 824},
28064 ["GreaterFullEqual"] = 8807,
28065 ["NotGreaterFullEqual"] = {8807, 824},
28066 ["gE"] = 8807,
28067 ["geqq"] = 8807,
28068 ["ngE"] = {8807, 824},
28069 ["ngeqq"] = {8807, 824},
28070 ["lnE"] = 8808,
28071 ["lneqq"] = 8808,
28072 ["lvertneqq"] = {8808, 65024},
28073 ["lvnE"] = {8808, 65024},
28074 ["gnE"] = 8809,
28075 ["gneqq"] = 8809,
28076 ["gvertneqq"] = {8809, 65024},
28077 ["gvnE"] = {8809, 65024},
28078 ["Lt"] = 8810,
28079 ["NestedLessLess"] = 8810,
28080 ["NotLessLess"] = {8810, 824},
28081 ["ll"] = 8810,
28082 ["nLt"] = {8810, 8402},
28083 ["nLtv"] = {8810, 824},
28084 ["Gt"] = 8811,
28085 ["NestedGreaterGreater"] = 8811,
28086 ["NotGreaterGreater"] = {8811, 824},
28087 ["gg"] = 8811,
28088 ["nGt"] = {8811, 8402},
28089 ["nGtv"] = {8811, 824},
28090 ["between"] = 8812,
28091 ["twixt"] = 8812,
28092 ["NotCupCap"] = 8813,
28093 ["NotLess"] = 8814,
28094 ["nless"] = 8814,
28095 ["nlt"] = 8814,
28096 ["NotGreater"] = 8815,
28097 ["ngt"] = 8815,
28098 ["ngtr"] = 8815,
28099 ["NotLessEqual"] = 8816,
28100 ["nle"] = 8816,
28101 ["nleq"] = 8816,
28102 ["NotGreaterEqual"] = 8817,
28103 ["nge"] = 8817,
28104 ["ngeq"] = 8817,
28105 ["LessTilde"] = 8818,
28106 ["lesssim"] = 8818,
28107 ["lsim"] = 8818,
28108 ["GreaterTilde"] = 8819,
28109 ["gsim"] = 8819,
28110 ["gtrsim"] = 8819,
28111 ["NotLessTilde"] = 8820,
28112 ["nlsim"] = 8820,
28113 ["NotGreaterTilde"] = 8821,
28114 ["ngsim"] = 8821,
28115 ["LessGreater"] = 8822,
28116 ["lessgtr"] = 8822,
28117 ["lg"] = 8822,
28118 ["GreaterLess"] = 8823,
28119 ["gl"] = 8823,
28120 ["gtrless"] = 8823,
28121 ["NotLessGreater"] = 8824,
28122 ["ntlg"] = 8824,
28123 ["NotGreaterLess"] = 8825,
28124 ["ntgl"] = 8825,
28125 ["Precedes"] = 8826,
28126 ["pr"] = 8826,
28127 ["prec"] = 8826,
28128 ["Succeeds"] = 8827,
28129 ["sc"] = 8827,
28130 ["succ"] = 8827,
28131 ["PrecedesSlantEqual"] = 8828,
28132 ["prcue"] = 8828,
28133 ["preccurlyeq"] = 8828,
28134 ["SucceedsSlantEqual"] = 8829,
28135 ["sccue"] = 8829,
28136 ["succcurlyeq"] = 8829,
28137 ["PrecedesTilde"] = 8830,
28138 ["precsim"] = 8830,
28139 ["prsim"] = 8830,
28140 ["NotSucceedsTilde"] = {8831, 824},
28141 ["SucceedsTilde"] = 8831,
28142 ["scsim"] = 8831,
28143 ["succsim"] = 8831,
28144 ["NotPrecedes"] = 8832,
28145 ["npr"] = 8832,
28146 ["nprec"] = 8832,
28147 ["NotSucceeds"] = 8833,
28148 ["nsc"] = 8833,
28149 ["nsucc"] = 8833,
28150 ["NotSubset"] = {8834, 8402},
28151 ["nsubset"] = {8834, 8402},
28152 ["sub"] = 8834,
28153 ["subset"] = 8834,
28154 ["vnsub"] = {8834, 8402},
28155 ["NotSuperset"] = {8835, 8402},
28156 ["Superset"] = 8835,
28157 ["nsupset"] = {8835, 8402},
28158 ["sup"] = 8835,
28159 ["supset"] = 8835,
28160 ["vnsup"] = {8835, 8402},
28161 ["nsub"] = 8836,
28162 ["nsup"] = 8837,
28163 ["SubsetEqual"] = 8838,
28164 ["sube"] = 8838,
28165 ["subseteq"] = 8838,
28166 ["SupersetEqual"] = 8839,
28167 ["supe"] = 8839,
28168 ["supseteq"] = 8839,
28169 ["NotSubsetEqual"] = 8840,
28170 ["nsube"] = 8840,
28171 ["nsubseteq"] = 8840,
28172 ["NotSupersetEqual"] = 8841,
28173 ["nsupe"] = 8841,
28174 ["nsupseteq"] = 8841,
28175 ["subne"] = 8842,
28176 ["subsetneq"] = 8842,
28177 ["varsubsetneq"] = {8842, 65024},
28178 ["vsubne"] = {8842, 65024},
28179 ["supne"] = 8843,
28180 ["supsetneq"] = 8843,
28181 ["varsupsetneq"] = {8843, 65024},
28182 ["vsupne"] = {8843, 65024},
28183 ["cupdot"] = 8845,
28184 ["UnionPlus"] = 8846,
28185 ["uplus"] = 8846,
28186 ["NotSquareSubset"] = {8847, 824},
28187 ["SquareSubset"] = 8847,
28188 ["sqsub"] = 8847,
28189 ["sqsubset"] = 8847,
28190 ["NotSquareSuperset"] = {8848, 824},
28191 ["SquareSuperset"] = 8848,
28192 ["sqsup"] = 8848,
28193 ["sqsupset"] = 8848,
28194 ["SquareSubsetEqual"] = 8849,
28195 ["sqsube"] = 8849,
28196 ["sqsubseteq"] = 8849,
28197 ["SquareSupersetEqual"] = 8850,
28198 ["sqsupe"] = 8850,
28199 ["sqsupseteq"] = 8850,
28200 ["SquareIntersection"] = 8851,
28201 ["sqcap"] = 8851,
28202 ["sqcaps"] = {8851, 65024},
28203 ["SquareUnion"] = 8852,
28204 ["sqcup"] = 8852,
28205 ["sqcups"] = {8852, 65024},
28206 ["CirclePlus"] = 8853,
28207 ["oplus"] = 8853,
28208 ["CircleMinus"] = 8854,
28209 ["ominus"] = 8854,
28210 ["CircleTimes"] = 8855,
28211 ["otimes"] = 8855,
28212 ["osol"] = 8856,
28213 ["CircleDot"] = 8857,
28214 ["odot"] = 8857,
28215 ["circledcirc"] = 8858,
28216 ["ocir"] = 8858,
28217 ["circledast"] = 8859,
28218 ["oast"] = 8859,
28219 ["circleddash"] = 8861,
28220 ["odash"] = 8861,
28221 ["boxplus"] = 8862,
28222 ["plusb"] = 8862,
28223 ["boxminus"] = 8863,
28224 ["minusb"] = 8863,
28225 ["boxtimes"] = 8864,
28226 ["timesb"] = 8864,
28227 ["dotsquare"] = 8865,
28228 ["sdotb"] = 8865,
28229 ["RightTee"] = 8866,
28230 ["vdash"] = 8866,
28231 ["LeftTee"] = 8867,
28232 ["dashv"] = 8867,
28233 ["DownTee"] = 8868,
28234 ["top"] = 8868,
28235 ["UpTee"] = 8869,
28236 ["bot"] = 8869,
28237 ["bottom"] = 8869,
28238 ["perp"] = 8869,
28239 ["models"] = 8871,
28240 ["DoubleRightTee"] = 8872,
28241 ["vDash"] = 8872,
28242 ["Vdash"] = 8873,
28243 ["Vvdash"] = 8874,
28244 ["VDash"] = 8875,
28245 ["nvdash"] = 8876,
28246 ["nvDash"] = 8877,
28247 ["nVdash"] = 8878,
28248 ["nVDash"] = 8879,
28249 ["prurel"] = 8880,
28250 ["LeftTriangle"] = 8882,
28251 ["vartriangleleft"] = 8882,
28252 ["vltri"] = 8882,
28253 ["RightTriangle"] = 8883,
28254 ["vartriangleright"] = 8883,
28255 ["vrtri"] = 8883,
28256 ["LeftTriangleEqual"] = 8884,
28257 ["ltrie"] = 8884,
28258 ["nvltrie"] = {8884, 8402},
28259 ["trianglelefteq"] = 8884,
28260 ["RightTriangleEqual"] = 8885,
28261 ["nvrtrie"] = {8885, 8402},
28262 ["rtrie"] = 8885,
28263 ["trianglerighteq"] = 8885,
28264 ["origof"] = 8886,
28265 ["imof"] = 8887,
28266 ["multimap"] = 8888,
28267 ["mumap"] = 8888,
28268 ["hercon"] = 8889,
28269 ["intcal"] = 8890,
28270 ["intercal"] = 8890,
28271 ["veebar"] = 8891,
28272 ["barvee"] = 8893,
28273 ["angrtvb"] = 8894,
28274 ["lrtri"] = 8895,
28275 ["Wedge"] = 8896,
28276 ["bigwedge"] = 8896,
28277 ["xwedge"] = 8896,
28278 ["Vee"] = 8897,
28279 ["bigvee"] = 8897,
28280 ["xvee"] = 8897,
28281 ["Intersection"] = 8898,
28282 ["bigcap"] = 8898,
28283 ["xcap"] = 8898,
28284 ["Union"] = 8899,
28285 ["bigcup"] = 8899,
28286 ["xcup"] = 8899,
28287 ["Diamond"] = 8900,
28288 ["diam"] = 8900,
28289 ["diamond"] = 8900,
28290 ["sdot"] = 8901,
28291 ["Star"] = 8902,
28292 ["sstarf"] = 8902,
28293 ["divideontimes"] = 8903,
28294 ["divonx"] = 8903,
28295 ["bowtie"] = 8904,
28296 ["ltimes"] = 8905,
28297 ["rtimes"] = 8906,
28298 ["leftthreetimes"] = 8907,
28299 ["lthree"] = 8907,
28300 ["rightthreetimes"] = 8908,
28301 ["rthree"] = 8908,
28302 ["backsimeq"] = 8909,
28303 ["bsime"] = 8909,
28304 ["curlyvee"] = 8910,
28305 ["cuvee"] = 8910,
28306 ["curlywedge"] = 8911,
28307 ["cuwed"] = 8911,
28308 ["Sub"] = 8912,
28309 ["Subset"] = 8912,
28310 ["Sup"] = 8913,
28311 ["Supset"] = 8913,
28312 ["Cap"] = 8914,
28313 ["Cup"] = 8915,
28314 ["fork"] = 8916,
28315 ["pitchfork"] = 8916,
28316 ["epar"] = 8917,
28317 ["lessdot"] = 8918,
28318 ["ltdot"] = 8918,
28319 ["gtdot"] = 8919,
28320 ["gtrdot"] = 8919,
28321 ["Ll"] = 8920,
28322 ["nLl"] = {8920, 824},
28323 ["Gg"] = 8921,
28324 ["ggg"] = 8921,
28325 ["nGg"] = {8921, 824},
28326 ["LessEqualGreater"] = 8922,
28327 ["leg"] = 8922,
28328 ["lesg"] = {8922, 65024},
28329 ["lesseqgtr"] = 8922,
28330 ["GreaterEqualLess"] = 8923,
28331 ["gel"] = 8923,
28332 ["gesl"] = {8923, 65024},
28333 ["gtreqless"] = 8923,
28334 ["cuepr"] = 8926,
28335 ["curlyeqprec"] = 8926,
28336 ["cuesc"] = 8927,
28337 ["curlyeqsucc"] = 8927,
28338 ["NotPrecedesSlantEqual"] = 8928,
28339 ["nprcue"] = 8928,
28340 ["NotSucceedsSlantEqual"] = 8929,
28341 ["nsccue"] = 8929,
28342 ["NotSquareSubsetEqual"] = 8930,
28343 ["nsqsube"] = 8930,
28344 ["NotSquareSupersetEqual"] = 8931,
28345 ["nsqsupe"] = 8931,
28346 ["lnsim"] = 8934,
28347 ["gnsim"] = 8935,
28348 ["precnsim"] = 8936,
28349 ["prnsim"] = 8936,
28350 ["scnsim"] = 8937,
28351 ["succnsim"] = 8937,
28352 ["NotLeftTriangle"] = 8938,
28353 ["nltri"] = 8938,
28354 ["ntriangleleft"] = 8938,
28355 ["NotRightTriangle"] = 8939,
28356 ["nrtri"] = 8939,
28357 ["ntriangleright"] = 8939,
28358 ["NotLeftTriangleEqual"] = 8940,
28359 ["nltrie"] = 8940,
28360 ["ntrianglelefteq"] = 8940,
28361 ["NotRightTriangleEqual"] = 8941,
28362 ["nrtrie"] = 8941,
28363 ["ntrianglerighteq"] = 8941,
28364 ["vellip"] = 8942,
28365 ["ctdot"] = 8943,
28366 ["utdot"] = 8944,
28367 ["dtdot"] = 8945,
28368 ["disin"] = 8946,
28369 ["isinsv"] = 8947,
28370 ["isins"] = 8948,
28371 ["isindot"] = 8949,
28372 ["notindot"] = {8949, 824},
28373 ["notinvc"] = 8950,
28374 ["notinvb"] = 8951,
28375 ["isinE"] = 8953,
28376 ["notinE"] = {8953, 824},
28377 ["nisd"] = 8954,
28378 ["xnis"] = 8955,
28379 ["nis"] = 8956,
28380 ["notnivc"] = 8957,
28381 ["notnivb"] = 8958,
28382 ["barwed"] = 8965,
28383 ["barwedge"] = 8965,
28384 ["Barwed"] = 8966,
28385 ["doublebarwedge"] = 8966,
28386 ["LeftCeiling"] = 8968,
28387 ["lceil"] = 8968,
28388 ["RightCeiling"] = 8969,
28389 ["rceil"] = 8969,
28390 ["LeftFloor"] = 8970,
28391 ["lfloor"] = 8970,
28392 ["RightFloor"] = 8971,
28393 ["rfloor"] = 8971,
28394 ["drcrop"] = 8972,
28395 ["dlcrop"] = 8973,
28396 ["urcrop"] = 8974,
28397 ["ulcrop"] = 8975,
28398 ["bnot"] = 8976,
28399 ["profline"] = 8978,
28400 ["profsurf"] = 8979,
28401 ["telrec"] = 8981,
28402 ["target"] = 8982,
28403 ["ulcorn"] = 8988,
28404 ["ulcorner"] = 8988,
28405 ["urcorn"] = 8989,
28406 ["urcorner"] = 8989,
28407 ["dlcorn"] = 8990,
28408 ["llcorner"] = 8990,
28409 ["drcorn"] = 8991,
28410 ["lrcorner"] = 8991,
28411 ["frown"] = 8994,
28412 ["sfrown"] = 8994,
28413 ["smile"] = 8995,
28414 ["ssmile"] = 8995,
28415 ["cylcty"] = 9005,
28416 ["profalar"] = 9006,
28417 ["topbot"] = 9014,
28418 ["ovbar"] = 9021,
28419 ["solbar"] = 9023,
28420 ["angzarr"] = 9084,
28421 ["lmoust"] = 9136,
28422 ["lmoustache"] = 9136,
28423 ["rmoust"] = 9137,
28424 ["rmoustache"] = 9137,
28425 ["OverBracket"] = 9140,
28426 ["tbrk"] = 9140,
28427 ["UnderBracket"] = 9141,
28428 ["bbrk"] = 9141,
28429 ["bbrktbrk"] = 9142,
28430 ["OverParenthesis"] = 9180,
28431 ["UnderParenthesis"] = 9181,
28432 ["OverBrace"] = 9182,
28433 ["UnderBrace"] = 9183,
28434 ["trpezium"] = 9186,
28435 ["elinters"] = 9191,
28436 ["blank"] = 9251,
28437 ["circledS"] = 9416,
28438 ["oS"] = 9416,
28439 ["HorizontalLine"] = 9472,
28440 ["boxh"] = 9472,
28441 ["boxv"] = 9474,
28442 ["boxdr"] = 9484,
28443 ["boxdl"] = 9488,
28444 ["boxur"] = 9492,
28445 ["boxul"] = 9496,
28446 ["boxvr"] = 9500,
28447 ["boxvl"] = 9508,
28448 ["boxhd"] = 9516,
28449 ["boxhu"] = 9524,
28450 ["boxvh"] = 9532,
28451 ["boxH"] = 9552,
28452 ["boxV"] = 9553,
28453 ["boxdR"] = 9554,
28454 ["boxDr"] = 9555,
28455 ["boxDR"] = 9556,
28456 ["boxdL"] = 9557,
28457 ["boxDl"] = 9558,
28458 ["boxDL"] = 9559,
28459 ["boxuR"] = 9560,
28460 ["boxUr"] = 9561,
28461 ["boxUR"] = 9562,
28462 ["boxuL"] = 9563,
28463 ["boxUl"] = 9564,
28464 ["boxUL"] = 9565,
28465 ["boxvR"] = 9566,
28466 ["boxVr"] = 9567,
28467 ["boxVR"] = 9568,
28468 ["boxvL"] = 9569,
28469 ["boxVl"] = 9570,
28470 ["boxVL"] = 9571,
28471 ["boxHd"] = 9572,
28472 ["boxhD"] = 9573,
28473 ["boxHD"] = 9574,
28474 ["boxHu"] = 9575,
28475 ["boxhU"] = 9576,
28476 ["boxHU"] = 9577,
28477 ["boxvH"] = 9578,
28478 ["boxVh"] = 9579,
28479 ["boxVH"] = 9580,
28480 ["uhblk"] = 9600,
28481 ["lhblk"] = 9604,
28482 ["block"] = 9608,
28483 ["blk14"] = 9617,
28484 ["blk12"] = 9618,
28485 ["blk34"] = 9619,
28486 ["Square"] = 9633,
28487 ["squ"] = 9633,
28488 ["square"] = 9633,
28489 ["FilledVerySmallSquare"] = 9642,
28490 ["blacksquare"] = 9642,
28491 ["squarf"] = 9642,
28492 ["squf"] = 9642,
28493 ["EmptyVerySmallSquare"] = 9643,
28494 ["rect"] = 9645,
28495 ["marker"] = 9646,
28496 ["fltns"] = 9649,
28497 ["bigtriangleup"] = 9651,
28498 ["xutri"] = 9651,
28499 ["blacktriangle"] = 9652,
28500 ["utrif"] = 9652,
28501 ["triangle"] = 9653,
28502 ["utri"] = 9653,
28503 ["blacktriangleright"] = 9656,
28504 ["rtrif"] = 9656,
28505 ["rtri"] = 9657,
28506 ["triangleright"] = 9657,
28507 ["bigtriangledown"] = 9661,
28508 ["xdtri"] = 9661,
28509 ["blacktriangledown"] = 9662,
28510 ["dtrif"] = 9662,
28511 ["dtri"] = 9663,
28512 ["triangledown"] = 9663,
28513 ["blacktriangleleft"] = 9666,
28514 ["ltrif"] = 9666,
28515 ["ltri"] = 9667,
28516 ["triangleleft"] = 9667,
28517 ["loz"] = 9674,
28518 ["lozenge"] = 9674,
28519 ["cir"] = 9675,
28520 ["tridot"] = 9708,
28521 ["bigcirc"] = 9711,
28522 ["xcirc"] = 9711,
28523 ["ultri"] = 9720,
28524 ["urtri"] = 9721,
28525 ["lltri"] = 9722,
28526 ["EmptySmallSquare"] = 9723,
28527 ["FilledSmallSquare"] = 9724,
28528 ["bigstar"] = 9733,
28529 ["starf"] = 9733,
28530 ["star"] = 9734,
28531 ["phone"] = 9742,
28532 ["female"] = 9792,
28533 ["male"] = 9794,
28534 ["spades"] = 9824,
28535 ["spadesuit"] = 9824,
28536 ["clubs"] = 9827,
28537 ["clubsuit"] = 9827,
28538 ["hearts"] = 9829,
28539 ["heartsuit"] = 9829,
28540 ["diamondsuit"] = 9830,
28541 ["diams"] = 9830,
28542 ["sung"] = 9834,
28543 ["flat"] = 9837,
28544 ["natur"] = 9838,
28545 ["natural"] = 9838,
28546 ["sharp"] = 9839,
28547 ["check"] = 10003,
28548 ["checkmark"] = 10003,
28549 ["cross"] = 10007,
28550 ["malt"] = 10016,
28551 ["maltese"] = 10016,
28552 ["sext"] = 10038,
28553 ["VerticalSeparator"] = 10072,
28554 ["lbbrk"] = 10098,
28555 ["rbbrk"] = 10099,
28556 ["bsolhsub"] = 10184,
28557 ["suphsol"] = 10185,
28558 ["LeftDoubleBracket"] = 10214,
28559 ["lobrk"] = 10214,
28560 ["RightDoubleBracket"] = 10215,
28561 ["robrk"] = 10215,
28562 ["LeftAngleBracket"] = 10216,
28563 ["lang"] = 10216,
28564 ["langle"] = 10216,
28565 ["RightAngleBracket"] = 10217,
28566 ["rang"] = 10217,
28567 ["rangle"] = 10217,
28568 ["Lang"] = 10218,
28569 ["Rang"] = 10219,
28570 ["loang"] = 10220,
28571 ["roang"] = 10221,
28572 ["LongLeftArrow"] = 10229,
28573 ["longleftarrow"] = 10229,
28574 ["xlarr"] = 10229,
28575 ["LongRightArrow"] = 10230,
28576 ["longrightarrow"] = 10230,
28577 ["xrarr"] = 10230,
28578 ["LongLeftRightArrow"] = 10231,
28579 ["longleftrightarrow"] = 10231,
28580 ["xharr"] = 10231,
28581 ["DoubleLongLeftArrow"] = 10232,
28582 ["Longleftarrow"] = 10232,
28583 ["xlArr"] = 10232,
28584 ["DoubleLongRightArrow"] = 10233,
28585 ["Longrightarrow"] = 10233,
28586 ["xrArr"] = 10233,
28587 ["DoubleLongLeftRightArrow"] = 10234,
28588 ["Longleftrightarrow"] = 10234,
28589 ["xhArr"] = 10234,
28590 ["longmapsto"] = 10236,
28591 ["xmap"] = 10236,
28592 ["dzigrarr"] = 10239,
28593 ["nvlArr"] = 10498,
28594 ["nvrArr"] = 10499,
28595 ["nvHarr"] = 10500,
28596 ["Map"] = 10501,
28597 ["lbarr"] = 10508,
28598 ["bkarow"] = 10509,
28599 ["rbarr"] = 10509,
28600 ["lBarr"] = 10510,
28601 ["dbkarow"] = 10511,
28602 ["rBarr"] = 10511,
28603 ["RBarr"] = 10512,
28604 ["drbkarow"] = 10512,
28605 ["DDotrahd"] = 10513,
28606 ["UpArrowBar"] = 10514,
28607 ["DownArrowBar"] = 10515,
28608 ["Rarrtl"] = 10518,
28609 ["latail"] = 10521,
28610 ["ratail"] = 10522,
28611 ["lAtail"] = 10523,
28612 ["rAtail"] = 10524,
28613 ["larrfs"] = 10525,
28614 ["rarrfs"] = 10526,
28615 ["larrbfs"] = 10527,
28616 ["rarrbfs"] = 10528,
28617 ["nwarhk"] = 10531,
28618 ["nearhk"] = 10532,
28619 ["hksearow"] = 10533,
28620 ["searhk"] = 10533,
28621 ["hkswarow"] = 10534,
28622 ["swarhk"] = 10534,
28623 ["nwnear"] = 10535,
28624 ["nesear"] = 10536,
28625 ["toea"] = 10536,
28626 ["seswar"] = 10537,
28627 ["tosa"] = 10537,
28628 ["swnwar"] = 10538,
28629 ["nrarrc"] = {10547, 824},
28630 ["rarrc"] = 10547,
28631 ["cudarrr"] = 10549,
28632 ["ldca"] = 10550,
28633 ["rdca"] = 10551,
28634 ["cudarrl"] = 10552,
28635 ["larrpl"] = 10553,
28636 ["curarrm"] = 10556,
28637 ["cularrp"] = 10557,
28638 ["rarrpl"] = 10565,
28639 ["harrcir"] = 10568,
28640 ["Uarrocir"] = 10569,
28641 ["lurdshar"] = 10570,
28642 ["ldrushar"] = 10571,
28643 ["LeftRightVector"] = 10574,
28644 ["RightUpDownVector"] = 10575,
28645 ["DownLeftRightVector"] = 10576,
28646 ["LeftUpDownVector"] = 10577,
28647 ["LeftVectorBar"] = 10578,
28648 ["RightVectorBar"] = 10579,
28649 ["RightUpVectorBar"] = 10580,
28650 ["RightDownVectorBar"] = 10581,
28651 ["DownLeftVectorBar"] = 10582,
28652 ["DownRightVectorBar"] = 10583,
28653 ["LeftUpVectorBar"] = 10584,
28654 ["LeftDownVectorBar"] = 10585,
28655 ["LeftTeeVector"] = 10586,
28656 ["RightTeeVector"] = 10587,
28657 ["RightUpTeeVector"] = 10588,
28658 ["RightDownTeeVector"] = 10589,
28659 ["DownLeftTeeVector"] = 10590,
28660 ["DownRightTeeVector"] = 10591,
28661 ["LeftUpTeeVector"] = 10592,
28662 ["LeftDownTeeVector"] = 10593,
28663 ["lHar"] = 10594,
28664 ["uHar"] = 10595,
28665 ["rHar"] = 10596,
28666 ["dHar"] = 10597,
28667 ["luruhar"] = 10598,
28668 ["ldrdhar"] = 10599,
28669 ["ruluhar"] = 10600,
28670 ["rdldhar"] = 10601,
28671 ["lharul"] = 10602,
28672 ["llhard"] = 10603,
28673 ["rharul"] = 10604,
28674 ["lrhard"] = 10605,
28675 ["UpEquilibrium"] = 10606,
28676 ["udhar"] = 10606,
28677 ["ReverseUpEquilibrium"] = 10607,
28678 ["duhar"] = 10607,
28679 ["RoundImplies"] = 10608,
28680 ["erarr"] = 10609,
28681 ["simrarr"] = 10610,
28682 ["larrsim"] = 10611,
28683 ["rarrsim"] = 10612,
28684 ["rarrap"] = 10613,
28685 ["ltlarr"] = 10614,
28686 ["gtrarr"] = 10616,
28687 ["subrarr"] = 10617,
28688 ["suplarr"] = 10619,
28689 ["lfisht"] = 10620,
28690 ["rfisht"] = 10621,
28691 ["ufisht"] = 10622,
28692 ["dfisht"] = 10623,
28693 ["lopar"] = 10629,
28694 ["ropar"] = 10630,
28695 ["lbrke"] = 10635,
28696 ["rbrke"] = 10636,
28697 ["lbrkslu"] = 10637,
28698 ["rbrksld"] = 10638,
28699 ["lbrksld"] = 10639,
28700 ["rbrkslu"] = 10640,
28701 ["langd"] = 10641,
28702 ["rangd"] = 10642,
28703 ["lparlt"] = 10643,
28704 ["rpargt"] = 10644,
28705 ["gtlPar"] = 10645,
28706 ["ltrPar"] = 10646,
28707 ["vzigzag"] = 10650,
28708 ["vangrt"] = 10652,
28709 ["angrtvbd"] = 10653,
28710 ["ange"] = 10660,
28711 ["range"] = 10661,
28712 ["dwangle"] = 10662,
28713 ["uwangle"] = 10663,
28714 ["angmsdaa"] = 10664,
28715 ["angmsdab"] = 10665,
28716 ["angmsdac"] = 10666,
28717 ["angmsdad"] = 10667,
28718 ["angmsdae"] = 10668,
28719 ["angmsdaf"] = 10669,
28720 ["angmsdag"] = 10670,
28721 ["angmsdah"] = 10671,
28722 ["bemptyv"] = 10672,
28723 ["demptyv"] = 10673,
28724 ["cemptyv"] = 10674,
28725 ["raemptyv"] = 10675,
28726 ["laemptyv"] = 10676,
28727 ["ohbar"] = 10677,
28728 ["omid"] = 10678,
28729 ["opar"] = 10679,
28730 ["operp"] = 10681,
28731 ["olcross"] = 10683,
28732 ["odsold"] = 10684,
28733 ["olcir"] = 10686,
28734 ["ofcir"] = 10687,
28735 ["olt"] = 10688,
28736 ["ogt"] = 10689,
28737 ["cirscir"] = 10690,
28738 ["cirE"] = 10691,
28739 ["solb"] = 10692,
28740 ["bsolb"] = 10693,
28741 ["boxbox"] = 10697,
28742 ["trisb"] = 10701,
28743 ["rtriltri"] = 10702,
28744 ["LeftTriangleBar"] = 10703,
28745 ["NotLeftTriangleBar"] = {10703, 824},
28746 ["NotRightTriangleBar"] = {10704, 824},
28747 ["RightTriangleBar"] = 10704,
28748 ["iinfin"] = 10716,
28749 ["infintie"] = 10717,
28750 ["nvinfin"] = 10718,
28751 ["eparsl"] = 10723,
28752 ["smeparsl"] = 10724,
28753 ["eqvparsl"] = 10725,
28754 ["blacklozenge"] = 10731,
28755 ["lozf"] = 10731,
28756 ["RuleDelayed"] = 10740,
28757 ["dsol"] = 10742,
28758 ["bigodot"] = 10752,
28759 ["xodot"] = 10752,
28760 ["bigoplus"] = 10753,
28761 ["xoplus"] = 10753,
28762 ["bigotimes"] = 10754,
28763 ["xotime"] = 10754,
28764 ["biguplus"] = 10756,
28765 ["xuplus"] = 10756,
28766 ["bigsqcup"] = 10758,
28767 ["xsqcup"] = 10758,
28768 ["iiiint"] = 10764,
28769 ["qint"] = 10764,
28770 ["fpartint"] = 10765,
28771 ["cirfnint"] = 10768,
28772 ["awint"] = 10769,
28773 ["rppolint"] = 10770,
28774 ["scpolint"] = 10771,
28775 ["npolint"] = 10772,
28776 ["pointint"] = 10773,
28777 ["quatint"] = 10774,
28778 ["intlarhk"] = 10775,
28779 ["pluscir"] = 10786,
28780 ["plusacir"] = 10787,
28781 ["simplus"] = 10788,
28782 ["plusdu"] = 10789,
28783 ["plussim"] = 10790,
28784 ["plustwo"] = 10791,
28785 ["mcomma"] = 10793,
28786 ["minusdu"] = 10794,
28787 ["loplus"] = 10797,
28788 ["roplus"] = 10798,
28789 ["Cross"] = 10799,
28790 ["timesd"] = 10800,
28791 ["timesbar"] = 10801,
28792 ["smashp"] = 10803,
28793 ["lotimes"] = 10804,
28794 ["rotimes"] = 10805,
28795 ["otimesas"] = 10806,
28796 ["Otimes"] = 10807,
28797 ["odiv"] = 10808,
28798 ["triplus"] = 10809,
28799 ["triminus"] = 10810,
28800 ["tritime"] = 10811,
28801 ["intprod"] = 10812,
28802 ["iprod"] = 10812,
28803 ["amalg"] = 10815,
28804 ["capdot"] = 10816,
28805 ["ncup"] = 10818,
28806 ["ncap"] = 10819,
28807 ["capand"] = 10820,
28808 ["cupor"] = 10821,
28809 ["cupcap"] = 10822,
28810 ["capcup"] = 10823,
28811 ["cupbrcap"] = 10824,
28812 ["capbrcup"] = 10825,
28813 ["cupcup"] = 10826,
28814 ["capcap"] = 10827,
28815 ["ccups"] = 10828,
28816 ["ccaps"] = 10829,
28817 ["ccupssm"] = 10832,
28818 ["And"] = 10835,
28819 ["Or"] = 10836,
28820 ["andand"] = 10837,
28821 ["oror"] = 10838,
28822 ["orslope"] = 10839,
28823 ["andslope"] = 10840,
28824 ["andv"] = 10842,
28825 ["orv"] = 10843,
28826 ["andd"] = 10844,
28827 ["ord"] = 10845,
28828 ["wedbar"] = 10847,
28829 ["sdote"] = 10854,
28830 ["simdot"] = 10858,
28831 ["congdot"] = 10861,
28832 ["ncongdot"] = {10861, 824},
28833 ["easter"] = 10862,
28834 ["apacir"] = 10863,
28835 ["apE"] = 10864,
28836 ["napE"] = {10864, 824},
28837 ["eplus"] = 10865,
28838 ["pluse"] = 10866,
28839 ["Esim"] = 10867,
28840 ["Colone"] = 10868,
28841 ["Equal"] = 10869,
28842 ["ddotseq"] = 10871,
28843 ["eDDot"] = 10871,
28844 ["equivDD"] = 10872,
28845 ["ltcir"] = 10873,
28846 ["gtcir"] = 10874,
28847 ["ltquest"] = 10875,
28848 ["gtquest"] = 10876,
28849 ["LessSlantEqual"] = 10877,
28850 ["NotLessSlantEqual"] = {10877, 824},
28851 ["leqslant"] = 10877,
28852 ["les"] = 10877,
28853 ["nleqslant"] = {10877, 824},
28854 ["nles"] = {10877, 824},
28855 ["GreaterSlantEqual"] = 10878,
28856 ["NotGreaterSlantEqual"] = {10878, 824},
28857 ["geqslant"] = 10878,
28858 ["ges"] = 10878,
28859 ["ngeqslant"] = {10878, 824},
28860 ["nges"] = {10878, 824},
28861 ["lesdot"] = 10879,
28862 ["gesdot"] = 10880,
28863 ["lesdoto"] = 10881,
28864 ["gesdoto"] = 10882,
28865 ["lesdotor"] = 10883,
28866 ["gesdotol"] = 10884,
28867 ["lap"] = 10885,
28868 ["lessapprox"] = 10885,
28869 ["gap"] = 10886,
28870 ["gtrapprox"] = 10886,
28871 ["lne"] = 10887,
28872 ["lneq"] = 10887,
28873 ["gne"] = 10888,
28874 ["gneq"] = 10888,
28875 ["lnap"] = 10889,
28876 ["lnapprox"] = 10889,
28877 ["gnap"] = 10890,
28878 ["gnapprox"] = 10890,
28879 ["lEg"] = 10891,
28880 ["lesseqqgtr"] = 10891,
28881 ["gEl"] = 10892,
28882 ["gtreqqless"] = 10892,
28883 ["lsime"] = 10893,
28884 ["gsime"] = 10894,
28885 ["lsimg"] = 10895,
28886 ["gsiml"] = 10896,
28887 ["lgE"] = 10897,
28888 ["glE"] = 10898,
28889 ["lesges"] = 10899,
28890 ["gesles"] = 10900,
28891 ["els"] = 10901,
28892 ["eqslantless"] = 10901,
28893 ["egs"] = 10902,
28894 ["eqslantgtr"] = 10902,
28895 ["elsdot"] = 10903,
28896 ["egsdot"] = 10904,
28897 ["el"] = 10905,
28898 ["eg"] = 10906,
28899 ["siml"] = 10909,
28900 ["simg"] = 10910,
28901 ["simlE"] = 10911,
28902 ["simgE"] = 10912,
28903 ["LessLess"] = 10913,
28904 ["NotNestedLessLess"] = {10913, 824},
28905 ["GreaterGreater"] = 10914,
28906 ["NotNestedGreaterGreater"] = {10914, 824},
28907 ["glj"] = 10916,
28908 ["gla"] = 10917,
28909 ["ltcc"] = 10918,
28910 ["gtcc"] = 10919,
28911 ["lescc"] = 10920,
28912 ["gescc"] = 10921,
28913 ["smt"] = 10922,
28914 ["lat"] = 10923,
28915 ["smte"] = 10924,
28916 ["smtes"] = {10924, 65024},
28917 ["late"] = 10925,
28918 ["lates"] = {10925, 65024},
28919 ["bumpE"] = 10926,
28920 ["NotPrecedesEqual"] = {10927, 824},
28921 ["PrecedesEqual"] = 10927,
28922 ["npre"] = {10927, 824},
28923 ["npreceq"] = {10927, 824},
28924 ["pre"] = 10927,
28925 ["preceq"] = 10927,
28926 ["NotSucceedsEqual"] = {10928, 824},
28927 ["SucceedsEqual"] = 10928,
28928 ["nsce"] = {10928, 824},
28929 ["nsucceq"] = {10928, 824},
28930 ["sce"] = 10928,
28931 ["succeq"] = 10928,
28932 ["prE"] = 10931,
28933 ["scE"] = 10932,
28934 ["precneqq"] = 10933,
28935 ["prnE"] = 10933,
28936 ["scnE"] = 10934,
28937 ["succneqq"] = 10934,
28938 ["prap"] = 10935,
28939 ["precapprox"] = 10935,
28940 ["scap"] = 10936,
28941 ["succapprox"] = 10936,
28942 ["precnapprox"] = 10937,
28943 ["prnap"] = 10937,
28944 ["scnap"] = 10938,
28945 ["succnapprox"] = 10938,
28946 ["Pr"] = 10939,
28947 ["Sc"] = 10940,
28948 ["subdot"] = 10941,
28949 ["supdot"] = 10942,
28950 ["subplus"] = 10943,
28951 ["supplus"] = 10944,
28952 ["submult"] = 10945,
28953 ["supmult"] = 10946,
28954 ["subedot"] = 10947,
28955 ["supedot"] = 10948,
28956 ["nsubE"] = {10949, 824},
28957 ["nsubseteqq"] = {10949, 824},
28958 ["subE"] = 10949,
28959 ["subseteqq"] = 10949,
28960 ["nsupE"] = {10950, 824},
28961 ["nsupseteqq"] = {10950, 824},
28962 ["supE"] = 10950,
28963 ["supseteqq"] = 10950,
28964 ["subsim"] = 10951,
28965 ["supsim"] = 10952,
28966 ["subnE"] = 10955,
28967 ["subsetneqq"] = 10955,
28968 ["varsubsetneqq"] = {10955, 65024},
28969 ["vsubnE"] = {10955, 65024},
28970 ["supnE"] = 10956,
28971 ["supsetneqq"] = 10956,
28972 ["varsupsetneqq"] = {10956, 65024},
28973 ["vsupnE"] = {10956, 65024},
28974 ["csub"] = 10959,
28975 ["csup"] = 10960,
28976 ["csube"] = 10961,
28977 ["csupe"] = 10962,
28978 ["subsup"] = 10963,
28979 ["supsub"] = 10964,
28980 ["subsub"] = 10965,
28981 ["supsup"] = 10966,
28982 ["suphsub"] = 10967,
28983 ["supdsub"] = 10968,
28984 ["forkv"] = 10969,
28985 ["topfork"] = 10970,
28986 ["mlcp"] = 10971,
28987 ["Dashv"] = 10980,
28988 ["DoubleLeftTee"] = 10980,
28989 ["Vdashl"] = 10982,
28990 ["Barv"] = 10983,
28991 ["vBar"] = 10984,
28992 ["vBarv"] = 10985,
28993 ["Vbar"] = 10987,
28994 ["Not"] = 10988,
28995 ["bNot"] = 10989,
28996 ["rnmid"] = 10990,
28997 ["cirmid"] = 10991,
28998 ["midcir"] = 10992,
28999 ["topcir"] = 10993,
29000 ["nhpar"] = 10994,
29001 ["parsim"] = 10995,
29002 ["nparsl"] = {11005, 8421},
29003 ["parsl"] = 11005,
29004 ["fflig"] = 64256,
29005 ["filig"] = 64257,
29006 ["fllig"] = 64258,
29007 ["ffilig"] = 64259,
29008 ["ffllig"] = 64260,
29009 ["Ascr"] = 119964,
29010 ["Cscr"] = 119966,
29011 ["Dscr"] = 119967,
29012 ["Gscr"] = 119970,
29013 ["Jscr"] = 119973,
29014 ["Kscr"] = 119974,
29015 ["Nscr"] = 119977,
29016 ["Oscr"] = 119978,
29017 ["Pscr"] = 119979,
29018 ["Qscr"] = 119980,
29019 ["Sscr"] = 119982,
29020 ["Tscr"] = 119983,
29021 ["Uscr"] = 119984,
29022 ["Vscr"] = 119985,
29023 ["Wscr"] = 119986,
29024 ["Xscr"] = 119987,
29025 ["Yscr"] = 119988,
29026 ["Zscr"] = 119989,
29027 ["ascr"] = 119990,
29028 ["bscr"] = 119991,
29029 ["cscr"] = 119992,
29030 ["dscr"] = 119993,
29031 ["fscr"] = 119995,
29032 ["hscr"] = 119997,
29033 ["iscr"] = 119998,
29034 ["jscr"] = 119999,
29035 ["kscr"] = 120000,
29036 ["lscr"] = 120001,
29037 ["mscr"] = 120002,
29038 ["nscr"] = 120003,
29039 ["pscr"] = 120005,
29040 ["qscr"] = 120006,
29041 ["rscr"] = 120007,
29042 ["sscr"] = 120008,
29043 ["tscr"] = 120009,
29044 ["uscr"] = 120010,
29045 ["vscr"] = 120011,
29046 ["wscr"] = 120012,
29047 ["xscr"] = 120013,
29048 ["yscr"] = 120014,
29049 ["zscr"] = 120015,
29050 ["Afr"] = 120068,
29051 ["Bfr"] = 120069,
29052 ["Dfr"] = 120071,
29053 ["Efr"] = 120072,
29054 ["Ffr"] = 120073,
29055 ["Gfr"] = 120074,
29056 ["Jfr"] = 120077,
29057 ["Kfr"] = 120078,
29058 ["Lfr"] = 120079,
29059 ["Mfr"] = 120080,
29060 ["Nfr"] = 120081,
29061 ["Ofr"] = 120082,
29062 ["Pfr"] = 120083,
29063 ["Qfr"] = 120084,
29064 ["Sfr"] = 120086,
29065 ["Tfr"] = 120087,
29066 ["Ufr"] = 120088,
29067 ["Vfr"] = 120089,
29068 ["Wfr"] = 120090,
29069 ["Xfr"] = 120091,
29070 ["Yfr"] = 120092,
29071 ["afr"] = 120094,
29072 ["bfr"] = 120095,
29073 ["cfr"] = 120096,
29074 ["dfr"] = 120097,
29075 ["efr"] = 120098,
29076 ["ffr"] = 120099,
29077 ["gfr"] = 120100,
29078 ["hfr"] = 120101,
29079 ["ifr"] = 120102,
29080 ["jfr"] = 120103,
29081 ["kfr"] = 120104,
29082 ["lfr"] = 120105,
29083 ["mfr"] = 120106,
29084 ["nfr"] = 120107,
29085 ["ofr"] = 120108,
29086 ["pfr"] = 120109,
29087 ["qfr"] = 120110,
29088 ["rfr"] = 120111,
29089 ["sfr"] = 120112,
29090 ["tfr"] = 120113,
29091 ["ufr"] = 120114,
29092 ["vfr"] = 120115,
29093 ["wfr"] = 120116,
29094 ["xfr"] = 120117,
29095 ["yfr"] = 120118,
29096 ["zfr"] = 120119,
29097 ["Aopf"] = 120120,
29098 ["Bopf"] = 120121,
29099 ["Dopf"] = 120123,
29100 ["Eopf"] = 120124,
29101 ["Fopf"] = 120125,
29102 ["Gopf"] = 120126,
29103 ["Iopf"] = 120128,
29104 ["Jopf"] = 120129,
29105 ["Kopf"] = 120130,
29106 ["Lopf"] = 120131,
29107 ["Mopf"] = 120132,
29108 ["Oopf"] = 120134,
29109 ["Sopf"] = 120138,
29110 ["Topf"] = 120139,
29111 ["Uopf"] = 120140,
29112 ["Vopf"] = 120141,
29113 ["Wopf"] = 120142,
29114 ["Xopf"] = 120143,
29115 ["Yopf"] = 120144,
29116 ["aopf"] = 120146,
29117 ["bopf"] = 120147,
29118 ["copf"] = 120148,
29119 ["dopf"] = 120149,
29120 ["eopf"] = 120150,
29121 ["fopf"] = 120151,
29122 ["gopf"] = 120152,
29123 ["hopf"] = 120153,
29124 ["iopf"] = 120154,
29125 ["jopf"] = 120155,
29126 ["kopf"] = 120156,
29127 ["lopf"] = 120157,
29128 ["mopf"] = 120158,
29129 ["nopf"] = 120159,
29130 ["oopf"] = 120160,
29131 ["popf"] = 120161,
29132 ["qopf"] = 120162,
29133 ["ropf"] = 120163,
29134 ["sopf"] = 120164,
29135 ["topf"] = 120165,
29136 ["uopf"] = 120166,
29137 ["vopf"] = 120167,
29138 ["wopf"] = 120168,
29139 ["xopf"] = 120169,
29140 ["yopf"] = 120170,
29141 ["zopf"] = 120171,
29142 }
29143 % \end{macrocode}
29144 % \begin{markdown}
29145 %
29146 % Given a string `s` of decimal digits, the \luamdef{entities.dec_entity}
29147 % returns the corresponding UTF8-encoded Unicode codepoint.
29148 %
29149 % \end{markdown}
29150 % \begin{macrocode}
29151 function entities.dec_entity(s)
29152 local n = tonumber(s)
29153 if n == nil then
29154 return "&#" .. s .. ";" -- fallback for unknown entities
29155 end
29156 return utf8.char(n)
29157 end
29158 % \end{macrocode}
29159 % \begin{markdown}
29160 %
29161 % Given a string `s` of hexadecimal digits, the
29162 % \luamdef{entities.hex_entity} returns the corresponding
29163 % UTF8-encoded Unicode codepoint.
29164 %
29165 % \end{markdown}
29166 % \begin{macrocode}
29167 function entities.hex_entity(s)
29168 local n = tonumber("0x"..s)
29169 if n == nil then
29170 return "&#x" .. s .. ";" -- fallback for unknown entities
29171 end
29172 return utf8.char(n)
29173 end
29174 % \end{macrocode}
29175 % \begin{markdown}
29176 %
29177 % Given a captured character `x` and a string `s` of hexadecimal digits, the
29178 % \luamdef{entities.hex_entity_with_x_char} returns the corresponding
29179 % UTF8-encoded Unicode codepoint or fallback with the `x` character.
29180 %
29181 % \end{markdown}
29182 % \begin{macrocode}
29183 function entities.hex_entity_with_x_char(x, s)
29184 local n = tonumber("0x"..s)
29185 if n == nil then
29186 return "&#" .. x .. s .. ";" -- fallback for unknown entities
29187 end
29188 return utf8.char(n)
29189 end
29190 % \end{macrocode}
29191 % \begin{markdown}
29192 %
29193 % Given a character entity name `s` (like `ouml`), the
29194 % \luamdef{entities.char_entity} returns the corresponding
29195 % UTF8-encoded Unicode codepoint.
29196 %
29197 % \end{markdown}
29198 % \begin{macrocode}
29199 function entities.char_entity(s)
29200 local code_points = character_entities[s]
29201 if code_points == nil then
29202 return "&" .. s .. ";"
29203 end
29204 if type(code_points) ~= 'table' then
29205 code_points = {code_points}
29206 end
29207 local char_table = {}
29208 for _, code_point in ipairs(code_points) do
29209 table.insert(char_table, utf8.char(code_point))
29210 end
29211 return table.concat(char_table)
29212 end
29213 % \end{macrocode}
29214 % \begin{markdown}
29215 %
29216 %### Plain \TeX{} Writer {#tex-writer}
29217 %
29218 % This section documents the \luamref{writer} object, which implements the
29219 % routines for producing the \TeX{} output. The object is an amalgamate of the
29220 % generic, \TeX{}, \LaTeX{} writer objects that were located in the
29221 % `lunamark/writer/generic.lua`, `lunamark/writer/tex.lua`, and
29222 % `lunamark/writer/latex.lua` files in the Lunamark Lua module.
29223 %
29224 % Although not specified in the Lua interface (see Section
29225 % <#sec:luainterface>), the \luamref{writer} object is exported, so that the
29226 % curious user could easily tinker with the methods of the objects produced by
29227 % the \luamref{writer.new} method described below. The user should be aware,
29228 % however, that the implementation may change in a future revision.
29229 %
29230 % \end{markdown}
29231 % \begin{macrocode}
29232 M.writer = {}
29233 % \end{macrocode}
29234 % \begin{markdown}
29235 %
29236 % The \luamdef{writer.new} method creates and returns a new \TeX{} writer
29237 % object associated with the Lua interface options (see Section
29238 % <#sec:lua-options>) `options`. When `options` are unspecified, it is
29239 % assumed that an empty table was passed to the method.
29240 %
29241 % The objects produced by the \luamref{writer.new} method expose instance methods
29242 % and variables of their own. As a convention, I will refer to these
29243 % \meta{member}s as `writer->`\meta{member}. All member variables are
29244 % immutable unless explicitly stated otherwise.
29245 %
29246 % \end{markdown}
29247 % \begin{macrocode}
29248 local parsers
29249 function M.writer.new(options)
29250 local self = {}
29251 % \end{macrocode}
29252 % \begin{markdown}
29253 %
29254 % Make `options` available as \luamdef{writer->options}, so that it is
29255 % accessible from extensions.
29256 %
29257 % \end{markdown}
29258 % \begin{macrocode}
29259 self.options = options
29260 % \end{macrocode}
29261 % \begin{markdown}
29262 %
29263 % Define \luamdef{writer->flatten\_inlines}, which indicates whether or not the
29264 % writer should produce raw text rather than text in the output format for
29265 % inline elements. The \luamref{writer->flatten\_inlines} member variable is
29266 % mutable.
29267 %
29268 % \end{markdown}
29269 % \begin{macrocode}
29270 self.flatten_inlines = false
29271 % \end{macrocode}
29272 % \begin{markdown}
29273 %
29274 %#### Slicing
29275 % Parse the \Opt{slice} option and define \luamdef{writer->slice\_begin},
29276 % \luamdef{writer->slice\_end}, and \luamdef{writer->is\_writing}. The
29277 % \luamref{writer->is\_writing} member variable is mutable.
29278 %
29279 % \end{markdown}
29280 % \begin{macrocode}
29281 local slice_specifiers = {}
29282 for specifier in options.slice:gmatch("[^%s]+") do
29283 table.insert(slice_specifiers, specifier)
29284 end
29285
29286 if #slice_specifiers == 2 then
29287 self.slice_begin, self.slice_end = table.unpack(slice_specifiers)
29288 local slice_begin_type = self.slice_begin:sub(1, 1)
29289 if slice_begin_type ~= "^" and slice_begin_type ~= "$" then
29290 self.slice_begin = "^" .. self.slice_begin
29291 end
29292 local slice_end_type = self.slice_end:sub(1, 1)
29293 if slice_end_type ~= "^" and slice_end_type ~= "$" then
29294 self.slice_end = "$" .. self.slice_end
29295 end
29296 elseif #slice_specifiers == 1 then
29297 self.slice_begin = "^" .. slice_specifiers[1]
29298 self.slice_end = "$" .. slice_specifiers[1]
29299 end
29300
29301 self.slice_begin_type = self.slice_begin:sub(1, 1)
29302 self.slice_begin_identifier = self.slice_begin:sub(2) or ""
29303 self.slice_end_type = self.slice_end:sub(1, 1)
29304 self.slice_end_identifier = self.slice_end:sub(2) or ""
29305
29306 if self.slice_begin == "^" and self.slice_end ~= "^" then
29307 self.is_writing = true
29308 else
29309 self.is_writing = false
29310 end
29311 % \end{macrocode}
29312 % \begin{markdown}
29313 %
29314 %#### Basic Formatter Variables and Functions
29315 % Define \luamdef{writer->space} as the output format of a space character.
29316 %
29317 % \end{markdown}
29318 % \begin{macrocode}
29319 self.space = " "
29320 % \end{macrocode}
29321 % \begin{markdown}
29322 %
29323 % Define \luamdef{writer->nbsp} as the output format of a non-breaking space
29324 % character.
29325 %
29326 % \end{markdown}
29327 % \begin{macrocode}
29328 self.nbsp = "\\markdownRendererNbsp{}"
29329 % \end{macrocode}
29330 % \begin{markdown}
29331 %
29332 % Define \luamdef{writer->plain} as a function that will transform an input
29333 % plain text block `s` to the output format.
29334 %
29335 % \end{markdown}
29336 % \begin{macrocode}
29337 function self.plain(s)
29338 return s
29339 end
29340 % \end{macrocode}
29341 % \begin{markdown}
29342 %
29343 % Define \luamdef{writer->paragraph} as a function that will transform an
29344 % input paragraph `s` to the output format.
29345 %
29346 % \end{markdown}
29347 % \begin{macrocode}
29348 function self.paragraph(s)
29349 if not self.is_writing then return "" end
29350 return s
29351 end
29352 % \end{macrocode}
29353 % \begin{markdown}
29354 %
29355 % Define \luamdef{writer->interblocksep} as the output format of a block
29356 % element separator.
29357 %
29358 % \end{markdown}
29359 % \begin{macrocode}
29360 self.interblocksep_text = "\\markdownRendererInterblockSeparator\n{}"
29361 function self.interblocksep()
29362 if not self.is_writing then return "" end
29363 return self.interblocksep_text
29364 end
29365 % \end{macrocode}
29366 % \begin{markdown}
29367 %
29368 % Define \luamdef{writer->paragraphsep} as the output format of a paragraph
29369 % separator. Users can use more than one blank line to delimit two blocks to
29370 % indicate the end of a series of blocks that make up a paragraph. This
29371 % produces a paragraph separator instead of an interblock separator.
29372 %
29373 % \end{markdown}
29374 % \begin{macrocode}
29375 self.paragraphsep_text = "\\markdownRendererParagraphSeparator\n{}"
29376 function self.paragraphsep()
29377 if not self.is_writing then return "" end
29378 return self.paragraphsep_text
29379 end
29380 % \end{macrocode}
29381 % \begin{markdown}
29382 %
29383 % Define \luamdef{writer->undosep} as a function that will remove the output
29384 % produced by an immediately preceding block element / paragraph separator.
29385 %
29386 % \end{markdown}
29387 % \begin{macrocode}
29388 self.undosep_text = "\\markdownRendererUndoSeparator\n{}"
29389 function self.undosep()
29390 if not self.is_writing then return "" end
29391 return self.undosep_text
29392 end
29393 % \end{macrocode}
29394 % \begin{markdown}
29395 %
29396 % Define \luamdef{writer->soft_line_break} as the output format of a soft
29397 % line break.
29398 %
29399 % \end{markdown}
29400 % \begin{macrocode}
29401 self.soft_line_break = function()
29402 if self.flatten_inlines then return "\n" end
29403 return "\\markdownRendererSoftLineBreak\n{}"
29404 end
29405 % \end{macrocode}
29406 % \begin{markdown}
29407 %
29408 % Define \luamdef{writer->hard_line_break} as the output format of a hard
29409 % line break.
29410 %
29411 % \end{markdown}
29412 % \begin{macrocode}
29413 self.hard_line_break = function()
29414 if self.flatten_inlines then return "\n" end
29415 return "\\markdownRendererHardLineBreak\n{}"
29416 end
29417 % \end{macrocode}
29418 % \begin{markdown}
29419 %
29420 % Define \luamdef{writer->ellipsis} as the output format of an ellipsis.
29421 %
29422 % \end{markdown}
29423 % \begin{macrocode}
29424 self.ellipsis = "\\markdownRendererEllipsis{}"
29425 % \end{macrocode}
29426 % \begin{markdown}
29427 %
29428 % Define \luamdef{writer->thematic_break} as the output format of a thematic
29429 % break.
29430 %
29431 % \end{markdown}
29432 % \begin{macrocode}
29433 function self.thematic_break()
29434 if not self.is_writing then return "" end
29435 return "\\markdownRendererThematicBreak{}"
29436 end
29437 % \end{macrocode}
29438 % \begin{markdown}
29439 %
29440 %#### Escaping Special Characters
29441 % Define tables \luamdef{writer->escaped_uri_chars} and
29442 % \luamdef{writer->escaped_minimal_strings} containing the mapping from
29443 % special plain characters and character strings that always need to be
29444 % escaped.
29445 %
29446 % \end{markdown}
29447 % \begin{macrocode}
29448 self.escaped_uri_chars = {
29449 ["{"] = "\\markdownRendererLeftBrace{}",
29450 ["}"] = "\\markdownRendererRightBrace{}",
29451 ["\\"] = "\\markdownRendererBackslash{}",
29452 ["\r"] = " ",
29453 ["\n"] = " ",
29454 }
29455 self.escaped_minimal_strings = {
29456 ["^^"] = "\\markdownRendererCircumflex"
29457 .. "\\markdownRendererCircumflex ",
29458 ["☒"] = "\\markdownRendererTickedBox{}",
29459 ["⌛"] = "\\markdownRendererHalfTickedBox{}",
29460 ["☐"] = "\\markdownRendererUntickedBox{}",
29461 [entities.hex_entity('FFFD')]
29462 = "\\markdownRendererReplacementCharacter{}",
29463 }
29464 % \end{macrocode}
29465 % \begin{markdown}
29466 %
29467 % Define table \luamdef{writer->escaped_strings} containing the mapping from
29468 % character strings that need to be escaped in typeset content.
29469 %
29470 % \end{markdown}
29471 % \begin{macrocode}
29472 self.escaped_strings = util.table_copy(self.escaped_minimal_strings)
29473 self.escaped_strings[entities.hex_entity('00A0')] = self.nbsp
29474 % \end{macrocode}
29475 % \begin{markdown}
29476 %
29477 % Define a table \luamdef{writer->escaped_chars} containing the mapping from
29478 % special plain \TeX{} characters (including the active pipe character (`|`)
29479 % of \Hologo{ConTeXt}) that need to be escaped in typeset content.
29480 %
29481 % \end{markdown}
29482 % \begin{macrocode}
29483 self.escaped_chars = {
29484 ["{"] = "\\markdownRendererLeftBrace{}",
29485 ["}"] = "\\markdownRendererRightBrace{}",
29486 ["%"] = "\\markdownRendererPercentSign{}",
29487 ["\\"] = "\\markdownRendererBackslash{}",
29488 ["#"] = "\\markdownRendererHash{}",
29489 ["$"] = "\\markdownRendererDollarSign{}",
29490 ["&"] = "\\markdownRendererAmpersand{}",
29491 ["_"] = "\\markdownRendererUnderscore{}",
29492 ["^"] = "\\markdownRendererCircumflex{}",
29493 ["~"] = "\\markdownRendererTilde{}",
29494 ["|"] = "\\markdownRendererPipe{}",
29495 [entities.hex_entity('0000')]
29496 = "\\markdownRendererReplacementCharacter{}",
29497 }
29498 % \end{macrocode}
29499 % \begin{markdown}
29500 %
29501 % Use the \luamref{writer->escaped_chars}, \luamref{writer->escaped_uri_chars},
29502 % and \luamref{writer->escaped_minimal_strings} tables to create the
29503 % \luamdef{escape_typographic_text},
29504 % \luamdef{escape_programmatic_text}, and
29505 % \luamdef{escape_minimal} local escaper functions.
29506 %
29507 % \end{markdown}
29508 % \begin{macrocode}
29509 local function create_escaper(char_escapes, string_escapes)
29510 local escape = util.escaper(char_escapes, string_escapes)
29511 return function(s)
29512 if self.flatten_inlines then return s end
29513 return escape(s)
29514 end
29515 end
29516 local escape_typographic_text = create_escaper(
29517 self.escaped_chars, self.escaped_strings)
29518 local escape_programmatic_text = create_escaper(
29519 self.escaped_uri_chars, self.escaped_minimal_strings)
29520 local escape_minimal = create_escaper(
29521 {}, self.escaped_minimal_strings)
29522 % \end{macrocode}
29523 % \begin{markdown}
29524 %
29525 % Define the following semantic aliases for the escaper functions:
29526 %
29527 % - \luamdef{writer->escape} transforms a text string that should always be
29528 % made printable.
29529 % - \luamdef{writer->string} transforms a text string that should be made
29530 % printable only when the \Opt{hybrid} Lua option is disabled. When \Opt{hybrid}
29531 % is enabled, the text string should be kept as-is.
29532 % - \luamdef{writer->math} transforms a math span.
29533 % - \luamdef{writer->identifier} transforms an input programmatic identifier.
29534 % - \luamdef{writer->uri} transforms an input URI.
29535 % - \luamdef{writer->infostring} transforms a fence code infostring.
29536 %
29537 % \end{markdown}
29538 % \begin{macrocode}
29539 self.escape = escape_typographic_text
29540 self.math = escape_minimal
29541 if options.hybrid then
29542 self.identifier = escape_minimal
29543 self.string = escape_minimal
29544 self.uri = escape_minimal
29545 self.infostring = escape_minimal
29546 else
29547 self.identifier = escape_programmatic_text
29548 self.string = escape_typographic_text
29549 self.uri = escape_programmatic_text
29550 self.infostring = escape_programmatic_text
29551 end
29552 % \end{macrocode}
29553 % \begin{markdown}
29554 %
29555 %#### Formatters of Warnings and Errors
29556 % Define \luamdef{writer->warning} as a function that will transform an input
29557 % warning `t` with optional more warning text `m` to the output format.
29558 %
29559 % \end{markdown}
29560 % \begin{macrocode}
29561 function self.warning(t, m)
29562 return {"\\markdownRendererWarning{", self.escape(t), "}{",
29563 escape_minimal(t), "}{", self.escape(m or ""), "}{",
29564 escape_minimal(m or ""), "}"}
29565 end
29566 % \end{macrocode}
29567 % \begin{markdown}
29568 %
29569 % Define \luamdef{writer->error} as a function that will transform an input
29570 % error text `t` with optional more error text `m` to the output format.
29571 %
29572 % \end{markdown}
29573 % \begin{macrocode}
29574 function self.error(t, m)
29575 return {"\\markdownRendererError{", self.escape(t), "}{",
29576 escape_minimal(t), "}{", self.escape(m or ""), "}{",
29577 escape_minimal(m or ""), "}"}
29578 end
29579 % \end{macrocode}
29580 % \begin{markdown}
29581 %
29582 %#### Formatter of Code Spans
29583 % Define \luamdef{writer->code} as a function that will transform an input
29584 % inline code span `s` with optional attributes `attributes` to the output
29585 % format.
29586 %
29587 % \end{markdown}
29588 % \begin{macrocode}
29589 function self.code(s, attributes)
29590 if self.flatten_inlines then return s end
29591 local buf = {}
29592 if attributes ~= nil then
29593 table.insert(buf,
29594 "\\markdownRendererCodeSpanAttributeContextBegin\n")
29595 table.insert(buf, self.attributes(attributes))
29596 end
29597 table.insert(buf,
29598 {"\\markdownRendererCodeSpan{", self.escape(s), "}"})
29599 if attributes ~= nil then
29600 table.insert(buf,
29601 "\\markdownRendererCodeSpanAttributeContextEnd{}")
29602 end
29603 return buf
29604 end
29605 % \end{macrocode}
29606 % \begin{markdown}
29607 %
29608 %#### Formatter of Hyperlinks
29609 % Define \luamdef{writer->link} as a function that will transform an input
29610 % hyperlink to the output format, where `lab` corresponds to the label,
29611 % `src` to URI, `tit` to the title of the link, and `attributes` to
29612 % optional attributes.
29613 %
29614 % \end{markdown}
29615 % \begin{macrocode}
29616 function self.link(lab, src, tit, attributes)
29617 if self.flatten_inlines then return lab end
29618 local buf = {}
29619 if attributes ~= nil then
29620 table.insert(buf,
29621 "\\markdownRendererLinkAttributeContextBegin\n")
29622 table.insert(buf, self.attributes(attributes))
29623 end
29624 table.insert(buf, {"\\markdownRendererLink{",lab,"}",
29625 "{",self.escape(src),"}",
29626 "{",self.uri(src),"}",
29627 "{",self.string(tit or ""),"}"})
29628 if attributes ~= nil then
29629 table.insert(buf,
29630 "\\markdownRendererLinkAttributeContextEnd{}")
29631 end
29632 return buf
29633 end
29634 % \end{macrocode}
29635 % \begin{markdown}
29636 %
29637 %#### Formatter of Images
29638 % Define \luamdef{writer->image} as a function that will transform an input
29639 % image to the output format, where `lab` corresponds to the label, `src`
29640 % to the URL, `tit` to the title of the image, and `attributes` to
29641 % optional attributes.
29642 %
29643 % \end{markdown}
29644 % \begin{macrocode}
29645 function self.image(lab, src, tit, attributes)
29646 if self.flatten_inlines then return lab end
29647 local buf = {}
29648 if attributes ~= nil then
29649 table.insert(buf,
29650 "\\markdownRendererImageAttributeContextBegin\n")
29651 table.insert(buf, self.attributes(attributes))
29652 end
29653 table.insert(buf, {"\\markdownRendererImage{",lab,"}",
29654 "{",self.string(src),"}",
29655 "{",self.uri(src),"}",
29656 "{",tit,"}"})
29657 if attributes ~= nil then
29658 table.insert(buf,
29659 "\\markdownRendererImageAttributeContextEnd{}")
29660 end
29661 return buf
29662 end
29663 % \end{macrocode}
29664 % \begin{markdown}
29665 %
29666 %#### Formatters of Lists
29667 % Define \luamdef{writer->bulletlist} as a function that will transform an input
29668 % bulleted list to the output format, where `items` is an array of the list
29669 % items and `tight` specifies, whether the list is tight or not.
29670 %
29671 % \end{markdown}
29672 % \begin{macrocode}
29673 function self.bulletlist(items,tight)
29674 if not self.is_writing then return "" end
29675 local buffer = {}
29676 for _,item in ipairs(items) do
29677 if item ~= "" then
29678 buffer[#buffer + 1] = self.bulletitem(item)
29679 end
29680 end
29681 local contents = util.intersperse(buffer,"\n")
29682 if tight and options.tightLists then
29683 return {"\\markdownRendererUlBeginTight\n",contents,
29684 "\n\\markdownRendererUlEndTight "}
29685 else
29686 return {"\\markdownRendererUlBegin\n",contents,
29687 "\n\\markdownRendererUlEnd "}
29688 end
29689 end
29690 % \end{macrocode}
29691 % \begin{markdown}
29692 %
29693 % Define \luamdef{writer->bulletitem} as a function that will transform an
29694 % input bulleted list item to the output format, where `s` is the text of
29695 % the list item.
29696 %
29697 % \end{markdown}
29698 % \begin{macrocode}
29699 function self.bulletitem(s)
29700 return {"\\markdownRendererUlItem ",s,
29701 "\\markdownRendererUlItemEnd "}
29702 end
29703 % \end{macrocode}
29704 % \begin{markdown}
29705 %
29706 % Define \luamdef{writer->orderedlist} as a function that will transform an
29707 % input ordered list to the output format, where `items` is an array of the
29708 % list items and `tight` specifies, whether the list is tight or not. If the
29709 % optional parameter `startnum` is present, it is the number of the first list
29710 % item.
29711 %
29712 % \end{markdown}
29713 % \begin{macrocode}
29714 function self.orderedlist(items,tight,startnum)
29715 if not self.is_writing then return "" end
29716 local buffer = {}
29717 local num = startnum
29718 for _,item in ipairs(items) do
29719 if item ~= "" then
29720 buffer[#buffer + 1] = self.ordereditem(item,num)
29721 end
29722 if num ~= nil and item ~= "" then
29723 num = num + 1
29724 end
29725 end
29726 local contents = util.intersperse(buffer,"\n")
29727 if tight and options.tightLists then
29728 return {"\\markdownRendererOlBeginTight\n",contents,
29729 "\n\\markdownRendererOlEndTight "}
29730 else
29731 return {"\\markdownRendererOlBegin\n",contents,
29732 "\n\\markdownRendererOlEnd "}
29733 end
29734 end
29735 % \end{macrocode}
29736 % \begin{markdown}
29737 %
29738 % Define \luamdef{writer->ordereditem} as a function that will transform an
29739 % input ordered list item to the output format, where `s` is the text of
29740 % the list item. If the optional parameter `num` is present, it is the number
29741 % of the list item.
29742 %
29743 % \end{markdown}
29744 % \begin{macrocode}
29745 function self.ordereditem(s,num)
29746 if num ~= nil then
29747 return {"\\markdownRendererOlItemWithNumber{",num,"}",s,
29748 "\\markdownRendererOlItemEnd "}
29749 else
29750 return {"\\markdownRendererOlItem ",s,
29751 "\\markdownRendererOlItemEnd "}
29752 end
29753 end
29754 % \end{macrocode}
29755 % \begin{markdown}
29756 %
29757 %#### Formatters of HTML Tags, Elements, and Comments
29758 % Define \luamdef{writer->inline_html_comment} as a function that will
29759 % transform the contents of an inline HTML comment, to the output
29760 % format, where `contents` are the contents of the HTML comment.
29761 %
29762 % \end{markdown}
29763 % \begin{macrocode}
29764 function self.inline_html_comment(contents)
29765 if self.flatten_inlines then return contents end
29766 return {"\\markdownRendererInlineHtmlComment{",contents,"}"}
29767 end
29768 % \end{macrocode}
29769 % \begin{markdown}
29770 %
29771 % Define \luamdef{writer->inline_html_tag} as a function that will
29772 % transform the contents of an opening, closing, or empty inline HTML
29773 % tag to the output format, where `contents` are the contents of the
29774 % HTML tag.
29775 %
29776 % \end{markdown}
29777 % \begin{macrocode}
29778 function self.inline_html_tag(contents)
29779 if self.flatten_inlines then return contents end
29780 return {"\\markdownRendererInlineHtmlTag{",
29781 self.string(contents),"}"}
29782 end
29783 % \end{macrocode}
29784 % \begin{markdown}
29785 %
29786 % Define \luamdef{writer->block_html_element} as a function that will
29787 % transform the contents of a block HTML element to the output format,
29788 % where `s` are the contents of the HTML element.
29789 %
29790 % \end{markdown}
29791 % \begin{macrocode}
29792 function self.block_html_element(s)
29793 if not self.is_writing then return "" end
29794 local name = util.cache(options.cacheDir, s, nil, nil, ".verbatim")
29795 return {"\\markdownRendererInputBlockHtmlElement{",name,"}"}
29796 end
29797 % \end{macrocode}
29798 % \begin{markdown}
29799 %
29800 % Define \luamdef{writer->block_html_cdata_element} as a function that
29801 % transforms the contents of a block HTML CDATA element such as
29802 % `<script>`, `<pre>`, `<style>`, or `<textarea>` (CommonMark HTML block
29803 % type~1) to the output format.
29804 %
29805 % \end{markdown}
29806 % \begin{macrocode}
29807 function self.block_html_cdata_element(s)
29808 if not self.is_writing then return "" end
29809 local name = util.cache(options.cacheDir, s, nil, nil, ".verbatim")
29810 return {"\\markdownRendererInputBlockHtmlCdataElement{",name,"}"}
29811 end
29812 % \end{macrocode}
29813 % \begin{markdown}
29814 %
29815 % Define \luamdef{writer->block_html_comment} as a function that
29816 % transforms the contents of a block HTML comment (CommonMark HTML block
29817 % type~2) to the output format, where `s` is the full comment text.
29818 %
29819 % \end{markdown}
29820 % \begin{macrocode}
29821 function self.block_html_comment(contents)
29822 if self.flatten_inlines then return contents end
29823 return {"\\markdownRendererBlockHtmlComment{",contents,"}"}
29824 end
29825 % \end{macrocode}
29826 % \begin{markdown}
29827 %
29828 % Define \luamdef{writer->block_html_processing_instruction} as a function that
29829 % transforms the contents of a block HTML processing instruction (CommonMark
29830 % HTML block type~3) to the output format.
29831 %
29832 % \end{markdown}
29833 % \begin{macrocode}
29834 function self.block_html_processing_instruction(s)
29835 if not self.is_writing then return "" end
29836 local name = util.cache(options.cacheDir, s, nil, nil, ".verbatim")
29837 return {
29838 "\\markdownRendererInputBlockHtmlProcessingInstruction{",name,"}"}
29839 end
29840 % \end{macrocode}
29841 % \begin{markdown}
29842 %
29843 % Define \luamdef{writer->block_html_declaration} as a function that
29844 % transforms the contents of a block HTML declaration (CommonMark HTML block
29845 % type~4) to the output format.
29846 %
29847 % \end{markdown}
29848 % \begin{macrocode}
29849 function self.block_html_declaration(s)
29850 if not self.is_writing then return "" end
29851 local name = util.cache(options.cacheDir, s, nil, nil, ".verbatim")
29852 return {
29853 "\\markdownRendererInputBlockHtmlDeclaration{",name,"}"}
29854 end
29855 % \end{macrocode}
29856 % \begin{markdown}
29857 %
29858 % Define \luamdef{writer->block_html_cdata_section} as a function that
29859 % transforms the contents of a block HTML CDATA section (CommonMark HTML
29860 % block type~5) to the output format.
29861 %
29862 % \end{markdown}
29863 % \begin{macrocode}
29864 function self.block_html_cdata_section(s)
29865 if not self.is_writing then return "" end
29866 local name = util.cache(options.cacheDir, s, nil, nil, ".verbatim")
29867 return {"\\markdownRendererInputBlockHtmlCdataSection{",name,"}"}
29868 end
29869 % \end{macrocode}
29870 % \begin{markdown}
29871 %
29872 % Define \luamdef{writer->block_html_pcdata_element} as a function that
29873 % transforms the contents of a block HTML PCDATA element such as `<div>`
29874 % or `<table>` (CommonMark HTML block type~6) to the output format.
29875 %
29876 % \end{markdown}
29877 % \begin{macrocode}
29878 function self.block_html_pcdata_element(s)
29879 if not self.is_writing then return "" end
29880 local name = util.cache(options.cacheDir, s, nil, nil, ".verbatim")
29881 return {"\\markdownRendererInputBlockHtmlPcdataElement{",name,"}"}
29882 end
29883 % \end{macrocode}
29884 % \begin{markdown}
29885 %
29886 % Define \luamdef{writer->block_html_standalone_tag} as a function that
29887 % transforms the contents of a block HTML element that does not fall into
29888 % types 1--6 (CommonMark HTML block type~7) to the output format.
29889 %
29890 % \end{markdown}
29891 % \begin{macrocode}
29892 function self.block_html_standalone_tag(contents)
29893 if self.flatten_inlines then return contents end
29894 return {"\\markdownRendererBlockHtmlStandaloneTag{",
29895 self.string(contents),"}"}
29896 end
29897 % \end{macrocode}
29898 % \begin{markdown}
29899 %
29900 % Define \luamdef{writer->inline_html_processing_instruction} as a function
29901 % that transforms the contents of an inline HTML processing instruction to the
29902 % output format.
29903 %
29904 % \end{markdown}
29905 % \begin{macrocode}
29906 function self.inline_html_processing_instruction(contents)
29907 if self.flatten_inlines then return contents end
29908 return {"\\markdownRendererInlineHtmlProcessingInstruction{",
29909 self.string(contents),"}"}
29910 end
29911 % \end{macrocode}
29912 % \begin{markdown}
29913 %
29914 % Define \luamdef{writer->inline_html_declaration} as a function that
29915 % transforms the contents of an inline HTML declaration to the output
29916 % format.
29917 %
29918 % \end{markdown}
29919 % \begin{macrocode}
29920 function self.inline_html_declaration(contents)
29921 if self.flatten_inlines then return contents end
29922 return {"\\markdownRendererInlineHtmlDeclaration{",
29923 self.string(contents),"}"}
29924 end
29925 % \end{macrocode}
29926 % \begin{markdown}
29927 %
29928 % Define \luamdef{writer->inline_html_cdata_section} as a function that
29929 % transforms the contents of an inline HTML CDATA section to the output
29930 % format.
29931 %
29932 % \end{markdown}
29933 % \begin{macrocode}
29934 function self.inline_html_cdata_section(contents)
29935 if self.flatten_inlines then return contents end
29936 return {"\\markdownRendererInlineHtmlCdataSection{",
29937 self.string(contents),"}"}
29938 end
29939 % \end{macrocode}
29940 % \begin{markdown}
29941 %
29942 % Define \luamdef{writer->inline_html_open_tag} as a function that
29943 % transforms the contents of an inline HTML opening tag to the output
29944 % format.
29945 %
29946 % \end{markdown}
29947 % \begin{macrocode}
29948 function self.inline_html_open_tag(contents)
29949 if self.flatten_inlines then return contents end
29950 return {"\\markdownRendererInlineHtmlOpenTag{",
29951 self.string(contents),"}"}
29952 end
29953 % \end{macrocode}
29954 % \begin{markdown}
29955 %
29956 % Define \luamdef{writer->inline_html_close_tag} as a function that
29957 % transforms the contents of an inline HTML closing tag to the output
29958 % format.
29959 %
29960 % \end{markdown}
29961 % \begin{macrocode}
29962 function self.inline_html_close_tag(contents)
29963 if self.flatten_inlines then return contents end
29964 return {"\\markdownRendererInlineHtmlCloseTag{",
29965 self.string(contents),"}"}
29966 end
29967 % \end{macrocode}
29968 % \begin{markdown}
29969 %
29970 % Define \luamdef{writer->inline_html_empty_tag} as a function that
29971 % transforms the contents of an inline HTML self-closing (empty) tag to the
29972 % output format.
29973 %
29974 % \end{markdown}
29975 % \begin{macrocode}
29976 function self.inline_html_empty_tag(contents)
29977 if self.flatten_inlines then return contents end
29978 return {"\\markdownRendererInlineHtmlEmptyTag{",
29979 self.string(contents),"}"}
29980 end
29981 % \end{macrocode}
29982 % \begin{markdown}
29983 %
29984 %#### Formatter of Emphasis
29985 % Define \luamdef{writer->emphasis} as a function that will transform an
29986 % emphasized span `s` of input text to the output format.
29987 %
29988 % \end{markdown}
29989 % \begin{macrocode}
29990 function self.emphasis(s)
29991 if self.flatten_inlines then return s end
29992 return {"\\markdownRendererEmphasis{",s,"}"}
29993 end
29994 % \end{macrocode}
29995 % \begin{markdown}
29996 %
29997 %#### Formatter of Strong Emphasis
29998 % Define \luamdef{writer->strong} as a function that will transform a strongly
29999 % emphasized span `s` of input text to the output format.
30000 %
30001 % \end{markdown}
30002 % \begin{macrocode}
30003 function self.strong(s)
30004 if self.flatten_inlines then return s end
30005 return {"\\markdownRendererStrongEmphasis{",s,"}"}
30006 end
30007 % \end{macrocode}
30008 % \begin{markdown}
30009 %
30010 %#### Formatter of Tickboxes
30011 % Define \luamdef{writer->tickbox} as a function that will transform a
30012 % number `f` to the output format.
30013 %
30014 % \end{markdown}
30015 % \begin{macrocode}
30016 function self.tickbox(f)
30017 if f == 1.0 then
30018 return "☒ "
30019 elseif f == 0.0 then
30020 return "☐ "
30021 else
30022 return "⌛ "
30023 end
30024 end
30025 % \end{macrocode}
30026 % \begin{markdown}
30027 %
30028 %#### Formatter of Blockquotes
30029 % Define \luamdef{writer->blockquote} as a function that will transform an
30030 % input block quote `s` to the output format.
30031 %
30032 % \end{markdown}
30033 % \begin{macrocode}
30034 function self.blockquote(s)
30035 if not self.is_writing then return "" end
30036 return {"\\markdownRendererBlockQuoteBegin\n",s,
30037 "\\markdownRendererBlockQuoteEnd "}
30038 end
30039 % \end{macrocode}
30040 % \begin{markdown}
30041 %
30042 %#### Formatter of Code Blocks
30043 % Define \luamdef{writer->verbatim} as a function that will transform an
30044 % input code block `s` to the output format.
30045 %
30046 % \end{markdown}
30047 % \begin{macrocode}
30048 function self.verbatim(s)
30049 if not self.is_writing then return "" end
30050 s = s:gsub("\n$", "")
30051 local name = util.cache_verbatim(options.cacheDir, s)
30052 return {"\\markdownRendererInputVerbatim{",name,"}"}
30053 end
30054 % \end{macrocode}
30055 % \begin{markdown}
30056 %
30057 %#### Formatter of Documents
30058 % Define \luamdef{writer->document} as a function that will transform a
30059 % document `d` to the output format.
30060 %
30061 % \end{markdown}
30062 % \begin{macrocode}
30063 function self.document(d)
30064 local buf = {"\\markdownRendererDocumentBegin\n"}
30065
30066 -- warn against the `hybrid` option
30067 if options.hybrid then
30068 local text = "The `hybrid` option has been soft-deprecated."
30069 local more = "Consider using one of the following better options "
30070 .. "for mixing TeX and markdown: `contentBlocks`, "
30071 .. "`rawAttribute`, `texComments`, `texMathDollars`, "
30072 .. "`texMathSingleBackslash`, and "
30073 .. "`texMathDoubleBackslash`. "
30074 .. "For more information, see the user manual at "
30075 .. "<https://witiko.github.io/markdown/>."
30076 table.insert(buf, self.warning(text, more))
30077 end
30078
30079 -- insert the text of the document
30080 table.insert(buf, d)
30081
30082 -- pop all attributes
30083 table.insert(buf, self.pop_attributes())
30084
30085 table.insert(buf, "\\markdownRendererDocumentEnd")
30086
30087 return buf
30088 end
30089 % \end{macrocode}
30090 % \begin{markdown}
30091 %
30092 %#### Formatter of Attributes
30093 % Define \luamdef{writer->attributes} as a function that will transform
30094 % input attributes `attrs` to the output format.
30095 %
30096 % \end{markdown}
30097 % \begin{macrocode}
30098 local seen_identifiers = {}
30099 local key_value_regex = "([^= ]+)%s*=%s*(.*)"
30100 local function normalize_attributes(attributes, auto_identifiers)
30101 -- normalize attributes
30102 local normalized_attributes = {}
30103 local has_explicit_identifiers = false
30104 local key, value
30105 for _, attribute in ipairs(attributes or {}) do
30106 if attribute:sub(1, 1) == "#" then
30107 table.insert(normalized_attributes, attribute)
30108 has_explicit_identifiers = true
30109 seen_identifiers[attribute:sub(2)] = true
30110 elseif attribute:sub(1, 1) == "." then
30111 table.insert(normalized_attributes, attribute)
30112 else
30113 key, value = attribute:match(key_value_regex)
30114 if key:lower() == "id" then
30115 table.insert(normalized_attributes, "#" .. value)
30116 elseif key:lower() == "class" then
30117 local classes = {}
30118 for class in value:gmatch("%S+") do
30119 table.insert(classes, class)
30120 end
30121 table.sort(classes)
30122 for _, class in ipairs(classes) do
30123 table.insert(normalized_attributes, "." .. class)
30124 end
30125 else
30126 table.insert(normalized_attributes, attribute)
30127 end
30128 end
30129 end
30130
30131 -- if no explicit identifiers exist, add auto identifiers
30132 if not has_explicit_identifiers and auto_identifiers ~= nil then
30133 local seen_auto_identifiers = {}
30134 for _, auto_identifier in ipairs(auto_identifiers) do
30135 if seen_auto_identifiers[auto_identifier] == nil then
30136 seen_auto_identifiers[auto_identifier] = true
30137 if seen_identifiers[auto_identifier] == nil then
30138 seen_identifiers[auto_identifier] = true
30139 table.insert(normalized_attributes,
30140 "#" .. auto_identifier)
30141 else
30142 local auto_identifier_number = 1
30143 while true do
30144 local numbered_auto_identifier = auto_identifier .. "-"
30145 .. auto_identifier_number
30146 if seen_identifiers[numbered_auto_identifier] == nil then
30147 seen_identifiers[numbered_auto_identifier] = true
30148 table.insert(normalized_attributes,
30149 "#" .. numbered_auto_identifier)
30150 break
30151 end
30152 auto_identifier_number = auto_identifier_number + 1
30153 end
30154 end
30155 end
30156 end
30157 end
30158
30159 -- sort and deduplicate normalized attributes
30160 table.sort(normalized_attributes)
30161 local seen_normalized_attributes = {}
30162 local deduplicated_normalized_attributes = {}
30163 for _, attribute in ipairs(normalized_attributes) do
30164 if seen_normalized_attributes[attribute] == nil then
30165 seen_normalized_attributes[attribute] = true
30166 table.insert(deduplicated_normalized_attributes, attribute)
30167 end
30168 end
30169
30170 return deduplicated_normalized_attributes
30171 end
30172
30173 function self.attributes(attributes, should_normalize_attributes)
30174 local normalized_attributes
30175 if should_normalize_attributes == false then
30176 normalized_attributes = attributes
30177 else
30178 normalized_attributes = normalize_attributes(attributes)
30179 end
30180
30181 local buf = {}
30182 local key, value
30183 for _, attribute in ipairs(normalized_attributes) do
30184 if attribute:sub(1, 1) == "#" then
30185 table.insert(buf, {"\\markdownRendererAttributeIdentifier{",
30186 attribute:sub(2), "}"})
30187 elseif attribute:sub(1, 1) == "." then
30188 table.insert(buf, {"\\markdownRendererAttributeClassName{",
30189 attribute:sub(2), "}"})
30190 else
30191 key, value = attribute:match(key_value_regex)
30192 table.insert(buf, {"\\markdownRendererAttributeKeyValue{",
30193 key, "}{", value, "}"})
30194 end
30195 end
30196
30197 return buf
30198 end
30199 % \end{macrocode}
30200 % \begin{markdown}
30201 %
30202 %#### Tracking Active Attributes
30203 % Define \luamdef{writer->active\_attributes} as a stack of block-level
30204 % attributes that are currently active. The
30205 % \luamref{writer->active\_attributes} member variable is mutable.
30206 %
30207 % \end{markdown}
30208 % \begin{macrocode}
30209 self.active_attributes = {}
30210 % \end{macrocode}
30211 % \begin{markdown}
30212 %
30213 % Define \luamdef{writer->attribute\_type\_levels} as a hash table that
30214 % maps attribute types to the number of attributes of said type in
30215 % \luamref{writer->active\_attributes}.
30216 %
30217 % \end{markdown}
30218 % \begin{macrocode}
30219 self.attribute_type_levels = {}
30220 setmetatable(self.attribute_type_levels,
30221 { __index = function() return 0 end })
30222 % \end{macrocode}
30223 % \begin{markdown}
30224 %
30225 % Define \luamdef{writer->push\_attributes} and
30226 % \luamdef{writer->pop\_attributes} as functions that will add a new set
30227 % of active block-level attributes or remove the most current attributes
30228 % from \luamref{writer->active\_attributes}.
30229 %
30230 % \end{markdown}
30231 % \begin{macrocode}
30232 local function apply_attributes()
30233 local buf = {}
30234 for i = 1, #self.active_attributes do
30235 local start_output = self.active_attributes[i][3]
30236 if start_output ~= nil then
30237 table.insert(buf, start_output)
30238 end
30239 end
30240 return buf
30241 end
30242
30243 local function tear_down_attributes()
30244 local buf = {}
30245 for i = #self.active_attributes, 1, -1 do
30246 local end_output = self.active_attributes[i][4]
30247 if end_output ~= nil then
30248 table.insert(buf, end_output)
30249 end
30250 end
30251 return buf
30252 end
30253 % \end{macrocode}
30254 % \begin{markdown}
30255 %
30256 % The \luamref{writer->push\_attributes} method adds `attributes`
30257 % of type `attribute_type` to \luamref{writer->active\_attributes}. The
30258 % `start_output` string is used to construct a rope that will be returned by
30259 % this function, together with output produced as a result of slicing (see
30260 % \Opt{slice}). The `end_output` string is stored together with `attributes`
30261 % and is used to construct the return value of the
30262 % \luamref{writer->pop\_attributes}
30263 % method.
30264 %
30265 % \end{markdown}
30266 % \begin{macrocode}
30267 function self.push_attributes(attribute_type, attributes,
30268 start_output, end_output)
30269 local attribute_type_level
30270 = self.attribute_type_levels[attribute_type]
30271 self.attribute_type_levels[attribute_type]
30272 = attribute_type_level + 1
30273
30274 -- index attributes in a hash table for easy lookup
30275 attributes = attributes or {}
30276 for i = 1, #attributes do
30277 attributes[attributes[i]] = true
30278 end
30279
30280 local buf = {}
30281 -- handle slicing
30282 if attributes["#" .. self.slice_end_identifier] ~= nil and
30283 self.slice_end_type == "^" then
30284 if self.is_writing then
30285 table.insert(buf, self.undosep())
30286 table.insert(buf, tear_down_attributes())
30287 end
30288 self.is_writing = false
30289 end
30290 if attributes["#" .. self.slice_begin_identifier] ~= nil and
30291 self.slice_begin_type == "^" then
30292 table.insert(buf, apply_attributes())
30293 self.is_writing = true
30294 end
30295 if self.is_writing and start_output ~= nil then
30296 table.insert(buf, start_output)
30297 end
30298 table.insert(self.active_attributes,
30299 {attribute_type, attributes,
30300 start_output, end_output})
30301 return buf
30302 end
30303
30304 % \end{macrocode}
30305 % \begin{markdown}
30306 %
30307 % The \luamref{writer->pop\_attributes} method removes the most current of
30308 % active block-level attributes from \luamref{writer->active\_attributes}
30309 % until attributes of type `attribute_type` have been removed. The method
30310 % returns a rope constructed from the `end_output` string specified
30311 % in the calls of \luamref{writer->push\_attributes} that produced the most
30312 % current attributes, and also from output produced as a result of slicing
30313 % (see \Opt{slice}).
30314 %
30315 % \end{markdown}
30316 % \begin{macrocode}
30317 function self.pop_attributes(attribute_type)
30318 local buf = {}
30319 -- pop attributes until we find attributes of correct type
30320 -- or until no attributes remain
30321 local current_attribute_type = false
30322 while current_attribute_type ~= attribute_type and
30323 #self.active_attributes > 0 do
30324 local attributes, _, end_output
30325 current_attribute_type, attributes, _, end_output = table.unpack(
30326 self.active_attributes[#self.active_attributes])
30327 local attribute_type_level
30328 = self.attribute_type_levels[current_attribute_type]
30329 self.attribute_type_levels[current_attribute_type]
30330 = attribute_type_level - 1
30331 if self.is_writing and end_output ~= nil then
30332 table.insert(buf, end_output)
30333 end
30334 table.remove(self.active_attributes, #self.active_attributes)
30335 -- handle slicing
30336 if attributes["#" .. self.slice_end_identifier] ~= nil
30337 and self.slice_end_type == "$" then
30338 if self.is_writing then
30339 table.insert(buf, self.undosep())
30340 table.insert(buf, tear_down_attributes())
30341 end
30342 self.is_writing = false
30343 end
30344 if attributes["#" .. self.slice_begin_identifier] ~= nil and
30345 self.slice_begin_type == "$" then
30346 self.is_writing = true
30347 table.insert(buf, apply_attributes())
30348 end
30349 end
30350 return buf
30351 end
30352 % \end{macrocode}
30353 % \begin{markdown}
30354 %
30355 %#### Automatically Generated Identifiers for Headings
30356 % Create an auto identifier string by stripping and converting characters from string `s`.
30357 %
30358 % \end{markdown}
30359 % \begin{macrocode}
30360 local function create_auto_identifier(s)
30361 local buffer = {}
30362 local prev_space = false
30363 local letter_found = false
30364 local normalized_s = s
30365 if not options.unicodeNormalization
30366 or options.unicodeNormalizationForm ~= "nfc" then
30367 normalized_s = util.normalize(normalized_s, "nfc")
30368 end
30369
30370 for _, code in utf8.codes(normalized_s) do
30371 local char = utf8.char(code)
30372
30373 -- Remove everything up to the first letter.
30374 if not letter_found then
30375 local is_letter = lpeg.match(
30376 parsers.unicode.alpha,
30377 char
30378 )
30379 if is_letter then
30380 letter_found = true
30381 else
30382 goto continue
30383 end
30384 end
30385
30386 -- Remove all non-alphanumeric characters, except underscores,
30387 -- hyphens, and periods.
30388 if not lpeg.match(
30389 ( parsers.underscore
30390 + parsers.dash
30391 + parsers.period
30392 + parsers.unicode.word
30393 + #parsers.unicode.whitespace ),
30394 char
30395 ) then
30396 goto continue
30397 end
30398
30399 -- Replace all spaces and newlines with hyphens.
30400 if lpeg.match(
30401 ( parsers.newline
30402 + #parsers.unicode.whitespace ),
30403 char
30404 ) then
30405 char = "-"
30406 if prev_space then
30407 goto continue
30408 else
30409 prev_space = true
30410 end
30411 else
30412 -- Case-fold all alphabetic characters.
30413 local form = nil
30414 if options.unicodeNormalization then
30415 form = options.unicodeNormalizationForm
30416 end
30417 char = util.casefold(char, form)
30418 prev_space = false
30419 end
30420
30421 table.insert(buffer, char)
30422
30423 ::continue::
30424 end
30425
30426 if prev_space then
30427 table.remove(buffer)
30428 end
30429
30430 local identifier = #buffer == 0 and "section"
30431 or table.concat(buffer, "")
30432 return identifier
30433 end
30434 % \end{macrocode}
30435 % \begin{markdown}
30436 %
30437 % Create an GitHub-flavored auto identifier string by stripping and converting characters from string `s`.
30438 %
30439 % \end{markdown}
30440 % \begin{macrocode}
30441 local function create_gfm_auto_identifier(s)
30442 local buffer = {}
30443 local prev_space = false
30444 local letter_found = false
30445 local normalized_s = s
30446 if not options.unicodeNormalization
30447 or options.unicodeNormalizationForm ~= "nfc" then
30448 normalized_s = util.normalize(normalized_s, "nfc")
30449 end
30450
30451 for _, code in utf8.codes(normalized_s) do
30452 local char = utf8.char(code)
30453
30454 -- Remove everything up to the first non-space.
30455 if not letter_found then
30456 local is_letter = not lpeg.match(
30457 #parsers.unicode.whitespace,
30458 char
30459 )
30460 if is_letter then
30461 letter_found = true
30462 else
30463 goto continue
30464 end
30465 end
30466
30467 -- Remove all non-alphanumeric characters, except underscores
30468 -- and hyphens.
30469 if not lpeg.match(
30470 ( parsers.underscore
30471 + parsers.dash
30472 + parsers.unicode.word
30473 + #parsers.unicode.whitespace ),
30474 char
30475 ) then
30476 prev_space = false
30477 goto continue
30478 end
30479
30480 -- Replace all spaces and newlines with hyphens.
30481 if lpeg.match(
30482 ( parsers.newline
30483 + #parsers.unicode.whitespace ),
30484 char
30485 ) then
30486 char = "-"
30487 if prev_space then
30488 goto continue
30489 else
30490 prev_space = true
30491 end
30492 else
30493 -- Case-fold all alphabetic characters.
30494 local form = nil
30495 if options.unicodeNormalization then
30496 form = options.unicodeNormalizationForm
30497 end
30498 char = util.casefold(char, form)
30499 prev_space = false
30500 end
30501
30502 table.insert(buffer, char)
30503
30504 ::continue::
30505 end
30506
30507 if prev_space then
30508 table.remove(buffer)
30509 end
30510
30511 local identifier = #buffer == 0 and "section"
30512 or table.concat(buffer, "")
30513 return identifier
30514 end
30515 % \end{macrocode}
30516 % \begin{markdown}
30517 %
30518 %#### Formatter of Headings
30519 % Define \luamdef{writer->heading} as a function that will transform an
30520 % input heading `s` at level `level` with attributes `attributes` to the
30521 % output format.
30522 %
30523 % \end{markdown}
30524 % \begin{macrocode}
30525 self.secbegin_text = "\\markdownRendererSectionBegin\n"
30526 self.secend_text = "\n\\markdownRendererSectionEnd "
30527 function self.heading(s, level, attributes)
30528 local buf = {}
30529 local flat_text, inlines = table.unpack(s)
30530
30531 -- push empty attributes for implied sections
30532 while self.attribute_type_levels["heading"] < level - 1 do
30533 table.insert(buf,
30534 self.push_attributes("heading",
30535 nil,
30536 self.secbegin_text,
30537 self.secend_text))
30538 end
30539
30540 -- pop attributes for sections that have ended
30541 while self.attribute_type_levels["heading"] >= level do
30542 table.insert(buf, self.pop_attributes("heading"))
30543 end
30544
30545 -- construct attributes for the new section
30546 local auto_identifiers = {}
30547 if self.options.autoIdentifiers then
30548 table.insert(auto_identifiers, create_auto_identifier(flat_text))
30549 end
30550 if self.options.gfmAutoIdentifiers then
30551 table.insert(auto_identifiers,
30552 create_gfm_auto_identifier(flat_text))
30553 end
30554 local normalized_attributes = normalize_attributes(attributes,
30555 auto_identifiers)
30556
30557 -- push attributes for the new section
30558 local start_output = {}
30559 local end_output = {}
30560 table.insert(start_output, self.secbegin_text)
30561 table.insert(end_output, self.secend_text)
30562
30563 table.insert(buf, self.push_attributes("heading",
30564 normalized_attributes,
30565 start_output,
30566 end_output))
30567 assert(self.attribute_type_levels["heading"] == level)
30568
30569 -- render the heading and its attributes
30570 if self.is_writing and #normalized_attributes > 0 then
30571 table.insert(buf,
30572 "\\markdownRendererHeaderAttributeContextBegin\n")
30573 table.insert(buf, self.attributes(normalized_attributes, false))
30574 end
30575
30576 local cmd
30577 level = level + options.shiftHeadings
30578 if level <= 1 then
30579 cmd = "\\markdownRendererHeadingOne"
30580 elseif level == 2 then
30581 cmd = "\\markdownRendererHeadingTwo"
30582 elseif level == 3 then
30583 cmd = "\\markdownRendererHeadingThree"
30584 elseif level == 4 then
30585 cmd = "\\markdownRendererHeadingFour"
30586 elseif level == 5 then
30587 cmd = "\\markdownRendererHeadingFive"
30588 elseif level >= 6 then
30589 cmd = "\\markdownRendererHeadingSix"
30590 else
30591 cmd = ""
30592 end
30593 if self.is_writing then
30594 table.insert(buf, {cmd, "{", inlines, "}"})
30595 end
30596
30597 if self.is_writing and #normalized_attributes > 0 then
30598 table.insert(buf, "\\markdownRendererHeaderAttributeContextEnd{}")
30599 end
30600
30601 return buf
30602 end
30603 % \end{macrocode}
30604 % \begin{markdown}
30605 %
30606 %#### Managing State and Deferred Writer Calls
30607 % Define \luamdef{writer->get_state} as a function that returns the current
30608 % state of the writer, where the state of a writer are its mutable member
30609 % variables.
30610 %
30611 % \end{markdown}
30612 % \begin{macrocode}
30613 function self.get_state()
30614 return {
30615 is_writing=self.is_writing,
30616 flatten_inlines=self.flatten_inlines,
30617 active_attributes={table.unpack(self.active_attributes)},
30618 }
30619 end
30620 % \end{macrocode}
30621 % \begin{markdown}
30622 %
30623 % Define \luamdef{writer->set_state} as a function that restores the input
30624 % state `s` and returns the previous state of the writer.
30625 %
30626 % \end{markdown}
30627 % \begin{macrocode}
30628 function self.set_state(s)
30629 local previous_state = self.get_state()
30630 for key, value in pairs(s) do
30631 self[key] = value
30632 end
30633 return previous_state
30634 end
30635 % \end{macrocode}
30636 % \begin{markdown}
30637 %
30638 % Define \luamdef{writer->defer_call} as a function that will encapsulate the
30639 % input function `f`, so that `f` is called with the state of the writer at the
30640 % time of calling \luamref{writer->defer_call}.
30641 %
30642 % \end{markdown}
30643 % \begin{macrocode}
30644 function self.defer_call(f)
30645 local previous_state = self.get_state()
30646 return function(...)
30647 local state = self.set_state(previous_state)
30648 local return_value = f(...)
30649 self.set_state(state)
30650 return return_value
30651 end
30652 end
30653
30654 return self
30655 end
30656 % \end{macrocode}
30657 % \begin{markdown}
30658 %
30659 %### Parsers
30660 % The \luamdef{parsers} hash table stores PEG patterns that are
30661 % static and can be reused between different \luamref{reader} objects.
30662 %
30663 % \end{markdown}
30664 % \begin{macrocode}
30665 parsers = {}
30666 % \end{macrocode}
30667 % \begin{markdown}
30668 %
30669 %#### Basic Parsers
30670 %
30671 % \end{markdown}
30672 % \begin{macrocode}
30673 parsers.percent = P("%")
30674 parsers.at = P("@")
30675 parsers.comma = P(",")
30676 parsers.asterisk = P("*")
30677 parsers.dash = P("-")
30678 parsers.plus = P("+")
30679 parsers.underscore = P("_")
30680 parsers.period = P(".")
30681 parsers.hash = P("#")
30682 parsers.dollar = P("$")
30683 parsers.ampersand = P("&")
30684 parsers.backtick = P("`")
30685 parsers.less = P("<")
30686 parsers.more = P(">")
30687 parsers.space = P(" ")
30688 parsers.squote = P("'")
30689 parsers.dquote = P('"')
30690 parsers.lparent = P("(")
30691 parsers.rparent = P(")")
30692 parsers.lbracket = P("[")
30693 parsers.rbracket = P("]")
30694 parsers.lbrace = P("{")
30695 parsers.rbrace = P("}")
30696 parsers.circumflex = P("^")
30697 parsers.slash = P("/")
30698 parsers.equal = P("=")
30699 parsers.colon = P(":")
30700 parsers.semicolon = P(";")
30701 parsers.exclamation = P("!")
30702 parsers.pipe = P("|")
30703 parsers.tilde = P("~")
30704 parsers.backslash = P("\\")
30705 parsers.tab = P("\t")
30706 parsers.newline = P("\n")
30707
30708 parsers.digit = R("09")
30709 parsers.hexdigit = R("09","af","AF")
30710 parsers.letter = R("AZ","az")
30711 parsers.alphanumeric = R("AZ","az","09")
30712 parsers.keyword = parsers.letter
30713 * (parsers.alphanumeric + parsers.dash)^0
30714
30715 parsers.doubleasterisks = P("**")
30716 parsers.doubleunderscores = P("__")
30717 parsers.doubletildes = P("~~")
30718 parsers.fourspaces = P(" ")
30719
30720 parsers.any = P(1)
30721 parsers.eof = P(-1)
30722 parsers.succeed = P(true)
30723 parsers.fail = P(false)
30724
30725 parsers.internal_punctuation = S(":;,.?")
30726 parsers.ascii_punctuation = S("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~")
30727
30728 parsers.escapable = parsers.ascii_punctuation
30729 parsers.anyescaped = parsers.backslash / ""
30730 * parsers.escapable
30731 + parsers.any
30732
30733 parsers.spacechar = S("\t ")
30734 parsers.spacing = S(" \n\r\t")
30735 parsers.nonspacechar = parsers.any - parsers.spacing
30736 parsers.optionalspace = parsers.spacechar^0
30737
30738 parsers.normalchar = parsers.any - (V("SpecialChar")
30739 + parsers.spacing)
30740 parsers.nonindentspace = parsers.space^-3 * - parsers.spacechar
30741 parsers.indent = parsers.space^-3 * parsers.tab
30742 + parsers.fourspaces / ""
30743 parsers.linechar = P(1 - parsers.newline)
30744
30745 parsers.blankline = parsers.optionalspace
30746 * parsers.newline / "\n"
30747 parsers.blanklines = parsers.blankline^0
30748 parsers.skipblanklines = ( parsers.optionalspace
30749 * parsers.newline)^0
30750 parsers.indentedline = parsers.indent /""
30751 * C( parsers.linechar^1
30752 * parsers.newline^-1)
30753 parsers.optionallyindentedline = parsers.indent^-1 /""
30754 * C( parsers.linechar^1
30755 * parsers.newline^-1)
30756 parsers.sp = parsers.spacing^0
30757 parsers.spnl = parsers.optionalspace
30758 * ( parsers.newline
30759 * parsers.optionalspace)^-1
30760 parsers.line = parsers.linechar^0 * parsers.newline
30761 parsers.nonemptyline = parsers.line - parsers.blankline
30762
30763 % \end{macrocode}
30764 % \begin{markdown}
30765 %
30766 %#### Parsers for Unicode Character Classes and Categories
30767 % We define high-level parsers in table \luamdef{parsers.unicode} based on the
30768 % low-level parsers in \luamref{unicode_data.categories}, defined in Section
30769 % <#sec:unicode-character-classes-and-categories>. Unlike the low-level
30770 % parsers, the high-level parsers are invariant to the number of bytes the
30771 % Unicode characters occupy after conversion to UTF-8.
30772 %
30773 % \end{markdown}
30774 % \begin{macrocode}
30775 parsers.unicode = {}
30776 parsers.unicode.preceding_punctuation = parsers.fail
30777 parsers.unicode.punctuation = parsers.fail
30778 parsers.unicode.alpha = parsers.fail
30779 parsers.unicode.numeric = parsers.fail
30780 parsers.unicode.word = parsers.fail
30781 parsers.unicode.preceding_whitespace = parsers.fail
30782 parsers.unicode.whitespace = parsers.fail
30783 for n = 1, 4 do
30784 % \end{macrocode}
30785 % \begin{markdown}
30786 %
30787 % For punctuation, accept any characters from Unicode categories P
30788 % (punctuation) and S (symbol), as mandated by [the CommonMark standard][1].
30789 %
30790 % [1]: https://spec.commonmark.org/0.31.2/#unicode-punctuation-character
30791 %
30792 % \end{markdown}
30793 % \begin{macrocode}
30794 local punctuation_of_length_n
30795 = unicode_data.categories.P[n]
30796 + unicode_data.categories.S[n]
30797 parsers.unicode.preceding_punctuation
30798 = parsers.unicode.preceding_punctuation
30799 + B(punctuation_of_length_n)
30800 parsers.unicode.punctuation
30801 = parsers.unicode.punctuation
30802 + punctuation_of_length_n
30803 % \end{macrocode}
30804 % \begin{markdown}
30805 %
30806 % For alphabetical characters, accept any characters from Unicode category
30807 % L (letter), similar to the character class `%a` from the Lua library Selene
30808 % Unicode.
30809 %
30810 % \end{markdown}
30811 % \begin{macrocode}
30812 local alpha_of_length_n = unicode_data.categories.L[n]
30813 parsers.unicode.alpha
30814 = parsers.unicode.alpha
30815 + alpha_of_length_n
30816 % \end{macrocode}
30817 % \begin{markdown}
30818 %
30819 % For numeric characters, accept any characters from Unicode category
30820 % N (number), similar to the character class `%n` from the Lua library Selene
30821 % Unicode.
30822 %
30823 % \end{markdown}
30824 % \begin{macrocode}
30825 local numeric_of_length_n = unicode_data.categories.N[n]
30826 parsers.unicode.numeric
30827 = parsers.unicode.numeric
30828 + numeric_of_length_n
30829 % \end{macrocode}
30830 % \begin{markdown}
30831 %
30832 % For word characters, accept any characters from Unicode categories
30833 % L (letter), N (number), and Pc (connector punctuation), similar to the
30834 % character class `%w` from the Lua library Selene Unicode.
30835 %
30836 % \end{markdown}
30837 % \begin{macrocode}
30838 local word_of_length_n
30839 = alpha_of_length_n
30840 + numeric_of_length_n
30841 + unicode_data.categories.Pc[n]
30842 parsers.unicode.word
30843 = parsers.unicode.word
30844 + word_of_length_n
30845 % \end{macrocode}
30846 % \begin{markdown}
30847 %
30848 % For space characters, accept any characters from Unicode category Z
30849 % (separator), as well as the ASCII control characters 9 (horizontal tab)
30850 % through 13 (carriage return), similar to the character class `%s` from the
30851 % Lua library Selene Unicode.
30852 %
30853 % \end{markdown}
30854 % \begin{macrocode}
30855 local whitespace_of_length_n = unicode_data.categories.Z[n]
30856 if n == 1 then
30857 whitespace_of_length_n
30858 = whitespace_of_length_n
30859 + R("\t\r")
30860 end
30861 parsers.unicode.preceding_whitespace
30862 = parsers.unicode.preceding_whitespace
30863 + B(whitespace_of_length_n)
30864 parsers.unicode.whitespace
30865 = parsers.unicode.whitespace
30866 + whitespace_of_length_n
30867 end
30868 % \end{macrocode}
30869 % \begin{markdown}
30870 %
30871 %#### Parsers Used for Indentation
30872 %
30873 % \end{markdown}
30874 % \begin{macrocode}
30875
30876 parsers.leader = parsers.space^-3
30877
30878 % \end{macrocode}
30879 % \begin{markdown}
30880 %
30881 % Check if a trail exists and is non-empty in the indent table `indent_table`.
30882 %
30883 % \end{markdown}
30884 % \begin{macrocode}
30885 local function has_trail(indent_table)
30886 return indent_table ~= nil and
30887 indent_table.trail ~= nil and
30888 next(indent_table.trail) ~= nil
30889 end
30890
30891 % \end{macrocode}
30892 % \begin{markdown}
30893 %
30894 % Check if indent table `indent_table` has any indents.
30895 %
30896 % \end{markdown}
30897 % \begin{macrocode}
30898 local function has_indents(indent_table)
30899 return indent_table ~= nil and
30900 indent_table.indents ~= nil and
30901 next(indent_table.indents) ~= nil
30902 end
30903
30904 % \end{macrocode}
30905 % \begin{markdown}
30906 %
30907 % Add a trail `trail_info` to the indent table `indent_table`.
30908 %
30909 % \end{markdown}
30910 % \begin{macrocode}
30911 local function add_trail(indent_table, trail_info)
30912 indent_table.trail = trail_info
30913 return indent_table
30914 end
30915
30916 % \end{macrocode}
30917 % \begin{markdown}
30918 %
30919 % Remove a trail `trail_info` from the indent table `indent_table`.
30920 %
30921 % \end{markdown}
30922 % \begin{macrocode}
30923 local function remove_trail(indent_table)
30924 indent_table.trail = nil
30925 return indent_table
30926 end
30927
30928 % \end{macrocode}
30929 % \begin{markdown}
30930 %
30931 % Update the indent table `indent_table` by adding or removing a new
30932 % indent `add`.
30933 %
30934 % \end{markdown}
30935 % \begin{macrocode}
30936 local function update_indent_table(indent_table, new_indent, add)
30937 indent_table = remove_trail(indent_table)
30938
30939 if not has_indents(indent_table) then
30940 indent_table.indents = {}
30941 end
30942
30943
30944 if add then
30945 indent_table.indents[#indent_table.indents + 1] = new_indent
30946 else
30947 if indent_table.indents[#indent_table.indents].name
30948 == new_indent.name then
30949 indent_table.indents[#indent_table.indents] = nil
30950 end
30951 end
30952
30953 return indent_table
30954 end
30955
30956 % \end{macrocode}
30957 % \begin{markdown}
30958 %
30959 % Remove an indent by its name `name`.
30960 %
30961 % \end{markdown}
30962 % \begin{macrocode}
30963 local function remove_indent(name)
30964 local remove_indent_level =
30965 function(s, i, indent_table) -- luacheck: ignore s i
30966 indent_table = update_indent_table(indent_table, {name=name},
30967 false)
30968 return true, indent_table
30969 end
30970
30971 return Cg(Cmt(Cb("indent_info"), remove_indent_level), "indent_info")
30972 end
30973
30974 % \end{macrocode}
30975 % \begin{markdown}
30976 %
30977 % Process the spacing of a string of spaces and tabs `spacing` with preceding indent width from
30978 % the start of the line `indent` and strip up to `left_strip_length` spaces. Return the remainder
30979 % `remainder` and whether there is enough spaces to produce a code `is_code`. Return how many
30980 % spaces were stripped, as well as if the minimum was met `is_minimum` and what remainder it
30981 % left `minimum_remainder`.
30982 %
30983 % \end{markdown}
30984 % \begin{macrocode}
30985 local function process_starter_spacing(indent, spacing,
30986 minimum, left_strip_length)
30987 left_strip_length = left_strip_length or 0
30988
30989 local count = 0
30990 local tab_value = 4 - (indent) % 4
30991
30992 local code_started, minimum_found = false, false
30993 local code_start, minimum_remainder = "", ""
30994
30995 local left_total_stripped = 0
30996 local full_remainder = ""
30997
30998 if spacing ~= nil then
30999 for i = 1, #spacing do
31000 local character = spacing:sub(i, i)
31001
31002 if character == "\t" then
31003 count = count + tab_value
31004 tab_value = 4
31005 elseif character == " " then
31006 count = count + 1
31007 tab_value = 4 - (1 - tab_value) % 4
31008 end
31009
31010 if (left_strip_length ~= 0) then
31011 local possible_to_strip = math.min(count, left_strip_length)
31012 count = count - possible_to_strip
31013 left_strip_length = left_strip_length - possible_to_strip
31014 left_total_stripped = left_total_stripped + possible_to_strip
31015 else
31016 full_remainder = full_remainder .. character
31017 end
31018
31019 if (minimum_found) then
31020 minimum_remainder = minimum_remainder .. character
31021 elseif (count >= minimum) then
31022 minimum_found = true
31023 minimum_remainder = minimum_remainder
31024 .. string.rep(" ", count - minimum)
31025 end
31026
31027 if (code_started) then
31028 code_start = code_start .. character
31029 elseif (count >= minimum + 4) then
31030 code_started = true
31031 code_start = code_start
31032 .. string.rep(" ", count - (minimum + 4))
31033 end
31034 end
31035 end
31036
31037 local remainder
31038 if (code_started) then
31039 remainder = code_start
31040 else
31041 remainder = string.rep(" ", count - minimum)
31042 end
31043
31044 local is_minimum = count >= minimum
31045 return {
31046 is_code = code_started,
31047 remainder = remainder,
31048 left_total_stripped = left_total_stripped,
31049 is_minimum = is_minimum,
31050 minimum_remainder = minimum_remainder,
31051 total_length = count,
31052 full_remainder = full_remainder
31053 }
31054 end
31055
31056 % \end{macrocode}
31057 % \begin{markdown}
31058 %
31059 % Count the total width of all indents in the indent table `indent_table`.
31060 %
31061 % \end{markdown}
31062 % \begin{macrocode}
31063 local function count_indent_tab_level(indent_table)
31064 local count = 0
31065 if not has_indents(indent_table) then
31066 return count
31067 end
31068
31069 for i=1, #indent_table.indents do
31070 count = count + indent_table.indents[i].length
31071 end
31072 return count
31073 end
31074
31075 % \end{macrocode}
31076 % \begin{markdown}
31077 %
31078 % Count the total width of a delimiter `delimiter`.
31079 %
31080 % \end{markdown}
31081 % \begin{macrocode}
31082 local function total_delimiter_length(delimiter)
31083 local count = 0
31084 if type(delimiter) == "string" then return #delimiter end
31085 for _, value in pairs(delimiter) do
31086 count = count + total_delimiter_length(value)
31087 end
31088 return count
31089 end
31090
31091 % \end{macrocode}
31092 % \begin{markdown}
31093 %
31094 % Process the container starter `starter` of a type `indent_type`. Adjust the width of the indent
31095 % if the delimiter is followed only by whitespaces `is_blank`.
31096 %
31097 % \end{markdown}
31098 % \begin{macrocode}
31099 local function process_starter_indent(_, _, indent_table, starter,
31100 is_blank, indent_type, breakable)
31101 local last_trail = starter[1]
31102 local delimiter = starter[2]
31103 local raw_new_trail = starter[3]
31104
31105 if indent_type == "bq" and not breakable then
31106 indent_table.ignore_blockquote_blank = true
31107 end
31108
31109 if has_trail(indent_table) then
31110 local trail = indent_table.trail
31111 if trail.is_code then
31112 return false
31113 end
31114 last_trail = trail.remainder
31115 else
31116 local sp = process_starter_spacing(0, last_trail, 0, 0)
31117
31118 if sp.is_code then
31119 return false
31120 end
31121 last_trail = sp.remainder
31122 end
31123
31124 local preceding_indentation = count_indent_tab_level(indent_table) % 4
31125 local last_trail_length = #last_trail
31126 local delimiter_length = total_delimiter_length(delimiter)
31127
31128 local total_indent_level = preceding_indentation + last_trail_length
31129 + delimiter_length
31130
31131 local sp = {}
31132 if not is_blank then
31133 sp = process_starter_spacing(total_indent_level, raw_new_trail,
31134 0, 1)
31135 end
31136
31137 local del_trail_length = sp.left_total_stripped
31138 if is_blank then
31139 del_trail_length = 1
31140 elseif not sp.is_code then
31141 del_trail_length = del_trail_length + #sp.remainder
31142 end
31143
31144 local indent_length = last_trail_length + delimiter_length
31145 + del_trail_length
31146 local new_indent_info = {name=indent_type, length=indent_length}
31147
31148 indent_table = update_indent_table(indent_table, new_indent_info,
31149 true)
31150 indent_table = add_trail(indent_table,
31151 {is_code=sp.is_code,
31152 remainder=sp.remainder,
31153 total_length=sp.total_length,
31154 full_remainder=sp.full_remainder})
31155
31156 return true, indent_table
31157 end
31158
31159 % \end{macrocode}
31160 % \begin{markdown}
31161 %
31162 % Return the pattern corresponding with the indent name `name`.
31163 %
31164 % \end{markdown}
31165 % \begin{macrocode}
31166 local function decode_pattern(name)
31167 local delimeter = parsers.succeed
31168 if name == "bq" then
31169 delimeter = parsers.more
31170 end
31171
31172 return C(parsers.optionalspace) * C(delimeter)
31173 * C(parsers.optionalspace) * Cp()
31174 end
31175
31176 % \end{macrocode}
31177 % \begin{markdown}
31178 %
31179 % Find the first blank-only indent of the indent table `indent_table` followed
31180 % by blank-only indents.
31181 %
31182 % \end{markdown}
31183 % \begin{macrocode}
31184 local function left_blank_starter(indent_table)
31185 local blank_starter_index
31186
31187 if not has_indents(indent_table) then
31188 return
31189 end
31190
31191 for i = #indent_table.indents,1,-1 do
31192 local value = indent_table.indents[i]
31193 if value.name == "li" then
31194 blank_starter_index = i
31195 else
31196 break
31197 end
31198 end
31199
31200 return blank_starter_index
31201 end
31202
31203 % \end{macrocode}
31204 % \begin{markdown}
31205 %
31206 % Apply the patterns decoded from the indents of the indent table `indent_table`
31207 % iteratively starting at position `index` of the string `s`. If the `is_optional`
31208 % mode is selected, match as many patterns as possible, else match all or fail.
31209 % With the option `is_blank`, the parsing behaves as optional after the position
31210 % of a blank-only indent has been surpassed.
31211 %
31212 % \end{markdown}
31213 % \begin{macrocode}
31214 local function traverse_indent(s, i, indent_table, is_optional,
31215 is_blank, current_line_indents)
31216 local new_index = i
31217
31218 local preceding_indentation = 0
31219 local current_trail = {}
31220
31221 local blank_starter = left_blank_starter(indent_table)
31222
31223 if current_line_indents == nil then
31224 current_line_indents = {}
31225 end
31226
31227 for index = 1,#indent_table.indents do
31228 local value = indent_table.indents[index]
31229 local pattern = decode_pattern(value.name)
31230
31231 -- match decoded pattern
31232 local new_indent_info = lpeg.match(Ct(pattern), s, new_index)
31233 if new_indent_info == nil then
31234 local blankline_end = lpeg.match(
31235 Ct(parsers.blankline * Cg(Cp(), "pos")), s, new_index)
31236 if is_optional or not indent_table.ignore_blockquote_blank
31237 or not blankline_end then
31238 return is_optional, new_index, current_trail,
31239 current_line_indents
31240 end
31241
31242 return traverse_indent(s, tonumber(blankline_end.pos),
31243 indent_table, is_optional, is_blank,
31244 current_line_indents)
31245 end
31246
31247 local raw_last_trail = new_indent_info[1]
31248 local delimiter = new_indent_info[2]
31249 local raw_new_trail = new_indent_info[3]
31250 local next_index = new_indent_info[4]
31251
31252 local space_only = delimiter == ""
31253
31254 -- check previous trail
31255 if not space_only and next(current_trail) == nil then
31256 local sp = process_starter_spacing(0, raw_last_trail, 0, 0)
31257 current_trail = {is_code=sp.is_code, remainder=sp.remainder,
31258 total_length=sp.total_length,
31259 full_remainder=sp.full_remainder}
31260 end
31261
31262 if next(current_trail) ~= nil then
31263 if not space_only and current_trail.is_code then
31264 return is_optional, new_index, current_trail,
31265 current_line_indents
31266 end
31267 if current_trail.internal_remainder ~= nil then
31268 raw_last_trail = current_trail.internal_remainder
31269 end
31270 end
31271
31272 local raw_last_trail_length = 0
31273 local delimiter_length = 0
31274
31275 if not space_only then
31276 delimiter_length = #delimiter
31277 raw_last_trail_length = #raw_last_trail
31278 end
31279
31280 local total_indent_level = preceding_indentation
31281 + raw_last_trail_length + delimiter_length
31282
31283 local spacing_to_process
31284 local minimum = 0
31285 local left_strip_length = 0
31286
31287 if not space_only then
31288 spacing_to_process = raw_new_trail
31289 left_strip_length = 1
31290 else
31291 spacing_to_process = raw_last_trail
31292 minimum = value.length
31293 end
31294
31295 local sp = process_starter_spacing(total_indent_level,
31296 spacing_to_process, minimum,
31297 left_strip_length)
31298
31299 if space_only and not sp.is_minimum then
31300 return is_optional or (is_blank and blank_starter <= index),
31301 new_index, current_trail, current_line_indents
31302 end
31303
31304 local indent_length = raw_last_trail_length + delimiter_length
31305 + sp.left_total_stripped
31306
31307 -- update info for the next pattern
31308 if not space_only then
31309 preceding_indentation = preceding_indentation + indent_length
31310 else
31311 preceding_indentation = preceding_indentation + value.length
31312 end
31313
31314 current_trail = {is_code=sp.is_code, remainder=sp.remainder,
31315 internal_remainder=sp.minimum_remainder,
31316 total_length=sp.total_length,
31317 full_remainder=sp.full_remainder}
31318
31319 current_line_indents[#current_line_indents + 1] = new_indent_info
31320 new_index = next_index
31321 end
31322
31323 return true, new_index, current_trail, current_line_indents
31324 end
31325
31326 % \end{macrocode}
31327 % \begin{markdown}
31328 %
31329 % Check if a code trail is expected.
31330 %
31331 % \end{markdown}
31332 % \begin{macrocode}
31333 local function check_trail(expect_code, is_code)
31334 return (expect_code and is_code) or (not expect_code and not is_code)
31335 end
31336
31337 % \end{macrocode}
31338 % \begin{markdown}
31339 %
31340 % Check if the current trail of the `indent_table` would produce code if it is expected `expect_code`
31341 % or it would not if it is not. If there is no trail, process and check the current spacing `spacing`.
31342 %
31343 % \end{markdown}
31344 % \begin{macrocode}
31345 local check_trail_joined =
31346 function(s, i, indent_table, -- luacheck: ignore s i
31347 spacing, expect_code, omit_remainder)
31348 local is_code
31349 local remainder
31350
31351 if has_trail(indent_table) then
31352 local trail = indent_table.trail
31353 is_code = trail.is_code
31354 if is_code then
31355 remainder = trail.remainder
31356 else
31357 remainder = trail.full_remainder
31358 end
31359 else
31360 local sp = process_starter_spacing(0, spacing, 0, 0)
31361 is_code = sp.is_code
31362 if is_code then
31363 remainder = sp.remainder
31364 else
31365 remainder = sp.full_remainder
31366 end
31367 end
31368
31369 local result = check_trail(expect_code, is_code)
31370 if omit_remainder then
31371 return result
31372 end
31373 return result, remainder
31374 end
31375
31376 % \end{macrocode}
31377 % \begin{markdown}
31378 %
31379 % Check if the current trail of the `indent_table` is of length between `min` and `max`.
31380 %
31381 % \end{markdown}
31382 % \begin{macrocode}
31383 local check_trail_length =
31384 function(s, i, indent_table, -- luacheck: ignore s i
31385 spacing, min, max)
31386 local trail
31387
31388 if has_trail(indent_table) then
31389 trail = indent_table.trail
31390 else
31391 trail = process_starter_spacing(0, spacing, 0, 0)
31392 end
31393
31394 local total_length = trail.total_length
31395 if total_length == nil then
31396 return false
31397 end
31398
31399 return min <= total_length and total_length <= max
31400 end
31401
31402 % \end{macrocode}
31403 % \begin{markdown}
31404 %
31405 % Check the indentation of the continuation line, optionally with
31406 % the mode `is_optional` selected. Check blank line exclusively with `is_blank`.
31407 %
31408 % \end{markdown}
31409 % \begin{macrocode}
31410 local function check_continuation_indentation(s, i, indent_table,
31411 is_optional, is_blank)
31412 if not has_indents(indent_table) then
31413 return true
31414 end
31415
31416 local passes, new_index, current_trail, current_line_indents =
31417 traverse_indent(s, i, indent_table, is_optional, is_blank)
31418
31419 if passes then
31420 indent_table.current_line_indents = current_line_indents
31421 indent_table = add_trail(indent_table, current_trail)
31422 return new_index, indent_table
31423 end
31424 return false
31425 end
31426
31427 % \end{macrocode}
31428 % \begin{markdown}
31429 %
31430 % Get name of the last indent from the `indent_table`.
31431 %
31432 % \end{markdown}
31433 % \begin{macrocode}
31434 local function get_last_indent_name(indent_table)
31435 if has_indents(indent_table) then
31436 return indent_table.indents[#indent_table.indents].name
31437 end
31438 end
31439
31440 % \end{macrocode}
31441 % \begin{markdown}
31442 %
31443 % Remove the remainder altogether if the last indent from the `indent_table`
31444 % is blank-only.
31445 %
31446 % \end{markdown}
31447 % \begin{macrocode}
31448 local function remove_remainder_if_blank(indent_table, remainder)
31449 if get_last_indent_name(indent_table) == "li" then
31450 return ""
31451 end
31452 return remainder
31453 end
31454
31455 % \end{macrocode}
31456 % \begin{markdown}
31457 %
31458 % Take the trail `trail` or create a new one from `spacing` and compare it
31459 % with the expected `trail_type`. On success return the index `i` and the
31460 % remainder of the trail.
31461 %
31462 % \end{markdown}
31463 % \begin{macrocode}
31464 local check_trail_type =
31465 function(s, i, -- luacheck: ignore s i
31466 trail, spacing, trail_type)
31467 if trail == nil then
31468 trail = process_starter_spacing(0, spacing, 0, 0)
31469 end
31470
31471 if trail_type == "non-code" then
31472 return check_trail(false, trail.is_code)
31473 end
31474 if trail_type == "code" then
31475 return check_trail(true, trail.is_code)
31476 end
31477 if trail_type == "full-code" then
31478 if (trail.is_code) then
31479 return i, trail.remainder
31480 end
31481 return i, ""
31482 end
31483 if trail_type == "full-any" then
31484 return i, trail.internal_remainder
31485 end
31486 end
31487
31488 % \end{macrocode}
31489 % \begin{markdown}
31490 %
31491 % Stores or restores an `is_freezing` trail from indent table `indent_table`.
31492 %
31493 % \end{markdown}
31494 % \begin{macrocode}
31495 local trail_freezing =
31496 function(s, i, -- luacheck: ignore s i
31497 indent_table, is_freezing)
31498 if is_freezing then
31499 if indent_table.is_trail_frozen then
31500 indent_table.trail = indent_table.frozen_trail
31501 else
31502 indent_table.frozen_trail = indent_table.trail
31503 indent_table.is_trail_frozen = true
31504 end
31505 else
31506 indent_table.frozen_trail = nil
31507 indent_table.is_trail_frozen = false
31508 end
31509 return true, indent_table
31510 end
31511
31512 % \end{macrocode}
31513 % \begin{markdown}
31514 %
31515 % Check the indentation of the continuation line, optionally with
31516 % the mode `is_optional` selected. Check blank line specifically with `is_blank`.
31517 % Additionally, also directly check the new trail with a type `trail_type`.
31518 %
31519 % \end{markdown}
31520 % \begin{macrocode}
31521 local check_continuation_indentation_and_trail =
31522 function (s, i, indent_table, is_optional, is_blank, trail_type,
31523 reset_rem, omit_remainder)
31524 if not has_indents(indent_table) then
31525 local spacing, new_index = lpeg.match( C(parsers.spacechar^0)
31526 * Cp(), s, i)
31527 local result, remainder = check_trail_type(s, i,
31528 indent_table.trail, spacing, trail_type)
31529 if remainder == nil then
31530 if result then
31531 return new_index
31532 end
31533 return false
31534 end
31535 if result then
31536 return new_index, remainder
31537 end
31538 return false
31539 end
31540
31541 local passes, new_index, current_trail = traverse_indent(s, i,
31542 indent_table, is_optional, is_blank)
31543
31544 if passes then
31545 local spacing
31546 if current_trail == nil then
31547 local newer_spacing, newer_index = lpeg.match(
31548 C(parsers.spacechar^0) * Cp(), s, i)
31549 current_trail = process_starter_spacing(0, newer_spacing, 0, 0)
31550 new_index = newer_index
31551 spacing = newer_spacing
31552 else
31553 spacing = current_trail.remainder
31554 end
31555 local result, remainder = check_trail_type(s, new_index,
31556 current_trail, spacing, trail_type)
31557 if remainder == nil or omit_remainder then
31558 if result then
31559 return new_index
31560 end
31561 return false
31562 end
31563
31564 if is_blank and reset_rem then
31565 remainder = remove_remainder_if_blank(indent_table, remainder)
31566 end
31567 if result then
31568 return new_index, remainder
31569 end
31570 return false
31571 end
31572 return false
31573 end
31574
31575 % \end{macrocode}
31576 % \begin{markdown}
31577 %
31578 % The following patterns check whitespace indentation at the start of a block.
31579 %
31580 % \end{markdown}
31581 % \begin{macrocode}
31582 parsers.check_trail = Cmt( Cb("indent_info") * C(parsers.spacechar^0)
31583 * Cc(false), check_trail_joined)
31584
31585 parsers.check_trail_no_rem = Cmt( Cb("indent_info")
31586 * C(parsers.spacechar^0) * Cc(false)
31587 * Cc(true), check_trail_joined)
31588
31589 parsers.check_code_trail = Cmt( Cb("indent_info")
31590 * C(parsers.spacechar^0)
31591 * Cc(true), check_trail_joined)
31592
31593 parsers.check_trail_length_range = function(min, max)
31594 return Cmt( Cb("indent_info") * C(parsers.spacechar^0) * Cc(min)
31595 * Cc(max), check_trail_length)
31596 end
31597
31598 parsers.check_trail_length = function(n)
31599 return parsers.check_trail_length_range(n, n)
31600 end
31601
31602 % \end{macrocode}
31603 % \begin{markdown}
31604 %
31605 % The following patterns handle trail backup, to prevent a failing pattern to modify it before
31606 % passing it to the next.
31607 %
31608 % \end{markdown}
31609 % \begin{macrocode}
31610 parsers.freeze_trail = Cg( Cmt(Cb("indent_info")
31611 * Cc(true), trail_freezing), "indent_info")
31612
31613 parsers.unfreeze_trail = Cg(Cmt(Cb("indent_info") * Cc(false),
31614 trail_freezing), "indent_info")
31615
31616 % \end{macrocode}
31617 % \begin{markdown}
31618 %
31619 % The following patterns check indentation in continuation lines as defined by the container start.
31620 %
31621 % \end{markdown}
31622 % \begin{macrocode}
31623 parsers.check_minimal_indent = Cmt(Cb("indent_info") * Cc(false),
31624 check_continuation_indentation)
31625
31626 parsers.check_optional_indent = Cmt(Cb("indent_info") * Cc(true),
31627 check_continuation_indentation)
31628
31629 parsers.check_minimal_blank_indent
31630 = Cmt( Cb("indent_info") * Cc(false)
31631 * Cc(true)
31632 , check_continuation_indentation)
31633
31634 % \end{macrocode}
31635 % \begin{markdown}
31636 %
31637 % The following patterns check indentation in continuation lines as defined by the container start.
31638 % Additionally the subsequent trail is also directly checked.
31639 %
31640 % \end{markdown}
31641 % \begin{macrocode}
31642
31643 parsers.check_minimal_indent_and_trail =
31644 Cmt( Cb("indent_info")
31645 * Cc(false) * Cc(false) * Cc("non-code") * Cc(true)
31646 , check_continuation_indentation_and_trail)
31647
31648 parsers.check_minimal_indent_and_code_trail =
31649 Cmt( Cb("indent_info")
31650 * Cc(false) * Cc(false) * Cc("code") * Cc(false)
31651 , check_continuation_indentation_and_trail)
31652
31653 parsers.check_minimal_blank_indent_and_full_code_trail =
31654 Cmt( Cb("indent_info")
31655 * Cc(false) * Cc(true) * Cc("full-code") * Cc(true)
31656 , check_continuation_indentation_and_trail)
31657
31658 parsers.check_minimal_indent_and_any_trail =
31659 Cmt( Cb("indent_info")
31660 * Cc(false) * Cc(false) * Cc("full-any") * Cc(true) * Cc(false)
31661 , check_continuation_indentation_and_trail)
31662
31663 parsers.check_minimal_blank_indent_and_any_trail =
31664 Cmt( Cb("indent_info")
31665 * Cc(false) * Cc(true) * Cc("full-any") * Cc(true) * Cc(false)
31666 , check_continuation_indentation_and_trail)
31667
31668 parsers.check_minimal_blank_indent_and_any_trail_no_rem =
31669 Cmt( Cb("indent_info")
31670 * Cc(false) * Cc(true) * Cc("full-any") * Cc(true) * Cc(true)
31671 , check_continuation_indentation_and_trail)
31672
31673 parsers.check_optional_indent_and_any_trail =
31674 Cmt( Cb("indent_info")
31675 * Cc(true) * Cc(false) * Cc("full-any") * Cc(true) * Cc(false)
31676 , check_continuation_indentation_and_trail)
31677
31678 parsers.check_optional_blank_indent_and_any_trail =
31679 Cmt( Cb("indent_info")
31680 * Cc(true) * Cc(true) * Cc("full-any") * Cc(true) * Cc(false)
31681 , check_continuation_indentation_and_trail)
31682
31683 % \end{macrocode}
31684 % \begin{markdown}
31685 %
31686 % The following patterns specify behaviour around newlines.
31687 %
31688 % \end{markdown}
31689 % \begin{macrocode}
31690
31691 parsers.spnlc_noexc = parsers.optionalspace
31692 * ( parsers.newline
31693 * parsers.check_minimal_indent_and_any_trail)^-1
31694
31695 parsers.spnlc = parsers.optionalspace
31696 * (V("EndlineNoSub"))^-1
31697
31698 parsers.spnlc_sep = parsers.optionalspace * V("EndlineNoSub")
31699 + parsers.spacechar^1
31700
31701 parsers.only_blank = parsers.spacechar^0
31702 * (parsers.newline + parsers.eof)
31703
31704 % \end{macrocode}
31705 % \begin{figure}
31706 % \hspace*{-0.1\textwidth}
31707 % \begin{minipage}{1.2\textwidth}
31708 % \centering
31709 % \begin{tikzpicture}[shorten >=1pt, line width=0.1mm, >={Stealth[length=2mm]}, node distance=4.5cm, on grid, auto]
31710 % \node[state, initial by diamond, accepting] (noop) {initial};
31711 % \node[state] (odd_backslash) [above right=of noop] {odd backslash};
31712 % \node[state] (even_backslash) [below right=of odd_backslash] {even backslash};
31713 % \node[state] (comment) [below=of noop] {comment};
31714 % \node[state] (leading_spaces) [below=of even_backslash, align=center] {leading tabs\\and spaces};
31715 % \node[state] (blank_line) [below right=of comment] {blank line};
31716 % \path[->]
31717 % (noop) edge [in=150, out=180, loop] node [align=center, yshift=-0.75cm] {match [$^\wedge$\textbackslash\%]\\capture \textbackslash$\!^{2k}$\meta{match}\\reset $k$} ()
31718 % edge [bend right=10] node [below right=-0.2cm] {match \textbackslash} (odd_backslash)
31719 % edge [bend left=30] node [left, align=center] {match \%\\capture \textbackslash$\!^k$\\reset $k$} (comment)
31720 % (comment) edge [in=305, out=325, loop] node [xshift=-1.2cm] {match [$^\wedge$$\drsh$]} ()
31721 % edge [bend left=10] node {match $\drsh$} (leading_spaces)
31722 % (leading_spaces) edge [loop below] node {match [\textvisiblespace$\rightleftarrows$]} ()
31723 % edge [bend right=90] node [right] {match \textbackslash} (odd_backslash)
31724 % edge [bend left=10] node {match \%} (comment)
31725 % edge [bend right=10] node {$\epsilon$} (blank_line)
31726 % edge [bend left=10] node [align=center, right=0.3cm] {match [$^\wedge$\textvisiblespace$\rightleftarrows$$\drsh$\textbackslash\%]\\capture \meta{match}} (noop)
31727 % (blank_line) edge [loop below] node {match [\textvisiblespace$\rightleftarrows$]} ()
31728 % edge [bend left=90] node [align=center, below=1.2cm] {match $\drsh$\\ capture $\drsh\drsh$} (noop)
31729 % (odd_backslash) edge [bend right=10] node [align=center, xshift=-0.3cm, yshift=0.2cm] {match \textbackslash\\increment $k$} (even_backslash)
31730 % edge [bend right=10] node [align=center, above left=-0.3cm, xshift=0.1cm] {match [$^\wedge$\textbackslash]\\for \%, capture \textbackslash$\!^k$\%\\for [$^\wedge$\%], capture \textbackslash$\!^{2k+1}$\meta{match}\\reset $k$} (noop)
31731 % (even_backslash) edge [bend left=10] node {$\epsilon$} (noop);
31732 % \end{tikzpicture}
31733 % \caption{A pushdown automaton that recognizes \TeX{} comments}
31734 % \label{fig:commented_line}
31735 % \end{minipage}
31736 % \end{figure}
31737 % \begin{markdown}
31738 %
31739 % The \luamdef{parsers.commented_line}`^1` parser recognizes the regular
31740 % language of \TeX{} comments, see an equivalent finite automaton in Figure
31741 % <#fig:commented_line>.
31742 %
31743 % \end{markdown}
31744 % \begin{macrocode}
31745 parsers.commented_line_letter = parsers.linechar
31746 + parsers.newline
31747 - parsers.backslash
31748 - parsers.percent
31749 parsers.commented_line = Cg(Cc(""), "backslashes")
31750 * Cg(Cc(true), "pure_comment")
31751 * ((#(parsers.commented_line_letter
31752 - parsers.newline)
31753 * Cb("backslashes")
31754 * Cs(parsers.commented_line_letter
31755 - parsers.newline)^1 -- initial
31756 * Cg(Cc(""), "backslashes")
31757 * Cg(Cc(false), "pure_comment"))
31758 + #( parsers.backslash
31759 * (parsers.backslash + parsers.newline))
31760 * Cg((parsers.backslash -- even backslash
31761 * ( parsers.backslash
31762 + #parsers.newline))^1, "backslashes")
31763 * Cg(Cc(false), "pure_comment")
31764 + (parsers.backslash
31765 * (#parsers.percent
31766 * Cb("backslashes")
31767 / function(backslashes)
31768 return string.rep("\\", #backslashes / 2)
31769 end
31770 * C(parsers.percent)
31771 + #parsers.commented_line_letter
31772 * Cb("backslashes")
31773 * Cc("\\")
31774 * C(parsers.commented_line_letter))
31775 * Cg(Cc(""), "backslashes")
31776 * Cg(Cc(false), "pure_comment")))^0
31777 * (#parsers.percent
31778 * Cb("backslashes")
31779 / function(backslashes)
31780 return string.rep("\\", #backslashes / 2)
31781 end
31782 * ((Cb("pure_comment")
31783 * parsers.percent -- comment
31784 * parsers.line
31785 * #parsers.blankline) -- blank line
31786 / function(is_pure)
31787 return is_pure and "" or "\n"
31788 end
31789 + parsers.percent -- comment
31790 * parsers.line
31791 * parsers.optionalspace) -- leading spaces
31792 + #(parsers.newline)
31793 * Cb("backslashes")
31794 * C(parsers.newline))
31795
31796 parsers.chunk = parsers.line * (parsers.optionallyindentedline
31797 - parsers.blankline)^0
31798
31799 parsers.attribute_key_char = parsers.unicode.alpha
31800 + parsers.unicode.numeric
31801 + S("-_:.")
31802 parsers.attribute_raw_char = parsers.unicode.alpha
31803 + parsers.unicode.numeric
31804 + S("-_")
31805 parsers.attribute_key = (parsers.attribute_key_char
31806 - parsers.dash - parsers.digit)
31807 * parsers.attribute_key_char^0
31808 parsers.attribute_value = ( (parsers.dquote / "")
31809 * (parsers.anyescaped - parsers.dquote)^0
31810 * (parsers.dquote / ""))
31811 + ( (parsers.squote / "")
31812 * (parsers.anyescaped - parsers.squote)^0
31813 * (parsers.squote / ""))
31814 + ( parsers.anyescaped
31815 - parsers.dquote
31816 - parsers.rbrace
31817 - parsers.space)^0
31818 parsers.attribute_identifier = parsers.attribute_key_char^1
31819 parsers.attribute_classname = parsers.unicode.alpha
31820 * parsers.attribute_key_char^0
31821 parsers.attribute_raw = parsers.attribute_raw_char^1
31822
31823 parsers.attribute = (parsers.dash * Cc(".unnumbered"))
31824 + C( parsers.hash
31825 * parsers.attribute_identifier)
31826 + C( parsers.period
31827 * parsers.attribute_classname)
31828 + Cs( parsers.attribute_key
31829 * parsers.optionalspace
31830 * parsers.equal
31831 * parsers.optionalspace
31832 * parsers.attribute_value)
31833 parsers.attributes = parsers.lbrace
31834 * parsers.optionalspace
31835 * parsers.attribute
31836 * (parsers.spacechar^1
31837 * parsers.attribute)^0
31838 * parsers.optionalspace
31839 * parsers.rbrace
31840
31841 parsers.raw_attribute = parsers.lbrace
31842 * parsers.optionalspace
31843 * parsers.equal
31844 * C(parsers.attribute_raw)
31845 * parsers.optionalspace
31846 * parsers.rbrace
31847
31848 -- block followed by 0 or more optionally
31849 -- indented blocks with first line indented.
31850 parsers.indented_blocks = function(bl)
31851 return Cs( bl
31852 * ( parsers.blankline^1
31853 * parsers.indent
31854 * -parsers.blankline
31855 * bl)^0
31856 * (parsers.blankline^1 + parsers.eof) )
31857 end
31858 % \end{macrocode}
31859 % \begin{markdown}
31860 %
31861 %#### Parsers Used for HTML Entities
31862 %
31863 % \end{markdown}
31864 % \begin{macrocode}
31865 local function repeat_between(pattern, min, max)
31866 return -pattern^(max + 1) * pattern^min
31867 end
31868
31869 parsers.hexentity = parsers.ampersand * parsers.hash * C(S("Xx"))
31870 * C(repeat_between(parsers.hexdigit, 1, 6))
31871 * parsers.semicolon
31872 parsers.decentity = parsers.ampersand * parsers.hash
31873 * C(repeat_between(parsers.digit, 1, 7))
31874 * parsers.semicolon
31875 parsers.tagentity = parsers.ampersand * C(parsers.alphanumeric^1)
31876 * parsers.semicolon
31877
31878 parsers.html_entities
31879 = parsers.hexentity / entities.hex_entity_with_x_char
31880 + parsers.decentity / entities.dec_entity
31881 + parsers.tagentity / entities.char_entity
31882 parsers.html_space_entity_char
31883 = Cmt(parsers.html_entities, function(_, i, entity)
31884 return entity == " " and i or nil
31885 end)
31886 % \end{macrocode}
31887 % \begin{markdown}
31888 %
31889 %#### Parsers Used for Markdown Lists
31890 %
31891 % \end{markdown}
31892 % \begin{macrocode}
31893 parsers.bullet = function(bullet_char, interrupting)
31894 local allowed_end
31895 if interrupting then
31896 allowed_end = C(parsers.spacechar^1) * #parsers.linechar
31897 else
31898 allowed_end = C(parsers.spacechar^1)
31899 + #(parsers.newline + parsers.eof)
31900 end
31901 return parsers.check_trail
31902 * Ct(C(bullet_char) * Cc(""))
31903 * allowed_end
31904 end
31905
31906 local function tickbox(interior)
31907 return parsers.optionalspace * parsers.lbracket
31908 * interior * parsers.rbracket * parsers.spacechar^1
31909 end
31910
31911 parsers.ticked_box = tickbox(S("xX")) * Cc(1.0)
31912 parsers.halfticked_box = tickbox(S("./")) * Cc(0.5)
31913 parsers.unticked_box = tickbox(parsers.spacechar^1) * Cc(0.0)
31914
31915 % \end{macrocode}
31916 % \begin{markdown}
31917 %
31918 %#### Parsers Used for Markdown Code Spans
31919 %
31920 % \end{markdown}
31921 % \begin{macrocode}
31922 parsers.openticks = Cg(parsers.backtick^1, "ticks")
31923
31924 local function captures_equal_length(_,i,a,b)
31925 return #a == #b and i
31926 end
31927
31928 parsers.closeticks = Cmt(C(parsers.backtick^1)
31929 * Cb("ticks"), captures_equal_length)
31930
31931 parsers.intickschar = (parsers.any - S("\n\r`"))
31932 + V("NoSoftLineBreakEndline")
31933 + (parsers.backtick^1 - parsers.closeticks)
31934
31935 local function process_inticks(s)
31936 s = s:gsub("\n", " ")
31937 s = s:gsub("^ (.*) $", "%1")
31938 return s
31939 end
31940
31941 parsers.inticks = parsers.openticks
31942 * C(parsers.space^0)
31943 * parsers.closeticks
31944 + parsers.openticks
31945 * Cs(Cs(parsers.intickschar^0) / process_inticks)
31946 * parsers.closeticks
31947
31948 % \end{macrocode}
31949 % \begin{markdown}
31950 %
31951 %#### Parsers Used for HTML
31952 %
31953 % \end{markdown}
31954 % \begin{macrocode}
31955 -- case-insensitive match (we assume s is lowercase)
31956 -- must be single byte encoding
31957 parsers.keyword_exact = function(s)
31958 local parser = P(0)
31959 for i=1,#s do
31960 local c = s:sub(i,i)
31961 local m = c .. upper(c)
31962 parser = parser * S(m)
31963 end
31964 return parser
31965 end
31966
31967 parsers.special_block_keyword =
31968 parsers.keyword_exact("pre") +
31969 parsers.keyword_exact("script") +
31970 parsers.keyword_exact("style") +
31971 parsers.keyword_exact("textarea")
31972
31973 parsers.block_keyword =
31974 parsers.keyword_exact("address") +
31975 parsers.keyword_exact("article") +
31976 parsers.keyword_exact("aside") +
31977 parsers.keyword_exact("base") +
31978 parsers.keyword_exact("basefont") +
31979 parsers.keyword_exact("blockquote") +
31980 parsers.keyword_exact("body") +
31981 parsers.keyword_exact("caption") +
31982 parsers.keyword_exact("center") +
31983 parsers.keyword_exact("col") +
31984 parsers.keyword_exact("colgroup") +
31985 parsers.keyword_exact("dd") +
31986 parsers.keyword_exact("details") +
31987 parsers.keyword_exact("dialog") +
31988 parsers.keyword_exact("dir") +
31989 parsers.keyword_exact("div") +
31990 parsers.keyword_exact("dl") +
31991 parsers.keyword_exact("dt") +
31992 parsers.keyword_exact("fieldset") +
31993 parsers.keyword_exact("figcaption") +
31994 parsers.keyword_exact("figure") +
31995 parsers.keyword_exact("footer") +
31996 parsers.keyword_exact("form") +
31997 parsers.keyword_exact("frame") +
31998 parsers.keyword_exact("frameset") +
31999 parsers.keyword_exact("h1") +
32000 parsers.keyword_exact("h2") +
32001 parsers.keyword_exact("h3") +
32002 parsers.keyword_exact("h4") +
32003 parsers.keyword_exact("h5") +
32004 parsers.keyword_exact("h6") +
32005 parsers.keyword_exact("head") +
32006 parsers.keyword_exact("header") +
32007 parsers.keyword_exact("hr") +
32008 parsers.keyword_exact("html") +
32009 parsers.keyword_exact("iframe") +
32010 parsers.keyword_exact("legend") +
32011 parsers.keyword_exact("li") +
32012 parsers.keyword_exact("link") +
32013 parsers.keyword_exact("main") +
32014 parsers.keyword_exact("menu") +
32015 parsers.keyword_exact("menuitem") +
32016 parsers.keyword_exact("nav") +
32017 parsers.keyword_exact("noframes") +
32018 parsers.keyword_exact("ol") +
32019 parsers.keyword_exact("optgroup") +
32020 parsers.keyword_exact("option") +
32021 parsers.keyword_exact("p") +
32022 parsers.keyword_exact("param") +
32023 parsers.keyword_exact("section") +
32024 parsers.keyword_exact("source") +
32025 parsers.keyword_exact("summary") +
32026 parsers.keyword_exact("table") +
32027 parsers.keyword_exact("tbody") +
32028 parsers.keyword_exact("td") +
32029 parsers.keyword_exact("tfoot") +
32030 parsers.keyword_exact("th") +
32031 parsers.keyword_exact("thead") +
32032 parsers.keyword_exact("title") +
32033 parsers.keyword_exact("tr") +
32034 parsers.keyword_exact("track") +
32035 parsers.keyword_exact("ul")
32036
32037 -- end conditions
32038 parsers.html_blankline_end_condition
32039 = parsers.linechar^0
32040 * ( parsers.newline
32041 * (parsers.check_minimal_blank_indent_and_any_trail
32042 * #parsers.blankline
32043 + parsers.check_minimal_indent_and_any_trail)
32044 * parsers.linechar^1)^0
32045 * (parsers.newline^-1 / "")
32046
32047 local function remove_trailing_blank_lines(s)
32048 return s:gsub("[\n\r]+%s*$", "")
32049 end
32050
32051 parsers.html_until_end = function(end_marker)
32052 return (
32053 Cs(C( parsers.newline
32054 * (parsers.check_minimal_blank_indent_and_any_trail
32055 * #parsers.blankline
32056 + parsers.check_minimal_indent_and_any_trail)
32057 + parsers.linechar - end_marker)^0)
32058 * (C(parsers.linechar^0 * parsers.newline^-1)
32059 / remove_trailing_blank_lines)
32060 )
32061 end
32062
32063 -- attributes
32064 parsers.html_attribute_spacing = parsers.optionalspace
32065 * V("NoSoftLineBreakEndline")
32066 * parsers.optionalspace
32067 + parsers.spacechar^1
32068
32069 parsers.html_attribute_name = ( parsers.letter
32070 + parsers.colon
32071 + parsers.underscore)
32072 * ( parsers.alphanumeric
32073 + parsers.colon
32074 + parsers.underscore
32075 + parsers.period
32076 + parsers.dash)^0
32077
32078 parsers.html_attribute_value = parsers.squote
32079 * (parsers.linechar - parsers.squote)^0
32080 * parsers.squote
32081 + parsers.dquote
32082 * (parsers.linechar - parsers.dquote)^0
32083 * parsers.dquote
32084 + ( parsers.any
32085 - parsers.spacechar
32086 - parsers.newline
32087 - parsers.dquote
32088 - parsers.squote
32089 - parsers.backtick
32090 - parsers.equal
32091 - parsers.less
32092 - parsers.more)^1
32093
32094 parsers.html_inline_attribute_value = parsers.squote
32095 * (V("NoSoftLineBreakEndline")
32096 + parsers.any
32097 - parsers.blankline^2
32098 - parsers.squote)^0
32099 * parsers.squote
32100 + parsers.dquote
32101 * (V("NoSoftLineBreakEndline")
32102 + parsers.any
32103 - parsers.blankline^2
32104 - parsers.dquote)^0
32105 * parsers.dquote
32106 + (parsers.any
32107 - parsers.spacechar
32108 - parsers.newline
32109 - parsers.dquote
32110 - parsers.squote
32111 - parsers.backtick
32112 - parsers.equal
32113 - parsers.less
32114 - parsers.more)^1
32115
32116 parsers.html_attribute_value_specification
32117 = parsers.optionalspace
32118 * parsers.equal
32119 * parsers.optionalspace
32120 * parsers.html_attribute_value
32121
32122 parsers.html_spnl = parsers.optionalspace
32123 * (V("NoSoftLineBreakEndline")
32124 * parsers.optionalspace)^-1
32125
32126 parsers.html_inline_attribute_value_specification
32127 = parsers.html_spnl
32128 * parsers.equal
32129 * parsers.html_spnl
32130 * parsers.html_inline_attribute_value
32131
32132 parsers.html_attribute
32133 = parsers.html_attribute_spacing
32134 * parsers.html_attribute_name
32135 * parsers.html_inline_attribute_value_specification^-1
32136
32137 parsers.html_non_newline_attribute
32138 = parsers.spacechar^1
32139 * parsers.html_attribute_name
32140 * parsers.html_attribute_value_specification^-1
32141
32142 parsers.nested_breaking_blank = parsers.newline
32143 * parsers.check_minimal_blank_indent
32144 * parsers.blankline
32145
32146 parsers.html_comment_start = P("<!--")
32147 * parsers.optionalspace
32148
32149 parsers.html_comment_end = parsers.optionalspace
32150 * P("-->")
32151
32152 parsers.html_comment
32153 = parsers.html_comment_start
32154 * parsers.html_until_end(parsers.html_comment_end)
32155
32156 parsers.html_inline_comment = (parsers.html_comment_start / "")
32157 * -P(">") * -P("->")
32158 * Cs(( parsers.any
32159 - parsers.nested_breaking_blank
32160 - parsers.html_comment_end)^0)
32161 * (parsers.html_comment_end / "")
32162
32163 parsers.html_cdatasection_start = P("<![CDATA[")
32164
32165 parsers.html_cdatasection_end = P("]]>")
32166
32167 parsers.html_cdatasection
32168 = Cs( parsers.html_cdatasection_start
32169 * parsers.html_until_end(parsers.html_cdatasection_end))
32170 / remove_trailing_blank_lines
32171
32172 parsers.html_inline_cdatasection
32173 = parsers.html_cdatasection_start
32174 * Cs(V("NoSoftLineBreakEndline") + parsers.any
32175 - parsers.nested_breaking_blank - parsers.html_cdatasection_end)^0
32176 * parsers.html_cdatasection_end
32177
32178 parsers.html_declaration_start = P("<!") * parsers.letter
32179
32180 parsers.html_declaration_end = P(">")
32181
32182 parsers.html_declaration
32183 = Cs( parsers.html_declaration_start
32184 * parsers.html_until_end(parsers.html_declaration_end))
32185 / remove_trailing_blank_lines
32186
32187 parsers.html_inline_declaration
32188 = parsers.html_declaration_start
32189 * Cs(V("NoSoftLineBreakEndline") + parsers.any
32190 - parsers.nested_breaking_blank - parsers.html_declaration_end)^0
32191 * parsers.html_declaration_end
32192
32193 parsers.html_instruction_start = P("<?")
32194
32195 parsers.html_instruction_end = P("?>")
32196
32197 parsers.html_instruction
32198 = Cs( parsers.html_instruction_start
32199 * parsers.html_until_end(parsers.html_instruction_end))
32200 / remove_trailing_blank_lines
32201
32202 parsers.html_inline_instruction = parsers.html_instruction_start
32203 * Cs( V("NoSoftLineBreakEndline")
32204 + parsers.any
32205 - parsers.nested_breaking_blank
32206 - parsers.html_instruction_end)^0
32207 * parsers.html_instruction_end
32208
32209 parsers.html_blankline = parsers.newline
32210 * parsers.optionalspace
32211 * parsers.newline
32212
32213 parsers.html_tag_start = parsers.less
32214
32215 parsers.html_tag_closing_start = parsers.less
32216 * parsers.slash
32217
32218 parsers.html_tag_end = parsers.html_spnl
32219 * parsers.more
32220
32221 parsers.html_empty_tag_end = parsers.html_spnl
32222 * parsers.slash
32223 * parsers.more
32224
32225 -- opening tags
32226 parsers.html_any_open_inline_tag = parsers.html_tag_start
32227 * parsers.keyword
32228 * parsers.html_attribute^0
32229 * parsers.html_tag_end
32230
32231 parsers.html_any_open_tag = parsers.html_tag_start
32232 * parsers.keyword
32233 * parsers.html_non_newline_attribute^0
32234 * parsers.html_tag_end
32235
32236 parsers.html_open_tag = parsers.html_tag_start
32237 * parsers.block_keyword
32238 * parsers.html_attribute^0
32239 * parsers.html_tag_end
32240
32241 parsers.html_open_special_tag = parsers.html_tag_start
32242 * parsers.special_block_keyword
32243 * parsers.html_attribute^0
32244 * parsers.html_tag_end
32245
32246 -- incomplete tags
32247 parsers.incomplete_tag_following = parsers.spacechar
32248 + parsers.more
32249 + parsers.slash * parsers.more
32250 + #(parsers.newline + parsers.eof)
32251
32252 parsers.incomplete_special_tag_following = parsers.spacechar
32253 + parsers.more
32254 + #( parsers.newline
32255 + parsers.eof)
32256
32257 parsers.html_incomplete_open_tag = parsers.html_tag_start
32258 * parsers.block_keyword
32259 * parsers.incomplete_tag_following
32260
32261 parsers.html_incomplete_open_special_tag
32262 = parsers.html_tag_start
32263 * parsers.special_block_keyword
32264 * parsers.incomplete_special_tag_following
32265
32266 parsers.html_incomplete_close_tag = parsers.html_tag_closing_start
32267 * parsers.block_keyword
32268 * parsers.incomplete_tag_following
32269
32270 parsers.html_incomplete_close_special_tag
32271 = parsers.html_tag_closing_start
32272 * parsers.special_block_keyword
32273 * parsers.incomplete_tag_following
32274
32275 -- closing tags
32276 parsers.html_close_tag = parsers.html_tag_closing_start
32277 * parsers.block_keyword
32278 * parsers.html_tag_end
32279
32280 parsers.html_any_close_tag = parsers.html_tag_closing_start
32281 * parsers.keyword
32282 * parsers.html_tag_end
32283
32284 parsers.html_close_special_tag = parsers.html_tag_closing_start
32285 * parsers.special_block_keyword
32286 * parsers.html_tag_end
32287
32288 -- empty tags
32289 parsers.html_any_empty_inline_tag = parsers.html_tag_start
32290 * parsers.keyword
32291 * parsers.html_attribute^0
32292 * parsers.html_empty_tag_end
32293
32294 parsers.html_any_empty_tag = parsers.html_tag_start
32295 * parsers.keyword
32296 * parsers.html_non_newline_attribute^0
32297 * parsers.optionalspace
32298 * parsers.slash
32299 * parsers.more
32300
32301 parsers.html_empty_tag = parsers.html_tag_start
32302 * parsers.block_keyword
32303 * parsers.html_attribute^0
32304 * parsers.html_empty_tag_end
32305
32306 parsers.html_empty_special_tag = parsers.html_tag_start
32307 * parsers.special_block_keyword
32308 * parsers.html_attribute^0
32309 * parsers.html_empty_tag_end
32310
32311 parsers.html_incomplete_blocks
32312 = parsers.html_incomplete_open_tag
32313 + parsers.html_incomplete_open_special_tag
32314 + parsers.html_incomplete_close_tag
32315
32316 -- parse special html blocks
32317 parsers.html_blankline_ending_special_block_opening
32318 = ( parsers.html_close_special_tag
32319 + parsers.html_empty_special_tag)
32320 * #( parsers.optionalspace
32321 * (parsers.newline + parsers.eof))
32322
32323 parsers.html_blankline_ending_special_block
32324 = parsers.html_blankline_ending_special_block_opening
32325 * parsers.html_blankline_end_condition
32326
32327 parsers.html_special_block_opening
32328 = parsers.html_incomplete_open_special_tag
32329 - parsers.html_empty_special_tag
32330
32331 parsers.html_closing_special_block
32332 = Cs( parsers.html_special_block_opening
32333 * parsers.html_until_end(parsers.html_close_special_tag))
32334 / remove_trailing_blank_lines
32335
32336 parsers.html_special_block
32337 = parsers.html_blankline_ending_special_block
32338 + parsers.html_closing_special_block
32339
32340 -- parse html blocks
32341 parsers.html_block_opening = parsers.html_incomplete_open_tag
32342 + parsers.html_incomplete_close_tag
32343
32344 parsers.html_block = parsers.html_block_opening
32345 * parsers.html_blankline_end_condition
32346
32347 -- parse any html blocks
32348 parsers.html_any_block_opening
32349 = ( parsers.html_any_open_tag
32350 + parsers.html_any_close_tag
32351 + parsers.html_any_empty_tag)
32352 * #(parsers.optionalspace * (parsers.newline + parsers.eof))
32353
32354 parsers.html_any_block = parsers.html_any_block_opening
32355 * parsers.html_blankline_end_condition
32356
32357 parsers.html_inline_comment_full = parsers.html_comment_start
32358 * -P(">") * -P("->")
32359 * Cs(( parsers.any - P("--")
32360 - parsers.nested_breaking_blank
32361 - parsers.html_comment_end)^0)
32362 * parsers.html_comment_end
32363
32364 parsers.html_inline_tags = parsers.html_inline_comment_full
32365 + parsers.html_any_empty_inline_tag
32366 + parsers.html_inline_instruction
32367 + parsers.html_inline_cdatasection
32368 + parsers.html_inline_declaration
32369 + parsers.html_any_open_inline_tag
32370 + parsers.html_any_close_tag
32371
32372 % \end{macrocode}
32373 % \begin{markdown}
32374 %
32375 %#### Parsers Used for Markdown Tags and Links
32376 %
32377 % \end{markdown}
32378 % \begin{macrocode}
32379 parsers.urlchar = parsers.anyescaped
32380 - parsers.newline
32381 - parsers.more
32382
32383 parsers.auto_link_scheme_part = parsers.alphanumeric
32384 + parsers.plus
32385 + parsers.period
32386 + parsers.dash
32387
32388 parsers.auto_link_scheme = parsers.letter
32389 * parsers.auto_link_scheme_part
32390 * parsers.auto_link_scheme_part^-30
32391
32392 parsers.absolute_uri = parsers.auto_link_scheme * parsers.colon
32393 * ( parsers.any - parsers.spacing
32394 - parsers.less - parsers.more)^0
32395
32396 parsers.printable_characters = S(".!#$%&'*+/=?^_`{|}~-")
32397
32398 parsers.email_address_local_part_char = parsers.alphanumeric
32399 + parsers.printable_characters
32400
32401 parsers.email_address_local_part
32402 = parsers.email_address_local_part_char^1
32403
32404 parsers.email_address_dns_label = parsers.alphanumeric
32405 * ( parsers.alphanumeric
32406 + parsers.dash)^-62
32407 * B(parsers.alphanumeric)
32408
32409 parsers.email_address_domain = parsers.email_address_dns_label
32410 * ( parsers.period
32411 * parsers.email_address_dns_label)^0
32412
32413 parsers.email_address = parsers.email_address_local_part
32414 * parsers.at
32415 * parsers.email_address_domain
32416
32417 parsers.auto_link_url = parsers.less
32418 * C(parsers.absolute_uri)
32419 * parsers.more
32420
32421 parsers.auto_link_email = parsers.less
32422 * C(parsers.email_address)
32423 * parsers.more
32424
32425 parsers.auto_link_relative_reference = parsers.less
32426 * C(parsers.urlchar^1)
32427 * parsers.more
32428
32429 parsers.autolink = parsers.auto_link_url
32430 + parsers.auto_link_email
32431
32432 -- content in balanced brackets, parentheses, or quotes:
32433 parsers.bracketed = P{ parsers.lbracket
32434 * (( parsers.backslash / "" * parsers.rbracket
32435 + parsers.any - (parsers.lbracket
32436 + parsers.rbracket
32437 + parsers.blankline^2)
32438 ) + V(1))^0
32439 * parsers.rbracket }
32440
32441 parsers.inparens = P{ parsers.lparent
32442 * ((parsers.anyescaped - (parsers.lparent
32443 + parsers.rparent
32444 + parsers.blankline^2)
32445 ) + V(1))^0
32446 * parsers.rparent }
32447
32448 parsers.squoted = P{ parsers.squote * parsers.alphanumeric
32449 * ((parsers.anyescaped - (parsers.squote
32450 + parsers.blankline^2)
32451 ) + V(1))^0
32452 * parsers.squote }
32453
32454 parsers.dquoted = P{ parsers.dquote * parsers.alphanumeric
32455 * ((parsers.anyescaped - (parsers.dquote
32456 + parsers.blankline^2)
32457 ) + V(1))^0
32458 * parsers.dquote }
32459
32460 parsers.link_text = parsers.lbracket
32461 * Cs((parsers.alphanumeric^1
32462 + parsers.bracketed
32463 + parsers.inticks
32464 + parsers.autolink
32465 + V("InlineHtml")
32466 + ( parsers.backslash * parsers.backslash)
32467 + ( parsers.backslash
32468 * ( parsers.lbracket
32469 + parsers.rbracket)
32470 + V("Space")
32471 + V("NoSoftLineBreakEndline")
32472 + (parsers.any
32473 - ( parsers.newline
32474 + parsers.lbracket
32475 + parsers.rbracket
32476 + parsers.blankline^2))))^0)
32477 * parsers.rbracket
32478
32479 parsers.link_label_body = -#(parsers.sp * parsers.rbracket)
32480 * #( ( parsers.any
32481 - parsers.rbracket)^-999
32482 * parsers.rbracket)
32483 * Cs((parsers.alphanumeric^1
32484 + parsers.inticks
32485 + parsers.autolink
32486 + V("InlineHtml")
32487 + ( parsers.backslash * parsers.backslash)
32488 + ( parsers.backslash
32489 * ( parsers.lbracket
32490 + parsers.rbracket)
32491 + V("Space")
32492 + V("NoSoftLineBreakEndline")
32493 + (parsers.any
32494 - ( parsers.newline
32495 + parsers.lbracket
32496 + parsers.rbracket
32497 + parsers.blankline^2))))^1)
32498
32499 parsers.link_label = parsers.lbracket
32500 * parsers.link_label_body
32501 * parsers.rbracket
32502
32503 parsers.inparens_url = P{ parsers.lparent
32504 * ((parsers.anyescaped - (parsers.lparent
32505 + parsers.rparent
32506 + parsers.spacing)
32507 ) + V(1))^0
32508 * parsers.rparent }
32509
32510 -- url for markdown links, allowing nested brackets:
32511 parsers.url = parsers.less * Cs((parsers.anyescaped
32512 - parsers.newline
32513 - parsers.less
32514 - parsers.more)^0)
32515 * parsers.more
32516 + -parsers.less
32517 * Cs((parsers.inparens_url + (parsers.anyescaped
32518 - parsers.spacing
32519 - parsers.lparent
32520 - parsers.rparent))^1)
32521
32522 -- quoted text:
32523 parsers.title_s = parsers.squote
32524 * Cs((parsers.html_entities
32525 + V("Space")
32526 + V("NoSoftLineBreakEndline")
32527 + ( parsers.anyescaped
32528 - parsers.newline
32529 - parsers.squote
32530 - parsers.blankline^2))^0)
32531 * parsers.squote
32532
32533 parsers.title_d = parsers.dquote
32534 * Cs((parsers.html_entities
32535 + V("Space")
32536 + V("NoSoftLineBreakEndline")
32537 + ( parsers.anyescaped
32538 - parsers.newline
32539 - parsers.dquote
32540 - parsers.blankline^2))^0)
32541 * parsers.dquote
32542
32543 parsers.title_p = parsers.lparent
32544 * Cs((parsers.html_entities
32545 + V("Space")
32546 + V("NoSoftLineBreakEndline")
32547 + ( parsers.anyescaped
32548 - parsers.newline
32549 - parsers.lparent
32550 - parsers.rparent
32551 - parsers.blankline^2))^0)
32552 * parsers.rparent
32553
32554 parsers.title
32555 = parsers.title_d + parsers.title_s + parsers.title_p
32556
32557 parsers.optionaltitle
32558 = parsers.spnlc * parsers.title * parsers.spacechar^0 + Cc("")
32559
32560 % \end{macrocode}
32561 % \begin{markdown}
32562 %
32563 %#### Helpers for Links and Link Reference Definitions
32564 %
32565 % \end{markdown}
32566 % \begin{macrocode}
32567 -- parse a reference definition: [foo]: /bar "title"
32568 parsers.define_reference_parser = (parsers.check_trail / "")
32569 * parsers.link_label * parsers.colon
32570 * parsers.spnlc * parsers.url
32571 * ( parsers.spnlc_sep * parsers.title
32572 * parsers.only_blank
32573 + Cc("") * parsers.only_blank)
32574 % \end{macrocode}
32575 % \begin{markdown}
32576 %
32577 %#### Inline Elements
32578 %
32579 % \end{markdown}
32580 % \begin{macrocode}
32581 parsers.Inline = V("Inline")
32582
32583 -- parse many p between starter and ender
32584 parsers.between = function(p, starter, ender)
32585 local ender2 = B(parsers.nonspacechar) * ender
32586 return ( starter
32587 * #parsers.nonspacechar
32588 * Ct(p * (p - ender2)^0)
32589 * ender2)
32590 end
32591
32592 % \end{macrocode}
32593 % \begin{markdown}
32594 %
32595 %#### Block Elements
32596 %
32597 % \end{markdown}
32598 % \begin{macrocode}
32599 parsers.lineof = function(c)
32600 return ( parsers.check_trail_no_rem
32601 * (P(c) * parsers.optionalspace)^3
32602 * (parsers.newline + parsers.eof))
32603 end
32604
32605 parsers.thematic_break_lines = parsers.lineof(parsers.asterisk)
32606 + parsers.lineof(parsers.dash)
32607 + parsers.lineof(parsers.underscore)
32608 % \end{macrocode}
32609 % \begin{markdown}
32610 %
32611 %#### Headings
32612 %
32613 % \end{markdown}
32614 % \begin{macrocode}
32615 -- parse Atx heading start and return level
32616 parsers.heading_start = #parsers.hash * C(parsers.hash^-6)
32617 * -parsers.hash / length
32618
32619 -- parse setext header ending and return level
32620 parsers.heading_level
32621 = parsers.nonindentspace * parsers.equal^1
32622 * parsers.optionalspace * #parsers.newline * Cc(1)
32623 + parsers.nonindentspace * parsers.dash^1
32624 * parsers.optionalspace * #parsers.newline * Cc(2)
32625
32626 local function strip_atx_end(s)
32627 return s:gsub("%s+#*%s*\n$","")
32628 end
32629
32630 parsers.atx_heading = parsers.check_trail_no_rem
32631 * Cg(parsers.heading_start, "level")
32632 * (C( parsers.optionalspace
32633 * parsers.hash^0
32634 * parsers.optionalspace
32635 * parsers.newline)
32636 + parsers.spacechar^1
32637 * C(parsers.line))
32638 % \end{macrocode}
32639 % \begin{markdown}
32640 %
32641 %### Markdown Reader {#markdown-reader}
32642 %
32643 % This section documents the \luamref{reader} object, which implements the
32644 % routines for parsing the markdown input. The object corresponds to the
32645 % markdown reader object that was located in the
32646 % `lunamark/reader/markdown.lua` file in the Lunamark Lua module.
32647 %
32648 % The \luamdef{reader.new} method creates and returns a new \TeX{} reader
32649 % object associated with the Lua interface options (see Section
32650 % <#sec:lua-options>) `options` and with a writer object `writer`. When
32651 % `options` are unspecified, it is assumed that an empty table was passed to
32652 % the method.
32653 %
32654 % The objects produced by the \luamref{reader.new} method expose instance methods
32655 % and variables of their own. As a convention, I will refer to these
32656 % \meta{member}s as `reader->`\meta{member}.
32657 %
32658 % \end{markdown}
32659 % \begin{macrocode}
32660 M.reader = {}
32661 function M.reader.new(writer, options)
32662 local self = {}
32663 % \end{macrocode}
32664 % \begin{markdown}
32665 %
32666 % Make the `writer` and `options` parameters available as
32667 % \luamdef{reader->writer} and \luamdef{reader->options}, respectively, so
32668 % that they are accessible from extensions.
32669 %
32670 % \end{markdown}
32671 % \begin{macrocode}
32672 self.writer = writer
32673 self.options = options
32674 % \end{macrocode}
32675 % \begin{markdown}
32676 %
32677 % Create a \luamdef{reader->parsers} hash table that stores PEG patterns
32678 % that depend on the received `options`. Make \luamref{reader->parsers} inherit
32679 % from the global \luamref{parsers} table.
32680 %
32681 % \end{markdown}
32682 % \begin{macrocode}
32683 self.parsers = {}
32684 (function(parsers)
32685 setmetatable(self.parsers, {
32686 __index = function (_, key)
32687 return parsers[key]
32688 end
32689 })
32690 end)(parsers)
32691 % \end{macrocode}
32692 % \begin{markdown}
32693 %
32694 % Make \luamref{reader->parsers} available as a local `parsers` variable that
32695 % will shadow the global \luamref{parsers} table and will make
32696 % \luamref{reader->parsers} easier to type in the rest of the reader code.
32697 %
32698 % \end{markdown}
32699 % \begin{macrocode}
32700 local parsers = self.parsers
32701 % \end{macrocode}
32702 % \begin{markdown}
32703 %
32704 %#### Top-Level Helper Functions
32705 % Define \luamdef{reader->normalize_tag} as a function that normalizes a
32706 % markdown reference tag by lowercasing it, and by collapsing any adjacent
32707 % whitespace characters.
32708 %
32709 % \end{markdown}
32710 % \begin{macrocode}
32711 function self.normalize_tag(tag)
32712 tag = util.rope_to_string(tag)
32713 tag = tag:gsub("[ \n\r\t]+", " ")
32714 tag = tag:gsub("^ ", ""):gsub(" $", "")
32715 local form = nil
32716 if options.unicodeNormalization then
32717 form = options.unicodeNormalizationForm
32718 end
32719 tag = util.casefold(tag, form)
32720 return tag
32721 end
32722 % \end{macrocode}
32723 % \begin{markdown}
32724 %
32725 % Define \luamdef{iterlines} as a function that iterates over the lines of
32726 % the input string `s`, transforms them using an input function `f`, and
32727 % reassembles them into a new string, which it returns.
32728 %
32729 % \end{markdown}
32730 % \begin{macrocode}
32731 local function iterlines(s, f)
32732 local rope = lpeg.match(Ct((parsers.line / f)^1), s)
32733 return util.rope_to_string(rope)
32734 end
32735 % \end{macrocode}
32736 % \begin{markdown}
32737 %
32738 % Define \luamdef{expandtabs} either as an identity function, when the
32739 % \Opt{preserveTabs} Lua interface option is enabled, or to a function that
32740 % expands tabs into spaces otherwise.
32741 %
32742 % \end{markdown}
32743 % \begin{macrocode}
32744 if options.preserveTabs then
32745 self.expandtabs = function(s) return s end
32746 else
32747 self.expandtabs = function(s)
32748 if s:find("\t") then
32749 return iterlines(s, util.expand_tabs_in_line)
32750 else
32751 return s
32752 end
32753 end
32754 end
32755 % \end{macrocode}
32756 % \begin{markdown}
32757 %
32758 %#### High-Level Parser Functions
32759 %
32760 % Create a \luamdef{reader->parser_functions} hash table that stores high-level
32761 % parser functions. Define \luamdef{reader->create_parser} as a function that
32762 % will create a high-level parser function \luamdef{reader->parser_functions.name},
32763 % that matches input using grammar `grammar`. If `toplevel` is true, the input
32764 % is expected to come straight from the user, not from a recursive call, and
32765 % will be preprocessed.
32766 %
32767 % \end{markdown}
32768 % \begin{macrocode}
32769 self.parser_functions = {}
32770 self.create_parser = function(name, grammar, toplevel)
32771 self.parser_functions[name] = function(str)
32772 % \end{macrocode}
32773 % \begin{markdown}
32774 %
32775 % If the parser function is top-level and the \Opt{stripIndent} Lua option is
32776 % enabled, we will first expand tabs in the input string `str` into spaces
32777 % and then we will count the minimum indent across all lines, skipping
32778 % blank lines. Next, we will remove the minimum indent from all lines.
32779 %
32780 % \end{markdown}
32781 % \begin{macrocode}
32782 if toplevel and options.stripIndent then
32783 local min_prefix_length, min_prefix = nil, ''
32784 str = iterlines(str, function(line)
32785 if lpeg.match(parsers.nonemptyline, line) == nil then
32786 return line
32787 end
32788 line = util.expand_tabs_in_line(line)
32789 local prefix = lpeg.match(C(parsers.optionalspace), line)
32790 local prefix_length = #prefix
32791 local is_shorter = min_prefix_length == nil
32792 if not is_shorter then
32793 is_shorter = prefix_length < min_prefix_length
32794 end
32795 if is_shorter then
32796 min_prefix_length, min_prefix = prefix_length, prefix
32797 end
32798 return line
32799 end)
32800 str = str:gsub('^' .. min_prefix, '')
32801 end
32802 % \end{macrocode}
32803 % \begin{markdown}
32804 %
32805 % If the parser is top-level and the \Opt{texComments} or \Opt{hybrid} Lua
32806 % options are enabled, we will strip all plain \TeX{} comments from the input
32807 % string `str` together with the trailing newline characters.
32808 %
32809 % \end{markdown}
32810 % \begin{macrocode}
32811 if toplevel and (options.texComments or options.hybrid) then
32812 str = lpeg.match(Ct(parsers.commented_line^1), str)
32813 str = util.rope_to_string(str)
32814 end
32815 local res = lpeg.match(grammar(), str)
32816 if res == nil then
32817 return writer.error(
32818 format("Parser `%s` failed to process the input text.", name),
32819 format("Here are the first 20 characters of the remaining "
32820 .. "unprocessed text: `%s`.", str:sub(1,20))
32821 )
32822 else
32823 return res
32824 end
32825 end
32826 end
32827
32828 self.create_parser("parse_blocks",
32829 function()
32830 return parsers.blocks
32831 end, true)
32832
32833 self.create_parser("parse_blocks_nested",
32834 function()
32835 return parsers.blocks_nested
32836 end, false)
32837
32838 self.create_parser("parse_inlines",
32839 function()
32840 return parsers.inlines
32841 end, false)
32842
32843 self.create_parser("parse_inlines_no_inline_note",
32844 function()
32845 return parsers.inlines_no_inline_note
32846 end, false)
32847
32848 self.create_parser("parse_inlines_no_html",
32849 function()
32850 return parsers.inlines_no_html
32851 end, false)
32852
32853 self.create_parser("parse_inlines_nbsp",
32854 function()
32855 return parsers.inlines_nbsp
32856 end, false)
32857
32858 self.create_parser("parse_inlines_no_link_or_emphasis",
32859 function()
32860 return parsers.inlines_no_link_or_emphasis
32861 end, false)
32862
32863 self.create_parser("parse_inlines_identity",
32864 function()
32865 return parsers.inlines_identity
32866 end, false)
32867
32868 self.create_parser("parse_inlines_string",
32869 function()
32870 return parsers.inlines_string
32871 end, false)
32872
32873 self.create_parser("parse_inlines_math",
32874 function()
32875 return parsers.inlines_math
32876 end, false)
32877 % \end{macrocode}
32878 % \begin{markdown}
32879 %
32880 %#### Parsers Used for Indentation (local)
32881 %
32882 % The following patterns represent basic building blocks of indented content.
32883 %
32884 % \end{markdown}
32885 % \begin{macrocode}
32886 parsers.minimally_indented_blankline
32887 = parsers.check_minimal_indent * (parsers.blankline / "")
32888
32889 parsers.minimally_indented_block
32890 = parsers.check_minimal_indent * V("Block")
32891
32892 parsers.minimally_indented_block_or_paragraph
32893 = parsers.check_minimal_indent * V("BlockOrParagraph")
32894
32895 parsers.minimally_indented_paragraph
32896 = parsers.check_minimal_indent * V("Paragraph")
32897
32898 parsers.minimally_indented_plain
32899 = parsers.check_minimal_indent * V("Plain")
32900
32901 parsers.minimally_indented_par_or_plain
32902 = parsers.minimally_indented_paragraph
32903 + parsers.minimally_indented_plain
32904
32905 parsers.minimally_indented_par_or_plain_no_blank
32906 = parsers.minimally_indented_par_or_plain
32907 - parsers.minimally_indented_blankline
32908
32909 parsers.minimally_indented_ref
32910 = parsers.check_minimal_indent * V("Reference")
32911
32912 parsers.minimally_indented_blank
32913 = parsers.check_minimal_indent * V("Blank")
32914
32915 parsers.conditionally_indented_blankline
32916 = parsers.check_minimal_blank_indent * (parsers.blankline / "")
32917
32918 parsers.minimally_indented_ref_or_block
32919 = parsers.minimally_indented_ref
32920 + parsers.minimally_indented_block
32921 - parsers.minimally_indented_blankline
32922
32923 parsers.minimally_indented_ref_or_block_or_par
32924 = parsers.minimally_indented_ref
32925 + parsers.minimally_indented_block_or_paragraph
32926 - parsers.minimally_indented_blankline
32927
32928 % \end{macrocode}
32929 % \begin{markdown}
32930 %
32931 % The following pattern parses the properly indented content that follows the initial container start.
32932 %
32933 % \end{markdown}
32934 % \begin{macrocode}
32935
32936 function parsers.separator_loop(separated_block, paragraph,
32937 block_separator, paragraph_separator)
32938 return separated_block
32939 + block_separator
32940 * paragraph
32941 * separated_block
32942 + paragraph_separator
32943 * paragraph
32944 end
32945
32946 function parsers.create_loop_body_pair(separated_block, paragraph,
32947 block_separator,
32948 paragraph_separator)
32949 return {
32950 block = parsers.separator_loop(separated_block, paragraph,
32951 block_separator, block_separator),
32952 par = parsers.separator_loop(separated_block, paragraph,
32953 block_separator, paragraph_separator)
32954 }
32955 end
32956
32957 parsers.block_sep_group = function(blank)
32958 return blank^0 * parsers.eof
32959 + ( blank^2 / writer.paragraphsep
32960 + blank^0 / writer.interblocksep
32961 )
32962 end
32963
32964 parsers.par_sep_group = function(blank)
32965 return blank^0 * parsers.eof
32966 + blank^0 / writer.paragraphsep
32967 end
32968
32969 parsers.sep_group_no_output = function(blank)
32970 return blank^0 * parsers.eof
32971 + blank^0
32972 end
32973
32974 parsers.content_blank = parsers.minimally_indented_blankline
32975
32976 parsers.ref_or_block_separated
32977 = parsers.sep_group_no_output(parsers.content_blank)
32978 * ( parsers.minimally_indented_ref
32979 - parsers.content_blank)
32980 + parsers.block_sep_group(parsers.content_blank)
32981 * ( parsers.minimally_indented_block
32982 - parsers.content_blank)
32983
32984 parsers.loop_body_pair =
32985 parsers.create_loop_body_pair(
32986 parsers.ref_or_block_separated,
32987 parsers.minimally_indented_par_or_plain_no_blank,
32988 parsers.block_sep_group(parsers.content_blank),
32989 parsers.par_sep_group(parsers.content_blank))
32990
32991 parsers.content_loop = ( V("Block")
32992 * parsers.loop_body_pair.block^0
32993 + (V("Paragraph") + V("Plain"))
32994 * parsers.ref_or_block_separated
32995 * parsers.loop_body_pair.block^0
32996 + (V("Paragraph") + V("Plain"))
32997 * parsers.loop_body_pair.par^0)
32998 * parsers.content_blank^0
32999
33000 parsers.indented_content = function()
33001 return Ct( (V("Reference") + (parsers.blankline / ""))
33002 * parsers.content_blank^0
33003 * parsers.check_minimal_indent
33004 * parsers.content_loop
33005 + (V("Reference") + (parsers.blankline / ""))
33006 * parsers.content_blank^0
33007 + parsers.content_loop)
33008 end
33009
33010 parsers.add_indent = function(pattern, name, breakable)
33011 return Cg(Cmt( Cb("indent_info")
33012 * Ct(pattern)
33013 * ( #parsers.linechar -- check if starter is blank
33014 * Cc(false) + Cc(true))
33015 * Cc(name)
33016 * Cc(breakable),
33017 process_starter_indent), "indent_info")
33018 end
33019
33020 % \end{macrocode}
33021 % \begin{markdown}
33022 %
33023 %#### Parsers Used for Markdown Lists (local)
33024 %
33025 % \end{markdown}
33026 % \begin{macrocode}
33027 if options.hashEnumerators then
33028 parsers.dig = parsers.digit + parsers.hash
33029 else
33030 parsers.dig = parsers.digit
33031 end
33032
33033 parsers.enumerator = function(delimiter_type, interrupting)
33034 local delimiter_range
33035 local allowed_end
33036 if interrupting then
33037 delimiter_range = P("1")
33038 allowed_end = C(parsers.spacechar^1) * #parsers.linechar
33039 else
33040 delimiter_range = parsers.dig * parsers.dig^-8
33041 allowed_end = C(parsers.spacechar^1)
33042 + #(parsers.newline + parsers.eof)
33043 end
33044
33045 return parsers.check_trail
33046 * Ct(C(delimiter_range) * C(delimiter_type))
33047 * allowed_end
33048 end
33049
33050 parsers.starter = parsers.bullet(parsers.dash)
33051 + parsers.bullet(parsers.asterisk)
33052 + parsers.bullet(parsers.plus)
33053 + parsers.enumerator(parsers.period)
33054 + parsers.enumerator(parsers.rparent)
33055
33056 % \end{macrocode}
33057 % \begin{markdown}
33058 %
33059 %#### Parsers Used for Blockquotes (local)
33060 %
33061 % \end{markdown}
33062 % \begin{macrocode}
33063 parsers.blockquote_start
33064 = parsers.check_trail
33065 * C(parsers.more)
33066 * C(parsers.spacechar^0)
33067
33068 parsers.blockquote_body
33069 = parsers.add_indent(parsers.blockquote_start, "bq", true)
33070 * parsers.indented_content()
33071 * remove_indent("bq")
33072
33073 if not options.breakableBlockquotes then
33074 parsers.blockquote_body
33075 = parsers.add_indent(parsers.blockquote_start, "bq", false)
33076 * parsers.indented_content()
33077 * remove_indent("bq")
33078 end
33079 % \end{macrocode}
33080 % \begin{markdown}
33081 %
33082 %#### Helpers for Emphasis and Strong Emphasis (local)
33083 %
33084 % Parse the content of a table `content_part` with links, images and emphasis disabled.
33085 %
33086 % \end{markdown}
33087 % \begin{macrocode}
33088 local function parse_content_part(content_part)
33089 local rope = util.rope_to_string(content_part)
33090 local parsed
33091 = self.parser_functions.parse_inlines_no_link_or_emphasis(rope)
33092 parsed.indent_info = nil
33093 return parsed
33094 end
33095
33096 % \end{macrocode}
33097 % \begin{markdown}
33098 %
33099 % Collect the content between the `opening_index` and `closing_index` in the delimiter table `t`.
33100 %
33101 % \end{markdown}
33102 % \begin{macrocode}
33103 local collect_emphasis_content =
33104 function(t, opening_index, closing_index)
33105 local content = {}
33106
33107 local content_part = {}
33108 for i = opening_index, closing_index do
33109 local value = t[i]
33110
33111 if value.rendered ~= nil then
33112 content[#content + 1] = parse_content_part(content_part)
33113 content_part = {}
33114 content[#content + 1] = value.rendered
33115 value.rendered = nil
33116 else
33117 if value.warning ~= nil then
33118 if next(content_part) ~= nil then
33119 content[#content + 1] = parse_content_part(content_part)
33120 end
33121 content_part = {}
33122
33123 content[#content + 1] = value.warning
33124 value.warning = nil
33125 end
33126 if value.type == "delimiter"
33127 and value.element == "emphasis" then
33128 if value.is_active then
33129 content_part[#content_part + 1]
33130 = string.rep(value.character, value.current_count)
33131 end
33132 else
33133 content_part[#content_part + 1] = value.content
33134 end
33135 value.content = ''
33136 value.is_active = false
33137 end
33138 end
33139
33140 if next(content_part) ~= nil then
33141 content[#content + 1] = parse_content_part(content_part)
33142 end
33143
33144 return content
33145 end
33146
33147 % \end{macrocode}
33148 % \begin{markdown}
33149 %
33150 % Render content between the `opening_index` and `closing_index` in the delimiter table `t`
33151 % as emphasis.
33152 %
33153 % \end{markdown}
33154 % \begin{macrocode}
33155 local function fill_emph(t, opening_index, closing_index)
33156 local content
33157 = collect_emphasis_content(t, opening_index + 1,
33158 closing_index - 1)
33159 t[opening_index + 1].is_active = true
33160 t[opening_index + 1].rendered = writer.emphasis(content)
33161 end
33162
33163 % \end{macrocode}
33164 % \begin{markdown}
33165 %
33166 % Render content between the `opening_index` and `closing_index` in the delimiter table `t`
33167 % as strong emphasis.
33168 %
33169 % \end{markdown}
33170 % \begin{macrocode}
33171 local function fill_strong(t, opening_index, closing_index)
33172 local content
33173 = collect_emphasis_content(t, opening_index + 1,
33174 closing_index - 1)
33175 t[opening_index + 1].is_active = true
33176 t[opening_index + 1].rendered = writer.strong(content)
33177 end
33178
33179 % \end{macrocode}
33180 % \begin{markdown}
33181 %
33182 % Check whether the opening delimiter `opening_delimiter` and closing delimiter `closing_delimiter` break
33183 % rule three together.
33184 %
33185 % \end{markdown}
33186 % \begin{macrocode}
33187 local function breaks_three_rule(opening_delimiter, closing_delimiter)
33188 return ( opening_delimiter.is_closing
33189 or closing_delimiter.is_opening)
33190 and (( opening_delimiter.original_count
33191 + closing_delimiter.original_count) % 3 == 0)
33192 and ( opening_delimiter.original_count % 3 ~= 0
33193 or closing_delimiter.original_count % 3 ~= 0)
33194 end
33195
33196 % \end{macrocode}
33197 % \begin{markdown}
33198 %
33199 % Look for the first potential emphasis opener in the delimiter table `t` in the range from
33200 % `bottom_index` to `latest_index` that has the same character `character` as the closing
33201 % delimiter `closing_delimiter`.
33202 %
33203 % \end{markdown}
33204 % \begin{macrocode}
33205 local find_emphasis_opener = function(t, bottom_index, latest_index,
33206 character, closing_delimiter)
33207 for i = latest_index, bottom_index, -1 do
33208 local value = t[i]
33209 if value.is_active and
33210 value.is_opening and
33211 value.type == "delimiter" and
33212 value.element == "emphasis" and
33213 (value.character == character) and
33214 (value.current_count > 0) then
33215 if not breaks_three_rule(value, closing_delimiter) then
33216 return i
33217 end
33218 end
33219 end
33220 end
33221
33222 % \end{macrocode}
33223 % \begin{markdown}
33224 %
33225 % Iterate over the delimiters in the delimiter table `t`, producing emphasis or strong emphasis macros.
33226 %
33227 % \end{markdown}
33228 % \begin{macrocode}
33229 local function process_emphasis(t, opening_index, closing_index)
33230 for i = opening_index, closing_index do
33231 local value = t[i]
33232 if value.type == "delimiter" and value.element == "emphasis" then
33233 local delimiter_length = string.len(value.content)
33234 value.character = string.sub(value.content, 1, 1)
33235 value.current_count = delimiter_length
33236 value.original_count = delimiter_length
33237 end
33238 end
33239
33240 local openers_bottom = {
33241 ['*'] = {
33242 [true] = {opening_index, opening_index, opening_index},
33243 [false] = {opening_index, opening_index, opening_index}
33244 },
33245 ['_'] = {
33246 [true] = {opening_index, opening_index, opening_index},
33247 [false] = {opening_index, opening_index, opening_index}
33248 }
33249 }
33250
33251 local current_position = opening_index
33252 local max_position = closing_index
33253
33254 while current_position <= max_position do
33255 local value = t[current_position]
33256
33257 if value.type ~= "delimiter" or
33258 value.element ~= "emphasis" or
33259 not value.is_active or
33260 not value.is_closing or
33261 (value.current_count <= 0) then
33262 current_position = current_position + 1
33263 goto continue
33264 end
33265
33266 local character = value.character
33267 local is_opening = value.is_opening
33268 local closing_length_modulo_three = value.original_count % 3
33269
33270 local current_openers_bottom
33271 = openers_bottom[character][is_opening]
33272 [closing_length_modulo_three + 1]
33273
33274 local opener_position
33275 = find_emphasis_opener(t, current_openers_bottom,
33276 current_position - 1, character, value)
33277
33278 if (opener_position == nil) then
33279 openers_bottom[character][is_opening]
33280 [closing_length_modulo_three + 1]
33281 = current_position
33282 current_position = current_position + 1
33283 goto continue
33284 end
33285
33286 local opening_delimiter = t[opener_position]
33287
33288 local current_opening_count = opening_delimiter.current_count
33289 local current_closing_count = t[current_position].current_count
33290
33291 if (current_opening_count >= 2)
33292 and (current_closing_count >= 2) then
33293 opening_delimiter.current_count = current_opening_count - 2
33294 t[current_position].current_count = current_closing_count - 2
33295 fill_strong(t, opener_position, current_position)
33296 else
33297 opening_delimiter.current_count = current_opening_count - 1
33298 t[current_position].current_count = current_closing_count - 1
33299 fill_emph(t, opener_position, current_position)
33300 end
33301
33302 ::continue::
33303 end
33304 end
33305
33306 parsers.delimiter_run = function(character)
33307 return (B(parsers.backslash * character) + -B(character))
33308 * character^1
33309 * -#character
33310 end
33311
33312 parsers.left_flanking_delimiter_run = function(character)
33313 return (B( parsers.any)
33314 * ( parsers.unicode.preceding_punctuation
33315 + parsers.unicode.preceding_whitespace)
33316 + -B(parsers.any))
33317 * parsers.delimiter_run(character)
33318 * #parsers.unicode.punctuation
33319 + parsers.delimiter_run(character)
33320 * -#( #parsers.unicode.punctuation
33321 + #parsers.unicode.whitespace
33322 + parsers.eof)
33323 end
33324
33325 parsers.right_flanking_delimiter_run = function(character)
33326 return parsers.unicode.preceding_punctuation
33327 * parsers.delimiter_run(character)
33328 * ( #parsers.unicode.punctuation
33329 + #parsers.unicode.whitespace
33330 + parsers.eof)
33331 + (B(parsers.any)
33332 * -( parsers.unicode.preceding_punctuation
33333 + parsers.unicode.preceding_whitespace))
33334 * parsers.delimiter_run(character)
33335 end
33336
33337 if options.underscores then
33338 parsers.emph_start
33339 = parsers.left_flanking_delimiter_run(parsers.asterisk)
33340 + ( -#parsers.right_flanking_delimiter_run(parsers.underscore)
33341 + ( parsers.unicode.preceding_punctuation
33342 * #parsers.right_flanking_delimiter_run(parsers.underscore)))
33343 * parsers.left_flanking_delimiter_run(parsers.underscore)
33344
33345 parsers.emph_end
33346 = parsers.right_flanking_delimiter_run(parsers.asterisk)
33347 + ( -#parsers.left_flanking_delimiter_run(parsers.underscore)
33348 + #( parsers.left_flanking_delimiter_run(parsers.underscore)
33349 * #parsers.unicode.punctuation))
33350 * parsers.right_flanking_delimiter_run(parsers.underscore)
33351 else
33352 parsers.emph_start
33353 = parsers.left_flanking_delimiter_run(parsers.asterisk)
33354
33355 parsers.emph_end
33356 = parsers.right_flanking_delimiter_run(parsers.asterisk)
33357 end
33358
33359 parsers.emph_capturing_open_and_close
33360 = #parsers.emph_start * #parsers.emph_end
33361 * Ct( Cg(Cc("delimiter"), "type")
33362 * Cg(Cc("emphasis"), "element")
33363 * Cg(C(parsers.emph_start), "content")
33364 * Cg(Cc(true), "is_opening")
33365 * Cg(Cc(true), "is_closing"))
33366
33367 parsers.emph_capturing_open = Ct( Cg(Cc("delimiter"), "type")
33368 * Cg(Cc("emphasis"), "element")
33369 * Cg(C(parsers.emph_start), "content")
33370 * Cg(Cc(true), "is_opening")
33371 * Cg(Cc(false), "is_closing"))
33372
33373 parsers.emph_capturing_close = Ct( Cg(Cc("delimiter"), "type")
33374 * Cg(Cc("emphasis"), "element")
33375 * Cg(C(parsers.emph_end), "content")
33376 * Cg(Cc(false), "is_opening")
33377 * Cg(Cc(true), "is_closing"))
33378
33379 parsers.emph_open_or_close = parsers.emph_capturing_open_and_close
33380 + parsers.emph_capturing_open
33381 + parsers.emph_capturing_close
33382
33383 parsers.emph_open = parsers.emph_capturing_open_and_close
33384 + parsers.emph_capturing_open
33385
33386 parsers.emph_close = parsers.emph_capturing_open_and_close
33387 + parsers.emph_capturing_close
33388
33389 % \end{macrocode}
33390 % \begin{markdown}
33391 %
33392 %#### Helpers for Links and Link Reference Definitions (local)
33393 %
33394 % \end{markdown}
33395 % \begin{macrocode}
33396 -- List of references defined in the document
33397 local references
33398
33399 -- List of note references defined in the document
33400 parsers.rawnotes = {}
33401
33402 % \end{macrocode}
33403 % \begin{markdown}
33404 %
33405 % The \luamdef{reader->register_link} method registers
33406 % a link reference, where `tag` is the link label, `url`
33407 % is the link destination, `title` is the optional link
33408 % title, and `attributes` are the optional attributes.
33409 %
33410 % \end{markdown}
33411 % \begin{macrocode}
33412 function self.register_link(_, tag, url, title,
33413 attributes)
33414 local normalized_tag = self.normalize_tag(tag)
33415 if references[normalized_tag] == nil then
33416 references[normalized_tag] = {
33417 url = url,
33418 title = title,
33419 attributes = attributes
33420 }
33421 return ""
33422 else
33423 local text
33424 = string.format('Multiply defined link reference "%s"', tag)
33425 local more = string.format("Look for the text `[%s]: ...`.", tag)
33426 return writer.warning(text, more)
33427 end
33428 end
33429
33430 % \end{macrocode}
33431 % \begin{markdown}
33432 %
33433 % The \luamdef{reader->lookup_reference} method looks up a
33434 % reference with link label `tag`.
33435 %
33436 % \end{markdown}
33437 % \begin{macrocode}
33438 function self.lookup_reference(tag)
33439 return references[self.normalize_tag(tag)]
33440 end
33441
33442 % \end{macrocode}
33443 % \begin{markdown}
33444 %
33445 % The \luamdef{reader->lookup_note_reference} method looks up a
33446 % note reference with label `tag`.
33447 %
33448 % \end{markdown}
33449 % \begin{macrocode}
33450 function self.lookup_note_reference(tag)
33451 return parsers.rawnotes[self.normalize_tag(tag)]
33452 end
33453
33454 parsers.title_s_direct_ref = parsers.squote
33455 * Cs((parsers.html_entities
33456 + ( parsers.anyescaped
33457 - parsers.squote
33458 - parsers.blankline^2))^0)
33459 * parsers.squote
33460
33461 parsers.title_d_direct_ref = parsers.dquote
33462 * Cs((parsers.html_entities
33463 + ( parsers.anyescaped
33464 - parsers.dquote
33465 - parsers.blankline^2))^0)
33466 * parsers.dquote
33467
33468 parsers.title_p_direct_ref = parsers.lparent
33469 * Cs((parsers.html_entities
33470 + ( parsers.anyescaped
33471 - parsers.lparent
33472 - parsers.rparent
33473 - parsers.blankline^2))^0)
33474 * parsers.rparent
33475
33476 parsers.title_direct_ref = parsers.title_s_direct_ref
33477 + parsers.title_d_direct_ref
33478 + parsers.title_p_direct_ref
33479
33480 parsers.inline_direct_ref_inside = parsers.lparent * parsers.spnl
33481 * Cg(parsers.url + Cc(""), "url")
33482 * parsers.spnl
33483 * Cg( parsers.title_direct_ref
33484 + Cc(""), "title")
33485 * parsers.spnl * parsers.rparent
33486
33487 parsers.inline_direct_ref = parsers.lparent * parsers.spnlc
33488 * Cg(parsers.url + Cc(""), "url")
33489 * parsers.spnlc
33490 * Cg(parsers.title + Cc(""), "title")
33491 * parsers.spnlc * parsers.rparent
33492
33493 parsers.empty_link = parsers.lbracket
33494 * parsers.rbracket
33495
33496 parsers.inline_link = parsers.link_text
33497 * parsers.inline_direct_ref
33498
33499 parsers.full_link = parsers.link_text
33500 * parsers.link_label
33501
33502 parsers.shortcut_link = parsers.link_label
33503 * -(parsers.empty_link + parsers.link_label)
33504
33505 parsers.collapsed_link = parsers.link_label
33506 * parsers.empty_link
33507
33508 parsers.image_opening = #(parsers.exclamation * parsers.inline_link)
33509 * Cg(Cc("inline"), "link_type")
33510 + #(parsers.exclamation * parsers.full_link)
33511 * Cg(Cc("full"), "link_type")
33512 + #( parsers.exclamation
33513 * parsers.collapsed_link)
33514 * Cg(Cc("collapsed"), "link_type")
33515 + #(parsers.exclamation * parsers.shortcut_link)
33516 * Cg(Cc("shortcut"), "link_type")
33517 + #(parsers.exclamation * parsers.empty_link)
33518 * Cg(Cc("empty"), "link_type")
33519
33520 parsers.link_opening = #parsers.inline_link
33521 * Cg(Cc("inline"), "link_type")
33522 + #parsers.full_link
33523 * Cg(Cc("full"), "link_type")
33524 + #parsers.collapsed_link
33525 * Cg(Cc("collapsed"), "link_type")
33526 + #parsers.shortcut_link
33527 * Cg(Cc("shortcut"), "link_type")
33528 + #parsers.empty_link
33529 * Cg(Cc("empty_link"), "link_type")
33530 + #parsers.link_text
33531 * Cg(Cc("link_text"), "link_type")
33532
33533 parsers.note_opening = #(parsers.circumflex * parsers.link_text)
33534 * Cg(Cc("note_inline"), "link_type")
33535
33536 parsers.raw_note_opening = #( parsers.lbracket
33537 * parsers.circumflex
33538 * parsers.link_label_body
33539 * parsers.rbracket)
33540 * Cg(Cc("raw_note"), "link_type")
33541
33542 local inline_note_element = Cg(Cc("note"), "element")
33543 * parsers.note_opening
33544 * Cg( parsers.circumflex
33545 * parsers.lbracket, "content")
33546
33547 local image_element = Cg(Cc("image"), "element")
33548 * parsers.image_opening
33549 * Cg( parsers.exclamation
33550 * parsers.lbracket, "content")
33551
33552 local note_element = Cg(Cc("note"), "element")
33553 * parsers.raw_note_opening
33554 * Cg( parsers.lbracket
33555 * parsers.circumflex, "content")
33556
33557 local link_element = Cg(Cc("link"), "element")
33558 * parsers.link_opening
33559 * Cg(parsers.lbracket, "content")
33560
33561 local opening_elements = parsers.fail
33562
33563 if options.inlineNotes then
33564 opening_elements = opening_elements + inline_note_element
33565 end
33566
33567 opening_elements = opening_elements + image_element
33568
33569 if options.notes then
33570 opening_elements = opening_elements + note_element
33571 end
33572
33573 opening_elements = opening_elements + link_element
33574
33575 parsers.link_image_opening = Ct( Cg(Cc("delimiter"), "type")
33576 * Cg(Cc(true), "is_opening")
33577 * Cg(Cc(false), "is_closing")
33578 * opening_elements)
33579
33580 parsers.link_image_closing = Ct( Cg(Cc("delimiter"), "type")
33581 * Cg(Cc("link"), "element")
33582 * Cg(Cc(false), "is_opening")
33583 * Cg(Cc(true), "is_closing")
33584 * ( Cg(Cc(true), "is_direct")
33585 * Cg( parsers.rbracket
33586 * #parsers.inline_direct_ref,
33587 "content")
33588 + Cg(Cc(false), "is_direct")
33589 * Cg(parsers.rbracket, "content")))
33590
33591 parsers.link_image_open_or_close = parsers.link_image_opening
33592 + parsers.link_image_closing
33593
33594 if options.html then
33595 parsers.link_emph_precedence = parsers.inticks
33596 + parsers.autolink
33597 + parsers.html_inline_tags
33598 else
33599 parsers.link_emph_precedence = parsers.inticks
33600 + parsers.autolink
33601 end
33602
33603 parsers.link_and_emph_endline = parsers.newline
33604 * ((parsers.check_minimal_indent
33605 * -V("EndlineExceptions")
33606 + parsers.check_optional_indent
33607 * -V("EndlineExceptions")
33608 * -V("ListStarter")) / "")
33609 * parsers.spacechar^0 / "\n"
33610
33611 parsers.link_and_emph_content
33612 = Ct( Cg(Cc("content"), "type")
33613 * Cg(Cs(( parsers.link_emph_precedence
33614 + parsers.backslash * parsers.linechar
33615 + parsers.link_and_emph_endline
33616 + (parsers.linechar
33617 - parsers.blankline^2
33618 - parsers.link_image_open_or_close
33619 - parsers.emph_open_or_close))^0), "content"))
33620
33621 parsers.link_and_emph_table
33622 = (parsers.link_image_opening + parsers.emph_open)
33623 * parsers.link_and_emph_content
33624 * ((parsers.link_image_open_or_close + parsers.emph_open_or_close)
33625 * parsers.link_and_emph_content)^1
33626
33627 % \end{macrocode}
33628 % \begin{markdown}
33629 %
33630 % Collect the content between the `opening_index` and `closing_index` in the delimiter table `t`.
33631 %
33632 % \end{markdown}
33633 % \begin{macrocode}
33634 local function collect_link_content(t, opening_index, closing_index)
33635 local content = {}
33636 for i = opening_index, closing_index do
33637 content[#content + 1] = t[i].content
33638 end
33639 return util.rope_to_string(content)
33640 end
33641
33642 % \end{macrocode}
33643 % \begin{markdown}
33644 %
33645 % Look for the closest potential link opener in the delimiter table `t` in the range from
33646 % `bottom_index` to `latest_index`.
33647 %
33648 % \end{markdown}
33649 % \begin{macrocode}
33650 local function find_link_opener(t, bottom_index, latest_index)
33651 for i = latest_index, bottom_index, -1 do
33652 local value = t[i]
33653 if value.type == "delimiter" and
33654 value.is_opening and
33655 ( value.element == "link"
33656 or value.element == "image"
33657 or value.element == "note")
33658 and not value.removed then
33659 if value.is_active then
33660 return i
33661 end
33662 value.removed = true
33663 return nil
33664 end
33665 end
33666 end
33667
33668 % \end{macrocode}
33669 % \begin{markdown}
33670 %
33671 % Find the position of a delimiter that closes a full link after an an index `latest_index`
33672 % in the delimiter table `t`.
33673 %
33674 % \end{markdown}
33675 % \begin{macrocode}
33676 local function find_next_link_closing_index(t, latest_index)
33677 for i = latest_index, #t do
33678 local value = t[i]
33679 if value.is_closing and
33680 value.element == "link" and
33681 not value.removed then
33682 return i
33683 end
33684 end
33685 end
33686
33687 % \end{macrocode}
33688 % \begin{markdown}
33689 %
33690 % Disable all preceding opening link delimiters by marking them inactive with the `is_active` property
33691 % to prevent links within links. Images within links are allowed.
33692 %
33693 % \end{markdown}
33694 % \begin{macrocode}
33695 local function disable_previous_link_openers(t, opening_index)
33696 if t[opening_index].element == "image" then
33697 return
33698 end
33699
33700 for i = opening_index, 1, -1 do
33701 local value = t[i]
33702 if value.is_active and
33703 value.type == "delimiter" and
33704 value.is_opening and
33705 value.element == "link" then
33706 value.is_active = false
33707 end
33708 end
33709 end
33710
33711 % \end{macrocode}
33712 % \begin{markdown}
33713 %
33714 % Disable the delimiters between the `opening_index` and `closing_index` in the delimiter table `t`
33715 % by marking them inactive with the `is_active` property.
33716 %
33717 % \end{markdown}
33718 % \begin{macrocode}
33719 local function disable_range(t, opening_index, closing_index)
33720 for i = opening_index, closing_index do
33721 local value = t[i]
33722 if value.is_active then
33723 value.is_active = false
33724 if value.type == "delimiter" then
33725 value.removed = true
33726 end
33727 end
33728 end
33729 end
33730
33731 % \end{macrocode}
33732 % \begin{markdown}
33733 %
33734 % Clear the parsed content between the `opening_index` and `closing_index` in the delimiter table `t`.
33735 %
33736 % \end{markdown}
33737 % \begin{macrocode}
33738 local delete_parsed_content_in_range =
33739 function(t, opening_index, closing_index)
33740 for i = opening_index, closing_index do
33741 t[i].rendered = nil
33742 end
33743 end
33744
33745 % \end{macrocode}
33746 % \begin{markdown}
33747 %
33748 % Clear the content between the `opening_index` and `closing_index` in the delimiter table `t`.
33749 %
33750 % \end{markdown}
33751 % \begin{macrocode}
33752 local function empty_content_in_range(t, opening_index, closing_index)
33753 for i = opening_index, closing_index do
33754 t[i].content = ''
33755 end
33756 end
33757
33758 % \end{macrocode}
33759 % \begin{markdown}
33760 %
33761 % Join the attributes from the link reference definition `reference_attributes` with the link's own
33762 % attributes `own_attributes`.
33763 %
33764 % \end{markdown}
33765 % \begin{macrocode}
33766 local function join_attributes(reference_attributes, own_attributes)
33767 local merged_attributes = {}
33768 for _, attribute in ipairs(reference_attributes or {}) do
33769 table.insert(merged_attributes, attribute)
33770 end
33771 for _, attribute in ipairs(own_attributes or {}) do
33772 table.insert(merged_attributes, attribute)
33773 end
33774 if next(merged_attributes) == nil then
33775 merged_attributes = nil
33776 end
33777 return merged_attributes
33778 end
33779
33780 % \end{macrocode}
33781 % \begin{markdown}
33782 %
33783 % Parse content between two delimiters in the delimiter table `t`. Produce the respective link and image
33784 % macros.
33785 %
33786 % \end{markdown}
33787 % \begin{macrocode}
33788 local render_link_or_image =
33789 function(t, opening_index, closing_index, content_end_index,
33790 reference)
33791 process_emphasis(t, opening_index, content_end_index)
33792 local mapped = collect_emphasis_content(t, opening_index + 1,
33793 content_end_index - 1)
33794
33795 local rendered = {}
33796 if (t[opening_index].element == "link") then
33797 rendered = writer.link(mapped, reference.url,
33798 reference.title, reference.attributes)
33799 end
33800
33801 if (t[opening_index].element == "image") then
33802 rendered = writer.image(mapped, reference.url,
33803 self.parser_functions.parse_inlines_string(reference.title),
33804 reference.attributes)
33805 end
33806
33807 if (t[opening_index].element == "note") then
33808 if (t[opening_index].link_type == "note_inline") then
33809 rendered = writer.note(mapped)
33810 end
33811 if (t[opening_index].link_type == "raw_note") then
33812 rendered = writer.note(reference)
33813 end
33814 end
33815
33816 t[opening_index].rendered = rendered
33817 delete_parsed_content_in_range(t, opening_index + 1,
33818 closing_index)
33819 empty_content_in_range(t, opening_index, closing_index)
33820 disable_previous_link_openers(t, opening_index)
33821 disable_range(t, opening_index, closing_index)
33822 end
33823
33824 % \end{macrocode}
33825 % \begin{markdown}
33826 %
33827 % Match the link destination of an inline link at index `closing_index` in table `t`
33828 % when `match_reference` is true. Additionally, match attributes when the option
33829 % \Opt{linkAttributes} is enabled.
33830 %
33831 % \end{markdown}
33832 % \begin{macrocode}
33833 local resolve_inline_following_content =
33834 function(t, closing_index, match_reference, match_link_attributes)
33835 local content = ""
33836 for i = closing_index + 1, #t do
33837 content = content .. t[i].content
33838 end
33839
33840 local matching_content = parsers.succeed
33841
33842 if match_reference then
33843 matching_content = matching_content
33844 * parsers.inline_direct_ref_inside
33845 end
33846
33847 if match_link_attributes then
33848 matching_content = matching_content
33849 * Cg(Ct(parsers.attributes^-1), "attributes")
33850 end
33851
33852 local matched = lpeg.match(Ct( matching_content
33853 * Cg(Cp(), "end_position")), content)
33854
33855 local matched_count = matched.end_position - 1
33856 for i = closing_index + 1, #t do
33857 local value = t[i]
33858
33859 local chars_left = matched_count
33860 matched_count = matched_count - #value.content
33861
33862 if matched_count <= 0 then
33863 value.content = value.content:sub(chars_left + 1)
33864 break
33865 end
33866
33867 value.content = ''
33868 value.is_active = false
33869 end
33870
33871 local attributes = matched.attributes
33872 if attributes == nil or next(attributes) == nil then
33873 attributes = nil
33874 end
33875
33876 return {
33877 url = matched.url or "",
33878 title = matched.title or "",
33879 attributes = attributes
33880 }
33881 end
33882
33883 % \end{macrocode}
33884 % \begin{markdown}
33885 %
33886 % Resolve an inline link `[a](b "c")` from the delimiters at `opening_index` and `closing_index`
33887 % within a delimiter table `t`. Here, compared to other types of links, no reference definition is needed.
33888 %
33889 % \end{markdown}
33890 % \begin{macrocode}
33891 local function resolve_inline_link(t, opening_index, closing_index)
33892 local inline_content
33893 = resolve_inline_following_content(t, closing_index, true,
33894 t.match_link_attributes)
33895 render_link_or_image(t, opening_index, closing_index,
33896 closing_index, inline_content)
33897 end
33898
33899 % \end{macrocode}
33900 % \begin{markdown}
33901 %
33902 % Resolve an inline note `^[a]` from the delimiters at `opening_index` and `closing_index`
33903 % within a delimiter table `t`.
33904 %
33905 % \end{markdown}
33906 % \begin{macrocode}
33907 local resolve_note_inline_link =
33908 function(t, opening_index, closing_index)
33909 local inline_content
33910 = resolve_inline_following_content(t, closing_index,
33911 false, false)
33912 render_link_or_image(t, opening_index, closing_index,
33913 closing_index, inline_content)
33914 end
33915
33916 % \end{macrocode}
33917 % \begin{markdown}
33918 %
33919 % Resolve a shortcut link `[a]` from the delimiters at `opening_index` and `closing_index` within a delimiter table `t`.
33920 % Continue if a tag `a` is not found in the references.
33921 %
33922 % \end{markdown}
33923 % \begin{macrocode}
33924 local function resolve_shortcut_link(t, opening_index, closing_index)
33925 local content
33926 = collect_link_content(t, opening_index + 1, closing_index - 1)
33927 local r = self.lookup_reference(content)
33928
33929 if r then
33930 local inline_content
33931 = resolve_inline_following_content(t, closing_index, false,
33932 t.match_link_attributes)
33933 r.attributes
33934 = join_attributes(r.attributes, inline_content.attributes)
33935 render_link_or_image(t, opening_index, closing_index,
33936 closing_index, r)
33937 end
33938 end
33939
33940 % \end{macrocode}
33941 % \begin{markdown}
33942 %
33943 % Resolve a note `[^a]` from the delimiters at `opening_index` and `closing_index` within a delimiter table `t`.
33944 % Continue if a tag `a` is not found in the rawnotes.
33945 %
33946 % \end{markdown}
33947 % \begin{macrocode}
33948 local function resolve_raw_note_link(t, opening_index, closing_index)
33949 local content
33950 = collect_link_content(t, opening_index + 1, closing_index - 1)
33951 local r = self.lookup_note_reference(content)
33952
33953 if r then
33954 local parsed_ref = self.parser_functions.parse_blocks_nested(r)
33955 render_link_or_image(t, opening_index, closing_index,
33956 closing_index, parsed_ref)
33957 end
33958 end
33959
33960 % \end{macrocode}
33961 % \begin{markdown}
33962 %
33963 % Resolve a full link `[a][b]` from the delimiters at `opening_index` and `closing_index` within a delimiter table `t`.
33964 % Continue if a tag `b` is not found in the references.
33965 %
33966 % \end{markdown}
33967 % \begin{macrocode}
33968 local function resolve_full_link(t, opening_index, closing_index)
33969 local next_link_closing_index
33970 = find_next_link_closing_index(t, closing_index + 4)
33971 local next_link_content
33972 = collect_link_content(t, closing_index + 3,
33973 next_link_closing_index - 1)
33974 local r = self.lookup_reference(next_link_content)
33975
33976 if r then
33977 local inline_content
33978 = resolve_inline_following_content(t, next_link_closing_index,
33979 false,
33980 t.match_link_attributes)
33981 r.attributes
33982 = join_attributes(r.attributes, inline_content.attributes)
33983 render_link_or_image(t, opening_index, next_link_closing_index,
33984 closing_index, r)
33985 else
33986 local text = string.format('Undefined link reference "%s"',
33987 next_link_content)
33988 local more = string.format("Look for the text `[...][%s]`.",
33989 next_link_content)
33990 t[opening_index].warning = writer.warning(text, more)
33991 end
33992 end
33993
33994 % \end{macrocode}
33995 % \begin{markdown}
33996 %
33997 % Resolve a collapsed link `[a][]` from the delimiters at `opening_index` and `closing_index`
33998 % within a delimiter table `t`.
33999 % Continue if a tag `a` is not found in the references.
34000 %
34001 % \end{markdown}
34002 % \begin{macrocode}
34003 local function resolve_collapsed_link(t, opening_index, closing_index)
34004 local next_link_closing_index
34005 = find_next_link_closing_index(t, closing_index + 4)
34006 local content
34007 = collect_link_content(t, opening_index + 1, closing_index - 1)
34008 local r = self.lookup_reference(content)
34009
34010 if r then
34011 local inline_content
34012 = resolve_inline_following_content(t, closing_index, false,
34013 t.match_link_attributes)
34014 r.attributes
34015 = join_attributes(r.attributes, inline_content.attributes)
34016 render_link_or_image(t, opening_index, next_link_closing_index,
34017 closing_index, r)
34018 else
34019 local text = string.format('Undefined link reference "%s"',
34020 content)
34021 local more = string.format("Look for the text `[%s][]`.",
34022 content)
34023 t[opening_index].warning = writer.warning(text, more)
34024 end
34025 end
34026
34027 % \end{macrocode}
34028 % \begin{markdown}
34029 %
34030 % Parse a table of link and emphasis delimiters `t`.
34031 % First, iterate over the link delimiters and produce either link or image macros.
34032 % Then run `process_emphasis` over the entire delimiter table, resolving emphasis and strong
34033 % emphasis and parsing any content outside of closed delimiters.
34034 %
34035 % \end{markdown}
34036 % \begin{macrocode}
34037 local function process_links_and_emphasis(t)
34038 for _,value in ipairs(t) do
34039 value.is_active = true
34040 end
34041
34042 for i,value in ipairs(t) do
34043 if not value.is_closing
34044 or value.type ~= "delimiter"
34045 or not ( value.element == "link"
34046 or value.element == "image"
34047 or value.element == "note")
34048 or value.removed then
34049 goto continue
34050 end
34051
34052 local opener_position = find_link_opener(t, 1, i - 1)
34053 if (opener_position == nil) then
34054 goto continue
34055 end
34056
34057 local opening_delimiter = t[opener_position]
34058 opening_delimiter.removed = true
34059
34060 local link_type = opening_delimiter.link_type
34061
34062 if (link_type == "inline") then
34063 resolve_inline_link(t, opener_position, i)
34064 end
34065 if (link_type == "shortcut") then
34066 resolve_shortcut_link(t, opener_position, i)
34067 end
34068 if (link_type == "full") then
34069 resolve_full_link(t, opener_position, i)
34070 end
34071 if (link_type == "collapsed") then
34072 resolve_collapsed_link(t, opener_position, i)
34073 end
34074 if (link_type == "note_inline") then
34075 resolve_note_inline_link(t, opener_position, i)
34076 end
34077 if (link_type == "raw_note") then
34078 resolve_raw_note_link(t, opener_position, i)
34079 end
34080
34081 ::continue::
34082 end
34083
34084 t[#t].content = t[#t].content:gsub("%s*$","")
34085
34086 process_emphasis(t, 1, #t)
34087 local final_result = collect_emphasis_content(t, 1, #t)
34088 return final_result
34089 end
34090
34091 function self.defer_link_and_emphasis_processing(delimiter_table)
34092 return writer.defer_call(function()
34093 return process_links_and_emphasis(delimiter_table)
34094 end)
34095 end
34096
34097 % \end{macrocode}
34098 % \begin{markdown}
34099 %
34100 %#### Inline Elements (local)
34101 %
34102 % \end{markdown}
34103 % \begin{macrocode}
34104 parsers.Str = ( parsers.normalchar
34105 * (parsers.normalchar + parsers.at)^0)
34106 / writer.string
34107
34108 parsers.Symbol = (parsers.backtick^1 + V("SpecialChar"))
34109 / writer.string
34110
34111 parsers.Ellipsis = P("...") / writer.ellipsis
34112
34113 parsers.Smart = parsers.Ellipsis
34114
34115 parsers.Code = parsers.inticks / writer.code
34116
34117 if options.blankBeforeBlockquote then
34118 parsers.bqstart = parsers.fail
34119 else
34120 parsers.bqstart = parsers.blockquote_start
34121 end
34122
34123 if options.blankBeforeHeading then
34124 parsers.headerstart = parsers.fail
34125 else
34126 parsers.headerstart = parsers.atx_heading
34127 end
34128
34129 if options.blankBeforeList then
34130 parsers.interrupting_bullets = parsers.fail
34131 parsers.interrupting_enumerators = parsers.fail
34132 else
34133 parsers.interrupting_bullets
34134 = parsers.bullet(parsers.dash, true)
34135 + parsers.bullet(parsers.asterisk, true)
34136 + parsers.bullet(parsers.plus, true)
34137
34138 parsers.interrupting_enumerators
34139 = parsers.enumerator(parsers.period, true)
34140 + parsers.enumerator(parsers.rparent, true)
34141 end
34142
34143 if options.html then
34144 parsers.html_interrupting
34145 = parsers.check_trail
34146 * ( parsers.html_incomplete_open_tag
34147 + parsers.html_incomplete_close_tag
34148 + parsers.html_incomplete_open_special_tag
34149 + parsers.html_comment_start
34150 + parsers.html_cdatasection_start
34151 + parsers.html_declaration_start
34152 + parsers.html_instruction_start
34153 - parsers.html_close_special_tag
34154 - parsers.html_empty_special_tag)
34155 else
34156 parsers.html_interrupting = parsers.fail
34157 end
34158
34159 if options.blankBeforeHtmlBlock then
34160 parsers.html_interrupting = parsers.fail
34161 end
34162
34163 parsers.ListStarter = parsers.starter
34164
34165 parsers.EndlineExceptions
34166 = parsers.blankline -- paragraph break
34167 + parsers.eof -- end of document
34168 + parsers.bqstart
34169 + parsers.thematic_break_lines
34170 + parsers.interrupting_bullets
34171 + parsers.interrupting_enumerators
34172 + parsers.headerstart
34173 + parsers.html_interrupting
34174
34175 parsers.NoSoftLineBreakEndlineExceptions = parsers.EndlineExceptions
34176
34177 parsers.endline = parsers.newline
34178 * (parsers.check_minimal_indent
34179 * -V("EndlineExceptions")
34180 + parsers.check_optional_indent
34181 * -V("EndlineExceptions")
34182 * -V("ListStarter")) / function(_) return end
34183 * parsers.spacechar^0
34184
34185 parsers.Endline = parsers.endline
34186 / writer.soft_line_break
34187
34188 parsers.EndlineNoSub = parsers.endline
34189
34190 parsers.NoSoftLineBreakEndline
34191 = parsers.newline
34192 * (parsers.check_minimal_indent
34193 * -V("NoSoftLineBreakEndlineExceptions")
34194 + parsers.check_optional_indent
34195 * -V("NoSoftLineBreakEndlineExceptions")
34196 * -V("ListStarter"))
34197 * parsers.spacechar^0
34198 / writer.space
34199
34200 parsers.EndlineBreak = parsers.backslash * parsers.endline
34201 / writer.hard_line_break
34202
34203 parsers.OptionalIndent
34204 = parsers.spacechar^1 / writer.space
34205
34206 parsers.Space = parsers.spacechar^2 * parsers.endline
34207 / writer.hard_line_break
34208 + parsers.spacechar^1
34209 * parsers.endline^-1
34210 * parsers.eof / self.expandtabs
34211 + parsers.spacechar^1 * parsers.endline
34212 / writer.soft_line_break
34213 + parsers.spacechar^1
34214 * -parsers.newline / self.expandtabs
34215 + parsers.spacechar^1
34216 + ( parsers.spacechar
34217 + parsers.html_space_entity_char)^1
34218 * parsers.endline / writer.soft_line_break
34219
34220 parsers.NonbreakingEndline
34221 = parsers.endline
34222 / writer.nbsp
34223
34224 parsers.NonbreakingSpace
34225 = parsers.spacechar^2 * parsers.endline
34226 / writer.nbsp
34227 + parsers.spacechar^1
34228 * parsers.endline^-1 * parsers.eof / ""
34229 + parsers.spacechar^1 * parsers.endline
34230 * parsers.optionalspace
34231 / writer.nbsp
34232 + parsers.spacechar^1 * parsers.optionalspace
34233 / writer.nbsp
34234
34235 % \end{macrocode}
34236 % \begin{markdown}
34237 %
34238 % The \luamdef{reader->auto_link_url} method produces an
34239 % autolink to a URL or a relative reference in the output
34240 % format, where `url` is the link destination and
34241 % `attributes` are the optional attributes.
34242 %
34243 % \end{markdown}
34244 % \begin{macrocode}
34245 function self.auto_link_url(url, attributes)
34246 return writer.link(writer.escape(url),
34247 url, nil, attributes)
34248 end
34249 % \end{macrocode}
34250 % \begin{markdown}
34251 %
34252 % The \luamdef{reader->auto_link_email} method produces an
34253 % autolink to an e-mail in the output format, where `email` is the email
34254 % address destination and `attributes` are the optional attributes.
34255 %
34256 % \end{markdown}
34257 % \begin{macrocode}
34258 function self.auto_link_email(email, attributes)
34259 return writer.link(writer.escape(email),
34260 "mailto:"..email,
34261 nil, attributes)
34262 end
34263
34264 parsers.AutoLinkUrl = parsers.auto_link_url
34265 / self.auto_link_url
34266
34267 parsers.AutoLinkEmail
34268 = parsers.auto_link_email
34269 / self.auto_link_email
34270
34271 parsers.AutoLinkRelativeReference
34272 = parsers.auto_link_relative_reference
34273 / self.auto_link_url
34274
34275 parsers.LinkAndEmph = Ct(parsers.link_and_emph_table)
34276 / self.defer_link_and_emphasis_processing
34277
34278 parsers.EscapedChar = parsers.backslash
34279 * C(parsers.escapable) / writer.string
34280
34281 if options.htmlOutput == "commonmark" then
34282 parsers.InlineHtml
34283 = Cs(parsers.html_inline_comment)
34284 / self.parser_functions.parse_inlines_no_html
34285 / writer.inline_html_comment
34286 + Cs(parsers.html_any_empty_inline_tag)
34287 / writer.inline_html_empty_tag
34288 + Cs(parsers.html_inline_instruction)
34289 / writer.inline_html_processing_instruction
34290 + Cs(parsers.html_inline_cdatasection)
34291 / writer.inline_html_cdata_section
34292 + Cs(parsers.html_inline_declaration)
34293 / writer.inline_html_declaration
34294 + Cs(parsers.html_any_open_inline_tag)
34295 / writer.inline_html_open_tag
34296 + Cs(parsers.html_any_close_tag)
34297 / writer.inline_html_close_tag
34298 else
34299 parsers.InlineHtml = Cs(parsers.html_inline_comment)
34300 / self.parser_functions.parse_inlines_no_html
34301 / writer.inline_html_comment
34302 + Cs( parsers.html_any_empty_inline_tag
34303 + parsers.html_inline_instruction
34304 + parsers.html_inline_cdatasection
34305 + parsers.html_inline_declaration
34306 + parsers.html_any_open_inline_tag
34307 + parsers.html_any_close_tag)
34308 / writer.inline_html_tag
34309 end
34310
34311 parsers.HtmlEntity = parsers.html_entities / writer.string
34312 % \end{macrocode}
34313 % \begin{markdown}
34314 %
34315 %#### Block Elements (local)
34316 %
34317 % \end{markdown}
34318 % \begin{macrocode}
34319 if options.htmlOutput == "commonmark" then
34320 parsers.DisplayHtml
34321 = parsers.check_trail
34322 * ( parsers.html_comment
34323 / self.parser_functions.parse_blocks_nested
34324 / writer.block_html_comment)
34325 + Cs(parsers.check_trail * parsers.html_special_block)
34326 / writer.block_html_cdata_element
34327 + Cs(parsers.check_trail * parsers.html_block)
34328 / writer.block_html_pcdata_element
34329 + Cs(parsers.check_trail * parsers.html_any_block)
34330 / writer.block_html_standalone_tag
34331 + Cs(parsers.check_trail * parsers.html_instruction)
34332 / writer.block_html_processing_instruction
34333 + Cs(parsers.check_trail * parsers.html_cdatasection)
34334 / writer.block_html_cdata_section
34335 + Cs(parsers.check_trail * parsers.html_declaration)
34336 / writer.block_html_declaration
34337 else
34338 parsers.DisplayHtml = Cs( parsers.check_trail
34339 * ( parsers.html_comment
34340 + parsers.html_special_block
34341 + parsers.html_block
34342 + parsers.html_any_block
34343 + parsers.html_instruction
34344 + parsers.html_cdatasection
34345 + parsers.html_declaration))
34346 / writer.block_html_element
34347 end
34348
34349 parsers.indented_non_blank_line = parsers.indentedline
34350 - parsers.blankline
34351
34352 parsers.Verbatim
34353 = Cs( parsers.check_code_trail
34354 * (parsers.line - parsers.blankline)
34355 * (( parsers.check_minimal_blank_indent_and_full_code_trail
34356 * parsers.blankline)^0
34357 * ( (parsers.check_minimal_indent / "")
34358 * parsers.check_code_trail
34359 * (parsers.line - parsers.blankline))^1)^0)
34360 / self.expandtabs / writer.verbatim
34361
34362 parsers.Blockquote = parsers.blockquote_body
34363 / writer.blockquote
34364
34365 parsers.ThematicBreak = parsers.thematic_break_lines
34366 / writer.thematic_break
34367
34368 parsers.Reference = parsers.define_reference_parser
34369 / self.register_link
34370
34371 parsers.Paragraph = parsers.freeze_trail
34372 * (Ct((parsers.Inline)^1)
34373 * (parsers.newline + parsers.eof)
34374 * parsers.unfreeze_trail
34375 / writer.paragraph)
34376
34377 parsers.Plain = parsers.nonindentspace * Ct(parsers.Inline^1)
34378 / writer.plain
34379 % \end{macrocode}
34380 % \begin{markdown}
34381 %
34382 %#### Lists (local)
34383 %
34384 % \end{markdown}
34385 % \begin{macrocode}
34386
34387 if options.taskLists then
34388 parsers.tickbox = ( parsers.ticked_box
34389 + parsers.halfticked_box
34390 + parsers.unticked_box
34391 ) / writer.tickbox
34392 else
34393 parsers.tickbox = parsers.fail
34394 end
34395
34396 parsers.list_blank = parsers.conditionally_indented_blankline
34397
34398 parsers.ref_or_block_list_separated
34399 = parsers.sep_group_no_output(parsers.list_blank)
34400 * parsers.minimally_indented_ref
34401 + parsers.block_sep_group(parsers.list_blank)
34402 * parsers.minimally_indented_block
34403
34404 parsers.ref_or_block_non_separated
34405 = parsers.minimally_indented_ref
34406 + (parsers.succeed / writer.interblocksep)
34407 * parsers.minimally_indented_block
34408 - parsers.minimally_indented_blankline
34409
34410 parsers.tight_list_loop_body_pair =
34411 parsers.create_loop_body_pair(
34412 parsers.ref_or_block_non_separated,
34413 parsers.minimally_indented_par_or_plain_no_blank,
34414 (parsers.succeed / writer.interblocksep),
34415 (parsers.succeed / writer.paragraphsep))
34416
34417 parsers.loose_list_loop_body_pair =
34418 parsers.create_loop_body_pair(
34419 parsers.ref_or_block_list_separated,
34420 parsers.minimally_indented_par_or_plain,
34421 parsers.block_sep_group(parsers.list_blank),
34422 parsers.par_sep_group(parsers.list_blank))
34423
34424 parsers.tight_list_content_loop
34425 = V("Block")
34426 * parsers.tight_list_loop_body_pair.block^0
34427 + (V("Paragraph") + V("Plain"))
34428 * parsers.ref_or_block_non_separated
34429 * parsers.tight_list_loop_body_pair.block^0
34430 + (V("Paragraph") + V("Plain"))
34431 * parsers.tight_list_loop_body_pair.par^0
34432
34433 parsers.loose_list_content_loop
34434 = V("Block")
34435 * parsers.loose_list_loop_body_pair.block^0
34436 + (V("Paragraph") + V("Plain"))
34437 * parsers.ref_or_block_list_separated
34438 * parsers.loose_list_loop_body_pair.block^0
34439 + (V("Paragraph") + V("Plain"))
34440 * parsers.loose_list_loop_body_pair.par^0
34441
34442 parsers.list_item_tightness_condition
34443 = -#( parsers.list_blank^0
34444 * parsers.minimally_indented_ref_or_block_or_par)
34445 * remove_indent("li")
34446 + remove_indent("li")
34447 * parsers.fail
34448
34449 parsers.indented_content_tight
34450 = Ct( (parsers.blankline / "")
34451 * #parsers.list_blank
34452 * remove_indent("li")
34453 + ( (V("Reference") + (parsers.blankline / ""))
34454 * parsers.check_minimal_indent
34455 * parsers.tight_list_content_loop
34456 + (V("Reference") + (parsers.blankline / ""))
34457 + (parsers.tickbox^-1 / writer.escape)
34458 * parsers.tight_list_content_loop
34459 )
34460 * parsers.list_item_tightness_condition)
34461
34462 parsers.indented_content_loose
34463 = Ct( (parsers.blankline / "")
34464 * #parsers.list_blank
34465 + ( (V("Reference") + (parsers.blankline / ""))
34466 * parsers.check_minimal_indent
34467 * parsers.loose_list_content_loop
34468 + (V("Reference") + (parsers.blankline / ""))
34469 + (parsers.tickbox^-1 / writer.escape)
34470 * parsers.loose_list_content_loop))
34471
34472 parsers.TightListItem = function(starter)
34473 return -parsers.ThematicBreak
34474 * parsers.add_indent(starter, "li")
34475 * parsers.indented_content_tight
34476 end
34477
34478 parsers.LooseListItem = function(starter)
34479 return -parsers.ThematicBreak
34480 * parsers.add_indent(starter, "li")
34481 * parsers.indented_content_loose
34482 * remove_indent("li")
34483 end
34484
34485 parsers.BulletListOfType = function(bullet_type)
34486 local bullet = parsers.bullet(bullet_type)
34487 return ( Ct( parsers.TightListItem(bullet)
34488 * ( (parsers.check_minimal_indent / "")
34489 * parsers.TightListItem(bullet)
34490 )^0
34491 )
34492 * Cc(true)
34493 * -#( (parsers.list_blank^0 / "")
34494 * parsers.check_minimal_indent
34495 * (bullet - parsers.ThematicBreak)
34496 )
34497 + Ct( parsers.LooseListItem(bullet)
34498 * ( (parsers.list_blank^0 / "")
34499 * (parsers.check_minimal_indent / "")
34500 * parsers.LooseListItem(bullet)
34501 )^0
34502 )
34503 * Cc(false)
34504 ) / writer.bulletlist
34505 end
34506
34507 parsers.BulletList = parsers.BulletListOfType(parsers.dash)
34508 + parsers.BulletListOfType(parsers.asterisk)
34509 + parsers.BulletListOfType(parsers.plus)
34510
34511 local function ordered_list(items,tight,starter)
34512 local startnum = starter[2][1]
34513 if options.startNumber then
34514 startnum = tonumber(startnum) or 1 -- fallback for '#'
34515 if startnum ~= nil then
34516 startnum = math.floor(startnum)
34517 end
34518 else
34519 startnum = nil
34520 end
34521 return writer.orderedlist(items,tight,startnum)
34522 end
34523
34524 parsers.OrderedListOfType = function(delimiter_type)
34525 local enumerator = parsers.enumerator(delimiter_type)
34526 return Cg(enumerator, "listtype")
34527 * (Ct( parsers.TightListItem(Cb("listtype"))
34528 * ( (parsers.check_minimal_indent / "")
34529 * parsers.TightListItem(enumerator))^0)
34530 * Cc(true)
34531 * -#((parsers.list_blank^0 / "")
34532 * parsers.check_minimal_indent * enumerator)
34533 + Ct( parsers.LooseListItem(Cb("listtype"))
34534 * ((parsers.list_blank^0 / "")
34535 * (parsers.check_minimal_indent / "")
34536 * parsers.LooseListItem(enumerator))^0)
34537 * Cc(false)
34538 ) * Ct(Cb("listtype")) / ordered_list
34539 end
34540
34541 parsers.OrderedList = parsers.OrderedListOfType(parsers.period)
34542 + parsers.OrderedListOfType(parsers.rparent)
34543 % \end{macrocode}
34544 % \begin{markdown}
34545 %
34546 %#### Blank (local)
34547 %
34548 % \end{markdown}
34549 % \begin{macrocode}
34550 parsers.Blank = parsers.blankline / ""
34551 + V("Reference")
34552 % \end{macrocode}
34553 % \begin{markdown}
34554 %
34555 %#### Headings (local)
34556 %
34557 % \end{markdown}
34558 % \begin{macrocode}
34559 function parsers.parse_heading_text(s)
34560 local inlines = self.parser_functions.parse_inlines(s)
34561 local flatten_inlines = self.writer.flatten_inlines
34562 self.writer.flatten_inlines = true
34563 local flat_text = self.parser_functions.parse_inlines(s)
34564 flat_text = util.rope_to_string(flat_text)
34565 self.writer.flatten_inlines = flatten_inlines
34566 return {flat_text, inlines}
34567 end
34568
34569 -- parse atx header
34570 parsers.AtxHeading = parsers.check_trail_no_rem
34571 * Cg(parsers.heading_start, "level")
34572 * ((C( parsers.optionalspace
34573 * parsers.hash^0
34574 * parsers.optionalspace
34575 * parsers.newline)
34576 + parsers.spacechar^1
34577 * C(parsers.line))
34578 / strip_atx_end
34579 / parsers.parse_heading_text)
34580 * Cb("level")
34581 / writer.heading
34582
34583 parsers.heading_line = parsers.linechar^1
34584 - parsers.thematic_break_lines
34585
34586 parsers.heading_text = parsers.heading_line
34587 * ( (V("Endline") / "\n")
34588 * ( parsers.heading_line
34589 - parsers.heading_level))^0
34590 * parsers.newline^-1
34591
34592 parsers.SetextHeading = parsers.freeze_trail
34593 * parsers.check_trail_no_rem
34594 * #( parsers.heading_text
34595 * parsers.check_minimal_indent
34596 * parsers.check_trail
34597 * parsers.heading_level)
34598 * Cs(parsers.heading_text)
34599 / parsers.parse_heading_text
34600 * parsers.check_minimal_indent_and_trail
34601 * parsers.heading_level
34602 * parsers.newline
34603 * parsers.unfreeze_trail
34604 / writer.heading
34605
34606 parsers.Heading = parsers.AtxHeading + parsers.SetextHeading
34607 % \end{macrocode}
34608 % \begin{markdown}
34609 %
34610 %#### Syntax Specification
34611 % Define \luamdef{reader->finalize_grammar} as a function that constructs the
34612 % PEG grammar of markdown, applies syntax extensions `extensions` and
34613 % returns a conversion function that takes a markdown string and turns it into
34614 % a plain \TeX{} output.
34615 %
34616 % \end{markdown}
34617 % \begin{macrocode}
34618 function self.finalize_grammar(extensions)
34619 % \end{macrocode}
34620 % \begin{markdown}
34621 %
34622 % Create a local writable copy of the global read-only
34623 % \luamref{walkable_syntax} hash table. This table can be used by user-defined
34624 % syntax extensions to insert new PEG patterns into existing rules
34625 % of the PEG grammar of markdown using
34626 % the \luamref{reader->insert_pattern} method. Furthermore, built-in syntax
34627 % extensions can use this table to override existing rules using the
34628 % \luamref{reader->update_rule} method.
34629 %
34630 % \end{markdown}
34631 % \begin{macrocode}
34632 local walkable_syntax = (function(global_walkable_syntax)
34633 local local_walkable_syntax = {}
34634 for lhs, rule in pairs(global_walkable_syntax) do
34635 local_walkable_syntax[lhs] = util.table_copy(rule)
34636 end
34637 return local_walkable_syntax
34638 end)(walkable_syntax)
34639 % \end{macrocode}
34640 % \begin{markdown}
34641 %
34642 % The \luamref{reader->insert_pattern} method adds a pattern to
34643 % \luamref{walkable_syntax}`[`*left-hand side terminal symbol*`]` before,
34644 % instead of, or after a right-hand-side terminal symbol.
34645 %
34646 % \end{markdown}
34647 % \begin{macrocode}
34648 local current_extension_name = nil
34649 self.insert_pattern = function(selector, pattern, pattern_name)
34650 assert(pattern_name == nil or type(pattern_name) == "string")
34651 local _, _, lhs, pos, rhs
34652 = selector:find("^(%a+)%s+([%a%s]+%a+)%s+(%a+)$")
34653 assert(lhs ~= nil,
34654 [[Expected selector in form ]]
34655 .. [["LHS (before|after|instead of) RHS", not "]]
34656 .. selector .. [["]])
34657 assert(walkable_syntax[lhs] ~= nil,
34658 [[Rule ]] .. lhs
34659 .. [[ -> ... does not exist in markdown grammar]])
34660 assert(pos == "before" or pos == "after" or pos == "instead of",
34661 [[Expected positional specifier "before", "after", ]]
34662 .. [[or "instead of", not "]]
34663 .. pos .. [["]])
34664 local rule = walkable_syntax[lhs]
34665 local index = nil
34666 for current_index, current_rhs in ipairs(rule) do
34667 if type(current_rhs) == "string" and current_rhs == rhs then
34668 index = current_index
34669 if pos == "after" then
34670 index = index + 1
34671 end
34672 break
34673 end
34674 end
34675 assert(index ~= nil,
34676 [[Rule ]] .. lhs .. [[ -> ]] .. rhs
34677 .. [[ does not exist in markdown grammar]])
34678 local accountable_pattern
34679 if current_extension_name then
34680 accountable_pattern
34681 = {pattern, current_extension_name, pattern_name}
34682 else
34683 assert(type(pattern) == "string",
34684 [[reader->insert_pattern() was called outside ]]
34685 .. [[an extension with ]]
34686 .. [[a PEG pattern instead of a rule name]])
34687 accountable_pattern = pattern
34688 end
34689 if pos == "instead of" then
34690 rule[index] = accountable_pattern
34691 else
34692 table.insert(rule, index, accountable_pattern)
34693 end
34694 -- TODO: Remove all occurrences of `pattern` after `index`
34695 -- to improve speed?
34696 end
34697 if options.htmlOverLinks then
34698 self.insert_pattern("Inline before AutoLinkUrl", "InlineHtml")
34699 end
34700 % \end{macrocode}
34701 % \begin{markdown}
34702 %
34703 % Create a local \luamdef{syntax} hash table that stores those rules of the
34704 % PEG grammar of markdown that can't be represented as an ordered choice
34705 % of terminal symbols.
34706 %
34707 % \end{markdown}
34708 % \begin{macrocode}
34709 local syntax =
34710 { "Blocks",
34711
34712 Blocks = V("InitializeState")
34713 * V("ExpectedJekyllData")
34714 * V("Blank")^0
34715 % \end{macrocode}
34716 % \begin{markdown}
34717 %
34718 % Only create interblock separators between pairs of blocks that are not
34719 % both paragraphs. Between a pair of paragraphs, any number of blank
34720 % lines will always produce a paragraph separator.
34721 %
34722 % \end{markdown}
34723 % \begin{macrocode}
34724 * ( V("Block")
34725 * ( V("Blank")^0 * parsers.eof
34726 + ( V("Blank")^2 / writer.paragraphsep
34727 + V("Blank")^0 / writer.interblocksep
34728 )
34729 )
34730 + ( V("Paragraph") + V("Plain") )
34731 * ( V("Blank")^0 * parsers.eof
34732 + ( V("Blank")^2 / writer.paragraphsep
34733 + V("Blank")^0 / writer.interblocksep
34734 )
34735 )
34736 * V("Block")
34737 * ( V("Blank")^0 * parsers.eof
34738 + ( V("Blank")^2 / writer.paragraphsep
34739 + V("Blank")^0 / writer.interblocksep
34740 )
34741 )
34742 + ( V("Paragraph") + V("Plain") )
34743 * ( V("Blank")^0 * parsers.eof
34744 + V("Blank")^0 / writer.paragraphsep
34745 )
34746 )^0,
34747
34748 ExpectedJekyllData = parsers.succeed,
34749
34750 Blank = parsers.Blank,
34751 Reference = parsers.Reference,
34752
34753 Blockquote = parsers.Blockquote,
34754 Verbatim = parsers.Verbatim,
34755 ThematicBreak = parsers.ThematicBreak,
34756 BulletList = parsers.BulletList,
34757 OrderedList = parsers.OrderedList,
34758 DisplayHtml = parsers.DisplayHtml,
34759 Heading = parsers.Heading,
34760 Paragraph = parsers.Paragraph,
34761 Plain = parsers.Plain,
34762
34763 ListStarter = parsers.ListStarter,
34764 EndlineExceptions = parsers.EndlineExceptions,
34765 NoSoftLineBreakEndlineExceptions
34766 = parsers.NoSoftLineBreakEndlineExceptions,
34767
34768 Str = parsers.Str,
34769 Space = parsers.Space,
34770 OptionalIndent = parsers.OptionalIndent,
34771 Endline = parsers.Endline,
34772 EndlineNoSub = parsers.EndlineNoSub,
34773 NoSoftLineBreakEndline
34774 = parsers.NoSoftLineBreakEndline,
34775 EndlineBreak = parsers.EndlineBreak,
34776 LinkAndEmph = parsers.LinkAndEmph,
34777 Code = parsers.Code,
34778 AutoLinkUrl = parsers.AutoLinkUrl,
34779 AutoLinkEmail = parsers.AutoLinkEmail,
34780 AutoLinkRelativeReference
34781 = parsers.AutoLinkRelativeReference,
34782 InlineHtml = parsers.InlineHtml,
34783 HtmlEntity = parsers.HtmlEntity,
34784 EscapedChar = parsers.EscapedChar,
34785 Smart = parsers.Smart,
34786 Symbol = parsers.Symbol,
34787 SpecialChar = parsers.fail,
34788 InitializeState = parsers.succeed,
34789 }
34790 % \end{macrocode}
34791 % \begin{markdown}
34792 %
34793 % Define \luamdef{reader->update_rule} as a function that receives two
34794 % arguments: a left-hand side terminal symbol and a function that accepts
34795 % the current PEG pattern in \luamref{walkable_syntax}`[`left-hand side
34796 % terminal symbol`]` if defined or `nil` otherwise and returns a
34797 % PEG pattern that will (re)define \luamref{walkable_syntax}`[`left-hand
34798 % side terminal symbol`]`.
34799 %
34800 % \end{markdown}
34801 % \begin{macrocode}
34802 self.update_rule = function(rule_name, get_pattern)
34803 assert(current_extension_name ~= nil)
34804 assert(syntax[rule_name] ~= nil,
34805 [[Rule ]] .. rule_name
34806 .. [[ -> ... does not exist in markdown grammar]])
34807 local previous_pattern
34808 local extension_name
34809 if walkable_syntax[rule_name] then
34810 local previous_accountable_pattern
34811 = walkable_syntax[rule_name][1]
34812 previous_pattern = previous_accountable_pattern[1]
34813 extension_name
34814 = previous_accountable_pattern[2]
34815 .. ", " .. current_extension_name
34816 else
34817 previous_pattern = nil
34818 extension_name = current_extension_name
34819 end
34820 local pattern
34821 % \end{macrocode}
34822 % \begin{markdown}
34823 %
34824 % Instead of a function, a PEG pattern `pattern` may also be
34825 % supplied with roughly the same effect as supplying the following
34826 % function, which will define \luamref{walkable_syntax}`[`left-hand
34827 % side terminal symbol`]` unless it has been previously defined.
34828 %
34829 % ``` lua
34830 % function(previous_pattern)
34831 % assert(previous_pattern == nil)
34832 % return pattern
34833 % end
34834 % ```
34835 %
34836 % \end{markdown}
34837 % \begin{macrocode}
34838 if type(get_pattern) == "function" then
34839 pattern = get_pattern(previous_pattern)
34840 else
34841 assert(previous_pattern == nil,
34842 [[Rule ]] .. rule_name ..
34843 [[ has already been updated by ]] .. extension_name)
34844 pattern = get_pattern
34845 end
34846 local accountable_pattern = { pattern, extension_name, rule_name }
34847 walkable_syntax[rule_name] = { accountable_pattern }
34848 end
34849 % \end{macrocode}
34850 % \begin{markdown}
34851 %
34852 % Define a hash table of all characters with special meaning and add method
34853 % \luamref{reader->add_special_character} that extends the hash table and
34854 % updates the PEG grammar of markdown.
34855 %
34856 % \end{markdown}
34857 % \begin{macrocode}
34858 local special_characters = {}
34859 self.add_special_character = function(c)
34860 table.insert(special_characters, c)
34861 syntax.SpecialChar = S(table.concat(special_characters, ""))
34862 end
34863
34864 self.add_special_character("*")
34865 self.add_special_character("[")
34866 self.add_special_character("]")
34867 self.add_special_character("<")
34868 self.add_special_character("!")
34869 self.add_special_character("\\")
34870 % \end{macrocode}
34871 % \begin{markdown}
34872 %
34873 % Add method \luamdef{reader->initialize_named_group} that defines named groups
34874 % with a default capture value.
34875 %
34876 % \end{markdown}
34877 % \begin{macrocode}
34878 self.initialize_named_group = function(name, value)
34879 local pattern = Ct("")
34880 if value ~= nil then
34881 pattern = pattern / value
34882 end
34883 syntax.InitializeState = syntax.InitializeState
34884 * Cg(pattern, name)
34885 end
34886 % \end{macrocode}
34887 % \begin{markdown}
34888 %
34889 % Add a named group for indentation.
34890 %
34891 % \end{markdown}
34892 % \begin{macrocode}
34893 self.initialize_named_group("indent_info")
34894 % \end{macrocode}
34895 % \begin{markdown}
34896 %
34897 % Apply syntax extensions.
34898 %
34899 % \end{markdown}
34900 % \begin{macrocode}
34901 for _, extension in ipairs(extensions) do
34902 current_extension_name = extension.name
34903 extension.extend_writer(writer)
34904 extension.extend_reader(self)
34905 end
34906 current_extension_name = nil
34907 % \end{macrocode}
34908 % \begin{markdown}
34909 %
34910 % If the \Opt{debugExtensions} option is enabled, serialize
34911 % \luamref{walkable_syntax} to a JSON for debugging purposes.
34912 %
34913 % \end{markdown}
34914 % \begin{macrocode}
34915 if options.debugExtensions then
34916 local sorted_lhs = {}
34917 for lhs, _ in pairs(walkable_syntax) do
34918 table.insert(sorted_lhs, lhs)
34919 end
34920 table.sort(sorted_lhs)
34921
34922 local output_lines = {"{"}
34923 for lhs_index, lhs in ipairs(sorted_lhs) do
34924 local encoded_lhs = util.encode_json_string(lhs)
34925 table.insert(output_lines, [[ ]] ..encoded_lhs .. [[: []])
34926 local rule = walkable_syntax[lhs]
34927 for rhs_index, rhs in ipairs(rule) do
34928 local human_readable_rhs
34929 if type(rhs) == "string" then
34930 human_readable_rhs = rhs
34931 else
34932 local pattern_name
34933 if rhs[3] then
34934 pattern_name = rhs[3]
34935 else
34936 pattern_name = "Anonymous Pattern"
34937 end
34938 local extension_name = rhs[2]
34939 human_readable_rhs = pattern_name .. [[ (]]
34940 .. extension_name .. [[)]]
34941 end
34942 local encoded_rhs
34943 = util.encode_json_string(human_readable_rhs)
34944 local output_line = [[ ]] .. encoded_rhs
34945 if rhs_index < #rule then
34946 output_line = output_line .. ","
34947 end
34948 table.insert(output_lines, output_line)
34949 end
34950 local output_line = " ]"
34951 if lhs_index < #sorted_lhs then
34952 output_line = output_line .. ","
34953 end
34954 table.insert(output_lines, output_line)
34955 end
34956 table.insert(output_lines, "}")
34957
34958 local output = table.concat(output_lines, "\n")
34959 local output_filename = options.debugExtensionsFileName
34960 local output_file = assert(io.open(output_filename, "w"),
34961 [[Could not open file "]] .. output_filename
34962 .. [[" for writing]])
34963 assert(output_file:write(output))
34964 assert(output_file:close())
34965 end
34966 % \end{macrocode}
34967 % \begin{markdown}
34968 %
34969 % Materialize \luamref{walkable_syntax} and merge it into \luamref{syntax} to
34970 % produce the complete PEG grammar of markdown. Whenever a rule exists
34971 % in both \luamref{walkable_syntax} and \luamref{syntax}, the rule from
34972 % \luamref{walkable_syntax} overrides the rule from \luamref{syntax}.
34973 %
34974 % \end{markdown}
34975 % \begin{macrocode}
34976 for lhs, rule in pairs(walkable_syntax) do
34977 syntax[lhs] = parsers.fail
34978 for _, rhs in ipairs(rule) do
34979 local pattern
34980 % \end{macrocode}
34981 % \begin{markdown}
34982 %
34983 % Although the interface of the \luamref{reader->insert_pattern} method does
34984 % not document this (see Section <#sec:lua-user-extensions>), we allow the
34985 % \luamref{reader->insert_pattern} and \luamref{reader->update_rule}
34986 % methods to insert not just PEG patterns, but also rule names that
34987 % reference the PEG grammar of Markdown.
34988 %
34989 % \end{markdown}
34990 % \begin{macrocode}
34991 if type(rhs) == "string" then
34992 pattern = V(rhs)
34993 else
34994 pattern = rhs[1]
34995 if type(pattern) == "string" then
34996 pattern = V(pattern)
34997 end
34998 end
34999 syntax[lhs] = syntax[lhs] + pattern
35000 end
35001 end
35002 % \end{macrocode}
35003 % \begin{markdown}
35004 %
35005 % Finalize the parser by reacting to options and by producing special parsers
35006 % for difficult edge cases such as blocks nested in definition lists or
35007 % inline content nested in link, note, and image labels.
35008 %
35009 % \end{markdown}
35010 % \begin{macrocode}
35011 if options.underscores then
35012 self.add_special_character("_")
35013 end
35014
35015 if not options.codeSpans then
35016 syntax.Code = parsers.fail
35017 else
35018 self.add_special_character("`")
35019 end
35020
35021 if not options.html then
35022 syntax.DisplayHtml = parsers.fail
35023 syntax.InlineHtml = parsers.fail
35024 syntax.HtmlEntity = parsers.fail
35025 else
35026 self.add_special_character("&")
35027 end
35028
35029 if options.preserveTabs then
35030 options.stripIndent = false
35031 end
35032
35033 if not options.smartEllipses then
35034 syntax.Smart = parsers.fail
35035 else
35036 self.add_special_character(".")
35037 end
35038
35039 if not options.relativeReferences then
35040 syntax.AutoLinkRelativeReference = parsers.fail
35041 end
35042
35043 if options.contentLevel == "inline" then
35044 syntax[1] = "Inlines"
35045 syntax.Inlines = V("InitializeState")
35046 * parsers.Inline^0
35047 * ( parsers.spacing^0
35048 * parsers.eof / "")
35049 syntax.Space = parsers.Space + parsers.blankline / writer.space
35050 end
35051
35052 local blocks_nested_t = util.table_copy(syntax)
35053 blocks_nested_t.ExpectedJekyllData = parsers.succeed
35054 parsers.blocks_nested = Ct(blocks_nested_t)
35055
35056 parsers.blocks = Ct(syntax)
35057
35058 local inlines_t = util.table_copy(syntax)
35059 inlines_t[1] = "Inlines"
35060 inlines_t.Inlines = V("InitializeState")
35061 * parsers.Inline^0
35062 * ( parsers.spacing^0
35063 * parsers.eof / "")
35064 parsers.inlines = Ct(inlines_t)
35065
35066 local inlines_no_inline_note_t = util.table_copy(inlines_t)
35067 inlines_no_inline_note_t.InlineNote = parsers.fail
35068 parsers.inlines_no_inline_note = Ct(inlines_no_inline_note_t)
35069
35070 local inlines_no_html_t = util.table_copy(inlines_t)
35071 inlines_no_html_t.DisplayHtml = parsers.fail
35072 inlines_no_html_t.InlineHtml = parsers.fail
35073 inlines_no_html_t.HtmlEntity = parsers.fail
35074 parsers.inlines_no_html = Ct(inlines_no_html_t)
35075
35076 local inlines_nbsp_t = util.table_copy(inlines_t)
35077 inlines_nbsp_t.Endline = parsers.NonbreakingEndline
35078 inlines_nbsp_t.Space = parsers.NonbreakingSpace
35079 parsers.inlines_nbsp = Ct(inlines_nbsp_t)
35080
35081 local inlines_identity_t = util.table_copy(inlines_t)
35082 inlines_identity_t.Str = parsers.any / function(s) return s end
35083 parsers.inlines_identity = Ct(inlines_identity_t)
35084
35085 local inlines_string_t = util.table_copy(inlines_t)
35086 inlines_string_t.Str = parsers.any / writer.string
35087 parsers.inlines_string = Ct(inlines_string_t)
35088
35089 local inlines_math_t = util.table_copy(inlines_t)
35090 inlines_math_t.Str = parsers.any / writer.math
35091 parsers.inlines_math = Ct(inlines_math_t)
35092
35093 local inlines_no_link_or_emphasis_t = util.table_copy(inlines_t)
35094 inlines_no_link_or_emphasis_t.LinkAndEmph = parsers.fail
35095 inlines_no_link_or_emphasis_t.EndlineExceptions
35096 = parsers.EndlineExceptions - parsers.eof
35097 parsers.inlines_no_link_or_emphasis
35098 = Ct(inlines_no_link_or_emphasis_t)
35099 % \end{macrocode}
35100 % \begin{markdown}
35101 %
35102 % Return a function that converts markdown string `input` into a plain \TeX{}
35103 % output and returns it..
35104 %
35105 % \end{markdown}
35106 % \begin{macrocode}
35107 return function(input)
35108 % \end{macrocode}
35109 % \begin{markdown}
35110 %
35111 % Normalize the input.
35112 %
35113 % \end{markdown}
35114 % \begin{macrocode}
35115 if options.unicodeNormalization then
35116 local form = options.unicodeNormalizationForm
35117 input = util.normalize(input, form)
35118 end
35119 % \end{macrocode}
35120 % \begin{markdown}
35121 % Since the Lua converter expects UNIX line endings, normalize the
35122 % input. Also add a line ending at the end of the file in case the input file
35123 % has none.
35124 % \end{markdown}
35125 % \begin{macrocode}
35126 input = input:gsub("\r\n?", "\n")
35127 if input:sub(-1) ~= "\n" then
35128 input = input .. "\n"
35129 end
35130 % \end{macrocode}
35131 % \begin{markdown}
35132 % Clear the table of references.
35133 % \end{markdown}
35134 % \begin{macrocode}
35135 references = {}
35136 local document = self.parser_functions.parse_blocks(input)
35137 local output = util.rope_to_string(writer.document(document))
35138 % \end{macrocode}
35139 % \begin{markdown}
35140 % Remove block element / paragraph separators immediately followed by the
35141 % output of \luamref{writer->undosep}, possibly interleaved by section ends.
35142 % Then, remove any leftover output of \luamref{writer->undosep}.
35143 % \end{markdown}
35144 % \begin{macrocode}
35145 local undosep_start, undosep_end
35146 local potential_secend_start, secend_start
35147 local potential_sep_start, sep_start
35148 while true do
35149 -- find a `writer->undosep`
35150 undosep_start, undosep_end
35151 = output:find(writer.undosep_text, 1, true)
35152 if undosep_start == nil then break end
35153 -- skip any preceding section ends
35154 secend_start = undosep_start
35155 while true do
35156 potential_secend_start = secend_start - #writer.secend_text
35157 if potential_secend_start < 1
35158 or output:sub(potential_secend_start,
35159 secend_start - 1) ~= writer.secend_text
35160 then
35161 break
35162 end
35163 secend_start = potential_secend_start
35164 end
35165 -- find an immediately preceding
35166 -- block element / paragraph separator
35167 sep_start = secend_start
35168 potential_sep_start = sep_start - #writer.interblocksep_text
35169 if potential_sep_start >= 1
35170 and output:sub(potential_sep_start,
35171 sep_start - 1) == writer.interblocksep_text
35172 then
35173 sep_start = potential_sep_start
35174 else
35175 potential_sep_start = sep_start - #writer.paragraphsep_text
35176 if potential_sep_start >= 1
35177 and output:sub(potential_sep_start,
35178 sep_start - 1) == writer.paragraphsep_text
35179 then
35180 sep_start = potential_sep_start
35181 end
35182 end
35183 -- remove `writer->undosep` and immediately preceding
35184 -- block element / paragraph separator
35185 output = output:sub(1, sep_start - 1)
35186 .. output:sub(secend_start, undosep_start - 1)
35187 .. output:sub(undosep_end + 1)
35188 end
35189 return output
35190 end
35191 end
35192 return self
35193 end
35194 % \end{macrocode}
35195 % \begin{markdown}
35196 %
35197 %### Built-In Syntax Extensions {#lua-built-in-extensions}
35198 %
35199 % Create \luamref{extensions} hash table that contains built-in syntax
35200 % extensions. Syntax extensions are functions that produce objects with two
35201 % methods: `extend_writer` and `extend_reader`. The `extend_writer` object
35202 % takes a \luamref{writer} object as the only parameter and mutates it.
35203 % Similarly, `extend_reader` takes a \luamref{reader} object as the only
35204 % parameter and mutates it.
35205 %
35206 % \end{markdown}
35207 % \begin{macrocode}
35208 M.extensions = {}
35209 % \end{macrocode}
35210 % \begin{markdown}
35211 %
35212 %#### Acronyms
35213 %
35214 % The \luamdef{extensions.acronyms} function recognizes acronyms, initialisms,
35215 % and other all-caps sequences in markdown text.
35216 %
35217 % \end{markdown}
35218 % \begin{macrocode}
35219 M.extensions.acronyms = function(acronyms)
35220 assert(#acronyms > 0)
35221 return {
35222 name = "built-in acronyms syntax extension",
35223 extend_writer = function(self)
35224 % \end{macrocode}
35225 % \begin{markdown}
35226 %
35227 % Define \luamdef{writer->acronym} as a function that will transform an input
35228 % acronym, initialism, or another all-caps sequence to the output format.
35229 %
35230 % \end{markdown}
35231 % \begin{macrocode}
35232 function self.acronym(s)
35233 if self.flatten_inlines then return s end
35234 return {"\\markdownRendererAcronym{",s,"}"}
35235 end
35236 end, extend_reader = function(self)
35237 local parsers = self.parsers
35238 local options = self.options
35239 local writer = self.writer
35240 % \end{macrocode}
35241 % \begin{markdown}
35242 %
35243 % In order to minimize the size and speed of the parser, we will first
35244 % construct prefix trees of all registered acronyms, initialisms, and other
35245 % all-caps sequences.
35246 %
35247 % \end{markdown}
35248 % \begin{macrocode}
35249 local prefix_tree = {_type = "intermediate"}
35250 for _, acronym in ipairs(acronyms) do
35251 local node = prefix_tree
35252 % \end{macrocode}
35253 % \begin{markdown}
35254 %
35255 % Normalize each acronym, initialism, or another all-caps sequence.
35256 %
35257 % \end{markdown}
35258 % \begin{macrocode}
35259 if options.unicodeNormalization then
35260 local form = options.unicodeNormalizationForm
35261 acronym = util.normalize(acronym, form)
35262 end
35263 for i = 1, #acronym do
35264 local acronym_byte = acronym:sub(i, i)
35265 if i < #acronym then
35266 if node[acronym_byte] == nil then
35267 node[acronym_byte] = {_type = "intermediate"}
35268 end
35269 node = node[acronym_byte]
35270 else
35271 table.insert(node, {acronym_byte, _type = "leaf"})
35272 end
35273 end
35274 end
35275 % \end{macrocode}
35276 % \begin{markdown}
35277 %
35278 % Next, we will construct a parser out of the prefix tree.
35279 %
35280 % \end{markdown}
35281 % \begin{macrocode}
35282 local subparsers = {}
35283 depth_first_search(prefix_tree, "", function(node, path)
35284 if node._type == "leaf" then
35285 local acronym_byte = table.unpack(node)
35286 if subparsers[path] == nil then
35287 subparsers[path] = parsers.fail
35288 end
35289 subparsers[path] = subparsers[path] + P(acronym_byte)
35290 end
35291 end, function(_, path)
35292 if #path > 0 then
35293 local byte = path:sub(#path, #path)
35294 local parent_path = path:sub(1, #path-1)
35295 local prefix = P(byte)
35296 local suffix = prefix * subparsers[path]
35297 if subparsers[parent_path] == nil then
35298 subparsers[parent_path] = parsers.fail
35299 end
35300 subparsers[parent_path] = subparsers[parent_path] + suffix
35301 end
35302 end)
35303 assert(subparsers[""] ~= nil)
35304 % \end{macrocode}
35305 % \begin{markdown}
35306 %
35307 % Only match acronyms at word boundaries.
35308 %
35309 % \end{markdown}
35310 % \begin{macrocode}
35311 local Acronym = ( parsers.unicode.punctuation
35312 - V("SpecialChar")
35313 + parsers.unicode.whitespace
35314 - V("EndlineExceptions"))^0
35315 / writer.string
35316 * (
35317 subparsers[""]
35318 * #(-parsers.normalchar
35319 + parsers.unicode.punctuation
35320 + parsers.unicode.whitespace
35321 + parsers.eof)
35322 / writer.acronym)
35323 self.insert_pattern("Inline before Str", Acronym, "Acronym")
35324 end
35325 }
35326 end
35327 %
35328 %#### Bracketed Spans
35329 %
35330 % The \luamdef{extensions.bracketed_spans} function implements the Pandoc
35331 % bracketed span syntax extension.
35332 %
35333 % \end{markdown}
35334 % \begin{macrocode}
35335 M.extensions.bracketed_spans = function()
35336 return {
35337 name = "built-in bracketed_spans syntax extension",
35338 extend_writer = function(self)
35339 % \end{macrocode}
35340 % \begin{markdown}
35341 %
35342 % Define \luamdef{writer->span} as a function that will transform an input
35343 % bracketed span `s` with attributes `attr` to the output format.
35344 %
35345 % \end{markdown}
35346 % \begin{macrocode}
35347 function self.span(s, attr)
35348 if self.flatten_inlines then return s end
35349 return {"\\markdownRendererBracketedSpanAttributeContextBegin",
35350 self.attributes(attr),
35351 "\\markdownRendererBracketedSpan{",s,"}",
35352 "\\markdownRendererBracketedSpanAttributeContextEnd{}"}
35353 end
35354 end, extend_reader = function(self)
35355 local parsers = self.parsers
35356 local writer = self.writer
35357
35358 local span_label = parsers.lbracket
35359 * (Cs((parsers.alphanumeric^1
35360 + parsers.inticks
35361 + parsers.autolink
35362 + V("InlineHtml")
35363 + ( parsers.backslash * parsers.backslash)
35364 + ( parsers.backslash
35365 * (parsers.lbracket + parsers.rbracket)
35366 + V("Space") + V("Endline")
35367 + (parsers.any
35368 - ( parsers.newline
35369 + parsers.lbracket
35370 + parsers.rbracket
35371 + parsers.blankline^2))))^1)
35372 / self.parser_functions.parse_inlines)
35373 * parsers.rbracket
35374
35375 local Span = span_label
35376 * Ct(parsers.attributes)
35377 / writer.span
35378
35379 self.insert_pattern("Inline before LinkAndEmph",
35380 Span, "Span")
35381 end
35382 }
35383 end
35384 % \end{macrocode}
35385 % \begin{markdown}
35386 %
35387 %#### Citations
35388 %
35389 % The \luamdef{extensions.citations} function implements the Pandoc citation
35390 % syntax extension. When the `citation_nbsps` parameter is enabled, the syntax
35391 % extension will replace regular spaces with non-breaking spaces inside the
35392 % prenotes and postnotes of citations.
35393 %
35394 % \end{markdown}
35395 % \begin{macrocode}
35396 M.extensions.citations = function(citation_nbsps)
35397 return {
35398 name = "built-in citations syntax extension",
35399 extend_writer = function(self)
35400 % \end{macrocode}
35401 % \begin{markdown}
35402 %
35403 % Define \luamdef{writer->citations} as a function that will transform an
35404 % input array of citations `cites` to the output format. If `text_cites`
35405 % is enabled, the citations should be rendered in-text, when applicable.
35406 % The `cites` array contains tables with the following keys and values:
35407 % \begin{itemize}
35408 % \item`suppress_author` -- If the value of the key is true, then the
35409 % author of the work should be omitted in the citation, when applicable.
35410 % \item`prenote` -- The value of the key is either `nil` or a rope
35411 % that should be inserted before the citation.
35412 % \item`postnote` -- The value of the key is either `nil` or a rope
35413 % that should be inserted after the citation.
35414 % \item`name` -- The value of this key is the citation name.
35415 % \end{itemize}
35416 %
35417 % \end{markdown}
35418 % \begin{macrocode}
35419 function self.citations(text_cites, cites)
35420 local buffer = {}
35421 if self.flatten_inlines then
35422 for _,cite in ipairs(cites) do
35423 if cite.prenote then
35424 table.insert(buffer, {cite.prenote, " "})
35425 end
35426 table.insert(buffer, cite.name)
35427 if cite.postnote then
35428 table.insert(buffer, {" ", cite.postnote})
35429 end
35430 end
35431 else
35432 table.insert(buffer,
35433 {"\\markdownRenderer",
35434 text_cites and "TextCite" or "Cite",
35435 "{", #cites, "}"})
35436 for _,cite in ipairs(cites) do
35437 table.insert(buffer,
35438 {cite.suppress_author and "-" or "+", "{",
35439 cite.prenote or "", "}{",
35440 cite.postnote or "", "}{", cite.name, "}"})
35441 end
35442 end
35443 return buffer
35444 end
35445 end, extend_reader = function(self)
35446 local parsers = self.parsers
35447 local writer = self.writer
35448
35449 local citation_chars
35450 = parsers.alphanumeric
35451 + S("#$%&-+<>~/_")
35452
35453 local citation_name
35454 = Cs(parsers.dash^-1) * parsers.at
35455 * Cs(citation_chars
35456 * ((( citation_chars
35457 + parsers.internal_punctuation
35458 - parsers.comma - parsers.semicolon)
35459 * -#(( parsers.internal_punctuation
35460 - parsers.comma
35461 - parsers.semicolon)^0
35462 * -( citation_chars
35463 + parsers.internal_punctuation
35464 - parsers.comma
35465 - parsers.semicolon)))^0
35466 * citation_chars)^-1)
35467
35468 local citation_body_prenote
35469 = Cs((parsers.alphanumeric^1
35470 + parsers.bracketed
35471 + parsers.inticks
35472 + parsers.autolink
35473 + V("InlineHtml")
35474 + V("Space") + V("EndlineNoSub")
35475 + (parsers.anyescaped
35476 - ( parsers.newline
35477 + parsers.rbracket
35478 + parsers.blankline^2))
35479 - ( parsers.spnl
35480 * parsers.dash^-1
35481 * parsers.at))^1)
35482
35483 local citation_body_postnote
35484 = Cs((parsers.alphanumeric^1
35485 + parsers.bracketed
35486 + parsers.inticks
35487 + parsers.autolink
35488 + V("InlineHtml")
35489 + V("Space") + V("EndlineNoSub")
35490 + (parsers.anyescaped
35491 - ( parsers.newline
35492 + parsers.rbracket
35493 + parsers.semicolon
35494 + parsers.blankline^2))
35495 - (parsers.spnl * parsers.rbracket))^1)
35496
35497 local citation_body_chunk
35498 = ( citation_body_prenote
35499 * parsers.spnlc_sep
35500 + Cc("")
35501 * parsers.spnlc
35502 )
35503 * citation_name
35504 * ( parsers.internal_punctuation
35505 - parsers.semicolon)^-1
35506 * ( parsers.spnlc / function(_) return end
35507 * citation_body_postnote
35508 + Cc("")
35509 * parsers.spnlc
35510 )
35511
35512 local citation_body
35513 = citation_body_chunk
35514 * ( parsers.semicolon
35515 * parsers.spnlc
35516 * citation_body_chunk
35517 )^0
35518
35519 local citation_headless_body_postnote
35520 = Cs((parsers.alphanumeric^1
35521 + parsers.bracketed
35522 + parsers.inticks
35523 + parsers.autolink
35524 + V("InlineHtml")
35525 + V("Space") + V("Endline")
35526 + (parsers.anyescaped
35527 - ( parsers.newline
35528 + parsers.rbracket
35529 + parsers.at
35530 + parsers.semicolon + parsers.blankline^2))
35531 - (parsers.spnl * parsers.rbracket))^0)
35532
35533 local citation_headless_body
35534 = citation_headless_body_postnote
35535 * ( parsers.semicolon
35536 * parsers.spnlc
35537 * citation_body_chunk
35538 )^0
35539
35540 local citations
35541 = function(text_cites, raw_cites)
35542 local function normalize(str)
35543 if str == "" then
35544 str = nil
35545 else
35546 str = (citation_nbsps and
35547 self.parser_functions.parse_inlines_nbsp or
35548 self.parser_functions.parse_inlines)(str)
35549 end
35550 return str
35551 end
35552
35553 local cites = {}
35554 for i = 1,#raw_cites,4 do
35555 cites[#cites+1] = {
35556 prenote = normalize(raw_cites[i]),
35557 suppress_author = raw_cites[i+1] == "-",
35558 name = writer.identifier(raw_cites[i+2]),
35559 postnote = normalize(raw_cites[i+3]),
35560 }
35561 end
35562 return writer.citations(text_cites, cites)
35563 end
35564
35565 local TextCitations
35566 = Ct((parsers.spnlc
35567 * Cc("")
35568 * citation_name
35569 * ((parsers.spnlc
35570 * parsers.lbracket
35571 * citation_headless_body
35572 * parsers.rbracket) + Cc("")))^1)
35573 / function(raw_cites)
35574 return citations(true, raw_cites)
35575 end
35576
35577 local ParenthesizedCitations
35578 = Ct((parsers.spnlc
35579 * parsers.lbracket
35580 * citation_body
35581 * parsers.rbracket)^1)
35582 / function(raw_cites)
35583 return citations(false, raw_cites)
35584 end
35585
35586 local Citations = TextCitations + ParenthesizedCitations
35587
35588 self.insert_pattern("Inline before LinkAndEmph",
35589 Citations, "Citations")
35590
35591 self.add_special_character("@")
35592 self.add_special_character("-")
35593 end
35594 }
35595 end
35596 % \end{macrocode}
35597 % \begin{markdown}
35598 %
35599 %#### Content Blocks
35600 %
35601 % The \luamdef{extensions.content_blocks} function implements the iA\\,Writer
35602 % content blocks syntax extension. The `language_map` parameter specifies
35603 % the filename of the JSON file that maps filename extensions to
35604 % programming language names.
35605 %
35606 % \end{markdown}
35607 % \begin{macrocode}
35608 M.extensions.content_blocks = function(language_map)
35609 % \end{macrocode}
35610 % \begin{markdown}
35611 %
35612 % The \luamdef{languages_json} table maps programming language filename
35613 % extensions to fence infostrings. All `language_map` files located by the
35614 % \pkg{kpathsea} library are loaded into a chain of tables.
35615 % \luamref{languages_json} corresponds to the first table and is chained with
35616 % the rest via Lua metatables.
35617 %
35618 % \end{markdown}
35619 % \begin{macrocode}
35620 local languages_json = (function()
35621 local base, prev, curr
35622 for _, pathname in ipairs(util.find_files(language_map)) do
35623 local file = io.open(pathname, "r")
35624 if not file then goto continue end
35625 local input = assert(file:read("*a"))
35626 assert(file:close())
35627 local json = input:gsub('("[^\n]-"):','[%1]=')
35628 curr = load("_ENV = {}; return "..json)()
35629 if type(curr) == "table" then
35630 if base == nil then
35631 base = curr
35632 else
35633 setmetatable(prev, { __index = curr })
35634 end
35635 prev = curr
35636 end
35637 ::continue::
35638 end
35639 return base or {}
35640 end)()
35641
35642 return {
35643 name = "built-in content_blocks syntax extension",
35644 extend_writer = function(self)
35645 % \end{macrocode}
35646 % \begin{markdown}
35647 %
35648 % Define \luamdef{writer->contentblock} as a function that will transform an
35649 % input iA\\,Writer content block to the output format, where `src`
35650 % corresponds to the URI prefix, `suf` to the URI extension,
35651 % `type` to the type of the content block (`localfile` or `onlineimage`),
35652 % and `tit` to the title of the content block.
35653 %
35654 % \end{markdown}
35655 % \begin{macrocode}
35656 function self.contentblock(src,suf,type,tit)
35657 if not self.is_writing then return "" end
35658 src = src.."."..suf
35659 suf = suf:lower()
35660 if type == "onlineimage" then
35661 return {"\\markdownRendererContentBlockOnlineImage{",suf,"}",
35662 "{",self.string(src),"}",
35663 "{",self.uri(src),"}",
35664 "{",self.string(tit or ""),"}"}
35665 elseif languages_json[suf] then
35666 return {"\\markdownRendererContentBlockCode{",suf,"}",
35667 "{",self.string(languages_json[suf]),"}",
35668 "{",self.string(src),"}",
35669 "{",self.uri(src),"}",
35670 "{",self.string(tit or ""),"}"}
35671 else
35672 return {"\\markdownRendererContentBlock{",suf,"}",
35673 "{",self.string(src),"}",
35674 "{",self.uri(src),"}",
35675 "{",self.string(tit or ""),"}"}
35676 end
35677 end
35678 end, extend_reader = function(self)
35679 local parsers = self.parsers
35680 local writer = self.writer
35681
35682 local contentblock_tail
35683 = parsers.optionaltitle
35684 * (parsers.newline + parsers.eof)
35685
35686 -- case insensitive online image suffix:
35687 local onlineimagesuffix
35688 = (function(...)
35689 local parser = nil
35690 for _, suffix in ipairs({...}) do
35691 local pattern=nil
35692 for i=1,#suffix do
35693 local char=suffix:sub(i,i)
35694 char = S(char:lower()..char:upper())
35695 if pattern == nil then
35696 pattern = char
35697 else
35698 pattern = pattern * char
35699 end
35700 end
35701 if parser == nil then
35702 parser = pattern
35703 else
35704 parser = parser + pattern
35705 end
35706 end
35707 return parser
35708 end)("png", "jpg", "jpeg", "gif", "tif", "tiff")
35709
35710 -- online image url for iA Writer content blocks with
35711 -- mandatory suffix, allowing nested brackets:
35712 local onlineimageurl
35713 = (parsers.less
35714 * Cs((parsers.anyescaped
35715 - parsers.more
35716 - parsers.spacing
35717 - #(parsers.period
35718 * onlineimagesuffix
35719 * parsers.more
35720 * contentblock_tail))^0)
35721 * parsers.period
35722 * Cs(onlineimagesuffix)
35723 * parsers.more
35724 + (Cs((parsers.inparens
35725 + (parsers.anyescaped
35726 - parsers.spacing
35727 - parsers.rparent
35728 - #(parsers.period
35729 * onlineimagesuffix
35730 * contentblock_tail)))^0)
35731 * parsers.period
35732 * Cs(onlineimagesuffix))
35733 ) * Cc("onlineimage")
35734
35735 -- filename for iA Writer content blocks with mandatory suffix:
35736 local localfilepath
35737 = parsers.slash
35738 * Cs((parsers.anyescaped
35739 - parsers.tab
35740 - parsers.newline
35741 - #(parsers.period
35742 * parsers.alphanumeric^1
35743 * contentblock_tail))^1)
35744 * parsers.period
35745 * Cs(parsers.alphanumeric^1)
35746 * Cc("localfile")
35747
35748 local ContentBlock
35749 = parsers.check_trail_no_rem
35750 * (localfilepath + onlineimageurl)
35751 * contentblock_tail
35752 / writer.contentblock
35753
35754 self.insert_pattern("Block before Blockquote",
35755 ContentBlock, "ContentBlock")
35756 end
35757 }
35758 end
35759 % \end{macrocode}
35760 % \begin{markdown}
35761 %
35762 %#### Definition Lists
35763 %
35764 % The \luamdef{extensions.definition_lists} function implements the Pandoc
35765 % definition list syntax extension. If the `tight_lists` parameter is `true`,
35766 % tight lists will produce special right item renderers.
35767 %
35768 % \end{markdown}
35769 % \begin{macrocode}
35770 M.extensions.definition_lists = function(tight_lists)
35771 return {
35772 name = "built-in definition_lists syntax extension",
35773 extend_writer = function(self)
35774 % \end{macrocode}
35775 % \begin{markdown}
35776 %
35777 % Define \luamdef{writer->definitionlist} as a function that will transform an
35778 % input definition list to the output format, where `items` is an array of
35779 % tables, each of the form `{ term = t, definitions = defs }`, where `t`
35780 % is a term and `defs` is an array of definitions. `tight` specifies,
35781 % whether the list is tight or not.
35782 %
35783 % \end{markdown}
35784 % \begin{macrocode}
35785 local function dlitem(term, defs)
35786 local retVal = {"\\markdownRendererDlItem{",term,"}"}
35787 for _, def in ipairs(defs) do
35788 retVal[#retVal+1]
35789 = {"\\markdownRendererDlDefinitionBegin ",def,
35790 "\\markdownRendererDlDefinitionEnd "}
35791 end
35792 retVal[#retVal+1] = "\\markdownRendererDlItemEnd "
35793 return retVal
35794 end
35795
35796 function self.definitionlist(items,tight)
35797 if not self.is_writing then return "" end
35798 local buffer = {}
35799 for _,item in ipairs(items) do
35800 buffer[#buffer + 1] = dlitem(item.term, item.definitions)
35801 end
35802 if tight and tight_lists then
35803 return {"\\markdownRendererDlBeginTight\n", buffer,
35804 "\n\\markdownRendererDlEndTight"}
35805 else
35806 return {"\\markdownRendererDlBegin\n", buffer,
35807 "\n\\markdownRendererDlEnd"}
35808 end
35809 end
35810 end, extend_reader = function(self)
35811 local parsers = self.parsers
35812 local writer = self.writer
35813
35814 local defstartchar = S("~:")
35815
35816 local defstart
35817 = parsers.check_trail_length(0) * defstartchar
35818 * #parsers.spacing
35819 * (parsers.tab + parsers.space^-3)
35820 + parsers.check_trail_length(1)
35821 * defstartchar * #parsers.spacing
35822 * (parsers.tab + parsers.space^-2)
35823 + parsers.check_trail_length(2)
35824 * defstartchar * #parsers.spacing
35825 * (parsers.tab + parsers.space^-1)
35826 + parsers.check_trail_length(3)
35827 * defstartchar * #parsers.spacing
35828
35829 local indented_line
35830 = (parsers.check_minimal_indent / "")
35831 * parsers.check_code_trail * parsers.line
35832
35833 local blank
35834 = parsers.check_minimal_blank_indent_and_any_trail
35835 * parsers.optionalspace * parsers.newline
35836
35837 local dlchunk = Cs(parsers.line * (indented_line - blank)^0)
35838
35839 local indented_blocks = function(bl)
35840 return Cs( bl
35841 * (blank^1 * (parsers.check_minimal_indent / "")
35842 * parsers.check_code_trail * -parsers.blankline * bl)^0
35843 * (blank^1 + parsers.eof))
35844 end
35845
35846 local function definition_list_item(term, defs, _)
35847 return { term = self.parser_functions.parse_inlines(term),
35848 definitions = defs }
35849 end
35850
35851 local DefinitionListItemLoose
35852 = C(parsers.line) * blank^0
35853 * Ct((parsers.check_minimal_indent * (defstart
35854 * indented_blocks(dlchunk)
35855 / self.parser_functions.parse_blocks_nested))^1)
35856 * Cc(false) / definition_list_item
35857
35858 local DefinitionListItemTight
35859 = C(parsers.line)
35860 * Ct((parsers.check_minimal_indent * (defstart * dlchunk
35861 / self.parser_functions.parse_blocks_nested))^1)
35862 * Cc(true) / definition_list_item
35863
35864 local DefinitionList
35865 = ( Ct(DefinitionListItemLoose^1) * Cc(false)
35866 + Ct(DefinitionListItemTight^1)
35867 * (blank^0
35868 * -DefinitionListItemLoose * Cc(true))
35869 ) / writer.definitionlist
35870
35871 self.insert_pattern("Block after Heading",
35872 DefinitionList, "DefinitionList")
35873 end
35874 }
35875 end
35876 % \end{macrocode}
35877 % \begin{markdown}
35878 %
35879 %#### Fancy Lists
35880 %
35881 % The \luamdef{extensions.fancy_lists} function implements the Pandoc fancy
35882 % list syntax extension.
35883 %
35884 % \end{markdown}
35885 % \begin{macrocode}
35886 M.extensions.fancy_lists = function()
35887 return {
35888 name = "built-in fancy_lists syntax extension",
35889 extend_writer = function(self)
35890 local options = self.options
35891
35892 % \end{macrocode}
35893 % \begin{markdown}
35894 %
35895 % Define \luamdef{writer->fancylist} as a function that will transform an
35896 % input ordered list to the output format, where:
35897 %
35898 %- `items` is an array of the list items,
35899 %- `tight` specifies, whether the list is tight or not,
35900 %- `startnum` is the number of the first list item,
35901 %- `numstyle` is the style of the list item labels from among the following:
35902 % - `Decimal` -- decimal arabic numbers,
35903 % - `LowerRoman` -- lower roman numbers,
35904 % - `UpperRoman` -- upper roman numbers,
35905 % - `LowerAlpha` -- lower ASCII alphabetic characters, and
35906 % - `UpperAlpha` -- upper ASCII alphabetic characters, and
35907 %- `numdelim` is the style of delimiters between list item labels and
35908 % texts from among the following:
35909 % - `Default` -- default style,
35910 % - `OneParen` -- parentheses, and
35911 % - `Period` -- periods.
35912 %
35913 % \end{markdown}
35914 % \begin{macrocode}
35915 function self.fancylist(items,tight,startnum,numstyle,numdelim)
35916 if not self.is_writing then return "" end
35917 local buffer = {}
35918 local num = startnum
35919 for _,item in ipairs(items) do
35920 if item ~= "" then
35921 buffer[#buffer + 1] = self.fancyitem(item,num)
35922 end
35923 if num ~= nil and item ~= "" then
35924 num = num + 1
35925 end
35926 end
35927 local contents = util.intersperse(buffer,"\n")
35928 if tight and options.tightLists then
35929 return {"\\markdownRendererFancyOlBeginTight{",
35930 numstyle,"}{",numdelim,"}",contents,
35931 "\n\\markdownRendererFancyOlEndTight "}
35932 else
35933 return {"\\markdownRendererFancyOlBegin{",
35934 numstyle,"}{",numdelim,"}",contents,
35935 "\n\\markdownRendererFancyOlEnd "}
35936 end
35937 end
35938 % \end{macrocode}
35939 % \begin{markdown}
35940 %
35941 % Define \luamdef{writer->fancyitem} as a function that will transform an
35942 % input fancy ordered list item to the output format, where `s` is the text of
35943 % the list item. If the optional parameter `num` is present, it is the number
35944 % of the list item.
35945 %
35946 % \end{markdown}
35947 % \begin{macrocode}
35948 function self.fancyitem(s,num)
35949 if num ~= nil then
35950 return {"\\markdownRendererFancyOlItemWithNumber{",num,"}",s,
35951 "\\markdownRendererFancyOlItemEnd "}
35952 else
35953 return {"\\markdownRendererFancyOlItem ",s,
35954 "\\markdownRendererFancyOlItemEnd "}
35955 end
35956 end
35957 end, extend_reader = function(self)
35958 local parsers = self.parsers
35959 local options = self.options
35960 local writer = self.writer
35961
35962 local function combine_markers_and_delims(markers, delims)
35963 local markers_table = {}
35964 for _,marker in ipairs(markers) do
35965 local start_marker
35966 local continuation_marker
35967 if type(marker) == "table" then
35968 start_marker = marker[1]
35969 continuation_marker = marker[2]
35970 else
35971 start_marker = marker
35972 continuation_marker = marker
35973 end
35974 for _,delim in ipairs(delims) do
35975 table.insert(markers_table,
35976 {start_marker, continuation_marker, delim})
35977 end
35978 end
35979 return markers_table
35980 end
35981
35982 local function join_table_with_func(func, markers_table)
35983 local pattern = func(table.unpack(markers_table[1]))
35984 for i = 2, #markers_table do
35985 pattern = pattern + func(table.unpack(markers_table[i]))
35986 end
35987 return pattern
35988 end
35989
35990 local lowercase_letter_marker = R("az")
35991 local uppercase_letter_marker = R("AZ")
35992
35993 local roman_marker = function(chars)
35994 local m, d, c = P(chars[1]), P(chars[2]), P(chars[3])
35995 local l, x, v, i
35996 = P(chars[4]), P(chars[5]), P(chars[6]), P(chars[7])
35997 return m^-3
35998 * (c*m + c*d + d^-1 * c^-3)
35999 * (x*c + x*l + l^-1 * x^-3)
36000 * (i*x + i*v + v^-1 * i^-3)
36001 end
36002
36003 local lowercase_roman_marker
36004 = roman_marker({"m", "d", "c", "l", "x", "v", "i"})
36005 local uppercase_roman_marker
36006 = roman_marker({"M", "D", "C", "L", "X", "V", "I"})
36007
36008 local lowercase_opening_roman_marker = P("i")
36009 local uppercase_opening_roman_marker = P("I")
36010
36011 local digit_marker = parsers.dig * parsers.dig^-8
36012
36013 local markers = {
36014 {lowercase_opening_roman_marker, lowercase_roman_marker},
36015 {uppercase_opening_roman_marker, uppercase_roman_marker},
36016 lowercase_letter_marker,
36017 uppercase_letter_marker,
36018 lowercase_roman_marker,
36019 uppercase_roman_marker,
36020 digit_marker
36021 }
36022
36023 local delims = {
36024 parsers.period,
36025 parsers.rparent
36026 }
36027
36028 local markers_table = combine_markers_and_delims(markers, delims)
36029
36030 local function enumerator(start_marker, _,
36031 delimiter_type, interrupting)
36032 local delimiter_range
36033 local allowed_end
36034 if interrupting then
36035 delimiter_range = P("1")
36036 allowed_end = C(parsers.spacechar^1) * #parsers.linechar
36037 else
36038 delimiter_range = start_marker
36039 allowed_end = C(parsers.spacechar^1)
36040 + #(parsers.newline + parsers.eof)
36041 end
36042
36043 return parsers.check_trail
36044 * Ct(C(delimiter_range) * C(delimiter_type))
36045 * allowed_end
36046 end
36047
36048 local starter = join_table_with_func(enumerator, markers_table)
36049
36050 local TightListItem = function(starter)
36051 return parsers.add_indent(starter, "li")
36052 * parsers.indented_content_tight
36053 end
36054
36055 local LooseListItem = function(starter)
36056 return parsers.add_indent(starter, "li")
36057 * parsers.indented_content_loose
36058 * remove_indent("li")
36059 end
36060
36061 local function roman2number(roman)
36062 local romans = { ["M"] = 1000, ["D"] = 500, ["C"] = 100,
36063 ["L"] = 50, ["X"] = 10, ["V"] = 5, ["I"] = 1 }
36064 local numeral = 0
36065
36066 local i = 1
36067 local len = string.len(roman)
36068 while i < len do
36069 local z1, z2 = romans[ string.sub(roman, i, i) ],
36070 romans[ string.sub(roman, i+1, i+1) ]
36071 if z1 < z2 then
36072 numeral = numeral + (z2 - z1)
36073 i = i + 2
36074 else
36075 numeral = numeral + z1
36076 i = i + 1
36077 end
36078 end
36079 if i <= len then
36080 numeral = numeral + romans[ string.sub(roman,i,i) ]
36081 end
36082 return numeral
36083 end
36084
36085 local function sniffstyle(numstr, delimend)
36086 local numdelim
36087 if delimend == ")" then
36088 numdelim = "OneParen"
36089 elseif delimend == "." then
36090 numdelim = "Period"
36091 else
36092 numdelim = "Default"
36093 end
36094
36095 local num
36096 num = numstr:match("^([I])$")
36097 if num then
36098 return roman2number(num), "UpperRoman", numdelim
36099 end
36100 num = numstr:match("^([i])$")
36101 if num then
36102 return roman2number(string.upper(num)), "LowerRoman", numdelim
36103 end
36104 num = numstr:match("^([A-Z])$")
36105 if num then
36106 return string.byte(num) - string.byte("A") + 1,
36107 "UpperAlpha", numdelim
36108 end
36109 num = numstr:match("^([a-z])$")
36110 if num then
36111 return string.byte(num) - string.byte("a") + 1,
36112 "LowerAlpha", numdelim
36113 end
36114 num = numstr:match("^([IVXLCDM]+)")
36115 if num then
36116 return roman2number(num), "UpperRoman", numdelim
36117 end
36118 num = numstr:match("^([ivxlcdm]+)")
36119 if num then
36120 return roman2number(string.upper(num)), "LowerRoman", numdelim
36121 end
36122 return math.floor(tonumber(numstr) or 1), "Decimal", numdelim
36123 end
36124
36125 local function fancylist(items,tight,start)
36126 local startnum, numstyle, numdelim
36127 = sniffstyle(start[2][1], start[2][2])
36128 return writer.fancylist(items,tight,
36129 options.startNumber and startnum or 1,
36130 numstyle or "Decimal",
36131 numdelim or "Default")
36132 end
36133
36134 local FancyListOfType
36135 = function(start_marker, continuation_marker, delimiter_type)
36136 local enumerator_start
36137 = enumerator(start_marker, continuation_marker,
36138 delimiter_type)
36139 local enumerator_cont
36140 = enumerator(continuation_marker, continuation_marker,
36141 delimiter_type)
36142 return Cg(enumerator_start, "listtype")
36143 * (Ct( TightListItem(Cb("listtype"))
36144 * ((parsers.check_minimal_indent / "")
36145 * TightListItem(enumerator_cont))^0)
36146 * Cc(true)
36147 * -#((parsers.conditionally_indented_blankline^0 / "")
36148 * parsers.check_minimal_indent * enumerator_cont)
36149 + Ct( LooseListItem(Cb("listtype"))
36150 * ((parsers.conditionally_indented_blankline^0 / "")
36151 * (parsers.check_minimal_indent / "")
36152 * LooseListItem(enumerator_cont))^0)
36153 * Cc(false)
36154 ) * Ct(Cb("listtype")) / fancylist
36155 end
36156
36157 local FancyList
36158 = join_table_with_func(FancyListOfType, markers_table)
36159
36160 local ListStarter = starter
36161
36162 self.update_rule("OrderedList", FancyList)
36163 self.update_rule("ListStarter", ListStarter)
36164 end
36165 }
36166 end
36167 % \end{macrocode}
36168 % \begin{markdown}
36169 %
36170 %#### Fenced Code
36171 %
36172 % The \luamdef{extensions.fenced_code} function implements the CommonMark
36173 % fenced code block syntax extension. When the `blank_before_code_fence`
36174 % parameter is `true`, the syntax extension requires a blank line between a
36175 % paragraph and the following fenced code block.
36176 %
36177 % When the `allow_attributes` option is `true`, the syntax extension permits
36178 % attributes following the infostring. When the `allow_raw_blocks` option is
36179 % `true`, the syntax extension permits the specification of raw blocks using
36180 % the Pandoc raw attribute syntax extension.
36181 %
36182 % \end{markdown}
36183 % \begin{macrocode}
36184 M.extensions.fenced_code = function(blank_before_code_fence,
36185 allow_attributes,
36186 allow_raw_blocks)
36187 return {
36188 name = "built-in fenced_code syntax extension",
36189 extend_writer = function(self)
36190 local options = self.options
36191
36192 % \end{macrocode}
36193 % \begin{markdown}
36194 %
36195 % Define \luamdef{writer->fencedCode} as a function that will transform an
36196 % input fenced code block `s` with the infostring `i` and optional attributes
36197 % `attr` to the output format.
36198 %
36199 % \end{markdown}
36200 % \begin{macrocode}
36201 function self.fencedCode(s, i, attr)
36202 if not self.is_writing then return "" end
36203 s = s:gsub("\n$", "")
36204 local buf = {}
36205 if attr ~= nil then
36206 table.insert(buf,
36207 {"\\markdownRendererFencedCodeAttributeContextBegin",
36208 self.attributes(attr)})
36209 end
36210 local name = util.cache_verbatim(options.cacheDir, s)
36211 table.insert(buf,
36212 {"\\markdownRendererInputFencedCode{",
36213 name,"}{",self.string(i),"}{",self.infostring(i),"}"})
36214 if attr ~= nil then
36215 table.insert(buf,
36216 "\\markdownRendererFencedCodeAttributeContextEnd{}")
36217 end
36218 return buf
36219 end
36220
36221 % \end{macrocode}
36222 % \begin{markdown}
36223 %
36224 % Define \luamdef{writer->rawBlock} as a function that will transform an
36225 % input raw block `s` with the raw attribute `attr` to the output format.
36226 %
36227 % \end{markdown}
36228 % \begin{macrocode}
36229 if allow_raw_blocks then
36230 function self.rawBlock(s, attr)
36231 if not self.is_writing then return "" end
36232 s = s:gsub("\n$", "")
36233 local name = util.cache_verbatim(options.cacheDir, s)
36234 return {"\\markdownRendererInputRawBlock{",
36235 name,"}{", self.string(attr),"}"}
36236 end
36237 end
36238 end, extend_reader = function(self)
36239 local parsers = self.parsers
36240 local writer = self.writer
36241
36242 local function captures_geq_length(_,i,a,b)
36243 return #a >= #b and i
36244 end
36245
36246 local function strip_enclosing_whitespaces(str)
36247 return str:gsub("^%s*(.-)%s*$", "%1")
36248 end
36249
36250 local tilde_infostring = Cs(Cs((V("HtmlEntity")
36251 + parsers.anyescaped
36252 - parsers.newline)^0)
36253 / strip_enclosing_whitespaces)
36254
36255 local backtick_infostring
36256 = Cs( Cs((V("HtmlEntity")
36257 + ( -#(parsers.backslash * parsers.backtick)
36258 * parsers.anyescaped)
36259 - parsers.newline
36260 - parsers.backtick)^0)
36261 / strip_enclosing_whitespaces)
36262
36263 local fenceindent
36264
36265 local function has_trail(indent_table)
36266 return indent_table ~= nil and
36267 indent_table.trail ~= nil and
36268 next(indent_table.trail) ~= nil
36269 end
36270
36271 local function has_indents(indent_table)
36272 return indent_table ~= nil and
36273 indent_table.indents ~= nil and
36274 next(indent_table.indents) ~= nil
36275 end
36276
36277 local function get_last_indent_name(indent_table)
36278 if has_indents(indent_table) then
36279 return indent_table.indents[#indent_table.indents].name
36280 end
36281 end
36282
36283 local count_fenced_start_indent =
36284 function(_, _, indent_table, trail)
36285 local last_indent_name = get_last_indent_name(indent_table)
36286 fenceindent = 0
36287 if last_indent_name ~= "li" then
36288 fenceindent = #trail
36289 end
36290 return true
36291 end
36292
36293 local fencehead = function(char, infostring)
36294 return Cmt( Cb("indent_info")
36295 * parsers.check_trail, count_fenced_start_indent)
36296 * Cg(char^3, "fencelength")
36297 * parsers.optionalspace
36298 * infostring
36299 * (parsers.newline + parsers.eof)
36300 end
36301
36302 local fencetail = function(char)
36303 return parsers.check_trail_no_rem
36304 * Cmt(C(char^3) * Cb("fencelength"), captures_geq_length)
36305 * parsers.optionalspace * (parsers.newline + parsers.eof)
36306 + parsers.eof
36307 end
36308
36309 local process_fenced_line =
36310 function(s, i, -- luacheck: ignore s i
36311 indent_table, line_content, is_blank)
36312 local remainder = ""
36313 if has_trail(indent_table) then
36314 remainder = indent_table.trail.internal_remainder
36315 end
36316
36317 if is_blank
36318 and get_last_indent_name(indent_table) == "li" then
36319 remainder = ""
36320 end
36321
36322 local str = remainder .. line_content
36323 local index = 1
36324 local remaining = fenceindent
36325
36326 while true do
36327 local c = str:sub(index, index)
36328 if c == " " and remaining > 0 then
36329 remaining = remaining - 1
36330 index = index + 1
36331 elseif c == "\t" and remaining > 3 then
36332 remaining = remaining - 4
36333 index = index + 1
36334 else
36335 break
36336 end
36337 end
36338
36339 return true, str:sub(index)
36340 end
36341
36342 local fencedline = function(char)
36343 return Cmt( Cb("indent_info")
36344 * C(parsers.line - fencetail(char))
36345 * Cc(false), process_fenced_line)
36346 end
36347
36348 local blankfencedline
36349 = Cmt( Cb("indent_info")
36350 * C(parsers.blankline)
36351 * Cc(true), process_fenced_line)
36352
36353 local TildeFencedCode
36354 = fencehead(parsers.tilde, tilde_infostring)
36355 * Cs(( (parsers.check_minimal_blank_indent / "")
36356 * blankfencedline
36357 + ( parsers.check_minimal_indent / "")
36358 * fencedline(parsers.tilde))^0)
36359 * ( (parsers.check_minimal_indent / "")
36360 * fencetail(parsers.tilde) + parsers.succeed)
36361
36362 local BacktickFencedCode
36363 = fencehead(parsers.backtick, backtick_infostring)
36364 * Cs(( (parsers.check_minimal_blank_indent / "")
36365 * blankfencedline
36366 + (parsers.check_minimal_indent / "")
36367 * fencedline(parsers.backtick))^0)
36368 * ( (parsers.check_minimal_indent / "")
36369 * fencetail(parsers.backtick) + parsers.succeed)
36370
36371 local infostring_with_attributes
36372 = Ct(C((parsers.linechar
36373 - ( parsers.optionalspace
36374 * parsers.attributes))^0)
36375 * parsers.optionalspace
36376 * Ct(parsers.attributes))
36377
36378 local FencedCode
36379 = ((TildeFencedCode + BacktickFencedCode)
36380 / function(infostring, code)
36381 local expanded_code = self.expandtabs(code)
36382
36383 if allow_raw_blocks then
36384 local raw_attr = lpeg.match(parsers.raw_attribute,
36385 infostring)
36386 if raw_attr then
36387 return writer.rawBlock(expanded_code, raw_attr)
36388 end
36389 end
36390
36391 local attr = nil
36392 if allow_attributes then
36393 local match = lpeg.match(infostring_with_attributes,
36394 infostring)
36395 if match then
36396 infostring, attr = table.unpack(match)
36397 end
36398 end
36399 return writer.fencedCode(expanded_code, infostring, attr)
36400 end)
36401
36402 self.insert_pattern("Block after Verbatim",
36403 FencedCode, "FencedCode")
36404
36405 local fencestart
36406 if blank_before_code_fence then
36407 fencestart = parsers.fail
36408 else
36409 fencestart = fencehead(parsers.backtick, backtick_infostring)
36410 + fencehead(parsers.tilde, tilde_infostring)
36411 end
36412
36413 self.update_rule("EndlineExceptions", function(previous_pattern)
36414 if previous_pattern == nil then
36415 previous_pattern = parsers.EndlineExceptions
36416 end
36417 return previous_pattern + fencestart
36418 end)
36419
36420 self.add_special_character("`")
36421 self.add_special_character("~")
36422 end
36423 }
36424 end
36425 % \end{macrocode}
36426 % \begin{markdown}
36427 %
36428 %#### Fenced Divs
36429 %
36430 % The \luamdef{extensions.fenced_divs} function implements the Pandoc fenced
36431 % div syntax extension. When the `blank_before_div_fence` parameter is `true`,
36432 % the syntax extension requires a blank line between a paragraph and the
36433 % following fenced code block.
36434 %
36435 % \end{markdown}
36436 % \begin{macrocode}
36437 M.extensions.fenced_divs = function(blank_before_div_fence)
36438 return {
36439 name = "built-in fenced_divs syntax extension",
36440 extend_writer = function(self)
36441 % \end{macrocode}
36442 % \begin{markdown}
36443 %
36444 % Define \luamdef{writer->div_begin} as a function that will transform the
36445 % beginning of an input fenced div with with attributes `attributes` to the
36446 % output format.
36447 %
36448 % \end{markdown}
36449 % \begin{macrocode}
36450 function self.div_begin(attributes)
36451 local start_output
36452 = {"\\markdownRendererFencedDivAttributeContextBegin\n",
36453 self.attributes(attributes)}
36454 local end_output
36455 = {"\\markdownRendererFencedDivAttributeContextEnd{}"}
36456 return self.push_attributes(
36457 "div", attributes, start_output, end_output)
36458 end
36459 % \end{macrocode}
36460 % \begin{markdown}
36461 %
36462 % Define \luamdef{writer->div_end} as a function that will produce the end of a
36463 % fenced div in the output format.
36464 %
36465 % \end{markdown}
36466 % \begin{macrocode}
36467 function self.div_end()
36468 return self.pop_attributes("div")
36469 end
36470 end, extend_reader = function(self)
36471 local parsers = self.parsers
36472 local writer = self.writer
36473 % \end{macrocode}
36474 % \begin{markdown}
36475 %
36476 % Define basic patterns for matching the opening and the closing tag of a div.
36477 %
36478 % \end{markdown}
36479 % \begin{macrocode}
36480 local fenced_div_infostring
36481 = Ct(parsers.attributes)
36482 + (
36483 C( parsers.attribute_classname
36484 - parsers.colon)^1
36485 / function (infostring)
36486 return {"." .. infostring}
36487 end
36488 )
36489
36490 local fenced_div_begin = parsers.nonindentspace
36491 * parsers.colon^3
36492 * parsers.optionalspace
36493 * fenced_div_infostring
36494 * ( parsers.spacechar^1
36495 * parsers.colon^1)^0
36496 * parsers.optionalspace
36497 * (parsers.newline + parsers.eof)
36498
36499 local fenced_div_end = parsers.nonindentspace
36500 * parsers.colon^3
36501 * parsers.optionalspace
36502 * (parsers.newline + parsers.eof)
36503 % \end{macrocode}
36504 % \begin{markdown}
36505 %
36506 % Initialize a named group named `fenced_div_level` for tracking how deep
36507 % we are nested in divs and the named group `fenced_div_num_opening_indents`
36508 % for tracking the indent of the starting div fence. The former named group
36509 % is immutable and should roll back properly when we fail to match a fenced
36510 % div. The latter is mutable and may contain items from unsuccessful matches
36511 % on top. However, we always know how many items at the head of the latter we
36512 % can trust by consulting the former.
36513 %
36514 % \end{markdown}
36515 % \begin{macrocode}
36516 self.initialize_named_group("fenced_div_level", "0")
36517 self.initialize_named_group("fenced_div_num_opening_indents")
36518
36519 local function increment_div_level()
36520 local push_indent_table =
36521 function(s, i, indent_table, -- luacheck: ignore s i
36522 fenced_div_num_opening_indents, fenced_div_level)
36523 fenced_div_level = tonumber(fenced_div_level) + 1
36524 local num_opening_indents = 0
36525 if indent_table.indents ~= nil then
36526 num_opening_indents = #indent_table.indents
36527 end
36528 fenced_div_num_opening_indents[fenced_div_level]
36529 = num_opening_indents
36530 return true, fenced_div_num_opening_indents
36531 end
36532
36533 local increment_level =
36534 function(s, i, fenced_div_level) -- luacheck: ignore s i
36535 fenced_div_level = tonumber(fenced_div_level) + 1
36536 return true, tostring(fenced_div_level)
36537 end
36538
36539 return Cg( Cmt( Cb("indent_info")
36540 * Cb("fenced_div_num_opening_indents")
36541 * Cb("fenced_div_level"), push_indent_table)
36542 , "fenced_div_num_opening_indents")
36543 * Cg( Cmt( Cb("fenced_div_level"), increment_level)
36544 , "fenced_div_level")
36545 end
36546
36547 local function decrement_div_level()
36548 local pop_indent_table =
36549 function(s, i, -- luacheck: ignore s i
36550 fenced_div_indent_table, fenced_div_level)
36551 fenced_div_level = tonumber(fenced_div_level)
36552 fenced_div_indent_table[fenced_div_level] = nil
36553 return true, tostring(fenced_div_level - 1)
36554 end
36555
36556 return Cg( Cmt( Cb("fenced_div_num_opening_indents")
36557 * Cb("fenced_div_level"), pop_indent_table)
36558 , "fenced_div_level")
36559 end
36560
36561
36562 local non_fenced_div_block
36563 = parsers.check_minimal_indent * V("Block")
36564 - parsers.check_minimal_indent_and_trail * fenced_div_end
36565
36566 local non_fenced_div_paragraph
36567 = parsers.check_minimal_indent * V("Paragraph")
36568 - parsers.check_minimal_indent_and_trail * fenced_div_end
36569
36570 local blank = parsers.minimally_indented_blank
36571
36572 local block_separated = parsers.block_sep_group(blank)
36573 * non_fenced_div_block
36574
36575 local loop_body_pair
36576 = parsers.create_loop_body_pair(block_separated,
36577 non_fenced_div_paragraph,
36578 parsers.block_sep_group(blank),
36579 parsers.par_sep_group(blank))
36580
36581 local content_loop = ( non_fenced_div_block
36582 * loop_body_pair.block^0
36583 + non_fenced_div_paragraph
36584 * block_separated
36585 * loop_body_pair.block^0
36586 + non_fenced_div_paragraph
36587 * loop_body_pair.par^0)
36588 * blank^0
36589
36590 local FencedDiv = fenced_div_begin
36591 / writer.div_begin
36592 * increment_div_level()
36593 * parsers.skipblanklines
36594 * Ct(content_loop)
36595 * parsers.minimally_indented_blank^0
36596 * parsers.check_minimal_indent_and_trail
36597 * fenced_div_end
36598 * decrement_div_level()
36599 * (Cc("") / writer.div_end)
36600
36601 self.insert_pattern("Block after Verbatim",
36602 FencedDiv, "FencedDiv")
36603
36604 self.add_special_character(":")
36605
36606 % \end{macrocode}
36607 % \begin{markdown}
36608 %
36609 % If the `blank_before_div_fence` parameter is `false`, we will have the
36610 % closing div at the beginning of a line break the current paragraph if
36611 % we are currently nested in a div and the indentation matches the opening
36612 % div fence.
36613 %
36614 % \end{markdown}
36615 % \begin{macrocode}
36616 local function is_inside_div()
36617 local check_div_level =
36618 function(s, i, fenced_div_level) -- luacheck: ignore s i
36619 fenced_div_level = tonumber(fenced_div_level)
36620 return fenced_div_level > 0
36621 end
36622
36623 return Cmt(Cb("fenced_div_level"), check_div_level)
36624 end
36625
36626 local function check_indent()
36627 local compare_indent =
36628 function(s, i, indent_table, -- luacheck: ignore s i
36629 fenced_div_num_opening_indents, fenced_div_level)
36630 fenced_div_level = tonumber(fenced_div_level)
36631 local num_current_indents
36632 = ( indent_table.current_line_indents ~= nil and
36633 #indent_table.current_line_indents) or 0
36634 local num_opening_indents
36635 = fenced_div_num_opening_indents[fenced_div_level]
36636 return num_current_indents == num_opening_indents
36637 end
36638
36639 return Cmt( Cb("indent_info")
36640 * Cb("fenced_div_num_opening_indents")
36641 * Cb("fenced_div_level"), compare_indent)
36642 end
36643
36644 local fencestart = is_inside_div()
36645 * fenced_div_end
36646 * check_indent()
36647
36648 if not blank_before_div_fence then
36649 self.update_rule("EndlineExceptions", function(previous_pattern)
36650 if previous_pattern == nil then
36651 previous_pattern = parsers.EndlineExceptions
36652 end
36653 return previous_pattern + fencestart
36654 end)
36655 end
36656 end
36657 }
36658 end
36659 % \end{macrocode}
36660 % \begin{markdown}
36661 %
36662 %#### Header Attributes
36663 %
36664 % The \luamdef{extensions.header_attributes} function implements the Pandoc
36665 % header attribute syntax extension.
36666 %
36667 % \end{markdown}
36668 % \begin{macrocode}
36669 M.extensions.header_attributes = function()
36670 return {
36671 name = "built-in header_attributes syntax extension",
36672 extend_writer = function()
36673 end, extend_reader = function(self)
36674 local parsers = self.parsers
36675 local writer = self.writer
36676
36677 local function strip_atx_end(s)
36678 return s:gsub("%s+#*%s*$","")
36679 end
36680
36681 local AtxHeading = Cg(parsers.heading_start, "level")
36682 * parsers.optionalspace
36683 * (C(((parsers.linechar
36684 - (parsers.attributes
36685 * parsers.optionalspace
36686 * parsers.newline))
36687 * (parsers.linechar
36688 - parsers.lbrace)^0)^1)
36689 / strip_atx_end
36690 / parsers.parse_heading_text)
36691 * Cg(Ct(parsers.newline
36692 + (parsers.attributes
36693 * parsers.optionalspace
36694 * parsers.newline)), "attributes")
36695 * Cb("level")
36696 * Cb("attributes")
36697 / writer.heading
36698
36699 local function strip_trailing_spaces(s)
36700 return s:gsub("%s*$","")
36701 end
36702
36703 local heading_line = (parsers.linechar
36704 - (parsers.attributes
36705 * parsers.optionalspace
36706 * parsers.newline))^1
36707 - parsers.thematic_break_lines
36708
36709 local heading_text
36710 = heading_line
36711 * ( (V("Endline") / "\n")
36712 * (heading_line - parsers.heading_level))^0
36713 * parsers.newline^-1
36714
36715 local SetextHeading
36716 = parsers.freeze_trail * parsers.check_trail_no_rem
36717 * #(heading_text
36718 * (parsers.attributes
36719 * parsers.optionalspace
36720 * parsers.newline)^-1
36721 * parsers.check_minimal_indent
36722 * parsers.check_trail
36723 * parsers.heading_level)
36724 * Cs(heading_text) / strip_trailing_spaces
36725 / parsers.parse_heading_text
36726 * Cg(Ct((parsers.attributes
36727 * parsers.optionalspace
36728 * parsers.newline)^-1), "attributes")
36729 * parsers.check_minimal_indent_and_trail * parsers.heading_level
36730 * Cb("attributes")
36731 * parsers.newline
36732 * parsers.unfreeze_trail
36733 / writer.heading
36734
36735 local Heading = AtxHeading + SetextHeading
36736 self.update_rule("Heading", Heading)
36737 end
36738 }
36739 end
36740 % \end{macrocode}
36741 % \begin{markdown}
36742 %
36743 %#### Inline Code Attributes
36744 %
36745 % The \luamdef{extensions.inline_code_attributes} function implements the
36746 % Pandoc inline code attribute syntax extension.
36747 %
36748 % \end{markdown}
36749 % \begin{macrocode}
36750 M.extensions.inline_code_attributes = function()
36751 return {
36752 name = "built-in inline_code_attributes syntax extension",
36753 extend_writer = function()
36754 end, extend_reader = function(self)
36755 local writer = self.writer
36756
36757 local CodeWithAttributes = parsers.inticks
36758 * Ct(parsers.attributes)
36759 / writer.code
36760
36761 self.insert_pattern("Inline before Code",
36762 CodeWithAttributes,
36763 "CodeWithAttributes")
36764 end
36765 }
36766 end
36767 % \end{macrocode}
36768 % \begin{markdown}
36769 %
36770 %#### Line Blocks
36771 %
36772 % The \luamdef{extensions.line_blocks} function implements the Pandoc line block
36773 % syntax extension.
36774 %
36775 % \end{markdown}
36776 % \begin{macrocode}
36777 M.extensions.line_blocks = function()
36778 return {
36779 name = "built-in line_blocks syntax extension",
36780 extend_writer = function(self)
36781 % \end{macrocode}
36782 % \begin{markdown}
36783 %
36784 % Define \luamdef{writer->lineblock} as a function that will transform
36785 % a line block consisted of `lines` to the output format, with
36786 % all but the last newline rendered as a line break.
36787 %
36788 % \end{markdown}
36789 % \begin{macrocode}
36790 function self.lineblock(lines)
36791 if not self.is_writing then return "" end
36792 local buffer = {}
36793 for i = 1, #lines - 1 do
36794 buffer[#buffer + 1] = { lines[i], self.hard_line_break }
36795 end
36796 buffer[#buffer + 1] = lines[#lines]
36797
36798 return {"\\markdownRendererLineBlockBegin\n"
36799 ,buffer,
36800 "\n\\markdownRendererLineBlockEnd "}
36801 end
36802 end, extend_reader = function(self)
36803 local parsers = self.parsers
36804 local writer = self.writer
36805
36806 local LineBlock
36807 = Ct((Cs(( (parsers.pipe * parsers.space) / ""
36808 * ((parsers.space)/entities.char_entity("nbsp"))^0
36809 * parsers.linechar^0 * (parsers.newline/""))
36810 * (-parsers.pipe
36811 * (parsers.space^1/" ")
36812 * parsers.linechar^1
36813 * (parsers.newline/"")
36814 )^0)
36815 / self.parser_functions.parse_inlines)^1)
36816 / writer.lineblock
36817
36818 self.insert_pattern("Block after Blockquote",
36819 LineBlock, "LineBlock")
36820 end
36821 }
36822 end
36823 % \end{macrocode}
36824 % \begin{markdown}
36825 %
36826 %#### Marked text
36827 %
36828 % The \luamdef{extensions.mark} function implements the Pandoc mark syntax
36829 % extension.
36830 %
36831 % \end{markdown}
36832 % \begin{macrocode}
36833 M.extensions.mark = function()
36834 return {
36835 name = "built-in mark syntax extension",
36836 extend_writer = function(self)
36837 % \end{macrocode}
36838 % \begin{markdown}
36839 %
36840 % Define \luamdef{writer->mark} as a function that will transform an input
36841 % marked text `s` to the output format.
36842 %
36843 % \end{markdown}
36844 % \begin{macrocode}
36845 function self.mark(s)
36846 if self.flatten_inlines then return s end
36847 return {"\\markdownRendererMark{", s, "}"}
36848 end
36849 end, extend_reader = function(self)
36850 local parsers = self.parsers
36851 local writer = self.writer
36852
36853 local doubleequals = P("==")
36854
36855 local Mark
36856 = parsers.between(V("Inline"), doubleequals, doubleequals)
36857 / function (inlines) return writer.mark(inlines) end
36858
36859 self.add_special_character("=")
36860 self.insert_pattern("Inline before LinkAndEmph",
36861 Mark, "Mark")
36862 end
36863 }
36864 end
36865 % \end{macrocode}
36866 % \begin{markdown}
36867 %
36868 %#### Link Attributes
36869 %
36870 % The \luamdef{extensions.link_attributes} function implements the Pandoc
36871 % link attribute syntax extension.
36872 %
36873 % \end{markdown}
36874 % \begin{macrocode}
36875 M.extensions.link_attributes = function()
36876 return {
36877 name = "built-in link_attributes syntax extension",
36878 extend_writer = function()
36879 end, extend_reader = function(self)
36880 local parsers = self.parsers
36881 local options = self.options
36882
36883 % \end{macrocode}
36884 % \begin{markdown}
36885 %
36886 % The following patterns define link reference definitions with attributes.
36887 %
36888 % \end{markdown}
36889 % \begin{macrocode}
36890 local define_reference_parser
36891 = (parsers.check_trail / "")
36892 * parsers.link_label
36893 * parsers.colon
36894 * parsers.spnlc * parsers.url
36895 * ( parsers.spnlc_sep * parsers.title
36896 * (parsers.spnlc * Ct(parsers.attributes))
36897 * parsers.only_blank
36898 + parsers.spnlc_sep * parsers.title * parsers.only_blank
36899 + Cc("") * (parsers.spnlc * Ct(parsers.attributes))
36900 * parsers.only_blank
36901 + Cc("") * parsers.only_blank)
36902
36903 local ReferenceWithAttributes = define_reference_parser
36904 / self.register_link
36905
36906 self.update_rule("Reference", ReferenceWithAttributes)
36907
36908 % \end{macrocode}
36909 % \begin{markdown}
36910 %
36911 % The following patterns define direct and indirect links with attributes.
36912 %
36913 % \end{markdown}
36914 % \begin{macrocode}
36915
36916 local LinkWithAttributesAndEmph
36917 = Ct(parsers.link_and_emph_table * Cg(Cc(true),
36918 "match_link_attributes"))
36919 / self.defer_link_and_emphasis_processing
36920
36921 self.update_rule("LinkAndEmph", LinkWithAttributesAndEmph)
36922
36923 % \end{macrocode}
36924 % \begin{markdown}
36925 %
36926 % The following patterns define autolinks with attributes.
36927 %
36928 % \end{markdown}
36929 % \begin{macrocode}
36930 local AutoLinkUrlWithAttributes
36931 = parsers.auto_link_url
36932 * Ct(parsers.attributes)
36933 / self.auto_link_url
36934
36935 self.insert_pattern("Inline before AutoLinkUrl",
36936 AutoLinkUrlWithAttributes,
36937 "AutoLinkUrlWithAttributes")
36938
36939 local AutoLinkEmailWithAttributes
36940 = parsers.auto_link_email
36941 * Ct(parsers.attributes)
36942 / self.auto_link_email
36943
36944 self.insert_pattern("Inline before AutoLinkEmail",
36945 AutoLinkEmailWithAttributes,
36946 "AutoLinkEmailWithAttributes")
36947
36948 if options.relativeReferences then
36949
36950 local AutoLinkRelativeReferenceWithAttributes
36951 = parsers.auto_link_relative_reference
36952 * Ct(parsers.attributes)
36953 / self.auto_link_url
36954
36955 self.insert_pattern(
36956 "Inline before AutoLinkRelativeReference",
36957 AutoLinkRelativeReferenceWithAttributes,
36958 "AutoLinkRelativeReferenceWithAttributes")
36959
36960 end
36961
36962 end
36963 }
36964 end
36965 % \end{macrocode}
36966 % \begin{markdown}
36967 %
36968 %#### Notes
36969 %
36970 % The \luamdef{extensions.notes} function implements the Pandoc note
36971 % and inline note syntax extensions. When the `note` parameter is
36972 % `true`, the Pandoc note syntax extension will be enabled. When the
36973 % `inline_notes` parameter is `true`, the Pandoc inline note syntax
36974 % extension will be enabled.
36975 %
36976 % \end{markdown}
36977 % \begin{macrocode}
36978 M.extensions.notes = function(notes, inline_notes)
36979 assert(notes or inline_notes)
36980 return {
36981 name = "built-in notes syntax extension",
36982 extend_writer = function(self)
36983 % \end{macrocode}
36984 % \begin{markdown}
36985 %
36986 % Define \luamdef{writer->note} as a function that will transform an
36987 % input note `s` to the output format.
36988 %
36989 % \end{markdown}
36990 % \begin{macrocode}
36991 function self.note(s)
36992 if self.flatten_inlines then return "" end
36993 return {"\\markdownRendererNote{",s,"}"}
36994 end
36995 end, extend_reader = function(self)
36996 local parsers = self.parsers
36997 local writer = self.writer
36998
36999 local rawnotes = parsers.rawnotes
37000
37001 if inline_notes then
37002 local InlineNote
37003 = parsers.circumflex
37004 * ( parsers.link_label
37005 / self.parser_functions.parse_inlines_no_inline_note)
37006 / writer.note
37007
37008 self.insert_pattern("Inline after LinkAndEmph",
37009 InlineNote, "InlineNote")
37010 end
37011 if notes then
37012 local function strip_first_char(s)
37013 return s:sub(2)
37014 end
37015
37016 local RawNoteRef
37017 = #(parsers.lbracket * parsers.circumflex)
37018 * parsers.link_label / strip_first_char
37019
37020 -- like indirect_link
37021 local function lookup_note(ref)
37022 return writer.defer_call(function()
37023 local found = rawnotes[self.normalize_tag(ref)]
37024 if found then
37025 return writer.note(
37026 self.parser_functions.parse_blocks_nested(found))
37027 else
37028 local text = string.format(
37029 'Undefined note reference "%s"', ref)
37030 local more = string.format(
37031 "Look for the text `[^%s]`.", ref)
37032 return {writer.warning(text, more), "[",
37033 self.parser_functions.parse_inlines("^" .. ref), "]"}
37034 end
37035 end)
37036 end
37037
37038 local function register_note(ref,rawnote)
37039 local normalized_tag = self.normalize_tag(ref)
37040 if rawnotes[normalized_tag] == nil then
37041 rawnotes[normalized_tag] = rawnote
37042 return ""
37043 else
37044 local text
37045 = string.format('Multiply defined note reference "%s"',
37046 ref)
37047 local more
37048 = string.format("Look for the text `[^%s]: ...`.", ref)
37049 return writer.warning(text, more)
37050 end
37051 end
37052
37053 local NoteRef = RawNoteRef / lookup_note
37054
37055 local optionally_indented_line
37056 = parsers.check_optional_indent_and_any_trail * parsers.line
37057
37058 local blank
37059 = parsers.check_optional_blank_indent_and_any_trail
37060 * parsers.optionalspace * parsers.newline
37061
37062 local chunk
37063 = Cs(parsers.line
37064 * (optionally_indented_line - blank)^0)
37065
37066 local indented_blocks = function(bl)
37067 return Cs( bl
37068 * ( blank^1 * (parsers.check_optional_indent / "")
37069 * parsers.check_code_trail
37070 * -parsers.blankline * bl)^0)
37071 end
37072
37073 local NoteBlock
37074 = parsers.check_trail_no_rem
37075 * RawNoteRef * parsers.colon
37076 * parsers.spnlc * indented_blocks(chunk)
37077 / register_note
37078
37079 self.update_rule("Reference", function(previous_pattern)
37080 if previous_pattern == nil then
37081 previous_pattern = parsers.Reference
37082 end
37083 return NoteBlock + previous_pattern
37084 end)
37085
37086 self.insert_pattern("Inline before LinkAndEmph",
37087 NoteRef, "NoteRef")
37088 end
37089
37090 self.add_special_character("^")
37091 end
37092 }
37093 end
37094 % \end{macrocode}
37095 % \begin{markdown}
37096 %
37097 %#### Pipe Tables
37098 %
37099 % The \luamdef{extensions.pipe_table} function implements the PHP
37100 % Markdown table syntax extension (also known as pipe tables in Pandoc). When
37101 % the `table_captions` parameter is `true`, the function also implements the
37102 % Pandoc table caption syntax extension for table captions. When the
37103 % `table_attributes` parameter is also `true`, the function also
37104 % allows attributes to be attached to the (possibly empty) table captions.
37105 %
37106 % \end{markdown}
37107 % \begin{macrocode}
37108 M.extensions.pipe_tables = function(table_captions, table_attributes)
37109
37110 local function make_pipe_table_rectangular(rows)
37111 local num_columns = #rows[2]
37112 local rectangular_rows = {}
37113 for i = 1, #rows do
37114 local row = rows[i]
37115 local rectangular_row = {}
37116 for j = 1, num_columns do
37117 rectangular_row[j] = row[j] or ""
37118 end
37119 table.insert(rectangular_rows, rectangular_row)
37120 end
37121 return rectangular_rows
37122 end
37123
37124 local function pipe_table_row(allow_empty_first_column
37125 , nonempty_column
37126 , column_separator
37127 , column)
37128 local row_beginning
37129 if allow_empty_first_column then
37130 row_beginning = -- empty first column
37131 #(parsers.spacechar^4
37132 * column_separator)
37133 * parsers.optionalspace
37134 * column
37135 * parsers.optionalspace
37136 -- non-empty first column
37137 + parsers.nonindentspace
37138 * nonempty_column^-1
37139 * parsers.optionalspace
37140 else
37141 row_beginning = parsers.nonindentspace
37142 * nonempty_column^-1
37143 * parsers.optionalspace
37144 end
37145
37146 return Ct(row_beginning
37147 * (-- single column with no leading pipes
37148 #(column_separator
37149 * parsers.optionalspace
37150 * parsers.newline)
37151 * column_separator
37152 * parsers.optionalspace
37153 -- single column with leading pipes or
37154 -- more than a single column
37155 + (column_separator
37156 * parsers.optionalspace
37157 * column
37158 * parsers.optionalspace)^1
37159 * (column_separator
37160 * parsers.optionalspace)^-1))
37161 end
37162
37163 return {
37164 name = "built-in pipe_tables syntax extension",
37165 extend_writer = function(self)
37166 % \end{macrocode}
37167 % \begin{markdown}
37168 %
37169 % Define \luamdef{writer->table} as a function that will transform an input
37170 % table to the output format, where `rows` is a sequence of columns and a
37171 % column is a sequence of cell texts.
37172 %
37173 % \end{markdown}
37174 % \begin{macrocode}
37175 function self.table(rows, caption, attributes)
37176 if not self.is_writing then return "" end
37177 local buffer = {}
37178 if attributes ~= nil then
37179 table.insert(buffer,
37180 "\\markdownRendererTableAttributeContextBegin\n")
37181 table.insert(buffer, self.attributes(attributes))
37182 end
37183 table.insert(buffer,
37184 {"\\markdownRendererTable{",
37185 caption or "", "}{", #rows - 1, "}{",
37186 #rows[1], "}"})
37187 local temp = rows[2] -- put alignments on the first row
37188 rows[2] = rows[1]
37189 rows[1] = temp
37190 for i, row in ipairs(rows) do
37191 table.insert(buffer, "{")
37192 for _, column in ipairs(row) do
37193 if i > 1 then -- do not use braces for alignments
37194 table.insert(buffer, "{")
37195 end
37196 table.insert(buffer, column)
37197 if i > 1 then
37198 table.insert(buffer, "}")
37199 end
37200 end
37201 table.insert(buffer, "}")
37202 end
37203 if attributes ~= nil then
37204 table.insert(buffer,
37205 "\\markdownRendererTableAttributeContextEnd{}")
37206 end
37207 return buffer
37208 end
37209 end, extend_reader = function(self)
37210 local parsers = self.parsers
37211 local writer = self.writer
37212
37213 local table_hline_separator = parsers.pipe + parsers.plus
37214
37215 local table_hline_column = (parsers.dash
37216 - #(parsers.dash
37217 * (parsers.spacechar
37218 + table_hline_separator
37219 + parsers.newline)))^1
37220 * (parsers.colon * Cc("r")
37221 + parsers.dash * Cc("d"))
37222 + parsers.colon
37223 * (parsers.dash
37224 - #(parsers.dash
37225 * (parsers.spacechar
37226 + table_hline_separator
37227 + parsers.newline)))^1
37228 * (parsers.colon * Cc("c")
37229 + parsers.dash * Cc("l"))
37230
37231 local table_hline = pipe_table_row(false
37232 , table_hline_column
37233 , table_hline_separator
37234 , table_hline_column)
37235
37236 local table_caption_beginning
37237 = ( parsers.check_minimal_blank_indent_and_any_trail_no_rem
37238 * parsers.optionalspace * parsers.newline)^0
37239 * parsers.check_minimal_indent_and_trail
37240 * (P("Table")^-1 * parsers.colon)
37241 * parsers.optionalspace
37242
37243 local function strip_trailing_spaces(s)
37244 return s:gsub("%s*$","")
37245 end
37246
37247 local table_row
37248 = pipe_table_row(true
37249 , (C((parsers.linechar - parsers.pipe)^1)
37250 / strip_trailing_spaces
37251 / self.parser_functions.parse_inlines)
37252 , parsers.pipe
37253 , (C((parsers.linechar - parsers.pipe)^0)
37254 / strip_trailing_spaces
37255 / self.parser_functions.parse_inlines))
37256
37257 local table_caption
37258 if table_captions then
37259 table_caption = #table_caption_beginning
37260 * table_caption_beginning
37261 if table_attributes then
37262 table_caption = table_caption
37263 * (C(((( parsers.linechar
37264 - (parsers.attributes
37265 * parsers.optionalspace
37266 * parsers.newline
37267 * -#( parsers.optionalspace
37268 * parsers.linechar)))
37269 + ( parsers.newline
37270 * #( parsers.optionalspace
37271 * parsers.linechar)
37272 * C(parsers.optionalspace)
37273 / writer.space))
37274 * (parsers.linechar
37275 - parsers.lbrace)^0)^1)
37276 / strip_trailing_spaces
37277 / self.parser_functions.parse_inlines)
37278 * (parsers.newline
37279 + ( Ct(parsers.attributes)
37280 * parsers.optionalspace
37281 * parsers.newline))
37282 else
37283 table_caption = table_caption
37284 * C(( parsers.linechar
37285 + ( parsers.newline
37286 * #( parsers.optionalspace
37287 * parsers.linechar)
37288 * C(parsers.optionalspace)
37289 / writer.space))^1)
37290 / self.parser_functions.parse_inlines
37291 * parsers.newline
37292 end
37293 else
37294 table_caption = parsers.fail
37295 end
37296
37297 local PipeTable
37298 = Ct( table_row * parsers.newline
37299 * (parsers.check_minimal_indent_and_trail / {})
37300 * table_hline * parsers.newline
37301 * ( (parsers.check_minimal_indent / {})
37302 * table_row * parsers.newline)^0)
37303 / make_pipe_table_rectangular
37304 * table_caption^-1
37305 / writer.table
37306
37307 self.insert_pattern("Block after Blockquote",
37308 PipeTable, "PipeTable")
37309 end
37310 }
37311 end
37312 % \end{macrocode}
37313 % \begin{markdown}
37314 %
37315 %#### Raw Attributes
37316 %
37317 % The \luamdef{extensions.raw_inline} function implements the Pandoc
37318 % raw attribute syntax extension for inline code spans.
37319 %
37320 % \end{markdown}
37321 % \begin{macrocode}
37322 M.extensions.raw_inline = function()
37323 return {
37324 name = "built-in raw_inline syntax extension",
37325 extend_writer = function(self)
37326 local options = self.options
37327
37328 % \end{macrocode}
37329 % \begin{markdown}
37330 %
37331 % Define \luamdef{writer->rawInline} as a function that will transform an
37332 % input inline raw span `s` with the raw attribute `attr` to the output format.
37333 %
37334 % \end{markdown}
37335 % \begin{macrocode}
37336 function self.rawInline(s, attr)
37337 if not self.is_writing then return "" end
37338 if self.flatten_inlines then return s end
37339 local name = util.cache_verbatim(options.cacheDir, s)
37340 return {"\\markdownRendererInputRawInline{",
37341 name,"}{", self.string(attr),"}"}
37342 end
37343 end, extend_reader = function(self)
37344 local writer = self.writer
37345
37346 local RawInline = parsers.inticks
37347 * parsers.raw_attribute
37348 / writer.rawInline
37349
37350 self.insert_pattern("Inline before Code",
37351 RawInline, "RawInline")
37352 end
37353 }
37354 end
37355 % \end{macrocode}
37356 % \begin{markdown}
37357 %
37358 %#### Strike-Through
37359 %
37360 % The \luamdef{extensions.strike_through} function implements the Pandoc
37361 % strike-through syntax extension.
37362 %
37363 % \end{markdown}
37364 % \begin{macrocode}
37365 M.extensions.strike_through = function()
37366 return {
37367 name = "built-in strike_through syntax extension",
37368 extend_writer = function(self)
37369 % \end{macrocode}
37370 % \begin{markdown}
37371 %
37372 % Define \luamdef{writer->strike_through} as a function that will transform
37373 % a strike-through span `s` of input text to the output format.
37374 %
37375 % \end{markdown}
37376 % \begin{macrocode}
37377 function self.strike_through(s)
37378 if self.flatten_inlines then return s end
37379 return {"\\markdownRendererStrikeThrough{",s,"}"}
37380 end
37381 end, extend_reader = function(self)
37382 local parsers = self.parsers
37383 local writer = self.writer
37384
37385 local StrikeThrough = (
37386 parsers.between(parsers.Inline, parsers.doubletildes,
37387 parsers.doubletildes)
37388 ) / writer.strike_through
37389
37390 self.insert_pattern("Inline after LinkAndEmph",
37391 StrikeThrough, "StrikeThrough")
37392
37393 self.add_special_character("~")
37394 end
37395 }
37396 end
37397 % \end{macrocode}
37398 % \begin{markdown}
37399 %
37400 %#### Subscripts
37401 %
37402 % The \luamdef{extensions.subscripts} function implements the Pandoc
37403 % subscript syntax extension.
37404 %
37405 % \end{markdown}
37406 % \begin{macrocode}
37407 M.extensions.subscripts = function()
37408 return {
37409 name = "built-in subscripts syntax extension",
37410 extend_writer = function(self)
37411 % \end{macrocode}
37412 % \begin{markdown}
37413 %
37414 % Define \luamdef{writer->subscript} as a function that will transform
37415 % a subscript span `s` of input text to the output format.
37416 %
37417 % \end{markdown}
37418 % \begin{macrocode}
37419 function self.subscript(s, parsed)
37420 if self.flatten_inlines then return s end
37421 return {"\\markdownRendererSubscript{",parsed,"}"}
37422 end
37423 end, extend_reader = function(self)
37424 local parsers = self.parsers
37425 local writer = self.writer
37426
37427 local Subscript = (
37428 parsers.between(parsers.Str, parsers.tilde, parsers.tilde)
37429 ) / function(s)
37430 return writer.subscript(
37431 s, self.parser_functions.parse_inlines_identity(s[1])
37432 )
37433 end
37434
37435 self.insert_pattern("Inline after LinkAndEmph",
37436 Subscript, "Subscript")
37437
37438 self.add_special_character("~")
37439 end
37440 }
37441 end
37442 % \end{macrocode}
37443 % \begin{markdown}
37444 %
37445 %#### Superscripts
37446 %
37447 % The \luamdef{extensions.superscripts} function implements the Pandoc
37448 % superscript syntax extension.
37449 %
37450 % \end{markdown}
37451 % \begin{macrocode}
37452 M.extensions.superscripts = function()
37453 return {
37454 name = "built-in superscripts syntax extension",
37455 extend_writer = function(self)
37456 % \end{macrocode}
37457 % \begin{markdown}
37458 %
37459 % Define \luamdef{writer->superscript} as a function that will transform
37460 % a superscript span `s` of input text to the output format.
37461 %
37462 % \end{markdown}
37463 % \begin{macrocode}
37464 function self.superscript(s, parsed)
37465 if self.flatten_inlines then return s end
37466 return {"\\markdownRendererSuperscript{",parsed,"}"}
37467 end
37468 end, extend_reader = function(self)
37469 local parsers = self.parsers
37470 local writer = self.writer
37471
37472 local Superscript = (
37473 parsers.between(parsers.Str, parsers.circumflex,
37474 parsers.circumflex)
37475 ) / function(s)
37476 return writer.superscript(
37477 s, self.parser_functions.parse_inlines_identity(s[1])
37478 )
37479 end
37480
37481 self.insert_pattern("Inline after LinkAndEmph",
37482 Superscript, "Superscript")
37483
37484 self.add_special_character("^")
37485 end
37486 }
37487 end
37488 % \end{macrocode}
37489 % \begin{markdown}
37490 %
37491 %#### \TeX{} Math
37492 %
37493 % The \luamdef{extensions.tex_math} function implements the Pandoc math
37494 % syntax extensions.
37495 %
37496 % \end{markdown}
37497 % \begin{macrocode}
37498 M.extensions.tex_math = function(tex_math_dollars,
37499 tex_math_single_backslash,
37500 tex_math_double_backslash)
37501 return {
37502 name = "built-in tex_math syntax extension",
37503 extend_writer = function(self)
37504 % \end{macrocode}
37505 % \begin{markdown}
37506 %
37507 % Define \luamdef{writer->display_math} as a function that will transform
37508 % a math span `s` of input text to the output format.
37509 %
37510 % \end{markdown}
37511 % \begin{macrocode}
37512 function self.display_math(s, parsed)
37513 if self.flatten_inlines then return s end
37514 return {"\\markdownRendererDisplayMath{",parsed,"}"}
37515 end
37516 % \end{macrocode}
37517 % \begin{markdown}
37518 %
37519 % Define \luamdef{writer->inline_math} as a function that will transform
37520 % a math span `s` of input text to the output format.
37521 %
37522 % \end{markdown}
37523 % \begin{macrocode}
37524 function self.inline_math(s, parsed)
37525 if self.flatten_inlines then return s end
37526 return {"\\markdownRendererInlineMath{",parsed,"}"}
37527 end
37528 end, extend_reader = function(self)
37529 local parsers = self.parsers
37530 local writer = self.writer
37531
37532 local function between(p, starter, ender)
37533 return (starter * Cs(p * (p - ender)^0) * ender)
37534 end
37535
37536 local function strip_preceding_whitespaces(str)
37537 return str:gsub("^%s*(.-)$", "%1")
37538 end
37539
37540 local allowed_before_closing
37541 = B( parsers.backslash * parsers.any
37542 + parsers.any * (parsers.any - parsers.backslash))
37543
37544 local allowed_before_closing_no_space
37545 = B( parsers.backslash * parsers.any
37546 + parsers.any * (parsers.nonspacechar - parsers.backslash))
37547
37548 % \end{macrocode}
37549 % \begin{markdown}
37550 %
37551 % The following patterns implement the Pandoc dollar math syntax extension.
37552 %
37553 % \end{markdown}
37554 % \begin{macrocode}
37555 local dollar_math_content
37556 = (parsers.newline * (parsers.check_optional_indent / "")
37557 + parsers.backslash^-1
37558 * parsers.linechar)
37559 - parsers.blankline^2
37560 - parsers.dollar
37561
37562 local inline_math_opening_dollars = parsers.dollar
37563 * #(parsers.nonspacechar)
37564
37565 local inline_math_closing_dollars
37566 = allowed_before_closing_no_space
37567 * parsers.dollar
37568 * -#(parsers.digit)
37569
37570 local inline_math_dollars = between(Cs( dollar_math_content),
37571 inline_math_opening_dollars,
37572 inline_math_closing_dollars)
37573
37574 local display_math_opening_dollars = parsers.dollar
37575 * parsers.dollar
37576
37577 local display_math_closing_dollars = parsers.dollar
37578 * parsers.dollar
37579
37580 local display_math_dollars = between(Cs( dollar_math_content),
37581 display_math_opening_dollars,
37582 display_math_closing_dollars)
37583 % \end{macrocode}
37584 % \begin{markdown}
37585 %
37586 % The following patterns implement the Pandoc single and double
37587 % backslash math syntax extensions.
37588 %
37589 % \end{markdown}
37590 % \begin{macrocode}
37591 local backslash_math_content
37592 = (parsers.newline * (parsers.check_optional_indent / "")
37593 + parsers.linechar)
37594 - parsers.blankline^2
37595 % \end{macrocode}
37596 % \begin{markdown}
37597 %
37598 % The following patterns implement the Pandoc double backslash math
37599 % syntax extension.
37600 %
37601 % \end{markdown}
37602 % \begin{macrocode}
37603 local inline_math_opening_double = parsers.backslash
37604 * parsers.backslash
37605 * parsers.lparent
37606
37607 local inline_math_closing_double = allowed_before_closing
37608 * parsers.spacechar^0
37609 * parsers.backslash
37610 * parsers.backslash
37611 * parsers.rparent
37612
37613 local inline_math_double = between(Cs( backslash_math_content),
37614 inline_math_opening_double,
37615 inline_math_closing_double)
37616 / strip_preceding_whitespaces
37617
37618 local display_math_opening_double = parsers.backslash
37619 * parsers.backslash
37620 * parsers.lbracket
37621
37622 local display_math_closing_double = allowed_before_closing
37623 * parsers.spacechar^0
37624 * parsers.backslash
37625 * parsers.backslash
37626 * parsers.rbracket
37627
37628 local display_math_double = between(Cs( backslash_math_content),
37629 display_math_opening_double,
37630 display_math_closing_double)
37631 / strip_preceding_whitespaces
37632 % \end{macrocode}
37633 % \begin{markdown}
37634 %
37635 % The following patterns implement the Pandoc single backslash math
37636 % syntax extension.
37637 %
37638 % \end{markdown}
37639 % \begin{macrocode}
37640 local inline_math_opening_single = parsers.backslash
37641 * parsers.lparent
37642
37643 local inline_math_closing_single = allowed_before_closing
37644 * parsers.spacechar^0
37645 * parsers.backslash
37646 * parsers.rparent
37647
37648 local inline_math_single = between(Cs( backslash_math_content),
37649 inline_math_opening_single,
37650 inline_math_closing_single)
37651 / strip_preceding_whitespaces
37652
37653 local display_math_opening_single = parsers.backslash
37654 * parsers.lbracket
37655
37656 local display_math_closing_single = allowed_before_closing
37657 * parsers.spacechar^0
37658 * parsers.backslash
37659 * parsers.rbracket
37660
37661 local display_math_single = between(Cs( backslash_math_content),
37662 display_math_opening_single,
37663 display_math_closing_single)
37664 / strip_preceding_whitespaces
37665
37666 local display_math = parsers.fail
37667
37668 local inline_math = parsers.fail
37669
37670 if tex_math_dollars then
37671 display_math = display_math + display_math_dollars
37672 inline_math = inline_math + inline_math_dollars
37673 end
37674
37675 if tex_math_double_backslash then
37676 display_math = display_math + display_math_double
37677 inline_math = inline_math + inline_math_double
37678 end
37679
37680 if tex_math_single_backslash then
37681 display_math = display_math + display_math_single
37682 inline_math = inline_math + inline_math_single
37683 end
37684
37685 local TexMath = display_math
37686 / function(s)
37687 return writer.display_math(
37688 s, self.parser_functions.parse_inlines_math(s)
37689 )
37690 end
37691 + inline_math
37692 / function(s)
37693 return writer.inline_math(
37694 s, self.parser_functions.parse_inlines_math(s)
37695 )
37696 end
37697
37698 self.insert_pattern("Inline after LinkAndEmph",
37699 TexMath, "TexMath")
37700
37701 if tex_math_dollars then
37702 self.add_special_character("$")
37703 end
37704
37705 if tex_math_single_backslash or tex_math_double_backslash then
37706 self.add_special_character("\\")
37707 self.add_special_character("[")
37708 self.add_special_character("]")
37709 self.add_special_character(")")
37710 self.add_special_character("(")
37711 end
37712 end
37713 }
37714 end
37715 % \end{macrocode}
37716 % \begin{markdown}
37717 %
37718 %#### YAML Metadata
37719 %
37720 % The \luamdef{extensions.jekyll_data} function implements the Pandoc
37721 % YAML metadata block syntax extension. When the
37722 % `expect_jekyll_data` parameter is `true`, then a markdown document
37723 % may begin directly with YAML metadata and may contain nothing
37724 % but YAML metadata. When both `expect_jekyll_data` and
37725 % `ensure_jekyll_data` parameters are `true`, then a a markdown document must
37726 % begin directly with YAML metadata and must contain nothing but
37727 % YAML metadata.
37728 %
37729 % \end{markdown}
37730 % \begin{macrocode}
37731 M.extensions.jekyll_data = function(expect_jekyll_data,
37732 ensure_jekyll_data)
37733 return {
37734 name = "built-in jekyll_data syntax extension",
37735 extend_writer = function(self)
37736 % \end{macrocode}
37737 % \begin{markdown}
37738 %
37739 % Define \luamdef{writer->jekyllData} as a function that will transform an
37740 % input YAML table `d` to the output format. The table is the value for
37741 % the key `p` in the parent table; if `p` is nil, then the table has no parent.
37742 % All scalar keys and values encountered in the table will be cast to a string
37743 % following YAML serialization rules. String values will also be
37744 % transformed using the function `t` for the typographic output format used by
37745 % the \mref{markdownRendererJekyllDataTypographicString} macro.
37746 %
37747 % \end{markdown}
37748 % \begin{macrocode}
37749 function self.jekyllData(d, t, p)
37750 if not self.is_writing then return "" end
37751
37752 local buf = {}
37753
37754 local keys = {}
37755 for k, _ in pairs(d) do
37756 table.insert(keys, k)
37757 end
37758 % \end{macrocode}
37759 % \begin{markdown}
37760 %
37761 % For reproducibility, sort the keys. For mixed string-and-numeric keys, sort
37762 % numeric keys before string keys.
37763 %
37764 % \end{markdown}
37765 % \begin{macrocode}
37766 table.sort(keys, function(first, second)
37767 if type(first) ~= type(second) then
37768 return type(first) < type(second)
37769 else
37770 return first < second
37771 end
37772 end)
37773
37774 if not p then
37775 table.insert(buf, "\\markdownRendererJekyllDataBegin")
37776 end
37777
37778 local is_sequence = false
37779 if #d > 0 and #d == #keys then
37780 for i=1, #d do
37781 if d[i] == nil then
37782 goto not_a_sequence
37783 end
37784 end
37785 is_sequence = true
37786 end
37787 ::not_a_sequence::
37788
37789 if is_sequence then
37790 table.insert(buf,
37791 "\\markdownRendererJekyllDataSequenceBegin{")
37792 table.insert(buf, self.identifier(p or "null"))
37793 table.insert(buf, "}{")
37794 table.insert(buf, #keys)
37795 table.insert(buf, "}")
37796 else
37797 table.insert(buf, "\\markdownRendererJekyllDataMappingBegin{")
37798 table.insert(buf, self.identifier(p or "null"))
37799 table.insert(buf, "}{")
37800 table.insert(buf, #keys)
37801 table.insert(buf, "}")
37802 end
37803
37804 for _, k in ipairs(keys) do
37805 local v = d[k]
37806 local typ = type(v)
37807 k = tostring(k or "null")
37808 if typ == "table" and next(v) ~= nil then
37809 table.insert(
37810 buf,
37811 self.jekyllData(v, t, k)
37812 )
37813 else
37814 k = self.identifier(k)
37815 v = tostring(v)
37816 if typ == "boolean" then
37817 table.insert(buf, "\\markdownRendererJekyllDataBoolean{")
37818 table.insert(buf, k)
37819 table.insert(buf, "}{")
37820 table.insert(buf, v)
37821 table.insert(buf, "}")
37822 elseif typ == "number" then
37823 table.insert(buf, "\\markdownRendererJekyllDataNumber{")
37824 table.insert(buf, k)
37825 table.insert(buf, "}{")
37826 table.insert(buf, v)
37827 table.insert(buf, "}")
37828 elseif typ == "string" then
37829 table.insert(buf,
37830 "\\markdownRendererJekyllDataProgrammaticString{")
37831 table.insert(buf, k)
37832 table.insert(buf, "}{")
37833 table.insert(buf, self.identifier(v))
37834 table.insert(buf, "}")
37835 table.insert(buf,
37836 "\\markdownRendererJekyllDataTypographicString{")
37837 table.insert(buf, k)
37838 table.insert(buf, "}{")
37839 table.insert(buf, t(v))
37840 table.insert(buf, "}")
37841 elseif typ == "table" then
37842 table.insert(buf, "\\markdownRendererJekyllDataEmpty{")
37843 table.insert(buf, k)
37844 table.insert(buf, "}")
37845 else
37846 local error = self.error(format(
37847 "Unexpected type %s for value of "
37848 .. "YAML key %s.", typ, k))
37849 table.insert(buf, error)
37850 end
37851 end
37852 end
37853
37854 if is_sequence then
37855 table.insert(buf, "\\markdownRendererJekyllDataSequenceEnd")
37856 else
37857 table.insert(buf, "\\markdownRendererJekyllDataMappingEnd")
37858 end
37859
37860 if not p then
37861 table.insert(buf, "\\markdownRendererJekyllDataEnd")
37862 end
37863
37864 return buf
37865 end
37866 end, extend_reader = function(self)
37867 local parsers = self.parsers
37868 local writer = self.writer
37869
37870 local JekyllData
37871 = Cmt( C((parsers.line - P("---") - P("..."))^0)
37872 , function(s, i, text) -- luacheck: ignore s i
37873 local data
37874 local ran_ok, _ = pcall(function()
37875 local tinyyaml = require("tinyyaml")
37876 data = tinyyaml.parse(text, {timestamps=false})
37877 end)
37878 if ran_ok and data ~= nil then
37879 return true, writer.jekyllData(data, function(s)
37880 return self.parser_functions.parse_blocks_nested(s)
37881 end, nil)
37882 else
37883 return false
37884 end
37885 end
37886 )
37887
37888 local UnexpectedJekyllData
37889 = P("---")
37890 * parsers.blankline / 0
37891 -- if followed by blank, it's thematic break
37892 * #(-parsers.blankline)
37893 * JekyllData
37894 * (P("---") + P("..."))
37895
37896 local ExpectedJekyllData
37897 = ( P("---")
37898 * parsers.blankline / 0
37899 -- if followed by blank, it's thematic break
37900 * #(-parsers.blankline)
37901 )^-1
37902 * JekyllData
37903 * (P("---") + P("..."))^-1
37904
37905 if ensure_jekyll_data then
37906 ExpectedJekyllData = ExpectedJekyllData
37907 * parsers.eof
37908 else
37909 ExpectedJekyllData = ( ExpectedJekyllData
37910 * (V("Blank")^0 / writer.interblocksep)
37911 )^-1
37912 end
37913
37914 self.insert_pattern("Block before Blockquote",
37915 UnexpectedJekyllData, "UnexpectedJekyllData")
37916 if expect_jekyll_data then
37917 self.update_rule("ExpectedJekyllData", ExpectedJekyllData)
37918 end
37919 end
37920 }
37921 end
37922 % \end{macrocode}
37923 % \begin{markdown}
37924 %
37925 %### Conversion from Markdown to Plain \TeX{}
37926 %
37927 % The \luamref{new} function of file `markdown.lua` loads file
37928 % `markdown-parser.lua` and calls its function \luamref{new} unless option
37929 % \Opt{eagerCache} or \Opt{finalizeCache} has been enabled and a cached
37930 % conversion output exists, in which case it is returned without loading file
37931 % `markdown-parser.lua`.
37932 %
37933 % \end{markdown}
37934 % \iffalse
37935 %</lua>
37936 %<*lua-loader>
37937 % \fi
37938 % \begin{macrocode}
37939 function M.new(options)
37940 % \end{macrocode}
37941 % \begin{markdown}
37942 %
37943 % Make the `options` table inherit from the \luamref{defaultOptions} and
37944 % \luamref{experimentalOptions} tables.
37945 %
37946 % \end{markdown}
37947 % \begin{macrocode}
37948 options = options or {}
37949 setmetatable(options, { __index = function (_, key)
37950 return defaultOptions[key] end })
37951 if options.experimental then
37952 setmetatable(options, { __index = function (_, key)
37953 return experimentalOptions[key] end })
37954 end
37955 % \end{macrocode}
37956 % \begin{markdown}
37957 %
37958 % Return a conversion function that tries to produce a cached conversion output
37959 % exists. If no cached conversion output exists, we load the file
37960 % `markdown-parser.lua` and use it to convert the input.
37961 %
37962 % \end{markdown}
37963 % \begin{macrocode}
37964 local parser_convert = nil
37965 return function(input, include_flat_output)
37966 local function convert(input)
37967 if parser_convert == nil then
37968 % \end{macrocode}
37969 % \begin{markdown}
37970 %
37971 % Lazy-load `markdown-parser.lua` and check that it originates from the same
37972 % version of the Markdown package.
37973 %
37974 % \end{markdown}
37975 % \begin{macrocode}
37976 local parser = require("markdown-parser")
37977 if metadata.version ~= parser.metadata.version then
37978 warn("markdown.lua " .. metadata.version .. " used with " ..
37979 "markdown-parser.lua " .. parser.metadata.version .. ".")
37980 end
37981 parser_convert = parser.new(options)
37982 end
37983 return parser_convert(input)
37984 end
37985 % \end{macrocode}
37986 % \begin{markdown}
37987 % If we cache markdown documents, produce the cache file and transform its
37988 % filename to plain \TeX{} output.
37989 %
37990 % When determining the name of the cache file, create salt for the hashing
37991 % function out of the package version and the passed options recognized by the
37992 % Lua interface (see Section <#sec:lua-options>).
37993 % \end{markdown}
37994 % \begin{macrocode}
37995 local raw_output, flat_output
37996 if options.eagerCache or options.finalizeCache then
37997 local salt = util.salt(options)
37998 local name, result = util.cache(options.cacheDir, input, salt,
37999 convert, ".md.tex")
38000 raw_output = [[\input{]] .. name .. [[}\relax]]
38001 flat_output = function()
38002 if result == nil then
38003 local input_file = assert(io.open(name, "r"),
38004 [[Could not open file "]] .. name .. [[" for reading]])
38005 result = assert(input_file:read("*a"))
38006 assert(input_file:close())
38007 end
38008 return result
38009 end
38010 % \end{macrocode}
38011 % \begin{markdown}
38012 % Otherwise, return the result of the conversion directly.
38013 % \end{markdown}
38014 % \begin{macrocode}
38015 else
38016 raw_output = convert(input)
38017 flat_output = function()
38018 return raw_output
38019 end
38020 end
38021 % \end{macrocode}
38022 % \begin{markdown}
38023 % If the \Opt{finalizeCache} option is enabled, populate the frozen cache in
38024 % the file \Opt{frozenCacheFileName} with an entry for markdown document
38025 % number \Opt{frozenCacheCounter}.
38026 % \end{markdown}
38027 % \begin{macrocode}
38028 if options.finalizeCache then
38029 local file, mode
38030 if options.frozenCacheCounter > 0 then
38031 mode = "a"
38032 else
38033 mode = "w"
38034 end
38035 file = assert(io.open(options.frozenCacheFileName, mode),
38036 [[Could not open file "]] .. options.frozenCacheFileName
38037 .. [[" for writing]])
38038 assert(file:write(
38039 [[\expandafter\global\expandafter\def\csname ]]
38040 .. [[markdownFrozenCache]] .. options.frozenCacheCounter
38041 .. [[\endcsname{]] .. raw_output .. [[}]] .. "\n"))
38042 assert(file:close())
38043 end
38044 % \end{macrocode}
38045 % \begin{markdown}
38046 % Besides the canonical output of the conversion, which may contain cached
38047 % files behind `\input`, also return a function that always produces
38048 % a flat output regardless of caching as the second return value.
38049 % \end{markdown}
38050 % \begin{macrocode}
38051 if include_flat_output then
38052 return raw_output, flat_output
38053 else
38054 return raw_output
38055 end
38056 end
38057 end
38058 % \end{macrocode}
38059 % \iffalse
38060 %</lua-loader>
38061 %<*lua>
38062 % \fi
38063 % \begin{markdown}
38064 %
38065 % The \luamref{new} function from file `markdown-parser.lua` returns a
38066 % conversion function that takes a markdown string and turns it into a plain
38067 % \TeX{} output. See Section <#sec:lua-conversion>.
38068 %
38069 % \end{markdown}
38070 % \begin{macrocode}
38071 function M.new(options)
38072 % \end{macrocode}
38073 % \begin{markdown}
38074 %
38075 % Make the `options` table inherit from the \luamref{defaultOptions} and
38076 % \luamref{experimentalOptions} tables.
38077 %
38078 % \end{markdown}
38079 % \begin{macrocode}
38080 options = options or {}
38081 setmetatable(options, { __index = function (_, key)
38082 return defaultOptions[key] end })
38083 if options.experimental then
38084 setmetatable(options, { __index = function (_, key)
38085 return experimentalOptions[key] end })
38086 end
38087 % \end{macrocode}
38088 % \begin{markdown}
38089 %
38090 % If the singleton cache contains a conversion function for the same `options`,
38091 % reuse it.
38092 %
38093 % \end{markdown}
38094 % \begin{macrocode}
38095 if options.singletonCache and singletonCache.convert then
38096 for k, v in pairs(defaultOptions) do
38097 if type(v) == "table" then
38098 for i = 1, math.max(#singletonCache.options[k], #options[k]) do
38099 if singletonCache.options[k][i] ~= options[k][i] then
38100 goto miss
38101 end
38102 end
38103 % \end{macrocode}
38104 % \begin{markdown}
38105 %
38106 % The \Opt{cacheDir} option is disregarded.
38107 %
38108 % \end{markdown}
38109 % \begin{macrocode}
38110 elseif k ~= "cacheDir"
38111 and singletonCache.options[k] ~= options[k] then
38112 goto miss
38113 end
38114 end
38115 return singletonCache.convert
38116 end
38117 ::miss::
38118 % \end{macrocode}
38119 % \begin{markdown}
38120 %
38121 % Apply built-in syntax extensions based on `options`.
38122 %
38123 % \end{markdown}
38124 % \begin{macrocode}
38125 local extensions = {}
38126
38127 if #options.acronyms > 0 then
38128 local acronyms_extension = M.extensions.acronyms(options.acronyms)
38129 table.insert(extensions, acronyms_extension)
38130 end
38131
38132 if options.bracketedSpans then
38133 local bracketed_spans_extension = M.extensions.bracketed_spans()
38134 table.insert(extensions, bracketed_spans_extension)
38135 end
38136
38137 if options.contentBlocks then
38138 local content_blocks_extension = M.extensions.content_blocks(
38139 options.contentBlocksLanguageMap)
38140 table.insert(extensions, content_blocks_extension)
38141 end
38142
38143 if options.definitionLists then
38144 local definition_lists_extension = M.extensions.definition_lists(
38145 options.tightLists)
38146 table.insert(extensions, definition_lists_extension)
38147 end
38148
38149 if options.fencedCode then
38150 local fenced_code_extension = M.extensions.fenced_code(
38151 options.blankBeforeCodeFence,
38152 options.fencedCodeAttributes,
38153 options.rawAttribute)
38154 table.insert(extensions, fenced_code_extension)
38155 end
38156
38157 if options.fencedDivs then
38158 local fenced_div_extension = M.extensions.fenced_divs(
38159 options.blankBeforeDivFence)
38160 table.insert(extensions, fenced_div_extension)
38161 end
38162
38163 if options.headerAttributes then
38164 local header_attributes_extension = M.extensions.header_attributes()
38165 table.insert(extensions, header_attributes_extension)
38166 end
38167
38168 if options.inlineCodeAttributes then
38169 local inline_code_attributes_extension =
38170 M.extensions.inline_code_attributes()
38171 table.insert(extensions, inline_code_attributes_extension)
38172 end
38173
38174 if options.jekyllData then
38175 local jekyll_data_extension = M.extensions.jekyll_data(
38176 options.expectJekyllData, options.ensureJekyllData)
38177 table.insert(extensions, jekyll_data_extension)
38178 end
38179
38180 if options.linkAttributes then
38181 local link_attributes_extension =
38182 M.extensions.link_attributes()
38183 table.insert(extensions, link_attributes_extension)
38184 end
38185
38186 if options.lineBlocks then
38187 local line_block_extension = M.extensions.line_blocks()
38188 table.insert(extensions, line_block_extension)
38189 end
38190
38191 if options.mark then
38192 local mark_extension = M.extensions.mark()
38193 table.insert(extensions, mark_extension)
38194 end
38195
38196 if options.pipeTables then
38197 local pipe_tables_extension = M.extensions.pipe_tables(
38198 options.tableCaptions, options.tableAttributes)
38199 table.insert(extensions, pipe_tables_extension)
38200 end
38201
38202 if options.rawAttribute then
38203 local raw_inline_extension = M.extensions.raw_inline()
38204 table.insert(extensions, raw_inline_extension)
38205 end
38206
38207 if options.strikeThrough then
38208 local strike_through_extension = M.extensions.strike_through()
38209 table.insert(extensions, strike_through_extension)
38210 end
38211
38212 if options.subscripts then
38213 local subscript_extension = M.extensions.subscripts()
38214 table.insert(extensions, subscript_extension)
38215 end
38216
38217 if options.superscripts then
38218 local superscript_extension = M.extensions.superscripts()
38219 table.insert(extensions, superscript_extension)
38220 end
38221
38222 if options.texMathDollars or
38223 options.texMathSingleBackslash or
38224 options.texMathDoubleBackslash then
38225 local tex_math_extension = M.extensions.tex_math(
38226 options.texMathDollars,
38227 options.texMathSingleBackslash,
38228 options.texMathDoubleBackslash)
38229 table.insert(extensions, tex_math_extension)
38230 end
38231
38232 if options.notes or options.inlineNotes then
38233 local notes_extension = M.extensions.notes(
38234 options.notes, options.inlineNotes)
38235 table.insert(extensions, notes_extension)
38236 end
38237
38238 if options.citations then
38239 local citations_extension
38240 = M.extensions.citations(options.citationNbsps)
38241 table.insert(extensions, citations_extension)
38242 end
38243
38244 if options.fancyLists then
38245 local fancy_lists_extension = M.extensions.fancy_lists()
38246 table.insert(extensions, fancy_lists_extension)
38247 end
38248 % \end{macrocode}
38249 % \begin{markdown}
38250 %
38251 % Apply user-defined syntax extensions based on `options.extensions`.
38252 %
38253 % \end{markdown}
38254 % \begin{macrocode}
38255 for _, user_extension_filename in ipairs(options.extensions) do
38256 local user_extension = (function(filename)
38257 % \end{macrocode}
38258 % \begin{markdown}
38259 %
38260 % First, load and compile the contents of the user-defined syntax extension.
38261 %
38262 % \end{markdown}
38263 % \begin{macrocode}
38264 local pathname = assert(util.find_file(filename),
38265 [[Could not locate user-defined syntax extension "]]
38266 .. filename)
38267 local input_file = assert(io.open(pathname, "r"),
38268 [[Could not open user-defined syntax extension "]]
38269 .. pathname .. [[" for reading]])
38270 local input = assert(input_file:read("*a"))
38271 assert(input_file:close())
38272 local user_extension, err = load([[
38273 local sandbox = {}
38274 setmetatable(sandbox, {__index = _G})
38275 _ENV = sandbox
38276 ]] .. input)()
38277 assert(user_extension,
38278 [[Failed to compile user-defined syntax extension "]]
38279 .. pathname .. [[": ]] .. (err or [[]]))
38280 % \end{macrocode}
38281 % \begin{markdown}
38282 %
38283 % Then, validate the user-defined syntax extension.
38284 %
38285 % \end{markdown}
38286 % \begin{macrocode}
38287 assert(user_extension.api_version ~= nil,
38288 [[User-defined syntax extension "]] .. pathname
38289 .. [[" does not specify mandatory field "api_version"]])
38290 assert(type(user_extension.api_version) == "number",
38291 [[User-defined syntax extension "]] .. pathname
38292 .. [[" specifies field "api_version" of type "]]
38293 .. type(user_extension.api_version)
38294 .. [[" but "number" was expected]])
38295 assert(user_extension.api_version > 0
38296 and user_extension.api_version
38297 <= metadata.user_extension_api_version,
38298 [[User-defined syntax extension "]] .. pathname
38299 .. [[" uses syntax extension API version "]]
38300 .. user_extension.api_version .. [[ but markdown.lua ]]
38301 .. metadata.version .. [[ uses API version ]]
38302 .. metadata.user_extension_api_version
38303 .. [[, which is incompatible]])
38304
38305 assert(user_extension.grammar_version ~= nil,
38306 [[User-defined syntax extension "]] .. pathname
38307 .. [[" does not specify mandatory field "grammar_version"]])
38308 assert(type(user_extension.grammar_version) == "number",
38309 [[User-defined syntax extension "]] .. pathname
38310 .. [[" specifies field "grammar_version" of type "]]
38311 .. type(user_extension.grammar_version)
38312 .. [[" but "number" was expected]])
38313 assert(user_extension.grammar_version == metadata.grammar_version,
38314 [[User-defined syntax extension "]] .. pathname
38315 .. [[" uses grammar version "]]
38316 .. user_extension.grammar_version
38317 .. [[ but markdown.lua ]] .. metadata.version
38318 .. [[ uses grammar version ]] .. metadata.grammar_version
38319 .. [[, which is incompatible]])
38320
38321 assert(user_extension.finalize_grammar ~= nil,
38322 [[User-defined syntax extension "]] .. pathname
38323 .. [[" does not specify mandatory "finalize_grammar" field]])
38324 assert(type(user_extension.finalize_grammar) == "function",
38325 [[User-defined syntax extension "]] .. pathname
38326 .. [[" specifies field "finalize_grammar" of type "]]
38327 .. type(user_extension.finalize_grammar)
38328 .. [[" but "function" was expected]])
38329 % \end{macrocode}
38330 % \begin{markdown}
38331 %
38332 % Finally, cast the user-defined syntax extension to the internal format
38333 % of user extensions used by the Markdown package (see Section
38334 % <#sec:lua-built-in-extensions>.)
38335 %
38336 % \end{markdown}
38337 % \begin{macrocode}
38338 local extension = {
38339 name = [[user-defined "]] .. pathname .. [[" syntax extension]],
38340 extend_reader = user_extension.finalize_grammar,
38341 extend_writer = function() end,
38342 }
38343 return extension
38344 end)(user_extension_filename)
38345 table.insert(extensions, user_extension)
38346 end
38347 % \end{macrocode}
38348 % \begin{markdown}
38349 %
38350 % Produce a conversion function from markdown to plain \TeX.
38351 %
38352 % \end{markdown}
38353 % \begin{macrocode}
38354 local writer = M.writer.new(options)
38355 local reader = M.reader.new(writer, options)
38356 local convert = reader.finalize_grammar(extensions)
38357 % \end{macrocode}
38358 % \begin{markdown}
38359 %
38360 % Force garbage collection to reclaim memory for temporary
38361 % objects created in \luamref{writer.new}, \luamref{reader.new},
38362 % and \luamref{reader->finalize_grammar}.
38363 %
38364 % \end{markdown}
38365 % \begin{macrocode}
38366 collectgarbage("collect")
38367 % \end{macrocode}
38368 % \begin{markdown}
38369 %
38370 % Update the singleton cache.
38371 %
38372 % \end{markdown}
38373 % \begin{macrocode}
38374 if options.singletonCache then
38375 local singletonCacheOptions = {}
38376 for k, v in pairs(options) do
38377 singletonCacheOptions[k] = v
38378 end
38379 setmetatable(singletonCacheOptions,
38380 { __index = function (_, key)
38381 return defaultOptions[key] end })
38382 singletonCache.options = singletonCacheOptions
38383 singletonCache.convert = convert
38384 end
38385 % \end{macrocode}
38386 % \begin{markdown}
38387 %
38388 % Return the conversion function from markdown to plain \TeX.
38389 %
38390 % \end{markdown}
38391 % \begin{macrocode}
38392 return convert
38393 end
38394 % \end{macrocode}
38395 % \iffalse
38396 %</lua>
38397 %<*lua,lua-loader>
38398 % \fi
38399 % \begin{macrocode}
38400 return M
38401 % \end{macrocode}
38402 % \iffalse
38403 %</lua,lua-loader>
38404 %<*lua-cli>
38405 % \fi
38406 % \begin{markdown}
38407 %
38408 %### Command-Line Implementation {#lua-cli-implementation}
38409 %
38410 % The command-line implementation provides the actual conversion routine for
38411 % the command-line interface described in Section <#sec:lua-cli-interface>.
38412 %
38413 % \end{markdown}
38414 % \begin{macrocode}
38415
38416 local input
38417 if input_filename then
38418 local input_file = assert(io.open(input_filename, "r"),
38419 [[Could not open file "]] .. input_filename .. [[" for reading]])
38420 input = assert(input_file:read("*a"))
38421 assert(input_file:close())
38422 else
38423 input = assert(io.read("*a"))
38424 end
38425
38426 % \end{macrocode}
38427 % \begin{markdown}
38428 % First, ensure that the `options.cacheDir` directory exists.
38429 % \end{markdown}
38430 % \begin{macrocode}
38431 local lfs = require("lfs")
38432 if options.cacheDir and not lfs.isdir(options.cacheDir) then
38433 assert(lfs.mkdir(options["cacheDir"]))
38434 end
38435 % \end{macrocode}
38436 % \begin{markdown}
38437 %
38438 % If \pkg{Kpathsea} has not been loaded before or if Lua\TeX{} has not yet
38439 % been initialized, configure \pkg{Kpathsea} on top of loading it.
38440 %
38441 % \end{markdown}
38442 % \begin{macrocode}
38443 local kpse
38444 (function()
38445 local should_initialize = package.loaded.kpse == nil
38446 or tex.initialize ~= nil
38447 kpse = require("kpse")
38448 if should_initialize then
38449 kpse.set_program_name("luatex")
38450 end
38451 end)()
38452 local md = require("markdown")
38453 % \end{macrocode}
38454 % \begin{markdown}
38455 % Since we are loading the rest of the Lua implementation dynamically,
38456 % check that both the `markdown` module and the command line implementation
38457 % are the same version.
38458 % \end{markdown}
38459 % \begin{macrocode}
38460 if metadata.version ~= md.metadata.version then
38461 warn("markdown-cli.lua " .. metadata.version .. " used with " ..
38462 "markdown.lua " .. md.metadata.version .. ".")
38463 end
38464
38465 local convert = md.new(options)
38466 local raw_output, flat_output = convert(input, true)
38467 local output
38468 if flat_output == nil then
38469 if options.eagerCache then
38470 warn("markdown.lua has not produced flat output, so I am using " ..
38471 "backwards-compatible raw output instead. This may cause " ..
38472 'the conversion result to be hidden behind "\\input".')
38473 end
38474 output = raw_output
38475 else
38476 output = flat_output()
38477 end
38478
38479 if output_filename then
38480 local output_file = assert(io.open(output_filename, "w"),
38481 [[Could not open file "]] .. output_filename .. [[" for writing]])
38482 assert(output_file:write(output))
38483 assert(output_file:close())
38484 else
38485 assert(io.write(output))
38486 end
38487 % \end{macrocode}
38488 % \begin{markdown}
38489 % Remove the `options.cacheDir` directory if it is empty.
38490 % \end{markdown}
38491 % \begin{macrocode}
38492 if options.cacheDir then
38493 lfs.rmdir(options.cacheDir)
38494 end
38495 % \end{macrocode}
38496 % \iffalse
38497 %</lua-cli>
38498 %<*tex>
38499 % \fi
38500 % \begin{markdown}
38501 %
38502 % Plain \TeX{} Implementation {#teximplementation}
38503 %-----------------------------
38504 %
38505 % The plain \TeX{} implementation provides macros for the interfacing between
38506 % \TeX{} and Lua and for the buffering of input text. These macros are then
38507 % used to implement the macros for the conversion from markdown to plain \TeX{}
38508 % exposed by the plain \TeX{} interface (see Section <#sec:texinterface>).
38509 %
38510 %### Logging Facilities {#tex-interface-logging}
38511 %
38512 % \end{markdown}
38513 % \begin{macrocode}
38514 \ExplSyntaxOn
38515 \cs_if_free:NT
38516 \markdownInfo
38517 {
38518 \cs_new:Npn
38519 \markdownInfo #1
38520 {
38521 \msg_info:nne
38522 { markdown }
38523 { generic-message }
38524 { #1 }
38525 }
38526 }
38527 \cs_if_free:NT
38528 \markdownWarning
38529 {
38530 \cs_new:Npn
38531 \markdownWarning #1
38532 {
38533 \msg_warning:nne
38534 { markdown }
38535 { generic-message }
38536 { #1 }
38537 }
38538 }
38539 \cs_if_free:NT
38540 \markdownError
38541 {
38542 \cs_new:Npn
38543 \markdownError #1 #2
38544 {
38545 \msg_error:nnee
38546 { markdown }
38547 { generic-message-with-help-text }
38548 { #1 }
38549 { #2 }
38550 }
38551 }
38552 \msg_new:nnn
38553 { markdown }
38554 { generic-message }
38555 { #1 }
38556 \msg_new:nnnn
38557 { markdown }
38558 { generic-message-with-help-text }
38559 { #1 }
38560 { #2 }
38561 \cs_generate_variant:Nn
38562 \msg_info:nnn
38563 { nne }
38564 \cs_generate_variant:Nn
38565 \msg_warning:nnn
38566 { nne }
38567 \cs_generate_variant:Nn
38568 \msg_error:nnnn
38569 { nnee }
38570 \ExplSyntaxOff
38571 % \end{macrocode}
38572 % \begin{markdown}
38573 %
38574 %### Themes {#themes-implementation}
38575 %
38576 % This section implements the theme-loading mechanism and the built-in themes
38577 % provided with the Markdown package. Furthermore, this section also implements
38578 % the built-in plain \TeX{} themes provided with the Markdown package.
38579 %
38580 % \end{markdown}
38581 % \begin{macrocode}
38582 \ExplSyntaxOn
38583 \prop_new:N \g_@@_plain_tex_loaded_themes_linenos_prop
38584 \prop_new:N \g_@@_plain_tex_loaded_themes_versions_prop
38585 \cs_new:Nn
38586 \@@_plain_tex_load_theme:nnn
38587 {
38588 \prop_get:NnNTF
38589 \g_@@_plain_tex_loaded_themes_linenos_prop
38590 { #1 }
38591 \l_tmpa_tl
38592 {
38593 \prop_get:NnN
38594 \g_@@_plain_tex_loaded_themes_versions_prop
38595 { #1 }
38596 \l_tmpb_tl
38597 \str_if_eq:nVTF
38598 { #2 }
38599 \l_tmpb_tl
38600 {
38601 \msg_warning:nnnVn
38602 { markdown }
38603 { repeatedly-loaded-plain-tex-theme }
38604 { #1 }
38605 \l_tmpa_tl
38606 { #2 }
38607 }
38608 {
38609 \msg_error:nnnnVV
38610 { markdown }
38611 { different-versions-of-plain-tex-theme }
38612 { #1 }
38613 { #2 }
38614 \l_tmpb_tl
38615 \l_tmpa_tl
38616 }
38617 }
38618 {
38619 \prop_gput:Nnx
38620 \g_@@_plain_tex_loaded_themes_linenos_prop
38621 { #1 }
38622 { \tex_the:D \tex_inputlineno:D } % noqa: W200
38623 \prop_gput:Nnn
38624 \g_@@_plain_tex_loaded_themes_versions_prop
38625 { #1 }
38626 { #2 }
38627 % \end{macrocode}
38628 % \begin{markdown}
38629 %
38630 % Load built-in plain \TeX{} themes from the prop
38631 % \mref{g_@@_plain_tex_built_in_themes_prop} and from the filesystem otherwise.
38632 %
38633 % \end{markdown}
38634 % \begin{macrocode}
38635 \prop_if_in:NnTF
38636 \g_@@_plain_tex_built_in_themes_prop
38637 { #1 }
38638 {
38639 \msg_info:nnnn
38640 { markdown }
38641 { loading-built-in-plain-tex-theme }
38642 { #1 }
38643 { #2 }
38644 \prop_item:Nn
38645 \g_@@_plain_tex_built_in_themes_prop
38646 { #1 }
38647 }
38648 {
38649 \msg_info:nnnn
38650 { markdown }
38651 { loading-plain-tex-theme }
38652 { #1 }
38653 { #2 }
38654 \file_input:n
38655 { markdown theme #3 }
38656 }
38657 }
38658 }
38659 \msg_new:nnn
38660 { markdown }
38661 { loading-plain-tex-theme }
38662 { Loading~version~#2~of~plain~TeX~Markdown~theme~#1 }
38663 \msg_new:nnn
38664 { markdown }
38665 { loading-built-in-plain-tex-theme }
38666 { Loading~version~#2~of~built-in~plain~TeX~Markdown~theme~#1 }
38667 \msg_new:nnn
38668 { markdown }
38669 { repeatedly-loaded-plain-tex-theme }
38670 {
38671 Version~#3~of~plain~TeX~Markdown~theme~#1~was~previously~
38672 loaded~on~line~#2,~not~loading~it~again
38673 }
38674 \msg_new:nnn
38675 { markdown }
38676 { different-versions-of-plain-tex-theme }
38677 {
38678 Tried~to~load~version~#2~of~plain~TeX~Markdown~theme~#1~
38679 but~version~#3~has~already~been~loaded~on~line~#4
38680 }
38681 \cs_generate_variant:Nn
38682 \prop_gput:Nnn
38683 { Nnx }
38684 \cs_gset_eq:NN
38685 \@@_load_theme:nnn
38686 \@@_plain_tex_load_theme:nnn
38687 \cs_generate_variant:Nn
38688 \@@_load_theme:nnn
38689 { VeV }
38690 \cs_generate_variant:Nn
38691 \msg_error:nnnnnn
38692 { nnnnVV }
38693 \cs_generate_variant:Nn
38694 \msg_warning:nnnnn
38695 { nnnVn }
38696 % \end{macrocode}
38697 % \begin{markdown}
38698 %
38699 % Developers can use the \mref{markdownLoadPlainTeXTheme} macro to load a
38700 % corresponding plain \TeX{} theme from within themes for higher-level \TeX{}
38701 % formats such as \LaTeX{} and \Hologo{ConTeXt}.
38702 %
38703 % \end{markdown}
38704 % \begin{macrocode}
38705 \cs_new:Npn
38706 \markdownLoadPlainTeXTheme
38707 {
38708 % \end{macrocode}
38709 % \begin{markdown}
38710 %
38711 % First, we extract the name of the current theme from the
38712 % \mref{g_@@_current_theme_tl} macro.
38713 %
38714 % \end{markdown}
38715 % \begin{macrocode}
38716 \tl_set:NV
38717 \l_tmpa_tl
38718 \g_@@_current_theme_tl
38719 \tl_reverse:N
38720 \l_tmpa_tl
38721 \tl_set:Ne
38722 \l_tmpb_tl
38723 {
38724 \tl_tail:V
38725 \l_tmpa_tl
38726 }
38727 \tl_reverse:N
38728 \l_tmpb_tl
38729 % \end{macrocode}
38730 % \begin{markdown}
38731 %
38732 % Next, we munge the theme name.
38733 %
38734 % \end{markdown}
38735 % \begin{macrocode}
38736 \str_set:NV
38737 \l_tmpa_str
38738 \l_tmpb_tl
38739 \str_replace_all:Nnn
38740 \l_tmpa_str
38741 { / }
38742 { _ }
38743 % \end{macrocode}
38744 % \begin{markdown}
38745 %
38746 % Finally, we load the plain \TeX{} theme.
38747 %
38748 % \end{markdown}
38749 % \begin{macrocode}
38750 \@@_plain_tex_load_theme:VeV
38751 \l_tmpb_tl
38752 { \markdownThemeVersion }
38753 \l_tmpa_str
38754 }
38755 \cs_generate_variant:Nn
38756 \tl_set:Nn
38757 { Ne }
38758 \cs_generate_variant:Nn
38759 \@@_plain_tex_load_theme:nnn
38760 { VeV }
38761 % \end{macrocode}
38762 % \begin{markdown}
38763 %
38764 % The `witiko/dot` theme nags users that they should use the name
38765 % `witiko/diagrams@v1` instead.
38766 %
38767 % \end{markdown}
38768 % \begin{macrocode}
38769 \prop_gput:Nnn
38770 \g_@@_plain_tex_built_in_themes_prop
38771 { witiko / dot }
38772 {
38773 \str_if_eq:enF
38774 { \markdownThemeVersion }
38775 { silent }
38776 {
38777 \markdownWarning
38778 {
38779 The~theme~name~"witiko/dot"~has~been~soft-deprecated.
38780 \iow_newline:
38781 Consider~changing~the~name~to~"witiko/diagrams@v1".
38782 }
38783 }
38784 % \end{macrocode}
38785 % \begin{markdown}
38786 %
38787 % We enable the \Opt{fencedCode} Lua option.
38788 %
38789 % \end{markdown}
38790 % \begin{macrocode}
38791 \markdownSetup { fencedCode }
38792 % \end{macrocode}
38793 % \begin{markdown}
38794 %
38795 % We store the previous definition of the fenced code token renderer prototype:
38796 %
38797 % \end{markdown}
38798 % \begin{macrocode}
38799 \cs_set_eq:NN
38800 \@@_dot_previous_definition:nnn
38801 \markdownRendererInputFencedCodePrototype
38802 % \end{macrocode}
38803 % \begin{markdown}
38804 %
38805 % If the infostring starts with `dot …`, we redefine the fenced code block
38806 % token renderer prototype, so that it typesets the code block via Graphviz
38807 % tools if and only if the \Opt{frozenCache} plain \TeX{} option is
38808 % disabled and the code block has not been previously typeset:
38809 %
38810 % \end{markdown}
38811 % \begin{macrocode}
38812 \regex_const:Nn
38813 \c_@@_dot_infostring_regex
38814 { ^dot(\s+(.+))? }
38815 \seq_new:N
38816 \l_@@_dot_matches_seq
38817 \markdownSetup {
38818 rendererPrototypes = {
38819 inputFencedCode = {
38820 \regex_extract_once:NnNTF
38821 \c_@@_dot_infostring_regex
38822 { #2 }
38823 \l_@@_dot_matches_seq
38824 {
38825 \@@_if_option:nF
38826 { frozenCache }
38827 {
38828 \sys_shell_now:n
38829 {
38830 if~!~test~-e~#1.pdf.source~
38831 ||~!~diff~#1~#1.pdf.source;
38832 then~
38833 dot~-Tpdf~-o~#1.pdf~#1;
38834 cp~#1~#1.pdf.source;
38835 fi
38836 }
38837 }
38838 % \end{macrocode}
38839 % \begin{markdown}
38840 %
38841 % We include the typeset image using the image token renderer:
38842 %
38843 % \end{markdown}
38844 % \begin{macrocode}
38845 \exp_args:NNne
38846 \exp_last_unbraced:No
38847 \markdownRendererImage
38848 {
38849 { Graphviz~image }
38850 { #1.pdf }
38851 { #1.pdf }
38852 }
38853 {
38854 \seq_item:Nn
38855 \l_@@_dot_matches_seq
38856 { 3 }
38857 }
38858 }
38859 % \end{macrocode}
38860 % \begin{markdown}
38861 %
38862 % If the infostring does not start with `dot …`, we use the previous definition
38863 % of the fenced code token renderer prototype:
38864 %
38865 % \end{markdown}
38866 % \begin{macrocode}
38867 {
38868 \@@_dot_previous_definition:nnn
38869 { #1 }
38870 { #2 }
38871 { #3 }
38872 }
38873 },
38874 },
38875 }
38876 }
38877 % \end{macrocode}
38878 % \begin{markdown}
38879 %
38880 % The theme `witiko/diagrams` loads either the theme `witiko/dot` for version
38881 % `v1` or the theme `witiko/diagrams/v2` for version `v2`.
38882 %
38883 % \end{markdown}
38884 % \begin{macrocode}
38885 \prop_gput:Nnn
38886 \g_@@_plain_tex_built_in_themes_prop
38887 { witiko / diagrams }
38888 {
38889 \str_case:enF
38890 { \markdownThemeVersion }
38891 {
38892 { latest }
38893 {
38894 \msg_warning:nnnn
38895 { markdown }
38896 { pin-theme-version }
38897 { witiko/diagrams }
38898 { v2 }
38899 \markdownSetup
38900 {
38901 import = witiko/diagrams/v2,
38902 }
38903 }
38904 { v2 }
38905 {
38906 \markdownSetup
38907 {
38908 import = witiko/diagrams/v2,
38909 }
38910 }
38911 { v1 }
38912 {
38913 \markdownSetup
38914 {
38915 import = witiko/dot@silent,
38916 }
38917 }
38918 }
38919 {
38920 \msg_error:nnnen
38921 { markdown }
38922 { unknown-theme-version }
38923 { witiko/diagrams }
38924 { \markdownThemeVersion }
38925 { v1~and~v2 }
38926 }
38927 }
38928 \cs_generate_variant:Nn
38929 \msg_error:nnnnn
38930 { nnnen }
38931 \msg_new:nnn
38932 { markdown }
38933 { pin-theme-version }
38934 {
38935 Write~"#1@#2"~to~pin~version~"#2"~of~the~theme~"#1".
38936 This~will~keep~your~documents~from~suddenly~breaking
38937 when~we~have~released~future~versions~of~the~theme
38938 with~backwards-incompatible~syntax~and~behavior.
38939 }
38940 \msg_new:nnnn
38941 { markdown }
38942 { unknown-theme-version }
38943 { Unknown~version~"#2"~of~theme~"#1"~has~been~requested. }
38944 { Known~versions~are:~#3 }
38945 % \end{macrocode}
38946 % \begin{markdown}
38947 %
38948 % Next, we implement the theme `witiko/diagrams/v2`.
38949 %
38950 % \end{markdown}
38951 % \begin{macrocode}
38952 \prop_gput:Nnn
38953 \g_@@_plain_tex_built_in_themes_prop
38954 { witiko / diagrams / v2 }
38955 {
38956 % \end{macrocode}
38957 % \begin{markdown}
38958 %
38959 % We enable the \Opt{fencedCode} and \Opt{fencedCodeAttributes} Lua
38960 % option.
38961 %
38962 % \end{markdown}
38963 % \begin{macrocode}
38964 \@@_setup:n
38965 {
38966 fencedCode = true,
38967 fencedCodeAttributes = true,
38968 }
38969 % \end{macrocode}
38970 % \begin{markdown}
38971 %
38972 % Store the previous fenced code token renderer prototype.
38973 %
38974 % \end{markdown}
38975 % \begin{macrocode}
38976 \cs_set_eq:NN
38977 \@@_diagrams_previous_fenced_code:nnn
38978 \markdownRendererInputFencedCodePrototype
38979 % \end{macrocode}
38980 % \begin{markdown}
38981 %
38982 % Store the caption, the desired format, and the command to produce the
38983 % diagram.
38984 %
38985 % \end{markdown}
38986 % \begin{macrocode}
38987 \tl_new:N
38988 \l_@@_diagrams_caption_tl
38989 \tl_new:N
38990 \l_@@_diagrams_format_tl
38991 \tl_set:Nn
38992 \l_@@_diagrams_format_tl
38993 { pdf }
38994 \tl_new:N
38995 \l_@@_diagrams_command_tl
38996 \@@_setup:n
38997 {
38998 rendererPrototypes = {
38999 % \end{macrocode}
39000 % \begin{markdown}
39001 %
39002 % Route attributes on fenced code blocks to the image attribute renderer
39003 % prototypes.
39004 %
39005 % \end{markdown}
39006 % \begin{macrocode}
39007 fencedCodeAttributeContextBegin = {
39008 \group_begin:
39009 \markdownRendererImageAttributeContextBegin
39010 \cs_set_eq:NN
39011 \@@_diagrams_previous_key_value:nn
39012 \markdownRendererAttributeKeyValuePrototype
39013 \@@_setup:n
39014 {
39015 rendererPrototypes = {
39016 attributeKeyValue = {
39017 \str_case:nnF
39018 { ##1 }
39019 {
39020 { caption }
39021 {
39022 \tl_set:Nn
39023 \l_@@_diagrams_caption_tl
39024 { ##2 }
39025 }
39026 { format }
39027 {
39028 \tl_set:Nn
39029 \l_@@_diagrams_format_tl
39030 { ##2 }
39031 }
39032 { command }
39033 {
39034 \tl_set:Nn
39035 \l_@@_diagrams_command_tl
39036 { ##2 }
39037 }
39038 }
39039 {
39040 \@@_diagrams_previous_key_value:nn
39041 { ##1 }
39042 { ##2 }
39043 }
39044 },
39045 },
39046 }
39047 },
39048 fencedCodeAttributeContextEnd = {
39049 \markdownRendererImageAttributeContextEnd
39050 \group_end:
39051 },
39052 },
39053 }
39054 \cs_new:Nn
39055 \@@_diagrams_render_diagram:nnnn
39056 {
39057 \@@_if_option:nF
39058 { frozenCache }
39059 {
39060 \sys_shell_now:n
39061 {
39062 if~!~test~-e~#2.source~
39063 ||~!~diff~#1~#2.source;
39064 then~
39065 (#3);
39066 cp~#1~#2.source;
39067 fi
39068 }
39069 \exp_args:NNnV
39070 \exp_last_unbraced:No
39071 \markdownRendererImage
39072 {
39073 { #4 }
39074 { #2 }
39075 { #2 }
39076 }
39077 \l_@@_diagrams_caption_tl
39078 }
39079 }
39080 % \end{macrocode}
39081 % \begin{markdown}
39082 %
39083 % Use the prop \mdef{g_markdown_diagrams_infostrings_prop} to determine how the
39084 % code with a given infostring should be processed and routed to the token
39085 % renderer prototype(s) for images.
39086 %
39087 % \end{markdown}
39088 % \begin{macrocode}
39089 \prop_new:N
39090 \g_markdown_diagrams_infostrings_prop
39091 % \end{macrocode}
39092 % \begin{markdown}
39093 %
39094 % If we know a processing function for a given infostring, use it.
39095 %
39096 % \end{markdown}
39097 % \begin{macrocode}
39098 \@@_setup:n
39099 {
39100 rendererPrototypes = {
39101 inputFencedCode = {
39102 \prop_get:NnNTF
39103 \g_markdown_diagrams_infostrings_prop
39104 { #2 }
39105 \l_tmpa_tl
39106 {
39107 \cs_set:NV
39108 \@@_diagrams_infostrings_current:n
39109 \l_tmpa_tl
39110 \@@_diagrams_infostrings_current:n
39111 { #1 }
39112 }
39113 % \end{macrocode}
39114 % \begin{markdown}
39115 %
39116 % Otherwise, use the previous fenced code token renderer prototype.
39117 %
39118 % \end{markdown}
39119 % \begin{macrocode}
39120 {
39121 \@@_diagrams_previous_fenced_code:nnn
39122 { #1 }
39123 { #2 }
39124 { #3 }
39125 }
39126 },
39127 },
39128 }
39129 \cs_generate_variant:Nn
39130 \cs_set:Nn
39131 { NV }
39132 % \end{macrocode}
39133 % \begin{markdown}
39134 %
39135 % Typeset fenced code with infostring `dot` using the command `dot` from
39136 % the package Graphviz.
39137 %
39138 % \end{markdown}
39139 % \begin{macrocode}
39140 \cs_set:Nn
39141 \@@_diagrams_infostrings_current:n
39142 {
39143 \tl_set:Nn
39144 \l_tmpb_tl
39145 { dot~-T }
39146 \tl_put_right:NV
39147 \l_tmpb_tl
39148 \l_@@_diagrams_format_tl
39149 \tl_put_right:Nn
39150 \l_tmpb_tl
39151 { ~-o~#1. }
39152 \tl_put_right:NV
39153 \l_tmpb_tl
39154 \l_@@_diagrams_format_tl
39155 \tl_put_right:Nn
39156 \l_tmpb_tl
39157 { ~#1 }
39158 % \end{macrocode}
39159 % \begin{markdown}
39160 %
39161 % For the SVG format, use Inkscape to convert the resulting image to PDF.
39162 %
39163 % \end{markdown}
39164 % \begin{macrocode}
39165 \str_if_eq:VnT
39166 \l_@@_diagrams_format_tl
39167 { svg }
39168 {
39169 \tl_put_right:Nn
39170 \l_tmpb_tl
39171 { ;~inkscape~#1. }
39172 \tl_put_right:NV
39173 \l_tmpb_tl
39174 \l_@@_diagrams_format_tl
39175 \tl_put_right:Nn
39176 \l_tmpb_tl
39177 { ~--export-area-drawing~--export-dpi=300~-o~#1.pdf }
39178 }
39179 \@@_diagrams_render_diagram:nnVn
39180 { #1 }
39181 { #1.pdf }
39182 \l_tmpb_tl
39183 { Graphviz~image }
39184 }
39185 \cs_generate_variant:Nn
39186 \@@_diagrams_render_diagram:nnnn
39187 { nnVn }
39188 \@@_tl_set_from_cs:NNn
39189 \l_tmpa_tl
39190 \@@_diagrams_infostrings_current:n
39191 { 1 }
39192 \prop_gput:NnV
39193 \g_markdown_diagrams_infostrings_prop
39194 { dot }
39195 \l_tmpa_tl
39196 % \end{macrocode}
39197 % \begin{markdown}
39198 %
39199 % Typeset fenced code with infostring `mermaid` using the command `mmdc` from
39200 % the npm package `@mermaid-js/mermaid-cli`. The exact command can be
39201 % configured by redefining or appending to the
39202 % \mdef{g_@@_diagrams_mmdc_command_tl} token list, by redefining the
39203 % \mdef{mmdcCommand} macro, or using the HTML attribute `command`
39204 % on the fenced code.
39205 %
39206 % Unlike the token list, the macro can be redefined even before loading the
39207 % Markdown package. Unlike the token list and the macro, the HTML
39208 % attribute is local to a single fenced code.
39209 %
39210 % \end{markdown}
39211 % \begin{macrocode}
39212 \tl_new:N
39213 \g_@@_diagrams_mmdc_command_tl
39214 \tl_gset:Nn
39215 \g_@@_diagrams_mmdc_command_tl
39216 {
39217 \tl_if_empty:NTF
39218 \l_@@_diagrams_command_tl
39219 { mmdc }
39220 {
39221 \tl_use:N
39222 \l_@@_diagrams_command_tl
39223 }
39224 }
39225 \cs_if_free:NT
39226 \mmdcCommand
39227 {
39228 \cs_new:Npn
39229 \mmdcCommand
39230 {
39231 \tl_use:N
39232 \g_@@_diagrams_mmdc_command_tl
39233 }
39234 }
39235 \cs_set:Nn
39236 \@@_diagrams_infostrings_current:n
39237 {
39238 \tl_set:Nx
39239 \l_tmpb_tl
39240 { \mmdcCommand }
39241 \tl_put_right:Nn
39242 \l_tmpb_tl
39243 { ~--pdfFit~-i~#1~-o~#1.pdf }
39244 \@@_diagrams_render_diagram:nnVn
39245 { #1 }
39246 { #1.pdf }
39247 \l_tmpb_tl
39248 { Mermaid~image }
39249 }
39250 \@@_tl_set_from_cs:NNn
39251 \l_tmpa_tl
39252 \@@_diagrams_infostrings_current:n
39253 { 1 }
39254 \prop_gput:NnV
39255 \g_markdown_diagrams_infostrings_prop
39256 { mermaid }
39257 \l_tmpa_tl
39258 % \end{macrocode}
39259 % \begin{markdown}
39260 %
39261 % Typeset fenced code with infostring `plantuml` using the command `plantuml`
39262 % from the package PlantUML.
39263 %
39264 % \end{markdown}
39265 % \begin{macrocode}
39266 \regex_const:Nn
39267 \c_@@_diagrams_filename_suffix_regex
39268 { \.[^.]*$ }
39269 \cs_set:Nn
39270 \@@_diagrams_infostrings_current:n
39271 {
39272 % \end{macrocode}
39273 % \begin{markdown}
39274 %
39275 % Use the output format provided by the user.
39276 %
39277 % \end{markdown}
39278 % \begin{macrocode}
39279 \tl_set:Nn
39280 \l_tmpa_tl
39281 { #1 }
39282 \regex_replace_once:NxN
39283 \c_@@_diagrams_filename_suffix_regex
39284 {
39285 .
39286 \tl_use:N
39287 \l_@@_diagrams_format_tl
39288 }
39289 \l_tmpa_tl
39290 \tl_set:Nn
39291 \l_tmpb_tl
39292 { plantuml~-t }
39293 \tl_put_right:NV
39294 \l_tmpb_tl
39295 \l__markdown_diagrams_format_tl
39296 \tl_put_right:Nn
39297 \l_tmpb_tl
39298 { ~#1 }
39299 % \end{macrocode}
39300 % \begin{markdown}
39301 %
39302 % For the SVG format, use Inkscape to convert the resulting image to PDF.
39303 %
39304 % \end{markdown}
39305 % \begin{macrocode}
39306 \str_if_eq:VnT
39307 \l_@@_diagrams_format_tl
39308 { svg }
39309 {
39310 \tl_put_right:Nn
39311 \l_tmpb_tl
39312 { ;~inkscape~ }
39313 \tl_put_right:NV
39314 \l_tmpb_tl
39315 \l_tmpa_tl
39316 \tl_put_right:Nn
39317 \l_tmpb_tl
39318 { ~--export-area-drawing~--export-dpi=300~-o~ }
39319 \tl_set:Nn
39320 \l_tmpa_tl
39321 { #1 }
39322 \regex_replace_once:NnN
39323 \c_@@_diagrams_filename_suffix_regex
39324 { .pdf }
39325 \l_tmpa_tl
39326 \tl_put_right:NV
39327 \l_tmpb_tl
39328 \l_tmpa_tl
39329 }
39330 \@@_diagrams_render_diagram:nVVn
39331 { #1 }
39332 \l_tmpa_tl
39333 \l_tmpb_tl
39334 { PlantUML~image }
39335 }
39336 \cs_generate_variant:Nn
39337 \@@_diagrams_render_diagram:nnnn
39338 { nVVn }
39339 \cs_generate_variant:Nn
39340 \regex_replace_once:NnN
39341 { NxN }
39342 \@@_tl_set_from_cs:NNn
39343 \l_tmpa_tl
39344 \@@_diagrams_infostrings_current:n
39345 { 1 }
39346 \prop_gput:NnV
39347 \g_markdown_diagrams_infostrings_prop
39348 { plantuml }
39349 \l_tmpa_tl
39350 }
39351 % \end{macrocode}
39352 % \begin{markdown}
39353 %
39354 % We locally change the category code of percent signs, so that we
39355 % can use them in the shell code:
39356 %
39357 % \end{markdown}
39358 % \begin{macrocode}
39359 \group_begin:
39360 \char_set_catcode_other:N \%
39361 % \end{macrocode}
39362 % \begin{markdown}
39363 %
39364 % The `witiko/graphicx/http` theme stores the previous definition of the image
39365 % token renderer prototype:
39366 %
39367 % \end{markdown}
39368 % \begin{macrocode}
39369 \prop_gput:Nnn
39370 \g_@@_plain_tex_built_in_themes_prop
39371 { witiko / graphicx / http }
39372 {
39373 \cs_set_eq:NN
39374 \@@_graphicx_http_previous_definition:nnnn
39375 \markdownRendererImagePrototype
39376 % \end{macrocode}
39377 % \begin{markdown}
39378 %
39379 % We define variables and functions to enumerate the images for caching and to
39380 % store the pathname of the file containing the pathname of the downloaded
39381 % image file.
39382 %
39383 % \end{markdown}
39384 % \begin{macrocode}
39385 \int_new:N
39386 \g_@@_graphicx_http_image_number_int
39387 \int_gset:Nn
39388 \g_@@_graphicx_http_image_number_int
39389 { 0 }
39390 \cs_new:Nn
39391 \@@_graphicx_http_filename:
39392 {
39393 \markdownOptionCacheDir
39394 / witiko_graphicx_http .
39395 \int_use:N
39396 \g_@@_graphicx_http_image_number_int
39397 }
39398 % \end{macrocode}
39399 % \begin{markdown}
39400 %
39401 % We define a function that will receive two arguments that correspond to the
39402 % URL of the online image and to the pathname, where the online image should
39403 % be downloaded. The function produces a shell command that tries to
39404 % downloads the online image to the pathname.
39405 %
39406 % \end{markdown}
39407 % \begin{macrocode}
39408 \cs_new:Nn
39409 \@@_graphicx_http_download:nn
39410 {
39411 wget~-O~#2~#1~
39412 ||~curl~--location~-o~#2~#1~
39413 ||~rm~-f~#2
39414 }
39415 % \end{macrocode}
39416 % \begin{markdown}
39417 %
39418 % We redefine the image token renderer prototype, so that it tries to download
39419 % an online image.
39420 %
39421 % \end{markdown}
39422 % \begin{macrocode}
39423 \str_new:N
39424 \l_@@_graphicx_http_filename_str
39425 \ior_new:N
39426 \g_@@_graphicx_http_filename_ior
39427 \markdownSetup {
39428 rendererPrototypes = {
39429 image = {
39430 \@@_if_option:nF
39431 { frozenCache }
39432 {
39433 % \end{macrocode}
39434 % \begin{markdown}
39435 %
39436 % The image will be downloaded only if the image URL has the http or https
39437 % protocols and the \Opt{frozenCache} plain \TeX{} option is disabled:
39438 %
39439 % \end{markdown}
39440 % \begin{macrocode}
39441 \sys_shell_now:e
39442 {
39443 mkdir~-p~" \markdownOptionCacheDir ";
39444 if~printf~'%s'~"#3"~|~grep~-q~-E~'^https?:';
39445 then~
39446 % \end{macrocode}
39447 % \begin{markdown}
39448 %
39449 % The image will be downloaded to the pathname \Opt{cacheDir}<!--
39450 % -->`/`\meta{the MD5 digest of the image URL}`.`\meta{the suffix of the
39451 % image URL}:
39452 %
39453 % \end{markdown}
39454 % \begin{macrocode}
39455 OUTPUT_PREFIX=" \markdownOptionCacheDir ";
39456 OUTPUT_BODY="$(printf~'%s'~'#3'
39457 |~md5sum~|~cut~-d'~'~-f1)";
39458 OUTPUT_SUFFIX="$(printf~'%s'~'#3'
39459 |~sed~'s/.*[.]//')";
39460 OUTPUT="$OUTPUT_PREFIX/$OUTPUT_BODY.$OUTPUT_SUFFIX";
39461 % \end{macrocode}
39462 % \begin{markdown}
39463 %
39464 % The image will be downloaded only if it has not already been downloaded:
39465 %
39466 % \end{markdown}
39467 % \begin{macrocode}
39468 if~!~[~-e~"$OUTPUT"~];
39469 then~
39470 \@@_graphicx_http_download:nn
39471 { '#3' }
39472 { "$OUTPUT" } ;
39473 printf~'%s'~"$OUTPUT"~
39474 >~" \@@_graphicx_http_filename: ";
39475 fi;
39476 % \end{macrocode}
39477 % \begin{markdown}
39478 %
39479 % If the image does not have the http or https protocols or the image has
39480 % already been downloaded, the URL will be stored as-is:
39481 %
39482 % \end{markdown}
39483 % \begin{macrocode}
39484 else~
39485 printf~'%s'~'#3'~
39486 >~" \@@_graphicx_http_filename: ";
39487 fi
39488 }
39489 }
39490 % \end{macrocode}
39491 % \begin{markdown}
39492 %
39493 % We load the pathname of the downloaded image and we typeset the image using
39494 % the previous definition of the image renderer prototype:
39495 %
39496 % \end{markdown}
39497 % \begin{macrocode}
39498 \ior_open:Ne
39499 \g_@@_graphicx_http_filename_ior
39500 { \@@_graphicx_http_filename: }
39501 \ior_str_get:NN
39502 \g_@@_graphicx_http_filename_ior
39503 \l_@@_graphicx_http_filename_str
39504 \ior_close:N
39505 \g_@@_graphicx_http_filename_ior
39506 \@@_graphicx_http_previous_definition:nnVn
39507 { #1 }
39508 { #2 }
39509 \l_@@_graphicx_http_filename_str
39510 { #4 }
39511 \int_gincr:N
39512 \g_@@_graphicx_http_image_number_int
39513 }
39514 }
39515 }
39516 \cs_generate_variant:Nn
39517 \ior_open:Nn
39518 { Ne }
39519 \cs_generate_variant:Nn
39520 \@@_graphicx_http_previous_definition:nnnn
39521 { nnVn }
39522 }
39523 \group_end:
39524 % \end{macrocode}
39525 % \begin{markdown}
39526 %
39527 % The `witiko/tilde` theme redefines the tilde token renderer prototype,
39528 % so that it expands to a non-breaking space:
39529 %
39530 % \end{markdown}
39531 % \begin{macrocode}
39532 \prop_gput:Nnn
39533 \g_@@_plain_tex_built_in_themes_prop
39534 { witiko / tilde }
39535 {
39536 \markdownSetup {
39537 rendererPrototypes = {
39538 tilde = {~},
39539 },
39540 }
39541 }
39542 % \end{macrocode}
39543 % \begin{markdown}
39544 %
39545 % The themes `witiko/example/foo` and `witiko/example/bar` are supposed to be
39546 % used in code examples. They don't do anything.
39547 %
39548 % \end{markdown}
39549 % \begin{macrocode}
39550 \clist_map_inline:nn
39551 { foo, bar }
39552 {
39553 \prop_gput:Nnn
39554 \g_@@_plain_tex_built_in_themes_prop
39555 { witiko / example / #1 }
39556 {
39557 \markdownWarning
39558 {
39559 The~theme~witiko/example/#1~is~supposed~to~be~used~in~code~
39560 examples.~Using~it~in~actual~code~has~no~effect,~except~
39561 this~warning~message,~and~is~usually~a~mistake.
39562 }
39563 }
39564 }
39565 \ExplSyntaxOff
39566 % \end{macrocode}
39567 % \iffalse
39568 %</tex>
39569 %<*themes-witiko-markdown-defaults-tex>
39570 % \fi
39571 % \begin{markdown}
39572 %
39573 % The `witiko/markdown/defaults` plain \TeX{} theme provides default
39574 % definitions for token renderer prototypes. See Section
39575 % <#sec:tex-token-renderer-prototypes> for the actual definitions.
39576 %
39577 %### Token Renderer Prototypes {#tex-token-renderer-prototypes}
39578 %
39579 % The following definitions should be considered placeholder.
39580 %
39581 % \end{markdown}
39582 % \begin{macrocode}
39583 \def\markdownRendererInterblockSeparatorPrototype{\par}%
39584 \def\markdownRendererParagraphSeparatorPrototype{%
39585 \markdownRendererInterblockSeparator}%
39586 \def\markdownRendererHardLineBreakPrototype{\hfil\break}%
39587 \def\markdownRendererSoftLineBreakPrototype{ }%
39588 \let\markdownRendererEllipsisPrototype\dots
39589 \def\markdownRendererNbspPrototype{~}%
39590 \def\markdownRendererLeftBracePrototype{\char`\{}%
39591 \def\markdownRendererRightBracePrototype{\char`\}}%
39592 \def\markdownRendererDollarSignPrototype{\char`$}%
39593 \def\markdownRendererPercentSignPrototype{\char`\%}%
39594 \def\markdownRendererAmpersandPrototype{\&}%
39595 \def\markdownRendererUnderscorePrototype{\char`_}%
39596 \def\markdownRendererHashPrototype{\char`\#}%
39597 \def\markdownRendererCircumflexPrototype{\char`^}%
39598 \def\markdownRendererBackslashPrototype{\char`\\}%
39599 \def\markdownRendererTildePrototype{\char`~}%
39600 \def\markdownRendererPipePrototype{|}%
39601 \def\markdownRendererCodeSpanPrototype#1{{\tt#1}}%
39602 \def\markdownRendererLinkPrototype#1#2#3#4{#2}%
39603 \def\markdownRendererContentBlockPrototype#1#2#3#4{%
39604 \markdownInput{#3}}%
39605 \def\markdownRendererContentBlockOnlineImagePrototype{%
39606 \markdownRendererImage}%
39607 \def\markdownRendererContentBlockCodePrototype#1#2#3#4#5{%
39608 \markdownRendererInputFencedCode{#3}{#2}{#2}}%
39609 \def\markdownRendererImagePrototype#1#2#3#4{#2}%
39610 \def\markdownRendererUlBeginPrototype{}%
39611 \def\markdownRendererUlBeginTightPrototype{}%
39612 \def\markdownRendererUlItemPrototype{}%
39613 \def\markdownRendererUlItemEndPrototype{}%
39614 \def\markdownRendererUlEndPrototype{}%
39615 \def\markdownRendererUlEndTightPrototype{}%
39616 \def\markdownRendererOlBeginPrototype{}%
39617 \def\markdownRendererOlBeginTightPrototype{}%
39618 \def\markdownRendererFancyOlBeginPrototype#1#2{%
39619 \markdownRendererOlBegin}%
39620 \def\markdownRendererFancyOlBeginTightPrototype#1#2{%
39621 \markdownRendererOlBeginTight}%
39622 \def\markdownRendererOlItemPrototype{}%
39623 \def\markdownRendererOlItemWithNumberPrototype#1{}%
39624 \def\markdownRendererOlItemEndPrototype{}%
39625 \def\markdownRendererFancyOlItemPrototype{\markdownRendererOlItem}%
39626 \def\markdownRendererFancyOlItemWithNumberPrototype{%
39627 \markdownRendererOlItemWithNumber}%
39628 \def\markdownRendererFancyOlItemEndPrototype{}%
39629 \def\markdownRendererOlEndPrototype{}%
39630 \def\markdownRendererOlEndTightPrototype{}%
39631 \def\markdownRendererFancyOlEndPrototype{\markdownRendererOlEnd}%
39632 \def\markdownRendererFancyOlEndTightPrototype{%
39633 \markdownRendererOlEndTight}%
39634 \def\markdownRendererDlBeginPrototype{}%
39635 \def\markdownRendererDlBeginTightPrototype{}%
39636 \def\markdownRendererDlItemPrototype#1{#1}%
39637 \def\markdownRendererDlItemEndPrototype{}%
39638 \def\markdownRendererDlDefinitionBeginPrototype{}%
39639 \def\markdownRendererDlDefinitionEndPrototype{\par}%
39640 \def\markdownRendererDlEndPrototype{}%
39641 \def\markdownRendererDlEndTightPrototype{}%
39642 \def\markdownRendererEmphasisPrototype#1{{\it#1}}%
39643 \def\markdownRendererStrongEmphasisPrototype#1{{\bf#1}}%
39644 \def\markdownRendererBlockQuoteBeginPrototype{\begingroup\it}%
39645 \def\markdownRendererBlockQuoteEndPrototype{\endgroup\par}%
39646 \def\markdownRendererLineBlockBeginPrototype{\begingroup\parindent=0pt}%
39647 \def\markdownRendererLineBlockEndPrototype{\endgroup}%
39648 \def\markdownRendererInputVerbatimPrototype#1{%
39649 \par{\tt\input#1\relax{}}\par}%
39650 \def\markdownRendererInputFencedCodePrototype#1#2#3{%
39651 \markdownRendererInputVerbatim{#1}}%
39652 \def\markdownRendererHeadingOnePrototype#1{#1}%
39653 \def\markdownRendererHeadingTwoPrototype#1{#1}%
39654 \def\markdownRendererHeadingThreePrototype#1{#1}%
39655 \def\markdownRendererHeadingFourPrototype#1{#1}%
39656 \def\markdownRendererHeadingFivePrototype#1{#1}%
39657 \def\markdownRendererHeadingSixPrototype#1{#1}%
39658 \def\markdownRendererThematicBreakPrototype{}%
39659 \def\markdownRendererNotePrototype#1{#1}%
39660 \def\markdownRendererCitePrototype#1{}%
39661 \def\markdownRendererTextCitePrototype#1{}%
39662 \def\markdownRendererTickedBoxPrototype{[X]}%
39663 \def\markdownRendererHalfTickedBoxPrototype{[/]}%
39664 \def\markdownRendererUntickedBoxPrototype{[ ]}%
39665 \def\markdownRendererStrikeThroughPrototype#1{#1}%
39666 \def\markdownRendererSuperscriptPrototype#1{#1}%
39667 \def\markdownRendererSubscriptPrototype#1{#1}%
39668 \def\markdownRendererDisplayMathPrototype#1{$$#1$$}%
39669 \def\markdownRendererInlineMathPrototype#1{$#1$}%
39670 \ExplSyntaxOn
39671 \cs_gset:Npn
39672 \markdownRendererHeaderAttributeContextBeginPrototype
39673 {
39674 \group_begin:
39675 \color_group_begin:
39676 }
39677 \cs_gset:Npn
39678 \markdownRendererHeaderAttributeContextEndPrototype
39679 {
39680 \color_group_end:
39681 \group_end:
39682 }
39683 \cs_gset_eq:NN
39684 \markdownRendererBracketedSpanAttributeContextBeginPrototype
39685 \markdownRendererHeaderAttributeContextBeginPrototype
39686 \cs_gset_eq:NN
39687 \markdownRendererBracketedSpanAttributeContextEndPrototype
39688 \markdownRendererHeaderAttributeContextEndPrototype
39689 \cs_gset_eq:NN
39690 \markdownRendererFencedDivAttributeContextBeginPrototype
39691 \markdownRendererHeaderAttributeContextBeginPrototype
39692 \cs_gset_eq:NN
39693 \markdownRendererFencedDivAttributeContextEndPrototype
39694 \markdownRendererHeaderAttributeContextEndPrototype
39695 \cs_gset_eq:NN
39696 \markdownRendererFencedCodeAttributeContextBeginPrototype
39697 \markdownRendererHeaderAttributeContextBeginPrototype
39698 \cs_gset_eq:NN
39699 \markdownRendererFencedCodeAttributeContextEndPrototype
39700 \markdownRendererHeaderAttributeContextEndPrototype
39701 \cs_gset:Npn
39702 \markdownRendererReplacementCharacterPrototype
39703 { \codepoint_str_generate:n { fffd } }
39704 \ExplSyntaxOff
39705 \def\markdownRendererSectionBeginPrototype{}%
39706 \def\markdownRendererSectionEndPrototype{}%
39707 \ExplSyntaxOn
39708 \cs_gset:Npn
39709 \markdownRendererWarningPrototype
39710 #1#2#3#4
39711 {
39712 \tl_set:Nn
39713 \l_tmpa_tl
39714 { #2 }
39715 \tl_if_empty:nF
39716 { #4 }
39717 {
39718 \tl_put_right:Nn
39719 \l_tmpa_tl
39720 { \iow_newline: #4 }
39721 }
39722 \exp_args:NV
39723 \markdownWarning
39724 \l_tmpa_tl
39725 }
39726 \ExplSyntaxOff
39727 \def\markdownRendererErrorPrototype#1#2#3#4{%
39728 \markdownError{#2}{#4}}%
39729 % \end{macrocode}
39730 % \begin{markdown}
39731 %
39732 %#### CommonMark Raw HTML Renderers
39733 %
39734 % The CommonMark raw HTML renderer prototypes (see Section
39735 % <#sec:commonmark-raw-html-renderers>) fall back onto
39736 % the renderer for generic inline HTML tags.
39737 %
39738 % \end{markdown}
39739 % \begin{macrocode}
39740 \def\markdownRendererInlineHtmlProcessingInstructionPrototype{%
39741 \markdownRendererInlineHtmlTagPrototype}%
39742 \def\markdownRendererInlineHtmlDeclarationPrototype{%
39743 \markdownRendererInlineHtmlTagPrototype}%
39744 \def\markdownRendererInlineHtmlCdataSectionPrototype{%
39745 \markdownRendererInlineHtmlTagPrototype}%
39746 \def\markdownRendererInlineHtmlOpenTagPrototype{%
39747 \markdownRendererInlineHtmlTagPrototype}%
39748 \def\markdownRendererInlineHtmlCloseTagPrototype{%
39749 \markdownRendererInlineHtmlTagPrototype}%
39750 \def\markdownRendererInlineHtmlEmptyTagPrototype{%
39751 \markdownRendererInlineHtmlTagPrototype}%
39752 % \end{macrocode}
39753 % \begin{markdown}
39754 %
39755 %#### CommonMark Block HTML Renderers
39756 %
39757 % Most CommonMark block HTML renderer prototypes (see Section
39758 % <#sec:commonmark-block-html-renderers>) fall back onto
39759 % the renderer prototype for generic block HTML elements.
39760 %
39761 % \end{markdown}
39762 % \begin{macrocode}
39763 \def\markdownRendererInputBlockHtmlCdataElementPrototype{%
39764 \markdownRendererInputBlockHtmlElementPrototype}%
39765 \def\markdownRendererInputBlockHtmlProcessingInstructionPrototype{%
39766 \markdownRendererInputBlockHtmlElementPrototype}%
39767 \def\markdownRendererInputBlockHtmlDeclarationPrototype{%
39768 \markdownRendererInputBlockHtmlElementPrototype}%
39769 \def\markdownRendererInputBlockHtmlCdataSectionPrototype{%
39770 \markdownRendererInputBlockHtmlElementPrototype}%
39771 \def\markdownRendererInputBlockHtmlPcdataElementPrototype{%
39772 \markdownRendererInputBlockHtmlElementPrototype}%
39773 % \end{macrocode}
39774 % \begin{markdown}
39775 %
39776 % The block comment HTML renderer (type 2) falls back on
39777 % the renderer prototype for inline HTML elements.
39778 %
39779 % \end{markdown}
39780 % \begin{macrocode}
39781 \def\markdownRendererBlockHtmlCommentPrototype{%
39782 \markdownRendererInlineHtmlCommentPrototype}%
39783 % \end{macrocode}
39784 % \begin{markdown}
39785 %
39786 % The standalone HTML tag renderer (type 7) falls back on
39787 % the renderer prototype for generic inline HTML tags.
39788 %
39789 % \end{markdown}
39790 % \begin{macrocode}
39791 \def\markdownRendererBlockHtmlStandaloneTagPrototype{%
39792 \markdownRendererInlineHtmlTagPrototype}%
39793 % \end{macrocode}
39794 % \begin{markdown}
39795 %
39796 %#### Raw Attributes
39797 %
39798 % In the raw block and inline raw span renderer prototypes, execute the content
39799 % with TeX when the raw attribute is `tex`, display the content as markdown when
39800 % the raw attribute is `md`, and ignore the content otherwise.
39801 %
39802 % \end{markdown}
39803 % \begin{macrocode}
39804 \ExplSyntaxOn
39805 \cs_new:Nn
39806 \@@_plain_tex_default_input_raw_inline:nn
39807 {
39808 \str_case:nn
39809 { #2 }
39810 {
39811 { md } { \markdownInput{#1} }
39812 { tex } { \markdownEscape{#1} \unskip }
39813 }
39814 }
39815 \cs_new:Nn
39816 \@@_plain_tex_default_input_raw_block:nn
39817 {
39818 \str_case:nn
39819 { #2 }
39820 {
39821 { md } { \markdownInput{#1} }
39822 { tex } { \markdownEscape{#1} }
39823 }
39824 }
39825 \cs_gset:Npn
39826 \markdownRendererInputRawInlinePrototype#1#2
39827 {
39828 \@@_plain_tex_default_input_raw_inline:nn
39829 { #1 }
39830 { #2 }
39831 }
39832 \cs_gset:Npn
39833 \markdownRendererInputRawBlockPrototype#1#2
39834 {
39835 \@@_plain_tex_default_input_raw_block:nn
39836 { #1 }
39837 { #2 }
39838 }
39839 \ExplSyntaxOff
39840 % \end{macrocode}
39841 % \begin{markdown}
39842 %
39843 %#### Simple YAML Metadata Renderer Prototypes
39844 % In this section, we implement the simple high-level interface for processing
39845 % simple YAML metadata using the key--value `markdown/jekyllData`. See
39846 % also Section <#sec:expl3yamlmetadata>.
39847 %
39848 % To keep track of the current type of structure we inhabit when we are
39849 % traversing a YAML document, we will maintain the
39850 % \mdef{g_\@\@_jekyll_data_datatypes_seq} stack. At every step of the traversal,
39851 % the stack will contain one of the following constants at any position $p$:
39852 %
39853 % \mdef{c_\@\@_jekyll_data_sequence_tl}
39854 %
39855 %: The currently traversed branch of the YAML document contains a sequence
39856 % at depth $p$.
39857 %
39858 % \mdef{c_\@\@_jekyll_data_mapping_tl}
39859 %
39860 %: The currently traversed branch of the YAML document contains a mapping
39861 % at depth $p$.
39862 %
39863 % \mdef{c_\@\@_jekyll_data_scalar_tl}
39864 %
39865 %: The currently traversed branch of the YAML document contains a scalar
39866 % value at depth $p$.
39867 %
39868 % \end{markdown}
39869 % \begin{macrocode}
39870 \ExplSyntaxOn
39871 \seq_new:N \g_@@_jekyll_data_datatypes_seq
39872 \tl_const:Nn \c_@@_jekyll_data_sequence_tl { sequence }
39873 \tl_const:Nn \c_@@_jekyll_data_mapping_tl { mapping }
39874 \tl_const:Nn \c_@@_jekyll_data_scalar_tl { scalar }
39875 % \end{macrocode}
39876 % \begin{markdown}
39877 %
39878 % To keep track of our current place when we are traversing a YAML
39879 % document, we will maintain the
39880 % \mdef{g_\@\@_jekyll_data_wildcard_absolute_address_seq} stack of keys using
39881 % the \mdef{\@\@_jekyll_data_push_address_segment:n} macro.
39882 %
39883 % \end{markdown}
39884 % \begin{macrocode}
39885 \seq_new:N \g_@@_jekyll_data_wildcard_absolute_address_seq
39886 \cs_new:Nn \@@_jekyll_data_push_address_segment:n
39887 {
39888 \seq_if_empty:NF
39889 \g_@@_jekyll_data_datatypes_seq
39890 {
39891 \seq_get_right:NN
39892 \g_@@_jekyll_data_datatypes_seq
39893 \l_tmpa_tl
39894 % \end{macrocode}
39895 % \begin{markdown}
39896 %
39897 % If we are currently in a sequence, we will put an asterisk (`*`) instead of
39898 % a key into \mref{g_\@\@_jekyll_data_wildcard_absolute_address_seq} to make
39899 % it represent a *wildcard*. Keeping a wildcard instead of a precise address
39900 % makes it easy for the users to react to *any* item of a sequence regardless
39901 % of how many there are, which can often be useful.
39902 %
39903 % \end{markdown}
39904 % \begin{macrocode}
39905 \str_if_eq:NNTF
39906 \l_tmpa_tl
39907 \c_@@_jekyll_data_sequence_tl
39908 {
39909 \seq_put_right:Nn
39910 \g_@@_jekyll_data_wildcard_absolute_address_seq
39911 { * }
39912 }
39913 {
39914 \seq_put_right:Nn
39915 \g_@@_jekyll_data_wildcard_absolute_address_seq
39916 { #1 }
39917 }
39918 }
39919 }
39920 % \end{macrocode}
39921 % \begin{markdown}
39922 %
39923 % Out of \mref{g_\@\@_jekyll_data_wildcard_absolute_address_seq}, we will
39924 % construct the following two token lists:
39925 %
39926 % \mdef{g_\@\@_jekyll_data_wildcard_absolute_address_tl}
39927 %
39928 %: An *absolute wildcard*: The wildcard from the root of the document
39929 % prefixed with a slash (`/`) with individual keys and asterisks also
39930 % delimited by slashes. Allows the users to react to complex
39931 % context-sensitive structures with ease.
39932 %
39933 %: For example, the `name` key in the following YAML document
39934 % would correspond to the `/*/person/name` absolute wildcard:
39935 % ``` yaml
39936 % [{person: {name: Elon, surname: Musk}}]
39937 % ```
39938 %
39939 % \mdef{g_\@\@_jekyll_data_wildcard_relative_address_tl}
39940 %
39941 %: A *relative wildcard*: The rightmost segment of the wildcard. Allows the
39942 % users to react to simple context-free structures.
39943 %
39944 %: For example, the `name` key in the following YAML document
39945 % would correspond to the `name` relative wildcard:
39946 % ``` yaml
39947 % [{person: {name: Elon, surname: Musk}}]
39948 % ```
39949 %
39950 % We will construct \mref{g_\@\@_jekyll_data_wildcard_absolute_address_tl}
39951 % using the \mdef{\@\@_jekyll_data_concatenate_address:NN} macro and
39952 % we will construct both token lists using the
39953 % \mdef{\@\@_jekyll_data_update_address_tls:} macro.
39954 %
39955 % \end{markdown}
39956 % \begin{macrocode}
39957 \tl_new:N \g_@@_jekyll_data_wildcard_absolute_address_tl
39958 \tl_new:N \g_@@_jekyll_data_wildcard_relative_address_tl
39959 \cs_new:Nn \@@_jekyll_data_concatenate_address:NN
39960 {
39961 \seq_pop_left:NN #1 \l_tmpa_tl
39962 \tl_set:Nx #2 { / \seq_use:Nn #1 { / } }
39963 \seq_put_left:NV #1 \l_tmpa_tl
39964 }
39965 \cs_new:Nn \@@_jekyll_data_update_address_tls:
39966 {
39967 \@@_jekyll_data_concatenate_address:NN
39968 \g_@@_jekyll_data_wildcard_absolute_address_seq
39969 \g_@@_jekyll_data_wildcard_absolute_address_tl
39970 \seq_get_right:NN
39971 \g_@@_jekyll_data_wildcard_absolute_address_seq
39972 \g_@@_jekyll_data_wildcard_relative_address_tl
39973 }
39974 % \end{macrocode}
39975 % \begin{markdown}
39976 %
39977 % To make sure that the stacks and token lists stay in sync, we will use the
39978 % \mdef{\@\@_jekyll_data_push:nN} and \mdef{\@\@_jekyll_data_pop:}
39979 % macros.
39980 %
39981 % \end{markdown}
39982 % \begin{macrocode}
39983 \cs_new:Nn \@@_jekyll_data_push:nN
39984 {
39985 \@@_jekyll_data_push_address_segment:n
39986 { #1 }
39987 \seq_put_right:NV
39988 \g_@@_jekyll_data_datatypes_seq
39989 #2
39990 \@@_jekyll_data_update_address_tls:
39991 }
39992 \cs_new:Nn \@@_jekyll_data_pop:
39993 {
39994 \seq_pop_right:NN
39995 \g_@@_jekyll_data_wildcard_absolute_address_seq
39996 \l_tmpa_tl
39997 \seq_pop_right:NN
39998 \g_@@_jekyll_data_datatypes_seq
39999 \l_tmpa_tl
40000 \@@_jekyll_data_update_address_tls:
40001 }
40002 % \end{macrocode}
40003 % \begin{markdown}
40004 %
40005 % To set a single key--value, we will use the
40006 % \mdef{\@\@_jekyll_data_set_keyval_known:nn} macro, ignoring unknown keys.
40007 % To set key--values for both absolute and relative wildcards, we will use the
40008 % \mdef{\@\@_jekyll_data_set_keyvals_known:nn} macro.
40009 %
40010 % \end{markdown}
40011 % \begin{macrocode}
40012 \cs_new:Nn \@@_jekyll_data_set_keyval_known:nn
40013 {
40014 \keys_set_known:nn
40015 { markdown/jekyllData }
40016 { { #1 } = { #2 } }
40017 }
40018 \cs_generate_variant:Nn
40019 \@@_jekyll_data_set_keyval_known:nn
40020 { Vn }
40021 \cs_new:Nn \@@_jekyll_data_set_keyvals_known:nn
40022 {
40023 \@@_jekyll_data_push:nN
40024 { #1 }
40025 \c_@@_jekyll_data_scalar_tl
40026 \@@_jekyll_data_set_keyval_known:Vn
40027 \g_@@_jekyll_data_wildcard_absolute_address_tl
40028 { #2 }
40029 \@@_jekyll_data_set_keyval_known:Vn
40030 \g_@@_jekyll_data_wildcard_relative_address_tl
40031 { #2 }
40032 \@@_jekyll_data_pop:
40033 }
40034 % \end{macrocode}
40035 % \begin{markdown}
40036 %
40037 % Finally, we will register our macros as token renderer prototypes
40038 % to be able to react to the traversal of a YAML document.
40039 %
40040 % \end{markdown}
40041 % \begin{macrocode}
40042 \def\markdownRendererJekyllDataSequenceBeginPrototype#1#2{
40043 \@@_jekyll_data_push:nN
40044 { #1 }
40045 \c_@@_jekyll_data_sequence_tl
40046 }
40047 \def\markdownRendererJekyllDataMappingBeginPrototype#1#2{
40048 \@@_jekyll_data_push:nN
40049 { #1 }
40050 \c_@@_jekyll_data_mapping_tl
40051 }
40052 \def\markdownRendererJekyllDataSequenceEndPrototype{
40053 \@@_jekyll_data_pop:
40054 }
40055 \def\markdownRendererJekyllDataMappingEndPrototype{
40056 \@@_jekyll_data_pop:
40057 }
40058 \def\markdownRendererJekyllDataBooleanPrototype#1#2{
40059 \@@_jekyll_data_set_keyvals_known:nn
40060 { #1 }
40061 { #2 }
40062 }
40063 \def\markdownRendererJekyllDataEmptyPrototype#1{}
40064 \def\markdownRendererJekyllDataNumberPrototype#1#2{
40065 \@@_jekyll_data_set_keyvals_known:nn
40066 { #1 }
40067 { #2 }
40068 }
40069 % \end{macrocode}
40070 % \begin{markdown}
40071 %
40072 % We will process all string scalar values assuming that they may contain
40073 % markdown markup and are intended for typesetting.
40074 %
40075 % \end{markdown}
40076 % \begin{macrocode}
40077 \def\markdownRendererJekyllDataProgrammaticStringPrototype#1#2{}
40078 \def\markdownRendererJekyllDataTypographicStringPrototype#1#2{
40079 \@@_jekyll_data_set_keyvals_known:nn
40080 { #1 }
40081 { #2 }
40082 }
40083 \ExplSyntaxOff
40084 % \end{macrocode}
40085 % \begin{markdown}
40086 %
40087 %#### Complex YAML Metadata Renderer Prototypes
40088 % In this section, we implement the high-level interface for routing complex
40089 % YAML metadata to expl3 key--values using the option
40090 % `jekyllDataKeyValue`=\meta{module}. See also Section <#sec:expl3yamlmetadata>.
40091 %
40092 % \end{markdown}
40093 % \begin{macrocode}
40094 \ExplSyntaxOn
40095 \@@_with_various_cases:nn
40096 { jekyllDataKeyValue }
40097 {
40098 \keys_define:nn
40099 { markdown/options }
40100 {
40101 #1 .code:n = {
40102 \@@_route_jekyll_data_to_key_values:n
40103 { ##1 }
40104 },
40105 % \end{macrocode}
40106 % \begin{markdown}
40107 %
40108 % When no \meta{module} has been provided, assume that the YAML metadata
40109 % specify absolute paths to key--values.
40110 %
40111 % \end{markdown}
40112 % \begin{macrocode}
40113 #1 .value_required:n = { false },
40114 #1 .default:n = { },
40115 }
40116 }
40117 \seq_new:N
40118 \l_@@_jekyll_data_current_position_seq
40119 \tl_new:N
40120 \l_@@_jekyll_data_current_position_tl
40121 \cs_new:Nn
40122 \@@_route_jekyll_data_to_key_values:n
40123 {
40124 \markdownSetup
40125 {
40126 renderers = {
40127 jekyllData(Sequence|Mapping)Begin = {
40128 \bool_lazy_and:nnTF
40129 {
40130 \seq_if_empty_p:N
40131 \l_@@_jekyll_data_current_position_seq
40132 }
40133 {
40134 \str_if_eq_p:nn
40135 { ##1 }
40136 { null }
40137 }
40138 {
40139 \tl_if_empty:nF
40140 { #1 }
40141 {
40142 \seq_put_right:Nn
40143 \l_@@_jekyll_data_current_position_seq
40144 { #1 }
40145 }
40146 }
40147 {
40148 \seq_put_right:Nn
40149 \l_@@_jekyll_data_current_position_seq
40150 { ##1 }
40151 }
40152 },
40153 jekyllData(Sequence|Mapping)End = {
40154 \seq_pop_right:NN
40155 \l_@@_jekyll_data_current_position_seq
40156 \l_tmpa_tl
40157 },
40158 % \end{macrocode}
40159 % \begin{markdown}
40160 %
40161 % For every YAML key `path.to.`\meta{key} with a value of type
40162 % \meta{non-string type}, set the key \meta{non-string type} of the key–value
40163 % \meta{module}`/path/to/`\meta{key} if it is known and the key \meta{key} of
40164 % the key–value \meta{module}`/path/to` otherwise. \meta{Non-string type} is
40165 % one of `boolean`, `number`, and `empty`.
40166 %
40167 % \end{markdown}
40168 % \begin{macrocode}
40169 jekyllDataBoolean = {
40170 \tl_set:Nx
40171 \l_@@_jekyll_data_current_position_tl
40172 {
40173 \seq_use:Nn
40174 \l_@@_jekyll_data_current_position_seq
40175 { / }
40176 }
40177 \keys_if_exist:VnTF
40178 \l_@@_jekyll_data_current_position_tl
40179 { ##1 / boolean }
40180 {
40181 \@@_keys_set:xn
40182 {
40183 \tl_use:N
40184 \l_@@_jekyll_data_current_position_tl
40185 / ##1 / boolean
40186 }
40187 { ##2 }
40188 }
40189 {
40190 \@@_keys_set:xn
40191 {
40192 \tl_use:N
40193 \l_@@_jekyll_data_current_position_tl
40194 / ##1
40195 }
40196 { ##2 }
40197 }
40198 },
40199 jekyllDataNumber = {
40200 \tl_set:Nx
40201 \l_@@_jekyll_data_current_position_tl
40202 {
40203 \seq_use:Nn
40204 \l_@@_jekyll_data_current_position_seq
40205 { / }
40206 }
40207 \keys_if_exist:VnTF
40208 \l_@@_jekyll_data_current_position_tl
40209 { ##1 / number }
40210 {
40211 \@@_keys_set:xn
40212 {
40213 \tl_use:N
40214 \l_@@_jekyll_data_current_position_tl
40215 / ##1 / number
40216 }
40217 { ##2 }
40218 }
40219 {
40220 \@@_keys_set:xn
40221 {
40222 \tl_use:N
40223 \l_@@_jekyll_data_current_position_tl
40224 / ##1
40225 }
40226 { ##2 }
40227 }
40228 },
40229 % \end{macrocode}
40230 % \begin{markdown}
40231 %
40232 % For the \meta{non-string type} of `empty`, no value is passed to the
40233 % key–value. Therefore, a default value should always be defined for nullable
40234 % keys using the key property `.default:n`.
40235 %
40236 % \end{markdown}
40237 % \begin{macrocode}
40238 jekyllDataEmpty = {
40239 \tl_set:Nx
40240 \l_@@_jekyll_data_current_position_tl
40241 {
40242 \seq_use:Nn
40243 \l_@@_jekyll_data_current_position_seq
40244 { / }
40245 }
40246 \keys_if_exist:VnTF
40247 \l_@@_jekyll_data_current_position_tl
40248 { ##1 / empty }
40249 {
40250 \keys_set:xn
40251 {
40252 \tl_use:N
40253 \l_@@_jekyll_data_current_position_tl
40254 / ##1
40255 }
40256 { empty }
40257 }
40258 {
40259 \keys_set:Vn
40260 \l_@@_jekyll_data_current_position_tl
40261 { ##1 }
40262 }
40263 },
40264 % \end{macrocode}
40265 % \begin{markdown}
40266 %
40267 % For every YAML key `path.to.`\meta{key} with a value of type `string`,
40268 % set the keys `typographicString` and `programmaticString` of the key–value
40269 % \meta{module}`/path/to/`\meta{key} if they are known with the typographic and
40270 % programmatic strings of the value, respectively. Furthermore, set the key
40271 % \meta{key} of the key–value \meta{module}`/path/to` with the typographic
40272 % string of the value unless the key `typographicString` is known. If the key
40273 % `programmaticString` is known, only set the key \meta{key} if it is known. In
40274 % contrast, if neither `typographicString` nor `programmaticString` are known,
40275 % set \meta{key} normally, i.e. regardless of whether it is known or unknown.
40276 %
40277 % \end{markdown}
40278 % \begin{macrocode}
40279 jekyllDataTypographicString = {
40280 \tl_set:Nx
40281 \l_@@_jekyll_data_current_position_tl
40282 {
40283 \seq_use:Nn
40284 \l_@@_jekyll_data_current_position_seq
40285 { / }
40286 }
40287 \keys_if_exist:VnTF
40288 \l_@@_jekyll_data_current_position_tl
40289 { ##1 / typographicString }
40290 {
40291 \@@_keys_set:xn
40292 {
40293 \tl_use:N
40294 \l_@@_jekyll_data_current_position_tl
40295 / ##1 / typographicString
40296 }
40297 { ##2 }
40298 }
40299 {
40300 \keys_if_exist:VnTF
40301 \l_@@_jekyll_data_current_position_tl
40302 { ##1 / programmaticString }
40303 {
40304 \@@_keys_set_known:xn
40305 {
40306 \tl_use:N
40307 \l_@@_jekyll_data_current_position_tl
40308 / ##1
40309 }
40310 { ##2 }
40311 }
40312 {
40313 \@@_keys_set:xn
40314 {
40315 \tl_use:N
40316 \l_@@_jekyll_data_current_position_tl
40317 / ##1
40318 }
40319 { ##2 }
40320 }
40321 }
40322 },
40323 jekyllDataProgrammaticString = {
40324 \tl_set:Nx
40325 \l_@@_jekyll_data_current_position_tl
40326 {
40327 \seq_use:Nn
40328 \l_@@_jekyll_data_current_position_seq
40329 { / }
40330 }
40331 \keys_if_exist:VnT
40332 \l_@@_jekyll_data_current_position_tl
40333 { ##1 / programmaticString }
40334 {
40335 \@@_keys_set:xn
40336 {
40337 \tl_use:N
40338 \l_@@_jekyll_data_current_position_tl
40339 / ##1 / programmaticString
40340 }
40341 { ##2 }
40342 }
40343 },
40344 },
40345 }
40346 }
40347 \cs_new:Nn
40348 \@@_keys_set:nn
40349 {
40350 \keys_set:nn
40351 { }
40352 { { #1 } = { #2 } }
40353 }
40354 \cs_new:Nn
40355 \@@_keys_set_known:nn
40356 {
40357 \keys_set_known:nn
40358 { }
40359 { { #1 } = { #2 } }
40360 }
40361 \cs_generate_variant:Nn
40362 \@@_keys_set:nn
40363 { xn }
40364 \cs_generate_variant:Nn
40365 \@@_keys_set_known:nn
40366 { xn }
40367 \cs_generate_variant:Nn
40368 \keys_set:nn
40369 { xn, Vn }
40370 \prg_generate_conditional_variant:Nnn
40371 \keys_if_exist:nn
40372 { Vn }
40373 { T, TF }
40374 \ExplSyntaxOff
40375 % \end{macrocode}
40376 % \iffalse
40377 %</themes-witiko-markdown-defaults-tex>
40378 %<*tex>
40379 % \fi
40380 % \begin{markdown}
40381 %
40382 % If plain \TeX{} is the top layer, we load the `witiko/markdown/defaults`
40383 % plain \TeX{} theme with the default definitions for token renderer
40384 % prototypes unless the option `noDefaults` has been enabled (see Section
40385 % <#sec:plain>).
40386 %
40387 % \end{markdown}
40388 % \begin{macrocode}
40389 \ExplSyntaxOn
40390 \str_if_eq:VVT
40391 \c_@@_top_layer_tl
40392 \c_@@_option_layer_plain_tex_tl
40393 {
40394 \use:c
40395 { ExplSyntaxOff }
40396 \@@_if_option:nF
40397 { noDefaults }
40398 {
40399 \@@_if_option:nTF
40400 { experimental }
40401 {
40402 \@@_setup:n
40403 { theme = witiko/markdown/defaults@experimental }
40404 }
40405 {
40406 \@@_setup:n
40407 { theme = witiko/markdown/defaults }
40408 }
40409 }
40410 \use:c
40411 { ExplSyntaxOn }
40412 }
40413 \ExplSyntaxOff
40414 % \end{macrocode}
40415 % \begin{markdown}
40416 %
40417 %### Lua Snippets
40418 % After the \mdef{markdownPrepareLuaOptions} macro has been fully expanded,
40419 % the \mdef{markdownLuaOptions} macro will expands to a Lua table that
40420 % contains the plain \TeX{} options (see Section <#sec:tex-options>) in a
40421 % format recognized by Lua (see Section <#sec:lua-options>).
40422 %
40423 % \end{markdown}
40424 % \begin{macrocode}
40425 \ExplSyntaxOn
40426 \tl_new:N \g_@@_formatted_lua_options_tl
40427 \cs_new:Nn \@@_format_lua_options:
40428 {
40429 \tl_gclear:N
40430 \g_@@_formatted_lua_options_tl
40431 \seq_map_function:NN
40432 \g_@@_lua_options_seq
40433 \@@_format_lua_option:n
40434 }
40435 \cs_new:Nn \@@_format_lua_option:n
40436 {
40437 \@@_typecheck_option:n
40438 { #1 }
40439 \@@_get_option_type:nN
40440 { #1 }
40441 \l_tmpa_tl
40442 \bool_case_true:nF
40443 {
40444 {
40445 \str_if_eq_p:VV
40446 \l_tmpa_tl
40447 \c_@@_option_type_boolean_tl ||
40448 \str_if_eq_p:VV
40449 \l_tmpa_tl
40450 \c_@@_option_type_number_tl ||
40451 \str_if_eq_p:VV
40452 \l_tmpa_tl
40453 \c_@@_option_type_counter_tl
40454 }
40455 {
40456 \@@_get_option_value:nN
40457 { #1 }
40458 \l_tmpa_tl
40459 \tl_gput_right:Nx
40460 \g_@@_formatted_lua_options_tl
40461 { #1~=~ \l_tmpa_tl ,~ }
40462 }
40463 {
40464 \str_if_eq_p:VV
40465 \l_tmpa_tl
40466 \c_@@_option_type_clist_tl
40467 }
40468 {
40469 \@@_get_option_value:nN
40470 { #1 }
40471 \l_tmpa_tl
40472 \tl_gput_right:Nx
40473 \g_@@_formatted_lua_options_tl
40474 { #1~=~\c_left_brace_str }
40475 \clist_map_inline:Vn
40476 \l_tmpa_tl
40477 {
40478 \@@_lua_escape:xN
40479 { ##1 }
40480 \l_tmpb_tl
40481 \tl_gput_right:Nn
40482 \g_@@_formatted_lua_options_tl
40483 { " }
40484 \tl_gput_right:NV
40485 \g_@@_formatted_lua_options_tl
40486 \l_tmpb_tl
40487 \tl_gput_right:Nn
40488 \g_@@_formatted_lua_options_tl
40489 { " ,~ }
40490 }
40491 \tl_gput_right:Nx
40492 \g_@@_formatted_lua_options_tl
40493 { \c_right_brace_str ,~ }
40494 }
40495 }
40496 {
40497 \@@_get_option_value:nN
40498 { #1 }
40499 \l_tmpa_tl
40500 \@@_lua_escape:xN
40501 { \l_tmpa_tl }
40502 \l_tmpb_tl
40503 \tl_gput_right:Nn
40504 \g_@@_formatted_lua_options_tl
40505 { #1~=~ " }
40506 \tl_gput_right:NV
40507 \g_@@_formatted_lua_options_tl
40508 \l_tmpb_tl
40509 \tl_gput_right:Nn
40510 \g_@@_formatted_lua_options_tl
40511 { " ,~ }
40512 }
40513 }
40514 \cs_generate_variant:Nn
40515 \clist_map_inline:nn
40516 { Vn }
40517 \let
40518 \markdownPrepareLuaOptions
40519 \@@_format_lua_options:
40520 \def
40521 \markdownLuaOptions
40522 {
40523 {
40524 \g_@@_formatted_lua_options_tl
40525 }
40526 }
40527 \sys_if_engine_luatex:TF
40528 {
40529 \cs_new:Nn
40530 \@@_lua_escape:nN
40531 {
40532 \tl_set:Nx
40533 #2
40534 {
40535 \lua_escape:n
40536 { #1 }
40537 }
40538 }
40539 }
40540 {
40541 \regex_const:Nn
40542 \c_@@_lua_escape_regex
40543 { [\\"'] }
40544 \cs_new:Nn
40545 \@@_lua_escape:nN
40546 {
40547 \tl_set:Nn
40548 #2
40549 { #1 }
40550 \regex_replace_all:NnN
40551 \c_@@_lua_escape_regex
40552 { \u { c_backslash_str } \0 }
40553 #2
40554 }
40555 }
40556 \cs_generate_variant:Nn
40557 \@@_lua_escape:nN
40558 { xN }
40559 % \end{macrocode}
40560 % \begin{markdown}
40561 %
40562 % After the \mdef{markdownPrepareInputFilename} macro has been
40563 % fully expanded, the \mdef{markdownInputFilename} macro will
40564 % expands to a Lua string that contains the input filename passed
40565 % as the first argument.
40566 %
40567 % \end{markdown}
40568 % \begin{macrocode}
40569 \tl_new:N
40570 \markdownInputFilename
40571 \cs_new:Npn
40572 \markdownPrepareInputFilename
40573 #1
40574 {
40575 \@@_lua_escape:xN
40576 { #1 }
40577 \markdownInputFilename
40578 \tl_gset:Nx
40579 \markdownInputFilename
40580 { " \markdownInputFilename " }
40581 }
40582 % \end{macrocode}
40583 % \begin{markdown}
40584 %
40585 % The \mdef{markdownPrepare} macro contains the Lua code that is executed prior
40586 % to any conversion from markdown to plain \TeX{}. It exposes the
40587 % `convert` function for the use by any further Lua code.
40588 %
40589 % \end{markdown}
40590 % \begin{macrocode}
40591 \cs_new:Npn
40592 \markdownPrepare
40593 {
40594 % \end{macrocode}
40595 % \begin{markdown}
40596 % First, ensure that the \Opt{cacheDir} directory exists.
40597 % \end{markdown}
40598 % \begin{macrocode}
40599 local~lfs = require("lfs")
40600 local~options = \markdownLuaOptions
40601 if~not~lfs.isdir(options.cacheDir) then~
40602 assert(lfs.mkdir(options.cacheDir))
40603 end~
40604 % \end{macrocode}
40605 % \begin{markdown}
40606 % Next, load the `markdown` module and create a converter function using
40607 % the plain \TeX{} options, which were serialized to a Lua table via the
40608 % \mref{markdownLuaOptions} macro.
40609 % \end{markdown}
40610 % \begin{macrocode}
40611 local~md = require("markdown")
40612 local~convert = md.new(options)
40613 }
40614 % \end{macrocode}
40615 % \begin{markdown}
40616 %
40617 % The \mdef{markdownConvert} macro contains the Lua code that is executed
40618 % during the conversion from markdown to plain \TeX{}. It opens the
40619 % input file, converts it, and prints the conversion result.
40620 %
40621 % \end{markdown}
40622 % \begin{macrocode}
40623 \cs_new:Npn
40624 \markdownConvert
40625 {
40626 local~filename = \markdownInputFilename
40627 local~file = assert(io.open(filename, "r"),
40628 [[Could~not~open~file~"]] .. filename .. [["~for~reading]])
40629 local~input = assert(file:read("*a"))
40630 assert(file:close())
40631 print(convert(input))
40632 }
40633 \ExplSyntaxOff
40634 % \end{macrocode}
40635 % \begin{markdown}
40636 %
40637 % The \mdef{markdownCleanup} macro contains the Lua code that is executed
40638 % after any conversion from markdown to plain \TeX{}.
40639 %
40640 % \end{markdown}
40641 % \begin{macrocode}
40642 \def\markdownCleanup{%
40643 % \end{macrocode}
40644 % \begin{markdown}
40645 % Remove the `options.cacheDir` directory if it is empty.
40646 % \end{markdown}
40647 % \begin{macrocode}
40648 if options.cacheDir then
40649 lfs.rmdir(options.cacheDir)
40650 end
40651 }%
40652 % \end{macrocode}
40653 % \begin{markdown}
40654 %
40655 %### Buffering Block-Level Markdown Input {#buffering-block}
40656 %
40657 % The macros \mdef{markdownInputFileStream} and \mdef{markdownOutputFileStream}
40658 % contain the number of the input and output file streams that will be used for
40659 % the IO operations of the package.
40660 %
40661 % \end{markdown}
40662 % \begin{macrocode}
40663 \csname newread\endcsname\markdownInputFileStream
40664 \csname newwrite\endcsname\markdownOutputFileStream
40665 % \end{macrocode}
40666 % \begin{markdown}
40667 %
40668 % The \mdef{markdownReadAndConvertTab} macro contains the tab character literal.
40669 %
40670 % \end{markdown}
40671 % \begin{macrocode}
40672 \begingroup
40673 \catcode`\^^I=12%
40674 \gdef\markdownReadAndConvertTab{^^I}%
40675 \endgroup
40676 % \end{macrocode}
40677 % \begin{markdown}
40678 %
40679 % The \mref{markdownReadAndConvert} macro is largely a rewrite of the
40680 % \Hologo{LaTeX2e} `\filecontents` macro to plain \TeX{}.
40681 %
40682 % \end{markdown}
40683 % \begin{macrocode}
40684 \begingroup
40685 % \end{macrocode}
40686 % \begin{markdown}
40687 % Make the newline and tab characters active and swap the character codes of
40688 % the backslash symbol (`\`) and the pipe symbol (`|`), so that we can use the
40689 % backslash as an ordinary character inside the macro definition. Likewise,
40690 % swap the character codes of the percent sign (`\%`) and the ampersand (`@`),
40691 % so that we can remove percent signs from the beginning of lines when
40692 % \Opt{stripPercentSigns} is enabled.
40693 % \end{markdown}
40694 % \begin{macrocode}
40695 \catcode`\^^M=13%
40696 \catcode`\^^I=13%
40697 \catcode`|=0%
40698 \catcode`\\=12%
40699 |catcode`@=14%
40700 |catcode`|%=12@
40701 |gdef|markdownReadAndConvert#1#2{@
40702 |begingroup@
40703 % \end{macrocode}
40704 % \begin{markdown}
40705 % If we are not reading markdown documents from the frozen cache,
40706 % open the \Opt{inputTempFileName} file for writing.
40707 % \end{markdown}
40708 % \begin{macrocode}
40709 |markdownIfOption{frozenCache}{}{@
40710 |immediate|openout|markdownOutputFileStream@
40711 |markdownOptionInputTempFileName|relax@
40712 |markdownInfo{@
40713 Buffering block-level markdown input into the temporary @
40714 input file "|markdownOptionInputTempFileName" and scanning @
40715 for the closing token sequence "#1"}@
40716 }@
40717 % \end{macrocode}
40718 % \begin{markdown}
40719 % Locally change the category of the special plain \TeX{} characters to
40720 % *other* in order to prevent unwanted interpretation of the input. Change
40721 % also the category of the space character, so that we can retrieve it
40722 % unaltered.
40723 % \end{markdown}
40724 % \begin{macrocode}
40725 |def|do##1{|catcode`##1=12}|dospecials@
40726 |catcode`| =12@
40727 |markdownMakeOther@
40728 % \end{macrocode}
40729 % \begin{markdown}
40730 % The \mdef{markdownReadAndConvertStripPercentSigns} macro will process the
40731 % individual lines of output, stipping away leading percent signs (`\%`) when
40732 % \Opt{stripPercentSigns} is enabled.
40733 % Notice the use of the comments (`@`) to ensure that the entire macro is at
40734 % a single line and therefore no (active) newline symbols
40735 % (`^^M`) are produced.
40736 % \end{markdown}
40737 % \begin{macrocode}
40738 |def|markdownReadAndConvertStripPercentSign##1{@
40739 |markdownIfOption{stripPercentSigns}{@
40740 |if##1%@
40741 |expandafter|expandafter|expandafter@
40742 |markdownReadAndConvertProcessLine@
40743 |else@
40744 |expandafter|expandafter|expandafter@
40745 |markdownReadAndConvertProcessLine@
40746 |expandafter|expandafter|expandafter##1@
40747 |fi@
40748 }{@
40749 |expandafter@
40750 |markdownReadAndConvertProcessLine@
40751 |expandafter##1@
40752 }@
40753 }@
40754 % \end{macrocode}
40755 % \begin{markdown}
40756 % The \mdef{markdownReadAndConvertProcessLine} macro will process the individual
40757 % lines of output.
40758 % Notice the use of the comments (`@`) to ensure that the entire macro is at
40759 % a single line and therefore no (active) newline symbols
40760 % (`^^M`) are produced.
40761 % \end{markdown}
40762 % \begin{macrocode}
40763 |def|markdownReadAndConvertProcessLine##1#1##2#1##3|relax{@
40764 % \end{macrocode}
40765 % \begin{markdown}
40766 % If we are not reading markdown documents from the frozen cache and the ending
40767 % token sequence does not appear in the line, store the line in the
40768 % \Opt{inputTempFileName} file.
40769 % If we are reading markdown documents from the frozen cache and the
40770 % ending token sequence does not appear in the line, gobble the line.
40771 % \end{markdown}
40772 % \begin{macrocode}
40773 |ifx|relax##3|relax@
40774 |markdownIfOption{frozenCache}{}{@
40775 |immediate|write|markdownOutputFileStream{##1}@
40776 }@
40777 |else@
40778 % \end{macrocode}
40779 % \begin{markdown}
40780 % When the ending token sequence appears in the line, make the next newline
40781 % character close the \Opt{inputTempFileName} file, return the
40782 % character categories back to the former state, convert the
40783 % \Opt{inputTempFileName} file from markdown to plain \TeX{},
40784 % `\input` the result of the conversion, and expand the ending control
40785 % sequence.
40786 % \end{markdown}
40787 % \begin{macrocode}
40788 |def^^M{@
40789 |markdownInfo{The ending token sequence was found}@
40790 |markdownIfOption{frozenCache}{}{@
40791 |immediate|closeout|markdownOutputFileStream@
40792 }@
40793 |endgroup@
40794 |markdownInput{@
40795 |markdownOptionOutputDir@
40796 /|markdownOptionInputTempFileName@
40797 }@
40798 #2}@
40799 |fi@
40800 % \end{macrocode}
40801 % \begin{markdown}
40802 % Repeat with the next line.
40803 % \end{markdown}
40804 % \begin{macrocode}
40805 ^^M}@
40806 % \end{macrocode}
40807 % \begin{markdown}
40808 % Make the tab character active at expansion time and make it expand to a
40809 % literal tab character.
40810 % \end{markdown}
40811 % \begin{macrocode}
40812 |catcode`|^^I=13@
40813 |def^^I{|markdownReadAndConvertTab}@
40814 % \end{macrocode}
40815 % \begin{markdown}
40816 % Make the newline character active at expansion time and make it consume the
40817 % rest of the line on expansion. Throw away the rest of the first line and
40818 % pass the second line to the \mref{markdownReadAndConvertProcessLine} macro.
40819 % \end{markdown}
40820 % \begin{macrocode}
40821 |catcode`|^^M=13@
40822 |def^^M##1^^M{@
40823 |def^^M####1^^M{@
40824 |markdownReadAndConvertStripPercentSign####1#1#1|relax}@
40825 ^^M}@
40826 ^^M}@
40827 % \end{macrocode}
40828 % \begin{markdown}
40829 % Reset the character categories back to the former state.
40830 % \end{markdown}
40831 % \begin{macrocode}
40832 |endgroup
40833 % \end{macrocode}
40834 % \begin{markdown}
40835 %
40836 % Use the \pkg{lt3luabridge} library to define the \mdef{markdownLuaExecute}
40837 % macro, which takes in a Lua scripts and expands to the standard output
40838 % produced by its execution.
40839 %
40840 % \end{markdown}
40841 % \begin{macrocode}
40842 \ExplSyntaxOn
40843 \cs_new:Npn
40844 \markdownLuaExecute
40845 #1
40846 {
40847 \int_compare:nNnT
40848 { \g_luabridge_method_int }
40849 =
40850 { \c_luabridge_method_shell_int }
40851 {
40852 \sys_if_shell_unrestricted:F
40853 {
40854 \sys_if_shell:TF
40855 {
40856 \msg_error:nn
40857 { markdown }
40858 { restricted-shell-access }
40859 }
40860 {
40861 \msg_error:nn
40862 { markdown }
40863 { disabled-shell-access }
40864 }
40865 }
40866 }
40867 \str_gset:NV
40868 \g_luabridge_output_dirname_str
40869 \markdownOptionOutputDir
40870 \luabridge_now:e
40871 { #1 }
40872 }
40873 \cs_generate_variant:Nn
40874 \msg_new:nnnn
40875 { nnnV }
40876 \tl_set:Nn
40877 \l_tmpa_tl
40878 {
40879 You~may~need~to~run~TeX~with~the~--shell-escape~or~the~
40880 --enable-write18~flag,~or~write~shell_escape=t~in~the~
40881 texmf.cnf~file.
40882 }
40883 \msg_new:nnnV
40884 { markdown }
40885 { restricted-shell-access }
40886 { Shell~escape~is~restricted }
40887 \l_tmpa_tl
40888 \msg_new:nnnV
40889 { markdown }
40890 { disabled-shell-access }
40891 { Shell~escape~is~disabled }
40892 \l_tmpa_tl
40893 \ExplSyntaxOff
40894 % \end{macrocode}
40895 % \begin{markdown}
40896 %
40897 %### Buffering Inline Markdown Input {#buffering-inline}
40898 %
40899 % This section describes the implementation of the macro \mref{markinline}.
40900 %
40901 % \end{markdown}
40902 % \begin{macrocode}
40903 \ExplSyntaxOn
40904 \tl_new:N
40905 \g_@@_after_markinline_tl
40906 \tl_gset:Nn
40907 \g_@@_after_markinline_tl
40908 { \unskip }
40909 \cs_new:Npn
40910 \markinline
40911 {
40912 % \end{macrocode}
40913 % \begin{markdown}
40914 %
40915 % Locally change the category of the special plain \TeX{} characters
40916 % to *other* in order to prevent unwanted interpretation of the input
40917 % markdown text as \TeX{} code.
40918 %
40919 % \end{markdown}
40920 % \begin{macrocode}
40921 \group_begin:
40922 \cctab_select:N
40923 \c_other_cctab
40924 % \end{macrocode}
40925 % \begin{markdown}
40926 %
40927 % Unless we are reading markdown documents from the frozen cache,
40928 % open the file \Opt{inputTempFileName} for writing.
40929 %
40930 % \end{markdown}
40931 % \begin{macrocode}
40932 \@@_if_option:nF
40933 { frozenCache }
40934 {
40935 \immediate
40936 \openout
40937 \markdownOutputFileStream
40938 \markdownOptionInputTempFileName
40939 \relax
40940 \msg_info:nne
40941 { markdown }
40942 { buffering-markinline }
40943 { \markdownOptionInputTempFileName }
40944 }
40945 % \end{macrocode}
40946 % \begin{markdown}
40947 %
40948 % Peek ahead and extract the inline markdown text.
40949 %
40950 % \end{markdown}
40951 % \begin{macrocode}
40952 \peek_regex_replace_once:nnF
40953 { { (.*?) } }
40954 {
40955 % \end{macrocode}
40956 % \begin{markdown}
40957 %
40958 % Unless we are reading markdown documents from the frozen cache,
40959 % store the text in the file \Opt{inputTempFileName} and close it.
40960 %
40961 % \end{markdown}
40962 % \begin{macrocode}
40963 \c { @@_if_option:nF }
40964 \cB { frozenCache \cE }
40965 \cB {
40966 \c { immediate }
40967 \c { write }
40968 \c { markdownOutputFileStream }
40969 \cB { \1 \cE }
40970 \c { immediate }
40971 \c { closeout }
40972 \c { markdownOutputFileStream }
40973 \cE }
40974 % \end{macrocode}
40975 % \begin{markdown}
40976 %
40977 % Reset the category codes and `\input` the result of the conversion.
40978 %
40979 % \end{markdown}
40980 % \begin{macrocode}
40981 \c { group_end: }
40982 \c { group_begin: }
40983 \c { @@_setup:n }
40984 \cB { contentLevel = inline \cE }
40985 \c { markdownInput }
40986 \cB {
40987 \c { markdownOptionOutputDir } /
40988 \c { markdownOptionInputTempFileName }
40989 \cE }
40990 \c { group_end: }
40991 \c { tl_use:N }
40992 \c { g_@@_after_markinline_tl }
40993 }
40994 {
40995 \msg_error:nn
40996 { markdown }
40997 { markinline-peek-failure }
40998 \group_end:
40999 \tl_use:N
41000 \g_@@_after_markinline_tl
41001 }
41002 }
41003 \msg_new:nnn
41004 { markdown }
41005 { buffering-markinline }
41006 { Buffering~inline~markdown~input~into~
41007 the~temporary~input~file~"#1". }
41008 \msg_new:nnnn
41009 { markdown }
41010 { markinline-peek-failure }
41011 { Use~of~\iow_char:N \\ markinline~doesn't~match~its~definition }
41012 { The~macro~should~be~followed~by~inline~
41013 markdown~text~in~curly~braces }
41014 \ExplSyntaxOff
41015 % \end{macrocode}
41016 % \begin{markdown}
41017 %
41018 %### Typesetting Markdown
41019 %
41020 % The \mref{markdownInput} macro uses an implementation of the
41021 % \mref{markdownLuaExecute} macro to convert the contents of the file whose
41022 % filename it has received as its single argument from markdown to plain
41023 % \TeX{}.
41024 %
41025 % \end{markdown}
41026 % \begin{macrocode}
41027 \ExplSyntaxOn
41028 \cs_new:Npn
41029 \markdownInput
41030 #1
41031 {
41032 \@@_if_option:nTF
41033 { frozenCache }
41034 {
41035 \markdownInputRaw
41036 { #1 }
41037 }
41038 {
41039 % \end{macrocode}
41040 % \begin{markdown}
41041 %
41042 % If the file does not exist in the current directory, we will search for it in
41043 % the directories specified in `\l_file_search_path_seq`. On \LaTeX, this
41044 % also includes the directories specified in `\input@path`.
41045 %
41046 % \end{markdown}
41047 % \begin{macrocode}
41048 \tl_set:Nx
41049 \l_tmpa_tl
41050 { #1 }
41051 \file_get_full_name:VNTF
41052 \l_tmpa_tl
41053 \l_tmpb_tl
41054 {
41055 \exp_args:NV
41056 \markdownInputRaw
41057 \l_tmpb_tl
41058 }
41059 {
41060 \msg_error:nnV
41061 { markdown }
41062 { markdown-file-does-not-exist }
41063 \l_tmpa_tl
41064 }
41065 }
41066 }
41067 \msg_new:nnn
41068 { markdown }
41069 { markdown-file-does-not-exist }
41070 {
41071 Markdown~file~#1~does~not~exist
41072 }
41073 \ExplSyntaxOff
41074 \begingroup
41075 % \end{macrocode}
41076 % \begin{markdown}
41077 % Swap the category code of the backslash symbol and the pipe symbol, so that
41078 % we may use the backslash symbol freely inside the Lua code. Furthermore,
41079 % use the ampersand symbol to specify parameters.
41080 % \end{markdown}
41081 % \begin{macrocode}
41082 \catcode`|=0%
41083 \catcode`\\=12%
41084 \catcode`|&=6%
41085 |gdef|markdownInputRaw#1{%
41086 % \end{macrocode}
41087 % \begin{markdown}
41088 % Change the category code of the percent sign (`\%`) to other, so that a user
41089 % of the \Opt{hybrid} Lua option or a malevolent actor can't produce TeX
41090 % comments in the plain TeX output of the Markdown package.
41091 % \end{markdown}
41092 % \begin{macrocode}
41093 |begingroup
41094 |catcode`|%=12
41095 % \end{macrocode}
41096 % \begin{markdown}
41097 % Furthermore, also change the category code of the hash sign (`#`) to other,
41098 % so that it's safe to tokenize the plain TeX output without mistaking hash
41099 % signs with TeX's parameter numbers.
41100 % \end{markdown}
41101 % \begin{macrocode}
41102 |catcode`|#=12
41103 % \end{macrocode}
41104 % \begin{markdown}
41105 % If we are reading from the frozen cache, input it, expand the corresponding
41106 % `\markdownFrozenCache`\meta{number} macro, and increment
41107 % \Opt{frozenCacheCounter}.
41108 % \end{markdown}
41109 % \begin{macrocode}
41110 |markdownIfOption{frozenCache}{%
41111 |ifnum|markdownOptionFrozenCacheCounter=0|relax
41112 |markdownInfo{Reading frozen cache from
41113 "|markdownOptionFrozenCacheFileName"}%
41114 |input|markdownOptionFrozenCacheFileName|relax
41115 |fi
41116 |markdownInfo{Including markdown document number
41117 "|the|markdownOptionFrozenCacheCounter" from frozen cache}%
41118 |csname markdownFrozenCache%
41119 |the|markdownOptionFrozenCacheCounter|endcsname
41120 |global|advance|markdownOptionFrozenCacheCounter by 1|relax
41121 }{%
41122 |markdownInfo{Including markdown document "&1"}%
41123 % \end{macrocode}
41124 % \begin{markdown}
41125 % Attempt to open the markdown document to record it in the `.log` and
41126 % `.fls` files. This allows external programs such as \LaTeX Mk to track
41127 % changes to the markdown document.
41128 % \end{markdown}
41129 % \begin{macrocode}
41130 |openin|markdownInputFileStream{&1}%
41131 |closein|markdownInputFileStream
41132 |markdownPrepareLuaOptions
41133 |markdownPrepareInputFilename{&1}%
41134 |markdownLuaExecute{%
41135 |markdownPrepare
41136 |markdownConvert
41137 |markdownCleanup}%
41138 % \end{macrocode}
41139 % \begin{markdown}
41140 % If we are finalizing the frozen cache, increment \Opt{frozenCacheCounter}.
41141 % \end{markdown}
41142 % \begin{macrocode}
41143 |markdownIfOption{finalizeCache}{%
41144 |global|advance|markdownOptionFrozenCacheCounter by 1|relax}{}%
41145 }%
41146 |endgroup
41147 }%
41148 |endgroup
41149 % \end{macrocode}
41150 % \begin{markdown}
41151 % The \mref{markdownEscape} macro resets the category codes of the percent sign
41152 % and the hash sign back to comment and parameter, respectively, before using
41153 % the `\input` built-in of \TeX{} to execute a \TeX{} document in the middle of
41154 % a markdown document fragment.
41155 % \end{markdown}
41156 % \begin{macrocode}
41157 \gdef\markdownEscape#1{%
41158 \catcode`\%=14\relax
41159 \catcode`\#=6\relax
41160 \input #1\relax
41161 \catcode`\%=12\relax
41162 \catcode`\#=12\relax
41163 }%
41164 % \end{macrocode}
41165 % \iffalse
41166 %</tex>
41167 %<*latex>
41168 % \fi
41169 % \begin{markdown}
41170 %
41171 % \LaTeX{} Implementation {#lateximplementation}
41172 %-------------------------
41173 %
41174 % The \LaTeX{} implementation makes use of the fact that, apart from some subtle
41175 % differences, \LaTeX{} implements the majority of the plain \TeX{}
41176 % format~[@latex17, Section 9]. As a consequence, we can directly reuse the
41177 % existing plain \TeX{} implementation.
41178 %
41179 % \end{markdown}
41180 % \begin{macrocode}
41181 \def\markdownVersionSpace{ }%
41182 \ProvidesPackage{markdown}[\markdownLastModified\markdownVersionSpace v%
41183 \markdownVersion\markdownVersionSpace markdown renderer]%
41184 % \end{macrocode}
41185 % \begin{markdown}
41186 %
41187 %### Typesetting Markdown
41188 % The \mdef{markinlinePlainTeX} macro is used to store the original plain
41189 % \TeX{} implementation of the \mref{markinline} macro. The \mref{markinline}
41190 % macro is then redefined to accept an optional argument with options
41191 % recognized by the \LaTeX{} interface (see Section <#sec:latex-options>).
41192 %
41193 % \end{markdown}
41194 % \begin{macrocode}
41195 \ExplSyntaxOn
41196 \cs_gset_eq:NN
41197 \markinlinePlainTeX
41198 \markinline
41199 \cs_gset:Npn
41200 \markinline
41201 {
41202 \peek_regex_replace_once:nn
41203 { ( \[ (.*?) \] ) ? }
41204 {
41205 % \end{macrocode}
41206 % \begin{markdown}
41207 %
41208 % Apply the options locally.
41209 %
41210 % \end{markdown}
41211 % \begin{macrocode}
41212 \c { group_begin: }
41213 \c { @@_setup:n }
41214 \cB { \2 \cE }
41215 \c { tl_put_right:Nn }
41216 \c { g_@@_after_markinline_tl }
41217 \cB { \c { group_end: } \cE }
41218 \c { markinlinePlainTeX }
41219 }
41220 }
41221 \ExplSyntaxOff
41222 % \end{macrocode}
41223 % \begin{markdown}
41224 %
41225 % The \mdef{markdownInputPlainTeX} macro is used to store the original plain
41226 % \TeX{} implementation of the \mref{yamlInput} macro. The \mref{markdownInput}
41227 % and \mref{yamlInput} macros are then redefined to accept an optional argument
41228 % with options recognized by the \LaTeX{} interface (see Section
41229 % <#sec:latex-options>).
41230 %
41231 % \end{markdown}
41232 % \begin{macrocode}
41233 \let\markdownInputPlainTeX\markdownInput
41234 \renewcommand\markdownInput[2][]{%
41235 \begingroup
41236 \markdownSetup{#1}%
41237 \markdownInputPlainTeX{#2}%
41238 \endgroup}%
41239 \renewcommand\yamlInput[2][]{%
41240 \begingroup
41241 \yamlSetup{jekyllData, expectJekyllData, ensureJekyllData, #1}%
41242 \markdownInputPlainTeX{#2}%
41243 \endgroup}%
41244 % \end{macrocode}
41245 % \begin{markdown}
41246 %
41247 % The \envmref{markdown}, \envmref{markdown*}, and \envmref{yaml} \LaTeX{}
41248 % environments are implemented using the \mref{markdownReadAndConvert} macro.
41249 %
41250 % \end{markdown}
41251 % \begin{macrocode}
41252 \ExplSyntaxOn
41253 \renewenvironment
41254 { markdown }
41255 {
41256 % \end{macrocode}
41257 % \markdownBegin
41258 %
41259 % In our implementation of the \envmref{markdown} \LaTeX{} environment, we
41260 % want to distinguish between the following two cases:
41261 % ``` tex
41262 % \begin{markdown} [smartEllipses] \begin{markdown}
41263 % \% This is an optional argument ^ [smartEllipses]
41264 % \% ... \% ^ This is link
41265 % \end{markdown} \end{markdown}
41266 % ```````
41267 %
41268 % Therefore, we cannot use the built-in \LaTeX{} support for environments
41269 % with optional arguments or packages such as \pkg{xparse}. Instead, we
41270 % must read the optional argument manually and prevent reading past the
41271 % end of a line.
41272 %
41273 % To prevent reading past the end of a line when looking for the optional
41274 % argument of the \envmref{markdown} \LaTeX{} environment and accidentally
41275 % tokenizing markdown text, we change the category code of carriage return
41276 % (`\r`, ASCII character 13 in decimal) from 5 (end of line).
41277 %
41278 % While any category code other than 5 (end of line) would work, we switch to
41279 % the category 13 (active), which is also used by the
41280 % \mref{markdownReadAndConvert} macro. This is necessary if we read until the
41281 % end of a line, because then the carriage return character will be
41282 % produced by \TeX{} via the `\endlinechar` plain \TeX{} macro and it needs
41283 % to have the correct category code, so that \mref{markdownReadAndConvert}
41284 % processes it correctly.
41285 %
41286 % \markdownEnd
41287 % \begin{macrocode}
41288 \group_begin:
41289 \char_set_catcode_active:n { 13 }
41290 % \end{macrocode}
41291 % \begin{markdown}
41292 %
41293 % To prevent doubling the hash signs (`#`, ASCII code 35 in decimal), we switch
41294 % its category from 6 (parameter) to 11 (letter).
41295 %
41296 % \end{markdown}
41297 % \begin{macrocode}
41298 \char_set_catcode_letter:n { 35 }
41299 % \end{macrocode}
41300 % \begin{markdown}
41301 %
41302 % After we have matched the opening `[` that begins the optional argument,
41303 % we accept carriage returns as well.
41304 %
41305 % \end{markdown}
41306 % \begin{macrocode}
41307 \peek_regex_replace_once:nnF
41308 { \ *\[\r*([^]]*)\][^\r]* }
41309 {
41310 % \end{macrocode}
41311 % \begin{markdown}
41312 %
41313 % After we have matched the optional argument, we switch back the category
41314 % code of carriage returns and hash signs and we retokenize the content. This
41315 % will cause single new lines to produce a space token and multiple new lines
41316 % to produce `\par` tokens. Furthermore, this will cause hash signs followed
41317 % by a number to be recognized as parameter numbers, which is necessary when
41318 % we use the optional argument to redefine token renderers and token renderer
41319 % prototypes.
41320 %
41321 % \end{markdown}
41322 % \begin{macrocode}
41323 \c { group_end: }
41324 \c { tl_set_rescan:Nnn } \c { l_tmpa_tl } { } { \1 }
41325 % \end{macrocode}
41326 % \begin{markdown}
41327 %
41328 % Then, we pass the retokenized content to the \mref{markdownSetup} macro.
41329 %
41330 % \end{markdown}
41331 % \begin{macrocode}
41332 \c { @@_setup:V } \c { l_tmpa_tl }
41333 % \end{macrocode}
41334 % \begin{markdown}
41335 %
41336 % Finally, regardless of whether or not we have matched the optional argument,
41337 % we let the \mref{markdownReadAndConvert} macro process the rest of the
41338 % \LaTeX{} environment.
41339 %
41340 % We also make provision for using the \mref{markdown} command as a part of a
41341 % different \LaTeX{} environment as follows:
41342 %
41343 % ``` tex
41344 % \newenvironment{foo}\%
41345 % {code before \markdown[some, options]}\%
41346 % {\markdownEnd code after}
41347 % ```
41348 %
41349 % \end{markdown}
41350 % \begin{macrocode}
41351 \c { exp_args:NV }
41352 \c { markdownReadAndConvert@ }
41353 \c { @currenvir }
41354 }
41355 {
41356 \group_end:
41357 \exp_args:NV
41358 \markdownReadAndConvert@
41359 \@currenvir
41360 }
41361 }
41362 { \markdownEnd }
41363 \renewenvironment
41364 { markdown* }
41365 [ 1 ]
41366 {
41367 \@@_if_option:nTF
41368 { experimental }
41369 {
41370 \msg_error:nn
41371 { markdown }
41372 { latex-markdown-star-deprecated }
41373 }
41374 {
41375 \msg_warning:nn
41376 { markdown }
41377 { latex-markdown-star-deprecated }
41378 }
41379 \@@_setup:n
41380 { #1 }
41381 \markdownReadAndConvert@
41382 { markdown* }
41383 }
41384 { \markdownEnd }
41385 \renewenvironment
41386 { yaml }
41387 {
41388 \group_begin:
41389 \yamlSetup
41390 { jekyllData, expectJekyllData, ensureJekyllData }
41391 \markdown
41392 }
41393 { \yamlEnd }
41394 \msg_new:nnn
41395 { markdown }
41396 { latex-markdown-star-deprecated }
41397 {
41398 The~markdown*~LaTeX~environment~has~been~deprecated~and~will~
41399 be~removed~in~the~next~major~version~of~the~Markdown~package.
41400 }
41401 \cs_generate_variant:Nn % noqa: w402
41402 \@@_setup:n
41403 { V }
41404 \ExplSyntaxOff
41405 \begingroup
41406 % \end{macrocode}
41407 % \begin{markdown}
41408 % Locally swap the category code of the backslash symbol with the pipe symbol,
41409 % and of the left (`{`) and right brace (`}`) with the less-than (`<`)
41410 % and greater-than (`>`) signs. This is required in order that all the
41411 % special symbols that appear in the first argument of the
41412 % `markdownReadAndConvert` macro have the category code *other*.
41413 % \end{markdown}
41414 % \begin{macrocode}
41415 \catcode`\|=0\catcode`\<=1\catcode`\>=2%
41416 \catcode`\\=12|catcode`|{=12|catcode`|}=12%
41417 |gdef|markdownReadAndConvert@#1<%
41418 |markdownReadAndConvert<\end{#1}>%
41419 <|end<#1>>>%
41420 |endgroup
41421 % \end{macrocode}
41422 % \begin{markdown}
41423 %
41424 %### Themes {#latex-themes-implementation}
41425 %
41426 % This section overrides the plain \TeX{} implementation of the theme-loading
41427 % mechanism from Section <#sec:themes-implementation>. Furthermore, this section
41428 % also implements the built-in \LaTeX{} themes provided with the Markdown package.
41429 %
41430 % \end{markdown}
41431 % \begin{macrocode}
41432 \ExplSyntaxOn
41433 \prop_new:N \g_@@_latex_loaded_themes_linenos_prop
41434 \prop_new:N \g_@@_latex_loaded_themes_versions_prop
41435 \cs_gset:Nn
41436 \@@_load_theme:nnn
41437 {
41438 % \end{macrocode}
41439 % \begin{markdown}
41440 %
41441 % If the Markdown package has not yet been loaded, determine whether
41442 % either this is a built-in theme according to the prop
41443 % \mref{g_@@_latex_built_in_themes_prop} or a file named
41444 % `markdowntheme`\meta{munged theme name}`.sty` exists and whether we are still
41445 % in the preamble.
41446 %
41447 % \end{markdown}
41448 % \begin{macrocode}
41449 \ifmarkdownLaTeXLoaded
41450 \ifx\@onlypreamble\@notprerr
41451 % \end{macrocode}
41452 % \begin{markdown}
41453 %
41454 % If both conditions are true, end with an error, since we cannot load
41455 % \LaTeX{} themes after the preamble.
41456 %
41457 % \end{markdown}
41458 % \begin{macrocode}
41459 \bool_if:nTF
41460 {
41461 \bool_lazy_or_p:nn
41462 {
41463 \prop_if_in_p:Nn
41464 \g_@@_latex_built_in_themes_prop
41465 { #1 }
41466 }
41467 {
41468 \file_if_exist_p:n
41469 { markdown theme #3.sty }
41470 }
41471 }
41472 {
41473 \msg_error:nn
41474 { markdown }
41475 { latex-theme-after-preamble }
41476 }
41477 % \end{macrocode}
41478 % \begin{markdown}
41479 %
41480 % Otherwise, try loading a plain \TeX{} theme instead.
41481 %
41482 % \end{markdown}
41483 % \begin{macrocode}
41484 {
41485 \@@_plain_tex_load_theme:nnn
41486 { #1 }
41487 { #2 }
41488 { #3 }
41489 }
41490 \else
41491 % \end{macrocode}
41492 % \begin{markdown}
41493 %
41494 % If the Markdown package has already been loaded but we are still in the
41495 % preamble, load a \LaTeX{} theme if it exists or load a plain \TeX{} theme
41496 % otherwise.
41497 %
41498 % \end{markdown}
41499 % \begin{macrocode}
41500 \bool_if:nTF
41501 {
41502 \bool_lazy_or_p:nn
41503 {
41504 \prop_if_in_p:Nn
41505 \g_@@_latex_built_in_themes_prop
41506 { #1 }
41507 }
41508 {
41509 \file_if_exist_p:n
41510 { markdown theme #3.sty }
41511 }
41512 }
41513 {
41514 \prop_get:NnNTF
41515 \g_@@_latex_loaded_themes_linenos_prop
41516 { #1 }
41517 \l_tmpa_tl
41518 {
41519 \prop_get:NnN
41520 \g_@@_latex_loaded_themes_versions_prop
41521 { #1 }
41522 \l_tmpb_tl
41523 \str_if_eq:nVTF
41524 { #2 }
41525 \l_tmpb_tl
41526 {
41527 \msg_warning:nnnVn
41528 { markdown }
41529 { repeatedly-loaded-latex-theme }
41530 { #1 }
41531 \l_tmpa_tl
41532 { #2 }
41533 }
41534 {
41535 \msg_error:nnnnVV
41536 { markdown }
41537 { different-versions-of-latex-theme }
41538 { #1 }
41539 { #2 }
41540 \l_tmpb_tl
41541 \l_tmpa_tl
41542 }
41543 }
41544 {
41545 \prop_gput:Nnx
41546 \g_@@_latex_loaded_themes_linenos_prop
41547 { #1 }
41548 { \tex_the:D \tex_inputlineno:D } % noqa: W200
41549 \prop_gput:Nnn
41550 \g_@@_latex_loaded_themes_versions_prop
41551 { #1 }
41552 { #2 }
41553 % \end{macrocode}
41554 % \begin{markdown}
41555 %
41556 % Load built-in plain \TeX{} themes from the prop
41557 % \mref{g_@@_latex_built_in_themes_prop} and from the filesystem otherwise.
41558 %
41559 % \end{markdown}
41560 % \begin{macrocode}
41561 \prop_if_in:NnTF
41562 \g_@@_latex_built_in_themes_prop
41563 { #1 }
41564 {
41565 \msg_info:nnnn
41566 { markdown }
41567 { loading-built-in-latex-theme }
41568 { #1 }
41569 { #2 }
41570 \prop_item:Nn
41571 \g_@@_latex_built_in_themes_prop
41572 { #1 }
41573 }
41574 {
41575 \msg_info:nnnn
41576 { markdown }
41577 { loading-latex-theme }
41578 { #1 }
41579 { #2 }
41580 \RequirePackage
41581 { markdown theme #3 }
41582 }
41583 }
41584 }
41585 {
41586 \@@_plain_tex_load_theme:nnn
41587 { #1 }
41588 { #2 }
41589 { #3 }
41590 }
41591 \fi
41592 \else
41593 % \end{macrocode}
41594 % \begin{markdown}
41595 %
41596 % If the Markdown package has not yet been loaded, postpone the loading until
41597 % the Markdown package has finished loading.
41598 %
41599 % \end{markdown}
41600 % \begin{macrocode}
41601 \msg_info:nnnn
41602 { markdown }
41603 { theme-loading-postponed }
41604 { #1 }
41605 { #2 }
41606 \AtEndOfPackage
41607 {
41608 \@@_set_theme:n
41609 { #1 @ #2 }
41610 }
41611 \fi
41612 }
41613 \msg_new:nnn
41614 { markdown }
41615 { theme-loading-postponed }
41616 {
41617 Postponing~loading~version~#2~of~Markdown~theme~#1~until~
41618 Markdown~package~has~finished~loading
41619 }
41620 \msg_new:nnn
41621 { markdown }
41622 { loading-built-in-latex-theme }
41623 { Loading~version~#2~of~built-in~LaTeX~Markdown~theme~#1 }
41624 \msg_new:nnn
41625 { markdown }
41626 { loading-latex-theme }
41627 { Loading~version~#2~of~LaTeX~Markdown~theme~#1 }
41628 \msg_new:nnn
41629 { markdown }
41630 { repeatedly-loaded-latex-theme }
41631 {
41632 Version~#3~of~LaTeX~Markdown~theme~#1~was~previously~
41633 loaded~on~line~#2,~not~loading~it~again
41634 }
41635 \msg_new:nnn
41636 { markdown }
41637 { different-versions-of-latex-theme }
41638 {
41639 Tried~to~load~version~#2~of~LaTeX~Markdown~theme~#1~
41640 but~version~#3~has~already~been~loaded~on~line~#4
41641 }
41642 \cs_generate_variant:Nn
41643 \msg_new:nnnn
41644 { nnVV }
41645 \tl_set:Nn
41646 \l_tmpa_tl
41647 { Cannot~load~LaTeX~Markdown~theme~#1~after~ }
41648 \tl_put_right:NV
41649 \l_tmpa_tl
41650 \c_backslash_str
41651 \tl_put_right:Nn
41652 \l_tmpa_tl
41653 { begin { document } }
41654 \tl_set:Nn
41655 \l_tmpb_tl
41656 { Load~Markdown~theme~#1~before~ }
41657 \tl_put_right:NV
41658 \l_tmpb_tl
41659 \c_backslash_str
41660 \tl_put_right:Nn
41661 \l_tmpb_tl
41662 { begin { document } }
41663 \msg_new:nnVV
41664 { markdown }
41665 { latex-theme-after-preamble }
41666 \l_tmpa_tl
41667 \l_tmpb_tl
41668 % \end{macrocode}
41669 % \begin{markdown}
41670 %
41671 % The `witiko/dot` and `witiko/graphicx/http` \LaTeX{} themes load the package
41672 % \pkg{graphicx}, see also Section <#sec:latex-prerequisites>. Then, they
41673 % load the corresponding plain \TeX{} themes.
41674 %
41675 % \end{markdown}
41676 % \begin{macrocode}
41677 \tl_set:Nn
41678 \l_tmpa_tl
41679 {
41680 \RequirePackage
41681 { graphicx }
41682 \markdownLoadPlainTeXTheme
41683 }
41684 \prop_gput:NnV
41685 \g_@@_latex_built_in_themes_prop
41686 { witiko / dot }
41687 \l_tmpa_tl
41688 \prop_gput:NnV
41689 \g_@@_latex_built_in_themes_prop
41690 { witiko / graphicx / http }
41691 \l_tmpa_tl
41692 % \end{macrocode}
41693 % \begin{markdown}
41694 %
41695 % The `witiko/glossaries` theme first checks that the version is either `v1` or
41696 % `latest`, issuing a warning for the latter.
41697 %
41698 % \end{markdown}
41699 % \begin{macrocode}
41700 \prop_gput:Nnn
41701 \g_@@_latex_built_in_themes_prop
41702 { witiko / glossaries }
41703 {
41704 \str_case:enF
41705 { \markdownThemeVersion }
41706 {
41707 { latest }
41708 {
41709 \msg_warning:nnnn
41710 { markdown }
41711 { pin-theme-version }
41712 { witiko/glossaries }
41713 { v1 }
41714 }
41715 { v1 }
41716 { }
41717 }
41718 {
41719 \msg_error:nnnen
41720 { markdown }
41721 { unknown-theme-version }
41722 { witiko/glossaries }
41723 { \markdownThemeVersion }
41724 { v1 }
41725 }
41726 }
41727 \ExplSyntaxOff
41728 % \end{macrocode}
41729 % \begin{markdown}
41730 %
41731 % In Section <#sec:latex-snippets-implementation>, we'll continue the
41732 % implementation of the theme by defining the snippet
41733 % `witiko/glossaries/import-acronyms`.
41734 %
41735 % \end{markdown}
41736 % \iffalse
41737 %</latex>
41738 %<*themes-witiko-markdown-defaults-latex>
41739 % \fi
41740 % \begin{markdown}
41741 %
41742 % The `witiko/markdown/defaults` \LaTeX{} theme also loads the corresponding
41743 % plain \TeX{} theme.
41744 %
41745 % \end{markdown}
41746 % \begin{macrocode}
41747 \markdownLoadPlainTeXTheme
41748 % \end{macrocode}
41749 % \iffalse
41750 %</themes-witiko-markdown-defaults-latex>
41751 %<*latex>
41752 % \fi
41753 % \begin{markdown}
41754 %
41755 % Next, the \LaTeX{} theme overrides some of the plain \TeX{} definitions.
41756 % See Section <#sec:latex-token-renderer-prototypes> for the actual
41757 % definitions.
41758 %
41759 %### Snippets {#latex-snippets-implementation}
41760 %
41761 % This section defines the built-in \LaTeX{} snippet
41762 % `witiko/glossaries/import-acronyms`.
41763 %
41764 % \end{markdown}
41765 % \begin{macrocode}
41766 \ExplSyntaxOn
41767 \prop_get:NnN
41768 \g_@@_latex_built_in_themes_prop
41769 { witiko / glossaries }
41770 \l_tmpa_tl
41771 \tl_put_right:Nn
41772 \l_tmpa_tl
41773 {
41774 \cs_new:Nn
41775 \@@_register_acronym:n
41776 {
41777 \@@_setup:n
41778 {
41779 % \end{macrocode}
41780 % \begin{markdown}
41781 %
41782 % When we register an acronym with the \Opt{acronyms} option, enclose it in an
41783 % extra set of braces in case the acronym contained a comma.
41784 %
41785 % \end{markdown}
41786 % \begin{macrocode}
41787 acronyms += {{ #1 }},
41788 }
41789 }
41790 \cs_generate_variant:Nn
41791 \@@_register_acronym:n
41792 { V }
41793 \prop_new:N
41794 \g_@@_acronyms_to_labels_prop
41795 \tl_new:N
41796 \l_@@_acronym_short_tl
41797 % \end{macrocode}
41798 % \begin{markdown}
41799 %
41800 % When we import an acronym from the \pkg{glossaries} package, we receive
41801 % a \meta{label}, which doesn't correspond to an acronym. Therefore, we
41802 % register the short form of the corresponding acronym instead and keep
41803 % a mapping from these short forms back to the labels when we need to display
41804 % an acronym in the markdown text.
41805 %
41806 % \end{markdown}
41807 % \begin{macrocode}
41808 \cs_new:Nn
41809 \@@_register_acronym_label:n
41810 {
41811 \tl_set:Nx
41812 \l_@@_acronym_short_tl
41813 { \glsentryshort { #1 } }
41814 % \end{macrocode}
41815 % \begin{markdown}
41816 %
41817 % Be idempotent and only import each acronym once.
41818 %
41819 % \end{markdown}
41820 % \begin{macrocode}
41821 \prop_if_in:NVF
41822 \g_@@_acronyms_to_labels_prop
41823 \l_@@_acronym_short_tl
41824 {
41825 \@@_register_acronym:V
41826 \l_@@_acronym_short_tl
41827 \prop_gput:NVn
41828 \g_@@_acronyms_to_labels_prop
41829 \l_@@_acronym_short_tl
41830 { #1 }
41831 }
41832 }
41833 \cs_generate_variant:Nn
41834 \@@_register_acronym_label:n
41835 { V }
41836 % \end{macrocode}
41837 % \begin{markdown}
41838 %
41839 % When we need to diplay an acronym in the markdown text, first consult our
41840 % mapping to see if it has been imported from the \pkg{glossaries} package.
41841 %
41842 % \end{markdown}
41843 % \begin{macrocode}
41844 \tl_new:N
41845 \l_@@_acronym_label_tl
41846 \cs_new:Nn
41847 \@@_print_acronym:n
41848 {
41849 \prop_get:NnNTF
41850 \g_@@_acronyms_to_labels_prop
41851 { #1 }
41852 \l_@@_acronym_label_tl
41853 {
41854 % \end{macrocode}
41855 % \begin{markdown}
41856 %
41857 % If it has, retrieve the \meta{label} and display the acronym using the
41858 % \pkg{glossaries} package, linking it to the corresponding glossary entry.
41859 %
41860 % \end{markdown}
41861 % \begin{macrocode}
41862 \group_begin:
41863 \cs_set_eq:NN
41864 \acronymfont
41865 \markdownRendererAcronymPrototype
41866 \exp_args:NV
41867 \acrshort
41868 \l_@@_acronym_label_tl
41869 \group_end:
41870 }
41871 {
41872 % \end{macrocode}
41873 % \begin{markdown}
41874 %
41875 % Otherwise, just format the acronym using the current renderer prototype.
41876 %
41877 % \end{markdown}
41878 % \begin{macrocode}
41879 \markdownRendererAcronymPrototype
41880 { #1 }
41881 }
41882 }
41883 \cs_generate_variant:Nn
41884 \@@_print_acronym:n
41885 { x }
41886 % \end{macrocode}
41887 % \begin{markdown}
41888 %
41889 % In the snippet `witiko/glossaries/import-acronyms`, first import all acronyms
41890 % from the \pkg{glossaries} package and register them with the \Opt{acronyms}
41891 % option.
41892 %
41893 % \end{markdown}
41894 % \begin{macrocode}
41895 \markdownSetupSnippet
41896 { import-acronyms }
41897 {
41898 code = {
41899 \forglsentries
41900 [ acronym ]
41901 \l_@@_acronym_label_tl
41902 {
41903 \@@_register_acronym_label:V
41904 \l_@@_acronym_label_tl
41905 }
41906 % \end{macrocode}
41907 % \begin{markdown}
41908 %
41909 % Then, redefine the corresponding token renderers to format acronyms that appear
41910 % in the markdown text.
41911 %
41912 % \end{markdown}
41913 % \begin{macrocode}
41914 \@@_setup:n
41915 {
41916 renderers = {
41917 acronym = {
41918 % \end{macrocode}
41919 % \begin{markdown}
41920 %
41921 % Fold nested acronyms.
41922 %
41923 % \end{markdown}
41924 % \begin{macrocode}
41925 \group_begin:
41926 \markdownSetup {
41927 unprotectedRenderers = {
41928 acronym = { ##1 },
41929 }
41930 }
41931 \@@_print_acronym:x
41932 { #1 }
41933 \group_end:
41934 }
41935 }
41936 }
41937 }
41938 }
41939 }
41940 \prop_gput:NnV
41941 \g_@@_latex_built_in_themes_prop
41942 { witiko / glossaries }
41943 \l_tmpa_tl
41944 \ExplSyntaxOff
41945 % \end{macrocode}
41946 % \begin{markdown}
41947 %
41948 %### Options
41949 % The supplied package options are processed using the \mref{markdownSetup} macro.
41950 %
41951 % \end{markdown}
41952 % \begin{macrocode}
41953 \DeclareOption*{%
41954 \expandafter\markdownSetup\expandafter{\CurrentOption}}%
41955 \ProcessOptions\relax
41956 % \end{macrocode}
41957 % \iffalse
41958 %</latex>
41959 %<*themes-witiko-markdown-defaults-latex>
41960 % \fi
41961 % \begin{markdown}
41962 %
41963 %### Token Renderer Prototypes {#latex-token-renderer-prototypes}
41964 %
41965 % The following configuration should be considered placeholder. If the option
41966 % `plain` has been enabled (see Section <#sec:plain>), none of the definitions
41967 % will take effect.
41968 % \end{markdown}
41969 % \begin{macrocode}
41970 \markdownIfOption{plain}{\iffalse}{\iftrue}
41971 % \end{macrocode}
41972 % \begin{markdown}
41973 %
41974 %#### Acronyms
41975 %
41976 % If the \Opt{acronyms} option is non-empty, render acronyms, initialisms, and
41977 % other all-caps sequences using small caps.
41978 %
41979 % \end{markdown}
41980 % \begin{macrocode}
41981 \ExplSyntaxOn
41982 \int_new:N
41983 \g_@@_heading_nesting_depth_int
41984 \markdownSetup {
41985 rendererPrototypes = {
41986 acronym = {
41987 % \end{macrocode}
41988 % \begin{markdown}
41989 %
41990 % Prevent acronyms in headings.
41991 %
41992 % \end{markdown}
41993 % \begin{macrocode}
41994 \int_if_zero:nTF
41995 { \g_@@_heading_nesting_depth_int }
41996 {
41997 % \end{macrocode}
41998 % \begin{markdown}
41999 %
42000 % Prevent nested acronyms.
42001 %
42002 % \end{markdown}
42003 % \begin{macrocode}
42004 \group_begin:
42005 \markdownSetup {
42006 unprotectedRenderers = {
42007 acronym = { ##1 },
42008 }
42009 }
42010 \tl_set:Nn
42011 \l_tmpa_tl
42012 { #1 }
42013 % \end{macrocode}
42014 % \begin{markdown}
42015 %
42016 % Render all characters that are neither digits nor ASCII lower case
42017 % characters in small caps. Ideally, we would also be able to exclude Unicode
42018 % lower-case characters but that doesn't seem possible with expl3 at the
42019 % moment [@latex26, Chapter 34 (The l3unicode module)].
42020 %
42021 % \end{markdown}
42022 % \begin{macrocode}
42023 \regex_replace_all:nnN
42024 { [^\d a-z]+ }
42025 {
42026 \c{ textsc } \cB\{
42027 \c{ MakeLowercase } \cB\{ \0 \cE\}
42028 \cE\}
42029 }
42030 \l_tmpa_tl
42031 % \end{macrocode}
42032 % \begin{markdown}
42033 %
42034 % Furthermore, if the current typeface supports it, render all digits using
42035 % old-style numerals.
42036 %
42037 % \end{markdown}
42038 % \begin{macrocode}
42039 \cs_if_exist:NT
42040 \oldstylenums
42041 {
42042 \regex_replace_all:nnN
42043 { \d+ }
42044 { \c{ oldstylenums } \cB\{ \0 \cE\} }
42045 \l_tmpa_tl
42046 }
42047 % \end{macrocode}
42048 % \begin{markdown}
42049 %
42050 % If the package \pkg{microtype} is loaded, letter-space the small caps.
42051 %
42052 % \end{markdown}
42053 % \begin{macrocode}
42054 \@ifpackageloaded
42055 { microtype }
42056 {
42057 \textls
42058 {
42059 \tl_use:N
42060 \l_tmpa_tl
42061 }
42062 }
42063 {
42064 \tl_use:N
42065 \l_tmpa_tl
42066 }
42067 \group_end:
42068 }
42069 % \end{macrocode}
42070 % \begin{markdown}
42071 %
42072 % Prevent acronyms in headings.
42073 %
42074 % \end{markdown}
42075 % \begin{macrocode}
42076 { #1 }
42077 },
42078 },
42079 }
42080 % \end{macrocode}
42081 % \begin{markdown}
42082 %
42083 % If the package \pkg{glossaries} is loaded with the option `acronym`, use the
42084 % built-in snippet \LaTeX{} `witiko/glossaries/import-acronyms`.
42085 % \end{markdown}
42086 % \begin{macrocode}
42087 \@ifpackageloaded
42088 { glossaries }
42089 {
42090 \cs_if_exist:NT
42091 \@gls@do@acronymsdef
42092 {
42093 \markdownSetup {
42094 import = /witiko/glossaries@v1,
42095 snippet = /witiko/glossaries/import-acronyms,
42096 }
42097 }
42098 }
42099 { }
42100 % \end{macrocode}
42101 % \begin{markdown}
42102 %
42103 %#### Lists
42104 %
42105 % If either the \Opt{tightLists} or the \Opt{fancyLists} option is enabled
42106 % and the current document class is not \pkg{beamer}, use a package that
42107 % provides support for tight and fancy lists.
42108 %
42109 % If either the package \pkg{paralist} or the package \pkg{enumitem} have
42110 % already been loaded, use them. Otherwise, if the option \Opt{experimental}
42111 % or the command `\DocumentMetadata` have been used, use the package
42112 % \pkg{enumitem}. Otherwise, use the package \pkg{paralist}.
42113 %
42114 % \end{markdown}
42115 % \begin{macrocode}
42116 \bool_new:N
42117 \g_@@_tight_or_fancy_lists_bool
42118 \bool_gset_false:N
42119 \g_@@_tight_or_fancy_lists_bool
42120 \@@_if_option:nTF
42121 { tightLists }
42122 {
42123 \bool_gset_true:N
42124 \g_@@_tight_or_fancy_lists_bool
42125 }
42126 {
42127 \@@_if_option:nT
42128 { fancyLists }
42129 {
42130 \bool_gset_true:N
42131 \g_@@_tight_or_fancy_lists_bool
42132 }
42133 }
42134 \bool_new:N
42135 \g_@@_beamer_paralist_or_enumitem_bool
42136 \bool_gset_true:N
42137 \g_@@_beamer_paralist_or_enumitem_bool
42138 \@ifclassloaded
42139 { beamer }
42140 { }
42141 {
42142 \@ifpackageloaded
42143 { paralist }
42144 { }
42145 {
42146 \@ifpackageloaded
42147 { enumitem }
42148 { }
42149 {
42150 \bool_gset_false:N
42151 \g_@@_beamer_paralist_or_enumitem_bool
42152 }
42153 }
42154 }
42155 \bool_if:nT
42156 {
42157 \g_@@_tight_or_fancy_lists_bool &&
42158 ! \g_@@_beamer_paralist_or_enumitem_bool
42159 }
42160 {
42161 \str_if_eq:enTF
42162 { \markdownThemeVersion }
42163 { experimental }
42164 {
42165 \RequirePackage
42166 { enumitem }
42167 }
42168 {
42169 \IfDocumentMetadataTF
42170 {
42171 \RequirePackage
42172 { enumitem }
42173 }
42174 {
42175 \RequirePackage
42176 { paralist }
42177 }
42178 }
42179 }
42180 \ExplSyntaxOff
42181 % \end{macrocode}
42182 % \begin{markdown}
42183 %
42184 % If we loaded the \pkg{enumitem} package, define the tight and
42185 % fancy list renderer prototypes to make use of the capabilities of
42186 % the package.
42187 %
42188 % \end{markdown}
42189 % \begin{macrocode}
42190 \ExplSyntaxOn
42191 \cs_new:Nn
42192 \@@_latex_fancy_list_item_label_number:nn
42193 {
42194 \str_case:nn
42195 { #1 }
42196 {
42197 { Decimal } { #2 }
42198 { LowerRoman } { \int_to_roman:n { #2 } }
42199 { UpperRoman } { \int_to_Roman:n { #2 } }
42200 { LowerAlpha } { \int_to_alph:n { #2 } }
42201 { UpperAlpha } { \int_to_Alph:n { #2 } }
42202 }
42203 }
42204 \cs_new:Nn
42205 \@@_latex_fancy_list_item_label_delimiter:n
42206 {
42207 \str_case:nn
42208 { #1 }
42209 {
42210 { Default } { . }
42211 { OneParen } { ) }
42212 { Period } { . }
42213 }
42214 }
42215 \cs_new:Nn
42216 \@@_latex_fancy_list_item_label:nnn
42217 {
42218 \@@_latex_fancy_list_item_label_number:nn
42219 { #1 }
42220 { #3 }
42221 \@@_latex_fancy_list_item_label_delimiter:n
42222 { #2 }
42223 }
42224 \cs_generate_variant:Nn
42225 \@@_latex_fancy_list_item_label:nnn
42226 { VVn }
42227 \tl_new:N
42228 \l_@@_latex_fancy_list_item_label_number_style_tl
42229 \tl_new:N
42230 \l_@@_latex_fancy_list_item_label_delimiter_style_tl
42231 \@ifpackageloaded { enumitem } {
42232 \markdownSetup { rendererPrototypes = {
42233 % \end{macrocode}
42234 % \begin{markdown}
42235 %
42236 % First, let's define the tight list item renderer prototypes.
42237 %
42238 % \end{markdown}
42239 % \begin{macrocode}
42240 ulBeginTight = {
42241 \begin
42242 { itemize }
42243 [ noitemsep ]
42244 },
42245 ulEndTight = {
42246 \end
42247 { itemize }
42248 },
42249 olBeginTight = {
42250 \begin
42251 { enumerate }
42252 [ noitemsep ]
42253 },
42254 olEndTight = {
42255 \end
42256 { enumerate }
42257 },
42258 dlBeginTight = {
42259 \begin
42260 { description }
42261 [ noitemsep ]
42262 },
42263 dlEndTight = {
42264 \end
42265 { description }
42266 },
42267 % \end{macrocode}
42268 % \begin{markdown}
42269 %
42270 % Second, let's define the fancy list item renderer prototypes.
42271 %
42272 % \end{markdown}
42273 % \begin{macrocode}
42274 fancyOlBegin = {
42275 \group_begin:
42276 \tl_set:Nn
42277 \l_@@_latex_fancy_list_item_label_number_style_tl
42278 { #1 }
42279 \tl_set:Nn
42280 \l_@@_latex_fancy_list_item_label_delimiter_style_tl
42281 { #2 }
42282 \begin
42283 { enumerate }
42284 },
42285 fancyOlBeginTight = {
42286 \group_begin:
42287 \tl_set:Nn
42288 \l_@@_latex_fancy_list_item_label_number_style_tl
42289 { #1 }
42290 \tl_set:Nn
42291 \l_@@_latex_fancy_list_item_label_delimiter_style_tl
42292 { #2 }
42293 \begin
42294 { enumerate }
42295 [ noitemsep ]
42296 },
42297 fancyOlEnd(|Tight) = {
42298 \end { enumerate }
42299 \group_end:
42300 },
42301 fancyOlItemWithNumber = {
42302 \item
42303 [
42304 \@@_latex_fancy_list_item_label:VVn
42305 \l_@@_latex_fancy_list_item_label_number_style_tl
42306 \l_@@_latex_fancy_list_item_label_delimiter_style_tl
42307 { #1 }
42308 ]
42309 },
42310 } }
42311 % \end{macrocode}
42312 % \begin{markdown}
42313 %
42314 % Otherwise, if we loaded the \pkg{paralist} package, define the
42315 % tight and fancy list renderer prototypes to make use of the
42316 % capabilities of the package.
42317 %
42318 % \end{markdown}
42319 % \begin{macrocode}
42320 }
42321 { \@ifpackageloaded { paralist } {
42322 \markdownSetup { rendererPrototypes = {
42323 % \end{macrocode}
42324 % \begin{markdown}
42325 %
42326 % Make tight bullet lists a little less compact by adding extra vertical space
42327 % above and below them.
42328 %
42329 % \end{markdown}
42330 % \begin{macrocode}
42331 ulBeginTight = {
42332 \group_begin:
42333 \pltopsep=\topsep
42334 \plpartopsep=\partopsep
42335 \begin { compactitem }
42336 },
42337 ulEndTight = {
42338 \end { compactitem }
42339 \group_end:
42340 },
42341 fancyOlBegin = {
42342 \group_begin:
42343 \tl_set:Nn
42344 \l_@@_latex_fancy_list_item_label_number_style_tl
42345 { #1 }
42346 \tl_set:Nn
42347 \l_@@_latex_fancy_list_item_label_delimiter_style_tl
42348 { #2 }
42349 \begin { enumerate }
42350 },
42351 fancyOlEnd = {
42352 \end { enumerate }
42353 \group_end:
42354 },
42355 % \end{macrocode}
42356 % \begin{markdown}
42357 %
42358 % Make tight ordered lists a little less compact by adding extra vertical
42359 % space above and below them.
42360 %
42361 % \end{markdown}
42362 % \begin{macrocode}
42363 olBeginTight = {
42364 \group_begin:
42365 \plpartopsep=\partopsep
42366 \pltopsep=\topsep
42367 \begin { compactenum }
42368 },
42369 olEndTight = {
42370 \end { compactenum }
42371 \group_end:
42372 },
42373 fancyOlBeginTight = {
42374 \group_begin:
42375 \tl_set:Nn
42376 \l_@@_latex_fancy_list_item_label_number_style_tl
42377 { #1 }
42378 \tl_set:Nn
42379 \l_@@_latex_fancy_list_item_label_delimiter_style_tl
42380 { #2 }
42381 \plpartopsep=\partopsep
42382 \pltopsep=\topsep
42383 \begin { compactenum }
42384 },
42385 fancyOlEndTight = {
42386 \end { compactenum }
42387 \group_end:
42388 },
42389 fancyOlItemWithNumber = {
42390 \item
42391 [
42392 \@@_latex_fancy_list_item_label:VVn
42393 \l_@@_latex_fancy_list_item_label_number_style_tl
42394 \l_@@_latex_fancy_list_item_label_delimiter_style_tl
42395 { #1 }
42396 ]
42397 },
42398 % \end{macrocode}
42399 % \begin{markdown}
42400 %
42401 % Make tight definition lists a little less compact by adding extra
42402 % vertical space above and below them.
42403 %
42404 % \end{markdown}
42405 % \begin{macrocode}
42406 dlBeginTight = {
42407 \group_begin:
42408 \plpartopsep=\partopsep
42409 \pltopsep=\topsep
42410 \begin { compactdesc }
42411 },
42412 dlEndTight = {
42413 \end { compactdesc }
42414 \group_end:
42415 }
42416 } }
42417 }
42418 {
42419 % \end{macrocode}
42420 % \begin{markdown}
42421 %
42422 % Otherwise, if we loaded neither the \pkg{enumitem} package nor the
42423 % \pkg{paralist} package, define the tight and fancy list renderer
42424 % prototypes to fall back on the corresponding renderers for the
42425 % non-tight lists.
42426 %
42427 % \end{markdown}
42428 % \begin{macrocode}
42429 \markdownSetup
42430 {
42431 rendererPrototypes = {
42432 ulBeginTight = \markdownRendererUlBegin,
42433 ulEndTight = \markdownRendererUlEnd,
42434 fancyOlBegin = \markdownRendererOlBegin,
42435 fancyOlEnd = \markdownRendererOlEnd,
42436 olBeginTight = \markdownRendererOlBegin,
42437 olEndTight = \markdownRendererOlEnd,
42438 fancyOlBeginTight = \markdownRendererOlBegin,
42439 fancyOlEndTight = \markdownRendererOlEnd,
42440 dlBeginTight = \markdownRendererDlBegin,
42441 dlEndTight = \markdownRendererDlEnd,
42442 },
42443 }
42444 } }
42445 \ExplSyntaxOff
42446 \RequirePackage{amsmath}
42447 % \end{macrocode}
42448 % \begin{markdown}
42449 %
42450 % Unless the \pkg{unicode-math} package has been loaded, load the \pkg{amssymb}
42451 % package with symbols to be used for tickboxes.
42452 %
42453 % \end{markdown}
42454 % \begin{macrocode}
42455 \@ifpackageloaded{unicode-math}{
42456 \markdownSetup{rendererPrototypes={
42457 untickedBox = {$\mdlgwhtsquare$},
42458 }}
42459 }{
42460 \RequirePackage{amssymb}
42461 \markdownSetup{rendererPrototypes={
42462 untickedBox = {$\square$},
42463 }}
42464 }
42465 \RequirePackage{csvsimple}
42466 \RequirePackage{fancyvrb}
42467 \RequirePackage{graphicx}
42468 \markdownSetup{rendererPrototypes={
42469 hardLineBreak = {\\},
42470 leftBrace = {\textbraceleft},
42471 rightBrace = {\textbraceright},
42472 dollarSign = {\textdollar},
42473 underscore = {\textunderscore},
42474 circumflex = {\textasciicircum},
42475 backslash = {\textbackslash},
42476 tilde = {\textasciitilde},
42477 pipe = {\textbar},
42478 % \end{macrocode}
42479 % \begin{markdown}
42480 %
42481 % We can capitalize on the fact that the expansion of renderers is performed by
42482 % \TeX{} during the typesetting. Therefore, even if we don't know whether a
42483 % span of text is part of math formula or not when we are parsing markdown,%
42484 % ^[This property may actually be undecidable. Suppose a span of text is a part
42485 % of a macro definition. Then, whether the span of text is part of a math
42486 % formula or not depends on where the macro is later used, which may easily
42487 % be *both* inside and outside a math formula.] we can reliably detect math
42488 % mode inside the renderer.
42489 %
42490 % Here, we will redefine the code span renderer prototype to typeset upright
42491 % text in math formulae and typewriter text outside math formulae.
42492 %
42493 % \end{markdown}
42494 % \begin{macrocode}
42495 codeSpan = {%
42496 \ifmmode
42497 \text{#1}%
42498 \else
42499 \texttt{#1}%
42500 \fi
42501 }}}
42502 % \end{macrocode}
42503 % \begin{markdown}
42504 %
42505 %#### Content Blocks
42506 %
42507 % In content block renderer prototypes, display the content as a table using
42508 % the package \pkg{csvsimple} when the raw attribute is `csv`, display the
42509 % content using the default templates of the package \pkg{luaxml} when the
42510 % raw attribute is `html`, execute the content with TeX when the raw attribute
42511 % is `tex`, and display the content as markdown otherwise.
42512 %
42513 % \end{markdown}
42514 % \begin{macrocode}
42515 \ExplSyntaxOn
42516 \markdownSetup{
42517 rendererPrototypes = {
42518 contentBlock = {
42519 \str_case:nnF
42520 { #1 }
42521 {
42522 { csv }
42523 {
42524 \begin { table }
42525 \begin { center }
42526 \csvautotabular { #3 }
42527 \end{ center }
42528 \tl_if_empty:nF
42529 { #4 }
42530 { \caption { #4 } }
42531 \end { table }
42532 }
42533 { html }
42534 {
42535 % \end{macrocode}
42536 % \begin{markdown}
42537 %
42538 % If we are using [\TeX{}4ht][1], we will pass HTML elements to the
42539 % output HTML document unchanged.
42540 %
42541 % [1]: https://tug.org/tex4ht/
42542 %
42543 % \end{markdown}
42544 % \begin{macrocode}
42545 \cs_if_exist:NTF
42546 \HCode
42547 {
42548 \if_mode_vertical:
42549 \IgnorePar
42550 \fi:
42551 \EndP
42552 \special
42553 { t4ht* < #3 }
42554 \par
42555 \ShowPar
42556 }
42557 {
42558 \@@_luaxml_print_html:n
42559 { #3 }
42560 }
42561 }
42562 { tex }
42563 {
42564 \markdownEscape
42565 { #3 }
42566 }
42567 }
42568 {
42569 \markdownInput
42570 { #3 }
42571 }
42572 },
42573 },
42574 }
42575 \ExplSyntaxOff
42576 \markdownSetup{rendererPrototypes={
42577 ulBegin = {\begin{itemize}},
42578 ulEnd = {\end{itemize}},
42579 olBegin = {\begin{enumerate}},
42580 olItem = {\item{}},
42581 olItemWithNumber = {\item[#1.]},
42582 olEnd = {\end{enumerate}},
42583 dlBegin = {\begin{description}},
42584 dlItem = {\item[#1]},
42585 dlEnd = {\end{description}},
42586 emphasis = {\emph{#1}},
42587 tickedBox = {$\boxtimes$},
42588 halfTickedBox = {$\boxdot$}}}
42589 % \end{macrocode}
42590 % \begin{markdown}
42591 %
42592 % If HTML identifiers appear after a heading, we make them
42593 % produce `\label` macros.
42594 %
42595 % \end{markdown}
42596 % \begin{macrocode}
42597 \ExplSyntaxOn
42598 \seq_new:N
42599 \g_@@_header_identifiers_seq
42600 \markdownSetup
42601 {
42602 rendererPrototypes = {
42603 headerAttributeContextBegin = {
42604 \markdownSetup
42605 {
42606 rendererPrototypes = {
42607 attributeIdentifier = {
42608 \seq_gput_right:Nn
42609 \g_@@_header_identifiers_seq
42610 { ##1 }
42611 },
42612 },
42613 }
42614 },
42615 headerAttributeContextEnd = {
42616 \seq_map_inline:Nn
42617 \g_@@_header_identifiers_seq
42618 { \label { ##1 } }
42619 \seq_gclear:N
42620 \g_@@_header_identifiers_seq
42621 },
42622 },
42623 }
42624 % \end{macrocode}
42625 % \begin{markdown}
42626 %
42627 % If the `unnumbered` HTML class (or the `{-}` shorthand) appears after
42628 % a heading the heading and all its subheadings will be unnumbered.
42629 %
42630 % \end{markdown}
42631 % \begin{macrocode}
42632 \bool_new:N
42633 \l_@@_header_unnumbered_bool
42634 \markdownSetup
42635 {
42636 rendererPrototypes = {
42637 headerAttributeContextBegin += {
42638 \markdownSetup
42639 {
42640 rendererPrototypes = {
42641 attributeClassName = {
42642 \bool_if:nT
42643 {
42644 \str_if_eq_p:nn
42645 { ##1 }
42646 { unnumbered } &&
42647 ! \l_@@_header_unnumbered_bool
42648 }
42649 {
42650 \group_begin:
42651 \bool_set_true:N
42652 \l_@@_header_unnumbered_bool
42653 \c@secnumdepth = -2
42654 \markdownSetup
42655 {
42656 rendererPrototypes = {
42657 sectionBegin = {
42658 \group_begin:
42659 },
42660 sectionEnd = {
42661 \group_end:
42662 },
42663 },
42664 }
42665 }
42666 },
42667 },
42668 }
42669 },
42670 },
42671 }
42672 \ExplSyntaxOff
42673 \markdownSetup{rendererPrototypes={
42674 superscript = {\textsuperscript{#1}},
42675 subscript = {\textsubscript{#1}},
42676 blockQuoteBegin = {\begin{quotation}},
42677 blockQuoteEnd = {\end{quotation}},
42678 inputVerbatim = {\VerbatimInput{#1}},
42679 thematicBreak = {\noindent\rule[0.5ex]{\linewidth}{1pt}},
42680 note = {\footnote{#1}}}}
42681 % \end{macrocode}
42682 % \begin{markdown}
42683 %
42684 %#### Fenced Code
42685 % When no infostring has been specified, default to the indented code block
42686 % renderer.
42687 %
42688 % \end{markdown}
42689 % \begin{macrocode}
42690 \RequirePackage{ltxcmds}
42691 \ExplSyntaxOn
42692 \cs_gset_protected:Npn
42693 \markdownRendererInputFencedCodePrototype#1#2#3
42694 {
42695 \tl_if_empty:nTF
42696 { #2 }
42697 { \markdownRendererInputVerbatim{#1} }
42698 % \end{macrocode}
42699 % \begin{markdown}
42700 %
42701 % Otherwise, extract the first word of the infostring and treat it as the name
42702 % of the programming language in which the code block is written.
42703 %
42704 % \end{markdown}
42705 % \begin{macrocode}
42706 {
42707 \regex_extract_once:nnN
42708 { \w* }
42709 { #2 }
42710 \l_tmpa_seq
42711 \seq_pop_left:NN
42712 \l_tmpa_seq
42713 \l_tmpa_tl
42714 % \end{macrocode}
42715 % \begin{markdown}
42716 %
42717 % When the \pkg{minted} package is loaded, use it for syntax highlighting.
42718 %
42719 % \end{markdown}
42720 % \begin{macrocode}
42721 \ltx@ifpackageloaded
42722 { minted }
42723 {
42724 \catcode`\%=14\relax
42725 \catcode`\#=6\relax
42726 \exp_args:NV
42727 \inputminted
42728 \l_tmpa_tl
42729 { #1 }
42730 \catcode`\%=12\relax
42731 \catcode`\#=12\relax
42732 }
42733 {
42734 % \end{macrocode}
42735 % \begin{markdown}
42736 %
42737 % When the \pkg{listings} package is loaded, use it for syntax highlighting.
42738 %
42739 % \end{markdown}
42740 % \begin{macrocode}
42741 \ltx@ifpackageloaded
42742 { listings }
42743 { \lstinputlisting [ language = \l_tmpa_tl ] { #1 } }
42744 % \end{macrocode}
42745 % \begin{markdown}
42746 %
42747 % When neither the \pkg{listings} package nor the \pkg{minted} package is
42748 % loaded, act as though no infostring were given.
42749 %
42750 % \end{markdown}
42751 % \begin{macrocode}
42752 { \markdownRendererInputFencedCode { #1 } { } { } }
42753 }
42754 }
42755 }
42756 \ExplSyntaxOff
42757 % \end{macrocode}
42758 % \begin{markdown}
42759 %
42760 % Support the nesting of strong emphasis.
42761 %
42762 % \end{markdown}
42763 % \begin{macrocode}
42764 \ExplSyntaxOn
42765 \def\markdownLATEXStrongEmphasis#1{
42766 \str_if_in:NnTF
42767 \f@series
42768 { b }
42769 { \textnormal{#1} }
42770 { \textbf{#1} }
42771 }
42772 \ExplSyntaxOff
42773 \markdownSetup{rendererPrototypes={strongEmphasis={%
42774 \protect\markdownLATEXStrongEmphasis{#1}}}}
42775 % \end{macrocode}
42776 % \begin{markdown}
42777 %
42778 % Support \LaTeX{} document classes that do not provide chapters.
42779 %
42780 % \end{markdown}
42781 % \begin{macrocode}
42782 \@ifundefined{chapter}{%
42783 \markdownSetup{rendererPrototypes = {
42784 headingOne = {\section{#1}},
42785 headingTwo = {\subsection{#1}},
42786 headingThree = {\subsubsection{#1}},
42787 headingFour = {\paragraph{#1}},
42788 headingFive = {\subparagraph{#1}}}}
42789 }{%
42790 \markdownSetup{rendererPrototypes = {
42791 headingOne = {\chapter{#1}},
42792 headingTwo = {\section{#1}},
42793 headingThree = {\subsection{#1}},
42794 headingFour = {\subsubsection{#1}},
42795 headingFive = {\paragraph{#1}},
42796 headingSix = {\subparagraph{#1}}}}
42797 }%
42798 % \end{macrocode}
42799 % \begin{markdown}
42800 %
42801 % Prevent acronyms in headings.
42802 %
42803 % \end{markdown}
42804 % \begin{macrocode}
42805 \ExplSyntaxOn
42806 \markdownSetup {
42807 rendererPrototypes = {
42808 heading* ^= {
42809 \int_gincr:N
42810 \g_@@_heading_nesting_depth_int
42811 },
42812 heading* $= {
42813 \int_gdecr:N
42814 \g_@@_heading_nesting_depth_int
42815 }
42816 }
42817 }
42818 \ExplSyntaxOff
42819 % \end{macrocode}
42820 % \begin{markdown}
42821 %
42822 %#### Tickboxes
42823 % If the \Opt{taskLists} option is enabled, we will hide bullets in unordered
42824 % list items with tickboxes.
42825 %
42826 % \end{markdown}
42827 % \begin{macrocode}
42828 \markdownSetup{
42829 rendererPrototypes = {
42830 ulItem = {%
42831 \futurelet\markdownLaTeXCheckbox\markdownLaTeXUlItem
42832 },
42833 },
42834 }
42835 \def\markdownLaTeXUlItem{%
42836 \ifx\markdownLaTeXCheckbox\markdownRendererTickedBox
42837 \item[\markdownLaTeXCheckbox]%
42838 \expandafter\@gobble
42839 \else
42840 \ifx\markdownLaTeXCheckbox\markdownRendererHalfTickedBox
42841 \item[\markdownLaTeXCheckbox]%
42842 \expandafter\expandafter\expandafter\@gobble
42843 \else
42844 \ifx\markdownLaTeXCheckbox\markdownRendererUntickedBox
42845 \item[\markdownLaTeXCheckbox]%
42846 \expandafter\expandafter\expandafter\expandafter
42847 \expandafter\expandafter\expandafter\@gobble
42848 \else
42849 \item{}%
42850 \fi
42851 \fi
42852 \fi
42853 }
42854 % \end{macrocode}
42855 % \begin{markdown}
42856 %
42857 %#### HTML elements
42858 % If the \Opt{html} option is enabled and we are using [\TeX{}4ht][1], we will
42859 % pass HTML elements to the output HTML document unchanged.
42860 %
42861 % [1]: https://tug.org/tex4ht/
42862 %
42863 % \end{markdown}
42864 % \begin{macrocode}
42865 \@ifundefined{HCode}{}{
42866 \markdownSetup{
42867 rendererPrototypes = {
42868 inlineHtmlTag = {%
42869 \ifvmode
42870 \IgnorePar
42871 \EndP
42872 \fi
42873 \HCode{#1}%
42874 },
42875 inputBlockHtmlElement = {%
42876 \ifvmode
42877 \IgnorePar
42878 \fi
42879 \EndP
42880 \special{t4ht*<#1}%
42881 \par
42882 \ShowPar
42883 },
42884 },
42885 }
42886 }
42887 % \end{macrocode}
42888 % \begin{markdown}
42889 %
42890 %#### Citations
42891 % Here is a basic implementation for citations that uses the \LaTeX{} `\cite`
42892 % macro. There are also implementations that use the \pkg{natbib} `\citep`,
42893 % and `\citet` macros, and the Bib\LaTeX{} `\autocites` and `\textcites`
42894 % macros. These implementations will be used, when the respective packages are
42895 % loaded.
42896 %
42897 % \end{markdown}
42898 % \begin{macrocode}
42899 \newcount\markdownLaTeXCitationsCounter
42900
42901 % Basic implementation
42902 \long\def\@gobblethree#1#2#3{}%
42903 \def\markdownLaTeXBasicCitations#1#2#3#4#5#6{%
42904 \advance\markdownLaTeXCitationsCounter by 1\relax
42905 \ifx\relax#4\relax
42906 \ifx\relax#5\relax
42907 \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal
42908 \relax
42909 \cite{#1#2#6}% No prenotes/postnotes, just accumulate cites
42910 \expandafter\expandafter\expandafter
42911 \expandafter\expandafter\expandafter\expandafter
42912 \@gobblethree
42913 \fi
42914 \else% Before a postnote (#5), dump the accumulator
42915 \ifx\relax#1\relax\else
42916 \cite{#1}%
42917 \fi
42918 \cite[#5]{#6}%
42919 \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal
42920 \relax
42921 \else
42922 \expandafter\expandafter\expandafter
42923 \expandafter\expandafter\expandafter\expandafter
42924 \expandafter\expandafter\expandafter
42925 \expandafter\expandafter\expandafter\expandafter
42926 \markdownLaTeXBasicCitations
42927 \fi
42928 \expandafter\expandafter\expandafter
42929 \expandafter\expandafter\expandafter\expandafter{%
42930 \expandafter\expandafter\expandafter
42931 \expandafter\expandafter\expandafter\expandafter}%
42932 \expandafter\expandafter\expandafter
42933 \expandafter\expandafter\expandafter\expandafter{%
42934 \expandafter\expandafter\expandafter
42935 \expandafter\expandafter\expandafter\expandafter}%
42936 \expandafter\expandafter\expandafter
42937 \@gobblethree
42938 \fi
42939 \else% Before a prenote (#4), dump the accumulator
42940 \ifx\relax#1\relax\else
42941 \cite{#1}%
42942 \fi
42943 \ifnum\markdownLaTeXCitationsCounter>1\relax
42944 \space % Insert a space before the prenote in later citations
42945 \fi
42946 #4~\expandafter\cite\ifx\relax#5\relax{#6}\else[#5]{#6}\fi
42947 \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal
42948 \relax
42949 \else
42950 \expandafter\expandafter\expandafter
42951 \expandafter\expandafter\expandafter\expandafter
42952 \markdownLaTeXBasicCitations
42953 \fi
42954 \expandafter\expandafter\expandafter{%
42955 \expandafter\expandafter\expandafter}%
42956 \expandafter\expandafter\expandafter{%
42957 \expandafter\expandafter\expandafter}%
42958 \expandafter
42959 \@gobblethree
42960 \fi\markdownLaTeXBasicCitations{#1#2#6},}
42961 \let\markdownLaTeXBasicTextCitations\markdownLaTeXBasicCitations
42962
42963 % Natbib implementation
42964 \def\markdownLaTeXNatbibCitations#1#2#3#4#5{%
42965 \advance\markdownLaTeXCitationsCounter by 1\relax
42966 \ifx\relax#3\relax
42967 \ifx\relax#4\relax
42968 \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal
42969 \relax
42970 \citep{#1,#5}% No prenotes/postnotes, just accumulate cites
42971 \expandafter\expandafter\expandafter
42972 \expandafter\expandafter\expandafter\expandafter
42973 \@gobbletwo
42974 \fi
42975 \else% Before a postnote (#4), dump the accumulator
42976 \ifx\relax#1\relax\else
42977 \citep{#1}%
42978 \fi
42979 \citep[][#4]{#5}%
42980 \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal
42981 \relax
42982 \else
42983 \expandafter\expandafter\expandafter
42984 \expandafter\expandafter\expandafter\expandafter
42985 \expandafter\expandafter\expandafter
42986 \expandafter\expandafter\expandafter\expandafter
42987 \markdownLaTeXNatbibCitations
42988 \fi
42989 \expandafter\expandafter\expandafter
42990 \expandafter\expandafter\expandafter\expandafter{%
42991 \expandafter\expandafter\expandafter
42992 \expandafter\expandafter\expandafter\expandafter}%
42993 \expandafter\expandafter\expandafter
42994 \@gobbletwo
42995 \fi
42996 \else% Before a prenote (#3), dump the accumulator
42997 \ifx\relax#1\relax\relax\else
42998 \citep{#1}%
42999 \fi
43000 \citep[#3][#4]{#5}%
43001 \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal
43002 \relax
43003 \else
43004 \expandafter\expandafter\expandafter
43005 \expandafter\expandafter\expandafter\expandafter
43006 \markdownLaTeXNatbibCitations
43007 \fi
43008 \expandafter\expandafter\expandafter{%
43009 \expandafter\expandafter\expandafter}%
43010 \expandafter
43011 \@gobbletwo
43012 \fi\markdownLaTeXNatbibCitations{#1,#5}}
43013 \def\markdownLaTeXNatbibTextCitations#1#2#3#4#5{%
43014 \advance\markdownLaTeXCitationsCounter by 1\relax
43015 \ifx\relax#3\relax
43016 \ifx\relax#4\relax
43017 \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal
43018 \relax
43019 \citet{#1,#5}% No prenotes/postnotes, just accumulate cites
43020 \expandafter\expandafter\expandafter
43021 \expandafter\expandafter\expandafter\expandafter
43022 \@gobbletwo
43023 \fi
43024 \else% After a prenote or a postnote, dump the accumulator
43025 \ifx\relax#1\relax\else
43026 \citet{#1}%
43027 \fi
43028 , \citet[#3][#4]{#5}%
43029 \ifnum\markdownLaTeXCitationsCounter<\markdownLaTeXCitationsTotal
43030 \relax
43031 ,
43032 \else
43033 \ifnum
43034 \markdownLaTeXCitationsCounter=\markdownLaTeXCitationsTotal
43035 \relax
43036 ,
43037 \fi
43038 \fi
43039 \expandafter\expandafter\expandafter
43040 \expandafter\expandafter\expandafter\expandafter
43041 \markdownLaTeXNatbibTextCitations
43042 \expandafter\expandafter\expandafter
43043 \expandafter\expandafter\expandafter\expandafter{%
43044 \expandafter\expandafter\expandafter
43045 \expandafter\expandafter\expandafter\expandafter}%
43046 \expandafter\expandafter\expandafter
43047 \@gobbletwo
43048 \fi
43049 \else% After a prenote or a postnote, dump the accumulator
43050 \ifx\relax#1\relax\relax\else
43051 \citet{#1}%
43052 \fi
43053 , \citet[#3][#4]{#5}%
43054 \ifnum\markdownLaTeXCitationsCounter<\markdownLaTeXCitationsTotal
43055 \relax
43056 ,
43057 \else
43058 \ifnum
43059 \markdownLaTeXCitationsCounter=\markdownLaTeXCitationsTotal
43060 \relax
43061 ,
43062 \fi
43063 \fi
43064 \expandafter\expandafter\expandafter
43065 \markdownLaTeXNatbibTextCitations
43066 \expandafter\expandafter\expandafter{%
43067 \expandafter\expandafter\expandafter}%
43068 \expandafter
43069 \@gobbletwo
43070 \fi\markdownLaTeXNatbibTextCitations{#1,#5}}
43071
43072 % BibLaTeX implementation
43073 \def\markdownLaTeXBibLaTeXCitations#1#2#3#4#5{%
43074 \advance\markdownLaTeXCitationsCounter by 1\relax
43075 \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal
43076 \relax
43077 \autocites#1[#3][#4]{#5}%
43078 \expandafter\@gobbletwo
43079 \fi\markdownLaTeXBibLaTeXCitations{#1[#3][#4]{#5}}}
43080 \def\markdownLaTeXBibLaTeXTextCitations#1#2#3#4#5{%
43081 \advance\markdownLaTeXCitationsCounter by 1\relax
43082 \ifnum\markdownLaTeXCitationsCounter>\markdownLaTeXCitationsTotal
43083 \relax
43084 \textcites#1[#3][#4]{#5}%
43085 \expandafter\@gobbletwo
43086 \fi\markdownLaTeXBibLaTeXTextCitations{#1[#3][#4]{#5}}}
43087
43088 \markdownSetup{rendererPrototypes = {
43089 cite = {%
43090 \markdownLaTeXCitationsCounter=1%
43091 \def\markdownLaTeXCitationsTotal{#1}%
43092 \@ifundefined{autocites}{%
43093 \@ifundefined{citep}{%
43094 \expandafter\expandafter\expandafter
43095 \markdownLaTeXBasicCitations
43096 \expandafter\expandafter\expandafter{%
43097 \expandafter\expandafter\expandafter}%
43098 \expandafter\expandafter\expandafter{%
43099 \expandafter\expandafter\expandafter}%
43100 }{%
43101 \expandafter\expandafter\expandafter
43102 \markdownLaTeXNatbibCitations
43103 \expandafter\expandafter\expandafter{%
43104 \expandafter\expandafter\expandafter}%
43105 }%
43106 }{%
43107 \expandafter\expandafter\expandafter
43108 \markdownLaTeXBibLaTeXCitations
43109 \expandafter{\expandafter}%
43110 }},
43111 textCite = {%
43112 \markdownLaTeXCitationsCounter=1%
43113 \def\markdownLaTeXCitationsTotal{#1}%
43114 \@ifundefined{autocites}{%
43115 \@ifundefined{citep}{%
43116 \expandafter\expandafter\expandafter
43117 \markdownLaTeXBasicTextCitations
43118 \expandafter\expandafter\expandafter{%
43119 \expandafter\expandafter\expandafter}%
43120 \expandafter\expandafter\expandafter{%
43121 \expandafter\expandafter\expandafter}%
43122 }{%
43123 \expandafter\expandafter\expandafter
43124 \markdownLaTeXNatbibTextCitations
43125 \expandafter\expandafter\expandafter{%
43126 \expandafter\expandafter\expandafter}%
43127 }%
43128 }{%
43129 \expandafter\expandafter\expandafter
43130 \markdownLaTeXBibLaTeXTextCitations
43131 \expandafter{\expandafter}%
43132 }}}}
43133 % \end{macrocode}
43134 % \begin{markdown}
43135 %
43136 %#### Links
43137 % Here is an implementation for hypertext links and relative references.
43138 %
43139 % \end{markdown}
43140 % \begin{macrocode}
43141 \RequirePackage{url}
43142 \RequirePackage{expl3}
43143 \ExplSyntaxOn
43144 \cs_gset_protected:Npn
43145 \markdownRendererLinkPrototype
43146 #1#2#3#4
43147 {
43148 \tl_set:Nn \l_tmpa_tl { #1 }
43149 \tl_set:Nn \l_tmpb_tl { #2 }
43150 \bool_set:Nn
43151 \l_tmpa_bool
43152 {
43153 \tl_if_eq_p:NN
43154 \l_tmpa_tl
43155 \l_tmpb_tl
43156 }
43157 \tl_set:Nn \l_tmpa_tl { #4 }
43158 \bool_set:Nn
43159 \l_tmpb_bool
43160 {
43161 \tl_if_empty_p:N
43162 \l_tmpa_tl
43163 }
43164 % \end{macrocode}
43165 % \begin{markdown}
43166 % If the label and the fully-escaped URI are equivalent and the title is
43167 % empty, assume that the link is an autolink. Otherwise, assume that the
43168 % link is either direct or indirect.
43169 % \end{markdown}
43170 % \begin{macrocode}
43171 \bool_if:nTF
43172 {
43173 \l_tmpa_bool && \l_tmpb_bool
43174 }
43175 {
43176 \markdownLaTeXRendererAutolink { #2 } { #3 }
43177 }
43178 {
43179 \markdownLaTeXRendererDirectOrIndirectLink
43180 { #1 } { #2 } { #3 } { #4 }
43181 }
43182 }
43183 \def\markdownLaTeXRendererAutolink#1#2{
43184 % \end{macrocode}
43185 % \begin{markdown}
43186 % If the URL begins with a hash sign, then we assume that it is a relative
43187 % reference. Otherwise, we assume that it is an absolute URL.
43188 % \end{markdown}
43189 % \begin{macrocode}
43190 \tl_set:Nn
43191 \l_tmpa_tl
43192 { #2 }
43193 \tl_trim_spaces:N
43194 \l_tmpa_tl
43195 \tl_set:Nx
43196 \l_tmpb_tl
43197 {
43198 \tl_range:Nnn
43199 \l_tmpa_tl
43200 { 1 }
43201 { 1 }
43202 }
43203 \str_if_eq:NNTF
43204 \l_tmpb_tl
43205 \c_hash_str
43206 {
43207 \tl_set:Nx
43208 \l_tmpb_tl
43209 {
43210 \tl_range:Nnn
43211 \l_tmpa_tl
43212 { 2 }
43213 { -1 }
43214 }
43215 \exp_args:NV
43216 \ref
43217 \l_tmpb_tl
43218 }
43219 {
43220 \url { #2 }
43221 }
43222 }
43223 \ExplSyntaxOff
43224 \def\markdownLaTeXRendererDirectOrIndirectLink#1#2#3#4{%
43225 #1\footnote{\ifx\empty#4\empty\else#4: \fi\url{#3}}}
43226 % \end{macrocode}
43227 % \begin{markdown}
43228 %
43229 %#### Tables
43230 % Here is a basic implementation of tables. If the \pkg{booktabs} package is
43231 % loaded, then it is used to produce horizontal lines.
43232 %
43233 % \end{markdown}
43234 % \begin{macrocode}
43235 \newcount\markdownLaTeXRowCounter
43236 \newcount\markdownLaTeXRowTotal
43237 \newcount\markdownLaTeXColumnCounter
43238 \newcount\markdownLaTeXColumnTotal
43239 \newtoks\markdownLaTeXTable
43240 \newtoks\markdownLaTeXTableAlignment
43241 \newtoks\markdownLaTeXTableEnd
43242 \AtBeginDocument{%
43243 \@ifpackageloaded{booktabs}{%
43244 \def\markdownLaTeXTopRule{\toprule}%
43245 \def\markdownLaTeXMidRule{\midrule}%
43246 \def\markdownLaTeXBottomRule{\bottomrule}%
43247 }{%
43248 \def\markdownLaTeXTopRule{\hline}%
43249 \def\markdownLaTeXMidRule{\hline}%
43250 \def\markdownLaTeXBottomRule{\hline}%
43251 }%
43252 }
43253 \markdownSetup{rendererPrototypes={
43254 table = {%
43255 \markdownLaTeXTable={}%
43256 \markdownLaTeXTableAlignment={}%
43257 \markdownLaTeXTableEnd={%
43258 \markdownLaTeXBottomRule
43259 \end{tabular}}%
43260 \ifx\empty#1\empty\else
43261 \addto@hook\markdownLaTeXTable{%
43262 \begin{table}
43263 \centering}%
43264 \addto@hook\markdownLaTeXTableEnd{%
43265 \caption{#1}}%
43266 \fi
43267 }
43268 }}
43269 % \end{macrocode}
43270 % \begin{markdown}
43271 %
43272 % If the \Opt{tableAttributes} option is enabled, we will register any
43273 % identifiers, so that they can be used as \LaTeX{} labels for referencing
43274 % tables.
43275 %
43276 % \end{markdown}
43277 % \begin{macrocode}
43278 \ExplSyntaxOn
43279 \seq_new:N
43280 \l_@@_table_identifiers_seq
43281 \markdownSetup {
43282 rendererPrototypes = {
43283 table += {
43284 \seq_map_inline:Nn
43285 \l_@@_table_identifiers_seq
43286 {
43287 \addto@hook
43288 \markdownLaTeXTableEnd
43289 { \label { ##1 } }
43290 }
43291 },
43292 }
43293 }
43294 \markdownSetup {
43295 rendererPrototypes = {
43296 tableAttributeContextBegin = {
43297 \group_begin:
43298 \markdownSetup {
43299 rendererPrototypes = {
43300 attributeIdentifier = {
43301 \seq_put_right:Nn
43302 \l_@@_table_identifiers_seq
43303 { ##1 }
43304 },
43305 },
43306 }
43307 },
43308 tableAttributeContextEnd = {
43309 \group_end:
43310 },
43311 },
43312 }
43313 \ExplSyntaxOff
43314 \markdownSetup{rendererPrototypes={
43315 table += {%
43316 \ifx\empty#1\empty\else
43317 \addto@hook\markdownLaTeXTableEnd{%
43318 \end{table}}%
43319 \fi
43320 \addto@hook\markdownLaTeXTable{\begin{tabular}}%
43321 \markdownLaTeXRowCounter=0%
43322 \markdownLaTeXRowTotal=#2%
43323 \markdownLaTeXColumnTotal=#3%
43324 \markdownLaTeXRenderTableRow
43325 }
43326 }}
43327 \def\markdownLaTeXRenderTableRow#1{%
43328 \markdownLaTeXColumnCounter=0%
43329 \ifnum\markdownLaTeXRowCounter=0\relax
43330 \markdownLaTeXReadAlignments#1%
43331 \markdownLaTeXTable=\expandafter\expandafter\expandafter{%
43332 \expandafter\the\expandafter\markdownLaTeXTable\expandafter{%
43333 \the\markdownLaTeXTableAlignment}}%
43334 \addto@hook\markdownLaTeXTable{\markdownLaTeXTopRule}%
43335 \else
43336 \markdownLaTeXRenderTableCell#1%
43337 \fi
43338 \ifnum\markdownLaTeXRowCounter=1\relax
43339 \addto@hook\markdownLaTeXTable\markdownLaTeXMidRule
43340 \fi
43341 \advance\markdownLaTeXRowCounter by 1\relax
43342 \ifnum\markdownLaTeXRowCounter>\markdownLaTeXRowTotal\relax
43343 \the\markdownLaTeXTable
43344 \the\markdownLaTeXTableEnd
43345 \expandafter\@gobble
43346 \fi\markdownLaTeXRenderTableRow}
43347 \def\markdownLaTeXReadAlignments#1{%
43348 \advance\markdownLaTeXColumnCounter by 1\relax
43349 \if#1d%
43350 \addto@hook\markdownLaTeXTableAlignment{l}%
43351 \else
43352 \addto@hook\markdownLaTeXTableAlignment{#1}%
43353 \fi
43354 \ifnum\markdownLaTeXColumnCounter<\markdownLaTeXColumnTotal\relax\else
43355 \expandafter\@gobble
43356 \fi\markdownLaTeXReadAlignments}
43357 \def\markdownLaTeXRenderTableCell#1{%
43358 \advance\markdownLaTeXColumnCounter by 1\relax
43359 \ifnum\markdownLaTeXColumnCounter<\markdownLaTeXColumnTotal\relax
43360 \addto@hook\markdownLaTeXTable{#1&}%
43361 \else
43362 \addto@hook\markdownLaTeXTable{#1\\}%
43363 \expandafter\@gobble
43364 \fi\markdownLaTeXRenderTableCell}
43365 % \end{macrocode}
43366 % \begin{markdown}
43367 %
43368 %#### Line Blocks
43369 % Here is a basic implementation of line blocks. If the \pkg{verse} package is
43370 % loaded, then it is used to produce the verses.
43371 %
43372 % \end{markdown}
43373 % \begin{macrocode}
43374
43375 \markdownIfOption{lineBlocks}{%
43376 \RequirePackage{verse}
43377 \markdownSetup{rendererPrototypes={
43378 lineBlockBegin = {%
43379 \begingroup
43380 \def\markdownRendererHardLineBreak{\\}%
43381 \begin{verse}%
43382 },
43383 lineBlockEnd = {%
43384 \end{verse}%
43385 \endgroup
43386 },
43387 }}
43388 }{}
43389
43390 % \end{macrocode}
43391 % \begin{markdown}
43392 %
43393 %#### YAML Metadata {#latex-yaml-metadata}
43394 %
43395 % The default setup of YAML metadata will invoke the `\title`,
43396 % `\author`, and `\date` macros when scalar values for keys that
43397 % correspond to the `title`, `author`, and `date` relative wildcards are
43398 % encountered, respectively.
43399 %
43400 % \end{markdown}
43401 % \begin{macrocode}
43402 \ExplSyntaxOn
43403 \keys_define:nn
43404 { markdown / jekyllData }
43405 {
43406 author .value_required:n = { true },
43407 author .code:n = {
43408 \author
43409 { #1 }
43410 },
43411 date .value_required:n = { true },
43412 date .code:n = {
43413 \date
43414 { #1 }
43415 },
43416 title .value_required:n = { true },
43417 title .code:n = {
43418 \title
43419 { #1 }
43420 % \end{macrocode}
43421 % \begin{markdown}
43422 %
43423 % To complement the default setup of our key--values, we will use
43424 % the `\maketitle` macro to typeset the title page of a document
43425 % at the end of YAML metadata. If we are in the preamble, we will wait
43426 % macro until after the beginning of the document. Otherwise, we will use
43427 % the `\maketitle` macro straight away, temporarily resetting the category
43428 % codes of the percent sign and the hash sign back to comment and parameter,
43429 % respectively.
43430 %
43431 % \end{markdown}
43432 % \begin{macrocode}
43433 \char_set_catcode_comment:N \%
43434 \char_set_catcode_parameter:N \#
43435 \AddToHook
43436 { begindocument / end }
43437 { \maketitle }
43438 \char_set_catcode_other:N \%
43439 \char_set_catcode_other:N \#
43440 },
43441 }
43442 % \end{macrocode}
43443 % \begin{markdown}
43444 %
43445 %#### Marked Text
43446 % If the \Opt{mark} option is enabled, we will load either the \pkg{soul}
43447 % package or the \pkg{lua-ul} package and use it to implement marked text.
43448 %
43449 % \end{markdown}
43450 % \begin{macrocode}
43451 \@@_if_option:nT
43452 { mark }
43453 {
43454 \sys_if_engine_luatex:TF
43455 {
43456 \RequirePackage
43457 { luacolor }
43458 \RequirePackage
43459 { lua-ul }
43460 \markdownSetup
43461 {
43462 rendererPrototypes = {
43463 mark = {
43464 \highLight
43465 { #1 }
43466 },
43467 }
43468 }
43469 }
43470 {
43471 \RequirePackage
43472 { xcolor }
43473 \RequirePackage
43474 { soul }
43475 \markdownSetup
43476 {
43477 rendererPrototypes = {
43478 mark = {
43479 \hl
43480 { #1 }
43481 },
43482 }
43483 }
43484 }
43485 }
43486 % \end{macrocode}
43487 % \begin{markdown}
43488 %
43489 %#### Strike-Through
43490 % If the \Opt{strikeThrough} option is enabled, we will load either the
43491 % \pkg{soul} package or the \pkg{lua-ul} package and use it to implement
43492 % strike-throughs.
43493 %
43494 % \end{markdown}
43495 % \begin{macrocode}
43496 \@@_if_option:nT
43497 { strikeThrough }
43498 {
43499 \sys_if_engine_luatex:TF
43500 {
43501 \RequirePackage
43502 { lua-ul }
43503 \markdownSetup
43504 {
43505 rendererPrototypes = {
43506 strikeThrough = {
43507 \strikeThrough
43508 { #1 }
43509 },
43510 }
43511 }
43512 }
43513 {
43514 \RequirePackage
43515 { soul }
43516 \markdownSetup
43517 {
43518 rendererPrototypes = {
43519 strikeThrough = {
43520 \st
43521 { #1 }
43522 },
43523 }
43524 }
43525 }
43526 }
43527 % \end{macrocode}
43528 % \begin{markdown}
43529 %
43530 %#### Images and their attributes
43531 %
43532 % We define images to be rendered as floating figures using the command
43533 % `\includegraphics`, where the image label is the alt text and the image
43534 % title is the caption of the figure.
43535 %
43536 % If the \Opt{linkAttributes} option is enabled, we will make attributes in the
43537 % form \meta{key}`=`\meta{value} set the corresponding keys of the
43538 % \pkg{graphicx} package to the corresponding values and we will register any
43539 % identifiers, so that they can be used as \LaTeX{} labels for referencing
43540 % figures.
43541 %
43542 % \end{markdown}
43543 % \begin{macrocode}
43544 \seq_new:N
43545 \l_@@_image_identifiers_seq
43546 \markdownSetup {
43547 rendererPrototypes = {
43548 image = {
43549 \tl_if_empty:nTF
43550 { #4 }
43551 {
43552 \begin { center }
43553 \includegraphics
43554 [ alt = { #1 } ]
43555 { #3 }
43556 \end { center }
43557 }
43558 {
43559 \begin { figure }
43560 \begin { center }
43561 \includegraphics
43562 [ alt = { #1 } ]
43563 { #3 }
43564 \caption { #4 }
43565 \seq_map_inline:Nn
43566 \l_@@_image_identifiers_seq
43567 { \label { ##1 } }
43568 \end { center }
43569 \end { figure }
43570 }
43571 },
43572 }
43573 }
43574 \@@_if_option:nT
43575 { linkAttributes }
43576 {
43577 \RequirePackage { graphicx }
43578 }
43579 \markdownSetup {
43580 rendererPrototypes = {
43581 imageAttributeContextBegin = {
43582 \group_begin:
43583 \markdownSetup {
43584 rendererPrototypes = {
43585 attributeIdentifier = {
43586 \seq_put_right:Nn
43587 \l_@@_image_identifiers_seq
43588 { ##1 }
43589 },
43590 attributeKeyValue = {
43591 \setkeys
43592 { Gin }
43593 { { ##1 } = { ##2 } }
43594 },
43595 },
43596 }
43597 },
43598 imageAttributeContextEnd = {
43599 \group_end:
43600 },
43601 },
43602 }
43603 \ExplSyntaxOff
43604 % \end{macrocode}
43605 % \begin{markdown}
43606 %
43607 %#### Raw Attributes
43608 %
43609 % In the raw block and inline raw span renderer prototypes, display the content
43610 % using the default templates of the package \pkg{luaxml} when the raw
43611 % attribute is `html` and default to the plain TeX renderer prototypes
43612 % otherwise, translating raw attribute `latex` to `tex`.
43613 %
43614 % \end{markdown}
43615 % \begin{macrocode}
43616 \ExplSyntaxOn
43617 \cs_new:Nn
43618 \@@_luaxml_print_html:n
43619 {
43620 \luabridge_now:n
43621 {
43622 local~input_file = assert(io.open(" #1 ", "r"))
43623 local~input = assert(input_file:read("*a"))
43624 assert(input_file:close())
43625 input = "<body>" .. input .. "</body>"
43626 local~dom = require("luaxml-domobject").html_parse(input)
43627 local~output = require("luaxml-htmltemplates"):process_dom(dom)
43628 print(output)
43629 }
43630 }
43631 \cs_gset_protected:Npn
43632 \markdownRendererInputRawInlinePrototype#1#2
43633 {
43634 \str_case:nnF
43635 { #2 }
43636 {
43637 { latex }
43638 {
43639 \@@_plain_tex_default_input_raw_inline:nn
43640 { #1 }
43641 { tex }
43642 }
43643 { html }
43644 {
43645 % \end{macrocode}
43646 % \begin{markdown}
43647 %
43648 % If we are using [\TeX{}4ht][1], we will pass HTML elements to the
43649 % output HTML document unchanged.
43650 %
43651 % [1]: https://tug.org/tex4ht/
43652 %
43653 % \end{markdown}
43654 % \begin{macrocode}
43655 \cs_if_exist:NTF
43656 \HCode
43657 {
43658 \if_mode_vertical:
43659 \IgnorePar
43660 \EndP
43661 \fi:
43662 \special
43663 { t4ht* < #1 }
43664 }
43665 {
43666 \@@_luaxml_print_html:n
43667 { #1 }
43668 }
43669 }
43670 }
43671 {
43672 \@@_plain_tex_default_input_raw_inline:nn
43673 { #1 }
43674 { #2 }
43675 }
43676 }
43677 \cs_gset_protected:Npn
43678 \markdownRendererInputRawBlockPrototype#1#2
43679 {
43680 \str_case:nnF
43681 { #2 }
43682 {
43683 { latex }
43684 {
43685 \@@_plain_tex_default_input_raw_block:nn
43686 { #1 }
43687 { tex }
43688 }
43689 { html }
43690 {
43691 % \end{macrocode}
43692 % \begin{markdown}
43693 %
43694 % If we are using [\TeX{}4ht][1], we will pass HTML elements to the
43695 % output HTML document unchanged.
43696 %
43697 % [1]: https://tug.org/tex4ht/
43698 %
43699 % \end{markdown}
43700 % \begin{macrocode}
43701 \cs_if_exist:NTF
43702 \HCode
43703 {
43704 \if_mode_vertical:
43705 \IgnorePar
43706 \fi:
43707 \EndP
43708 \special
43709 { t4ht* < #1 }
43710 \par
43711 \ShowPar
43712 }
43713 {
43714 \@@_luaxml_print_html:n
43715 { #1 }
43716 }
43717 }
43718 }
43719 {
43720 \@@_plain_tex_default_input_raw_block:nn
43721 { #1 }
43722 { #2 }
43723 }
43724 }
43725 % \end{macrocode}
43726 % \begin{markdown}
43727 %
43728 %#### Bracketed spans
43729 %
43730 % If the \Opt{bracketedSpans} option is enabled, we will register any
43731 % identifiers, so that they can be used as \LaTeX{} labels for referencing
43732 % the last \LaTeX{} counter that has been incremented in e.g. ordered lists.
43733 %
43734 % \end{markdown}
43735 % \begin{macrocode}
43736 \seq_new:N
43737 \l_@@_bracketed_span_identifiers_seq
43738 \markdownSetup {
43739 rendererPrototypes = {
43740 bracketedSpanAttributeContextBegin $= {
43741 \markdownSetup {
43742 rendererPrototypes = {
43743 attributeIdentifier = {
43744 \seq_put_right:Nn
43745 \l_@@_bracketed_span_identifiers_seq
43746 { ##1 }
43747 },
43748 },
43749 }
43750 },
43751 bracketedSpanAttributeContextEnd ^= {
43752 \seq_map_inline:Nn
43753 \l_@@_bracketed_span_identifiers_seq
43754 { \label { ##1 } }
43755 },
43756 },
43757 }
43758 % \end{macrocode}
43759 % \begin{markdown}
43760 %
43761 % We will also allow acronyms to be manually marked up using the HTML
43762 % class `acronym`.
43763 %
43764 % \end{markdown}
43765 % \begin{macrocode}
43766 \markdownSetup {
43767 rendererPrototypes = {
43768 bracketedSpanAttributeContextBegin += {
43769 \markdownSetup {
43770 rendererPrototypes = {
43771 attributeClassName = {
43772 \str_if_eq:nnT
43773 { ##1 }
43774 { acronym }
43775 {
43776 \markdownSetup {
43777 rendererPrototypes = {
43778 bracketedSpan = {
43779 \markdownRendererAcronym
43780 { ####1 }
43781 }
43782 }
43783 }
43784 }
43785 },
43786 },
43787 }
43788 },
43789 },
43790 }
43791 \ExplSyntaxOff
43792 \fi % Closes `\markdownIfOption{plain}{\iffalse}{\iftrue}`
43793 % \end{macrocode}
43794 % \iffalse
43795 %</themes-witiko-markdown-defaults-latex>
43796 %<*latex>
43797 % \fi
43798 % \begin{markdown}
43799 %
43800 %### Miscellanea
43801 % When buffering user input, we should disable the bytes with the high bit set,
43802 % since these are made active by the \pkg{inputenc} package. We will do this by
43803 % redefining the \mref{markdownMakeOther} macro accordingly. The code is courtesy
43804 % of Scott Pakin, the creator of the \pkg{filecontents} package.
43805 %
43806 % \end{markdown}
43807 % \begin{macrocode}
43808 \newcommand\markdownMakeOther{%
43809 \count0=128\relax
43810 \loop
43811 \catcode\count0=11\relax
43812 \advance\count0 by 1\relax
43813 \ifnum\count0<256\repeat}%
43814 % \end{macrocode}
43815 % \iffalse
43816 %</latex>
43817 %<*context>
43818 % \fi
43819 % \begin{markdown}
43820 %
43821 % \Hologo{ConTeXt} Implementation {#contextimplementation}
43822 %---------------------------------
43823 %
43824 % The \Hologo{ConTeXt} implementation makes use of the fact that, apart from
43825 % some subtle differences, the Mark II and Mark IV \Hologo{ConTeXt} formats
43826 % *seem* to implement (the documentation is scarce) the majority of the
43827 % plain \TeX{} format required by the plain \TeX{} implementation. As a
43828 % consequence, we can directly reuse the existing plain \TeX{} implementation
43829 % after supplying the missing plain \TeX{} macros.
43830 %
43831 % When buffering user input, we should disable the bytes with the high bit set,
43832 % since these are made active by the `\enableregime` macro. We will do this
43833 % by redefining the \mref{markdownMakeOther} macro accordingly. The code is
43834 % courtesy of Scott Pakin, the creator of the \pkg{filecontents} \LaTeX{}
43835 % package.
43836 %
43837 % \end{markdown}
43838 % \begin{macrocode}
43839 \def\markdownMakeOther{%
43840 \count0=128\relax
43841 \loop
43842 \catcode\count0=11\relax
43843 \advance\count0 by 1\relax
43844 \ifnum\count0<256\repeat
43845 % \end{macrocode}
43846 % \begin{markdown}
43847 %
43848 % On top of that, make the pipe character (`|`) inactive during the scanning.
43849 % This is necessary, since the character is active in \Hologo{ConTeXt}.
43850 %
43851 % \end{markdown}
43852 % \begin{macrocode}
43853 \catcode`|=12}%
43854 % \end{macrocode}
43855 % \begin{markdown}
43856 %
43857 %### Typesetting Markdown
43858 % The \mref{inputmarkdown} and \mref{inputyaml} macros are defined to accept an
43859 % optional argument with options recognized by the \Hologo{ConTeXt} interface
43860 % (see Section <#sec:context-options>).
43861 %
43862 % \end{markdown}
43863 % \begin{macrocode}
43864 \long\def\inputmarkdown{%
43865 \dosingleempty
43866 \doinputmarkdown}%
43867 \long\def\doinputmarkdown[#1]#2{%
43868 \begingroup
43869 \iffirstargument
43870 \setupmarkdown[#1]%
43871 \fi
43872 \markdownInput{#2}%
43873 \endgroup}%
43874 \long\def\inputyaml{%
43875 \dosingleempty
43876 \doinputyaml}%
43877 \long\def\doinputyaml[#1]#2{%
43878 \doinputmarkdown
43879 [jekyllData, expectJekyllData, ensureJekyllData, #1]{#2}}%
43880 % \end{macrocode}
43881 % \begin{markdown}
43882 %
43883 % The \mref{startmarkdown}, \mref{stopmarkdown}, \mref{startyaml}, and
43884 % \mref{stopyaml} macros are implemented using the
43885 % \mref{markdownReadAndConvert} macro.
43886 %
43887 % In Knuth's \TeX, trailing spaces are removed very early on when a line is
43888 % being put to the input buffer.~[@knuth86b, sec. 31]. According to
43889 % @eijkhout92 [sec. 2.2], this is because ``these spaces are hard to see in
43890 % an editor''. At the moment, there is no option to suppress this behavior in
43891 % (Lua)\TeX, but \Hologo{ConTeXt} MkIV funnels all input through its own input
43892 % handler. This makes it possible to suppress the removal of trailing spaces
43893 % in \Hologo{ConTeXt} MkIV and therefore to insert hard line breaks into
43894 % markdown text.
43895 %
43896 % \end{markdown}
43897 % \begin{macrocode}
43898 \startluacode
43899 document.markdown_buffering = false
43900 local function preserve_trailing_spaces(line)
43901 if document.markdown_buffering then
43902 line = line:gsub("[ \t][ \t]$", "\t\t")
43903 end
43904 return line
43905 end
43906 resolvers.installinputlinehandler(preserve_trailing_spaces)
43907 \stopluacode
43908 \begingroup
43909 \catcode`\|=0%
43910 \catcode`\\=12%
43911 |gdef|startmarkdown{%
43912 |ctxlua{document.markdown_buffering = true}%
43913 |markdownReadAndConvert{\stopmarkdown}%
43914 {|stopmarkdown}}%
43915 |gdef|stopmarkdown{%
43916 |ctxlua{document.markdown_buffering = false}%
43917 |markdownEnd}%
43918 |gdef|startyaml{%
43919 |begingroup
43920 |ctxlua{document.markdown_buffering = true}%
43921 |setupyaml[jekyllData, expectJekyllData, ensureJekyllData]%
43922 |markdownReadAndConvert{\stopyaml}%
43923 {|stopyaml}}%
43924 |gdef|stopyaml{%
43925 |ctxlua{document.markdown_buffering = false}%
43926 |yamlEnd}%
43927 |endgroup
43928 % \end{macrocode}
43929 % \begin{markdown}
43930 %
43931 %### Themes {#context-themes-implementation}
43932 %
43933 % This section overrides the plain \TeX{} implementation of the theme-loading
43934 % mechanism from Section <#sec:themes-implementation>. Furthermore, this section
43935 % also implements the built-in \Hologo{ConTeXt} themes provided with the
43936 % Markdown package.
43937 %
43938 % \end{markdown}
43939 % \begin{macrocode}
43940 \ExplSyntaxOn
43941 \prop_new:N \g_@@_context_loaded_themes_linenos_prop
43942 \prop_new:N \g_@@_context_loaded_themes_versions_prop
43943 \cs_gset:Nn
43944 \@@_load_theme:nnn
43945 {
43946 % \end{macrocode}
43947 % \begin{markdown}
43948 %
43949 % Determine whether either this is a built-in theme according to the prop
43950 % \mref{g_@@_context_built_in_themes_prop} or a file named
43951 % `t-markdowntheme`\meta{munged theme name}`.tex` exists. If it does, load it.
43952 % Otherwise, try loading a plain \TeX{} theme instead.
43953 %
43954 % \end{markdown}
43955 % \begin{macrocode}
43956 \bool_if:nTF
43957 {
43958 \bool_lazy_or_p:nn
43959 {
43960 \prop_if_in_p:Nn
43961 \g_@@_context_built_in_themes_prop
43962 { #1 }
43963 }
43964 {
43965 \file_if_exist_p:n
43966 { t - markdown theme #3.tex }
43967 }
43968 }
43969 {
43970 \prop_get:NnNTF
43971 \g_@@_context_loaded_themes_linenos_prop
43972 { #1 }
43973 \l_tmpa_tl
43974 {
43975 \prop_get:NnN
43976 \g_@@_context_loaded_themes_versions_prop
43977 { #1 }
43978 \l_tmpb_tl
43979 \str_if_eq:nVTF
43980 { #2 }
43981 \l_tmpb_tl
43982 {
43983 \msg_warning:nnnVn
43984 { markdown }
43985 { repeatedly-loaded-context-theme }
43986 { #1 }
43987 \l_tmpa_tl
43988 { #2 }
43989 }
43990 {
43991 \msg_error:nnnnVV
43992 { markdown }
43993 { different-versions-of-context-theme }
43994 { #1 }
43995 { #2 }
43996 \l_tmpb_tl
43997 \l_tmpa_tl
43998 }
43999 }
44000 {
44001 \prop_gput:Nnx
44002 \g_@@_context_loaded_themes_linenos_prop
44003 { #1 }
44004 { \tex_the:D \tex_inputlineno:D } % noqa: W200
44005 \prop_gput:Nnn
44006 \g_@@_context_loaded_themes_versions_prop
44007 { #1 }
44008 { #2 }
44009 % \end{macrocode}
44010 % \begin{markdown}
44011 %
44012 % Load built-in plain \TeX{} themes from the prop
44013 % \mref{g_@@_context_built_in_themes_prop} and from the filesystem otherwise.
44014 %
44015 % \end{markdown}
44016 % \begin{macrocode}
44017 \prop_if_in:NnTF
44018 \g_@@_context_built_in_themes_prop
44019 { #1 }
44020 {
44021 \msg_info:nnnn
44022 { markdown }
44023 { loading-built-in-context-theme }
44024 { #1 }
44025 { #2 }
44026 \prop_item:Nn
44027 \g_@@_context_built_in_themes_prop
44028 { #1 }
44029 }
44030 {
44031 \msg_info:nnnn
44032 { markdown }
44033 { loading-context-theme }
44034 { #1 }
44035 { #2 }
44036 \usemodule
44037 [ t ]
44038 [ markdown theme #3 ]
44039 }
44040 }
44041 }
44042 {
44043 \@@_plain_tex_load_theme:nnn
44044 { #1 }
44045 { #2 }
44046 { #3 }
44047 }
44048 }
44049 \msg_new:nnn
44050 { markdown }
44051 { loading-built-in-context-theme }
44052 { Loading~version~#2~of~built-in~ConTeXt~Markdown~theme~#1 }
44053 \msg_new:nnn
44054 { markdown }
44055 { loading-context-theme }
44056 { Loading~version~#2~of~ConTeXt~Markdown~theme~#1 }
44057 \msg_new:nnn
44058 { markdown }
44059 { repeatedly-loaded-context-theme }
44060 {
44061 Version~#3~of~ConTeXt~Markdown~theme~#1~was~previously~
44062 loaded~on~line~#2,~not~loading~it~again
44063 }
44064 \msg_new:nnn
44065 { markdown }
44066 { different-versions-of-context-theme }
44067 {
44068 Tried~to~load~version~#2~of~ConTeXt~Markdown~theme~#1~
44069 but~version~#3~has~already~been~loaded~on~line~#4
44070 }
44071 \ExplSyntaxOff
44072 % \end{macrocode}
44073 % \iffalse
44074 %</context>
44075 %<*themes-witiko-markdown-defaults-ctx>
44076 % \fi
44077 % \begin{markdown}
44078 %
44079 % The `witiko/markdown/defaults` \Hologo{ConTeXt} theme provides default
44080 % definitions for token renderer prototypes. First, the \Hologo{ConTeXt} theme
44081 % loads the plain \TeX{} theme with the default definitions for plain \TeX{}:
44082 %
44083 % \end{markdown}
44084 % \begin{macrocode}
44085 \markdownLoadPlainTeXTheme
44086 % \end{macrocode}
44087 % \begin{markdown}
44088 %
44089 % Next, the \Hologo{ConTeXt} theme overrides some of the plain \TeX{} definitions.
44090 % See Section <#sec:context-token-renderer-prototypes> for the actual
44091 % definitions.
44092 %
44093 %### Token Renderer Prototypes {#context-token-renderer-prototypes}
44094 %
44095 % The following configuration should be considered placeholder. If the option
44096 % `plain` has been enabled (see Section <#sec:plain>), none of the definitions
44097 % will take effect.
44098 %
44099 % \end{markdown}
44100 % \begin{macrocode}
44101 \markdownIfOption{plain}{\iffalse}{\iftrue}
44102 \def\markdownRendererHardLineBreakPrototype{\blank}%
44103 \def\markdownRendererLeftBracePrototype{\textbraceleft}%
44104 \def\markdownRendererRightBracePrototype{\textbraceright}%
44105 \def\markdownRendererDollarSignPrototype{\textdollar}%
44106 \def\markdownRendererPercentSignPrototype{\percent}%
44107 \def\markdownRendererUnderscorePrototype{\textunderscore}%
44108 \def\markdownRendererCircumflexPrototype{\textcircumflex}%
44109 \def\markdownRendererBackslashPrototype{\textbackslash}%
44110 \def\markdownRendererTildePrototype{\textasciitilde}%
44111 \def\markdownRendererPipePrototype{\char`|}%
44112 \def\markdownRendererLinkPrototype#1#2#3#4{%
44113 \useURL[#1][#3][][#4]#1\footnote[#1]{\ifx\empty#4\empty\else#4:
44114 \fi\tt<\hyphenatedurl{#3}>}}%
44115 \usemodule[database]
44116 \defineseparatedlist
44117 [MarkdownConTeXtCSV]
44118 [separator={,},
44119 before=\bTABLE,after=\eTABLE,
44120 first=\bTR,last=\eTR,
44121 left=\bTD,right=\eTD]
44122 \def\markdownConTeXtCSV{csv}
44123 \def\markdownRendererContentBlockPrototype#1#2#3#4{%
44124 \def\markdownConTeXtCSV@arg{#1}%
44125 \ifx\markdownConTeXtCSV@arg\markdownConTeXtCSV
44126 \placetable[][tab:#1]{#4}{%
44127 \processseparatedfile[MarkdownConTeXtCSV][#3]}%
44128 \else
44129 \markdownInput{#3}%
44130 \fi}%
44131 \def\markdownRendererImagePrototype#1#2#3#4{%
44132 \placefigure[][]{#4}{\externalfigure[#3]}}%
44133 \def\markdownRendererUlBeginPrototype{\startitemize}%
44134 \def\markdownRendererUlBeginTightPrototype{\startitemize[packed]}%
44135 \def\markdownRendererUlItemPrototype{\item}%
44136 \def\markdownRendererUlEndPrototype{\stopitemize}%
44137 \def\markdownRendererUlEndTightPrototype{\stopitemize}%
44138 \def\markdownRendererOlBeginPrototype{\startitemize[n]}%
44139 \def\markdownRendererOlBeginTightPrototype{\startitemize[packed,n]}%
44140 \def\markdownRendererOlItemPrototype{\item}%
44141 \def\markdownRendererOlItemWithNumberPrototype#1{\sym{#1.}}%
44142 \def\markdownRendererOlEndPrototype{\stopitemize}%
44143 \def\markdownRendererOlEndTightPrototype{\stopitemize}%
44144 \definedescription
44145 [MarkdownConTeXtDlItemPrototype]
44146 [location=hanging,
44147 margin=standard,
44148 headstyle=bold]%
44149 \definestartstop
44150 [MarkdownConTeXtDlPrototype]
44151 [before=\blank,
44152 after=\blank]%
44153 \definestartstop
44154 [MarkdownConTeXtDlTightPrototype]
44155 [before=\blank\startpacked,
44156 after=\stoppacked\blank]%
44157 \def\markdownRendererDlBeginPrototype{%
44158 \startMarkdownConTeXtDlPrototype}%
44159 \def\markdownRendererDlBeginTightPrototype{%
44160 \startMarkdownConTeXtDlTightPrototype}%
44161 \def\markdownRendererDlItemPrototype#1{%
44162 \startMarkdownConTeXtDlItemPrototype{#1}}%
44163 \def\markdownRendererDlItemEndPrototype{%
44164 \stopMarkdownConTeXtDlItemPrototype}%
44165 \def\markdownRendererDlEndPrototype{%
44166 \stopMarkdownConTeXtDlPrototype}%
44167 \def\markdownRendererDlEndTightPrototype{%
44168 \stopMarkdownConTeXtDlTightPrototype}%
44169 \def\markdownRendererEmphasisPrototype#1{{\em#1}}%
44170 \def\markdownRendererStrongEmphasisPrototype#1{{\bf#1}}%
44171 \def\markdownRendererBlockQuoteBeginPrototype{\startquotation}%
44172 \def\markdownRendererBlockQuoteEndPrototype{\stopquotation}%
44173 \def\markdownRendererLineBlockBeginPrototype{%
44174 \begingroup
44175 \def\markdownRendererHardLineBreak{
44176 }%
44177 \startlines
44178 }%
44179 \def\markdownRendererLineBlockEndPrototype{%
44180 \stoplines
44181 \endgroup
44182 }%
44183 \def\markdownRendererInputVerbatimPrototype#1{\typefile{#1}}%
44184 % \end{macrocode}
44185 % \begin{markdown}
44186 %
44187 %#### Fenced Code
44188 % When no infostring has been specified, default to the indented code block
44189 % renderer.
44190 %
44191 % \end{markdown}
44192 % \begin{macrocode}
44193 \ExplSyntaxOn
44194 \cs_gset:Npn
44195 \markdownRendererInputFencedCodePrototype#1#2#3
44196 {
44197 \tl_if_empty:nTF
44198 { #2 }
44199 { \markdownRendererInputVerbatim{#1} }
44200 % \end{macrocode}
44201 % \begin{markdown}
44202 %
44203 % Otherwise, extract the first word of the infostring and treat it as the name
44204 % of the programming language in which the code block is written.
44205 % This name is then used in the \Hologo{ConTeXt} `\definetyping` macro, which
44206 % allows the user to set up code highlighting mapping as follows:
44207 % ````` tex
44208 % % Map the `TEX` syntax highlighter to the `latex` infostring.
44209 % \definetyping [latex]
44210 % \setuptyping [latex] [option=TEX]
44211 %
44212 % \starttext
44213 % \startmarkdown
44214 % ~~~ latex
44215 % \documentclass{article}
44216 % \begin{document}
44217 % Hello world!
44218 % \end{document}
44219 % ~~~
44220 % \stopmarkdown
44221 % \stoptext
44222 % `````````
44223 %
44224 % \end{markdown}
44225 % \begin{macrocode}
44226 {
44227 \regex_extract_once:nnN
44228 { \w* }
44229 { #2 }
44230 \l_tmpa_seq
44231 \seq_pop_left:NN
44232 \l_tmpa_seq
44233 \l_tmpa_tl
44234 \typefile[ \l_tmpa_tl ][] {#1}
44235 }
44236 }
44237 \ExplSyntaxOff
44238 \def\markdownRendererHeadingOnePrototype#1{\chapter{#1}}%
44239 \def\markdownRendererHeadingTwoPrototype#1{\section{#1}}%
44240 \def\markdownRendererHeadingThreePrototype#1{\subsection{#1}}%
44241 \def\markdownRendererHeadingFourPrototype#1{\subsubsection{#1}}%
44242 \def\markdownRendererHeadingFivePrototype#1{\subsubsubsection{#1}}%
44243 \def\markdownRendererHeadingSixPrototype#1{\subsubsubsubsection{#1}}%
44244 \def\markdownRendererThematicBreakPrototype{%
44245 \blackrule[height=1pt, width=\hsize]}%
44246 \def\markdownRendererNotePrototype#1{\footnote{#1}}%
44247 \def\markdownRendererTickedBoxPrototype{$\boxtimes$}
44248 \def\markdownRendererHalfTickedBoxPrototype{$\boxdot$}
44249 \def\markdownRendererUntickedBoxPrototype{$\square$}
44250 \def\markdownRendererStrikeThroughPrototype#1{\overstrikes{#1}}
44251 \def\markdownRendererSuperscriptPrototype#1{\high{#1}}
44252 \def\markdownRendererSubscriptPrototype#1{\low{#1}}
44253 \def\markdownRendererDisplayMathPrototype#1{%
44254 \startformula#1\stopformula}%
44255 % \end{macrocode}
44256 % \begin{markdown}
44257 %
44258 %#### Tables
44259 % There is a basic implementation of tables.
44260 %
44261 % \end{markdown}
44262 % \begin{macrocode}
44263 \newcount\markdownConTeXtRowCounter
44264 \newcount\markdownConTeXtRowTotal
44265 \newcount\markdownConTeXtColumnCounter
44266 \newcount\markdownConTeXtColumnTotal
44267 \newtoks\markdownConTeXtTable
44268 \newtoks\markdownConTeXtTableFloat
44269 \def\markdownRendererTablePrototype#1#2#3{%
44270 \markdownConTeXtTable={}%
44271 \ifx\empty#1\empty
44272 \markdownConTeXtTableFloat={%
44273 \the\markdownConTeXtTable}%
44274 \else
44275 \markdownConTeXtTableFloat={%
44276 \placetable{#1}{\the\markdownConTeXtTable}}%
44277 \fi
44278 \begingroup
44279 \setupTABLE[r][each][topframe=off, bottomframe=off,
44280 leftframe=off, rightframe=off]
44281 \setupTABLE[c][each][topframe=off, bottomframe=off,
44282 leftframe=off, rightframe=off]
44283 \setupTABLE[r][1][topframe=on, bottomframe=on]
44284 \setupTABLE[r][#1][bottomframe=on]
44285 \markdownConTeXtRowCounter=0%
44286 \markdownConTeXtRowTotal=#2%
44287 \markdownConTeXtColumnTotal=#3%
44288 \markdownConTeXtRenderTableRow}
44289 \def\markdownConTeXtRenderTableRow#1{%
44290 \markdownConTeXtColumnCounter=0%
44291 \ifnum\markdownConTeXtRowCounter=0\relax
44292 \markdownConTeXtReadAlignments#1%
44293 \markdownConTeXtTable={\bTABLE}%
44294 \else
44295 \markdownConTeXtTable=\expandafter{%
44296 \the\markdownConTeXtTable\bTR}%
44297 \markdownConTeXtRenderTableCell#1%
44298 \markdownConTeXtTable=\expandafter{%
44299 \the\markdownConTeXtTable\eTR}%
44300 \fi
44301 \advance\markdownConTeXtRowCounter by 1\relax
44302 \ifnum\markdownConTeXtRowCounter>\markdownConTeXtRowTotal\relax
44303 \markdownConTeXtTable=\expandafter{%
44304 \the\markdownConTeXtTable\eTABLE}%
44305 \the\markdownConTeXtTableFloat
44306 \endgroup
44307 \expandafter\gobbleoneargument
44308 \fi\markdownConTeXtRenderTableRow}
44309 \def\markdownConTeXtReadAlignments#1{%
44310 \advance\markdownConTeXtColumnCounter by 1\relax
44311 \if#1d%
44312 \setupTABLE[c][\the\markdownConTeXtColumnCounter][align=right]
44313 \fi\if#1l%
44314 \setupTABLE[c][\the\markdownConTeXtColumnCounter][align=right]
44315 \fi\if#1c%
44316 \setupTABLE[c][\the\markdownConTeXtColumnCounter][align=middle]
44317 \fi\if#1r%
44318 \setupTABLE[c][\the\markdownConTeXtColumnCounter][align=left]
44319 \fi
44320 \ifnum\markdownConTeXtColumnCounter<\markdownConTeXtColumnTotal\relax
44321 \else
44322 \expandafter\gobbleoneargument
44323 \fi\markdownConTeXtReadAlignments}
44324 \def\markdownConTeXtRenderTableCell#1{%
44325 \advance\markdownConTeXtColumnCounter by 1\relax
44326 \markdownConTeXtTable=\expandafter{%
44327 \the\markdownConTeXtTable\bTD#1\eTD}%
44328 \ifnum\markdownConTeXtColumnCounter<\markdownConTeXtColumnTotal\relax
44329 \else
44330 \expandafter\gobbleoneargument
44331 \fi\markdownConTeXtRenderTableCell}
44332 % \end{macrocode}
44333 % \begin{markdown}
44334 %
44335 %#### Raw Attributes
44336 %
44337 % In the raw block and inline raw span renderer prototypes, default to the
44338 % plain TeX renderer prototypes, translating raw attribute `context` to `tex`.
44339 %
44340 % \end{markdown}
44341 % \begin{macrocode}
44342 \ExplSyntaxOn
44343 \cs_gset:Npn
44344 \markdownRendererInputRawInlinePrototype#1#2
44345 {
44346 \str_case:nnF
44347 { #2 }
44348 {
44349 { latex }
44350 {
44351 \@@_plain_tex_default_input_raw_inline:nn
44352 { #1 }
44353 { context }
44354 }
44355 }
44356 {
44357 \@@_plain_tex_default_input_raw_inline:nn
44358 { #1 }
44359 { #2 }
44360 }
44361 }
44362 \cs_gset:Npn
44363 \markdownRendererInputRawBlockPrototype#1#2
44364 {
44365 \str_case:nnF
44366 { #2 }
44367 {
44368 { context }
44369 {
44370 \@@_plain_tex_default_input_raw_block:nn
44371 { #1 }
44372 { tex }
44373 }
44374 }
44375 {
44376 \@@_plain_tex_default_input_raw_block:nn
44377 { #1 }
44378 { #2 }
44379 }
44380 }
44381 \cs_gset_eq:NN
44382 \markdownRendererInputRawBlockPrototype
44383 \markdownRendererInputRawInlinePrototype
44384 \fi % Closes `\markdownIfOption{plain}{\iffalse}{\iftrue}`
44385 \ExplSyntaxOff
44386 \stopmodule
44387 \protect
44388 % \end{macrocode}
44389 % \iffalse
44390 %</themes-witiko-markdown-defaults-ctx>
44391 %<*context>
44392 % \fi
44393 % \begin{markdown}
44394 %
44395 % At the end of the \Hologo{ConTeXt} module, we load the
44396 % `witiko/markdown/defaults` \Hologo{ConTeXt} theme with the default
44397 % definitions for token renderer prototypes unless the option `noDefaults`
44398 % has been enabled (see Section <#sec:plain>).
44399 %
44400 % \end{markdown}
44401 % \begin{macrocode}
44402 \ExplSyntaxOn
44403 \str_if_eq:VVT
44404 \c_@@_top_layer_tl
44405 \c_@@_option_layer_context_tl
44406 {
44407 \use:c
44408 { ExplSyntaxOff }
44409 \@@_if_option:nF
44410 { noDefaults }
44411 {
44412 \@@_if_option:nTF
44413 { experimental }
44414 {
44415 \@@_setup:n
44416 { theme = witiko/markdown/defaults@experimental }
44417 }
44418 {
44419 \@@_setup:n
44420 { theme = witiko/markdown/defaults }
44421 }
44422 }
44423 \use:c
44424 { ExplSyntaxOn }
44425 }
44426 \ExplSyntaxOff
44427 \stopmodule
44428 \protect
44429 % \end{macrocode}
44430 % \iffalse
44431 %</context>
44432 % \fi