Questions tagged [code-formatting]
For posts about making code appear correctly in questions, answers and their comments.
480
questions
2
votes
1
answer
132
views
Font in code blocks [duplicate]
Has the font in code blocks changed recently? Is this intended?
Being exclusively active in the r tag, I'm very irritated by the distracting misalignment of < and -, which together are the ...
16
votes
0
answers
105
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 ...
6
votes
1
answer
78
views
code formatting lost after edit, revert would not fix it
I made an edit to this answer, (changed "unicode" to "str") however when I saved the edit, the code formatting was lost. I quickly reverted the edit, however the code formatting ...
-23
votes
2
answers
258
views
When is it OK to upload images of code/data/errors? [duplicate]
When is it OK to upload images of code/data/errors?
– If your answer is never, can we please talk about it?
Don't get me wrong.
I don't endorse uploading code/text in an image instead of uploading ...
5
votes
0
answers
148
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 ...
3
votes
1
answer
407
views
My post "appears to contain code that is not properly formatted as code", but I did wrap code in <pre><code> tags [duplicate]
I was trying to answer a coding question in JavaScript. I had some code and used <pre><code>, put my code in, then typed </pre></code>. I then came across this error when ...
1
vote
1
answer
166
views
'Code zoom' feature to view code in expanded popup [duplicate]
Right now, viewing code on Stack Overflow is quite inconvenient as it's displayed in a small text box where lines don't wrap.
I hope a "code zoom" feature can be added - similar to the one ...
15
votes
1
answer
341
views
Code blocks surrounded by triple backtick then single backtick
Off the back of Code blocks surrounded by single backtick then triple backticks, it looks like the original problem was not exactly resolved, but more reversed.
I'm seeing a lot of questions come ...
1
vote
1
answer
146
views
Correct use of code block formatting?
Is the following correct use of a code block (the curly braces icon) in a Stack Overflow question?
def __init__(self,rect_len,rect_wid,stylus_in):
self.len = rect_len
self.wid = ...
1
vote
0
answers
97
views
Indented code block italicizing text contained within asterisks
I stumbled across this question which has some peculiar formatting in the code block.
I noticed that some of the text within the code block was italicized, which I was under the impression could not ...
70
votes
2
answers
746
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 ...
31
votes
2
answers
476
views
Should I use inline code when mentioning a class, function, interface name? [duplicate]
I always use inline code when mentioning class, interface, and function names within my English sentences. In my opinion, this makes it better to read as it separates English words and grammar from ...
5
votes
1
answer
109
views
No-break space in code block renders as normal space [duplicate]
Problem: In a code block, a no-break space is substituted with a regular space. In certain cases, the writer's intention is to utilize a no-break space, not a regular space.
Situation: In this ...
-8
votes
1
answer
281
views
How to paste Python code in Stack Overflow without DIY [duplicate]
Here is an image of correct code (in fact, code of a previous question):
If I copy this code and paste it in a code sample in this editor, I got this (another image):
So I'm obliged to add a tab at ...
-9
votes
1
answer
192
views
Are there any Stack Overflow rules regarding line indentation in formatted code?
... or in other words: Why would someone want to edit an answer just to remove four leading spaces of a few code lines?
Example: https://stackoverflow.com/revisions/73159227/5 - should I have known ...
34
votes
1
answer
1k
views
Why does the first line of a code block often get an extra level of indentation?
See the code block in the first revision of this question
Hi! I am learning c and I don understand why this code doesnt work.
Notice that the first line #include <stdio.h> is indented an extra 4 ...
2
votes
1
answer
140
views
Mixing monospace and normal text doesn't look nice
Sometimes I want to pluralize a Python class name, but the plural "s" should not be monospace, since it's not code. For example this answer:
The letters should line up.
-51
votes
6
answers
293
views
Do you agree that questions/answers on Stack Overflow should be included in code blocks as comments instead of long explanations?
What people usually do is to to write explanations of their problem outside of code blocks, but it would be shorter and clearer to write the problem settings as comments in the code block. Here are ...
9
votes
1
answer
170
views
Prevent wrapping inline code
I've just made an edit here, but the way the inline code wraps is not sensible.
Is there a way to indicate that " ".join(map(shlex.quote, sys.argv)) should not be broken over lines?
I don't ...
3
votes
0
answers
115
views
Text and code blocks under spoiler
I'm trying to ask a question and put additional information under the spoiler. The best solution I've found looks like this:
>!Text block
>!
>!<pre><code>
>!code block
>!<...
12
votes
0
answers
158
views
What causes these list item marker display issues for content that begins with a code block? [closed]
Yesterday I made an edit that produced some unexpected output. It seems that when an item in an ordered or unordered list begins with a code block, in (at least) Firefox (but not Chrome) the list ...
38
votes
0
answers
197
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 ...
5
votes
1
answer
369
views
HTML formatting inside highlighted code blocks is no longer supported - how can I fix my posts? (Obsolete)
This question isn't relevant anymore since the site once again supports HTML formatting inside code blocks. Stack Exchange implemented the plug-in workaround noted in the answer, to resolve an issue ...
5
votes
0
answers
298
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 ...
3
votes
0
answers
161
views
Why can I publish a post here, but I get an error when I try to post the same text on Stack Overflow? [duplicate]
I don't understand why I can't post my question on Stack Overflow, but I can post it here.
The text is exactly the same, but when I want to post it on Stack Overflow I can't do it because a message ...
23
votes
0
answers
611
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 ...
-9
votes
2
answers
5k
views
Give a code block a filename
It's relevant and useful to include the name of the file that a code block should go in. For example, an update to a Next configuration would go in the next.config.js file, an NPM script would go in ...
14
votes
1
answer
356
views
Putting code in quote blocks when not quoting anything - is removing the quotes correct?
I've noticed recently a new (citation needed) "trend" where some users are putting their code blocks/fences inside quote blocks as well. These code blocks aren't, however, quoting anything; ...
3
votes
0
answers
109
views
Why are strange backslashes (escapes?) suddenly appearing in rendered code? [duplicate]
I've noticed that lately strange backslashes are appearing more and more frequently in edited code.
Here is another example. Is this a user failure or a bug in the site's code rendering?
28
votes
1
answer
460
views
Is the new editor's inline code tool supposed to break up code blocks?
Earlier today, I encountered a question with several lines of code that had been entered as individual, inline code blocks instead of a single, fenced code block. I assumed the OP was unfamiliar with ...
-25
votes
1
answer
188
views
I miss the highlighting of code, etc [closed]
I much prefer the colored highlighting that was applied to 'code' before about a week ago.
Is there a way to re-enable that? Or configure the pages to work with a different CSS? Or something else?
I ...
6
votes
0
answers
116
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 ...
1
vote
2
answers
135
views
Formatting MySQL code in order to be able to submit a question
I can't make a post because Stack Overflow keeps insisting on some formatting, even though my code is already formatted.
This was a preview of my post. Notice how code is already "parsed" by ...
8
votes
1
answer
174
views
Why does TOML code block formatting look so bad?
I have a Stack Overflow answer here that includes a TOML code block.
I have tagged the code fence:
```toml
But the resulting highlighting looks very poor and does not even highlight the comments ...
1
vote
0
answers
62
views
Styling in code fences [duplicate]
I recently supplied an answer and the two asterisks were causing italics so I kept messing around until I figured out a solution.
Is it expected behavior that regular code fences of triple back-tick ...
2
votes
1
answer
110
views
Why was my code highlighting edit rejected?
I suggested an edit to a question's code block, from:
```import requests
...
to:
```python
import requests
...
This was a simple case of an asker writing unintended Markdown, and the edit fixed that....
3
votes
0
answers
52
views
Partial syntax highlighting in a question [duplicate]
On questions where the code overflows, the syntax highlighting stops wherever the end of the content visible without scrolling is.
Scrolling down a bit fixes the issue. This problem occurs in Safari ...
2
votes
1
answer
300
views
Why would Stack Overflow code blocks (only) suddenly be displayed in italics?
Okay, it's not April 1st, so the new fonts must be serious. I'd like to express a like or dislike of the new fonts to those who decide such things without starting a flame war. Or is there an option ...
7
votes
0
answers
464
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 ...
3
votes
0
answers
91
views
Is there a comprehensive list of languages the code highlighter supports? [duplicate]
The triple backtick is my go to, to format snippets of code.
```
I regularly use them like:
```json for JSON
```py for Python
... and many more
Does a list of the linters Stack Overflow supports ...
-9
votes
1
answer
142
views
Displaying HTML first on Stack Overflow snippets [closed]
Currently, code snippets are displayed JavaScript first, then CSS and finally HTML. Regardless of the order they appear in the post source or anything.
This does not make any sense to me. Does it for ...
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 ...
300
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 ...
40
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 ...
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 ...
2
votes
0
answers
170
views
Code highlighting broken? [closed]
On Windows 10 with Firefox 93.0 I get this interesting to read code:
Related question
2
votes
0
answers
86
views
Post shows more content when edited than actually exists [duplicate]
Today, I wanted to edit the following question:
Discord Global DM Wait Time
I just wanted to change the format so that the post could be more descriptive. But when I was redirected to the edit, I ...
8
votes
0
answers
148
views
Tabs are discouraged. Should we use them anyway in answers about make where they are meaningful? [duplicate]
For better formatting tabs are discouraged in questions and answers. See, for example, the How to create a Minimal, Reproducible Example section of the help:
Also, use spaces instead of tabs – tabs ...
9
votes
1
answer
196
views
Code blocks deciding to go out of the frame
I just recently came across a bug, I saw a post with code like this foo bar, with (`), but somehow it became like this:
It went under the "Featured on Meta" and "The Overflow Bug" ...
3
votes
0
answers
99
views
Multiple programming languages answer structure [duplicate]
As an iOS developer, I see a lot of old answers in Objective-C, often accompanied with new Swift version, which may be in many different Swift versions too (Swift 2, Swift 3, etc.)
I'm sure this is ...