Skip to content

Commit

Permalink
Bump maven-site and doxia to latests
Browse files Browse the repository at this point in the history
* maven-site-plugin v4.0.0-M8
* doxia & fluido skin 2.0.0-M6
* Sections and tables updated
  • Loading branch information
abelsromero committed Dec 29, 2023
1 parent 3aff152 commit 346119b
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 93 deletions.
2 changes: 1 addition & 1 deletion asciidoctor-converter-doxia-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<url>https://github.com/asciidoctor/asciidoctor-maven-plugin</url>

<properties>
<doxia.version>2.0.0-M3</doxia.version>
<doxia.version>2.0.0-M6</doxia.version>
<maven.coveralls.plugin.version>4.3.0</maven.coveralls.plugin.version>
<plexus.component.metadata.version>2.1.1</plexus.component.metadata.version>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>4.0.0-M3</version>
<version>4.0.0-M8</version>
<configuration>
<asciidoc>
<baseDir>${project.basedir}/src/site/asciidoc</baseDir>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.11.1</version>
<version>2.0.0-M6</version>
</skin>
</project>
16 changes: 15 additions & 1 deletion asciidoctor-parser-doxia-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
<description>Asciidoctor Doxia Module based on Asciidoctor AST processing (for Maven Site integration)</description>

<properties>
<doxia.version>1.11.1</doxia.version>
<doxia.version>2.0.0-M6</doxia.version>
<maven.coveralls.plugin.version>4.3.0</maven.coveralls.plugin.version>
<plexus.component.metadata.version>2.1.1</plexus.component.metadata.version>
</properties>

Expand Down Expand Up @@ -78,6 +79,19 @@
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>${maven.coveralls.plugin.version}</version>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
</plugin>
</plugins>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.1.2</version>
<version>3.4.0</version>
</plugin>
<!-- tag::plugin-decl[] -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
<version>4.0.0-M8</version>
<configuration>
<asciidoc>
<baseDir>${project.basedir}/src/site/asciidoc</baseDir>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<skin>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.11.1</version>
<version>2.0.0-M6</version>
</skin>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,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("<h2><a name=\"$id\"></a>$value</h2>")
found = find("<h2><a id=\"$id\"></a>$value</h2>")
} else if (level == 3) {
found = find("<h3><a name=\"$id\"></a>$value</h3>")
found = find("<h3><a id=\"$id\"></a>$value</h3>")
} else if (level == 4) {
found = find("<h4><a name=\"$id\"></a>$value</h4>")
found = find("<h4><a id=\"$id\"></a>$value</h4>")
}
assertFound("Section Title (level:$level)", value, found)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
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 javax.inject.Inject;
import javax.inject.Provider;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.logging.Logger;

import static org.asciidoctor.maven.commons.StringUtils.isNotBlank;

Expand All @@ -37,6 +38,8 @@
@Component(role = Parser.class, hint = AsciidoctorAstDoxiaParser.ROLE_HINT)
public class AsciidoctorAstDoxiaParser extends AbstractTextParser {

private final Logger logger = LoggerFactory.getLogger(AsciidoctorAstDoxiaParser.class);

@Inject
protected Provider<MavenProject> mavenProjectProvider;

Expand All @@ -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;
}

Expand All @@ -81,13 +84,13 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept

sink.body();
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))
new LogRecordsProcessors(logHandler, siteDirectory, errorMessage -> logger.error(errorMessage))
.processLogRecords(memoryLogHandler);

} catch (Exception exception) {
Expand All @@ -101,11 +104,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)));
final MemoryLogHandler memoryLogHandler = new MemoryLogHandler(logHandler.getOutputToConsole(), 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;
}

Expand Down Expand Up @@ -147,7 +149,7 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) {
try {
asciidoctor.requireLibrary(require);
} catch (Exception ex) {
getLog().error(ex.getLocalizedMessage());
logger.error(ex.getLocalizedMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import org.asciidoctor.ast.StructuralNode;
import org.asciidoctor.jruby.ast.impl.SectionImpl;
import org.asciidoctor.maven.site.ast.NodeProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SectionNodeProcessor extends AbstractSinkNodeProcessor implements NodeProcessor {

private final Logger logger = LoggerFactory.getLogger(SectionNodeProcessor.class);

public SectionNodeProcessor(Sink sink) {
super(sink);
}
Expand All @@ -24,45 +28,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("<h1>" + formattedTitle + "</h1>");
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 static 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ void should_convert_html_without_any_configuration() throws FileNotFoundExceptio

assertThat(result)
.isEqualTo("<h1>Document Title</h1><p>Preamble paragraph.</p>" +
"<h2><a name=\"Section_A\"></a>Section A</h2>" +
"<h2><a id=\"id_section_a\"></a>Section A</h2>" +
"<p><strong>Section A</strong> paragraph.</p>" +
"<h3><a name=\"Section_A_Subsection\"></a>Section A Subsection</h3>" +
"<h3><a id=\"id_section_a_subsection\"></a>Section A Subsection</h3>" +
"<p><strong>Section A</strong> <em>subsection</em> paragraph.</p>" +
"<h2><a name=\"Section_B\"></a>Section B</h2>" +
"<h2><a id=\"id_section_b\"></a>Section B</h2>" +
"<p><strong>Section B</strong> paragraph.</p>" +
"<ul>" +
"<li>Item 1</li>" +
"<li>Item 2</li>" +
"<li>Item 3</li></ul><div class=\"source\"><pre class=\"prettyprint\"><code>require 'asciidoctor'</code></pre></div>");
"<li>Item 3</li></ul>" +
"<div class=\"source\"><pre class=\"prettyprint\"><code>require 'asciidoctor'</code></pre></div>");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void should_convert_section_level_2() {
String html = process(content, 1);

assertThat(html)
.isEqualTo("<h2><a name=\"First_section_title\"></a>First section title</h2>");
.isEqualTo("<h2><a id=\"_first_section_title\"></a>First section title</h2>");
}

@Test
Expand All @@ -48,7 +48,7 @@ void should_convert_section_level_3() {
String html = process(content, 2);

assertThat(html)
.isEqualTo("<h3><a name=\"Second_section_title\"></a>Second section title</h3>");
.isEqualTo("<h3><a id=\"_second_section_title\"></a>Second section title</h3>");
}

@Test
Expand All @@ -58,7 +58,7 @@ void should_convert_section_level_4() {
String html = process(content, 3);

assertThat(html)
.isEqualTo("<h4><a name=\"Third_section_title\"></a>Third section title</h4>");
.isEqualTo("<h4><a id=\"_third_section_title\"></a>Third section title</h4>");
}

@Test
Expand All @@ -68,17 +68,18 @@ void should_convert_section_level_5() {
String html = process(content, 4);

assertThat(html)
.isEqualTo("<h5><a name=\"Fourth_section_title\"></a>Fourth section title</h5>");
.isEqualTo("<h5><a id=\"_fourth_section_title\"></a>Fourth section title</h5>");
}

@Test
void should_convert_section_level_6() {
void should_convert_section_level_6_as_level_5() {
// Maven site does not support more than H5
String content = documentWithSections();

String html = process(content, 5);

assertThat(html)
.isEqualTo("<h6><a name=\"Fifth_section_title\"></a>Fifth section title</h6>");
.isEqualTo("<h5><a id=\"_fifth_section_title\"></a>Fifth section title</h5>");
}

@Test
Expand All @@ -90,17 +91,17 @@ void should_convert_section_with_sectionNumbers() {

// With numbering
assertThat(process(content, 1, attributes))
.isEqualTo("<h2><a name=\"a1._First_section_title\"></a>1. First section title</h2>");
.isEqualTo("<h2><a id=\"_first_section_title\"></a>1. First section title</h2>");
assertThat(process(content, 2, attributes))
.isEqualTo("<h3><a name=\"a1.1._Second_section_title\"></a>1.1. Second section title</h3>");
.isEqualTo("<h3><a id=\"_second_section_title\"></a>1.1. Second section title</h3>");
assertThat(process(content, 3, attributes))
.isEqualTo("<h4><a name=\"a1.1.1._Third_section_title\"></a>1.1.1. Third section title</h4>");
.isEqualTo("<h4><a id=\"_third_section_title\"></a>1.1.1. Third section title</h4>");

// Without numbering by default
assertThat(process(content, 4, attributes))
.isEqualTo("<h5><a name=\"Fourth_section_title\"></a>Fourth section title</h5>");
.isEqualTo("<h5><a id=\"_fourth_section_title\"></a>Fourth section title</h5>");
assertThat(process(content, 5, attributes))
.isEqualTo("<h6><a name=\"Fifth_section_title\"></a>Fifth section title</h6>");
.isEqualTo("<h5><a id=\"_fifth_section_title\"></a>Fifth section title</h5>");
}

@Test
Expand All @@ -113,15 +114,28 @@ void should_convert_section_with_sectionNumbers_and_sectNumLevels() {

// With numbering
assertThat(process(content, 1, attributes))
.isEqualTo("<h2><a name=\"a1._First_section_title\"></a>1. First section title</h2>");
.isEqualTo("<h2><a id=\"_first_section_title\"></a>1. First section title</h2>");
assertThat(process(content, 2, attributes))
.isEqualTo("<h3><a name=\"a1.1._Second_section_title\"></a>1.1. Second section title</h3>");
.isEqualTo("<h3><a id=\"_second_section_title\"></a>1.1. Second section title</h3>");
assertThat(process(content, 3, attributes))
.isEqualTo("<h4><a name=\"a1.1.1._Third_section_title\"></a>1.1.1. Third section title</h4>");
.isEqualTo("<h4><a id=\"_third_section_title\"></a>1.1.1. Third section title</h4>");
assertThat(process(content, 4, attributes))
.isEqualTo("<h5><a name=\"a1.1.1.1._Fourth_section_title\"></a>1.1.1.1. Fourth section title</h5>");
.isEqualTo("<h5><a id=\"_fourth_section_title\"></a>1.1.1.1. Fourth section title</h5>");
assertThat(process(content, 5, attributes))
.isEqualTo("<h6><a name=\"a1.1.1.1.1._Fifth_section_title\"></a>1.1.1.1.1. Fifth section title</h6>");
.isEqualTo("<h5><a id=\"_fifth_section_title\"></a>1.1.1.1.1. Fifth section title</h5>");
}

@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("<h2><a id=\"my_first_section_title\"></a>First section title</h2>");
}

private String documentWithSections() {
Expand Down
Loading

0 comments on commit 346119b

Please sign in to comment.