-
Notifications
You must be signed in to change notification settings - Fork 173
/
Asciidoctor.java
394 lines (361 loc) · 14 KB
/
Asciidoctor.java
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
package org.asciidoctor;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.Collection;
import java.util.Map;
import org.asciidoctor.extension.JavaExtensionRegistry;
import org.asciidoctor.extension.RubyExtensionRegistry;
import org.asciidoctor.internal.DocumentRuby;
import org.asciidoctor.internal.JRubyAsciidoctor;
/**
*
*
* @author lordofthejars
*
*/
public interface Asciidoctor {
public static final String STRUCTURE_MAX_LEVEL = "STRUCTURE_MAX_LEVEL";
/**
* Parse the AsciiDoc source input into an Document {@link DocumentRuby} and
* render it to the specified backend format.
*
* Accepts input as String object.
*
*
* @param content
* the AsciiDoc source as String.
* @param options
* a Hash of options to control processing (default: {}).
* @return the rendered output String is returned
*/
String render(String content, Map<String, Object> options);
/**
* Parse the AsciiDoc source input into an Document {@link DocumentRuby} and
* render it to the specified backend format.
*
* Accepts input as String object.
*
*
* @param content
* the AsciiDoc source as String.
* @param options
* a Hash of options to control processing (default: {}).
* @return the rendered output String is returned
*/
String render(String content, Options options);
/**
* Parse the AsciiDoc source input into an Document {@link DocumentRuby} and
* render it to the specified backend format.
*
* Accepts input as String object.
*
*
* @param content
* the AsciiDoc source as String.
* @param options
* a Hash of options to control processing (default: {}).
* @return the rendered output String is returned
*/
String render(String content, OptionsBuilder options);
/**
* Parse the document read from reader, and rendered result is sent to
* writer.
*
* @param contentReader
* where asciidoc content is read.
* @param rendererWriter
* where rendered content is written. Writer is flushed, but not
* closed.
* @param options
* a Hash of options to control processing (default: {}).
* @throws IOException
* if an error occurs while writing rendered content, this
* exception is thrown.
*/
void render(Reader contentReader, Writer rendererWriter,
Map<String, Object> options) throws IOException;
/**
* Parse the document read from reader, and rendered result is sent to
* writer.
*
* @param contentReader
* where asciidoc content is read.
* @param rendererWriter
* where rendered content is written. Writer is flushed, but not
* closed.
* @param options
* a Hash of options to control processing (default: {}).
* @throws IOException
* if an error occurs while writing rendered content, this
* exception is thrown.
*/
void render(Reader contentReader, Writer rendererWriter, Options options)
throws IOException;
/**
* Parse the document read from reader, and rendered result is sent to
* writer.
*
* @param contentReader
* where asciidoc content is read.
* @param rendererWriter
* where rendered content is written. Writer is flushed, but not
* closed.
* @param options
* a Hash of options to control processing (default: {}).
* @throws IOException
* if an error occurs while writing rendered content, this
* exception is thrown.
*/
void render(Reader contentReader, Writer rendererWriter,
OptionsBuilder options) throws IOException;
/**
* Parse the AsciiDoc source input into an Document {@link DocumentRuby} and
* render it to the specified backend format.
*
* Accepts input as File path.
*
* If the :in_place option is true, and the input is a File, the output is
* written to a file adjacent to the input file, having an extension that
* corresponds to the backend format. Otherwise, if the :to_file option is
* specified, the file is written to that file. If :to_file is not an
* absolute path, it is resolved relative to :to_dir, if given, otherwise
* the Document#base_dir. If the target directory does not exist, it will
* not be created unless the :mkdirs option is set to true. If the file
* cannot be written because the target directory does not exist, or because
* it falls outside of the Document#base_dir in safe mode, an IOError is
* raised.
*
* @param filename
* an input Asciidoctor file.
* @param options
* a Hash of options to control processing (default: {}).
* @return returns nothing if the rendered output String is written to a
* file.
*/
String renderFile(File filename, Map<String, Object> options);
/**
* Parse the AsciiDoc source input into an Document {@link DocumentRuby} and
* render it to the specified backend format.
*
* Accepts input as File path.
*
* If the :in_place option is true, and the input is a File, the output is
* written to a file adjacent to the input file, having an extension that
* corresponds to the backend format. Otherwise, if the :to_file option is
* specified, the file is written to that file. If :to_file is not an
* absolute path, it is resolved relative to :to_dir, if given, otherwise
* the Document#base_dir. If the target directory does not exist, it will
* not be created unless the :mkdirs option is set to true. If the file
* cannot be written because the target directory does not exist, or because
* it falls outside of the Document#base_dir in safe mode, an IOError is
* raised.
*
* @param filename
* an input Asciidoctor file.
* @param options
* a Hash of options to control processing (default: {}).
* @return returns nothing if the rendered output String is written to a
* file.
*/
String renderFile(File filename, Options options);
/**
* Parse the AsciiDoc source input into an Document {@link DocumentRuby} and
* render it to the specified backend format.
*
* Accepts input as File path.
*
* If the :in_place option is true, and the input is a File, the output is
* written to a file adjacent to the input file, having an extension that
* corresponds to the backend format. Otherwise, if the :to_file option is
* specified, the file is written to that file. If :to_file is not an
* absolute path, it is resolved relative to :to_dir, if given, otherwise
* the Document#base_dir. If the target directory does not exist, it will
* not be created unless the :mkdirs option is set to true. If the file
* cannot be written because the target directory does not exist, or because
* it falls outside of the Document#base_dir in safe mode, an IOError is
* raised.
*
* @param filename
* an input Asciidoctor file.
* @param options
* a Hash of options to control processing (default: {}).
* @return returns nothing if the rendered output String is written to a
* file.
*/
String renderFile(File filename, OptionsBuilder options);
/**
* Parse all AsciiDoc files found using DirectoryWalker instance.
*
* @param directoryWalker
* strategy used to retrieve all files to be rendered.
* @param options
* a Hash of options to control processing (default: {}).
* @return returns an array of 0 positions if the rendered output is written
* to a file.
*/
String[] renderDirectory(DirectoryWalker directoryWalker,
Map<String, Object> options);
/**
* Parse all AsciiDoc files found using DirectoryWalker instance.
*
* @param directoryWalker
* strategy used to retrieve all files to be rendered.
* @param options
* a Hash of options to control processing (default: {}).
* @return returns an array of 0 positions if the rendered output is written
* to a file.
*/
String[] renderDirectory(DirectoryWalker directoryWalker, Options options);
/**
* Parse all AsciiDoc files found using DirectoryWalker instance.
*
* @param directoryWalker
* strategy used to retrieve all files to be rendered.
* @param options
* a Hash of options to control processing (default: {}).
* @return returns an array of 0 positions if the rendered output is written
* to a file.
*/
String[] renderDirectory(DirectoryWalker directoryWalker,
OptionsBuilder options);
/**
* Parses all files added inside a collection.
*
* @param asciidoctorFiles
* to be rendered.
* @param options
* a Hash of options to control processing (default: {}).
* @return returns an array of 0 positions if the rendered output is written
* to a file.
*/
String[] renderFiles(Collection<File> asciidoctorFiles,
Map<String, Object> options);
/**
* Parses all files added inside a collection.
*
* @param asciidoctorFiles
* to be rendered.
* @param options
* a Hash of options to control processing (default: {}).
* @return returns an array of 0 positions if the rendered output is written
* to a file.
*/
String[] renderFiles(Collection<File> asciidoctorFiles, Options options);
/**
* Parses all files added inside a collection.
*
* @param asciidoctorFiles
* to be rendered.
* @param options
* a Hash of options to control processing (default: {}).
* @return returns an array of 0 positions if the rendered output is written
* to a file.
*/
String[] renderFiles(Collection<File> asciidoctorFiles,
OptionsBuilder options);
/**
* Reads and creates structured document containing header and content chunks.
* By default it dig only one level down but it can be tweak by setting STRUCTURE_MAX_LEVEL
* option.
*
* @param filename
* to read the attributes.
* @param options
* a Hash of options to control processing (default: {}).
* @return structured document.
*/
StructuredDocument readDocumentStructure(File filename,Map<String,Object> options);
/**
* Reads and creates structured document containing header and content chunks.
* By default it dig only one level down but it can be tweak by setting STRUCTURE_MAX_LEVEL
* option.
*
* @param content
* where rendered content is written. Writer is flushed, but not
* closed.
* @param options
* a Hash of options to control processing (default: {}).
* @return structured document.
*/
StructuredDocument readDocumentStructure(String content,Map<String,Object> options);
/**
* Reads and creates structured document containing header and content chunks.
* By default it dig only one level down but it can be tweak by setting STRUCTURE_MAX_LEVEL
* option.
*
* @param contentReader
* where asciidoc content is read.
* @param options
* a Hash of options to control processing (default: {}).
* @return structured document.
*/
StructuredDocument readDocumentStructure(Reader contentReader,Map<String,Object> options);
/**
* Reads only header parameters instead of all document.
*
* @param filename
* to read the attributes.
* @return header.
*/
DocumentHeader readDocumentHeader(File filename);
/**
* Reads only header parameters instead of all document.
*
* @param content
* where rendered content is written. Writer is flushed, but not
* closed.
* @return header.
*/
DocumentHeader readDocumentHeader(String content);
/**
* Reads only header parameters instead of all document.
*
* @param contentReader
* where asciidoc content is read.
* @return header.
*/
DocumentHeader readDocumentHeader(Reader contentReader);
/**
* Creates an extension registry ready to be used for registering all processors
* @return Extension Registry object.
*/
JavaExtensionRegistry javaExtensionRegistry();
/**
* Creates an Ruby extension registry ready to be used for registering all processors
* @return Extension Registry object.
*/
RubyExtensionRegistry rubyExtensionRegistry();
/**
* Factory for creating a new instance of Asciidoctor interface.
*
* @author lordofthejars
*
*/
public static class Factory {
/**
* Creates a new instance of Asciidoctor.
*
* @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
* Ruby calls.
*/
public static Asciidoctor create() {
return JRubyAsciidoctor.create();
}
/**
* Creates a new instance of Asciidoctor and sets GEM_PATH environment
* variable to provided gemPath. This method is mostly used in OSGi
* environments.
*
* @param gemPath
* where gems are located.
*
* @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
* Ruby calls.
*/
public static Asciidoctor create(String gemPath) {
return JRubyAsciidoctor.create(gemPath);
}
}
}