diff --git a/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/src/site/asciidoc/sample.adoc b/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/src/site/asciidoc/sample.adoc
index 8d18df98..880c00ab 100644
--- a/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/src/site/asciidoc/sample.adoc
+++ b/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/src/site/asciidoc/sample.adoc
@@ -39,6 +39,7 @@ image::images/asciidoctor-logo.png[Asciidoctor is awesome]
=== Code blocks
[source,ruby]
+.Ruby example
----
puts "Hello, World!"
----
diff --git a/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/validate.groovy b/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/validate.groovy
index 854b71d7..855157fd 100644
--- a/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/validate.groovy
+++ b/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/validate.groovy
@@ -35,6 +35,8 @@ new HtmlAsserter(htmlContent).with { asserter ->
asserter.containsLiteral("This is a literal.")
asserter.containsSectionTitle("Code blocks", 3)
+ asserter.containsCodeBlock("Ruby example")
+ asserter.containsCodeBlock(null) // Java example without title
asserter.containsSectionTitle("Lists", 3)
@@ -210,6 +212,18 @@ class HtmlAsserter {
lastAssertionCursor = end
}
+ void containsCodeBlock(String title) {
+ def blockKey = "
"
+ def found = find(blockKey)
+ assertFound("Code blockKey", blockKey, found)
+
+ if (title != null) {
+ def titleKey = "
") + "
".length()
def end = htmlBlock.indexOf("")
@@ -225,11 +239,11 @@ class HtmlAsserter {
void assertTableHeaders(String htmlBlock, List
headers) {
def actualHeaders = Arrays.stream(htmlBlock.split("<"))
- .filter(line -> line.startsWith("th>"))
- .map(line -> {
- return line.substring("th>".length())
- })
- .collect(Collectors.toList())
+ .filter(line -> line.startsWith("th>"))
+ .map(line -> {
+ return line.substring("th>".length())
+ })
+ .collect(Collectors.toList())
if (actualHeaders != headers)
fail("Table headers not valid. Found: $actualHeaders, expected: $headers")
@@ -252,8 +266,8 @@ class HtmlAsserter {
// Removes linebreaks to validate to avoid OS dependant issues.
private String clean(String value) {
return value.replaceAll("\r\n", "")
- .replaceAll("\n", "")
- .trim();
+ .replaceAll("\n", "")
+ .trim();
}
}
diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ListingNodeProcessor.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ListingNodeProcessor.java
index 4e9c40d3..37e6ce07 100644
--- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ListingNodeProcessor.java
+++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ListingNodeProcessor.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 static org.asciidoctor.maven.commons.StringUtils.isNotBlank;
@@ -41,7 +42,7 @@ public boolean applies(StructuralNode node) {
public void process(StructuralNode node) {
final StringBuilder contentBuilder = new StringBuilder();
String language = (String) node.getAttribute("language");
- String style = (String) node.getAttribute("style");
+ String style = node.getStyle();
boolean isSourceBlock = isSourceBlock(language, style);
@@ -49,6 +50,11 @@ public void process(StructuralNode node) {
// source class triggers prettify auto-detection
contentBuilder.append("");
+ final String title = node.getTitle();
+ if (StringUtils.isNotBlank(title)) {
+ contentBuilder.append("
" + title + "
");
+ }
+
contentBuilder.append("
class HelloWorldLanguage {" +
- " public static void main(String[] args) {" +
- " System.out.println(\"Hello, World!\");" +
- " }" +
- "}
";
- }
-
@Test
void should_convert_full_source_block_with_line_numbers_attribute() {
String content = buildDocument("[source,java,linenums]");
@@ -97,8 +100,13 @@ private String documentWithListingStyleSourceBlock() {
}
private static String buildDocument(String blockDefinition) {
+ return buildDocument(null, blockDefinition);
+ }
+
+ private static String buildDocument(String title, String blockDefinition) {
return "= Document tile\n\n"
+ "== Section\n\n"
+ + buildTitle(title)
+ blockDefinition + "\n" +
"----\n" +
"class HelloWorldLanguage {\n" +
@@ -109,6 +117,31 @@ private static String buildDocument(String blockDefinition) {
"----\n";
}
+ private static String buildTitle(String title) {
+ if (isNotBlank(title))
+ return "." + title + "\n";
+ return "";
+ }
+
+ private static String expectedHtmlCodeBlock() {
+ return expectedHtmlCodeBlock(null);
+ }
+
+ private static String expectedHtmlCodeBlock(String title) {
+ // Actual styling is added in JS by prettify
+ return "" +
+ (isNotBlank(title) ? expectedTitle(title) : "") +
+ "
class HelloWorldLanguage {" +
+ " public static void main(String[] args) {" +
+ " System.out.println(\"Hello, World!\");" +
+ " }" +
+ "}
";
+ }
+
+ private static String expectedTitle(String title) {
+ return "" + title + "
";
+ }
+
private String process(String content) {
StructuralNode node = asciidoctor.load(content, Options.builder().build())
.findBy(Collections.singletonMap("context", ":listing"))