forked from asciidoctor/asciidoctor-maven-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(main) Port fixes for maven-site breadcrumbs from v2.2.x asciidoctor#763
(asciidoctor#774) * Add new HeaderParser and HeaderMetadata components to obtain Asciidoctor header details and inject them into the Sink header * Renames package `org.asciidoctor.maven.site.ast` to `org.asciidoctor.maven.site.parser` to match module name * Updated Integration Tests * Quick docs update (may require review after v3.0.0 release)
- Loading branch information
1 parent
5432f0c
commit 1fc2014
Showing
56 changed files
with
853 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...rter-doxia-module/src/it/maven-site-plugin/src/site/asciidoc/file-with-toc.adoc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
= File with TOC | ||
The Author | ||
:docdatetime: 2024-02-07 23:36:29 | ||
:toc: | ||
|
||
[.lead] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...nverter-doxia-module/src/main/java/org/asciidoctor/maven/site/SiteConverterDecorator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.asciidoctor.maven.site; | ||
|
||
import java.util.Map; | ||
|
||
import org.asciidoctor.Asciidoctor; | ||
import org.asciidoctor.Options; | ||
import org.asciidoctor.OptionsBuilder; | ||
import org.asciidoctor.ast.Document; | ||
|
||
/** | ||
* Asciidoctor conversion wrapper for maven-site integration. | ||
* In addition to conversion, handles header metadata extraction. | ||
*/ | ||
class SiteConverterDecorator { | ||
|
||
private final Asciidoctor asciidoctor; | ||
|
||
SiteConverterDecorator(Asciidoctor asciidoctor) { | ||
this.asciidoctor = asciidoctor; | ||
} | ||
|
||
Result process(String content, Options options) { | ||
final Document document = asciidoctor.load(content, headerProcessingMetadata(options)); | ||
final HeaderMetadata headerMetadata = HeaderMetadata.from(document); | ||
|
||
final String html = asciidoctor.convert(content, options); | ||
|
||
return new Result(headerMetadata, html); | ||
} | ||
|
||
private static Options headerProcessingMetadata(Options options) { | ||
Map<String, Object> optionsMap = options.map(); | ||
OptionsBuilder builder = Options.builder(); | ||
for (Map.Entry<String, Object> entry : optionsMap.entrySet()) { | ||
builder.option(entry.getKey(), entry.getValue()); | ||
} | ||
|
||
builder.parseHeaderOnly(Boolean.TRUE); | ||
return builder.build(); | ||
} | ||
|
||
/** | ||
* Simple tuple to return Asciidoctor extracted metadata and conversion result. | ||
*/ | ||
final class Result { | ||
|
||
private final HeaderMetadata headerMetadata; | ||
private final String html; | ||
|
||
Result(HeaderMetadata headerMetadata, String html) { | ||
this.headerMetadata = headerMetadata; | ||
this.html = html; | ||
} | ||
|
||
HeaderMetadata getHeaderMetadata() { | ||
return headerMetadata; | ||
} | ||
|
||
String getHtml() { | ||
return html; | ||
} | ||
} | ||
|
||
|
||
} |
Oops, something went wrong.