10
10
import org .asciidoctor .maven .site .parser .processors .test .NodeProcessorTest ;
11
11
import org .junit .jupiter .api .Test ;
12
12
13
+ import static org .asciidoctor .maven .commons .StringUtils .isNotBlank ;
13
14
import static org .asciidoctor .maven .site .parser .processors .test .StringTestUtils .clean ;
14
15
import static org .assertj .core .api .Assertions .assertThat ;
15
16
@@ -31,6 +32,17 @@ void should_convert_full_source_block() {
31
32
.isEqualTo (expectedHtmlCodeBlock ());
32
33
}
33
34
35
+ @ Test
36
+ void should_convert_full_source_block_with_caption () {
37
+ final String title = "Java example" ;
38
+ String content = buildDocument (title , "[source,java]" );
39
+
40
+ String html = process (content );
41
+
42
+ assertThat (html )
43
+ .isEqualTo (expectedHtmlCodeBlock (title ));
44
+ }
45
+
34
46
@ Test
35
47
void should_convert_shorthand_source_block () {
36
48
String content = documentWithShorthandSourceBlock ();
@@ -41,15 +53,6 @@ void should_convert_shorthand_source_block() {
41
53
.isEqualTo (expectedHtmlCodeBlock ());
42
54
}
43
55
44
- private static String expectedHtmlCodeBlock () {
45
- // Actual styling is added in JS by prettify
46
- return "<div class=\" source\" ><pre class=\" prettyprint\" ><code>class HelloWorldLanguage {" +
47
- " public static void main(String[] args) {" +
48
- " System.out.println(\" Hello, World!\" );" +
49
- " }" +
50
- "}</code></pre></div>" ;
51
- }
52
-
53
56
@ Test
54
57
void should_convert_full_source_block_with_line_numbers_attribute () {
55
58
String content = buildDocument ("[source,java,linenums]" );
@@ -97,8 +100,13 @@ private String documentWithListingStyleSourceBlock() {
97
100
}
98
101
99
102
private static String buildDocument (String blockDefinition ) {
103
+ return buildDocument (null , blockDefinition );
104
+ }
105
+
106
+ private static String buildDocument (String title , String blockDefinition ) {
100
107
return "= Document tile\n \n "
101
108
+ "== Section\n \n "
109
+ + buildTitle (title )
102
110
+ blockDefinition + "\n " +
103
111
"----\n " +
104
112
"class HelloWorldLanguage {\n " +
@@ -109,6 +117,31 @@ private static String buildDocument(String blockDefinition) {
109
117
"----\n " ;
110
118
}
111
119
120
+ private static String buildTitle (String title ) {
121
+ if (isNotBlank (title ))
122
+ return "." + title + "\n " ;
123
+ return "" ;
124
+ }
125
+
126
+ private static String expectedHtmlCodeBlock () {
127
+ return expectedHtmlCodeBlock (null );
128
+ }
129
+
130
+ private static String expectedHtmlCodeBlock (String title ) {
131
+ // Actual styling is added in JS by prettify
132
+ return "<div class=\" source\" >" +
133
+ (isNotBlank (title ) ? expectedTitle (title ) : "" ) +
134
+ "<pre class=\" prettyprint\" ><code>class HelloWorldLanguage {" +
135
+ " public static void main(String[] args) {" +
136
+ " System.out.println(\" Hello, World!\" );" +
137
+ " }" +
138
+ "}</code></pre></div>" ;
139
+ }
140
+
141
+ private static String expectedTitle (String title ) {
142
+ return "<div style=\" color: #7a2518; margin-bottom: .25em;\" >" + title + "</div>" ;
143
+ }
144
+
112
145
private String process (String content ) {
113
146
StructuralNode node = asciidoctor .load (content , Options .builder ().build ())
114
147
.findBy (Collections .singletonMap ("context" , ":listing" ))
0 commit comments