Markdown rendered incorrectly from plugin response but correctly from user input.
From a plugin, return a CommandResponse with text set as "/abc def g|h <foo> or /abc def g|h
Directly enter this text in the message box and compare the results of rendered markdown.
A markdown should be rendered correctly and consistently from plugin's CommandResponse.
This markdown - "/abc def g|h <foo> or /abc def g|h
Command Response (incorrectly displayed) - /abc def g|h h
User Input (correctly displayed) - /abc def g|h
Hi @harshilsharma63! Thanks for reporting this 馃憤
What Mattermost server version are you using?
@amyblais v5.1
@saturninoabril Would you be able to help test this?
Markdown rendering should be handled by the Web App plugin. You may use formatText(text, options) to display it properly.
For reference, please see exported libraries especially the post-utils / usage example at https://developers.mattermost.com/extend/plugins/webapp/reference/.
@saturninoabril so if I implement a slash command and I want to send markdown in CommandResponse, can I now do it just from the server side? I mean adding a webapp just for formatting markdown seems overkill.
Oh sorry... I missed your case. If you're sending text via CommandResponse, it should be handled by the client without writing extra client plugin. Could you provide once again your repro steps, observed response and expected? By looking at your original post, I cannot reproduce your issue.
@saturninoabril I tried it in a new plugin and it did work fine. Let me try verifying again in my original plugin and come back with a reproducible sample plugin.
@saturninoabril here you go, a minimal, complete, and verifiable plugin example demonstrating the bug - https://gist.github.com/harshilsharma63/94ba29395c06a31bbdb2d4980600251f
This will register a /demo slash command. If you run that, it will do two things -
CommandResponseboth with the exact same text. Notice how the markdown in two is rendered differently (incorrectly in CommandResponse).
Just for reference, here's a screenshot - https://imgur.com/a/cCLznlo
Thanks @harshilsharma63 for sharing! I'll try this early next week. Just need to prioritize some bug fixes for upcoming 5.2 release.
@saturninoabril sure. I'm excited for 5.2 release!
@harshavardhana @harshilsharma63 Hmmm, I maybe wrong but I don't think something on latest master has changed that fixes your use case. The function responsible is parseSlackLinksToMarkdown.
The text in CommandResponse is typically used for server feedback like success, fail or error. In your case, it seems that you're trying to indicate in the response the usage/hint of that command. If that's the case, I would suggest to register the command with autocomplete hint or suggestion.
If you think this is something that needs to fix, let me know and I'll file a ticket for it.
@saturninoabril looks like you meant @harshilsharma63
Oh sorry... That's right, should be @harshilsharma63.
@saturninoabril I do use autocomplete and hint feature of slash commands, and you are correct that I'm trying to show command usage syntax in the message. I show this message along with an error message when a user enters an incorrect syntax. Something like -
incorrect parameter 'file'. Use this command as `/command foo|bar <your-name>`
I think it makes for a good UX to report the correct syntax. Help text, on the other hand, is only visible until the user is still typing the incomplete command. What do you think?
@harshilsharma63 Yeah, I think it make sense. I filed a ticket for it ==> https://mattermost.atlassian.net/browse/MM-11594
Thanks!
@harshilsharma63 I've looked into this but unfortunately, there's no easy way to fix this without breaking Slack compatibility. It's designed to match patterns like for <http://someurl|like this>. In your particular usage, I suggest to avoid angle brackets. Response text could be something like:
var text = "`c|d [e]` or `/a c|d [e]`"
@saturninoabril I guess its a corner case. For now, I have replaced the pipe with a slash to display it correctly.
Thanks for looking into this. You may close the issue.