@@ -855,41 +855,37 @@ private void handleMarkdown(TagElement node) {
855855 int tokenIndexLast = -1 ;
856856 Token closingToken = null ;
857857 boolean shouldDisable = false ;
858- String fenceCharsStart = matcher .group (1 );
859- String infoString = matcher .group (2 );
860- int fenceLengthStart = fenceCharsStart .length ();
858+ String openingFenceChars = matcher .group (1 ).trim ();
859+ String infoString = matcher .group (2 ).trim ();
860+ int openingFenceLength = openingFenceChars .length ();
861+ boolean canAssumeJava = infoString .toLowerCase ().equals ("java" ) || infoString .isEmpty (); //$NON-NLS-1$
861862 while (matcher .find ()) {
862863 shouldDisable = true ;
863864 endPos = matcher .start () + node .getStartPosition ();
864865 tokenIndexLast = this .ctm .findIndex (endPos , ANY , true );
865866 closingToken = this .ctm .get (tokenIndexLast );
866- String fenceCharsEnd = matcher .group (1 ); // the fence itself
867- int fenceLengthEnd = fenceCharsStart .length ();
868- // Check if fences match
869- if (!fenceCharsStart .equals (fenceCharsEnd ))
867+ String closingFenceChars = matcher .group (1 );
868+ if (!openingFenceChars .equals (closingFenceChars ))
870869 continue ;
871870
872- if (fenceLengthStart == fenceLengthEnd ) {
873- if (tokenIndex > 1 )
874- openingToken .breakBefore ();
875- openingToken .breakAfter ();
876- if (this .ctm .size () - 1 != tokenIndexLast ) {
877- closingToken .putLineBreaksAfter (1 );
878- }
879- boolean canAssumeJava = infoString .toLowerCase ().equals ("java" ) || infoString .isEmpty (); //$NON-NLS-1$
871+ if (tokenIndex > 1 )
872+ openingToken .breakBefore ();
873+ openingToken .breakAfter ();
874+ if (this .ctm .size () - 1 != tokenIndexLast ) {
875+ closingToken .breakAfter ();
876+ }
880877
881- if (fenceLengthStart >= 3 && canAssumeJava && this .options .comment_format_source ) {
882- this .snippetForMarkdown = true ;
883- if (formatCode (tokenIndex , tokenIndexLast , true )) {
884- shouldDisable = false ;
885- }
886- this .snippetForMarkdown = false ;
878+ if (openingFenceLength >= 3 && canAssumeJava && this .options .comment_format_source ) {
879+ this .snippetForMarkdown = true ;
880+ if (formatCode (tokenIndex , tokenIndexLast , true )) {
881+ shouldDisable = false ;
887882 }
888- break ;
883+ this . snippetForMarkdown = false ;
889884 }
885+ break ;
890886 }
891887 if (shouldDisable ) {
892- disableFormattingExclusively (tokenIndex , tokenIndexLast + 1 );
888+ disableFormatting (tokenIndex , tokenIndexLast , false );
893889 }
894890 }
895891
0 commit comments