fix: enhance code block formatting in DiscordMessageParser

This commit is contained in:
Xujiayao 2026-03-17 16:39:16 +08:00 committed by Jason Xu
parent 94fd14f738
commit 1e798f4156

View file

@ -961,7 +961,15 @@ List<TextSegment> codeSegments;
if ("ansi".equalsIgnoreCase(language) && ConfigManager.getBoolean("message_parsing.discord_to_minecraft.ansi_code_blocks")) {
codeSegments = parseAnsiContent(content);
} else {
codeSegments = List.of(new TextSegment("[" + content + "]"));
StringBuilder sb = new StringBuilder("<code lang=[").append(language).append("]>");
// For each line of content string
for (String line : content.split("\n", 0)) {
sb.append("\n ").append(line);
}
sb.append("\n</code>");
codeSegments = List.of(new TextSegment(sb.toString()));
}
spans.add(new MarkdownSpan(matcher.start(), matcher.end(), content, MarkdownType.CODE_BLOCK, codeSegments));