mattermost / mattermost-plugin-github

GitHub plugin for Mattermost
Apache License 2.0
156 stars 146 forks source link

double underscores in name eaten by markdown #793

Open doc-sheet opened 2 weeks ago

doc-sheet commented 2 weeks ago

Hi.

GitHub version: 2.2.0, 376f881, built Tue, 13 Feb 2024 15:14:53 UTC with go1.21.7

I have no idea how to show an example so I'll try to describe it.

When you paste a link to a file with dunders in it's name like https://github.com/mattermost/mattermost-data-warehouse/blob/5a88112086f5aefc88ca60ebbbc3668a4ee35ffb/utils/geolite/__main__.py#L10

Link above code preview in chat treats __main__ as markdown

Like this:

https:\//github.com/mattermost/mattermost-data-warehouse/utils/geolite/main.py

1.
2.
3.
mickmister commented 2 weeks ago

Hi @doc-sheet, thanks for filing this issue. This one is interesting.

So when the user posts https://github.com/mattermost/mattermost-data-warehouse/blob/5a88112086f5aefc88ca60ebbbc3668a4ee35ffb/utils/geolite/__main__.py#L10, we create a post with a link like:

[mattermost/mattermost-data-warehouse/utils/geolite/__main__.py](https://github.com/mattermost/mattermost-data-warehouse/blob/5a88112086f5aefc88ca60ebbbc3668a4ee35ffb/utils/geolite/__main__.py#L10), with the underscores being treated as bold instead of preserving them:

image

@hmhealey What are your thoughts on this? When creating a markdown link with custom text, some characters can be unintentionally treated as markdown formatting, when they are meant to be kept in tact (such as __main__.py). If I put backslashes in the link, the markdown is correctly ignored, so the plugin could do this for underscores:

[mattermost/mattermost-data-warehouse/utils/geolite/\_\_main\_\_.py](https://github.com/mattermost/mattermost-data-warehouse/blob/5a88112086f5aefc88ca60ebbbc3668a4ee35ffb/utils/geolite/__main__.py#L10)

rendered as this without the bold markdown:

mattermost/mattermost-data-warehouse/utils/geolite/__main__.py

So the solution could just be to have the plugin prepend underscores in the URL with backslashes

hmhealey commented 2 weeks ago

Yeah, that makes sense to me. You'd just be escaping the special characters which seems like a decent fix to me