-11

Something I've noticed when editing the first posts for a lot of people is that many people use the 3 backticks method to enclose a code block that they copy and paste in.

Since the first line is supposed to be for syntax highlighting, if there isn't a newline between the backticks and the first line of code, it gets swallowed. For example, this code :

```console.log("this is line 1")
console.log("this is line 2")
```

Will result in :

console.log("this is line 2")

The examples in https://stackoverflow.com/help/formatting clearly show that you are supposed to have newlines, but for a new user copying and pasting their code, this might not come across.

So I guess my questions are :

  • Is there anything that can be done to make it clearer to people that their code isn't being formatted properly?
  • Can an error be surfaced that the first line cannot be parsed as the language hint for the following block?
  • Or can the markdown be changed to automatically include a newline so this line isn't lost if it's clear that the first line isn't a language hint?
  • Or is this a problem for new users that exists between the keyboard and the chair?
12
  • 5
    Or can the markdown be changed to automatically include a newline so this line isn't lost? I doubt it as normally the language-hint will go directly after the three ticks.
    – rene
    Jan 25, 2022 at 19:10
  • 1
    +1 - I agree that something like the error you've suggested could be implemented. I haven't yet noticed any content being changed automatically by/in any StackOverflow tool/section, probably it's a standard that's followed, but yes, that can also be changed if needed. The post editor is not up to the mark, at least to me it seems so because it's not properly functional; for example, many submissions would be blocked by the system showing errors like "Your post is mostly code..." while it's sometimes not. It can be improved a lot. Jan 25, 2022 at 19:16
  • 1
    I've seen many posts whose parts are ignored by the system, so yes, this issue should be addressed IMHO because if new users' contributions are taken into consideration, then this could increase participation and activity and the clarity of the usage of the site's tools. Jan 25, 2022 at 19:21
  • @rene, I know. One thought could be that if the first line cannot be parsed as the language-hint, it does not swallow the line. But this may be an unnecessary complication to the markdown renderer, but I just spit-balling ideas at this point.
    – Kylaaa
    Jan 25, 2022 at 19:25
  • 3
    "Is there anything that can be done to make it clearer to people that their code isn't being formatted properly?" - People can proof read their post like they're supposed to and say "Oh, a line of my code is missing" Jan 25, 2022 at 19:34
  • 2
    I doubt there's any system that people who don't look at their own post cannot find a way to mess up.
    – khelwood
    Jan 25, 2022 at 19:38
  • @Nick and khelwood, certainly, I bring up this up because I've seen this problem a few times and wanted to discuss possible ways to improve the UI. The answer could just be: "no, the tools are fine, users just aren't using them"
    – Kylaaa
    Jan 25, 2022 at 19:41
  • This looks like a duplicate of meta.stackoverflow.com/q/391467/6083675. But also an important bit of context is that the first line is where you put the syntax highlighting language, so it's not as simple as forcing it to be blank.
    – Laurel
    Jan 25, 2022 at 19:59
  • Thank you for sharing the link @Laurel, I did some searching to see if this has already been asked, but couldn't find anything. I'll close the question as a duplicate in a bit
    – Kylaaa
    Jan 25, 2022 at 20:08
  • 3
    Voting on any of the Meta sites is different than on main sites. On Meta sites, votes much more strongly represent people's agreement or disagreement with the position expressed in the post, rather than just an expression of people's opinion on the quality of the post, although they can also reflect that. On bug reports, voting can represent people being able to reproduce the issue, or not. As a consequence, downvotes on Meta should not be automatically considered to mean that there are problems with the post. On the other hand, it doesn't hurt to double-check that the post quality is good.
    – Makyen Mod
    Jan 25, 2022 at 20:24
  • @Makyen, thank you for the explanation. This is my first meta post and wasn't sure about the etiquette.
    – Kylaaa
    Jan 25, 2022 at 20:58
  • 1
    Agreed. The system really ought to detect the most common user errors, especially if the result is hidden content. The same goes for content enclosed in <> (often hidden as an unknown HTML tag). 10 years can pass before it is discovered by an editor. Jan 26, 2022 at 15:31

1 Answer 1

5

This isn't a problem that we would like the team to spend development time on in the next 6 to 8 weeks.

Code fences came into effect with the switch to Common Mark in June 2020. If you believe my query just over 10,000 questions were asked by "in-experienced" users (by my definition users < 100 rep) while in that same period 1,695,011 questions were asked by that same population. Roughly 0,5% of the askers might run into that issue.

As the preview behaves correctly, the OP has plenty of opportunity to notice and rectify their mishap.

enter image description here

I don't think we need more tooling to make life easier of those that are so much in a hurry that they don't spot missing relevant bits and pieces from code they could dream by now.

I would rather see development time being spent on fixing some difficult to parse / diagnose errors in the review phase, like the infamous It looks like your post is mostly code

1
  • Fair enough, thank you for the write up.
    – Kylaaa
    Jan 25, 2022 at 21:01

Not the answer you're looking for? Browse other questions tagged .