diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/DocumentNodeProcessor.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/DocumentNodeProcessor.java
index 75b096c1..9437cb1c 100644
--- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/DocumentNodeProcessor.java
+++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/DocumentNodeProcessor.java
@@ -5,6 +5,8 @@
import org.asciidoctor.maven.site.parser.NodeProcessor;
import org.asciidoctor.maven.site.parser.NodeSinker;
+import static org.asciidoctor.maven.commons.StringUtils.isNotBlank;
+
/**
* Root document processor.
*
@@ -32,11 +34,12 @@ public void process(StructuralNode node) {
final Sink sink = getSink();
sink.body();
- // TODO review how this fits with Section titles also being 1
- sink.sectionTitle1();
- sink.rawText(node.getTitle());
- sink.sectionTitle1_();
-
+ String title = node.getTitle();
+ if (isNotBlank(title)) {
+ sink.sectionTitle1();
+ sink.rawText(title);
+ sink.sectionTitle1_();
+ }
node.getBlocks()
.forEach(this::sink);
diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/LiteralNodeProcessor.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/LiteralNodeProcessor.java
index 17f5f665..e12ac6f8 100644
--- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/LiteralNodeProcessor.java
+++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/LiteralNodeProcessor.java
@@ -3,6 +3,7 @@
import org.apache.maven.doxia.sink.Sink;
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.jruby.ast.impl.BlockImpl;
+import org.asciidoctor.maven.commons.StringUtils;
import org.asciidoctor.maven.site.parser.NodeProcessor;
import org.asciidoctor.maven.site.parser.NodeSinker;
@@ -33,10 +34,13 @@ public boolean applies(StructuralNode node) {
public void process(StructuralNode node) {
final Sink sink = getSink();
- sink.division();
- sink.rawText("
");
- sink.rawText(((BlockImpl) node).getSource());
- sink.rawText("
");
- sink.division_();
+ String source = ((BlockImpl) node).getSource();
+ if (StringUtils.isNotBlank(source)) {
+ sink.division();
+ sink.rawText("");
+ sink.rawText(source);
+ sink.rawText("
");
+ sink.division_();
+ }
}
}
diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParserTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParserTest.java
index 2a836449..fc30ef6e 100644
--- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParserTest.java
+++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParserTest.java
@@ -1,5 +1,11 @@
package org.asciidoctor.maven.site.parser;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.StringReader;
+import java.io.StringWriter;
+
import lombok.SneakyThrows;
import org.apache.maven.doxia.parser.AbstractTextParser;
import org.apache.maven.doxia.parser.ParseException;
@@ -10,8 +16,6 @@
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-import java.io.*;
-
import static org.asciidoctor.maven.site.parser.AsciidoctorAstDoxiaParserTest.TestMocks.mockAsciidoctorDoxiaParser;
import static org.asciidoctor.maven.site.parser.processors.test.ReflectionUtils.extractField;
import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.clean;
@@ -45,17 +49,23 @@ void should_convert_html_without_any_configuration() throws FileNotFoundExceptio
assertThat(result)
.isEqualTo("Document Title
Preamble paragraph.
" +
+ ""+
"
Section A
" +
"
Section A paragraph.
" +
+ "
"+
"
Section A Subsection
" +
"
Section A 'subsection' paragraph.
" +
+ "
"+
+ "
"+
+ ""+
"
Section B
" +
"
Section B paragraph.
" +
"
" +
"- Item 1
" +
"- Item 2
" +
"- Item 3
" +
- "
");
+ "
" +
+ "
");
}
@Test
diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/NodeSinkerTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/NodeSinkerTest.java
index 942f5ab8..fc04e6ab 100644
--- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/NodeSinkerTest.java
+++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/NodeSinkerTest.java
@@ -4,6 +4,7 @@
import java.util.List;
import org.apache.maven.doxia.sink.Sink;
+import org.asciidoctor.ast.Block;
import org.asciidoctor.ast.Document;
import org.asciidoctor.ast.ListItem;
import org.asciidoctor.ast.StructuralNode;
@@ -27,7 +28,6 @@ class NodeSinkerTest {
private NodeSinker nodeSinker;
private StringWriter sinkWriter;
-
@BeforeEach
void setup() throws NoSuchFieldException, IllegalAccessException {
Sink sink = createSink();
@@ -53,6 +53,7 @@ void should_not_fail_when_processing_invalid_node() {
@Test
void should_process_document_node() {
StructuralNode mockNode = mockNode("document");
+ Mockito.when(mockNode.getTitle()).thenReturn("Something");
nodeSinker.sink(mockNode);
@@ -171,6 +172,9 @@ private static StructuralNode mockNode(String nodeName) {
private static T mockNode(String nodeName, Class extends StructuralNode> clazz) {
StructuralNode mockNode = Mockito.mock(clazz);
Mockito.when(mockNode.getNodeName()).thenReturn(nodeName);
+ if (Block.class.isAssignableFrom(clazz)) {
+ Mockito.when(((Block) mockNode).getSource()).thenReturn("Something");
+ }
return (T) mockNode;
}
}
diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/DocumentNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/DocumentNodeProcessorTest.java
index 6d19d252..3fd02335 100644
--- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/DocumentNodeProcessorTest.java
+++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/DocumentNodeProcessorTest.java
@@ -1,5 +1,7 @@
package org.asciidoctor.maven.site.parser.processors;
+import java.io.StringWriter;
+
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Options;
import org.asciidoctor.ast.StructuralNode;
@@ -7,8 +9,6 @@
import org.asciidoctor.maven.site.parser.processors.test.NodeProcessorTest;
import org.junit.jupiter.api.Test;
-import java.io.StringWriter;
-
import static org.assertj.core.api.Assertions.assertThat;
@NodeProcessorTest(DocumentNodeProcessor.class)
@@ -18,6 +18,16 @@ class DocumentNodeProcessorTest {
private NodeProcessor nodeProcessor;
private StringWriter sinkWriter;
+ @Test
+ void should_not_fail_if_document_is_empty() {
+ String content = "";
+
+ String html = process(content, 0);
+
+ assertThat(html)
+ .isEmpty();
+ }
+
@Test
void should_convert_document_title() {
String content = "= Document tile";
@@ -25,7 +35,7 @@ void should_convert_document_title() {
String html = process(content, 0);
assertThat(html)
- .isEqualTo("Document tile
");
+ .isEqualTo("Document tile
");
}
@Test
@@ -35,7 +45,7 @@ void should_convert_document_title_with_markup() {
String html = process(content, 0);
assertThat(html)
- .isEqualTo("Document tile
");
+ .isEqualTo("Document tile
");
}
private String process(String content, int level) {
diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ListItemNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ListItemNodeProcessorTest.java
index dbeceab8..c8deb13e 100644
--- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ListItemNodeProcessorTest.java
+++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ListItemNodeProcessorTest.java
@@ -1,5 +1,8 @@
package org.asciidoctor.maven.site.parser.processors;
+import java.io.StringWriter;
+import java.util.Collections;
+
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.Options;
import org.asciidoctor.ast.StructuralNode;
@@ -9,9 +12,6 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
-import java.io.StringWriter;
-import java.util.Collections;
-
import static org.assertj.core.api.Assertions.assertThat;
@NodeProcessorTest(ListItemNodeProcessor.class)
@@ -25,51 +25,51 @@ class ListItemNodeProcessorTest {
@ValueSource(strings = {"*", "-"})
void should_convert_list_item(String marker) {
String content = new DocumentBuilder()
- .listItem(marker)
- .toString();
+ .listItem(marker)
+ .toString();
String html = process(content);
assertThat(html)
- .isEqualTo(htmlListItem());
+ .isEqualTo(htmlListItem());
}
@Test
void should_convert_ordered_list_item() {
String content = new DocumentBuilder()
- .listItem(".")
- .toString();
+ .listItem(".")
+ .toString();
String html = process(content);
assertThat(html)
- .isEqualTo(htmlListItem());
+ .isEqualTo(htmlListItem());
}
@ParameterizedTest
@ValueSource(strings = {"*", "-"})
void should_convert_ordered_list_item_with_formatting() {
String content = new DocumentBuilder()
- .formattedListItem("*")
- .toString();
+ .formattedListItem("*")
+ .toString();
String html = process(content);
assertThat(html)
- .isEqualTo(htmlListItemWithFormatting());
+ .isEqualTo(htmlListItemWithFormatting());
}
@ParameterizedTest
@ValueSource(strings = {"*", "-"})
void should_convert_ordered_list_item_with_link(String marker) {
String content = new DocumentBuilder()
- .linkListItem(marker)
- .toString();
+ .linkListItem(marker)
+ .toString();
String html = process(content);
assertThat(html)
- .isEqualTo(htmlListItemWithLink());
+ .isEqualTo(htmlListItemWithLink());
}
private static String htmlListItem() {
@@ -116,8 +116,8 @@ public String toString() {
private String process(String content) {
StructuralNode node = asciidoctor.load(content, Options.builder().build())
- .findBy(Collections.singletonMap("context", ":list_item"))
- .get(0);
+ .findBy(Collections.singletonMap("context", ":list_item"))
+ .get(0);
nodeProcessor.process(node);
diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/LiteralNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/LiteralNodeProcessorTest.java
index c6a46440..231e1a5f 100644
--- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/LiteralNodeProcessorTest.java
+++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/LiteralNodeProcessorTest.java
@@ -26,18 +26,18 @@ void should_convert_simple_literal() {
String html = process(content);
assertThat(html)
- .isEqualTo("");
+ .isEqualTo("");
}
private String documentWithLiteralBlock() {
return "= Document tile\n\n"
- + "== Section\n\n This is a literal line.\n";
+ + "== Section\n\n This is a literal line.\n";
}
private String process(String content) {
StructuralNode node = asciidoctor.load(content, Options.builder().build())
- .findBy(Collections.singletonMap("context", ":literal"))
- .get(0);
+ .findBy(Collections.singletonMap("context", ":literal"))
+ .get(0);
nodeProcessor.process(node);
diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/UnorderedListNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/UnorderedListNodeProcessorTest.java
index c2ab213a..26d790e3 100644
--- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/UnorderedListNodeProcessorTest.java
+++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/UnorderedListNodeProcessorTest.java
@@ -29,10 +29,10 @@ void should_convert_simple_list() {
String html = process(content);
assertThat(html)
- .isEqualTo("" +
- "- unordered item 1
" +
- "- unordered item 2
" +
- "
");
+ .isEqualTo("" +
+ "- unordered item 1
" +
+ "- unordered item 2
" +
+ "
");
}
@Test
@@ -42,44 +42,44 @@ void should_convert_nested_list() {
String html = process(content);
assertThat(html)
- .isEqualTo("" +
- "- unordered item 1" +
- "
" +
- "- unordered item 1 1
" +
- "- unordered item 1 2
" +
- "
" +
- " " +
- "- unordered item 2" +
- "
" +
- "- unordered item 2 1" +
- "
" +
- "- unordered item 2 1 1
" +
- " " +
- "
");
+ .isEqualTo("" +
+ "- unordered item 1" +
+ "
" +
+ "- unordered item 1 1
" +
+ "- unordered item 1 2
" +
+ "
" +
+ " " +
+ "- unordered item 2" +
+ "
" +
+ "- unordered item 2 1" +
+ "
" +
+ "- unordered item 2 1 1
" +
+ " " +
+ "
");
}
private static String buildDocumentWithSimpleList() {
return "= Document tile\n\n"
- + "== Section\n\n"
- + "* unordered item 1\n"
- + "* unordered item 2\n";
+ + "== Section\n\n"
+ + "* unordered item 1\n"
+ + "* unordered item 2\n";
}
private static String buildDocumentWithNestedLists() {
return "= Document tile\n\n"
- + "== Section\n\n"
- + "* unordered item 1\n"
- + "** unordered item 1 1\n"
- + "** unordered item 1 2\n"
- + "* unordered item 2\n"
- + "** unordered item 2 1\n"
- + "*** unordered item 2 1 1\n";
+ + "== Section\n\n"
+ + "* unordered item 1\n"
+ + "** unordered item 1 1\n"
+ + "** unordered item 1 2\n"
+ + "* unordered item 2\n"
+ + "** unordered item 2 1\n"
+ + "*** unordered item 2 1 1\n";
}
private String process(String content) {
StructuralNode node = asciidoctor.load(content, Options.builder().build())
- .findBy(Collections.singletonMap("context", ":ulist"))
- .get(0);
+ .findBy(Collections.singletonMap("context", ":ulist"))
+ .get(0);
nodeProcessor.process(node);