Questions tagged [code-formatting]
For posts about making code appear correctly in questions, answers and their comments.
88
questions with no upvoted or accepted answers
152
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.
...
83
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 ...
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 ...
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 ...
52
votes
0
answers
722
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 ...
50
votes
0
answers
720
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 ...
38
votes
0
answers
195
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 ...
37
votes
0
answers
332
views
Code Snippet as a formatting tool
Since the Stack Snippet is being misused, let us make it a feature!
My proposal is to add a dropdown to select the language, and let people paste their code inside to format the code. The language ...
34
votes
0
answers
215
views
Users frequently start code blocks on the same line as the triple backticks
Every day I fix up lots of questions where the poster has written their code blocks like this:
```<html>
blah
blah
</html>```
When they do this, the first line of the code is not ...
32
votes
0
answers
511
views
Add warning for code surrounded by '''
I have seen so many people confuse ``` with ''', resulting in a post that needs to be edited. Can the linter add a warning that ''' does not highlight code, or can it be added in the sidebar?
28
votes
0
answers
270
views
When asking a question, make it clearer how to format code properly
We've all seen new questions with code that looks something like this:
func someFunction() {
// code here
more here
etc.
}
Obviously they posted:
func someFunction() {
// code here
more ...
23
votes
0
answers
168
views
Visually group code and snippet icons, and clarify which one to use
Could we please revamp the editing toolbar to make it easier to use the correct code formatting tool?
In case you are not in the editor right now, here's what the toolbar currently looks like:
...
23
votes
0
answers
382
views
Grey background doesn't appear for code in deleted answers
The grey background for code seems to have disappeared for deleted answers. For example, this deleted answer looks like this:
This happens on meta as well
Bug?
I'm using the latest version of ...
22
votes
0
answers
244
views
Add visual difference for negative code examples
I see that often someone makes negative examples and marks them either with //DON'T or similar. I think that is not enough; one should be able to visually tell positive from negative examples. For ...
21
votes
0
answers
543
views
How can I add foldable code or text when answering someone’s question on Stack Overflow?
How do I add foldable code or text on Stack Overflow when writing a question or an answer?
<details>
<summary>Click to expand!</summary>
```HTML
<h1>Hide this until someone ...
20
votes
0
answers
358
views
Formatting of code in comments does not preserve spaces
I entered a comment of the form Omit the `& ` entirely containing a segment in backticks. However, the space after the & inside the code segment was collapsed with the following space outside ...
20
votes
0
answers
155
views
Scrolling on single line code snipets
I realise this will be a bit of a pain to solve, but when trying to read long, one line code snippets, I find myself having to constantly stop to read what I've scrolled to, as showing here:
I ...
16
votes
0
answers
103
views
Can the New Question wizard check for multiline code inside single backticks?
Every day I fix up numerous questions that have multi-line code blocks enclosed in single backticks rather than triple backtick code fences. Or they don't put a newline between the triple backticks ...
13
votes
0
answers
290
views
RTL characters in code snippets
Here is a code snippet, snapshotted from a character-based terminal that doesn't apply the Unicode bidi algorithm:
Here's the same code snippet in Stack Overflow: {{a|1}} {{א|1}}
Note how the ...
13
votes
0
answers
312
views
Post lacks formatting when being edited
This answer has perfectly formatted code in the beginning. However, when I hit the edit link it turns out, that code is no longer formatted, because it starts without first four spaces.
What am I ...
12
votes
0
answers
104
views
Adding a link to a code with brackets escapes it automatically
Recently while formatting a post, I noticed that the brackets in the code (formatted by using `code`) are getting escaped automatically, when we give a link to it.
Take this as a sample callMe(\[\]). ...
10
votes
0
answers
118
views
Code links not distinguished on iPhone
Links within inline code (backticks) are not rendered in blue nor distinguished any other way from regular text on iPhone (tested on iPhone SE 2020, iOS 14.0.1).
Below is a screenshot for this post:
...
9
votes
0
answers
168
views
Formatted code colors have changed, for the worse
Why have formatted code colors changed within the past 2 days?
Here is an example with the old colors on the left, new on the right
(Taken from this question which was asked 2 days ago, and I ...
9
votes
0
answers
200
views
Associate TypeScript language with its tag
Code blocks on questions tagged with TypeScript should be automatically formatted with TypeScript syntax highlighting. Currently, they are not (at least not always), despite the presence of TypeScript ...
8
votes
0
answers
104
views
Edit shows expected code with a different format than what it really is
I'm using Google Chrome on Android 10 - Samsung Galaxy A30s.
When looking at this question
We can see the first code block has a specific indentation. Then, when clicking to edit
The expected result ...
8
votes
0
answers
72
views
Could we see edits in rendered output without highlighting, please?
In the review queue we can view the changes as "rendered output" or "markdown".
Sometimes I come across reviews that look like this:
I find this hard to read with all the green highlighting going on....
7
votes
0
answers
385
views
Automatically apply Kotlin code formatting to [android-jetpack-compose] questions
I have noticed that applying some tags automatically adds code highlighting to code blocks.
Obviously all language tags apply the appropriate formatting, but some technology tags also do this without ...
7
votes
0
answers
117
views
Triple-backtick code blocks don't get blockquoted correctly
Suppose I have a code block like this contrived pseudocode:
```
Here {
is
}
my code
```
When I select the whole block including the backticks and then use try to blockquote it using the button or ...
7
votes
0
answers
143
views
This message keeps me from posting "Your post appears to contain code that is not properly formatted as code."
I am trying to post a question on StackOverflow but it seems like this message "Your post appears to contain code that is not properly formatted as code" keeps me from posting. I have ...
7
votes
0
answers
99
views
"How to Format" in the "Ask a question" sidebar mentions both ways of creating code blocks, without drawing a link between them
As noted in What is the preferrred method for formatting code?, the "Ask a question" sidebar that shows up while writing the body of a new question suggests to "indent code by 4 spaces" even though ...
7
votes
0
answers
348
views
Your post appears to contain code
Is it possible to override that error message?
I have the feeling something changed in the way the content of the questions are checked, it is the second time I gave up and did not post a question ...
7
votes
0
answers
423
views
Highlight Specific Lines of Code Snippet
I found a few questions that address a similar idea of code highlighting but nothing that really hits on the area that I'm referring to. Is there a use case for wanting to highlight specific lines of ...
6
votes
0
answers
91
views
Existing answer detected as improperly formatted code while trying to edit
I'm trying to edit the regex community-wiki reference post, but any change I make gives me the error:
Your post appears to contain code that is not properly formatted as code. Please indent all code ...
6
votes
0
answers
136
views
Stack Overflow rejecting well-formatted code in question
Stack Overflow is rejecting a post that I am trying to create regarding Python. It complains that my post has improper code formatting, for reasons that I don't understand, even though the preview ...
6
votes
0
answers
163
views
Deleted code block rendering problem on recent update of Chrome
Browser bug, or site bug?
Chrome just recently updated (to version 85.0.4183.121). After the update, code blocks found in deleted posts are rendered badly:
Interestingly, if you select the text, it ...
6
votes
0
answers
89
views
Preview does not render code blocks as code if they contain a paragraph separator (unicode decimal 8233, hex 2029)
If you edit this question, you'll see the problem.
Here's a code block with a paragraph separator char between "foo" and "bar":
var str = "foo
bar"
var also = "other lines"
The above line renders ...
6
votes
0
answers
65
views
Run-on string when formatter believes a string ending back tick is escaped
I came across this answer's code snippet. In Golang, strings enclosed in backticks are taken as a raw string. It doesn't parse for escape sequences. The code formatter erroneously colors the rest of ...
6
votes
0
answers
86
views
Code highlighting of string continues after \"
The newly released Stack Overflow App contains a bug resulting in a wrong coloring after the ending of a string.
I looked up my answer on Stack Overflow, inside the Stack Exchange App, the mobile and ...
5
votes
0
answers
147
views
Are code fences officially preferred yet? User found error message saying otherwise!
I found a question on SO where the asker had been presented with an "error" message:
Oops! Your edit couldn't be submitted because:
Your post appears to contain code that is not properly ...
5
votes
0
answers
293
views
Is having the ability to apply rich text formatting inside code blocks important?
For many years, it's been possible to apply rich text formatting to code blocks inside posts by formatting the code block using the HTML tags <pre><code> and using more HTML tags inside ...
5
votes
0
answers
106
views
Syntax highlighting Java code in response to a Kotlin question
I provided an answer to a question tagged kotlin and javafx. The code blocks in my answer were predominantly in Java.
Without any language tags on the code blocks, the syntax highlighting for the Java ...
5
votes
0
answers
86
views
Small CSS bug with <pre><hr> ... <hr> ... <hr></pre>
The following formatting strategy
<pre>
Line 1
<hr>
Line 2
<hr>
Line 3
</pre>
renders like this for me (in Chrome) as of March 2021 (image edited to be narrower so it doesn't ...
5
votes
0
answers
108
views
Preview Doesn't Match Live View
This question (Fatal error when try add snippets code on functions.php Wordpress) had HTML in it that caused the preview to display subtly different (after Complemento) than the actual question.
...
5
votes
0
answers
73
views
Markdown with fenced code blocks within lists has inconsistent previewed/final renderings
About the bug
This is a bug whose effects you can see in the revision history of this answer. Specifically, it’s about the edit that created Revision 15 (click “side-by-side markdown” to see that ...
5
votes
0
answers
118
views
Are edits that purely reformat code, based on preference, good edits?
Start note: This question is very similar to a question that was flagged as similar. Are purely cosmetic edits to original code frowned-upon, even if they accompany high-value non-code revisions? The ...
5
votes
0
answers
179
views
Which part of my previous post "is NOT properly formatted as code" on Stack Overflow?
Could anyone specify which part was wrong with my description in my previous post?
I've just asked a question on Stack Overflow here. In the process, I couldn't post my question because of the ...
5
votes
0
answers
132
views
Can we add a nudge to use a PowerShell validator when PowerShell code is detected?
For a while I have been contributing to Stack Overflow with PowerShell questions and answers. In here I am seeing a lot of questions with code examples that could be automatically resolved (or ...
5
votes
0
answers
211
views
What is going on here? There is no code
I tried asking a question on Stack Overflow and got a weird message saying I didn't have properly formatted code. Does anyone know what is going on here?
Putting that line in code blocks didn't make ...
5
votes
0
answers
88
views
Stripping of non-printable characters when formatting as code
I came across a question by a new user today. I assume that due to unfamiliarity with the intricacies of the SE editor, they tried to mark a code block using `...` - which didn't quite produce the ...
5
votes
0
answers
159
views
Code markup (on Stack Overflow) and screen readers
I once read a post on meta (specifically for Stack Overflow) about text formatted as code is bad for screen-reader users as the screen readers read each character inside a code block individually.
E....