Welcome to Codidact Meta!
Codidact Meta is the meta-discussion site for the Codidact community network and the Codidact software. Whether you have bug reports or feature requests, support questions or rule discussions that touch the whole network – this is the site for you.
How are tabs handled in code blocks?
While this question is of particular interest to the technical sites, and especially to Software, it concerns core site functionality. I figured it would be more polite to ask than to make a "sandbox" post.
I'm planning to write some canonical Q&A about IndentationError
s in Python for the Software site. This requires discussing code that is broken because some lines of text start with some inappropriate mixture of tab and space characters.
Similar (non-canonical; I have been rounding up old duplicates lately) questions on Some Other site have had issues because the site automatically converted tabs to spaces in formatted code blocks, destroying the information needed to demonstrate and discuss the problem.
Are tabs automatically converted on Codidact? If so, to how many spaces?
Better yet: is there any way to make tabs appear highlighted in the code display, so that it's immediately apparent that the code is indented with tabs rather than spaces?
1 answer
To answer the question of what the behavior is: in a dev environment, I created a post with two code blocks, one containing spaces and one containing tabs. I couldn't just type the tabs into the post editor because the browser intercepted the tab and treated it as "move to next field". I created test samples in both emacs and TextEdit and pasted those into the editor to see what would happen.
In both cases, there is no obvious difference in the rendering -- a 4-stop tab looks the same as 4 spaces. However, if you try to select the space, in the first case you can select individual spaces but in the second case you can only select the tabbed block of spaces. This tells me that the tab was preserved by the post editor. We're using a library for syntax highlighting, I believe highlight.js
. I don't know enough about that to know if the library supports some way to make tabs visible as tabs, but I'm leaving this partial answer in case someone else can build on what I've found.
0 comment threads