Skip to content

Commit

Permalink
Refactor Head Parsing to ease porting to main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Feb 8, 2024
1 parent 589b744 commit 82f4ef0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
import org.apache.maven.doxia.parser.Parser;
import org.apache.maven.doxia.sink.Sink;
import org.apache.maven.project.MavenProject;
import org.asciidoctor.*;
import org.asciidoctor.ast.Author;
import org.asciidoctor.Asciidoctor;
import org.asciidoctor.AttributesBuilder;
import org.asciidoctor.OptionsBuilder;
import org.asciidoctor.SafeMode;
import org.asciidoctor.maven.log.LogHandler;
import org.asciidoctor.maven.log.LogRecordFormatter;
import org.asciidoctor.maven.log.LogRecordsProcessors;
import org.asciidoctor.maven.log.MemoryLogHandler;
import org.asciidoctor.maven.site.SiteConverter.HeaderMetadata;
import org.asciidoctor.maven.site.SiteConverter.Result;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.IOUtil;
Expand All @@ -22,7 +23,6 @@
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.util.Optional;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -90,28 +90,12 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
throw new ParseException(exception.getMessage(), exception);
}

sinkHeader(sink, headerMetadata.getHeaderMetadata());
new HeadParser(sink)
.parse(headerMetadata.getHeaderMetadata());

sink.rawText(headerMetadata.getHtml());
}

private static void sinkHeader(Sink sink, HeaderMetadata headerMetadata) {
sink.head();
sink.title();
sink.text(Optional.ofNullable(headerMetadata.getTitle()).orElse("[Untitled]"));
sink.title_();

for (String author : headerMetadata.getAuthors()) {
sink.author();
sink.text(author.toString());
sink.author_();
}

sink.date();
sink.text(headerMetadata.getDateTime());
sink.date_();
sink.head_();
}

private MemoryLogHandler asciidoctorLoggingSetup(Asciidoctor asciidoctor, LogHandler logHandler, File siteDirectory) {

Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/asciidoctor/maven/site/HeadParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.asciidoctor.maven.site;

import org.apache.maven.doxia.sink.Sink;

import java.util.Optional;

class HeadParser {

private final Sink sink;

HeadParser(Sink sink) {
this.sink = sink;
}

void parse(SiteConverter.HeaderMetadata headerMetadata) {
sink.head();
sink.title();
sink.text(Optional.ofNullable(headerMetadata.getTitle()).orElse("[Untitled]"));
sink.title_();

for (String author : headerMetadata.getAuthors()) {
sink.author();
sink.text(author.toString());
sink.author_();
}

sink.date();
sink.text(headerMetadata.getDateTime());
sink.date_();
sink.head_();
}
}

0 comments on commit 82f4ef0

Please sign in to comment.