1
1
package org .asciidoctor .maven .site ;
2
2
3
+ import javax .inject .Inject ;
4
+ import javax .inject .Provider ;
5
+ import java .io .File ;
6
+ import java .io .IOException ;
7
+ import java .io .Reader ;
8
+ import java .util .logging .Logger ;
9
+
3
10
import org .apache .maven .doxia .parser .AbstractTextParser ;
4
11
import org .apache .maven .doxia .parser .ParseException ;
5
12
import org .apache .maven .doxia .parser .Parser ;
6
13
import org .apache .maven .doxia .sink .Sink ;
7
14
import org .apache .maven .project .MavenProject ;
8
- import org .asciidoctor .*;
15
+ import org .asciidoctor .Asciidoctor ;
16
+ import org .asciidoctor .AttributesBuilder ;
17
+ import org .asciidoctor .OptionsBuilder ;
18
+ import org .asciidoctor .SafeMode ;
9
19
import org .asciidoctor .maven .log .LogHandler ;
10
20
import org .asciidoctor .maven .log .LogRecordFormatter ;
11
21
import org .asciidoctor .maven .log .LogRecordsProcessors ;
12
22
import org .asciidoctor .maven .log .MemoryLogHandler ;
23
+ import org .asciidoctor .maven .site .SiteConverterDecorator .Result ;
13
24
import org .codehaus .plexus .component .annotations .Component ;
14
25
import org .codehaus .plexus .util .IOUtil ;
15
26
import org .codehaus .plexus .util .xml .Xpp3Dom ;
16
27
17
- import javax .inject .Inject ;
18
- import javax .inject .Provider ;
19
- import java .io .File ;
20
- import java .io .IOException ;
21
- import java .io .Reader ;
22
- import java .util .logging .Logger ;
23
-
24
28
/**
25
29
* This class is used by <a href="https://maven.apache.org/doxia/overview.html">the Doxia framework</a>
26
30
* to handle the actual parsing of the AsciiDoc input files into HTML to be consumed/wrapped
@@ -67,31 +71,36 @@ public void parse(Reader reader, Sink sink, String reference) throws ParseExcept
67
71
final Asciidoctor asciidoctor = Asciidoctor .Factory .create ();
68
72
69
73
SiteConversionConfiguration conversionConfig = new SiteConversionConfigurationParser (project )
70
- .processAsciiDocConfig (siteConfig , defaultOptions (siteDirectory ), defaultAttributes ());
74
+ .processAsciiDocConfig (siteConfig , defaultOptions (siteDirectory ), defaultAttributes ());
71
75
for (String require : conversionConfig .getRequires ()) {
72
76
requireLibrary (asciidoctor , require );
73
77
}
74
78
75
79
final LogHandler logHandler = getLogHandlerConfig (siteConfig );
76
80
final MemoryLogHandler memoryLogHandler = asciidoctorLoggingSetup (asciidoctor , logHandler , siteDirectory );
77
81
78
- // QUESTION should we keep OptionsBuilder & AttributesBuilder separate for call to convertAsciiDoc?
79
- String asciidocHtml = convertAsciiDoc (asciidoctor , source , conversionConfig .getOptions ());
82
+ final SiteConverterDecorator siteConverter = new SiteConverterDecorator (asciidoctor );
83
+ final Result headerMetadata = siteConverter .process (source , conversionConfig .getOptions ());
84
+
80
85
try {
81
86
// process log messages according to mojo configuration
82
87
new LogRecordsProcessors (logHandler , siteDirectory , errorMessage -> getLog ().error (errorMessage ))
83
- .processLogRecords (memoryLogHandler );
88
+ .processLogRecords (memoryLogHandler );
84
89
} catch (Exception exception ) {
85
90
throw new ParseException (exception .getMessage (), exception );
86
91
}
87
92
88
- sink .rawText (asciidocHtml );
93
+ new HeadParser (sink )
94
+ .parse (headerMetadata .getHeaderMetadata ());
95
+
96
+ sink .rawText (headerMetadata .getHtml ());
89
97
}
90
98
99
+
91
100
private MemoryLogHandler asciidoctorLoggingSetup (Asciidoctor asciidoctor , LogHandler logHandler , File siteDirectory ) {
92
101
93
102
final MemoryLogHandler memoryLogHandler = new MemoryLogHandler (logHandler .getOutputToConsole (),
94
- logRecord -> getLog ().info (LogRecordFormatter .format (logRecord , siteDirectory )));
103
+ logRecord -> getLog ().info (LogRecordFormatter .format (logRecord , siteDirectory )));
95
104
asciidoctor .registerLogHandler (memoryLogHandler );
96
105
// disable default console output of AsciidoctorJ
97
106
Logger .getLogger ("asciidoctor" ).setUseParentHandlers (false );
@@ -119,16 +128,16 @@ protected File resolveSiteDirectory(MavenProject project, Xpp3Dom siteConfig) {
119
128
}
120
129
121
130
protected OptionsBuilder defaultOptions (File siteDirectory ) {
122
- return Options . builder ()
123
- .backend ("xhtml" )
124
- .safe (SafeMode .UNSAFE )
125
- .baseDir (new File (siteDirectory , ROLE_HINT ));
131
+ return OptionsBuilder . options ()
132
+ .backend ("xhtml" )
133
+ .safe (SafeMode .UNSAFE )
134
+ .baseDir (new File (siteDirectory , ROLE_HINT ));
126
135
}
127
136
128
137
protected AttributesBuilder defaultAttributes () {
129
- return Attributes . builder ()
130
- .attribute ("idprefix" , "@" )
131
- .attribute ("showtitle" , "@" );
138
+ return AttributesBuilder . attributes ()
139
+ .attribute ("idprefix" , "@" )
140
+ .attribute ("showtitle" , "@" );
132
141
}
133
142
134
143
private void requireLibrary (Asciidoctor asciidoctor , String require ) {
@@ -140,9 +149,4 @@ private void requireLibrary(Asciidoctor asciidoctor, String require) {
140
149
}
141
150
}
142
151
}
143
-
144
- protected String convertAsciiDoc (Asciidoctor asciidoctor , String source , Options options ) {
145
- return asciidoctor .convert (source , options );
146
- }
147
-
148
152
}
0 commit comments