Forum Suggestion: Unformatted Code Warning

Forum Suggestion: Unformatted Code Warning
0

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

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

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

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.

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

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?

@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

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

I did not get any warning with my post.

I may be misunderstanding what should trigger the warning.

I think we have set this to not trigger for users above trust level of 3 (which makes it less annoying).

To test it out, you probably need to sign up with a new account (throw away one)?

@raisedadead Woohoo! Confirmed working.

@RandellDawson The default trust level threshold is set to 3. IIRC mods are always trust level 4 (the maximum).

For people ≥ trust level 3, you can set this in the browser console to test:

localStorage.ucd_forceShowWarning = '1'

That will override any trust level settings and also the “do not show again” setting.

All of those settings are currently per device, so you’d need to set it separately for desktop and mobile.

You should then be able to trigger the warning by starting a new thread and typing func() or similar without backticks. If you’re worried about accidentally creating junk threads, leave the title blank, and you shouldn’t be able to post anyway (but will still trigger the unformatted code warning).

2 Likes

I noticed Build a Product Landing Page video 2 still does not have backticks surrounding the code. I had to fix it for the user.

I think that may be (possibly?) due to the <code> tags surrounding the UA string triggering a false alarm and the user dismissing the warning.

I can blanket whitelist text within <code> tags if needed, but actually I wonder if that’s a good idea — it’s not really the correct way to format code on Discourse. For example, <code><span></span></code> renders as that exact HTML, when the intention was almost certainly to render <code>&lt;span&gt;&lt;/span&gt;</code> instead.

[Edit: Opened a PR against this on the fCC repo]

Is the warning for only when a poster starts a thread or does it pop up when a person replies to a thread with code?

below is test only:

no backticks

got the warning for the above line.

Huh… you can use

<h2></h2>

but can’t color it red green or whatever…

Got warning , clicked “Fix Code” and fixed=

  <h1> Testing Time</h1>

func blahbla()
{
  if(a=2)
  {
    console.log("Yay")
 }
else
  {
    console.log("try again...")
   }
}

edited to add this, clicked save Edit, got warning, clicked “Post anyway”:

func Yay_oops()
{
for (var i = 0, i < arr.length; i++)

*mistake intentional

Yep it does work when you try to reply with unformatted code as well when I hit Reply.

(yes I fixed the code lol)

I had the warning when posting the following url:

I’ve had a few false positives like this, though I suppose it’s better to have false positives than false negatives. I’m going to just click to never show again I think.

1 Like

Thanks for the bug report!

There are always tradeoffs, but I’m trying to err on the side of annoying people less. This case is due to underscores in the path part of the URL making it “look like” a variable name. I’ll fix and add tests for it in the next release.

Have all your other false positives been URLs? Could you list them too?

If I recall correctly some were from inline code such as x = 5 or

Object.prototype.map() and things like that

but if I can’t replicate it here then don’t worry about it I guess, if I come across any more I’ll post them here

Saying O(n) without putting it in backticks can trip it sometimes

Not sure how I feel about that but I suppose I can live with it, I’m guessing you probably don’t want to special case it

Sorry for the slow reply, glad you got it sorted :slight_smile: triggered it

Might be worth checking all of the emoticons against the detection script

Thanks for all the feedback! All bugs thus far reported should be fixed as of v0.8 (should be online shortly).