Questions tagged [code-formatting]

For posts about making code appear correctly in questions, answers and their comments.

Filter by
Sorted by
Tagged with
301 votes
7 answers
3k views

Change the code block button from inserting indentation to triple-backticks

Working with indentation as formatting is a very annoying experience and it's clear that new users have a problem with it. Also, many users seem to be in support for triple-backticks. There are many ...
Ted Klein Bergman's user avatar
287 votes
5 answers
3k views

Markdown editor indent and outdent functionality

No tab key support It has been a while for me here on Stack Overflow, and from the beginning of my experience I've noticed something which still leaves a bad taste in my mouth when I create and edit ...
Marco Bonelli's user avatar
263 votes
18 answers
5k views

Let's have a "Tidy Up" button!

Code formatting is one of the major contributor to review queue. I've seen "Tidy Up" buttons in .NET Fiddle and JSFiddle and Current Situation I currently have to go to JSFiddle, paste my code, ...
Amit Joki's user avatar
  • 58.8k
258 votes
1 answer
81k views

How do I format my code blocks?

How do I post text so that it is formatted as code? What do I need to do so that my code shows up properly—not escaped or removed—when posted? And how do I get the correct syntax ...
228 votes
4 answers
2k views

Can we have darker <code> blocks in <blockquotes>?

Currently, blockquotes, inline code and code blocks have the same background colour. That doesn't work very well when you have a code block or inline code in a block quote. Sure, the ...
naught101's user avatar
  • 19.1k
169 votes
2 answers
170k views

Why should I not upload images of code/data/errors?

I am new to Stack Overflow, and I have asked about 5 questions so far. I have uploaded images of my code on most of my questions. On two separate occasions, two different users advised me not to ...
169 votes
5 answers
2k views

Could Stack Overflow support GitHub flavored markdown?

Stack Overflow already uses its own markdown extensions, and there is already overlap with GitHub Flavored Markdown. There are very few additional pieces of syntax left to bridge the gap completely. ...
mmocny's user avatar
  • 8,805
155 votes
1 answer
2k views

Collapsible Code Markup

Background When answering questions on SO I generally like to ensure that my code is runnable by including sample data, so someone can copy, paste, and run it, seeing exactly what I'd proposed. ...
JohnLBevan's user avatar
  • 23.6k
149 votes
6 answers
3k views

How can we avoid "overhang" code indentation?

The single most common formatting mistake I see (many, many times per day) is code like this: string firstLineIsFine = "yup"; if (firstLineIsFine == "yup") { ...
Jon Skeet's user avatar
  • 1.5m
118 votes
2 answers
2k views

Let's fork Google Prettify library! [closed]

Let's add our own bells and whistles to the library. Especially, I'd like to see code highlighting (anything will do), which is clearly needed and would be a great way to emphasise the important parts....
Bohemian's user avatar
  • 419k
114 votes
5 answers
4k views

When is it okay to edit posts for "Code Formatting?"

I recently posted this answer: Continuing the most outer loop from the most nested one It contains a block of Java code, written by me, currently under an edit war between myself and the original ...
Raven Dreamer's user avatar
108 votes
3 answers
17k views

How does the highlight.js change affect Stack Overflow specifically?

Update 2020-09-24 This is now live network-wide (including Stack Overflow). Update This is now live on Meta Stack Exchange and Meta Stack Overflow. Any bugs and feedback can be posted on the main post ...
Ben Kelly's user avatar
  • 101
100 votes
9 answers
3k views

Why is there no line numbering in code sections?

Many times users paste long code and those who want to refer to a specific line refer to it by its content, which can be misleading or cumbersome if the content appears elsewhere or the line is long. ...
user1803551's user avatar
  • 13.2k
91 votes
3 answers
3k views

Should there be a warning for code containing bidirectional Unicode text?

Articles on the misuse of bidirectional text have been making the rounds recently. Put simply, this abuses the concept of bidirectional Unicode text to compile something different from what it ...
Anon Coward's user avatar
  • 10.4k
88 votes
3 answers
3k views

How should compiler errors, linker errors and logs be formatted?

How should I format compiler errors when I want to put them in code? Should they be in a code section: dk2.cpp: In function 'int main()': dk2.cpp:29:28: error: no matching function for call to '...
sashoalm's user avatar
  • 77.3k
86 votes
2 answers
8k views

When should code formatting be used for non-code text?

I reviewed an edit that did no change to the post apart from introducing code formatting like this to words that aren't code, such as iOS and Android (while curiously leaving Delphi untouched). I didn'...
82 votes
0 answers
766 views

Can the editor have a dialog for adding code?

Regarding screenshots of code, Shog9 said this back in February: Honestly, @Tanner, this is probably one of those situations where if we want to do better than a text warning we have to dig into ...
BSMP's user avatar
  • 4,707
80 votes
2 answers
2k views

Do not remove trailing spaces in inline code

If I write ` a b c ` Markdown renders it as a b c Inline code should not be trimmed. It's still code, and the spaces can be relevant. Example: [...] so .2 and .3 are invalid ...
Oriol's user avatar
  • 281k
77 votes
1 answer
611 views

"=>" causes bad autoindentation in code snippets

Paste this JS code in the stack snippet editor: (function() { console.log(foo + "=>"); })(); Select it all with ctrl+A and use shift+tab to autoindent. The code becomes (function() { console....
Oriol's user avatar
  • 281k
75 votes
1 answer
1k views

Can we add a button "Format with Prettier" to the toolbar when editing posts?

Prettier supports formatting Markdown text and a bunch of languages. Can we add it as a button or format on save? All the posts will have a unified look and feel, without the extra spaces, wrong ...
Lipis's user avatar
  • 21.6k
71 votes
3 answers
2k views

Don't wrap code at hyphen

It is common when writing Haskell questions to write language extensions beginning with - as code. The editor seems to think this is a hyphenated word that it can split between two lines, even though ...
crockeea's user avatar
  • 21.7k
70 votes
2 answers
742 views

Indent 8 spaces when clicking the Code Sample button after a list item

In order to format code in a numbered or bulleted list, you need to indent it eight spaces instead of the usual four. This is by design. If the Sample Code button is pressed when a user has a block ...
Suragch's user avatar
  • 499k
70 votes
2 answers
870 views

Code blocks surrounded by single backtick then triple backticks

In the past couple of days I've noticed a number of questions that have their code blocks entered like: ` ``` code ``` ` There's a line with a single backtick, then the normal triple-backtick code ...
Barmar's user avatar
  • 764k
69 votes
2 answers
15k views

Triple backticks for code blocks (like GitHub flavored markdown) [duplicate]

It would really be useful if Stack Overflow supported GitHub's style of triple backticks for code blocks. Current Stack Overflow requires indenting every line. That means if I have code like this: ...
gman's user avatar
  • 104k
68 votes
6 answers
2k views

Should code be edited so that it is visible rather than being in one long line?

In many instances, I have seen code that is poorly formatted or all in one line (like below using R). Is it appropriate to edit the code so that it is more legible? I know in some instances these are ...
AndrewGB's user avatar
  • 16.6k
68 votes
0 answers
634 views

Discourage (and possibly auto-replace) code spans spanning multiple lines with code block

I'm making this a feature-request to implement a solution to the problem described in this question: Why are inline code spans across multiple lines allowed? From time to time, I see some code ...
SeinopSys's user avatar
  • 8,867
64 votes
5 answers
974 views

Misunderstanding how the "make code sample" button works

It seems that some people don't understand how the "make code sample" button {} works. I encounter posts like this all the time: The problem appears to be that they first click {}, and then ...
Jonathon Reinhart's user avatar
57 votes
5 answers
1k views

A way to reduce the number of questions with only images?

The problem: This is something that I particularly see a lot in the pandas tag. People will ask questions that look something like the following: I have the following dataframe <link to imgur ...
noah's user avatar
  • 2,686
57 votes
6 answers
2k views

Are more people using the inline backtick option for code blocks and, if so, why and what do we do about it?

If someone uses backticks for a whole code block, you end up with ugly multi-line bland emphasis that won't do any syntax highlighting, like this: string foo = "hello world"; Console.WriteLine(foo); ...
Joel Coehoorn's user avatar
55 votes
2 answers
914 views

New Stack Snippets design requires more horizontal scrolling through code

I can't see the new Stack Snippet layout as an improvement. The window is now narrower, with wasted space around it, making it harder to format code to not require horizontal scrolling, especially if ...
m69 ''snarky and unwelcoming'''s user avatar
54 votes
1 answer
3k views

How do I remove excess indentation on my code blocks?

This happens to me a lot on Stack Overflow: I paste in some code, but it is indented to the right far too much. This requires cumbersome horizontal scrolling to view all of the code, and oftentimes ...
Alexander Mills's user avatar
54 votes
1 answer
737 views

Support CommonMark fenced code blocks

It would be great to add support for fenced code blocks as defined in the CommonMark spec: it would be consistent with GitHub code blocks it would be much more practical to type, instead of having to ...
Matthieu Napoli's user avatar
54 votes
0 answers
730 views

Code formatting article in help center is confusing

Prompted by Does inline code span require HTML escaping?, I took a look at /help/formatting. While it's mostly accurate, there is a fair amount of ambiguous terminology and subtle inaccuracies. I've ...
Jason C's user avatar
  • 39.6k
52 votes
14 answers
14k views

Cannot figure why am getting "Your post appears to contain code that is not properly formatted"

I tried changing every section in the code below (using/not using four character indentation with/without pre). I also tried removing the formatting and the line separators on the list. Nothing helps -...
boardrider's user avatar
  • 6,055
52 votes
3 answers
1k views

Should we make the {} button add ``` instead of four spaces?

I didn't know that the three backticks code fence feature was implemented until I asked this question. This is a great new feature! I think the code block button in the editor (the {} button) should ...
Sweeper's user avatar
  • 238k
52 votes
2 answers
1k views

Creating "expandable" code blocks

I just wrote a question on Stack Overflow. Now I was thinking if it would be a good idea to include the full stacktrace to the error or just the error message. From my point of view, the stacktrace ...
Jürgen Steinblock's user avatar
50 votes
2 answers
1k views

Cannot edit post due to code [duplicate]

I keep seeing these posts that are mostly code wrapped by a few lines of text, aforesaid code being formatted terribly. If I try to improve their post and edit the code I get the error: it looks ...
MD XF's user avatar
  • 6,411
50 votes
0 answers
721 views

Pressing the quote button destroys text in code fences

Let's say I want to quote this shell code in a post: foo=bar echo $foo First I put it in code fences so it shows up as code: ```sh foo=bar echo $foo ``` Then to quote it, I select it and either ...
wjandrea's user avatar
  • 30.5k
49 votes
1 answer
647 views

Code wrapped inside headers is too small

Any inline code block inside a header gets rendered with the same font-size as normal paragraphs, and this makes code look very inappropriate inside headers. For example, the following Markdown: ...
Marco Bonelli's user avatar
49 votes
1 answer
590 views

Code font size of the new layout looks smaller than it was in web browser

I just found out that Stack Overflow has a new outfit. I don't want to bother with the aesthetic part but I do care about the font size of the code block: I'll use Why is it faster to process a ...
Tay2510's user avatar
  • 5,898
48 votes
2 answers
723 views

Code block inside quote block formatting is broken on meta

After seeing How to include code inside a quotation? and its associated answer, I saw that a code block inside a quote block formatting is broken on meta. If we use the example from the answer on meta ...
NathanOliver's user avatar
44 votes
3 answers
904 views

How should we handle edits adding unnecessary inline `code` formatting?

I've seen a few (more than a few, no links at the moment) suggested edits where the user simply wants to add code tags as they believe code is needed for every proper noun on Stack Overflow. The ...
nanofarad's user avatar
  • 40.9k
44 votes
3 answers
1k views

Is this formatting overuse?

A particular user frequents the same tag(s) I do so I see his answers a lot. I find many of them practically unreadable due to all the bold, code, links, etc. formatting that he jams into such a small ...
JeffC's user avatar
  • 23.6k
43 votes
3 answers
3k views

Why must jsfiddle.net links be accompanied by code while there are no restrictions for others like codepen.io?

I noticed that when you post a link from jsfiddle.net without some code in your answer or question the system doesn't allow you, and a relevant message is displayed. But when you include a link from ...
laaposto's user avatar
  • 12k
42 votes
2 answers
768 views

Rejected Edit that Formatted Code to be Visible

I had an edit rejected, where I was mostly formatting the post so that the code would appear as code. Some of it wasn't even showing as visible before my edit. (One piece of code just appeared as a ...
SuperBiasedMan's user avatar
41 votes
2 answers
1k views

Spaces around code keywords

An answer had no spaces around the keywords, and displayed as expected in my browser (Grazing, IOS 8; but Safari is similar). I fixed it, but the author rolled back the edit, and left a comment that ...
tripleee's user avatar
  • 182k
41 votes
7 answers
679 views

Is it appropriate to ask a user to spend time formatting their own code?

9 out of 10 poor questions have code flung onto the site in the most unpalatable and unreadable way. I have wasted days of my life fixing other people's code formatting and got bored with it a while ...
TheGeneral's user avatar
  • 80.6k
39 votes
4 answers
2k views

Is it frowned upon to use backticks around a word or even part of it to refer to some function or keyword as part of a sentence?

I'm talking about things like "you can do that by taking your usersArray and mapping it to each user's name", essentially incorporating part of the inline code into the natural flow of the ...
CherryDT's user avatar
  • 27.9k
38 votes
1 answer
377 views

Code block adjustment

One of the things I've noticed quite often is someone will present their code like this: if( $a > 5) { echo $foo; // why isn't it showing today? } ?> People then comment and ...
Niet the Dark Absol's user avatar
38 votes
0 answers
201 views

Posting properly formatted code is poorly explained and harder than it needs to be

Every day I leave comments on the site asking users to fix their code formatting, or notes that I have already done so. True, a lot of it comes down to apathy (or lack of consideration) on the part of ...
Karl Knechtel's user avatar

1
2 3 4 5
10