| 1 |
\fontfam[lm] |
| 2 |
\hyperlinks\Blue\Blue |
| 3 |
|
| 4 |
% Set options of the Markdown module |
| 5 |
\_def \markdownOptions { |
| 6 |
cacheDir="_markdown_example", |
| 7 |
definitionLists=true, |
| 8 |
fencedCode=true, |
| 9 |
hashEnumerators=true, |
| 10 |
smartEllipses=true, |
| 11 |
strikeThrough=true, |
| 12 |
} |
| 13 |
|
| 14 |
% Set renderers of the Markdown module |
| 15 |
%% Attribute Renderers |
| 16 |
%%% TODO |
| 17 |
|
| 18 |
%% Block Quote Renderers |
| 19 |
\_def \markdownRendererBlockQuoteBegin {\_begblock} |
| 20 |
\_def \markdownRendererBlockQuoteEnd {\_endblock} |
| 21 |
|
| 22 |
%% Bracketed Spans Attribute Context Renderers |
| 23 |
%%% TODO |
| 24 |
|
| 25 |
%% Bullet List Renderers |
| 26 |
\_def \markdownRendererUlBegin {\_begitems \_itemskipamount=\_olistskipamount} |
| 27 |
\_def \markdownRendererUlBeginTight {\_begitems} |
| 28 |
\_def \markdownRendererUlItem {\_startitem} |
| 29 |
\_def \markdownRendererUlItemEnd {\_par} |
| 30 |
\_def \markdownRendererUlEnd {\_enditems} |
| 31 |
\_def \markdownRendererUlEndTight {\_enditems} |
| 32 |
|
| 33 |
%% Citations Renderers |
| 34 |
%%% TODO |
| 35 |
|
| 36 |
%% Code Block Renderers |
| 37 |
\_def \markdownRendererInputVerbatim #1{\_verbinput (-) {#1} } |
| 38 |
\_def \markdownRendererInputFencedCode #1#2{\_verbinput \_hisyntax{#2} (-) {#1} } |
| 39 |
|
| 40 |
%% Code Span Renderer |
| 41 |
\_def \markdownRendererCodeSpan #1{{\_ttfont #1}} |
| 42 |
|
| 43 |
%% Code Span Attribute Context Renderers |
| 44 |
%%% TODO |
| 45 |
|
| 46 |
%% Content Block Renderers |
| 47 |
%%% TODO |
| 48 |
|
| 49 |
%% Definition List Renderers |
| 50 |
\_sdef{_item:d}{\_aftergroup\dword} |
| 51 |
\_def \dword #1#2{{\bf#2 }\ignorespaces} |
| 52 |
\_def \markdownRendererDlBegin {\_begitems \_style d \_itemskipamount=\_olistskipamount} |
| 53 |
\_def \markdownRendererDlBeginTight {\_begitems \_style d} |
| 54 |
\_def \markdownRendererDlItem {% |
| 55 |
\_begingroup |
| 56 |
\_def \markdownRendererInterblockSeparator {% |
| 57 |
\_par |
| 58 |
\_advance\_leftskip by\_iindent |
| 59 |
\_def \markdownRendererInterblockSeparator {\_par}% |
| 60 |
}% |
| 61 |
\_startitem |
| 62 |
} |
| 63 |
\_def \markdownRendererDlItemEnd {% |
| 64 |
\_par |
| 65 |
\_endgroup |
| 66 |
} |
| 67 |
\_def \markdownRendererDlDefinitionBegin {} |
| 68 |
\_def \markdownRendererDlDefinitionEnd #1{% |
| 69 |
\_ifx #1\markdownRendererDlDefinitionBegin |
| 70 |
\_firstnoindent |
| 71 |
\markdownRendererInterblockSeparator |
| 72 |
\_vskip\_itemskipamount |
| 73 |
\_fi |
| 74 |
#1% |
| 75 |
} |
| 76 |
\_def \markdownRendererDlEnd {\_enditems} |
| 77 |
\_def \markdownRendererDlEndTight {\_enditems} |
| 78 |
|
| 79 |
%% Ellipsis Renderer |
| 80 |
\_def \markdownRendererEllipsis {$\_ldots$} |
| 81 |
|
| 82 |
%% Emphasis Renderers |
| 83 |
\_def \markdownRendererEmphasis #1{{\_em #1}} |
| 84 |
\_def \markdownRendererStrongEmphasis #1{{\_bf #1}} |
| 85 |
|
| 86 |
%% Fenced Code Attribute Context Renderers |
| 87 |
%%% TODO |
| 88 |
|
| 89 |
%% Fenced Div Attribute Context Renderers |
| 90 |
%%% TODO |
| 91 |
|
| 92 |
%% Header Attribute Context Renderers |
| 93 |
%%% TODO |
| 94 |
|
| 95 |
%% Heading Renderers |
| 96 |
\_def \markdownRendererHeadingOne #1{\_printtit{#1}} |
| 97 |
\_def \markdownRendererHeadingTwo #1{\_inchap{#1}} |
| 98 |
\_def \markdownRendererHeadingThree #1{\_insec{#1}} |
| 99 |
\_def \markdownRendererHeadingFour #1{\_insecc{#1}} |
| 100 |
\_def \markdownRendererHeadingFive #1{{\_bf #1}\_firstnoindent} |
| 101 |
\_def \markdownRendererHeadingSix #1{#1\_firstnoindent} |
| 102 |
|
| 103 |
%% HTML Comment Renderers |
| 104 |
%%% TODO |
| 105 |
|
| 106 |
%% HTML Tag and Element Renderers |
| 107 |
%%% TODO |
| 108 |
|
| 109 |
%% Image Renderer |
| 110 |
\_def \markdownRendererImage #1#2#3#4{% |
| 111 |
\_topinsert |
| 112 |
\_centerline{\_inspic{#3}}% |
| 113 |
\_cskip |
| 114 |
\_caption/f #4% |
| 115 |
\_par |
| 116 |
\_endinsert |
| 117 |
} |
| 118 |
|
| 119 |
%% Image Attribute Context Renderers |
| 120 |
%%% TODO |
| 121 |
|
| 122 |
%% Interblock Separator Renderer |
| 123 |
\_def \markdownRendererInterblockSeparator {\_par} |
| 124 |
\_def \markdownRendererParagraphSeparator {\markdownRendererInterblockSeparator} |
| 125 |
|
| 126 |
%% Line Block Renderers |
| 127 |
%%% TODO |
| 128 |
|
| 129 |
%% Line Break Renderers |
| 130 |
\_def \markdownRendererSoftLineBreak { } |
| 131 |
\_def \markdownRendererHardLineBreak {\_nl} |
| 132 |
|
| 133 |
%% Link Renderer |
| 134 |
\_def \markdownRendererLink #1#2#3#4{\_ea\_ulink\_ea[\_expanded{#3}]{#1}} |
| 135 |
|
| 136 |
%% Link Attribute Context Renderers |
| 137 |
%%% TODO |
| 138 |
|
| 139 |
%% Markdown Document Renderers |
| 140 |
\_let \markdownRendererDocumentBegin \_relax |
| 141 |
\_let \markdownRendererDocumentEnd \_relax |
| 142 |
|
| 143 |
%% Non-Breaking Space Renderer |
| 144 |
\_def \markdownRendererNbsp {~} |
| 145 |
|
| 146 |
%% Note Renderer |
| 147 |
%%% TODO |
| 148 |
|
| 149 |
%% Ordered List Renderers |
| 150 |
\_def \markdownRendererOlBegin {\_begitems \_style n \_itemskipamount=\_olistskipamount} |
| 151 |
\_def \markdownRendererOlBeginTight {\_begitems \_style n} |
| 152 |
\_def \markdownRendererFancyOlBegin #1#2{\markdownRendererOlBegin} |
| 153 |
\_def \markdownRendererFancyOlBeginTight #1#2{\markdownRendererOlBeginTight} |
| 154 |
\_def \markdownRendererOlItem {\_startitem} |
| 155 |
\_def \markdownRendererOlItemEnd {\_par} |
| 156 |
\_def \markdownRendererOlItemWithNumber #1{\_itemnum=#1 \_advance\_itemnum by -1 \_startitem} |
| 157 |
\_let \markdownRendererFancyOlItem \markdownRendererOlItem |
| 158 |
\_let \markdownRendererFancyOlItemEnd \markdownRendererOlItemEnd |
| 159 |
\_let \markdownRendererFancyOlItemWithNumber \markdownRendererOlItemWithNumber |
| 160 |
\_def \markdownRendererOlEnd {\_enditems} |
| 161 |
\_def \markdownRendererOlEndTight {\_enditems} |
| 162 |
\_let \markdownRendererFancyOlEndTight \markdownRendererOlEndTight |
| 163 |
\_let \markdownRendererFancyOlEnd \markdownRendererOlEnd |
| 164 |
|
| 165 |
%% Raw Content Renderers |
| 166 |
%%% TODO |
| 167 |
|
| 168 |
%% Section Renderers |
| 169 |
\_let \markdownRendererSectionBegin \_relax |
| 170 |
\_let \markdownRendererSectionEnd \_relax |
| 171 |
|
| 172 |
%% Replacement Character Renderers |
| 173 |
\_def \markdownRendererReplacementCharacter {^^^^fffd} |
| 174 |
|
| 175 |
%% Special Character Renderers |
| 176 |
\_edef \markdownRendererAmpersand #1{\_csstring\&} |
| 177 |
\_edef \markdownRendererBackslash #1{\_csstring\\} |
| 178 |
\_edef \markdownRendererCircumflex #1{\_csstring\^} |
| 179 |
\_edef \markdownRendererDollarSign #1{\_csstring\$} |
| 180 |
\_edef \markdownRendererHash #1{\_csstring\#} |
| 181 |
\_edef \markdownRendererLeftBrace #1{\_csstring\{} |
| 182 |
\_edef \markdownRendererPercentSign #1{\_csstring\%} |
| 183 |
\_def \markdownRendererPipe #1{|} |
| 184 |
\_edef \markdownRendererRightBrace #1{\_csstring\}} |
| 185 |
\_edef \markdownRendererTilde #1{\_csstring\~} |
| 186 |
\_def \markdownRendererUnderscore #1{_} |
| 187 |
|
| 188 |
%% Strike-Through Renderer |
| 189 |
\_def \markdownRendererStrikeThrough #1{% |
| 190 |
\_setbox0=\_hbox {#1}% |
| 191 |
\_leavevmode |
| 192 |
\_rlap {\raise.5ex \_hbox to \_wd0 {\_hfil \_hrulefill \_hfil}}% |
| 193 |
\_box0 |
| 194 |
} |
| 195 |
|
| 196 |
%% Subscript Renderer |
| 197 |
%%% TODO |
| 198 |
|
| 199 |
%% Superscript Renderer |
| 200 |
%%% TODO |
| 201 |
|
| 202 |
%% Table Renderer |
| 203 |
%%% TODO |
| 204 |
|
| 205 |
%% TeX Math Renderers |
| 206 |
%%% TODO |
| 207 |
|
| 208 |
%% Thematic Break Renderer |
| 209 |
\_def \markdownRendererThematicBreak {% |
| 210 |
\_vskip 0.5\_baselineskip |
| 211 |
\_hrule |
| 212 |
\_par |
| 213 |
\_vskip 0.5\_baselineskip |
| 214 |
\_firstnoindent |
| 215 |
} |
| 216 |
|
| 217 |
%% Tickbox Renderers |
| 218 |
%%% TODO |
| 219 |
|
| 220 |
%% YAML Metadata Renderers |
| 221 |
\_let \markdownRendererJekyllDataBegin \_relax |
| 222 |
\_let \markdownRendererJekyllDataEnd \_relax |
| 223 |
\_def \markdownRendererJekyllDataMappingBegin #1#2{} |
| 224 |
\_let \markdownRendererJekyllDataMappingEnd \_relax |
| 225 |
\_def \markdownRendererJekyllDataSequenceBegin #1#2{} |
| 226 |
\_let \markdownRendererJekyllDataSequenceEnd \_relax |
| 227 |
\_def \markdownRendererJekyllDataBoolean #1#2{} |
| 228 |
\_def \markdownRendererJekyllDataNumber #1#2{} |
| 229 |
\_def \markdownRendererJekyllDataProgrammaticString #1#2{} |
| 230 |
\_def \markdownRendererJekyllDataTypographicString #1#2{} |
| 231 |
\_def \markdownRendererJekyllDataEmpty #1{} |
| 232 |
|
| 233 |
%% Warning and Error Renderers |
| 234 |
\_def \markdownRendererWarning #1#2#3#4{} |
| 235 |
\_def \markdownRendererError #1#2#3#4{} |
| 236 |
|
| 237 |
% Load the Markdown module and set TeX macros for the Markdown module |
| 238 |
\_directlua{ |
| 239 |
kpse = require("kpse") |
| 240 |
kpse.set_program_name("luatex") |
| 241 |
markdown = require("markdown") |
| 242 |
} |
| 243 |
|
| 244 |
\_eoldef \markdownBegin #1{% #1 includes the end of the current line, parameters can be here |
| 245 |
\_def\_markdownParams{#1}% |
| 246 |
\_bgroup \_setverb \_savemathsb \_endlinechar=`\^^J |
| 247 |
\_markdownBeginA |
| 248 |
} |
| 249 |
|
| 250 |
\_ea\_def \_ea\_markdownBeginA \_ea#\_ea1\_csstring\\markdownEnd#2^^J{% |
| 251 |
\_restoremathsb \_egroup |
| 252 |
\_bgroup |
| 253 |
\_catcode`\%=12\_relax |
| 254 |
\_catcode`\#=12\_relax |
| 255 |
\_directlua { |
| 256 |
% Prepare a table of options. |
| 257 |
local defaultOptions = {\markdownOptions} |
| 258 |
local currentOptions = {\_markdownParams} |
| 259 |
local options = {} |
| 260 |
for k,v in pairs(defaultOptions) do options[k] = v end |
| 261 |
for k,v in pairs(currentOptions) do options[k] = v end |
| 262 |
% Ensure that the cache directory exists. |
| 263 |
if options.cacheDir then |
| 264 |
local lfs = require("lfs") |
| 265 |
if not lfs.isdir(options.cacheDir) then |
| 266 |
assert(lfs.mkdir(options.cacheDir)) |
| 267 |
end |
| 268 |
end |
| 269 |
% Convert Markdown to TeX and print it. |
| 270 |
local convert = markdown.new(options) |
| 271 |
local input = "\_luaescapestring{#1}" |
| 272 |
local output = convert(input) |
| 273 |
tex.print(output) |
| 274 |
}% |
| 275 |
\_egroup |
| 276 |
} |
| 277 |
|
| 278 |
% Set the document metadata using a YAML metadata block |
| 279 |
\markdownBegin hybrid=true,jekyllData=true |
| 280 |
--- |
| 281 |
title: An Example *Markdown* Document |
| 282 |
author: Vít Starý Novotný |
| 283 |
date: \today |
| 284 |
--- |
| 285 |
|
| 286 |
# This is an H1 |
| 287 |
|
| 288 |
## This is an H2 |
| 289 |
|
| 290 |
### This is an H3 |
| 291 |
|
| 292 |
#### This is an H4 |
| 293 |
|
| 294 |
##### This is an H5 |
| 295 |
|
| 296 |
###### This is an H6 |
| 297 |
|
| 298 |
This is a text paragraph containing an ellipsis ... and followed by a |
| 299 |
thematic break. |
| 300 |
|
| 301 |
*** |
| 302 |
|
| 303 |
This is inline `code`. This is a [link](http://google.cz "Google"). |
| 304 |
This is an *emphasized* span of text. |
| 305 |
This is a __strongly emphasized__ span of text. |
| 306 |
|
| 307 |
 |
| 308 |
|
| 309 |
This is a fenced code block: |
| 310 |
|
| 311 |
``` tex |
| 312 |
\fontfam[LMfonts] |
| 313 |
Hello World! \bye |
| 314 |
``` |
| 315 |
|
| 316 |
This is a bullet list: |
| 317 |
|
| 318 |
* The first item of a bullet list, |
| 319 |
|
| 320 |
* the second item of a bullet list, |
| 321 |
|
| 322 |
* the third item of a bullet list. |
| 323 |
|
| 324 |
This is a compact bullet list: |
| 325 |
|
| 326 |
* The first item of a bullet list, |
| 327 |
* the second item of a bullet list, |
| 328 |
* the third item of a bullet list. |
| 329 |
|
| 330 |
This is an ordered list: |
| 331 |
|
| 332 |
5. The first item of an ordered list, |
| 333 |
|
| 334 |
6. the second item of an ordered list, |
| 335 |
|
| 336 |
7. the third item of an ordered list. |
| 337 |
|
| 338 |
This is an ordered list using hash enumerators: |
| 339 |
|
| 340 |
#. The first item of an ordered list, |
| 341 |
|
| 342 |
#. the second item of an ordered list, |
| 343 |
|
| 344 |
#. the third item of an ordered list. |
| 345 |
|
| 346 |
This is a compact ordered list: |
| 347 |
|
| 348 |
5. The first item of an ordered list, |
| 349 |
6. the second item of an ordered list, |
| 350 |
7. the third item of an ordered list. |
| 351 |
|
| 352 |
This is a compact ordered list using hash enumerators: |
| 353 |
|
| 354 |
#. The first item of an ordered list, |
| 355 |
#. the second item of an ordered list, |
| 356 |
#. the third item of an ordered list. |
| 357 |
|
| 358 |
This is a definition list: |
| 359 |
|
| 360 |
Term 1 |
| 361 |
|
| 362 |
: Definition 1 with some ~~removed text~~ |
| 363 |
|
| 364 |
Term 2 |
| 365 |
|
| 366 |
: Definition 2 |
| 367 |
|
| 368 |
Some code, part of Definition 2 |
| 369 |
|
| 370 |
Third paragraph of Definition 2. |
| 371 |
|
| 372 |
: Definition 3 |
| 373 |
|
| 374 |
This is a compact definition list: |
| 375 |
|
| 376 |
Term 1 |
| 377 |
: Definition 1 |
| 378 |
Term 2 |
| 379 |
: Definition 2 |
| 380 |
: Definition 3 |
| 381 |
|
| 382 |
\markdownEnd |
| 383 |
|
| 384 |
\bye |