@@ -592,27 +592,33 @@ Pair<List<DCTree>, List<DCTree>> splitBody(List<? extends DocTree> list) {
592
592
case TEXT , MARKDOWN -> {
593
593
var peekedNext = iter .hasNext () ? alist .get (iter .nextIndex ()) : null ;
594
594
var content = getContent (dt );
595
- int breakOffset = getSentenceBreak (dt .getKind (), content , peekedNext );
596
- if (breakOffset > 0 ) {
597
- // the end of sentence is within the current node;
598
- // split it, skipping whitespace in between the two parts
599
- var fsPart = newNode (dt .getKind (), dt .pos , content .substring (0 , breakOffset ).stripTrailing ());
600
- fs .add (fsPart );
601
- int wsOffset = skipWhiteSpace (content , breakOffset );
602
- if (wsOffset > 0 ) {
603
- var bodyPart = newNode (dt .getKind (), dt .pos + wsOffset , content .substring (wsOffset ));
604
- body .add (bodyPart );
605
- }
606
- foundFirstSentence = true ;
607
- } else if (peekedNext != null && isSentenceBreak (peekedNext , false )) {
608
- // the next node is a sentence break, so this is the end of the first sentence;
609
- // remove trailing spaces
610
- var fsPart = newNode (dt .getKind (), dt .pos , content .stripTrailing ());
611
- fs .add (fsPart );
595
+ if (isFirst && dt .getKind () == Kind .MARKDOWN && isIndented (content )) {
596
+ // begins with an indented code block (unusual), so no first sentence
597
+ body .add (dt );
612
598
foundFirstSentence = true ;
613
599
} else {
614
- // no sentence break found; keep scanning
615
- fs .add (dt );
600
+ int breakOffset = getSentenceBreak (dt .getKind (), content , peekedNext );
601
+ if (breakOffset > 0 ) {
602
+ // the end of sentence is within the current node;
603
+ // split it, skipping whitespace in between the two parts
604
+ var fsPart = newNode (dt .getKind (), dt .pos , content .substring (0 , breakOffset ).stripTrailing ());
605
+ fs .add (fsPart );
606
+ int wsOffset = skipWhiteSpace (content , breakOffset );
607
+ if (wsOffset > 0 ) {
608
+ var bodyPart = newNode (dt .getKind (), dt .pos + wsOffset , content .substring (wsOffset ));
609
+ body .add (bodyPart );
610
+ }
611
+ foundFirstSentence = true ;
612
+ } else if (peekedNext != null && isSentenceBreak (peekedNext , false )) {
613
+ // the next node is a sentence break, so this is the end of the first sentence;
614
+ // remove trailing spaces
615
+ var fsPart = newNode (dt .getKind (), dt .pos , content .stripTrailing ());
616
+ fs .add (fsPart );
617
+ foundFirstSentence = true ;
618
+ } else {
619
+ // no sentence break found; keep scanning
620
+ fs .add (dt );
621
+ }
616
622
}
617
623
}
618
624
@@ -651,6 +657,11 @@ private String getContent(DCTree dt) {
651
657
};
652
658
}
653
659
660
+ private static final Pattern INDENT = Pattern .compile (" {4}| {0,3}\t " );
661
+ private boolean isIndented (String s ) {
662
+ return INDENT .matcher (s ).lookingAt ();
663
+ }
664
+
654
665
private DCTree newNode (DocTree .Kind kind , int pos , String text ) {
655
666
return switch (kind ) {
656
667
case TEXT -> m .at (pos ).newTextTree (text );
0 commit comments