@@ -204,6 +204,66 @@ public void linkReferenceDefinitionHeading() {
204204 assertEquals (List .of (SourceSpan .of (1 , 0 , 7 ), SourceSpan .of (2 , 0 , 3 )), heading .getSourceSpans ());
205205 }
206206
207+ @ Test
208+ public void lazyContinuationLines () {
209+ {
210+ // From https://spec.commonmark.org/0.31.2/#example-250
211+ // Wrong source span for the inner block quote for the second line.
212+ var doc = PARSER .parse ("> > > foo\n bar\n " );
213+
214+ var bq1 = (BlockQuote ) doc .getLastChild ();
215+ assertEquals (List .of (SourceSpan .of (0 , 0 , 9 ), SourceSpan .of (1 , 0 , 3 )), bq1 .getSourceSpans ());
216+ var bq2 = (BlockQuote ) bq1 .getLastChild ();
217+ assertEquals (List .of (SourceSpan .of (0 , 2 , 7 ), SourceSpan .of (1 , 0 , 3 )), bq2 .getSourceSpans ());
218+ var bq3 = (BlockQuote ) bq2 .getLastChild ();
219+ assertEquals (List .of (SourceSpan .of (0 , 4 , 5 ), SourceSpan .of (1 , 0 , 3 )), bq3 .getSourceSpans ());
220+ var paragraph = (Paragraph ) bq3 .getLastChild ();
221+ assertEquals (List .of (SourceSpan .of (0 , 6 , 3 ), SourceSpan .of (1 , 0 , 3 )), paragraph .getSourceSpans ());
222+ }
223+
224+ {
225+ // Adding one character to the last line remove blockQuote3 source for the second line
226+ var doc = PARSER .parse ("> > > foo\n bars\n " );
227+
228+ var bq1 = (BlockQuote ) doc .getLastChild ();
229+ assertEquals (List .of (SourceSpan .of (0 , 0 , 9 ), SourceSpan .of (1 , 0 , 4 )), bq1 .getSourceSpans ());
230+ var bq2 = (BlockQuote ) bq1 .getLastChild ();
231+ assertEquals (List .of (SourceSpan .of (0 , 2 , 7 ), SourceSpan .of (1 , 0 , 4 )), bq2 .getSourceSpans ());
232+ var bq3 = (BlockQuote ) bq2 .getLastChild ();
233+ assertEquals (List .of (SourceSpan .of (0 , 4 , 5 ), SourceSpan .of (1 , 0 , 4 )), bq3 .getSourceSpans ());
234+ var paragraph = (Paragraph ) bq3 .getLastChild ();
235+ assertEquals (List .of (SourceSpan .of (0 , 6 , 3 ), SourceSpan .of (1 , 0 , 4 )), paragraph .getSourceSpans ());
236+ }
237+
238+ {
239+ // From https://spec.commonmark.org/0.31.2/#example-292
240+ var doc = PARSER .parse ("> 1. > Blockquote\n continued here." );
241+
242+ var bq1 = (BlockQuote ) doc .getLastChild ();
243+ assertEquals (List .of (SourceSpan .of (0 , 0 , 17 ), SourceSpan .of (1 , 0 , 15 )), bq1 .getSourceSpans ());
244+ var orderedList = (OrderedList ) bq1 .getLastChild ();
245+ assertEquals (List .of (SourceSpan .of (0 , 2 , 15 ), SourceSpan .of (1 , 0 , 15 )), orderedList .getSourceSpans ());
246+ var listItem = (ListItem ) orderedList .getLastChild ();
247+ assertEquals (List .of (SourceSpan .of (0 , 2 , 15 ), SourceSpan .of (1 , 0 , 15 )), listItem .getSourceSpans ());
248+ var bq2 = (BlockQuote ) listItem .getLastChild ();
249+ assertEquals (List .of (SourceSpan .of (0 , 5 , 12 ), SourceSpan .of (1 , 0 , 15 )), bq2 .getSourceSpans ());
250+ var paragraph = (Paragraph ) bq2 .getLastChild ();
251+ assertEquals (List .of (SourceSpan .of (0 , 7 , 10 ), SourceSpan .of (1 , 0 , 15 )), paragraph .getSourceSpans ());
252+ }
253+
254+ {
255+ // Lazy continuation line for nested blockquote
256+ var doc = PARSER .parse ("> > foo\n > bar\n " );
257+
258+ var bq1 = (BlockQuote ) doc .getLastChild ();
259+ assertEquals (List .of (SourceSpan .of (0 , 0 , 7 ), SourceSpan .of (1 , 0 , 5 )), bq1 .getSourceSpans ());
260+ var bq2 = (BlockQuote ) bq1 .getLastChild ();
261+ assertEquals (List .of (SourceSpan .of (0 , 2 , 5 ), SourceSpan .of (1 , 2 , 3 )), bq2 .getSourceSpans ());
262+ var paragraph = (Paragraph ) bq2 .getLastChild ();
263+ assertEquals (List .of (SourceSpan .of (0 , 4 , 3 ), SourceSpan .of (1 , 2 , 3 )), paragraph .getSourceSpans ());
264+ }
265+ }
266+
207267 @ Test
208268 public void visualCheck () {
209269 assertEquals ("(> {[* <foo>]})\n (> {[ <bar>]})\n (> {⸢* ⸤baz⸥⸣})\n " ,
0 commit comments