Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;
import org.commonmark.node.*;
import org.commonmark.renderer.NodeRenderer;
import org.commonmark.text.Characters;

/**
* The node renderer that renders all the core nodes (comes last in the order of node renderers).
Expand Down Expand Up @@ -111,13 +112,12 @@ public void visit(FencedCodeBlock fencedCodeBlock) {
Map<String, String> attributes = new LinkedHashMap<>();
String info = fencedCodeBlock.getInfo();
if (info != null && !info.isEmpty()) {
int space = info.indexOf(" ");
String language;
if (space == -1) {
language = info;
} else {
language = info.substring(0, space);
// The language is the first word of the info string, which ends at a space or tab
int end = 0;
while (end < info.length() && !Characters.isSpaceOrTab(info, end)) {
end++;
}
String language = info.substring(0, end);
attributes.put("class", "language-" + language);
}
renderCodeBlock(literal, fencedCodeBlock, attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public void tildeInfoCanStartWithBacktick() {
""");
}

@Test
public void languageEndsAtTab() {
assertRendering(
"```py\tx\ncode\n```\n",
"""
<pre><code class="language-py">code
</code></pre>
""");
}

@Test
public void backtickInfoDoesntAllowBacktick() {
assertRendering(
Expand Down
Loading