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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
local luaxml_sty = require "luaxml-sty"
-- try
local xmltransform = luaxml_sty.transformations.html
if not xmltransform then
xmltransform = luaxml_sty.declare_transformer("html")
end
xmltransform:add_action("head", [[
\tableofcontents
]])
xmltransform:add_action("img", [[\noindent\includegraphics[max width=\textwidth]{@{src}}]])
xmltransform:add_action("h1", [[\addcontentsline{toc}{section}{%s}\section*{%s}
]])
xmltransform:add_action("h2", [[\addcontentsline{toc}{subsection}{%s}\subsection*{%s}
]])
-- don't add lower sectioning level than subsection
xmltransform:add_action("h3", [[\addcontentsline{toc}{subsubsection}{%s}\subsubsection*{%s}
]])
xmltransform:add_action("h4", [[\addcontentsline{toc}{subsubsection}{%s}\subsubsection*{%s}
]])
xmltransform:add_action("h5", [[\addcontentsline{toc}{subsubsection}{%s}\subsubsection*{%s}
]])
xmltransform:add_action("h6", [[\addcontentsline{toc}{subsubsection}{%s}\subsubsection*{%s}
]])
xmltransform:add_action("i", [[\textit{%s}]])
xmltransform:add_action("em", [[\emph{%s}]])
xmltransform:add_action("b", [[\textbf{%s}]])
xmltransform:add_action("strong", [[\textbf{%s}]])
xmltransform:add_action("tt", [[\texttt{%s}]])
xmltransform:add_action("samp", [[\texttt{%s}]])
xmltransform:add_action("kbd", [[\texttt{%s}]])
xmltransform:add_action("var", [[\textit{%s}]])
xmltransform:add_action("dfn", [[\texttt{%s}]])
xmltransform:add_action("code", [[\texttt{%s}]])
xmltransform:add_action("a[href]", [[\textit{%s}\protect\footnote{\texttt{@{href}}}]])
local itemize = [[
\begin{itemize}
%s
\end{itemize}
]]
xmltransform:add_action("ul", itemize)
xmltransform:add_action("menu", itemize)
xmltransform:add_action("ol", [[
\begin{enumerate}
%s
\end{enumerate}
]])
xmltransform:add_action("dl", [[
\begin{description}
%s
\end{description}
]])
xmltransform:add_action("li", "\\item %s\n")
xmltransform:add_action("dt", "\\item[%s] ")
local quote = [[
\begin{quotation}
%s
\end{quotation}
]]
xmltransform:add_action("blockquote", quote)
xmltransform:add_action("q", "\\enquote{%s}")
xmltransform:add_action("abbr", "%s\\protect\\footnote{@{title}}")
xmltransform:add_action("sup", "\\textsuperscript{%s}")
xmltransform:add_action("sub", "\\textsubscript{%s}")
xmltransform:add_action("table", [[
\begin{calstable}
%s
\end{calstable}
]])
xmltransform:add_action("tr", "\\brow %s \\erow")
xmltransform:add_action("td", "\\cell{%s}")
xmltransform:add_action("th", "\\cell{%s}")
-- this is the original code for verbatim, but I changed LuaXML to not escape characters in verbatim,
-- so we can use the verbatim environment
xmltransform:add_action("pre", [[{\parindent=0pt\obeylines\ttfamily\catcode`\ =\active\def {\ }\catcode`\#=11%%
%s}
]], {verbatim=true})
xmltransform:add_action("pre *", [[%s]])
--
xmltransform:add_action("pre", [[
\begin{verbatim}%s\end{verbatim}
]], {verbatim=true})
xmltransform:add_action("details", [[%s
]])
xmltransform:add_action("details summary", [[
\medskip
\noindent %s
\smallskip
\noindent
]])
xmltransform:add_action("figure", [[
\begin{figure}[hbt!]
\centering
%s
\end{figure}
]])
xmltransform:add_action("figcaption", [[\caption{%s}]])
xmltransform:add_action("p", [[
%s
]])
xmltransform:add_action("br", [[\\]])
-- some fixes for weird web pages
xmltransform:add_action("a p", [[%s]])
xmltransform:add_action("h1 a[href], h2 a[href], h3 a[href], h4 a[href], h5 a[href], h6 a[href]", "%s")
-- mathjax is special element added by rmodepdf around LaTeX math
xmltransform:add_action("mathjax",[[%s]], {verbatim=true,collapse_newlines=false})
xmltransform:add_action("hyperlink", "\\hyperlink{@{href}}{%s}")
xmltransform:add_action("hypertarget", "\\hypertarget{@{id}}{%s}")
return xmltransform
|