Debian Codegraph @

texmf-dist/tex/luatex/luaxml/luaxml-htmltemplates.lua

raw
1
2 local luaxml_sty = require "luaxml-sty"
3 -- try
4 local xmltransform = luaxml_sty.transformations.html
5 if not xmltransform then
6 xmltransform = luaxml_sty.declare_transformer("html")
7 end
8
9
10 xmltransform:add_action("head", [[
11 \tableofcontents
12 ]])
13
14 xmltransform:add_action("img", [[\noindent\includegraphics[max width=\textwidth]{@{src}}]])
15
16 xmltransform:add_action("h1", [[\addcontentsline{toc}{section}{%s}\section*{%s}
17 ]])
18 xmltransform:add_action("h2", [[\addcontentsline{toc}{subsection}{%s}\subsection*{%s}
19 ]])
20 -- don't add lower sectioning level than subsection
21 xmltransform:add_action("h3", [[\addcontentsline{toc}{subsubsection}{%s}\subsubsection*{%s}
22 ]])
23 xmltransform:add_action("h4", [[\addcontentsline{toc}{subsubsection}{%s}\subsubsection*{%s}
24 ]])
25 xmltransform:add_action("h5", [[\addcontentsline{toc}{subsubsection}{%s}\subsubsection*{%s}
26 ]])
27 xmltransform:add_action("h6", [[\addcontentsline{toc}{subsubsection}{%s}\subsubsection*{%s}
28 ]])
29
30 xmltransform:add_action("i", [[\textit{%s}]])
31 xmltransform:add_action("em", [[\emph{%s}]])
32 xmltransform:add_action("b", [[\textbf{%s}]])
33 xmltransform:add_action("strong", [[\textbf{%s}]])
34 xmltransform:add_action("tt", [[\texttt{%s}]])
35 xmltransform:add_action("samp", [[\texttt{%s}]])
36 xmltransform:add_action("kbd", [[\texttt{%s}]])
37 xmltransform:add_action("var", [[\textit{%s}]])
38 xmltransform:add_action("dfn", [[\texttt{%s}]])
39 xmltransform:add_action("code", [[\texttt{%s}]])
40 xmltransform:add_action("a[href]", [[\textit{%s}\protect\footnote{\texttt{@{href}}}]])
41
42
43 local itemize = [[
44 \begin{itemize}
45 %s
46 \end{itemize}
47 ]]
48 xmltransform:add_action("ul", itemize)
49 xmltransform:add_action("menu", itemize)
50 xmltransform:add_action("ol", [[
51 \begin{enumerate}
52 %s
53 \end{enumerate}
54 ]])
55
56 xmltransform:add_action("dl", [[
57 \begin{description}
58 %s
59 \end{description}
60 ]])
61
62
63 xmltransform:add_action("li", "\\item %s\n")
64 xmltransform:add_action("dt", "\\item[%s] ")
65
66 local quote = [[
67 \begin{quotation}
68 %s
69 \end{quotation}
70 ]]
71
72 xmltransform:add_action("blockquote", quote)
73 xmltransform:add_action("q", "\\enquote{%s}")
74 xmltransform:add_action("abbr", "%s\\protect\\footnote{@{title}}")
75 xmltransform:add_action("sup", "\\textsuperscript{%s}")
76 xmltransform:add_action("sub", "\\textsubscript{%s}")
77
78 xmltransform:add_action("table", [[
79 \begin{calstable}
80 %s
81 \end{calstable}
82 ]])
83
84 xmltransform:add_action("tr", "\\brow %s \\erow")
85 xmltransform:add_action("td", "\\cell{%s}")
86 xmltransform:add_action("th", "\\cell{%s}")
87
88
89 -- this is the original code for verbatim, but I changed LuaXML to not escape characters in verbatim,
90 -- so we can use the verbatim environment
91 xmltransform:add_action("pre", [[{\parindent=0pt\obeylines\ttfamily\catcode`\ =\active\def {\ }\catcode`\#=11%%
92 %s}
93
94 ]], {verbatim=true})
95 xmltransform:add_action("pre *", [[%s]])
96
97 --
98 xmltransform:add_action("pre", [[
99 \begin{verbatim}%s\end{verbatim}
100 ]], {verbatim=true})
101
102 xmltransform:add_action("details", [[%s
103 ]])
104
105 xmltransform:add_action("details summary", [[
106 \medskip
107 \noindent %s
108
109 \smallskip
110 \noindent
111 ]])
112
113 xmltransform:add_action("figure", [[
114 \begin{figure}[hbt!]
115 \centering
116
117 %s
118
119 \end{figure}
120 ]])
121
122 xmltransform:add_action("figcaption", [[\caption{%s}]])
123
124
125 xmltransform:add_action("p", [[
126
127 %s
128
129 ]])
130
131 xmltransform:add_action("br", [[\\]])
132
133 -- some fixes for weird web pages
134 xmltransform:add_action("a p", [[%s]])
135 xmltransform:add_action("h1 a[href], h2 a[href], h3 a[href], h4 a[href], h5 a[href], h6 a[href]", "%s")
136
137
138 -- mathjax is special element added by rmodepdf around LaTeX math
139 xmltransform:add_action("mathjax",[[%s]], {verbatim=true,collapse_newlines=false})
140
141 xmltransform:add_action("hyperlink", "\\hyperlink{@{href}}{%s}")
142 xmltransform:add_action("hypertarget", "\\hypertarget{@{id}}{%s}")
143
144 return xmltransform