87

This feature request (and it being declined) is almost 6 years old. I'd appreciate if this could be reconsidered. There are a lot of use cases that have been mentioned but I don't even think this should be focused on code blocks. Since code blocks get a scrollbar anyway you can already fill your 30k character limit with a single code block, without taking up ...


18

We've implemented something like this here: Feedback requested: Runnable code snippets in questions and answers We thought about just embedding JSFiddle, but we really wanted to make sure that all the code was natively contained in the post itself instead of reliant on a third party. Also there were some license concerns. We decided to just roll our own ...


15

I'm not generally a fan of box text selection, but I can see how it might occasionally be useful in the context of Stack Overflow. Still, I think it would probably be more trouble than it's worth. I anticipate people getting confused over the fact that there are two ways to select text, especially if/when they try to use one and end up using the other. We'...


13

You mean a collapsed code-snippet like this? alert('Most folded code ever!');


13

The <details> tag does exactly this One main criticism for this feature request was that a new syntax had to be defined. This is provided by the HTML5 standard with the <details> and <summary> tags. Example <details> <summary>Some details</summary> <p>More info about the details.</p> </details> Shows ...


12

We don't want to encourage users to be posting very large blocks of code, to the point that they would need to leverage a feature like this. If you are coming across questions with this much code then the solution is to remove the unnecessary code, or encourage the author to do so. If answers are containing that much code then it's a sign that the ...


11

Apparently_the_code_that_wraps_header_text_can't_handle_long_lines_without_spaces. This happens whether prefixing the text with a '#' character or underlining with '='. It looks like h2 headers are affected as well, though of course they have to have more text. Update: Hey! Now it's fixed! Good work team!


9

If line numbering is really so problematic (IMO not), what about debugger-like break points? Not a complete solution, but at least very "visual". <!-- language: lang-java --> <!-- break color:red --> @Override public int add(int num1, int num2) { <!-- break:"here" color:yellow --> return num1 + num2; } And the ...


9

You can add line numbers yourself, for example using Notepad++ (like described here): Notepad++ can do that by using the TextFX plugin. Select the lines and then select TextFX->TextFX Tools->Insert Line Numbers from the menu bar. Then search&replace ^0+([0-9]+)\s with \1 to remove trailing 0s However, anyone who would like to copy the text, ...


8

You can make sure Prettify is loaded by invoking StackExchange.using('prettify', <callback>) in your script, which will then guarantee that PR is available in the global scope. I did this a while ago as part of a quick proof-of-concept for Mathematica highlighting (which may or may not work correctly now, depending on whether or not anything's changed)...


8

Besides that just typo questions should be flagged rather than answered, you can always (almost?) use (language specific) comments to highlight your code changes: Ah, just a typo. You meant: <html><!-- <<<<<<<<< <htwl> is mistyped --> <body> document </body> </html> Not ...


7

You simply need to indent those code lines a bit (8 spaces) more: element 1 element 2 // code here, 8 spaces element 3, this has subelements sub element 1 sub element 2 this one has a code block #!Shell, 12 spaces line of code 1 line of code 2 line of code 3 And four more for here: # a whole bunch of spaces sub element 3 element 4


7

I’d like to provide (but one) example of a valid reason for providing collapsible elements: log files. Sometimes you must provide logs for analysis, and often they tend to be lengthy and cannot be pared down without losing potentially valuable information. Yet, there is no reason to have them be full-length by default. For example, someone may be able to ...


7

Perhaps we should consider improvements to the posting interface as well: More explicit ways to say "This is code, and thus covered under the code license." Just using code formatting as a determination seems too likely to include content that shouldn't be included, and leave out content that should. A way to (easily) say "this is code, and I'm releasing it ...


6

I found a helpful userscript: SO - Code line nums The script toggles line numbers of code boxes when you click on the #L symbol in its top right corner. (It refers to mdev.me, so script blocking has probably to be adjusted)


6

You don't. Leave a comment, or leave it to people with 2k+ rep to make the edit. Suggested edits require review, and thus time from several people to review the change. To limit the size of the review queue only suggested edits have a minimal requirement of being non-trivial. High-rep users can make trivial edits at will as they can make the edit directly ...


6

Thanks for reporting this! It's fixed and will go out in the next update:


6

That's not a bad idea, but I suggest to disable this feature after a user has a total question score of 15 on Meta, because if a user has a total question score of 15, I suppose that he/she knows how Meta works.


6

It's not made obvious* but you need to tap code blocks to view them in full. That will open them up for viewing and they'll be scrollable. * It really needs to be since you're not the first to be confused about this, and there's nothing suggesting you can do this. This is actually bad user experience design at the moment.


6

It seems to be a bug in the way the Markdown parser handles code that is both indented and wrapped in <pre> tags. Specifically, the source for the original version of the question looks like this: <PRE> SELECT SECU.SECID, SECU.DENOM, [...] AND SECU.VDATE <= '12/26/2013' AND W1.OBSSCHEDID = ...


6

Indeed, the Markdown parser seems to treat any lines that only contain spaces and tabs as empty. Normally, I suspect this would be considered a feature: having the formatting of your post depend on whether or not a blank-looking line is actually empty or has spaces in it could get really annoying. For the rare occasions where you do need to start or end a ...


6

While I agree, that the visual effect is nice, I doubt this will be fixed/changed for these reasons: It's abuse of formatting. As Cody Gray already said, this uses a combination of markup, that is not intended for this task. This might lead to accessibility problems for users who can't use a standard browser. It is unnecessary. You can use normal headings ...


5

The algorithm that looks for what it thinks is code not properly formatted as code ought to ignore any content inside of <pre> tags. As a workaround, until this is (hopefully) changed, you can format those blocks as code to submit the post, and then remove the code formatting in an edit. As much as it pains me to mention this exploit; since it is ...


5

I edit a LOT of posts primarily to remove unnecessary horizontal scrollbars from code samples. It's not that hard to format code for a vertical layout; most people are just too lazy or indifferent to do so. Also, as I use mobile more and more, making the code snippets even wider is not going to be very productive. As it is I have a very difficult time ...


5

They could rig up something like this, they already use these interface elements elsewhere in the site: So of course, hitting the arrow would bring up the full code block. I'd actually do it somewhat differently in order to not lose width on the code block, but something along these lines would be helpful.


5

What you have there is already rather ok, depending on the amount of code. It doesn't look too bad. Some description while (stuff) { doit(); } More stuff The other option is to put a code block inside the quotes, which requires five spaces after the >: Some description while (stuff) { doit(); } More stuff


5

Ok, I'm dumb. One just needs to click on the code


5

The question you're trying to post contains items which look like a JavaScript injection to StackOverflow itself. If you format the code portion of your question as code (prefixed by 4 spaces), it should be fine. In the preview it should looke like this: <script>alert("This is my evil code which I don't want to execute on Stackoverflow")</script>...


5

If you really need to bold text or other formatting inside a code block, then you have to use the plain HTML to create the code block, as the Markdown parser itself will not parse anything further inside a code block. So this code: <pre><code>However, I have another option. I can use a code block that works very nicely but I can not <b>...


Only top voted, non community-wiki answers of a minimum length are eligible