Skip to content

Fix MarkdownUtil#monospace not correctly applying monospace formatting to strings with backticks - #3139

Open
ManosSef wants to merge 3 commits into
discord-jda:masterfrom
ManosSef:master
Open

Fix MarkdownUtil#monospace not correctly applying monospace formatting to strings with backticks#3139
ManosSef wants to merge 3 commits into
discord-jda:masterfrom
ManosSef:master

Conversation

@ManosSef

@ManosSef ManosSef commented Aug 26, 2026

Copy link
Copy Markdown

Pull Request Etiquette

  • I have checked the PRs for upcoming features/bug fixes.
  • I have read the contributing guidelines.
  • I applied the code formatter to my changes with ./gradlew format

Changes

  • Internal code
  • Library interface (affecting end-user code)
  • Documentation
  • Other: _____

Closes Issue: #3071

Description

Modifies the logic of MarkdownUtil#monospace, so that it:

  • Correctly applies monospace formatting even when the input string contains backticks, and
  • Does not add backslashes, since they have no effect on backticks and are actually visible in the Discord client, meaning the result string is not faithful to the input string.

Single backticks are allowed in monospace text by using double backticks as delimiters instead, and monospace text can start with backticks by inserting an extra space between the delimiter and the string, which does not appear on the client. These improvements allow the method to properly monospace text with backticks.

It is impossible to apply monospace formatting to text that contains both single and double backticks, so that case is not handled.

This should not be "out of scope" for JDA, since there is no complex parser logic involved. The current implementation is worse for text with backticks than just manually concatenating a backtick before and after the string, since it adds backslashes to the text which are shown on the client. This PR fixes the implementation enough to bring it on par with other methods in MarkdownUtil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant