80

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 ...


51

The standard way of including code is by indenting it all with four spaces: like so (literal text: "    like so") Or, for inline blocks, surrounding it with backticks like so (literal text: "`like so`"). As you've seen, using <pre><code> has unexpected limitations and also doesn't support nifty stuff like automatic ...


22

This is a hugely helpful idea for the [R] tag and I suspect any other statistics/data-heavy tags as well. We strongly recommend our users include sample data: How to make a great R reproducible example? Often due to the nature of the statistical beast even carefully culled sample data is unwieldy. For instance this well-conceived post: Dealing with ...


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'...


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

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> ...


11

I wrote a greasemonkey/chrome user script about a year ago that does this. It's up on stackapps if you're interested. From the link, its features are: Click the code region to have it expand to whatever size it needs Removes vertical scroll altogether (expands to full height) Intelligently expands horizontally Maxes out at window width so as not to make ...


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!


10

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


9

I know this is an old thread, but I thought I would add an updated answer as I recently decided to implement a convention for embedding jsFiddles into Markdown posts (while remaining sanitized) The convention I came up with was the following: // render jsFiddle embed iframe with default options $[http://jsfiddle.net/uzMPU/] // render jsFiddle embed iframe ...


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 get markdown help without having to come to meta by clicking the ? while editing and then clicking on the advanced help >> link that appears right under it: You can also click on the edit link of any post that has formatting you wish to emulate, and see how it was done by reviewing the code behind the answer - which will show the markup/markdown ...


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

I reported the same issue via the 'contact us' link at the bottom of Stack Overflow. I haven't gotten a response, but I imagine they are working on it. When you work on the cutting edge, expect blood! :) I quit Safari and looked at its info window in the Finder. It was in 32-bit mode (I set it as 32-bit for some reason which escapes me at the present moment)...


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

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

It would also be useful to support collapsed sections of text or images. Example usages: On one of the mathematical Stack Exchange sites, I might write an answer which contains a long but relatively uninteresting proof of one of the claims. Since the proof is needed for completeness but may be a detour from the main point, I want it to be collapsed until an ...


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 ...


5

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)


5

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 ...


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

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 ...


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