Skip to content

Commit 5815c3c

Browse files
ia3andyclaude
andcommitted
Add spec generator script and match GitHub softbreak rendering
Add a jbang script (generate-alerts-spec.java) that generates alerts-spec.txt from a template (alerts-spec-template.md) by rendering each example through the GitHub Markdown API and normalizing the HTML. Configure AlertsSpecTest with softbreak("<br>") to match GitHub's rendering, reducing the normalizations needed in the generator. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 057f13d commit 5815c3c

File tree

4 files changed

+407
-15
lines changed

4 files changed

+407
-15
lines changed

commonmark-ext-gfm-alerts/src/test/java/org/commonmark/ext/gfm/alerts/AlertsSpecTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class AlertsSpecTest extends RenderingTestCase {
2121

2222
private static final Set<Extension> EXTENSIONS = Set.of(AlertsExtension.create());
2323
private static final Parser PARSER = Parser.builder().extensions(EXTENSIONS).build();
24-
private static final HtmlRenderer RENDERER = HtmlRenderer.builder().extensions(EXTENSIONS).build();
24+
// Use softbreak("<br>") to match GitHub's rendering for easier comparison with GitHub API output.
25+
private static final HtmlRenderer RENDERER = HtmlRenderer.builder().extensions(EXTENSIONS).softbreak("<br>\n").build();
2526

2627
@Parameter
2728
Example example;
Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
# Alerts
2+
3+
## Standard types
4+
5+
```````````````````````````````` example alert
6+
> [!NOTE]
7+
> This is a note
8+
````````````````````````````````
9+
10+
```````````````````````````````` example alert
11+
> [!TIP]
12+
> This is a tip
13+
````````````````````````````````
14+
15+
```````````````````````````````` example alert
16+
> [!IMPORTANT]
17+
> This is important
18+
````````````````````````````````
19+
20+
```````````````````````````````` example alert
21+
> [!WARNING]
22+
> This is a warning
23+
````````````````````````````````
24+
25+
```````````````````````````````` example alert
26+
> [!CAUTION]
27+
> This is a caution
28+
````````````````````````````````
29+
30+
## Case insensitivity
31+
32+
Alert type matching is case-insensitive.
33+
34+
```````````````````````````````` example alert
35+
> [!note]
36+
> Content
37+
````````````````````````````````
38+
39+
```````````````````````````````` example alert
40+
> [!Note]
41+
> Content
42+
````````````````````````````````
43+
44+
## Alert content
45+
46+
Marker alone in first paragraph, blank line, then content:
47+
48+
```````````````````````````````` example alert
49+
> [!NOTE]
50+
>
51+
> Content
52+
````````````````````````````````
53+
54+
Multiple paragraphs:
55+
56+
```````````````````````````````` example alert
57+
> [!NOTE]
58+
> First paragraph
59+
>
60+
> Second paragraph
61+
````````````````````````````````
62+
63+
Inline formatting:
64+
65+
```````````````````````````````` example alert
66+
> [!TIP]
67+
> This is **bold** and *italic*
68+
````````````````````````````````
69+
70+
Code block inside alert:
71+
72+
```````````````````````````````` example alert
73+
> [!TIP]
74+
> Code:
75+
>
76+
> function() { }
77+
>
78+
> End
79+
````````````````````````````````
80+
81+
List inside alert:
82+
83+
```````````````````````````````` example alert
84+
> [!IMPORTANT]
85+
> Items:
86+
> - First item
87+
> - Second item
88+
````````````````````````````````
89+
90+
Links inside alert:
91+
92+
```````````````````````````````` example alert
93+
> [!NOTE]
94+
> Check out [this link](https://example.com) for more info
95+
````````````````````````````````
96+
97+
Heading inside alert:
98+
99+
```````````````````````````````` example alert
100+
> [!IMPORTANT]
101+
> ## Heading
102+
> Content below heading
103+
````````````````````````````````
104+
105+
Empty lines in middle of alert:
106+
107+
```````````````````````````````` example alert
108+
> [!NOTE]
109+
> First
110+
>
111+
>
112+
> After empty lines
113+
````````````````````````````````
114+
115+
## Not an alert
116+
117+
Text after marker on the same line:
118+
119+
```````````````````````````````` example alert
120+
> [!NOTE] Some text
121+
````````````````````````````````
122+
123+
Unknown type:
124+
125+
```````````````````````````````` example alert
126+
> [!INVALID]
127+
> Some text
128+
````````````````````````````````
129+
130+
Unconfigured custom type is not an alert:
131+
132+
```````````````````````````````` example alert
133+
> [!INFO]
134+
> Should be blockquote
135+
````````````````````````````````
136+
137+
Marker with no content:
138+
139+
```````````````````````````````` example alert
140+
> [!NOTE]
141+
````````````````````````````````
142+
143+
Whitespace-only content after marker:
144+
145+
```````````````````````````````` example alert
146+
> [!TIP]
147+
>
148+
>
149+
````````````````````````````````
150+
151+
Extra space inside marker:
152+
153+
```````````````````````````````` example alert
154+
> [! NOTE]
155+
> Should be blockquote
156+
````````````````````````````````
157+
158+
Missing brackets:
159+
160+
```````````````````````````````` example alert
161+
> !NOTE
162+
> Should be blockquote
163+
````````````````````````````````
164+
165+
Missing exclamation mark:
166+
167+
```````````````````````````````` example alert
168+
> [NOTE]
169+
> Should be blockquote
170+
````````````````````````````````
171+
172+
Regular blockquote is not affected:
173+
174+
```````````````````````````````` example alert
175+
> This is a regular blockquote
176+
````````````````````````````````
177+
178+
## Boundaries
179+
180+
Trailing spaces after marker:
181+
182+
```````````````````````````````` example alert
183+
> [!NOTE]
184+
> This is a note
185+
````````````````````````````````
186+
187+
Trailing tabs after marker:
188+
189+
```````````````````````````````` example alert
190+
> [!WARNING]→→
191+
> Be careful
192+
````````````````````````````````
193+
194+
Leading spaces before blockquote marker:
195+
196+
```````````````````````````````` example alert
197+
> [!IMPORTANT]
198+
> Content
199+
````````````````````````````````
200+
201+
Blank line after marker ends the blockquote (not an alert):
202+
203+
```````````````````````````````` example alert
204+
> [!NOTE]
205+
206+
Some text
207+
````````````````````````````````
208+
209+
Alert followed by blockquote:
210+
211+
```````````````````````````````` example alert
212+
> [!NOTE]
213+
> This is an alert
214+
215+
> This is a blockquote
216+
````````````````````````````````
217+
218+
Adjacent alerts:
219+
220+
```````````````````````````````` example alert
221+
> [!NOTE]
222+
> First alert
223+
224+
> [!WARNING]
225+
> Second alert
226+
````````````````````````````````
227+
228+
## Nesting and containers
229+
230+
Nested alert inside alert renders as blockquote:
231+
232+
```````````````````````````````` example alert
233+
> [!NOTE]
234+
> This is a note
235+
>> [!WARNING]
236+
>> Nested content
237+
````````````````````````````````
238+
239+
Nested blockquote inside alert:
240+
241+
```````````````````````````````` example alert
242+
> [!NOTE]
243+
> This is a note
244+
>> Nested blockquote
245+
````````````````````````````````
246+
247+
Alert inside list item stays as blockquote:
248+
249+
```````````````````````````````` example alert
250+
- > [!NOTE]
251+
> Test
252+
````````````````````````````````
253+
254+
Alert marker in content is treated as text:
255+
256+
```````````````````````````````` example alert
257+
> [!NOTE]
258+
> This is a note
259+
> [!WARNING]
260+
> This is still part of the note
261+
````````````````````````````````
262+
263+
## Continuation and interruption
264+
265+
Lazy continuation:
266+
267+
```````````````````````````````` example alert
268+
> [!NOTE]
269+
> First line
270+
Lazy continuation
271+
> Continues alert
272+
````````````````````````````````
273+
274+
Alert type after regular blockquote content is not an alert:
275+
276+
```````````````````````````````` example alert
277+
> Regular blockquote
278+
> [!NOTE]
279+
> More text
280+
````````````````````````````````

commonmark-ext-gfm-alerts/src/test/resources/alerts-spec.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Unknown type:
219219
> Some text
220220
.
221221
<blockquote>
222-
<p>[!INVALID]
222+
<p>[!INVALID]<br>
223223
Some text</p>
224224
</blockquote>
225225
````````````````````````````````
@@ -231,7 +231,7 @@ Unconfigured custom type is not an alert:
231231
> Should be blockquote
232232
.
233233
<blockquote>
234-
<p>[!INFO]
234+
<p>[!INFO]<br>
235235
Should be blockquote</p>
236236
</blockquote>
237237
````````````````````````````````
@@ -265,7 +265,7 @@ Extra space inside marker:
265265
> Should be blockquote
266266
.
267267
<blockquote>
268-
<p>[! NOTE]
268+
<p>[! NOTE]<br>
269269
Should be blockquote</p>
270270
</blockquote>
271271
````````````````````````````````
@@ -277,7 +277,7 @@ Missing brackets:
277277
> Should be blockquote
278278
.
279279
<blockquote>
280-
<p>!NOTE
280+
<p>!NOTE<br>
281281
Should be blockquote</p>
282282
</blockquote>
283283
````````````````````````````````
@@ -289,7 +289,7 @@ Missing exclamation mark:
289289
> Should be blockquote
290290
.
291291
<blockquote>
292-
<p>[NOTE]
292+
<p>[NOTE]<br>
293293
Should be blockquote</p>
294294
</blockquote>
295295
````````````````````````````````
@@ -405,7 +405,7 @@ Nested alert inside alert renders as blockquote:
405405
<p class="markdown-alert-title">Note</p>
406406
<p>This is a note</p>
407407
<blockquote>
408-
<p>[!WARNING]
408+
<p>[!WARNING]<br>
409409
Nested content</p>
410410
</blockquote>
411411
</div>
@@ -436,7 +436,7 @@ Alert inside list item stays as blockquote:
436436
<ul>
437437
<li>
438438
<blockquote>
439-
<p>[!NOTE]
439+
<p>[!NOTE]<br>
440440
Test</p>
441441
</blockquote>
442442
</li>
@@ -453,8 +453,8 @@ Alert marker in content is treated as text:
453453
.
454454
<div class="markdown-alert markdown-alert-note" data-alert-type="note">
455455
<p class="markdown-alert-title">Note</p>
456-
<p>This is a note
457-
[!WARNING]
456+
<p>This is a note<br>
457+
[!WARNING]<br>
458458
This is still part of the note</p>
459459
</div>
460460
````````````````````````````````
@@ -471,8 +471,8 @@ Lazy continuation
471471
.
472472
<div class="markdown-alert markdown-alert-note" data-alert-type="note">
473473
<p class="markdown-alert-title">Note</p>
474-
<p>First line
475-
Lazy continuation
474+
<p>First line<br>
475+
Lazy continuation<br>
476476
Continues alert</p>
477477
</div>
478478
````````````````````````````````
@@ -485,8 +485,8 @@ Alert type after regular blockquote content is not an alert:
485485
> More text
486486
.
487487
<blockquote>
488-
<p>Regular blockquote
489-
[!NOTE]
488+
<p>Regular blockquote<br>
489+
[!NOTE]<br>
490490
More text</p>
491491
</blockquote>
492-
````````````````````````````````
492+
````````````````````````````````

0 commit comments

Comments
 (0)