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.impl.AbstractSinkTest;
26
27
28
29
30 public class LatexSinkTest
31 extends AbstractSinkTest
32 {
33
34 protected String outputExtension()
35 {
36 return "tex";
37 }
38
39
40 protected Sink createSink( Writer writer )
41 {
42 return new LatexSink( writer );
43 }
44
45
46 protected boolean isXmlSink()
47 {
48 return false;
49 }
50
51
52 protected String getTitleBlock( String title )
53 {
54 return "\\title{" + LatexSink.escaped( title ) + "}" + EOL;
55 }
56
57
58 protected String getAuthorBlock( String author )
59 {
60 return "\\author{" + LatexSink.escaped( author ) + "}" + EOL;
61 }
62
63
64 protected String getDateBlock( String date )
65 {
66 return "\\date{" + LatexSink.escaped( date ) + "}" + EOL;
67 }
68
69
70 protected String getHeadBlock()
71 {
72 return ( (LatexSink) getSink() ).defaultSinkCommands()
73 + "\\documentclass[a4paper]{article}" + EOL + EOL
74 + ( (LatexSink) getSink() ).defaultPreamble()
75 + "\\begin{document}" + EOL + EOL;
76 }
77
78
79 protected String getBodyBlock()
80 {
81 return "\\end{document}" + EOL;
82 }
83
84
85 protected String getArticleBlock()
86 {
87 return "";
88 }
89
90
91 protected String getNavigationBlock()
92 {
93 return "";
94 }
95
96
97 protected String getSidebarBlock()
98 {
99 return "";
100 }
101
102
103 protected String getSectionTitleBlock( String title )
104 {
105 return title;
106 }
107
108
109 protected String getSection1Block( String title )
110 {
111 return EOL + "\\section{" + title + "}" + EOL;
112 }
113
114
115 protected String getSection2Block( String title )
116 {
117 return EOL + "\\subsection{" + title + "}" + EOL;
118 }
119
120
121 protected String getSection3Block( String title )
122 {
123 return EOL + "\\subsubsection{" + title + "}" + EOL;
124 }
125
126
127 protected String getSection4Block( String title )
128 {
129 return EOL + "\\paragraph{" + title + "}" + EOL;
130 }
131
132
133 protected String getSection5Block( String title )
134 {
135 return EOL + "\\subparagraph{" + title + "}" + EOL;
136 }
137
138
139 protected String getHeaderBlock()
140 {
141 return "";
142 }
143
144
145 protected String getContentBlock()
146 {
147 return "";
148 }
149
150
151 protected String getFooterBlock()
152 {
153 return "";
154 }
155
156
157 protected String getListBlock( String item )
158 {
159 return EOL + "\\begin{itemize}" + EOL + "\\item " + LatexSink.escaped( item ) + EOL + "\\end{itemize}" + EOL;
160 }
161
162
163 protected String getNumberedListBlock( String item )
164 {
165 return EOL + "\\begin{enumerate}" + EOL + "\\renewcommand{\\theenumi}{\\roman{enumi}}" + EOL + "\\item "
166 + LatexSink.escaped( item ) + EOL + "\\end{enumerate}" + EOL;
167 }
168
169
170 protected String getDefinitionListBlock( String definum, String definition )
171 {
172 return EOL + "\\begin{description}" + EOL + "\\item[\\mbox{" + definum + "}] "
173 + definition + EOL + "\\end{description}" + EOL;
174 }
175
176
177 protected String getFigureBlock( String source, String caption )
178 {
179 String figureBlock = EOL + "\\begin{figure}[htb]" + EOL + "\\begin{center}" + EOL + "\\includegraphics{" + source + "}" + EOL
180 + "\\end{center}" + EOL;
181 if (caption != null )
182 {
183 figureBlock += "\\caption{Figure\\_caption}" + EOL;
184 }
185 figureBlock += "\\end{figure}" + EOL;
186 return figureBlock;
187 }
188
189
190 protected String getTableBlock( String cell, String caption )
191 {
192 return EOL + "\\begin{table}[htp]" + EOL + "\\begin{center}" + EOL + "\\begin{tabular}{c}" + EOL
193 + "\\begin{tabular}[t]{c}cell\\end{tabular}\\\\" + EOL + "\\end{tabular}" + EOL
194 + "\\end{center}" + EOL + "\\caption{Table\\_caption}" + EOL + "\\end{table}" + EOL;
195 }
196
197
198 protected String getParagraphBlock( String text )
199 {
200 return EOL + EOL + text + EOL;
201 }
202
203
204 protected String getDataBlock( String value, String text )
205 {
206 return text;
207 }
208
209
210 protected String getTimeBlock( String datetime, String text )
211 {
212 return text;
213 }
214
215
216 protected String getAddressBlock( String text )
217 {
218 return text;
219 }
220
221
222 protected String getBlockquoteBlock( String text )
223 {
224 return text;
225 }
226
227
228 protected String getDivisionBlock( String text )
229 {
230 return text;
231 }
232
233
234 protected String getVerbatimBlock( String text )
235 {
236 return EOL + "\\begin{small}" + EOL + "\\begin{Verbatim}[frame=single]" + EOL + text + EOL
237 + "\\end{Verbatim}" + EOL + "\\end{small}" + EOL;
238 }
239
240
241 protected String getHorizontalRuleBlock()
242 {
243 return EOL + "\\begin{center}\\rule[0.5ex]{\\linewidth}{1pt}\\end{center}" + EOL;
244 }
245
246
247 protected String getPageBreakBlock()
248 {
249 return EOL + "\\newpage" + EOL;
250 }
251
252
253 protected String getAnchorBlock( String anchor )
254 {
255 return "\\hypertarget{" + anchor + "}{" + anchor + "}";
256 }
257
258
259 protected String getLinkBlock( String link, String text )
260 {
261 return "\\hyperlink{" + link + "}{" + text + "}";
262 }
263
264
265 protected String getInlineBlock( String text )
266 {
267 return text;
268 }
269
270
271 protected String getInlineItalicBlock( String text )
272 {
273 return "\\textit{" + text + "}";
274 }
275
276
277 protected String getInlineBoldBlock( String text )
278 {
279 return "\\textbf{" + text + "}";
280 }
281
282
283 protected String getInlineCodeBlock( String text )
284 {
285 return "\\texttt{\\small " + text + "}";
286 }
287
288
289 protected String getItalicBlock( String text )
290 {
291 return "\\textit{" + text + "}";
292 }
293
294
295 protected String getBoldBlock( String text )
296 {
297 return "\\textbf{" + text + "}";
298 }
299
300
301 protected String getMonospacedBlock( String text )
302 {
303 return "\\texttt{\\small " + text + "}";
304 }
305
306
307 protected String getLineBreakBlock()
308 {
309 return "\\newline" + EOL;
310 }
311
312
313 protected String getLineBreakOpportunityBlock()
314 {
315 return "";
316 }
317
318
319 protected String getNonBreakingSpaceBlock()
320 {
321 return "~";
322 }
323
324
325 protected String getTextBlock( String text )
326 {
327
328 return "\\textasciitilde" + EOL + ",\\_=,\\_\\symbol{45},\\_+,\\_*,\\_[,\\_],"
329 + "\\_\\symbol{60},\\_\\symbol{62},\\_\\{,\\_\\},\\_\\textbackslash";
330 }
331
332
333 protected String getRawTextBlock( String text )
334 {
335 return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
336 }
337
338
339 protected String getCommentBlock( String text )
340 {
341 return EOL + "%" + text;
342 }
343 }