Returns a PhraseNode instead of a String in InlineMacroProcessor
MODIFY
asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/AnnotatedLongInlineMacroProcessor.groovy
asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/AnnotatedLongInlineMacroProcessor.groovy
@@ -19,6 +19,6 @@ class AnnotatedLongInlineMacroProcessor extends InlineMacroProcessor {
Map<String, Object> options = new HashMap<String, Object>()
options['type'] = ':link'
options['target'] = "${target}.html"
- createPhraseNode(parent, 'anchor', target, attributes, options).convert()
+ createPhraseNode(parent, 'anchor', target, attributes, options)
}
}
\ No newline at end of file

MODIFY
asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/AnnotatedRegexpInlineMacroProcessor.groovy
asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/AnnotatedRegexpInlineMacroProcessor.groovy
@@ -17,6 +17,6 @@ class AnnotatedRegexpInlineMacroProcessor extends InlineMacroProcessor {
Map<String, Object> options = new HashMap<String, Object>()
options['type'] = ':link'
options['target'] = "${target}.html"
- createPhraseNode(parent, 'anchor', target, attributes, options).convert()
+ createPhraseNode(parent, 'anchor', target, attributes, options)
}
}
\ No newline at end of file

MODIFY
asciidoctorj-core/src/test/java/org/asciidoctor/extension/ManpageMacro.java
asciidoctorj-core/src/test/java/org/asciidoctor/extension/ManpageMacro.java
@@ -17,12 +17,12 @@ public class ManpageMacro extends InlineMacroProcessor {
}
@Override
- public String process(ContentNode parent, String target,
+ public Object process(ContentNode parent, String target,
Map<String, Object> attributes) {
Map<String, Object> options = new HashMap<String, Object>();
options.put("type", ":link");
options.put("target", target + ".html");
- return createPhraseNode(parent, "anchor", target, attributes, options).convert();
+ return createPhraseNode(parent, "anchor", target, attributes, options);
}
}

MODIFY
asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionGroupIsRegistered.java
asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionGroupIsRegistered.java
@@ -3,11 +3,12 @@ package org.asciidoctor.extension;
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Options;
import org.asciidoctor.SafeMode;
-import org.asciidoctor.arquillian.api.Unshared;
import org.asciidoctor.ast.ContentModel;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.Section;
import org.asciidoctor.ast.StructuralNode;
+import org.asciidoctor.log.LogRecord;
+import org.asciidoctor.log.TestLogHandlerService;
import org.asciidoctor.util.ClasspathResources;
import org.asciidoctor.util.TestHttpServer;
import org.jboss.arquillian.junit.Arquillian;
@@ -16,6 +17,7 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.After;
+import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -37,6 +39,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.logging.LogManager;
import static org.asciidoctor.OptionsBuilder.options;
import static org.hamcrest.CoreMatchers.containsString;
@@ -44,6 +47,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
@@ -60,14 +64,21 @@ public class WhenJavaExtensionGroupIsRegistered {
@ArquillianResource
public TemporaryFolder testFolder;
- @ArquillianResource(Unshared.class)
private Asciidoctor asciidoctor;
+ @Before
+ public void before() {
+ asciidoctor = Asciidoctor.Factory.create();
+ TestLogHandlerService.clear();
+ }
+
@After
- public void tearDown() {
+ public void tearDown() throws IOException {
if (TestHttpServer.getInstance() != null) {
TestHttpServer.getInstance().stop();
}
+ LogManager.getLogManager().readConfiguration();
+ TestLogHandlerService.clear();
}
class RubyIncludeSource extends IncludeProcessor {
@@ -651,6 +662,9 @@ public class WhenJavaExtensionGroupIsRegistered {
org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
Element link = doc.getElementsByTag("a").first();
assertThat(link.attr("href"), is("gittutorial.html"));
+
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test
@@ -668,6 +682,8 @@ public class WhenJavaExtensionGroupIsRegistered {
Element link = doc.getElementsByTag("a").first();
assertThat(link.attr("href"), is("gittutorial.html"));
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test
@@ -690,6 +706,8 @@ public class WhenJavaExtensionGroupIsRegistered {
assertNotNull(link);
assertThat(link.attr("href"), is("gittutorial.html"));
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test
@@ -710,6 +728,9 @@ public class WhenJavaExtensionGroupIsRegistered {
org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
Element link = doc.getElementsByTag("a").first();
assertNull(link);
+
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test
@@ -731,6 +752,8 @@ public class WhenJavaExtensionGroupIsRegistered {
assertNotNull(link);
assertThat(link.attr("href"), is("gittutorial.html"));
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test

MODIFY
asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java
asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java
@@ -3,11 +3,12 @@ package org.asciidoctor.extension;
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Options;
import org.asciidoctor.SafeMode;
-import org.asciidoctor.arquillian.api.Unshared;
import org.asciidoctor.ast.ContentModel;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.Section;
import org.asciidoctor.ast.StructuralNode;
+import org.asciidoctor.log.LogRecord;
+import org.asciidoctor.log.TestLogHandlerService;
import org.asciidoctor.util.ClasspathResources;
import org.asciidoctor.util.TestHttpServer;
import org.jboss.arquillian.junit.Arquillian;
@@ -16,6 +17,7 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.After;
+import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
@@ -36,6 +38,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
+import java.util.logging.LogManager;
import java.util.stream.Collectors;
import static org.asciidoctor.OptionsBuilder.options;
@@ -44,6 +47,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.startsWith;
+import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@@ -61,14 +65,21 @@ public class WhenJavaExtensionIsRegistered {
@ArquillianResource
public TemporaryFolder testFolder;
- @ArquillianResource(Unshared.class)
private Asciidoctor asciidoctor;
+ @Before
+ public void before() {
+ asciidoctor = Asciidoctor.Factory.create();
+ TestLogHandlerService.clear();
+ }
+
@After
- public void tearDown() {
+ public void tearDown() throws IOException {
if (TestHttpServer.getInstance() != null) {
TestHttpServer.getInstance().stop();
}
+ LogManager.getLogManager().readConfiguration();
+ TestLogHandlerService.clear();
}
class RubyIncludeSource extends IncludeProcessor {
@@ -635,6 +646,9 @@ public class WhenJavaExtensionIsRegistered {
org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
Element link = doc.getElementsByTag("a").first();
assertThat(link.attr("href"), is("gittutorial.html"));
+
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test
@@ -652,6 +666,8 @@ public class WhenJavaExtensionIsRegistered {
Element link = doc.getElementsByTag("a").first();
assertThat(link.attr("href"), is("gittutorial.html"));
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test
@@ -674,6 +690,8 @@ public class WhenJavaExtensionIsRegistered {
assertNotNull(link);
assertThat(link.attr("href"), is("gittutorial.html"));
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test
@@ -694,6 +712,9 @@ public class WhenJavaExtensionIsRegistered {
org.jsoup.nodes.Document doc = Jsoup.parse(content, "UTF-8");
Element link = doc.getElementsByTag("a").first();
assertNull(link);
+
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test
@@ -715,6 +736,8 @@ public class WhenJavaExtensionIsRegistered {
assertNotNull(link);
assertThat(link.attr("href"), is("gittutorial.html"));
+ final List<LogRecord> logRecords = TestLogHandlerService.getLogRecords();
+ assertThat(logRecords, hasSize(0));
}
@Test

MODIFY
asciidoctorj-documentation/src/main/asciidoc/integrator-guide.adoc
asciidoctorj-documentation/src/main/asciidoc/integrator-guide.adoc
@@ -728,12 +728,10 @@ include::src/test/java/org/asciidoctor/integrationguide/extension/IssueInlineMac
<2> All InlineMacroProcessors must extend the class `org.asciidoctor.extension.InlineMacroProcessor`.
<3> A InlineMacroProcessor must implement the abstract method `process` that is called by Asciidoctor.
The method must return the rendered result of this macro.
-<4> The implementation constructs a new phrase node that is a link, i.e. an `anchor` via the method `createPhraseNode()`.
+<4> The implementation constructs and returns a new phrase node that is a link, i.e. an `anchor` via the method `createPhraseNode()`.
The third parameter `target` defines that the text to render this link is the target of the macro, that means that the link will be rendered as `333` or `2`.
The last parameter, the options, must contain the target of the line, i.e. the referenced URL, and that the type of the anchor is a link.
It could also be a ':xref', a ':ref', or a ':bibref'.
-<5> Instead of returning the created AST node, the converted result is returned.
- The method `convert()` will invoke the correct converter, so that this also works when rendering to PDF.
To make AsciidoctorJ use our processor it has to be registered at the `JavaExtensionRegistry`:
@@ -773,8 +771,7 @@ The following processor would render the macro `rightclick:New|Class[]` like thi
include::src/test/java/org/asciidoctor/integrationguide/extension/ContextMenuInlineMacroProcessor.java[tags=include]
----
<1> The attributes of the PhraseNode must contain the key `menu` referring to the first menu selection, `submenus` referring to a possibly empty list of submenu selections, and finally the key `menuitem` referring to the final menu item selection.
-<2> Create an PhraseNode with context `menu` and no text.
-<3> The macro processor has to return the converted PhraseNode.
+<2> Create and return an PhraseNode with context `menu` and no text.
To create an inline image the PhraseNode must have the context `image`.
The following example assumes that there is a site \http://foo.bar that serves images given as the target of the macro.
@@ -792,8 +789,7 @@ include::src/test/java/org/asciidoctor/integrationguide/extension/ImageInlineMac
<3> Optional attributes `alt` for alternative text, `width` and `height` are set in the node attributes.
Other possible attributes include `title` to define the title attribute of the `img` element when rendering to HTML.
When setting the attribute `link` to any value the node will be converted to a link to that image, where the window can be defined via the attribute `window`.
-<4> Create a PhraseNode with context `image` and no text.
-<5> The macro processor has to return the converted PhraseNode.
+<4> Create and return a PhraseNode with context `image` and no text.
// #506

MODIFY
asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ContextMenuInlineMacroProcessor.java
asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ContextMenuInlineMacroProcessor.java
@@ -25,8 +25,7 @@ public class ContextMenuInlineMacroProcessor extends InlineMacroProcessor {
attrs.put("submenus", submenus);
attrs.put("menuitem", items[items.length - 1]);
- return createPhraseNode(parent, "menu", (String) null, attrs) // <2>
- .convert(); // <3>
+ return createPhraseNode(parent, "menu", (String) null, attrs); // <2>
}
}
//end::include[]

MODIFY
asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ImageInlineMacroProcessor.java
asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/ImageInlineMacroProcessor.java
@@ -24,8 +24,7 @@ public class ImageInlineMacroProcessor extends InlineMacroProcessor {
attrs.put("width", "64");
attrs.put("height", "64");
- return createPhraseNode(parent, "image", (String) null, attrs, options) // <4>
- .convert(); // <5>
+ return createPhraseNode(parent, "image", (String) null, attrs, options); // <4>
}
}
//end::include[]

MODIFY
asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/IssueInlineMacroProcessor.java
asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/IssueInlineMacroProcessor.java
@@ -28,8 +28,7 @@ public class IssueInlineMacroProcessor extends InlineMacroProcessor { // <2>
Map<String, Object> options = new HashMap<>();
options.put("type", ":link");
options.put("target", href);
- return createPhraseNode(parent, "anchor", target, attributes, options) // <4>
- .convert(); // <5>
+ return createPhraseNode(parent, "anchor", target, attributes, options); // <4>
}
}

MODIFY
asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/KeyboardInlineMacroProcessor.java
asciidoctorj-documentation/src/test/java/org/asciidoctor/integrationguide/extension/KeyboardInlineMacroProcessor.java
@@ -16,8 +16,7 @@ public class KeyboardInlineMacroProcessor extends InlineMacroProcessor {
public Object process(ContentNode parent, String target, Map<String, Object> attributes) {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("keys", Arrays.asList("Ctrl", target)); // <1>
- return createPhraseNode(parent, "kbd", (String) null, attrs) // <2>
- .convert(); // <3>
+ return createPhraseNode(parent, "kbd", (String) null, attrs); // <2>
}
}
//end::include[]

MODIFY
docs/integrator-guide.adoc
docs/integrator-guide.adoc
@@ -906,8 +906,7 @@ public class IssueInlineMacroProcessor extends InlineMacroProcessor { // <2>
Map<String, Object> options = new HashMap<>();
options.put("type", ":link");
options.put("target", href);
- return createPhraseNode(parent, "anchor", target, attributes, options) // <4>
- .convert(); // <5>
+ return createPhraseNode(parent, "anchor", target, attributes, options); // <4>
}
}
@@ -917,12 +916,10 @@ public class IssueInlineMacroProcessor extends InlineMacroProcessor { // <2>
<2> All InlineMacroProcessors must extend the class `org.asciidoctor.extension.InlineMacroProcessor`.
<3> A InlineMacroProcessor must implement the abstract method `process` that is called by Asciidoctor.
The method must return the rendered result of this macro.
-<4> The implementation constructs a new phrase node that is a link, i.e. an `anchor` via the method `createPhraseNode()`.
+<4> The implementation constructs and returns a new phrase node that is a link, i.e. an `anchor` via the method `createPhraseNode()`.
The third parameter `target` defines that the text to render this link is the target of the macro, that means that the link will be rendered as `333` or `2`.
The last parameter, the options, must contain the target of the line, i.e. the referenced URL, and that the type of the anchor is a link.
It could also be a ':xref', a ':ref', or a ':bibref'.
-<5> Instead of returning the created AST node, the converted result is returned.
- The method `convert()` will invoke the correct converter, so that this also works when rendering to PDF.
To make AsciidoctorJ use our processor it has to be registered at the `JavaExtensionRegistry`:
@@ -967,8 +964,7 @@ public class KeyboardInlineMacroProcessor extends InlineMacroProcessor {
public Object process(ContentNode parent, String target, Map<String, Object> attributes) {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put("keys", Arrays.asList("Ctrl", target)); // <1>
- return createPhraseNode(parent, "kbd", (String) null, attrs) // <2>
- .convert(); // <3>
+ return createPhraseNode(parent, "kbd", (String) null, attrs); // <2>
}
}
----
@@ -998,14 +994,12 @@ public class ContextMenuInlineMacroProcessor extends InlineMacroProcessor {
attrs.put("submenus", submenus);
attrs.put("menuitem", items[items.length - 1]);
- return createPhraseNode(parent, "menu", (String) null, attrs) // <2>
- .convert(); // <3>
+ return createPhraseNode(parent, "menu", (String) null, attrs); // <2>
}
}
----
<1> The attributes of the PhraseNode must contain the key `menu` referring to the first menu selection, `submenus` referring to a possibly empty list of submenu selections, and finally the key `menuitem` referring to the final menu item selection.
-<2> Create an PhraseNode with context `menu` and no text.
-<3> The macro processor has to return the converted PhraseNode.
+<2> Create and return an PhraseNode with context `menu` and no text.
To create an inline image the PhraseNode must have the context `image`.
The following example assumes that there is a site \http://foo.bar that serves images given as the target of the macro.
@@ -1032,8 +1026,7 @@ public class ImageInlineMacroProcessor extends InlineMacroProcessor {
attrs.put("width", "64");
attrs.put("height", "64");
- return createPhraseNode(parent, "image", (String) null, attrs, options) // <4>
- .convert(); // <5>
+ return createPhraseNode(parent, "image", (String) null, attrs, options); // <4>
}
}
----
@@ -1042,8 +1035,7 @@ public class ImageInlineMacroProcessor extends InlineMacroProcessor {
<3> Optional attributes `alt` for alternative text, `width` and `height` are set in the node attributes.
Other possible attributes include `title` to define the title attribute of the `img` element when rendering to HTML.
When setting the attribute `link` to any value the node will be converted to a link to that image, where the window can be defined via the attribute `window`.
-<4> Create a PhraseNode with context `image` and no text.
-<5> The macro processor has to return the converted PhraseNode.
+<4> Create and return a PhraseNode with context `image` and no text.
// #506

Returns a PhraseNode instead of a String in InlineMacroProcessor