diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 28ea77b3..73b89923 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -17,15 +17,19 @@ Bug Fixes:: * Fix open IMG tags in parser-doxia-module (#930) * Fix naming in Asciidoctor Converter Doxia Module pom (#934) + * Fix empty table generating element (asciidoctor-parser-doxia-module) (#938) Improvements:: * Added support for AsciidoctorJ v3.0.0 (#651) * Add compatibility with maven-site-plugin v3.20.0 and Doxia v2.0.0 (#933) - * Add support for code blocks titles in asciidoctor-parser-doxia-module (#935) - * Refactor AST traversal method in asciidoctor-parser-doxia-module (#944) + * Add support for code blocks titles (asciidoctor-parser-doxia-module) (#935) + * Refactor AST traversal method (asciidoctor-parser-doxia-module) (#944) * Empty titles in document or empty literals no longer generate

or
 in asciidoctor-parser-doxia-module (#944)
-  * Sections are now wrapped in 
in asciidoctor-parser-doxia-module (#944) + * Sections are now wrapped in
in (asciidoctor-parser-doxia-module) (#944) + * Add support for inline and Example blocks (asciidoctor-parser-doxia-module) (#938) + * Add support for captioned titles in appendixes, tables, listing, figure, and examples (asciidoctor-parser-doxia-module) (#938) + Build / Infrastructure:: 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 880c00ab..f1edc352 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 @@ -91,3 +91,16 @@ Linux::: BSD::: . FreeBSD . NetBSD + +=== Examples + +.Optional title (1) +==== +This is an example of an example block (1). +==== + +.Optional title (2) +[example] +This is an example of an example block (2). +*dadsas* https://dasd.com + 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 6d7d5b50..5dcbbda1 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 @@ -58,6 +58,10 @@ new HtmlAsserter(htmlContent).with { asserter -> asserter.containsUnorderedList("Desktop", "Server") asserter.descriptionListTerm("BSD") asserter.containsOrderedList("FreeBSD", "NetBSD") + + asserter.containsSectionTitle("Examples", 3) + asserter.containsExampleDiv() + asserter.containsExampleDiv() } String strong(String text) { @@ -224,8 +228,15 @@ class HtmlAsserter { } } + void containsExampleDiv() { + final def key = "
", key, found) + } + void assertTableCaption(String htmlBlock, String caption) { - def start = htmlBlock.indexOf("

") if (start < 0 || end < 0) fail("Caption not found ($start, $end)") @@ -239,11 +250,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") @@ -266,8 +277,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/NodeSinker.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/NodeSinker.java index 604bfced..bc375648 100644 --- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/NodeSinker.java +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/NodeSinker.java @@ -7,6 +7,7 @@ import org.asciidoctor.ast.StructuralNode; import org.asciidoctor.maven.site.parser.processors.DescriptionListNodeProcessor; import org.asciidoctor.maven.site.parser.processors.DocumentNodeProcessor; +import org.asciidoctor.maven.site.parser.processors.ExampleNodeProcessor; import org.asciidoctor.maven.site.parser.processors.ImageNodeProcessor; import org.asciidoctor.maven.site.parser.processors.ListItemNodeProcessor; import org.asciidoctor.maven.site.parser.processors.ListingNodeProcessor; @@ -35,6 +36,7 @@ public NodeSinker(Sink sink) { nodeProcessors = Arrays.asList( new DescriptionListNodeProcessor(sink, this), new DocumentNodeProcessor(sink, this), + new ExampleNodeProcessor(sink, this), new ImageNodeProcessor(sink, this), new ListItemNodeProcessor(sink, this), new ListingNodeProcessor(sink, this), 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 9437cb1c..18a4254e 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 @@ -18,7 +18,8 @@ public class DocumentNodeProcessor extends AbstractSinkNodeProcessor implements /** * Constructor. * - * @param sink Doxia {@link Sink} + * @param sink Doxia {@link Sink} + * @param nodeSinker */ public DocumentNodeProcessor(Sink sink, NodeSinker nodeSinker) { super(sink, nodeSinker); diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ExampleNodeProcessor.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ExampleNodeProcessor.java new file mode 100644 index 00000000..83404cdb --- /dev/null +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ExampleNodeProcessor.java @@ -0,0 +1,71 @@ +package org.asciidoctor.maven.site.parser.processors; + +import java.util.List; + +import org.apache.maven.doxia.sink.Sink; +import org.asciidoctor.ast.StructuralNode; +import org.asciidoctor.maven.site.parser.NodeProcessor; +import org.asciidoctor.maven.site.parser.NodeSinker; + +import static javax.swing.text.html.HTML.Attribute.STYLE; +import static org.asciidoctor.maven.commons.StringUtils.isNotBlank; + +/** + * Inline images are processed as paragraphs. + * + * @author abelsromero + * @since 3.1.0 + */ +public class ExampleNodeProcessor extends AbstractSinkNodeProcessor implements NodeProcessor { + + /** + * Constructor. + * + * @param sink Doxia {@link Sink} + * @param nodeSinker + */ + public ExampleNodeProcessor(Sink sink, NodeSinker nodeSinker) { + super(sink, nodeSinker); + } + + @Override + public boolean applies(StructuralNode node) { + return "example".equals(node.getNodeName()); + } + + @Override + public void process(StructuralNode node) { + // Add caption as a div (same as Asciidoctor): + // - For consistency + // - Using `figureCaption` requires wrapping the image in
which adds indentation + final Sink sink = getSink(); + + sink.division(); + final String title = TitleCaptionExtractor.getText(node); + if (isNotBlank(title)) { + sink.division(SinkAttributes.of(STYLE, Styles.CAPTION)); + sink.text(title); + sink.division_(); + } + + final List blocks = node.getBlocks(); + if (!blocks.isEmpty()) { + divWrap(sink, node, () -> blocks.forEach(this::sink)); + } else { + // For :content_model: simple (inline) + // https://docs.asciidoctor.org/asciidoc/latest/blocks/example-blocks/#example-style-syntax + final String content = (String) node.getContent(); + if (isNotBlank(content)) { + divWrap(sink, node, () -> sink.rawText(content)); + } + } + + sink.division_(); + } + + void divWrap(Sink sink, StructuralNode node, Runnable consumer) { + sink.division(SinkAttributes.of(STYLE, Styles.EXAMPLE)); + consumer.run(); + sink.division_(); + } +} diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ImageNodeProcessor.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ImageNodeProcessor.java index 47a48d9b..01cdc1f9 100644 --- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ImageNodeProcessor.java +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/ImageNodeProcessor.java @@ -1,15 +1,16 @@ package org.asciidoctor.maven.site.parser.processors; -import javax.swing.text.html.HTML.Attribute; import java.nio.file.FileSystems; import org.apache.maven.doxia.sink.Sink; -import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; import org.asciidoctor.ast.StructuralNode; import org.asciidoctor.maven.site.parser.NodeProcessor; import org.asciidoctor.maven.site.parser.NodeSinker; +import static javax.swing.text.html.HTML.Attribute.ALT; +import static javax.swing.text.html.HTML.Attribute.STYLE; import static org.asciidoctor.maven.commons.StringUtils.isBlank; +import static org.asciidoctor.maven.commons.StringUtils.isNotBlank; /** * Inline images are processed as paragraphs. @@ -40,12 +41,21 @@ public void process(StructuralNode node) { final String alt = (String) node.getAttribute("alt"); final String imagesdir = (String) node.getAttribute("imagesdir"); - String imagePath = isBlank(imagesdir) ? target : formatPath(imagesdir, target); - final SinkEventAttributeSet attributes = new SinkEventAttributeSet(); - if (!isBlank(alt)) - attributes.addAttribute(Attribute.ALT, alt); + final String imagePath = isBlank(imagesdir) ? target : formatPath(imagesdir, target); - getSink().figureGraphics(imagePath, attributes); + // Add caption as a div (same as Asciidoctor): + // - For consistency + // - Using `figureCaption` requires wrapping the image in
which adds indentation + final Sink sink = getSink(); + sink.division(); + sink.figureGraphics(imagePath, !isBlank(alt) ? SinkAttributes.of(ALT, alt) : null); + final String title = TitleCaptionExtractor.getText(node); + if (isNotBlank(title)) { + sink.division(SinkAttributes.of(STYLE, Styles.CAPTION)); + sink.text(title); + sink.division_(); + } + sink.division_(); } private String formatPath(String imagesdir, String target) { 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 e885f0b0..490a6d0a 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 @@ -2,7 +2,6 @@ import org.apache.maven.doxia.sink.Sink; import org.asciidoctor.ast.StructuralNode; -import org.asciidoctor.maven.commons.StringUtils; import org.asciidoctor.maven.site.parser.NodeProcessor; import org.asciidoctor.maven.site.parser.NodeSinker; @@ -39,20 +38,15 @@ public boolean applies(StructuralNode node) { @Override public void process(StructuralNode node) { final StringBuilder contentBuilder = new StringBuilder(); - String language = (String) node.getAttribute("language"); - String style = node.getStyle(); + final String language = (String) node.getAttribute("language"); + final String style = node.getStyle(); boolean isSourceBlock = isSourceBlock(language, style); if (isSourceBlock) { // source class triggers prettify auto-detection contentBuilder.append("
"); - - final String title = node.getTitle(); - if (StringUtils.isNotBlank(title)) { - contentBuilder.append("
" + title + "
"); - } - + processTitle(node, contentBuilder); contentBuilder.append("
" + title + "
"); + } + } + private boolean isLinenumsEnabled(StructuralNode node) { // linenums attribute can be set with empty string value return LINENUMS_ATTRIBUTE.equals(node.getAttribute("linenums")) diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/SectionNodeProcessor.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/SectionNodeProcessor.java index a1d06208..b56d828c 100644 --- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/SectionNodeProcessor.java +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/SectionNodeProcessor.java @@ -3,6 +3,8 @@ import org.apache.maven.doxia.sink.Sink; import org.asciidoctor.ast.Section; import org.asciidoctor.ast.StructuralNode; +import org.asciidoctor.jruby.ast.impl.SectionImpl; +import org.asciidoctor.maven.commons.StringUtils; import org.asciidoctor.maven.site.parser.NodeProcessor; import org.asciidoctor.maven.site.parser.NodeSinker; import org.slf4j.Logger; @@ -77,7 +79,14 @@ private String formatTitle(String title, Section node) { final Long sectnumlevels = getSectnumlevels(node); final int level = node.getLevel(); if (numbered && level <= sectnumlevels) { - return String.format("%s %s", node.getSectnum(), title); + // Use 'getString' instead of method to support pre-3.0.0 AsciidoctorJ + final String caption = node.getCaption(); + final String sectnum = ((SectionImpl) node).getString("sectnum"); + if (StringUtils.isBlank(caption)) { + return String.format("%s %s", sectnum, title); + } else { + return String.format("%s %s", caption.trim(), title); + } } return title; } diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/SinkAttributes.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/SinkAttributes.java new file mode 100644 index 00000000..6636e741 --- /dev/null +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/SinkAttributes.java @@ -0,0 +1,16 @@ +package org.asciidoctor.maven.site.parser.processors; + +import javax.swing.text.html.HTML.Attribute; + +import org.apache.maven.doxia.sink.SinkEventAttributes; +import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet; + +class SinkAttributes { + + static SinkEventAttributes of(Attribute name, String value) { + final var attributes = new SinkEventAttributeSet(); + attributes.addAttribute(name, value); + return attributes; + } + +} diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/Styles.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/Styles.java new file mode 100644 index 00000000..58f56678 --- /dev/null +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/Styles.java @@ -0,0 +1,22 @@ +package org.asciidoctor.maven.site.parser.processors; + +import java.util.stream.Collectors; +import java.util.stream.Stream; + +class Styles { + + public static final String CAPTION = Stream.of( + "color: #7a2518", + "margin-bottom: .25em" + ).collect(Collectors.joining("; ")); + + + public static final String EXAMPLE = Stream.of( + "background: #fffef7", + "border-color: #e0e0dc", + "border: 1px solid #e6e6e6", + "box-shadow: 0 1px 4px #e0e0dc", + "margin-bottom: 1.25em", + "padding: 1.25em" + ).collect(Collectors.joining("; ")); +} 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 fdb4dce7..4cfbb378 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 @@ -10,8 +10,8 @@ import org.asciidoctor.maven.site.parser.NodeProcessor; import org.asciidoctor.maven.site.parser.NodeSinker; +import static javax.swing.text.html.HTML.Attribute.STYLE; import static org.apache.maven.doxia.sink.Sink.JUSTIFY_LEFT; -import static org.asciidoctor.maven.commons.StringUtils.isBlank; import static org.asciidoctor.maven.commons.StringUtils.isNotBlank; /** @@ -44,8 +44,13 @@ public void process(StructuralNode node) { final Sink sink = getSink(); sink.table(); sink.tableRows(new int[]{JUSTIFY_LEFT}, false); - List header = tableNode.getHeader(); - List blocks = node.getBlocks(); + final List header = tableNode.getHeader(); + final List rows = tableNode.getBody(); + + if (header.isEmpty() && rows.isEmpty()) { + return; + } + if (!header.isEmpty()) { sink.tableRow(); @@ -59,7 +64,7 @@ public void process(StructuralNode node) { sink.tableRow_(); } - for (Row row : tableNode.getBody()) { + for (Row row : rows) { sink.tableRow(); for (Cell cell : row.getCells()) { sink.tableCell(); @@ -78,18 +83,21 @@ public void process(StructuralNode node) { private void processCaption(StructuralNode node, Sink sink) { // 'null' when not set or '[caption=]' final String tableCaption = (String) node.getAttribute("table-caption"); + final String caption = node.getCaption(); // disable single caption - final String title = node.getTitle(); + // if "[caption=]" -> remove caption + // disable too, when ":table-caption!:" + // final String title = node.getTitle(); + final String title = TitleCaptionExtractor.getText(node); if (isNotBlank(title)) { - // TODO why do we do this next line? - // node.getContentModel(); - sink.tableCaption(); - // It's safe: getCaption returns "" when '[caption=]' is set - if (isBlank(node.getCaption())) - sink.text(node.getTitle()); - else - sink.text(node.getCaption() + node.getTitle()); + // Contrary to other cases where we use
, we use
" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
") + "".length() + def start = htmlBlock.indexOf("", start) + 1 def end = htmlBlock.indexOf(": same as Fluido and Asciidoctor + // TODO Have a proper CSS stylesheet injected + sink.tableCaption(SinkAttributes.of(STYLE, Styles.CAPTION + "; text-align: left")); + // getCaption returns + // - "" when '[caption=]' + // - null when ':table-caption!: + sink.text(title); sink.tableCaption_(); } } diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TitleCaptionExtractor.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TitleCaptionExtractor.java new file mode 100644 index 00000000..fe7ff4d9 --- /dev/null +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/processors/TitleCaptionExtractor.java @@ -0,0 +1,23 @@ +package org.asciidoctor.maven.site.parser.processors; + +import org.asciidoctor.ast.StructuralNode; + +import static org.asciidoctor.maven.commons.StringUtils.isBlank; + +/** + * Utility to extract composed title and caption text. + * + * @author abelsromero + * @since 3.1.0 + */ +class TitleCaptionExtractor { + + // Not used in SectionNodeProcessor to avoid extra node processing + static String getText(StructuralNode node) { + // Caption is returned when a title is set in: + // - Image blocks + // - Listings + final String caption = node.getCaption(); + return isBlank(caption) ? node.getTitle() : String.format("%s %s", caption.trim(), node.getTitle()); + } +} 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 fc30ef6e..c2016446 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 @@ -18,7 +18,7 @@ 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; +import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.removeLineBreaks; import static org.asciidoctor.maven.site.parser.processors.test.TestNodeProcessorFactory.createSink; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; @@ -195,12 +195,12 @@ void should_fail_when_logHandler_failIf_is_WARNING() { private String parse(AbstractTextParser parser, File source) throws FileNotFoundException, ParseException { parser.parse(new FileReader(source), sink); - return clean(sinkWriter.toString()); + return removeLineBreaks(sinkWriter.toString()); } private String parse(AbstractTextParser parser, String source) throws ParseException { parser.parse(new StringReader(source), sink); - return clean(sinkWriter.toString()); + return removeLineBreaks(sinkWriter.toString()); } static class TestMocks { 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 fc04e6ab..e1f11fe6 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 @@ -5,9 +5,12 @@ import org.apache.maven.doxia.sink.Sink; import org.asciidoctor.ast.Block; +import org.asciidoctor.ast.Cell; import org.asciidoctor.ast.Document; import org.asciidoctor.ast.ListItem; +import org.asciidoctor.ast.Row; import org.asciidoctor.ast.StructuralNode; +import org.asciidoctor.ast.Table; import org.asciidoctor.jruby.ast.impl.BlockImpl; import org.asciidoctor.jruby.ast.impl.DocumentImpl; import org.asciidoctor.jruby.ast.impl.SectionImpl; @@ -105,6 +108,11 @@ void should_process_section_node() { @Test void should_process_table_node() { StructuralNode mockNode = mockNode("table", TableImpl.class); + Cell mockCell = Mockito.mock(Cell.class); + Mockito.when(mockCell.getText()).thenReturn("Cell text"); + Row mockRow = Mockito.mock(Row.class); + Mockito.when(mockRow.getCells()).thenReturn(List.of(mockCell)); + Mockito.when(((Table) mockNode).getBody()).thenReturn(List.of(mockRow)); nodeSinker.sink(mockNode); diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/DescriptionListNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/DescriptionListNodeProcessorTest.java index b4854b61..0bca84b6 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/DescriptionListNodeProcessorTest.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/DescriptionListNodeProcessorTest.java @@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test; import static org.asciidoctor.maven.site.parser.processors.test.Html.*; -import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.clean; +import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.removeLineBreaks; import static org.assertj.core.api.Assertions.assertThat; @NodeProcessorTest(DescriptionListNodeProcessor.class) @@ -146,6 +146,6 @@ private String process(String content) { nodeProcessor.process(node); - return clean(sinkWriter.toString()); + return removeLineBreaks(sinkWriter.toString()); } } diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ExampleNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ExampleNodeProcessorTest.java new file mode 100644 index 00000000..2e7abfb6 --- /dev/null +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ExampleNodeProcessorTest.java @@ -0,0 +1,229 @@ +package org.asciidoctor.maven.site.parser.processors; + +import java.io.StringWriter; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +import org.asciidoctor.Asciidoctor; +import org.asciidoctor.Options; +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 org.asciidoctor.maven.site.parser.processors.test.Html.*; +import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.removeLineBreaks; +import static org.assertj.core.api.Assertions.assertThat; + +@NodeProcessorTest(ExampleNodeProcessor.class) +class ExampleNodeProcessorTest { + + public static final String EXAMPLE_TITLE_OPENING = "
"; + public static final String EXAMPLE_CONTENT_OPENING = "
"; + + private Asciidoctor asciidoctor; + private NodeProcessor nodeProcessor; + private StringWriter sinkWriter; + + @Test + void should_convert_empty_example() { + String content = documentWithExample(null, null, List.of()); + + String html = process(content); + + assertThat(html) + .isEqualTo(div("")); + } + + @Test + void should_convert_minimal_example() { + String content = documentWithExample("SomeText", null, List.of()); + + String html = process(content); + + assertThat(html) + .isEqualTo(div( + EXAMPLE_CONTENT_OPENING + + p("SomeText") + + "
")); + } + + @Test + void should_convert_example_with_title() { + String content = documentWithExample("SomeText", "The title", List.of()); + + String html = process(content); + + assertThat(html) + .isEqualTo(div( + EXAMPLE_TITLE_OPENING + "Example 1. The title
" + + EXAMPLE_CONTENT_OPENING + + p("SomeText") + + "")); + } + + @Test + void should_convert_example_with_title_without_caption() { + String content = documentWithExample("SomeText", "The title", List.of(":example-caption!:")); + + String html = process(content); + + assertThat(html) + .isEqualTo(div( + EXAMPLE_TITLE_OPENING + "The title" + + EXAMPLE_CONTENT_OPENING + + p("SomeText") + + "")); + } + + @Test + void should_convert_with_nested_link() { + final String link = "https://docs.asciidoctor.org/"; + String content = documentWithExample(link, null, List.of()); + + String html = process(content); + + assertThat(html) + .isEqualTo(div( + EXAMPLE_CONTENT_OPENING + + p("https://docs.asciidoctor.org/") + + "")); + } + + @Test + void should_convert_with_nested_table() { + final String table = "|===\n" + + "|Header 1 |Header 2\n" + + "|Column 1, row 1\n" + + "|Column 2, row 1\n" + + "|==="; + String content = documentWithExample(table, null, List.of()); + + String html = process(content); + + assertThat(html) + .isEqualTo(div( + EXAMPLE_CONTENT_OPENING + + "" + + "" + + "" + + "
Header 1Header 2
Column 1, row 1Column 2, row 1
" + + "")); + } + + @Test + void should_convert_with_nested_list() { + final String list = "* Un\n" + + "** Dos\n" + + "* Tres\n" + + "** Quatre"; + String content = documentWithExample(list, null, List.of()); + + String html = process(content); + + assertThat(html) + .isEqualTo(div( + EXAMPLE_CONTENT_OPENING + + ul( + li("Un" + ul(li("Dos"))) + + li("Tres" + ul(li("Quatre"))) + ) + + "")); + } + + @Test + void should_convert_with_multiple_nested_elements() { + final String list = "* Un\n" + + "** Dos\n" + + "* Tres\n" + + "** Quatre"; + final String link = "https://docs.asciidoctor.org/"; + String content = documentWithExample(list + "\n\n" + link, null, List.of()); + + String html = process(content); + + assertThat(html) + .isEqualTo(div( + EXAMPLE_CONTENT_OPENING + + ul( + li("Un" + ul(li("Dos"))) + + li("Tres" + ul(li("Quatre"))) + ) + + p("https://docs.asciidoctor.org/") + + "")); + } + + private String documentWithExample(String text, String title, List attributes) { + return "= Tile\n\n" + "== Section\n\n" + + (attributes.isEmpty() ? "" : attributes.stream().collect(Collectors.joining("\n"))) + "\n" + + (title == null ? "" : "." + title) + "\n" + + "====" + "\n" + + (text == null ? "" : text) + "\n" + + "====" + "\n"; + } + + private String process(String content) { + StructuralNode node = asciidoctor.load(content, Options.builder().build()) + .findBy(Collections.singletonMap("context", ":example")) + .get(0); + + nodeProcessor.process(node); + + return removeLineBreaks(sinkWriter.toString()); + } + + @Nested + class WithSimpleContentModel { + + @Test + void should_convert_minimal_example() { + String content = "= Tile\n\n" + "== Section\n\n" + + "[example]\n" + + "SomeText"; + + String html = process(content); + + // Content is directly embedded instead of delegated to paragraph processor + assertThat(html) + .isEqualTo(div( + EXAMPLE_CONTENT_OPENING + + "SomeText" + + "")); + } + + @Test + void should_convert_minimal_example_with_title() { + String content = "= Tile\n\n" + "== Section\n\n" + + ".Optional title\n" + + "[example]\n" + + "SomeText"; + + String html = process(content); + + assertThat(html) + .isEqualTo(div( + EXAMPLE_TITLE_OPENING + "Example 1. Optional title" + + EXAMPLE_CONTENT_OPENING + + "SomeText" + + "")); + } + + @Test + void should_convert_minimal_example_with_link() { + final String link = "https://docs.asciidoctor.org/"; + String content = "= Tile\n\n" + "== Section\n\n" + + "[example]\n" + + "SomeText, " + link; + + String html = process(content); + + assertThat(html) + .isEqualTo(div( + EXAMPLE_CONTENT_OPENING + + "SomeText, https://docs.asciidoctor.org/" + + "")); + } + } +} diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ImageNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ImageNodeProcessorTest.java index c46ed1bd..602dea52 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ImageNodeProcessorTest.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ImageNodeProcessorTest.java @@ -10,9 +10,11 @@ import org.asciidoctor.Options; import org.asciidoctor.ast.StructuralNode; import org.asciidoctor.maven.site.parser.NodeProcessor; +import org.asciidoctor.maven.site.parser.processors.test.Html; 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.div; import static org.assertj.core.api.Assertions.assertThat; @NodeProcessorTest(ImageNodeProcessor.class) @@ -29,7 +31,7 @@ void should_convert_document_with_image() { String html = process(content, 0); assertThat(html) - .isEqualTo("\"Kitty\""); + .isEqualTo(div("\"Kitty\"")); } @Test @@ -40,7 +42,7 @@ void should_convert_document_with_image_and_imagesdir_attribute() { final String separator = FileSystems.getDefault().getSeparator(); assertThat(html) - .isEqualTo("\"Kitty\""); + .isEqualTo(div("\"Kitty\"")); } private String documentWithImage() { diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ListingNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ListingNodeProcessorTest.java index b1d5aa17..81534a63 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ListingNodeProcessorTest.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/ListingNodeProcessorTest.java @@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test; import static org.asciidoctor.maven.commons.StringUtils.isNotBlank; -import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.clean; +import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.removeLineBreaks; import static org.assertj.core.api.Assertions.assertThat; @NodeProcessorTest(ListingNodeProcessor.class) @@ -138,7 +138,7 @@ private static String expectedHtmlCodeBlock(String title) { } private static String expectedTitle(String title) { - return "
" + title + "
"; + return "
" + title + "
"; } private String process(String content) { @@ -148,6 +148,6 @@ private String process(String content) { nodeProcessor.process(node); - return clean(sinkWriter.toString()); + return removeLineBreaks(sinkWriter.toString()); } } diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/OrderedListNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/OrderedListNodeProcessorTest.java index 290fb677..1d30d922 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/OrderedListNodeProcessorTest.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/OrderedListNodeProcessorTest.java @@ -6,14 +6,12 @@ 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.BeforeEach; import org.junit.jupiter.api.Test; import java.io.StringWriter; -import java.util.Arrays; import java.util.Collections; -import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.clean; +import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.removeLineBreaks; import static org.assertj.core.api.Assertions.assertThat; @NodeProcessorTest(OrderedListNodeProcessor.class) @@ -80,6 +78,6 @@ private String process(String content) { nodeProcessor.process(node); - return clean(sinkWriter.toString()); + return removeLineBreaks(sinkWriter.toString()); } } diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/SectionNodeProcessorTest.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/SectionNodeProcessorTest.java index 89afada7..17ba8753 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/SectionNodeProcessorTest.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/SectionNodeProcessorTest.java @@ -11,6 +11,9 @@ 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.div; +import static org.asciidoctor.maven.site.parser.processors.test.Html.p; +import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.removeLineBreaks; import static org.assertj.core.api.Assertions.assertThat; @NodeProcessorTest(SectionNodeProcessor.class) @@ -27,7 +30,7 @@ void should_convert_document_title() { String html = process(content, 0); assertThat(html) - .isEqualTo("

Document tile

"); + .isEqualTo(div("

Document tile

")); } @Test @@ -37,21 +40,16 @@ void should_convert_section_level_2() { String html = process(content, 1); assertThat(html) - .isEqualTo("
" + - "

First section title

" + - "

First section body

" + - "
" + - "

Second section title

" + - "

Second section body

" + - "
" + - "

Third section title

" + - "

Third section body

" + - "
" + - "
Fourth section title
" + - "

Fourth section body

" + - "
" + - "
Fifth section title
" + - "

Fifth section body

"); + .isEqualTo(div("

First section title

" + + p("First section body") + + div("

Second section title

" + + p("Second section body") + + div("

Third section title

" + + p("Third section body") + + div("
Fourth section title
" + + p("Fourth section body") + + div("
Fifth section title
" + + p("Fifth section body"))))))); } @Test @@ -61,18 +59,15 @@ void should_convert_section_level_3() { String html = process(content, 2); assertThat(html) - .isEqualTo("
" + + .isEqualTo(div( "

Second section title

" + - "

Second section body

" + - "
" + - "

Third section title

" + - "

Third section body

" + - "
" + - "
Fourth section title
" + - "

Fourth section body

" + - "
" + - "
Fifth section title
" + - "

Fifth section body

"); + p("Second section body") + + div("

Third section title

" + + p("Third section body") + + div("
Fourth section title
" + + "

Fourth section body

" + + div("
Fifth section title
" + + p("Fifth section body")))))); } @Test @@ -82,15 +77,13 @@ void should_convert_section_level_4() { String html = process(content, 3); assertThat(html) - .isEqualTo("
" + + .isEqualTo(div( "

Third section title

" + - "

Third section body

" + - "
" + - "
Fourth section title
" + - "

Fourth section body

" + - "
" + - "
Fifth section title
" + - "

Fifth section body

"); + p("Third section body") + + div("
Fourth section title
" + + p("Fourth section body") + + div("
Fifth section title
" + + p("Fifth section body"))))); } @Test @@ -100,12 +93,10 @@ void should_convert_section_level_5() { String html = process(content, 4); assertThat(html) - .isEqualTo("
" + - "
Fourth section title
" + - "

Fourth section body

" + - "
" + - "
Fifth section title
" + - "

Fifth section body

"); + .isEqualTo(div("
Fourth section title
" + + p("Fourth section body") + + div("
Fifth section title
" + + p("Fifth section body")))); } @Test @@ -115,9 +106,8 @@ void should_convert_section_level_6() { String html = process(content, 5); assertThat(html) - .isEqualTo("
" + - "
Fifth section title
" + - "

Fifth section body

"); + .isEqualTo(div("
Fifth section title
" + + p("Fifth section body"))); } @Test @@ -127,23 +117,17 @@ void should_convert_section_with_sectionNumbers() { .build(); String content = documentWithSections(); - // With numbering assertThat(process(content, 1, attributes)) - .isEqualTo("
" + - "

1. First section title

" + - "

First section body

" + - "
" + - "

1.1. Second section title

" + - "

Second section body

" + - "
" + - "

1.1.1. Third section title

" + - "

Third section body

" + - "
" + - "
Fourth section title
" + - "

Fourth section body

" + - "
" + - "
Fifth section title
" + - "

Fifth section body

"); + .isEqualTo(div("

1. First section title

" + + p("First section body") + + div("

1.1. Second section title

" + + p("Second section body") + + div("

1.1.1. Third section title

" + + p("Third section body") + + div("
Fourth section title
" + + p("Fourth section body") + + div("
Fifth section title
" + + p("Fifth section body"))))))); } @Test @@ -154,23 +138,59 @@ void should_convert_section_with_sectionNumbers_and_sectNumLevels() { .build(); String content = documentWithSections(); - // With numbering assertThat(process(content, 1, attributes)) - .isEqualTo("
" + - "

1. First section title

" + - "

First section body

" + - "
" + - "

1.1. Second section title

" + - "

Second section body

" + - "
" + - "

1.1.1. Third section title

" + - "

Third section body

" + - "
" + - "
1.1.1.1. Fourth section title
" + - "

Fourth section body

" + - "
" + - "
1.1.1.1.1. Fifth section title
" + - "

Fifth section body

"); + .isEqualTo(div("

1. First section title

" + + p("First section body") + + div("

1.1. Second section title

" + + p("Second section body") + + div("

1.1.1. Third section title

" + + p("Third section body") + + div("
1.1.1.1. Fourth section title
" + + p("Fourth section body") + + div("
1.1.1.1.1. Fifth section title
" + + p("Fifth section body"))))))); + } + + @Test + void should_convert_sections_with_appendices() { + String content = "= Document tile\n\n" + + "== Section title\n\nSection body\n\n" + + "[appendix]\n" + + "=== Appendix title 1\n\nSection body\n\n" + + "[appendix]\n" + + "=== Appendix title 2\n\nSection body\n\n"; + + String html = process(content, 1); + + assertThat(html) + .isEqualTo(div("

Section title

" + + p("Section body") + + div("

Appendix A: Appendix title 1

" + + p("Section body")) + + div("

Appendix B: Appendix title 2

" + + p("Section body")))); + } + + @Test + void should_convert_sections_with_appendices_and_custom_captions() { + String content = "= Document tile\n" + + ":appendix-caption: App.\n" + + ":appendix-number: C\n\n" + + "== Section title\n\nSection body\n\n" + + "[appendix]\n" + + "=== Appendix title 1\n\nSection body\n\n" + + "[appendix]\n" + + "=== Appendix title 2\n\nSection body\n\n"; + + String html = process(content, 1); + + assertThat(html) + .isEqualTo(div("

Section title

" + + p("Section body") + + div("

App. D: Appendix title 1

" + + p("Section body")) + + div("

App. E: Appendix title 2

" + + p("Section body")))); } private String documentWithSections() { @@ -202,10 +222,6 @@ private String process(String content, int level, Attributes attributes) { return removeLineBreaks(sinkWriter.toString().trim()); } - private static String removeLineBreaks(String html) { - return html.replaceAll("(\r)?\n", ""); - } - private void reset(StringWriter sinkWriter) { final StringBuffer buffer = sinkWriter.getBuffer(); buffer.setLength(0); 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 4e2de710..662bd653 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 @@ -14,12 +14,9 @@ import org.junit.jupiter.api.Test; import static java.util.Collections.emptyList; -import static org.asciidoctor.maven.site.parser.processors.TableNodeProcessorTest.DocumentBuilder.CaptionOptions.disableLabelForTable; -import static org.asciidoctor.maven.site.parser.processors.TableNodeProcessorTest.DocumentBuilder.CaptionOptions.disableLabelsGlobally; -import static org.asciidoctor.maven.site.parser.processors.TableNodeProcessorTest.DocumentBuilder.CaptionOptions.noCaption; -import static org.asciidoctor.maven.site.parser.processors.TableNodeProcessorTest.DocumentBuilder.CaptionOptions.simpleCaption; +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.StringTestUtils.clean; +import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.removeLineBreaks; import static org.assertj.core.api.Assertions.assertThat; /** @@ -32,10 +29,28 @@ @NodeProcessorTest(TableNodeProcessor.class) class TableNodeProcessorTest { + private static final String CAPTION_STYLE = "color: #7a2518; margin-bottom: .25em; text-align: left"; + private Asciidoctor asciidoctor; private NodeProcessor nodeProcessor; private StringWriter sinkWriter; + @Test + void should_convert_empty_table() { + String content = "= Document tile\n" + + "\n" + + "\n" + + "== Section\n" + + "|===\n" + + "|==="; + + String html = process(content); + + // Header for now is just first row with class=a + assertThat(html) + .isEmpty(); + } + @Test void should_convert_table_with_header() { String content = documentWithTable(true, noCaption, emptyList()); @@ -44,16 +59,16 @@ void should_convert_table_with_header() { // Header for now is just first row with class=a assertThat(html) - .isEqualTo("" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "
NameLanguage
JRubyJava
RubiniusRuby
"); + .isEqualTo("" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
NameLanguage
JRubyJava
RubiniusRuby
"); } @Test @@ -63,13 +78,13 @@ void should_convert_table_without_header() { String html = process(content); assertThat(html) - .isEqualTo(clean("" + - "" + - "" + - "" + - "" + - "" + - "
JRubyJava
RubiniusRuby
")); + .isEqualTo(removeLineBreaks("" + + "" + + "" + + "" + + "" + + "" + + "
JRubyJava
RubiniusRuby
")); } @Test @@ -79,23 +94,23 @@ void should_convert_table_with_text_markup() { String html = process(content); assertThat(html) - .isEqualTo(expectedTableWithoutCaption()); + .isEqualTo(expectedTableWithoutCaption()); } @Test - void should_convert_table_with_label_and_title() { + void should_convert_table_with_caption_and_title() { String content = documentWithTable(false, simpleCaption, emptyList()); String html = process(content); assertThat(html) - .isEqualTo("" + - "" + - "" + - "" + - "" + - "" + - "
Table 1. Table caption…​or title
JRubyJava
RubiniusRuby
"); + .isEqualTo("" + + "" + + "" + + "" + + "" + + "" + + "
Table 1. Table caption…​or title
JRubyJava
RubiniusRuby
"); } @Test @@ -105,8 +120,8 @@ void should_convert_table_with_label_disabled() { String html = process(content); assertThat(html) - .startsWith(expectedNoLabelBeginning()) - .isEqualTo(expectedTableWithoutLabel()); + .startsWith(expectedNoLabelBeginning()) + .isEqualTo(expectedTableWithoutLabel()); } @Test @@ -116,44 +131,46 @@ void should_convert_table_with_labels_disabled_globally() { String html = process(content); assertThat(html) - .startsWith(expectedNoLabelBeginning()) - .isEqualTo(expectedTableWithoutLabel()); + .startsWith(expectedNoLabelBeginning()) + .isEqualTo(expectedTableWithoutLabel()); } private static String expectedNoLabelBeginning() { - return ""; + return "
Table caption…​or title
" + + ""; } private static String expectedTableWithoutLabel() { - return "
Table caption…​or title
" + - "" + - "" + - "" + - "" + - "" + - "
Table caption…​or title
JRubyJava
RubiniusRuby
"; + return "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
Table caption…​or title
JRubyJava
RubiniusRuby
"; } private static String expectedTableWithoutCaption() { return "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "" + - "
JRubyJava
RubiniusRuby
OpalJavaScript
"; + "
JRubyJava
RubiniusRuby
OpalJavaScript
"; } static class DocumentBuilder { static class CaptionOptions { - final boolean include; - final boolean disableForTable; - final boolean disableGlobally; + final boolean includeTitle; + final boolean disableCaptionsForTable; + final boolean disableCaptionsGlobally; static final CaptionOptions noCaption = new CaptionOptions(false, false, false); static final CaptionOptions simpleCaption = new CaptionOptions(true, false, false); @@ -161,36 +178,37 @@ static class CaptionOptions { static final CaptionOptions disableLabelsGlobally = new CaptionOptions(true, false, true); private CaptionOptions(boolean include, boolean disableForTable, boolean disableGlobally) { - this.include = include; - this.disableForTable = disableForTable; - this.disableGlobally = disableGlobally; + this.includeTitle = include; + this.disableCaptionsForTable = disableForTable; + this.disableCaptionsGlobally = disableGlobally; } } - static String documentWithTable(boolean includeHeaderRow, CaptionOptions captionOptions, List additionalRow) { + static String documentWithTable(boolean includeTableHeader, CaptionOptions captionOptions, List additionalRow) { return "= Document tile\n" + - (captionOptions.disableGlobally ? ":table-caption!:\n" : "") + - "\n" + - "== Section\n" + - (captionOptions.disableForTable ? "[caption=]\n" : "") + - (captionOptions.include ? ".Table caption...or title\n" : "") + - "|===\n" + - (includeHeaderRow ? "|Name |Language\n\n" : "") + - "|JRuby |Java\n" + - "|Rubinius |Ruby\n" + - (!additionalRow.isEmpty() ? additionalRow.stream().collect(Collectors.joining("|", " |", "")) : "") + - "|==="; + (captionOptions.disableCaptionsGlobally ? ":table-caption!:\n" : "") + + "\n\n" + + "== Section\n" + + (captionOptions.disableCaptionsForTable ? "[caption=]\n" : "") + + (captionOptions.includeTitle ? ".Table caption...or title\n" : "") + + "|===\n" + + (includeTableHeader ? "|Name |Language\n\n" : "") + + "|JRuby |Java\n" + + "|Rubinius |Ruby\n" + + (!additionalRow.isEmpty() ? additionalRow.stream().collect(Collectors.joining("|", " |", "")) : "") + + "|==="; } } private String process(String content) { StructuralNode node = asciidoctor.load(content, Options.builder().build()) - .findBy(Collections.singletonMap("context", ":table")) - .get(0); + .findBy(Collections.singletonMap("context", ":table")) + .get(0); nodeProcessor.process(node); - return clean(sinkWriter.toString()); + String string = sinkWriter.toString(); + return removeLineBreaks(string); } } 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 26d790e3..d7650432 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 @@ -11,7 +11,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.StringTestUtils.clean; +import static org.asciidoctor.maven.site.parser.processors.test.StringTestUtils.removeLineBreaks; import static org.assertj.core.api.Assertions.assertThat; @NodeProcessorTest(UnorderedListNodeProcessor.class) @@ -83,6 +83,6 @@ private String process(String content) { nodeProcessor.process(node); - return clean(sinkWriter.toString()); + return removeLineBreaks(sinkWriter.toString()); } } 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 43061dc5..0c062062 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 @@ -16,6 +16,10 @@ public static String monospace(String text) { return htmlElement("code", text); } + public static String div(String text) { + return htmlElement("div", text); + } + public static String ul(String... elements) { return htmlElement("ul", String.join("", elements)); } @@ -36,6 +40,10 @@ public static String dd(String text) { return htmlElement("dd", text); } + public static String p(String text) { + return htmlElement("p", text); + } + static String htmlElement(String element, String text) { return htmlElement(element, null, text); } diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/StringTestUtils.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/StringTestUtils.java index a699d2bb..163997fe 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/StringTestUtils.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/StringTestUtils.java @@ -7,9 +7,8 @@ public class StringTestUtils { * * @param value string to clean */ - public static String clean(String value) { - return value.replaceAll("\r\n", "") - .replaceAll("\n", "") + public static String removeLineBreaks(String value) { + return value.replaceAll("(\r)?\n", "") .trim(); } } diff --git a/docs/modules/site-integration/pages/parser-module-setup-and-configuration.adoc b/docs/modules/site-integration/pages/parser-module-setup-and-configuration.adoc index 91c05ed1..5b35e589 100644 --- a/docs/modules/site-integration/pages/parser-module-setup-and-configuration.adoc +++ b/docs/modules/site-integration/pages/parser-module-setup-and-configuration.adoc @@ -189,6 +189,8 @@ NOTE: Unlike in Asciidoctor lists, descriptions are not surrounded by `

` and ** Support for numbered lines with `linenums` ** Support for AsciiDoc titles +* Examples + * Literal blocks * Quotes