76

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


21

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


17

In my opinion, this is a great idea (if it is implemented as optional). Maybe add to the current formatting directives; something like: <!-- language:lang-c ln:true --> or as a new indicator: <!-- language:lang-c --> <!-- ln:true/yes/false/no/etc... -->


17

This makes no sense to me. Assume for example that the maximum height is 25 lines. You're suggesting a tolerance of three lines, meaning you don't get scrollbars before 28 lines -- that's like just increasing the maximum to 28 in the first place. Or possibly -- depending on how precisely you suggest to do this -- making a 29-line codeblock (with scrollbars) ...


16

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

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


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 feature is already there. Just preface each line with 4 spaces, like you would on the site. If you don't want to do this manually, press the fixed font button (which only appears when you are entering more than one line of text) or use Ctrl+K (the same shortcut as the sites' editor): And if you're not copy/pasting code in, remember you can use Shift+...


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

Unfortunately the eighth incarnation of a certain browser from Redmond has issues with max-height in conjunction with overflow: auto – under certain circumstances, it causes the issue you see. Until recently we had disabled max-height on IE8 (because of a different issue that seems since fixed). So we can either put that hack back in, causing giant ...


9

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

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

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


8

see Can we please have a place where changes to the markdown syntax are documented? There is no escaping at all in multi-backtick code. Start a code block with five backticks, and everything will appear verbatim until we find another run of (precisely) five backticks. thus you want ``\`` which will produce \ and for the record this is the same as ...


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

"Code blocks" in this context means code blocks generated by Markdown when you indent content four or more spaces. In your case, using the following would have worked as you expected: #include <yajl/yajl_parse.h> in the post editor produces #include <yajl/yajl_parse.h> in the generated content. If you use raw HTML in your post, anything ...


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

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

I think you'd need to submit a language filter to Google Code Prettify. There is no lang-regex there yet.. but there could be if someone contributed one!


6

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


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.


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