22

I've seen too many newbies hit the "quote" button instead of the "code" button while posting. This is much worse than if they just left the code inline, because the quote button rewraps all the text and saves the post with mangled code.

For example, here's some (bad) C++:

class X{};

X& foo() {
    X x;
    return x;
}
int main() {
    X &x = foo();
}

and some quote-mangled C++:

> class X{};
> 
> X& foo() {    X x;    return x; } int main() {    X &x = foo(); }

Once they've saved the post, it is impossible to recover the original formatted code without a substantial amount of effort. One user used it on a stack trace about 100 lines long producing an unreadable mess, not realizing that "quote" was the wrong function for a nicely-formatted stacktrace.

I understand the holdover from email, but it seems unnecessary for StackOverflow to rewrap given that quoted text renders essentially identically to unquoted text (aside from being enclosed in a <blockquote>). It seems to me it would be easier to have the quote button just prefix to each selected line, kind of like how the code button prefixes     , and leave it at that.

So the question is: why does the quote button have to rewrap text when you push the button?


For reference, here's how quoted text appears, first using the quote button and second by manually prefixing :

class X{};

X& foo() { X x; return x; } int main() { X &x = foo(); }

and

class X{};

X& foo() { X x; return x; } int main() { X &x = foo(); }

The appearance is identical, but the latter quote can actually be reversed into proper code later on.

2
  • 1
    I'm annoyed by the contraction of lines by the Quote tool too, but not due to code mixups. Usually I want my quotes line-break preserved. (For code mixups...if the OP can't be bothered to research the maddeningly simple text box control: Downvote.)
    – user7116
    Commented Mar 11, 2013 at 14:39
  • Sometimes the OP can't tell that they've destroyed the code. This is commonly the case with "walls of text": debug output, stack traces, variable dumps, etc., especially where they may be unfamiliar to the OP (e.g. something that was requested by a commenter).
    – nneonneo
    Commented Mar 11, 2013 at 17:27

1 Answer 1

1

Clarification/update first:

The "reflow the text when you click blockquote" is a deliberate feature, intended to improve the readability on quoted text. Anecdotally, it seems we have not only retained this WMD feature, but have even increased the limits on what it will reflow. This does mean that "blockquote", "blockquote" (i.e. enable then disable) is not side-effect free, but ultimately the editor includes full undo capability, both on the button-bar and via standard hotkeys.


It looks like you are starting with non-code, i.e.

class X{};

X& foo() {
  X x;
  return x;
}
int main() {
  X &x = foo();
}

enter image description here

which will indeed break things, because it doesn't assume that is code. If, however, you start with code-indenting, then it respects it; i.e. start with:

enter image description here

then it gets it right and correctly indents it as code. Now; as to whether it should re-flow a paragraph when you hit "quote" - in the intended usage that won't change the result:

enter image description here

Your last example is wrong simply because it does not use markdown correctly. You can quote code, but you still need code spacing. Your markdown is:

> class X{};
> 
> X& foo() {
>     X x;
>     return x;
> }
> int main() {
>     X &x = foo();
> }

But it is required to be:

>     class X{};
>     
>     X& foo() {
>         X x;
>         return x;
>     }
>     int main() {
>         X &x = foo();
>     }
11
  • 1
    This seems to be the OP's point, that the poster inadvertently clicks the quote button instead of the code button (and then for whatever reason can't be bothered to undo their mistake), making it difficult for subsequent editors to correct things.
    – Tim Stone
    Commented Mar 11, 2013 at 12:48
  • 2
    @Tim I don't think we can ever cater for "can't be bothered to undo their mistake". To take that reductio ad absurdum, should we automatically compensate for every mistake? What about if they select a block of text and start typing (over-writing it), and can't be bothered to correct it? The editor does, however, include undo functionality including standard hot-key support. Commented Mar 11, 2013 at 12:50
  • Oh, I agree, I was just simply pointing out what the OP's position was. Choosing to not wrap the lines when quoting would make the general case of editing quotes more difficult, although I suppose the editor could opt to not attempt to condense too-short lines...I can't decide if that would be problematic or not.
    – Tim Stone
    Commented Mar 11, 2013 at 12:55
  • Thanks for the response. I don't think this answers the question, though. I'm aware that rewrapping doesn't occur if you start with code, but I'm specifically referring to cases where quote is used instead of code. In the stack trace example, the user was faced with a giant wall of text either way and was unable to tell that the stack trace was mangled.
    – nneonneo
    Commented Mar 11, 2013 at 17:23
  • The main question is: why does the quote button have to rewrap text? We don't rewrap posts otherwise, so why do we have to rewrap quotes to make editing quotes easier? If anything, it makes editing quotes sometimes more difficult because a single line becomes split across multiple lines.
    – nneonneo
    Commented Mar 11, 2013 at 17:25
  • By the way, I am fully aware you can put code in a quote. This question does not concern that usage. The examples at the end are about showing that rewrapping is unnecessary from a rendering point of view. The last quoted block can easily be repaired back into a functional code block, while the second-to-last block is mangled. They render the same.
    – nneonneo
    Commented Mar 11, 2013 at 17:34
  • @nneonneo ok; I think I see what your priority is; let me check the reasons for that Commented Mar 11, 2013 at 19:26
  • Any update on this? Just curious.
    – nneonneo
    Commented Mar 26, 2013 at 21:38
  • @nneonneo yes, will edit Commented Mar 27, 2013 at 9:52
  • IMO, users in general have bigger problems than not knowing the difference between a blockquote and a code block, such as not knowing the difference between an answer and a question. Commented Mar 27, 2013 at 10:06
  • I specifically want to be able to quote code. That is, I have some code between triple-backticks that's been cited from a different source, I select the text, press the quote button, and the formatting gets destroyed. That's terrible.
    – jamesdlin
    Commented Jun 15, 2021 at 5:58

You must log in to answer this question.

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