1 package org.apache.maven.doxia.module.latex;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.Writer;
23
24 import org.apache.maven.doxia.sink.Sink;
25 import org.apache.maven.doxia.sink.AbstractSinkTest;
26
27
28
29
30
31 public class LatexSinkTest
32 extends AbstractSinkTest
33 {
34
35 protected String outputExtension()
36 {
37 return "tex";
38 }
39
40
41 protected Sink createSink( Writer writer )
42 {
43 return new LatexSink( writer );
44 }
45
46
47 protected boolean isXmlSink()
48 {
49 return false;
50 }
51
52
53 protected String getTitleBlock( String title )
54 {
55 return "\\title{" + LatexSink.escaped( title ) + "}" + EOL;
56 }
57
58
59 protected String getAuthorBlock( String author )
60 {
61 return "\\author{" + LatexSink.escaped( author ) + "}" + EOL;
62 }
63
64
65 protected String getDateBlock( String date )
66 {
67 return "\\date{" + LatexSink.escaped( date ) + "}" + EOL;
68 }
69
70
71 protected String getHeadBlock()
72 {
73 return ( (LatexSink) getSink() ).defaultSinkCommands()
74 + "\\documentclass[a4paper]{article}" + EOL + EOL
75 + ( (LatexSink) getSink() ).defaultPreamble()
76 + "\\begin{document}" + EOL + EOL;
77 }
78
79
80 protected String getBodyBlock()
81 {
82 return "\\end{document}" + EOL;
83 }
84
85
86 protected String getSectionTitleBlock( String title )
87 {
88 return title;
89 }
90
91
92 protected String getSection1Block( String title )
93 {
94 return EOL + "\\section{" + title + "}" + EOL;
95 }
96
97
98 protected String getSection2Block( String title )
99 {
100 return EOL + "\\subsection{" + title + "}" + EOL;
101 }
102
103
104 protected String getSection3Block( String title )
105 {
106 return EOL + "\\subsubsection{" + title + "}" + EOL;
107 }
108
109
110 protected String getSection4Block( String title )
111 {
112 return EOL + "\\paragraph{" + title + "}" + EOL;
113 }
114
115
116 protected String getSection5Block( String title )
117 {
118 return EOL + "\\subparagraph{" + title + "}" + EOL;
119 }
120
121
122 protected String getListBlock( String item )
123 {
124 return EOL + "\\begin{itemize}" + EOL + "\\item " + LatexSink.escaped( item ) + EOL + "\\end{itemize}" + EOL;
125 }
126
127
128 protected String getNumberedListBlock( String item )
129 {
130 return EOL + "\\begin{enumerate}" + EOL + "\\renewcommand{\\theenumi}{\\roman{enumi}}" + EOL + "\\item "
131 + LatexSink.escaped( item ) + EOL + "\\end{enumerate}" + EOL;
132 }
133
134
135 protected String getDefinitionListBlock( String definum, String definition )
136 {
137 return EOL + "\\begin{description}" + EOL + "\\item[\\mbox{" + definum + "}] "
138 + definition + EOL + "\\end{description}" + EOL;
139 }
140
141
142 protected String getFigureBlock( String source, String caption )
143 {
144 return EOL + "\\begin{figure}[htb]" + EOL + "\\begin{center}" + EOL + "\\includegraphics{" + source + "}" + EOL
145 + "\\end{center}" + EOL + "\\caption{Figure\\_caption}" + EOL + "\\end{figure}" + EOL;
146 }
147
148
149 protected String getTableBlock( String cell, String caption )
150 {
151 return EOL + "\\begin{table}[htp]" + EOL + "\\begin{center}" + EOL + "\\begin{tabular}{c}" + EOL
152 + "\\begin{tabular}[t]{c}cell\\end{tabular}\\\\" + EOL + "\\end{tabular}" + EOL
153 + "\\end{center}" + EOL + "\\caption{Table\\_caption}" + EOL + "\\end{table}" + EOL;
154 }
155
156
157 protected String getParagraphBlock( String text )
158 {
159 return EOL + EOL + text + EOL;
160 }
161
162
163 protected String getVerbatimBlock( String text )
164 {
165 return EOL + "\\begin{small}" + EOL + "\\begin{Verbatim}[frame=single]" + EOL + text + EOL
166 + "\\end{Verbatim}" + EOL + "\\end{small}" + EOL;
167 }
168
169
170 protected String getHorizontalRuleBlock()
171 {
172 return EOL + "\\begin{center}\\rule[0.5ex]{\\linewidth}{1pt}\\end{center}" + EOL;
173 }
174
175
176 protected String getPageBreakBlock()
177 {
178 return EOL + "\\newpage" + EOL;
179 }
180
181
182 protected String getAnchorBlock( String anchor )
183 {
184 return "\\hypertarget{" + anchor + "}{" + anchor + "}";
185 }
186
187
188 protected String getLinkBlock( String link, String text )
189 {
190 return "\\hyperlink{" + link + "}{" + text + "}";
191 }
192
193
194 protected String getItalicBlock( String text )
195 {
196 return "\\textit{" + text + "}";
197 }
198
199
200 protected String getBoldBlock( String text )
201 {
202 return "\\textbf{" + text + "}";
203 }
204
205
206 protected String getMonospacedBlock( String text )
207 {
208 return "\\texttt{\\small " + text + "}";
209 }
210
211
212 protected String getLineBreakBlock()
213 {
214 return "\\newline" + EOL;
215 }
216
217
218 protected String getNonBreakingSpaceBlock()
219 {
220 return "~";
221 }
222
223
224 protected String getTextBlock( String text )
225 {
226
227 return "\\textasciitilde" + EOL + ",\\_=,\\_\\symbol{45},\\_+,\\_*,\\_[,\\_],"
228 + "\\_\\symbol{60},\\_\\symbol{62},\\_\\{,\\_\\},\\_\\textbackslash";
229 }
230
231
232 protected String getRawTextBlock( String text )
233 {
234 return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
235 }
236
237
238 protected String getCommentBlock( String text )
239 {
240 return EOL + "% Simple comment with ----";
241 }
242 }