Skip to content
Merged
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 @@ -194,10 +194,6 @@ public static Optional<CodeFence> extractCode(String fullMessage) {
}

int languageStart = codeFenceStart + CODE_FENCE_SYMBOL.length();
int codeFenceEnd = fullMessage.indexOf(CODE_FENCE_SYMBOL, languageStart);
if (codeFenceEnd == -1) {
return Optional.empty();
}

// Language is between ``` and newline, no spaces allowed, like ```java
// Look for the next newline and then assert no space between
Expand All @@ -213,6 +209,11 @@ public static Optional<CodeFence> extractCode(String fullMessage) {
languageEnd = languageStart;
}

int codeFenceEnd = fullMessage.indexOf(CODE_FENCE_SYMBOL, languageEnd);
if (codeFenceEnd == -1) {
return Optional.empty();
}

String code = fullMessage.substring(languageEnd, codeFenceEnd).strip();

return Optional.of(new CodeFence(language, code));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ fun main() {

tests.add(Arguments.of("small code fence", "Foo `int x = 5` Bar", null));

tests.add(Arguments.of("six backticks", """
``````test
foo```""", new CodeFence("```test", "foo")));

tests.add(Arguments.of("single line", "```java test```", new CodeFence(null, "java test")));

tests.add(Arguments.of("space in language", """
```java test
test```
""", new CodeFence(null, """
java test
test""")));

return tests;
}

Expand Down