Questions tagged [code-formatting]
For posts about making code appear correctly in questions, answers and their comments.
402
questions
-10
votes
0answers
124 views
Automatically format code
This question is very similar to this one, but it was asked 5 years ago and hasn't had a response since.
During the periods that I am active on Stack Overflow, I'd say that I edit many, many posts ...
5
votes
0answers
93 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.
...
7
votes
0answers
46 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 ...
3
votes
0answers
43 views
Long lines in code break layout of revisions page [duplicate]
This first revision of a question has a very long line in a code section (no linebreaks). Instead of showing horizontal scrollbars, the preview of the post content does overflow the revisions page. ...
3
votes
0answers
178 views
Bug in JavaScript code colors [duplicate]
The following JavaScript code:
let hsv2hsl = (h,s,v,l=v-v*s/2, m=Math.min(l,1-l)) => [h,m?(v-l)/m:0,l];
colors are wrong (starting from /2 which is interpreted as comment):
Light mode:
Dark mode:
...
8
votes
0answers
95 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 ...
7
votes
1answer
148 views
Literal tab in code block renders as four spaces
I think this used to work correctly before because I have memories of testing this when responding to makefile questions before, where proper tabs are crucial. (That would have been before the switch ...
6
votes
0answers
77 views
The code editor is italicizing some code blocks [duplicate]
Example here:
I think it might have something to do with the arrow notation, since the italicized text didn't appear until I put that in.
6
votes
0answers
125 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
0answers
91 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 ...
25
votes
5answers
918 views
When should we use code, quotes and bold blocks?
I've seen countless posts where using Markdown blocks has been "wacky".
Many of these posts used citation blocks for error logs, for example, while others used bold or italics. Some also use ...
0
votes
2answers
302 views
How can I type backticks on my Samsung smartphone, which are needed for inline code snippets?
I'm a regular writer here on the site, and I'm more and more working with my smartphone (instead of my computer), but I have an issue: backticks only seem to be usable as accent signs (like "à&...
7
votes
2answers
148 views
How do I put a code block in a comment that starts and ends with spaces?
I was writing a reply in a comment just recently and I realized I could not turn something into a code block if it started and ended with a space. The particular comment in question is here. After a ...
107
votes
3answers
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 ...
-8
votes
2answers
214 views
OP's question was erroneously edited. The moderators want to keep erroneous question as it looks 'pretty' and readable
I have a question about my Stack Overflow post: Truncate column names in SELECT (MySQL client)
The OP for a MySQL query (Truncate column names in SELECT (MySQL client)) had a problem with the ...
6
votes
0answers
100 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 ...
3
votes
0answers
113 views
Why are tabs in the code replaced with spaces?
Why are tabs replaced by spaces in the output when I type them inside of code fences?
Here I used tabs:
int func()
{
somecode;
}
But you see spaces.
7
votes
1answer
99 views
CommonMark doesn't generate correct HTML markup
I have tried editing this post https://stackoverflow.com/a/62887975/1839439
This is what I see in the preview:
This is what I get after saving:
This is the markdown used:
You can try this if it ...
1
vote
0answers
37 views
Clojure code highlight is broken [duplicate]
I am wondering why nobody has reported this issue before.
It looks like the highlighter incorrectly picks symbols at the end of words.
This is a picture from this question:
Stuck with type hints in ...
9
votes
2answers
206 views
Why does syntax highlighting only work when previewing an edit to this old answer?
I made an edit to this old answer of mine. Among other changes, I converted from indentation-defined code blocks to code fence-defined code blocks. Despite the question being tagged as C#, I ...
3
votes
0answers
81 views
Code block overflows on Google Chrome [duplicate]
In rare circumstances a code block overflows the container in Google Chrome. It works fine in Firefox.
Example: php 5.3/mysql: why doesn't apache see mysql?
-4
votes
1answer
124 views
How to put bold text inside a code fence? [duplicate]
I want to make a code fence, and in that code fence, I want bold text.
I have tried:
<strong>bold</strong>
**Bold**
But they don't work.
Here is what I want to happen:
import tkinter as ...
5
votes
1answer
93 views
Just how short does a code block have to be to avoid horizontal scroll?
Today I edited an answer that interested me to try to get rid of the horizontal scroll.
You can see the final results here:
https://stackoverflow.com/a/59217352/5486
And the previous revision here:
...
3
votes
0answers
57 views
Why is not all the code formatted as code in my comment? [duplicate]
I've added a comment to this question, but as you can see there's something wrong in the formatting: I've used backticks on two places, and it works on the first, but not on the second place, as you ...
4
votes
1answer
175 views
How to handle questions with code as images [duplicate]
When someone (typically a first-time poster) posts a question that contains code presented as an image, we're supposed to encourage them to edit the question and repost as plain text, for all the ...
6
votes
0answers
79 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 ...
0
votes
0answers
70 views
SO couldn't format the following Lisp code properly [duplicate]
The following code is copied from https://github.com/emacs-mirror/emacs/blob/master/lisp/simple.el#L1347-L1358. When I copy it into the body of this question, the indentation goes wrong after line ...
4
votes
1answer
132 views
How can we add a tab to every line?
So, many people mess up code fences in their questions. One of the most common errors is that one tab is missing at the beginning of every line. Example:
public class ExampleClass{
private void ...
6
votes
1answer
93 views
Automatically resize code blocks to fit the horizontal scroll bar within the screen
Consider a fairly large block of code. For example, this question. On my 1366x768 screen laptop, this is what I see:
If I have to scroll horizontally in the code block, I have to first scroll down, ...
1
vote
1answer
125 views
How to properly format terraform (HCL) code
There's insufficient documentation on which code language identifier to use for the terraform language.
The expected values (tf, hcl, or terraform) do not work.
Is this supported, and if so, what is ...
4
votes
0answers
47 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 ...
-21
votes
2answers
165 views
Code readability of questions
When a user is asking a question SO has many ways of making sure the question is at high quality, SO has many guides and rules to make a good question and they are doing the job well.
I would like to ...
6
votes
0answers
59 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 ...
9
votes
0answers
161 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 ...
3
votes
0answers
82 views
Link to line in code snippet
When sharing code from GitHub with people, I can get a link to the exact line, which helps with clarity when I'm bringing attention to something specific.
I would like to do the same when linking ...
4
votes
0answers
106 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
0answers
138 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 ...
-23
votes
2answers
188 views
Why are people using 4 space-indent to post code?
I'm baffled why people are using 4 space-indent when posting code. It tends to screw up indentation on posts. It also does not have language-specific highlighting.
What I always use is the triple `. (...
1
vote
0answers
130 views
Weird line breaks in code in mobile view on IOS
See e.g. this recent answer of mine. The mobile view shows a line break in the middle of the keyword next even though there is a longer line just below it which isn't wrapped at all.
Screen shot:
...
1
vote
0answers
88 views
Bug: Interpreting C# code as incorrectly formatted code [duplicate]
When using the code format sometimes the color isn't correct.
For example, in this question the word CPerson Blue is blue instead of Black:
And the set is Blue, and get is Black:
This is a ...
32
votes
0answers
145 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 ...
4
votes
0answers
118 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 ...
3
votes
1answer
153 views
Misalignment of Unicode block characters in preformatted text blocks
I see a broken format of tables passed to <pre> tags, when the table has some Unicode decoration. Look:
postgres=# select * from pg_namespace ;
┌───────┬────────────────────┬──────────┬─────────...
1
vote
1answer
102 views
Bug in comment parsing
The following comment causes Stack Overflow to render the comment incorrectly, based on the documentation for Comment Formatting:
I think I see what you're doing. You really only need one example of ...
1
vote
0answers
90 views
What is the recommended way to format the output of some code? [duplicate]
As per title, consider some code which produces some output to STDOUT, what is the recommended way of formatting it.
For example, in Python, you could write:
print('Hello World!')
which produces ...
2
votes
0answers
36 views
How to format the data (questions/answers) on stackoverflow mobile site? [duplicate]
Its very difficult to format the data while working on stackoverflow mobile site. Somehow I used to manage it via adding spaces for code etc. But when theres a large complex data to be posted it ...
-9
votes
1answer
171 views
Changing the emphasis of python answers from python 2 to python 3
Frequently, I come across an excellent answer here, here or here, for example where the answer is written with python 2 in mind, and python 3 edited in as an afterthought.
I don't think the python 2 ...
75
votes
1answer
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 ...
2
votes
0answers
88 views
Feedback on the new ask question page - Formatting suggestions
I think you guys did a great job with the re-design of the ask question page. However there is this bit that I find can be improved.
There are currently three (or even 4) ways to format code:
...
-6
votes
1answer
138 views
ShellCheck integration into posted shell code blocks
If we could have ShellCheck optionally integrated into shell code blocks, recommended or performed automatically with result output;
It could save a good amount of repetitive and so automatable ...