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