It seems like a very high percentage of newbie posts don’t format their code properly, leading to all sorts of weird formatting errors, lots of first replies being “I can’t answer until your code is readable”, and lots of mods having to go back and help people add in backticks.
Seems to me like the best way around this would be automatically detecting when a post has code that isn’t enclosed in backticks and warning the user.
Solid. It wouldn’t take much to make the plugin catch almost all of the unformatted code here, but even if it only caught 50-60% this could be a huge boon.
It wouldn’t necessarily catch all languages (the most common ones in freeCodeCamp could) because they’re so many of them, but it would be beneficial. If I recall correctly this forum is run on Discourse though a plugin to do this may be possible. Maybe it could be an open source plugin for any Discourse forum to run
But yeah anything that helps the mods catch unformatted code would be a big plus. This just might be something to look out for (Although from the sound of it I may be the only one using this )
Modified the regexes/conditional to account for this.
That’s a great idea! Unfortunately, looking at info I can find on creating Discourse plugins, it seems like the threshold is pretty high (this “beginner’s guide”, for example, starts by recommending you read another guide that tells you how to set up the environment, which itself looks to be a fairly extensive process).
From what I can glean from the front-end using Chrome dev tools, it looks like the Rails backend serves up Ember components with dynamically generated IDs, so anything as simple as document.querySelector('#id') wouldn’t even work for selecting DOM elements. Though I guess refactoring the static JavaScript would be a piece of cake for a seasoned Rails developer.
I’ve done a few personal projects in Rails. Currently too busy to start something new, but I’ll keep it towards the top of my todo list unless someone else steps in.
Serendipitously enough, I learned Ember recently for unrelated reasons, and Discourse now has “theme components” as a lightweight, front-end only alternative to plugins, so I hacked something together. @QuincyLarson@raisedadead any chance we could get this added to the forum?
@lionel-rowe this may/may not be a good idea, and I haven’t looked at how this works, but would it be possible to target the code block button in the text box when that dialog is closed so that it could be highlighted, eg add click handler to confirm button -> onclick add inline style to code button that changes its colour to something obvious then transitions out after a second or so
I think it would be doable, though I’m not sure how easy without resorting to hacky document.querySelector stuff (which is definitely not “the Ember way”, haha). The other thing is that the message would need to change, as currently it only mentions the `backtick` method.
@raisedadead Awesome! No, I think installation should be fairly simple. The only gotcha I can think of is that theme components have to be enabled individually for each theme (light and dark).
If anyone encounters any, please let me know in this thread or open an issue on the relevant GitHub repo.