File tree Expand file tree Collapse file tree
main/java/org/commonmark/renderer/html
test/java/org/commonmark/test Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import java .util .Set ;
99import org .commonmark .node .*;
1010import org .commonmark .renderer .NodeRenderer ;
11+ import org .commonmark .text .Characters ;
1112
1213/**
1314 * The node renderer that renders all the core nodes (comes last in the order of node renderers).
@@ -111,13 +112,12 @@ public void visit(FencedCodeBlock fencedCodeBlock) {
111112 Map <String , String > attributes = new LinkedHashMap <>();
112113 String info = fencedCodeBlock .getInfo ();
113114 if (info != null && !info .isEmpty ()) {
114- int space = info .indexOf (" " );
115- String language ;
116- if (space == -1 ) {
117- language = info ;
118- } else {
119- language = info .substring (0 , space );
115+ // The language is the first word of the info string, which ends at a space or tab
116+ int end = 0 ;
117+ while (end < info .length () && !Characters .isSpaceOrTab (info , end )) {
118+ end ++;
120119 }
120+ String language = info .substring (0 , end );
121121 attributes .put ("class" , "language-" + language );
122122 }
123123 renderCodeBlock (literal , fencedCodeBlock , attributes );
Original file line number Diff line number Diff line change @@ -303,6 +303,12 @@ public void orderedListStartZero() {
303303 .isEqualTo ("<ol start=\" 0\" >\n <li>Test</li>\n </ol>\n " );
304304 }
305305
306+ @ Test
307+ public void fencedCodeLanguageEndsAtTab () {
308+ assertThat (defaultRenderer ().render (parse ("```py\t x\n code\n ```\n " )))
309+ .isEqualTo ("<pre><code class=\" language-py\" >code\n </code></pre>\n " );
310+ }
311+
306312 @ Test
307313 public void imageAltTextWithSoftLineBreak () {
308314 assertThat (defaultRenderer ().render (parse ("\n " )))
You can’t perform that action at this time.
0 commit comments