diff --git a/asciidoctor-converter-doxia-module/pom.xml b/asciidoctor-converter-doxia-module/pom.xml index 14fd010e..6be7a007 100644 --- a/asciidoctor-converter-doxia-module/pom.xml +++ b/asciidoctor-converter-doxia-module/pom.xml @@ -46,7 +46,7 @@ org.apache.maven.doxia doxia-site-renderer - 1.11.1 + ${doxia.version} test diff --git a/asciidoctor-converter-doxia-module/src/it/maven-site-plugin/pom.xml b/asciidoctor-converter-doxia-module/src/it/maven-site-plugin/pom.xml index df89a4b6..f02ac1c5 100644 --- a/asciidoctor-converter-doxia-module/src/it/maven-site-plugin/pom.xml +++ b/asciidoctor-converter-doxia-module/src/it/maven-site-plugin/pom.xml @@ -22,14 +22,14 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 3.4.5 + 3.5.0 org.apache.maven.plugins maven-site-plugin - 3.12.1 + 4.0.0-M13 ${project.basedir}/src/site/asciidoc diff --git a/asciidoctor-converter-doxia-module/src/it/maven-site-plugin/src/site/site.xml b/asciidoctor-converter-doxia-module/src/it/maven-site-plugin/src/site/site.xml index 71ea0778..d23bc776 100644 --- a/asciidoctor-converter-doxia-module/src/it/maven-site-plugin/src/site/site.xml +++ b/asciidoctor-converter-doxia-module/src/it/maven-site-plugin/src/site/site.xml @@ -14,6 +14,6 @@ org.apache.maven.skins maven-fluido-skin - 1.12.0 + 2.0.0-M8 diff --git a/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParser.java b/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParser.java index d2f8af37..7203b700 100644 --- a/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParser.java +++ b/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParser.java @@ -5,7 +5,6 @@ import java.io.File; import java.io.IOException; import java.io.Reader; -import java.util.logging.Logger; import org.apache.maven.doxia.parser.AbstractTextParser; import org.apache.maven.doxia.parser.ParseException; @@ -24,6 +23,8 @@ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This class is used by the Doxia framework @@ -37,6 +38,8 @@ @Component(role = Parser.class, hint = AsciidoctorConverterDoxiaParser.ROLE_HINT) public class AsciidoctorConverterDoxiaParser extends AbstractTextParser { + private final Logger logger = LoggerFactory.getLogger(AsciidoctorConverterDoxiaParser.class); + @Inject protected Provider mavenProjectProvider; @@ -56,7 +59,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept source = ""; } } catch (IOException ex) { - getLog().error("Could not read AsciiDoc source: " + ex.getLocalizedMessage()); + logger.error("Could not read AsciiDoc source: " + ex.getLocalizedMessage()); return; } @@ -84,7 +87,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept try { // process log messages according to mojo configuration - new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> getLog().error(errorMessage)) + new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> logger.error(errorMessage)) .processLogRecords(memoryLogHandler); } catch (Exception exception) { throw new ParseException(exception.getMessage(), exception); @@ -100,10 +103,10 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept private MemoryLogHandler asciidoctorLoggingSetup(Asciidoctor asciidoctor, LogHandler logHandler, File siteDirectory) { final MemoryLogHandler memoryLogHandler = new MemoryLogHandler(logHandler.getOutputToConsole(), - logRecord -> getLog().info(LogRecordFormatter.format(logRecord, siteDirectory))); + logRecord -> logger.info(LogRecordFormatter.format(logRecord, siteDirectory))); asciidoctor.registerLogHandler(memoryLogHandler); // disable default console output of AsciidoctorJ - Logger.getLogger("asciidoctor").setUseParentHandlers(false); + java.util.logging.Logger.getLogger("asciidoctor").setUseParentHandlers(false); return memoryLogHandler; } @@ -145,7 +148,7 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) { try { asciidoctor.requireLibrary(require); } catch (Exception ex) { - getLog().error(ex.getLocalizedMessage()); + logger.error(ex.getLocalizedMessage()); } } } diff --git a/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParserModule.java b/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParserModule.java index cb39ac9a..ae83e2fb 100644 --- a/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParserModule.java +++ b/asciidoctor-converter-doxia-module/src/main/java/org/asciidoctor/maven/site/AsciidoctorConverterDoxiaParserModule.java @@ -1,8 +1,8 @@ package org.asciidoctor.maven.site; +import javax.inject.Named; + import org.apache.maven.doxia.parser.module.AbstractParserModule; -import org.apache.maven.doxia.parser.module.ParserModule; -import org.codehaus.plexus.component.annotations.Component; /** * This class is the entry point for integration with the Maven Site Plugin @@ -12,7 +12,7 @@ * * @author jdlee */ -@Component(role = ParserModule.class, hint = AsciidoctorConverterDoxiaParser.ROLE_HINT) +@Named(AsciidoctorConverterDoxiaParser.ROLE_HINT) public class AsciidoctorConverterDoxiaParserModule extends AbstractParserModule { /** diff --git a/asciidoctor-parser-doxia-module/pom.xml b/asciidoctor-parser-doxia-module/pom.xml index d9456aab..d069e3f6 100644 --- a/asciidoctor-parser-doxia-module/pom.xml +++ b/asciidoctor-parser-doxia-module/pom.xml @@ -46,7 +46,7 @@ org.apache.maven.doxia doxia-site-renderer - 1.11.1 + ${doxia.version} test diff --git a/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/pom.xml b/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/pom.xml index 2ab11cb7..025e5409 100644 --- a/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/pom.xml +++ b/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/pom.xml @@ -17,13 +17,13 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 3.4.5 + 3.5.0 org.apache.maven.plugins maven-site-plugin - 3.12.1 + 4.0.0-M13 ${project.basedir}/src/site/asciidoc diff --git a/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/src/site/site.xml b/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/src/site/site.xml index 9ae5a719..e339f0d2 100644 --- a/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/src/site/site.xml +++ b/asciidoctor-parser-doxia-module/src/it/maven-site-plugin/src/site/site.xml @@ -9,9 +9,10 @@ ${reports} + org.apache.maven.skins maven-fluido-skin - 1.12.0 + 2.0.0-M8 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 096af4c7..5db89be3 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 @@ -153,13 +153,13 @@ class HtmlAsserter { void containsSectionTitle(String value, int level) { def found = -1 - def id = value.replaceAll(" ", "_") + def id = value.toLowerCase().replaceAll(" ", "_") if (level == 2) { - found = find("

$value

") + found = find("

$value

") } else if (level == 3) { - found = find("

$value

") + found = find("

$value

") } else if (level == 4) { - found = find("

$value

") + found = find("

$value

") } assertFound("Section Title (level:$level)", value, found) } @@ -185,7 +185,7 @@ class HtmlAsserter { } void containsOrderedList(String... values) { - def found = find("
  1. ${values.join('
  2. ')}
") + def found = find("
  1. ${values.join('
  2. ')}
") assertFound("Ordered list", values.join(','), found) } diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParser.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParser.java index ebe72db0..3a7da6cf 100644 --- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParser.java +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParser.java @@ -1,15 +1,14 @@ package org.asciidoctor.maven.site.parser; import javax.inject.Inject; +import javax.inject.Named; import javax.inject.Provider; import java.io.File; import java.io.IOException; import java.io.Reader; -import java.util.logging.Logger; import org.apache.maven.doxia.parser.AbstractTextParser; import org.apache.maven.doxia.parser.ParseException; -import org.apache.maven.doxia.parser.Parser; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.project.MavenProject; import org.asciidoctor.Asciidoctor; @@ -23,14 +22,15 @@ import org.asciidoctor.maven.log.LogRecordFormatter; import org.asciidoctor.maven.log.LogRecordsProcessors; import org.asciidoctor.maven.log.MemoryLogHandler; -import org.asciidoctor.maven.site.HeaderMetadata; import org.asciidoctor.maven.site.HeadParser; +import org.asciidoctor.maven.site.HeaderMetadata; import org.asciidoctor.maven.site.SiteConversionConfiguration; import org.asciidoctor.maven.site.SiteConversionConfigurationParser; import org.asciidoctor.maven.site.SiteLogHandlerDeserializer; -import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.asciidoctor.maven.commons.StringUtils.isNotBlank; @@ -42,9 +42,11 @@ * @author abelsromero * @since 3.0.0 */ -@Component(role = Parser.class, hint = AsciidoctorAstDoxiaParser.ROLE_HINT) +@Named(AsciidoctorAstDoxiaParser.ROLE_HINT) public class AsciidoctorAstDoxiaParser extends AbstractTextParser { + private final Logger logger = LoggerFactory.getLogger(AsciidoctorAstDoxiaParser.class); + @Inject protected Provider mavenProjectProvider; @@ -64,7 +66,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept source = ""; } } catch (IOException ex) { - getLog().error("Could not read AsciiDoc source: " + ex.getLocalizedMessage()); + logger.error("Could not read AsciiDoc source: " + ex.getLocalizedMessage()); return; } @@ -79,7 +81,7 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept final Asciidoctor asciidoctor = Asciidoctor.Factory.create(); SiteConversionConfiguration conversionConfig = new SiteConversionConfigurationParser(project) - .processAsciiDocConfig(siteConfig, defaultOptions(siteDirectory), defaultAttributes()); + .processAsciiDocConfig(siteConfig, defaultOptions(siteDirectory), defaultAttributes()); for (String require : conversionConfig.getRequires()) { requireLibrary(asciidoctor, require); } @@ -88,14 +90,14 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept final MemoryLogHandler memoryLogHandler = asciidoctorLoggingSetup(asciidoctor, logHandler, siteDirectory); if (isNotBlank(reference)) - getLog().debug("Document loaded: " + reference); + logger.debug("Document loaded: " + reference); Document document = asciidoctor.load(source, conversionConfig.getOptions()); try { // process log messages according to mojo configuration - new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> getLog().error(errorMessage)) - .processLogRecords(memoryLogHandler); + new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> logger.error(errorMessage)) + .processLogRecords(memoryLogHandler); } catch (Exception exception) { throw new ParseException(exception.getMessage(), exception); @@ -116,10 +118,10 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept private MemoryLogHandler asciidoctorLoggingSetup(Asciidoctor asciidoctor, LogHandler logHandler, File siteDirectory) { final MemoryLogHandler memoryLogHandler = new MemoryLogHandler(logHandler.getOutputToConsole(), - logRecord -> getLog().info(LogRecordFormatter.format(logRecord, siteDirectory))); + logRecord -> logger.info(LogRecordFormatter.format(logRecord, siteDirectory))); asciidoctor.registerLogHandler(memoryLogHandler); // disable default console output of AsciidoctorJ - Logger.getLogger("asciidoctor").setUseParentHandlers(false); + java.util.logging.Logger.getLogger("asciidoctor").setUseParentHandlers(false); return memoryLogHandler; } @@ -145,15 +147,15 @@ protected File resolveSiteDirectory(MavenProject project, Xpp3Dom siteConfig) { protected OptionsBuilder defaultOptions(File siteDirectory) { return Options.builder() - .backend("xhtml") - .safe(SafeMode.UNSAFE) - .baseDir(new File(siteDirectory, ROLE_HINT)); + .backend("xhtml") + .safe(SafeMode.UNSAFE) + .baseDir(new File(siteDirectory, ROLE_HINT)); } protected AttributesBuilder defaultAttributes() { return Attributes.builder() - .attribute("idprefix", "@") - .attribute("showtitle", "@"); + .attribute("idprefix", "@") + .attribute("showtitle", "@"); } private void requireLibrary(Asciidoctor asciidoctor, String require) { @@ -161,7 +163,7 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) { try { asciidoctor.requireLibrary(require); } catch (Exception ex) { - getLog().error(ex.getLocalizedMessage()); + logger.error(ex.getLocalizedMessage()); } } } diff --git a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParserModule.java b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParserModule.java index 0ecd381d..1d1a7292 100644 --- a/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParserModule.java +++ b/asciidoctor-parser-doxia-module/src/main/java/org/asciidoctor/maven/site/parser/AsciidoctorAstDoxiaParserModule.java @@ -1,8 +1,8 @@ package org.asciidoctor.maven.site.parser; +import javax.inject.Named; + import org.apache.maven.doxia.parser.module.AbstractParserModule; -import org.apache.maven.doxia.parser.module.ParserModule; -import org.codehaus.plexus.component.annotations.Component; /** * This class is the entry point for integration with the Maven Site Plugin @@ -13,7 +13,7 @@ * @author abelsromero * @since 3.0.0 */ -@Component(role = ParserModule.class, hint = AsciidoctorAstDoxiaParser.ROLE_HINT) +@Named(AsciidoctorAstDoxiaParser.ROLE_HINT) public class AsciidoctorAstDoxiaParserModule extends AbstractParserModule { /** 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 c637fbb1..5fd4a0f2 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 @@ -5,6 +5,8 @@ import org.asciidoctor.ast.StructuralNode; import org.asciidoctor.jruby.ast.impl.SectionImpl; import org.asciidoctor.maven.site.parser.NodeProcessor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Section title processor. @@ -15,6 +17,8 @@ */ public class SectionNodeProcessor extends AbstractSinkNodeProcessor implements NodeProcessor { + private final Logger logger = LoggerFactory.getLogger(SectionNodeProcessor.class); + /** * Constructor. * @@ -36,45 +40,33 @@ public void process(StructuralNode node) { private void sectionTitle(Sink sink, int level, String title, Section node) { final String formattedTitle = formatTitle(title, node); - switch (level) { - case 0: - // Kept for completeness, real document title is treated in - // DocumentNodeProcessor - sink.rawText("

" + formattedTitle + "

"); - break; - case 1: - sink.sectionTitle1(); - sink.text(formattedTitle); - sink.sectionTitle1_(); - break; - case 2: - sink.sectionTitle2(); - sink.text(formattedTitle); - sink.sectionTitle2_(); - break; - case 3: - sink.sectionTitle3(); - sink.text(formattedTitle); - sink.sectionTitle3_(); - break; - case 4: - sink.sectionTitle4(); - sink.text(formattedTitle); - sink.sectionTitle4_(); - break; - case 5: - sink.sectionTitle5(); - sink.text(formattedTitle); - sink.sectionTitle5_(); - break; - case 6: - sink.sectionTitle6(); - sink.text(formattedTitle); - sink.sectionTitle6_(); - break; + + if (level == 0) { + // Kept for completeness, real document title is treated in + // DocumentNodeProcessor + sink.sectionTitle1(); + sink.text(formattedTitle); + sink.sectionTitle1_(); + } else { + // Asciidoctor supports up o 6 levels, but Xhtml5BaseSink only up to 5 + int siteLevel = level + 1; + if (level >= 5) { + // TODO generate code manually or request change + logger.warn("Site module does not support level 6 sections. Re-writing as 5"); + siteLevel = 5; + } + sink.sectionTitle(siteLevel, null); + anchor(sink, node); + sink.text(formattedTitle); + sink.sectionTitle_(siteLevel); } } + private void anchor(Sink sink, Section node) { + sink.anchor(node.getId()); + sink.anchor_(); + } + private String formatTitle(String title, Section node) { final Boolean numbered = node.isNumbered(); final Long sectnumlevels = getSectnumlevels(node); 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 6b1ef90e..ce33c1f4 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; @@ -44,39 +48,39 @@ void should_convert_html_without_any_configuration() throws FileNotFoundExceptio String result = parse(parser, srcAsciidoc); 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
require 'asciidoctor'
"); + .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
" + + "
require 'asciidoctor'
"); } @Test void should_convert_html_with_an_attribute() throws ParseException { final String source = "= Document Title\n\n" + - "== Section A\n\n" + - "My attribute value is {custom-attribute}.\n"; + "== Section A\n\n" + + "My attribute value is {custom-attribute}.\n"; AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser( - "\n" + - " \n" + - " \n" + - " a_value\n" + - " \n" + - " \n" + - ""); + "\n" + + " \n" + + " \n" + + " a_value\n" + + " \n" + + " \n" + + ""); String result = parse(parser, source); assertThat(result) - .contains("

My attribute value is a_value.

"); + .contains("

My attribute value is a_value.

"); } @Test @@ -84,21 +88,21 @@ void should_process_empty_selfclosing_XML_attributes() throws ParseException { final String source = sectionsSample(); AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser( - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""); + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""); String result = parse(parser, source); assertThat(result) - .contains("1. Section A") - .contains("1.1. Section A Subsection") - .contains("2. Section B") - .contains("2.1. Section B Subsection"); + .contains("1. Section A") + .contains("1.1. Section A Subsection") + .contains("2. Section B") + .contains("2.1. Section B Subsection"); } @Test @@ -106,22 +110,22 @@ void should_process_config_with_sectnumlevels() throws ParseException { final String source = sectionsSample(); AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser( - "\n" + - " \n" + - " \n" + - " \n" + - " 1\n" + - " \n" + - " \n" + - ""); + "\n" + + " \n" + + " \n" + + " \n" + + " 1\n" + + " \n" + + " \n" + + ""); String result = parse(parser, source); assertThat(result) - .contains("1. Section A") - .contains("Section A Subsection") - .contains("2. Section B") - .contains("Section B Subsection"); + .contains("1. Section A") + .contains("Section A Subsection") + .contains("2. Section B") + .contains("Section B Subsection"); } @Test @@ -129,58 +133,58 @@ void should_process_empty_value_XML_attributes() throws ParseException { final String source = sectionsSample(); AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser( - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""); + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""); String result = parse(parser, source); assertThat(result) - .contains("1. Section A") - .contains("1.1. Section A Subsection") - .contains("2. Section B") - .contains("2.1. Section B Subsection"); + .contains("1. Section A") + .contains("1.1. Section A Subsection") + .contains("2. Section B") + .contains("2.1. Section B Subsection"); } private static String sectionsSample() { return "= Document Title\n\n" + - "== Section A\n\n" + - "Section A paragraph.\n\n" + - "=== Section A Subsection\n\n" + - "Section A 'subsection' paragraph.\n\n" + - "== Section B\n\n" + - "*Section B* paragraph.\n\n" + - "=== Section B Subsection\n\n" + - "Section B 'subsection' paragraph.\n\n"; + "== Section A\n\n" + + "Section A paragraph.\n\n" + + "=== Section A Subsection\n\n" + + "Section A 'subsection' paragraph.\n\n" + + "== Section B\n\n" + + "*Section B* paragraph.\n\n" + + "=== Section B Subsection\n\n" + + "Section B 'subsection' paragraph.\n\n"; } @Test void should_fail_when_logHandler_failIf_is_WARNING() { final String source = "= My Document\n\n" + - "include::unexistingdoc.adoc[]\n\n" + - "include::unexistingdoc.adoc[]"; + "include::unexistingdoc.adoc[]\n\n" + + "include::unexistingdoc.adoc[]"; AsciidoctorAstDoxiaParser parser = mockAsciidoctorDoxiaParser( - "\n" + - " \n" + - " \n" + - " \n" + - " WARN\n" + - " \n" + - " \n" + - " \n" + - ""); + "\n" + + " \n" + + " \n" + + " \n" + + " WARN\n" + + " \n" + + " \n" + + " \n" + + ""); Throwable throwable = catchThrowable(() -> parser.parse(new StringReader(source), sink)); // 'issues with WARN and ERROR are returned' assertThat(throwable) - .isInstanceOf(ParseException.class) - .hasMessageContaining("Found 2 issue(s) of severity WARN or higher during conversion"); + .isInstanceOf(ParseException.class) + .hasMessageContaining("Found 2 issue(s) of severity WARN or higher during conversion"); } private String parse(AbstractTextParser parser, File source) throws FileNotFoundException, ParseException { @@ -198,9 +202,9 @@ static class TestMocks { static javax.inject.Provider createMavenProjectMock(String configuration) { MavenProject mockProject = Mockito.mock(MavenProject.class); when(mockProject.getBasedir()) - .thenReturn(new File(".")); + .thenReturn(new File(".")); when(mockProject.getGoalConfiguration(anyString(), anyString(), anyString(), anyString())) - .thenReturn(configuration != null ? Xpp3DomBuilder.build(new StringReader(configuration)) : null); + .thenReturn(configuration != null ? Xpp3DomBuilder.build(new StringReader(configuration)) : null); return () -> mockProject; } 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 e29d9d2a..d0d83167 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 @@ -1,5 +1,9 @@ package org.asciidoctor.maven.site.parser.processors; +import java.io.StringWriter; +import java.util.Arrays; +import java.util.Collections; + import org.apache.maven.doxia.sink.Sink; import org.asciidoctor.Asciidoctor; import org.asciidoctor.Options; @@ -9,10 +13,6 @@ 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.assertj.core.api.Assertions.assertThat; @@ -39,9 +39,9 @@ void should_convert_simple_list() { String html = process(content); assertThat(html) - .isEqualTo("
    " + - "
  1. ordered item 1
  2. " + - "
  3. ordered item 2
"); + .isEqualTo("
    " + + "
  1. ordered item 1
  2. " + + "
  3. ordered item 2
"); } @Test @@ -51,40 +51,40 @@ void should_convert_nested_list() { String html = process(content); assertThat(html) - .isEqualTo("
    " + - "
  1. ordered item 1" + - "
      " + - "
    1. ordered item 1 1
  2. " + - "
  3. ordered item 1 2
  4. " + - "
  5. ordered item 2" + - "
      " + - "
    1. ordered item 2 1" + - "
        " + - "
      1. ordered item 2 1 1
"); + .isEqualTo("
    " + + "
  1. ordered item 1" + + "
      " + + "
    1. ordered item 1 1
  2. " + + "
  3. ordered item 1 2
  4. " + + "
  5. ordered item 2" + + "
      " + + "
    1. ordered item 2 1" + + "
        " + + "
      1. ordered item 2 1 1
"); } private static String buildDocumentWithSimpleList() { return "= Document tile\n\n" - + "== Section\n\n" - + ". ordered item 1\n" - + ". ordered item 2\n"; + + "== Section\n\n" + + ". ordered item 1\n" + + ". ordered item 2\n"; } private static String buildDocumentWithNestedLists() { return "= Document tile\n\n" - + "== Section\n\n" - + ". ordered item 1\n" - + ".. ordered item 1 1\n" - + ". ordered item 1 2\n" - + ". ordered item 2\n" - + ".. ordered item 2 1\n" - + "... ordered item 2 1 1\n"; + + "== Section\n\n" + + ". ordered item 1\n" + + ".. ordered item 1 1\n" + + ". ordered item 1 2\n" + + ". ordered item 2\n" + + ".. ordered item 2 1\n" + + "... ordered item 2 1 1\n"; } private String process(String content) { StructuralNode node = asciidoctor.load(content, Options.builder().build()) - .findBy(Collections.singletonMap("context", ":olist")) - .get(0); + .findBy(Collections.singletonMap("context", ":olist")) + .get(0); nodeProcessor.process(node); 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 69fb9672..c1072ca7 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 @@ -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.Attributes; import org.asciidoctor.Options; @@ -8,9 +11,6 @@ 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.assertj.core.api.Assertions.assertThat; @NodeProcessorTest(SectionNodeProcessor.class) @@ -28,7 +28,7 @@ void should_convert_document_title() { String html = process(content, 0); assertThat(html) - .isEqualTo("

Document tile

"); + .isEqualTo("

Document tile

"); } @Test @@ -38,7 +38,7 @@ void should_convert_section_level_2() { String html = process(content, 1); assertThat(html) - .isEqualTo("

First section title

"); + .isEqualTo("

First section title

"); } @Test @@ -48,7 +48,7 @@ void should_convert_section_level_3() { String html = process(content, 2); assertThat(html) - .isEqualTo("

Second section title

"); + .isEqualTo("

Second section title

"); } @Test @@ -58,7 +58,7 @@ void should_convert_section_level_4() { String html = process(content, 3); assertThat(html) - .isEqualTo("

Third section title

"); + .isEqualTo("

Third section title

"); } @Test @@ -68,7 +68,7 @@ void should_convert_section_level_5() { String html = process(content, 4); assertThat(html) - .isEqualTo("
Fourth section title
"); + .isEqualTo("
Fourth section title
"); } @Test @@ -78,59 +78,72 @@ void should_convert_section_level_6() { String html = process(content, 5); assertThat(html) - .isEqualTo("
Fifth section title
"); + .isEqualTo("
Fifth section title
"); } @Test void should_convert_section_with_sectionNumbers() { Attributes attributes = Attributes.builder() - .sectionNumbers(true) - .build(); + .sectionNumbers(true) + .build(); String content = documentWithSections(); // With numbering assertThat(process(content, 1, attributes)) - .isEqualTo("

1. First section title

"); + .isEqualTo("

1. First section title

"); assertThat(process(content, 2, attributes)) - .isEqualTo("

1.1. Second section title

"); + .isEqualTo("

1.1. Second section title

"); assertThat(process(content, 3, attributes)) - .isEqualTo("

1.1.1. Third section title

"); + .isEqualTo("

1.1.1. Third section title

"); // Without numbering by default assertThat(process(content, 4, attributes)) - .isEqualTo("
Fourth section title
"); + .isEqualTo("
Fourth section title
"); assertThat(process(content, 5, attributes)) - .isEqualTo("
Fifth section title
"); + .isEqualTo("
Fifth section title
"); } @Test void should_convert_section_with_sectionNumbers_and_sectNumLevels() { Attributes attributes = Attributes.builder() - .sectionNumbers(true) - .sectNumLevels(5) - .build(); + .sectionNumbers(true) + .sectNumLevels(5) + .build(); String content = documentWithSections(); // With numbering assertThat(process(content, 1, attributes)) - .isEqualTo("

1. First section title

"); + .isEqualTo("

1. First section title

"); assertThat(process(content, 2, attributes)) - .isEqualTo("

1.1. Second section title

"); + .isEqualTo("

1.1. Second section title

"); assertThat(process(content, 3, attributes)) - .isEqualTo("

1.1.1. Third section title

"); + .isEqualTo("

1.1.1. Third section title

"); assertThat(process(content, 4, attributes)) - .isEqualTo("
1.1.1.1. Fourth section title
"); + .isEqualTo("
1.1.1.1. Fourth section title
"); assertThat(process(content, 5, attributes)) - .isEqualTo("
1.1.1.1.1. Fifth section title
"); + .isEqualTo("
1.1.1.1.1. Fifth section title
"); + } + + @Test + void should_apply_id_prefix() { + Attributes attributes = Attributes.builder() + .attribute("idprefix", "my_") + .build(); + String content = documentWithSections(); + + String html = process(content, 1, attributes); + + assertThat(html) + .isEqualTo("

First section title

"); } private String documentWithSections() { return "= Document tile\n\n" - + "== First section title\n\nFirst section body\n\n" - + "=== Second section title\n\nSecond section body\n\n" - + "==== Third section title\n\nThird section body\n\n" - + "===== Fourth section title\n\nFourth section body\n\n" - + "====== Fifth section title\n\nFifth section body\n\n"; + + "== First section title\n\nFirst section body\n\n" + + "=== Second section title\n\nSecond section body\n\n" + + "==== Third section title\n\nThird section body\n\n" + + "===== Fourth section title\n\nFourth section body\n\n" + + "====== Fifth section title\n\nFifth section body\n\n"; } private String process(String content, int level) { @@ -139,11 +152,11 @@ private String process(String content, int level) { private String process(String content, int level, Attributes attributes) { StructuralNode node = asciidoctor.load(content, Options.builder().attributes(attributes).build()) - .findBy(Collections.singletonMap("context", ":section")) - .stream() - .filter(n -> n.getLevel() == level) - .findFirst() - .get(); + .findBy(Collections.singletonMap("context", ":section")) + .stream() + .filter(n -> n.getLevel() == level) + .findFirst() + .get(); reset(sinkWriter); nodeProcessor.process(node); 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 2221a989..26b9202e 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 @@ -45,16 +45,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 @@ -64,13 +64,13 @@ void should_convert_table_without_header() { String html = process(content); assertThat(html) - .isEqualTo(clean("" + - "" + - "" + - "" + - "" + - "" + - "
JRubyJava
RubiniusRuby
")); + .isEqualTo(clean("" + + "" + + "" + + "" + + "" + + "" + + "
JRubyJava
RubiniusRuby
")); } @Test @@ -80,7 +80,7 @@ void should_convert_table_with_text_markup() { String html = process(content); assertThat(html) - .isEqualTo(expectedTableWithoutCaption()); + .isEqualTo(expectedTableWithoutCaption()); } @Test @@ -90,14 +90,13 @@ void should_convert_table_with_label_and_title() { String html = process(content); assertThat(html) - .startsWith("") - .isEqualTo("
Table 1. Table caption…​or title
" + - "" + - "" + - "" + - "" + - "" + - "
Table 1. Table caption…​or title
JRubyJava
RubiniusRuby
"); + .isEqualTo("" + + "" + + "" + + "" + + "" + + "" + + "
Table 1. Table caption…​or title
JRubyJava
RubiniusRuby
"); } @Test @@ -107,8 +106,8 @@ void should_convert_table_with_label_disabled() { String html = process(content); assertThat(html) - .startsWith(expectedNoLabelBeginning()) - .isEqualTo(expectedTableWithoutLabel()); + .startsWith(expectedNoLabelBeginning()) + .isEqualTo(expectedTableWithoutLabel()); } @Test @@ -118,35 +117,35 @@ 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
"; + return "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
JRubyJava
RubiniusRuby
OpalJavaScript
"; } static class DocumentBuilder { @@ -172,24 +171,24 @@ private CaptionOptions(boolean include, boolean disableForTable, boolean disable static String documentWithTable(boolean includeHeaderRow, 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.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("|", " |", "")) : "") + + "|==="; } } 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); 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 68d54f8f..43061dc5 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 @@ -2,7 +2,7 @@ public class Html { - public static final String LIST_STYLE_TYPE_DECIMAL = "list-style-type: decimal"; + public static final String LIST_STYLE_TYPE_DECIMAL = "list-style-type: decimal;"; public static String strong(String text) { return htmlElement("strong", text); diff --git a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/TestNodeProcessorFactory.java b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/TestNodeProcessorFactory.java index 875e5404..d96e4445 100644 --- a/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/TestNodeProcessorFactory.java +++ b/asciidoctor-parser-doxia-module/src/test/java/org/asciidoctor/maven/site/parser/processors/test/TestNodeProcessorFactory.java @@ -5,7 +5,7 @@ import lombok.SneakyThrows; import org.apache.commons.lang3.tuple.Pair; import org.apache.maven.doxia.sink.Sink; -import org.apache.maven.doxia.siterenderer.RenderingContext; +import org.apache.maven.doxia.siterenderer.DocumentRenderingContext; import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink; import org.asciidoctor.maven.site.parser.NodeProcessor; import org.mockito.Mockito; @@ -20,6 +20,6 @@ public static Pair create(Class clazz) { } public static Sink createSink() { - return new SiteRendererSink(Mockito.mock(RenderingContext.class)); + return new SiteRendererSink(Mockito.mock(DocumentRenderingContext.class)); } } diff --git a/docs/modules/site-integration/pages/compatibility-matrix.adoc b/docs/modules/site-integration/pages/compatibility-matrix.adoc index 3d43d1d0..d0a42cb1 100644 --- a/docs/modules/site-integration/pages/compatibility-matrix.adoc +++ b/docs/modules/site-integration/pages/compatibility-matrix.adoc @@ -11,7 +11,7 @@ Since v3.x.x the Asciidoctor Maven Plugin has been split into independent compon |Asciidoctor Doxia Module | Maven Site Plugin | Supported |v3.x.x -|v3.1x.x +|v3.1x.x ~ v4.x.x |Yes |=== diff --git a/pom.xml b/pom.xml index ae616207..70b762a5 100644 --- a/pom.xml +++ b/pom.xml @@ -71,7 +71,10 @@ UTF-8 11 3.9.6 - 1.12.0 + + 2.0.0-M8 2.2.0 2.5.11 9.4.5.0