So having thought about it a bit, I think these are the possible basic ways to implement it:
- Catch the user pasting code and somehow make it formatted (see step #2).
- Catch the user posting a topic or reply that contains unformatted code and handle it.
- Bot-reply or -PM a user after he posted something with unformatted code.
I think option 3) is out of scope here and more a moderation or community management thing that is probably better be handled manually by moderators or with another plugin. Leaves 1) and 2).
#1 would require monitoring the paste events, analyze their content and then some interface for the next step. Alternatively the code could also automatically be wrapped in the correct formatting, but this adds a lot of complexity (what if someone pastes code into an already existing code block?). But this would also be the most newbie friendly way.
#2 would require analysis of the text to be posted. Again some form of interface would have to be applied to inform the user of his options or, again, some logic could try to add formatting to the post automatically. This would be very convenient for the user, but quite complex to implement (Is this 1 or 2 code samples? Code block or just code in text?)
The “Somehow make it formatted”, “handle it” and “interface” refers to the possible variant of the second step of the process. This would probably have to include some “error” or “notice” to the user:
Seems you are trying to post code.
``` around it to format as code.
Or select the code and hit the
</> button to format it automatically.
(Better wording of course).
Then this could maybe highlight the toolbar button to format as code.
If we decided to handle this at “pasting” time of code, the pasted text could also still be selected in the textarea so clicking the button would be enough.
Anything else to consider?