Add load(String,Options) and loadFile(File,Options)
MODIFY
asciidoctorj-api/src/main/java/org/asciidoctor/Asciidoctor.java
asciidoctorj-api/src/main/java/org/asciidoctor/Asciidoctor.java
@@ -66,7 +66,7 @@ public interface Asciidoctor extends AutoCloseable {
* Accepts input as String object.
*
* @param content the AsciiDoc source as String.
- * @param options a Map of options to control processing (default: {}).
+ * @param options options to control processing (default: empty).
* @return the rendered output String is returned
*/
String convert(String content, Options options);
@@ -78,7 +78,7 @@ public interface Asciidoctor extends AutoCloseable {
* Accepts input as String object.
*
* @param content the AsciiDoc source as String.
- * @param options a Map of options to control processing (default: {}).
+ * @param options options to control processing (default: empty).
* @param expectedResult the expected return type. Usually {@link String} for HTML based formats.
* In this case {@link #convert(String, Options)} is the same.
* @return the rendered output String is returned
@@ -138,7 +138,7 @@ public interface Asciidoctor extends AutoCloseable {
* @param contentReader where asciidoc content is read.
* @param rendererWriter where rendered content is written. Writer is flushed, but not
* closed.
- * @param options a Map of options to control processing (default: {}).
+ * @param options options to control processing (default: empty).
* @throws IOException if an error occurs while writing rendered content, this
* exception is thrown.
*/
@@ -234,7 +234,7 @@ public interface Asciidoctor extends AutoCloseable {
* raised.
*
* @param file an input Asciidoctor file.
- * @param options a Map of options to control processing (default: {}).
+ * @param options options to control processing (default: empty).
* @return returns nothing if the rendered output String is written to a
* file.
*/
@@ -258,7 +258,7 @@ public interface Asciidoctor extends AutoCloseable {
* raised.
*
* @param file an input Asciidoctor file.
- * @param options a Map of options to control processing (default: {}).
+ * @param options options to control processing (default: empty).
* @param expectedResult the expected return type. Usually {@link String} for HTML based formats.
* In this case {@link #convertFile(File, Map)} is the same.
* @return returns nothing if the rendered output is written to a
@@ -338,7 +338,7 @@ public interface Asciidoctor extends AutoCloseable {
* See {@code AsciiDocDirectoryWalker} for reference strategy.
*
* @param directoryWalker strategy used to retrieve all files to be rendered.
- * @param options a Map of options to control processing (default: {}).
+ * @param options options to control processing (default: empty).
* @return returns an array of 0 positions if the rendered output is written
* to a file.
*/
@@ -373,7 +373,7 @@ public interface Asciidoctor extends AutoCloseable {
* Convert all files from a collection.
*
* @param asciidoctorFiles to be converted.
- * @param options a Map of options to control processing (default: {}).
+ * @param options options to control processing (default: empty).
* @return returns an array of 0 positions if the rendered output is written
* to a file.
*/
@@ -547,22 +547,44 @@ public interface Asciidoctor extends AutoCloseable {
/**
* Loads AsciiDoc content and returns the Document object.
+ * @deprecated Use {@link #load(String, Options)} instead.
*
* @param content to be parsed.
* @param options a Map of options to control processing (default: {}).
* @return Document of given content.
*/
+ @Deprecated
Document load(String content, Map<String, Object> options);
+ /**
+ * Loads AsciiDoc content and returns the Document object.
+ *
+ * @param content to be parsed.
+ * @param options options to control processing (default: empty).
+ * @return Document of given content.
+ */
+ Document load(String content, Options options);
+
/**
* Loads AsciiDoc content from file and returns the Document object.
+ * @deprecated Use {@link #loadFile(File, Options)} instead.
*
* @param file to be parsed.
* @param options a Map of options to control processing (default: {}).
* @return Document of given content.
*/
+ @Deprecated
Document loadFile(File file, Map<String, Object> options);
+ /**
+ * Loads AsciiDoc content from file and returns the Document object.
+ *
+ * @param file to be parsed.
+ * @param options options to control processing (default: empty).
+ * @return Document of given content.
+ */
+ Document loadFile(File file, Options options);
+
/**
* Register a {@link LogHandler} to capture Asciidoctor message records.
*

MODIFY
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/JRubyAsciidoctor.java
@@ -465,6 +465,13 @@ public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler {
rubyRuntime.newString(content), rubyHash));
}
+ @Override
+ public Document load(String content, Options options) {
+ RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options.map());
+ return (Document) NodeConverter.createASTNode(getAsciidoctorModule().callMethod("load",
+ rubyRuntime.newString(content), rubyHash));
+ }
+
@Override
public Document loadFile(File file, Map<String, Object> options) {
RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options);
@@ -473,6 +480,14 @@ public class JRubyAsciidoctor implements AsciidoctorJRuby, LogHandler {
rubyRuntime.newString(file.getAbsolutePath()), rubyHash));
}
+ @Override
+ public Document loadFile(File file, Options options) {
+ RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options.map());
+
+ return (Document) NodeConverter.createASTNode(getAsciidoctorModule().callMethod("load_file",
+ rubyRuntime.newString(file.getAbsolutePath()), rubyHash));
+ }
+
@Override
public ExtensionGroup createGroup() {
return createGroup(UUID.randomUUID().toString());

MODIFY
asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciiDocIsLoadedToDocument.java
asciidoctorj-core/src/test/java/org/asciidoctor/WhenAsciiDocIsLoadedToDocument.java
@@ -80,7 +80,7 @@ public class WhenAsciiDocIsLoadedToDocument {
Document document = asciidoctor.load(DOCUMENT, new HashMap<>());
assertThat(document.getDoctitle(), is("Document Title"));
-
+ assertThat(document.getBlocks(), hasSize(3));
}
@Test
@@ -94,7 +94,7 @@ public class WhenAsciiDocIsLoadedToDocument {
public void should_find_elements_from_document() {
Document document = asciidoctor.load(DOCUMENT, new HashMap<>());
- Map<Object, Object> selector = new HashMap<Object, Object>();
+ Map<Object, Object> selector = new HashMap<>();
selector.put("context", ":image");
List<StructuralNode> findBy = document.findBy(selector);
assertThat(findBy, hasSize(2));
@@ -105,7 +105,7 @@ public class WhenAsciiDocIsLoadedToDocument {
}
@Test
- public void should_return_options_from_document() {
+ public void should_return_options_from_parsed_string_when_passed_as_map() {
Map<String, Object> options = OptionsBuilder.options().compact(true).asMap();
Document document = asciidoctor.load(DOCUMENT, options);
@@ -114,6 +114,31 @@ public class WhenAsciiDocIsLoadedToDocument {
assertThat((Boolean) documentOptions.get("compact"), is(true));
}
+ @Test
+ public void should_return_options_from_parsed_string_when_passed_as_options_object() {
+ Options options = Options.builder()
+ .compact(true)
+ .build();
+ Document document = asciidoctor.load(DOCUMENT, options);
+
+ Map<Object, Object> documentOptions = document.getOptions();
+
+ assertThat((Boolean) documentOptions.get("compact"), is(true));
+ }
+
+ @Test
+ public void should_return_options_from_parsed_file_when_passed_as_options_object() {
+ Options options = Options.builder()
+ .compact(true)
+ .build();
+ File resource = classpath.getResource("sourcelocation.adoc");
+ Document document = asciidoctor.loadFile(resource, options);
+
+ Map<Object, Object> documentOptions = document.getOptions();
+
+ assertThat((Boolean) documentOptions.get("compact"), is(true));
+ }
+
@Test
public void should_return_node_name() {
Document document = asciidoctor.load(DOCUMENT, new HashMap<>());
@@ -230,10 +255,11 @@ public class WhenAsciiDocIsLoadedToDocument {
public void should_be_able_to_read_asset() throws FileNotFoundException {
Map<String, Object> options = OptionsBuilder.options().safe(SafeMode.SAFE)
.attributes(AttributesBuilder.attributes().dataUri(false))
- .compact(true).asMap();
+ .compact(true)
+ .asMap();
Document document = asciidoctor.load(DOCUMENT, options);
File inputFile = classpath.getResource("rendersample.asciidoc");
- String content = document.readAsset(inputFile.getAbsolutePath(), new HashMap<Object, Object>());
+ String content = document.readAsset(inputFile.getAbsolutePath(), new HashMap<>());
assertThat(content.replace("\r", ""), is(IOUtils.readFull(new FileReader(inputFile)).replace("\r", "")));
}
@@ -264,7 +290,7 @@ public class WhenAsciiDocIsLoadedToDocument {
// When
Document document = asciidoctor.loadFile(file, OptionsBuilder.options().sourcemap(true).docType("book").asMap());
- Map<Object, Object> selector = new HashMap<Object, Object>();
+ Map<Object, Object> selector = new HashMap<>();
selector.put("context", ":paragraph");
List<StructuralNode> findBy = document.findBy(selector);

MODIFY
docs/modules/ROOT/pages/read-document-tree.adoc
docs/modules/ROOT/pages/read-document-tree.adoc
@@ -13,8 +13,7 @@ To load a document, use the `load` or `loadFile` methods.
import org.asciidoctor.ast.Document;
//...
-
-Document document = asciidoctor.load(DOCUMENT, new HashMap<String, Object>()); // <1>
+Document document = asciidoctor.load(DOCUMENT, Options.builder().build()); // <1>
assertThat(document.doctitle(), is("Document Title")); // <2>
----
<1> Document from a String is loaded into `Document` object.
@@ -30,8 +29,7 @@ import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.Section;
//...
-
-Document document = asciidoctor.load(DOCUMENT, new HashMap<String, Object>()); // <1>
+Document document = asciidoctor.load(DOCUMENT, Options.builder().build()); // <1>
Section section = (Section) document.blocks().get(1); // <2>
assertThat(section.index(), is(0)); // <3>
@@ -46,7 +44,8 @@ Blocks can also be retrieved from query using `findBy` method.
[source,java]
----
-Document document = asciidoctor.load(DOCUMENT, new HashMap<String, Object>());
+Document document = asciidoctor.load(DOCUMENT, Options.builder().build());
+
Map<Object, Object> selector = new HashMap<>(); // <1>
selector.put("context", ":image"); // <2>

Add load(String,Options) and loadFile(File,Options)