Skip to content

Escape markdown in codeblock suggestion embed#437

Merged
SebastiaanZ merged 2 commits into
masterfrom
codeblock-suggestion-escape-markdown
Sep 18, 2019
Merged

Escape markdown in codeblock suggestion embed#437
SebastiaanZ merged 2 commits into
masterfrom
codeblock-suggestion-escape-markdown

Conversation

@SebastiaanZ
Copy link
Copy Markdown
Contributor

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:
2019-09-18_09-06

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:

2019-09-18_09-08

Note: 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

#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
@SebastiaanZ SebastiaanZ added a: frontend Related to output and formatting p: 3 - low Low Priority t: bug Something isn't working labels Sep 18, 2019
@SebastiaanZ SebastiaanZ merged commit a64e2c2 into master Sep 18, 2019
@SebastiaanZ SebastiaanZ deleted the codeblock-suggestion-escape-markdown branch September 18, 2019 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: frontend Related to output and formatting p: 3 - low Low Priority t: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Escape discord markdown in detected poorly formatted python code before sending correction

3 participants