Forum Suggestion: Unformatted Code Warning

Forum Suggestion: Unformatted Code Warning
0
#1

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.

Edit: Discourse theme component

7 Likes
#2

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.

2 Likes
#3

I like this idea, but isn’t “[code]” and “[\code]” also a valid way of formatting code here?

#4

Doesn’t work for me :confused:

#5

I know that’s used by Phpbb forum.

#6

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 :slight_smile:

1 Like
#7
var a=10;

Sorry the closing tag is [/code]

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 :slight_smile: )

1 Like
#8

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.

Wonder if we have any of those around here? :thinking:

#9

This would be an interesting idea on freeCodeCamp’s open source for good.

#10

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.

2 Likes
How is the forum doing?
#11

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?

1 Like
#12

Yes, as soon as we can get more confirmation that this would be help.

#13

Definitely + 1 on this.

@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

#14

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.

1 Like
#15

Honestly, even if it only catches a relatively small portion of cases it would be a huge help as long as it doesn’t hit a bunch of false positives.

#16

Seems like a reasonable idea, though I think Ariel has a good point, false positives may make the situation annoying for users.

#17

Thanks for the feedback everyone.

I’ll have this plugin deployed in our next maintenance run first thing in morning my time around 11:00 am (UTC+5:30)

@lionel-rowe
Do I have to do anything additional apart from the installation instructions you already have?

#18

@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.

2 Likes
#19

Hi Everyone!

I have installed the component on the themes, can we have a few people test it out and let us know of the feedback.

/cc @moderators

Thanks.

2 Likes
#20

I did not get any warning with my post.

I may be misunderstanding what should trigger the warning.