diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessor.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessor.java index 4cfbb378..3076e202 100644 --- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessor.java +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessor.java @@ -97,7 +97,7 @@ private void processCaption(StructuralNode node, Sink sink) { // getCaption returns // - "" when '[caption=]' // - null when ':table-caption!: - sink.text(title); + sink.rawText(title); sink.tableCaption_(); } } diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ParagraphNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ParagraphNodeProcessorTest.java index 4ced15b8..bd75b9a6 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ParagraphNodeProcessorTest.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ParagraphNodeProcessorTest.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; @@ -7,9 +10,7 @@ import org.asciidoctor.maven.site.parser.processors.test.NodeProcessorTest; import org.junit.jupiter.api.Test; -import java.io.StringWriter; -import java.util.Collections; - +import static org.asciidoctor.maven.site.parser.processors.test.Html.p; import static org.assertj.core.api.Assertions.assertThat; @NodeProcessorTest(ParagraphNodeProcessor.class) @@ -26,7 +27,7 @@ void should_convert_minimal_paragraph() { String html = process(content); assertThat(html) - .isEqualTo("

SomeText

"); + .isEqualTo(p("SomeText")); } @Test @@ -36,7 +37,7 @@ void should_convert_paragraph_with_bold_markup() { String html = process(content); assertThat(html) - .isEqualTo("

Some text

"); + .isEqualTo(p("Some text")); } @Test @@ -46,7 +47,7 @@ void should_convert_paragraph_with_italics_markup() { String html = process(content); assertThat(html) - .isEqualTo("

Some text

"); + .isEqualTo(p("Some text")); } @Test @@ -56,17 +57,17 @@ void should_convert_paragraph_with_monospace_markup() { String html = process(content); assertThat(html) - .isEqualTo("

Some text

"); + .isEqualTo(p("Some text")); } @Test void should_convert_paragraph_with_inline_image() { - String content = documentWithParagraph("image:images/tiger.png[Kitty]"); + String content = documentWithParagraph("An inline image image:images/tiger.png[Kitty] here!"); String html = process(content); assertThat(html) - .isEqualTo("

\"Kitty\"

"); + .isEqualTo(p("An inline image \"Kitty\" here!")); } private String documentWithParagraph(String text) { @@ -75,8 +76,8 @@ private String documentWithParagraph(String text) { private String process(String content) { StructuralNode node = asciidoctor.load(content, Options.builder().build()) - .findBy(Collections.singletonMap("context", ":paragraph")) - .get(0); + .findBy(Collections.singletonMap("context", ":paragraph")) + .get(0); nodeProcessor.process(node); diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/PreambleNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/PreambleNodeProcessorTest.java index 99712620..32eccd16 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/PreambleNodeProcessorTest.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/PreambleNodeProcessorTest.java @@ -10,6 +10,7 @@ import org.asciidoctor.maven.site.parser.processors.test.NodeProcessorTest; import org.junit.jupiter.api.Test; +import static org.asciidoctor.maven.site.parser.processors.test.Html.p; import static org.assertj.core.api.Assertions.assertThat; @NodeProcessorTest(PreambleNodeProcessor.class) @@ -26,9 +27,7 @@ void should_convert_preamble() { String html = process(content); assertThat(html) - .isEqualTo("

This is a preamble." + - System.lineSeparator() + - "With two lines.

"); + .isEqualTo(p("This is a preamble." + System.lineSeparator() + "With two lines.")); } @Test @@ -38,7 +37,29 @@ void should_convert_preamble_with_markup() { String html = process(content); assertThat(html) - .isEqualTo("

This is a simple preamble.

"); + .isEqualTo(p("This is a simple preamble.")); + } + + @Test + void should_convert_preamble_with_link() { + final String link = "https://docs.asciidoctor.org/"; + String content = documentWithPreamble("There's link " + link + " in the preamble."); + + String html = process(content); + + assertThat(html) + .isEqualTo(p("There’s link https://docs.asciidoctor.org/ in the preamble.")); + } + + @Test + void should_convert_preamble_with_inline_image() { + final String inlineImage = "image:images/tiger.png[Kitty]"; + String content = documentWithPreamble("An inline image " + inlineImage + " here!"); + + String html = process(content); + + assertThat(html) + .isEqualTo(p("An inline image \"Kitty\" here!")); } private String documentWithPreamble() { diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessorTest.java index 662bd653..3e7b8666 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessorTest.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/TableNodeProcessorTest.java @@ -4,6 +4,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.asciidoctor.Asciidoctor; @@ -11,11 +12,15 @@ import org.asciidoctor.ast.StructuralNode; import org.asciidoctor.maven.site.parser.NodeProcessor; import org.asciidoctor.maven.site.parser.processors.test.NodeProcessorTest; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import static java.util.Collections.emptyList; import static org.asciidoctor.maven.site.parser.processors.TableNodeProcessorTest.DocumentBuilder.CaptionOptions.*; import static org.asciidoctor.maven.site.parser.processors.TableNodeProcessorTest.DocumentBuilder.documentWithTable; +import static org.asciidoctor.maven.site.parser.processors.test.Html.Attributes.STYLE; +import static org.asciidoctor.maven.site.parser.processors.test.Html.td; +import static org.asciidoctor.maven.site.parser.processors.test.Html.tr; import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.removeLineBreaks; import static org.assertj.core.api.Assertions.assertThat; @@ -135,6 +140,65 @@ void should_convert_table_with_labels_disabled_globally() { .isEqualTo(expectedTableWithoutLabel()); } + @Nested + class WhenCellContains { + + @Test + void formatted_text() { + final String formattedContent = "This *is* _a_ simple `cell`"; + String content = documentWithTable(false, noCaption, List.of(formattedContent, "Something else")); + + String html = process(content); + + assertThat(html) + .isEqualTo("" + + tr("a", td("JRuby", textAlignLeft()) + td("Java")) + + tr("b", td("Rubinius", textAlignLeft()) + td("Ruby")) + + tr("a", + td("This isa simple cell", textAlignLeft()) + + td("Something else")) + + "
"); + } + + @Test + void links() { + final String link = "https://docs.asciidoctor.org/"; + String content = documentWithTable(false, noCaption, List.of("With links " + link + ".", "Something else")); + + String html = process(content); + + assertThat(html) + .isEqualTo("" + + tr("a", td("JRuby", textAlignLeft()) + td("Java")) + + tr("b", td("Rubinius", textAlignLeft()) + td("Ruby")) + + tr("a", + td("With links https://docs.asciidoctor.org/.", textAlignLeft()) + + td("Something else")) + + "
"); + } + + @Test + void inline_images() { + final String inlineImage = "image:images/tiger.png[Kitty]"; + String content = documentWithTable(false, noCaption, List.of("Something first", "With inline (" + inlineImage + ") images.")); + + String html = process(content); + + assertThat(html) + .isEqualTo("" + + tr("a", td("JRuby", textAlignLeft()) + td("Java")) + + tr("b", td("Rubinius", textAlignLeft()) + td("Ruby")) + + tr("a", + td("Something first", textAlignLeft()) + + td("With inline (\"Kitty\") images.")) + + "
"); + } + + private Map textAlignLeft() { + return Map.of(STYLE, "text-align: left;"); + } + } + private static String expectedNoLabelBeginning() { return "" + ""; diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/Html.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/Html.java index 0c062062..b01147c6 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/Html.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/Html.java @@ -1,5 +1,11 @@ package org.asciidoctor.maven.site.parser.processors.test; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.asciidoctor.maven.site.parser.processors.test.Html.Attributes.CLASS; +import static org.asciidoctor.maven.site.parser.processors.test.Html.Attributes.STYLE; + public class Html { public static final String LIST_STYLE_TYPE_DECIMAL = "list-style-type: decimal;"; @@ -25,7 +31,7 @@ public static String ul(String... elements) { } public static String ol(String style, String... elements) { - return htmlElement("ol", style, String.join("", elements)); + return htmlElement("ol", String.join("", elements), Map.of(STYLE, style)); } public static String li(String text) { @@ -44,14 +50,36 @@ public static String p(String text) { return htmlElement("p", text); } + public static String tr(String className, String text) { + return htmlElement("tr", text, Map.of(CLASS, className)); + } + + public static String td(String text) { + return htmlElement("td", text, Map.of()); + } + + public static String td(String text, Map attributes) { + return htmlElement("td", text, attributes); + } + static String htmlElement(String element, String text) { - return htmlElement(element, null, text); + return htmlElement(element, text, Map.of()); } - static String htmlElement(String element, String style, String text) { - if (style == null) { - return String.format("<%1$s>%2$s", element, text).trim(); + static String htmlElement(String element, String text, Map attributes) { + if (!attributes.isEmpty()) { + String formattedAttributes = attributes.entrySet() + .stream() + .map(entry -> String.format("%s=\"%s\"", entry.getKey(), entry.getValue())) + .collect(Collectors.joining(" ")); + return String.format("<%1$s %3$s>%2$s", element, text, formattedAttributes).trim(); } - return String.format("<%1$s style=\"%3$s\">%2$s", element, text, style).trim(); + + return String.format("<%1$s>%2$s", element, text).trim(); + } + + public final class Attributes { + public static final String STYLE = "style"; + public static final String CLASS = "class"; } }
Table caption…​or title