Escape markdown in codeblock suggestion embed#437
Merged
Conversation
#434 If the content we prepare for the codeblock suggestion embed defined in the `bot` cog contains markdown characters (e.g., `__`, `**`), this will cause Discord to apply markdown, since both the codeblock syntax example as well as the codeblock result example will contain the characters, making it a matched formatting pair. This will hide those characters, which often have a function in the code, and break the example of a formatted codeblock. To deal with that, I've added a regex substitution that substitutes markdown characters by an escaped version of that markdown character. Example: `'__hello__'` will become `'\_\_hello\_\_'` I've added this substitution to both paths in the `on_message` event listener, since we can't substitute at an earlier place due to it generating `SyntaxErrors` with the `ast.parse` check. This closes #434
eivl
approved these changes
Sep 18, 2019
MarkKoz
approved these changes
Sep 18, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If the content we prepare for the codeblock suggestion embed defined in the
botcog contains markdown characters (e.g.,__,**), this will cause Discord to apply markdown, since both the codeblock syntax example as well as the codeblock result example will contain thecharacters, making it a matched formatting pair.
This will hide those characters, which often have a function in the code, and break the example of a formatted codeblock:

To deal with that, I've added a regex substitution that substitutes markdown characters by an escaped version of that markdown character. This will ensure the code is displayed correctly:
Note: I've added this substitution to both paths in the
on_messageevent listener, since we can't substitute at an earlier place due to it generatingSyntaxErrorswith theast.parsecheck.This closes #434