we have a lot of this Bounce not Working - Support - phpList Discuss where people post code in from some config file and all the commented out lines beginning with a hash become #bold - I guess due to the markup
is there some way to change this? It’s driving me nuts
Users will have bad results if they paste in raw code without trying to format it as code. There is no way to work around this, no magical AI that can “detect” code and format it for the user.
Two ways:
Use the ``` triple backticks at the top and bottom to mark a code block
Select the code then press ctrl+k (or use the toolbar button) to indent it all by four spaces
While it’s true that it would be very hard to impossible to actually detect something like code in pasted content and educating a user about that kind of content-handling would probably suffice it could still be possible to add some kind of “weird content paste”-detection. Let my try to explain:
Something like code-blocks is typically pasted into a response. Since discourse is automatically doing a markdown transformation for the live-preview it should be possible to verify what kind of content has been pasted. If it for example consists of mostly headlines (e.g. 10 headlines and like only 2 paragraphs) it could be possible that a user pasted text which should actually be formatted in a different way (in this case as a code-block). The editor could then show a small notification telling the user that some more work should be done, before actually saving the message.
Still this kind of detection would be very hard to implement and might even use lots of computing resources on the client, which especially for mobile devices might just be too much.
I will just have to see how this evolves. So far everyone pasting code is not using code tag and they don’t take any action despite the massive bold headlines showing up in the preview window. I might just have to hack in some kind or note some where in the post window, or make a popup notice or something. Am surprised if it is just the phpList community that have an issue with this however. Guess most people are pasting from the config.php though, which has a lot of commented out sections by nature.
For your particular site possibly an interesting approach would be to run all “text chunks” pasted in via 4-5 regexes. For PHPs case you could quite easily come up with a few regexes that would be very accurate at predicting that a chunk pasted in is PHP. Then the editor could auto wrap. This would not have any performance impact, but hooking it in would be a bit tricky.
A more general approach as proposed by @tDo may be a bit harder to come up with. Clearly if we ever shipped something like this it would have to be opt in.
Another very interesting thing @gingerling that you can try is giving users a “silver” badge first time they add a code block. It can create some incentive to learn how to use the system. (this can be easily automated with the current badge system)
I know we have discussed this before with @cpradio … we did eventually implement something like this on Stack Overflow but it is kind of tricky. And that was a site dedicated to code in a way that Discourse isn’t, necessarily.