mtx-context-markdown.tex /size: 2220 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=mtx-context-markdown,
3
%D version=2011.07.24,
4
%D title=\CONTEXT\ Extra Trickry,
5
%D subtitle=Rendering Markdown Files,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
% begin help
15
%
16
% usage: context --extra=markdown [options] list-of-files
17
%
18
% --sort : sort filenames first
19
% --paperoffset=dimension : left-top-offset
20
% --duplex : doublesided (singlesided is default)
21
% --backspace=dimension : extra left offset
22
% --topspace=dimension : extra top offset
23
% --bodyfont=specification : additional bodyfont specification
24
% --contents : add table of contents
25
%
26
% end help
27 28
\usemodule
[
markdown
]
29 30
\doifdocumentargument
{
paperoffset
}
{
31
\definepapersize
32
[
offset
=
\getdocumentargument
{
paperoffset
}
]
33
}
34 35
\doifdocumentargument
{
duplex
}
{
36
\setuppagenumbering
37
[
alternative
=
doublesided
]
38
}
{
39
\setuppagenumbering
40
[
alternative
=
singlesided
]
41
}
42 43
\setdocumentargumentdefault
{
textwidth
}
{
middle
}
44
\setdocumentargumentdefault
{
backspace
}
{
2
cm
}
45
\setdocumentargumentdefault
{
topspace
}
{
2
cm
}
46
\setdocumentargumentdefault
{
bodyfont
}
{}
47 48
\setuptolerance
49
[
verytolerant
,
stretch
]
50 51
\setuplayout
52
[
width
=
middle
,
53
height
=
middle
,
54
backspace
=
\getdocumentargument
{
backspace
}
,
55
topspace
=
\getdocumentargument
{
topspace
}
,
56
footer
=
0
pt
]
57 58
\setupbodyfont
59
[
dejavu
,
1
0
pt
,
\getdocumentargument
{
bodyfont
}
]
60 61
\setupwhitespace
62
[
big
]
63 64
% \enabletrackers[context.trace]
65 66
\setuplist
67
[
chapter
,
section
,
subsection
]
68
[
aligntitle
=
yes
,
69
width
=
4
em
]
70 71
\starttext
72 73
\doifdocumentargument
{
contents
}
{
74
\starttitle
[
title
=
{
Table
of
contents
}
]
75
\placelist
[
chapter
,
section
,
subsection
]
% todo: levels
76
\stoptitle
77
}
78 79 80
\startluacode
81
if
#
document
.
files
>
0
then
82
if
document
.
arguments
.
sort
then
83
table
.
sort
(
document
.
files
)
84
end
85
for
i
=
1
,
#
document
.
files
do
86
context
.
processmarkdownfile
(
document
.
files
[
i
]
)
87
context
.
page
(
)
88
end
89
end
90
\stopluacode
91 92
\stoptext
93