17

There are a few existing questions that discuss the use of the <pre> tag in code blocks.

I hadn't noticed this much, if at all, before, but within the last fortnight or so there have been at least three questions where the poster included the <pre> and </pre> HTML tags in their code section. This causes the code to appear incorrectly, as anything that appears within < and > will not show, causing apparent bugs with C++ code like 'vector v' that looks like it won't compile when the posted code is really vector<int> v. Experienced Stack Overflow users have commented on the apparent (but nonexisting) bugs in the posted code.

Can a check be added to the question sanitizer that will check for a <pre> tag and tell the poster that it should not be used (or in some other way try to discourage its use)?

Update: Since I've posted this, I've seen several more instances of questions from new users having <pre> and </pre> right before and after (respectively) code indented four spaces. Where does this come from? Is something automatically adding those HTML tags?

4
  • 6
    The worst thing about <pre> is I always have to stop myself from closing it with <post> Apr 2, 2019 at 20:59
  • Can you add some examples of this? It's not entirely clear to me what you mean.
    – user247702
    Apr 3, 2019 at 13:47
  • @Stijn What sort of examples? Questions that have use <pre> formatting? I remove it when I find it. Apr 3, 2019 at 21:42
  • It's ok, I understand now after trying. You're talking about people who use <pre> instead of code formatting, I thought you were talking about people who use <pre> inside a block with code formatting.
    – user247702
    Apr 4, 2019 at 9:03

2 Answers 2

21

Can a check be added to the question sanitizer that will check for a <pre> tag and either remove it, or tell the poster that it should not be used?

We should definitely not remove <pre> tags automatically. There are legitimate reasons to use it. I myself have used <pre> to format sections of formal grammar productions. You can't format it properly in a code block because some of the formatting, such as marking a

 thingoptional 

is going to be rendered as

thing<sub>optional</sub>

Experienced SO users have commented on the apparent (but nonexisting) bugs in the posted code.

I'd expect experienced SO users to hit the "edit" button and examine the source if something looks truly weird. And the same users can then apply their editing privileges to improve the post. It's something we often have to do with newcomers anyway.

2
  • 2
    I've removed the, um, "remove it" suggestion. The clues that a code block has a <pre> marker in it are subtle: extra indentation and a lack of syntax coloring. They can be easy to miss. Not all high rep users are fully aware of all the editing facilities. One of my edits to remove the pre block generated a comment along the lines of "how'd you know to add that stuff to the code", along with several follow up ones before that (high rep) user realized about the side-by-side markdown view. Apr 1, 2019 at 15:59
  • 1
    @1201ProgramAlarm - It's a good practical feature request now, upped. As for the comments you got, I'd say those people didn't look at the edit close enough, not as markdown anyway. Maybe there should better diff indicators, idk. Anyway, I'll leave this answer in case someone comes along and offers something along your first version. Apr 1, 2019 at 16:09
0

No, there's nothing that explicitly tell the user to use <pre>...</pre> to format multiline code (except some "obscure" Meta.SE posts). In the help of guided mode, there's only information about using 4-space indent or code fences. (that should already count as "discouraging")

However (I guess) the user may not read them and try different ways until it looks "somewhat right", and they may try pre-tag if they know some HTML.

Also there's no formatting toolbar (which contains the {} button used to format code) in the guided mode.

They can only notice that using pre tags cause problem if they check the preview very carefully (most users don't)


It is useful for the system to give warnings such as "Your code contains wrong HTML" if there are some wrong tags such as <iostream> or <int> in the post. Still doesn't help if the user paste HTML code inside pre-tag.

0

You must log in to answer this question.

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