Spaces are recommended for indentation, but tabs may also be used. Tabs will be converted to spaces. Tab stops are at every 8th column (processing systems may make this value configurable).
Why tho? By converting tabs to spaces, we lose the accessibility aspect that tabs provide by letting the reader decide what’s comfortable to them as tab-width should be configurable on the reader’s side, not the writer’s. Some programming languages, like Go, tabs are overwhelmingly preferred & sometimes even required. Copying some code would not work.
I would like to see a --disable-tab-expansion
flag that lets the author choose how they want their output to be output.
Found the release notes as well as includes directives documentation. Not it the
--help
text for the actual CLI. Missing from https://docutils.sourceforge.io/docs/user/config.html#tab-widthLast edit: toastal 2023-07-16
No luck actually trying.
Did not work in a docutils.conf file either.
The negative value for the TAB expansion width is only supported for literal inclusions, not for the main document or included rST files.
Understanding my ask a bit more now:
I want a code block options for
:tab-width: -1
, tho preferably I want this on a global flag because I do not wantdocutils
to convert my tabs to spaces so my code is a) easier to copy from a post and b) so the reader may adjust the tab widths while reading.Tab conversion was unexpected as reStructuredText seemed to have no issues allowing me to use tabs as indentation for block as well as indentation inside
code-block
s. Documentation was also confusing where some things (e.g. directives, CLI flags) hadtab-width
options that allowed values <1 whereas others did not.I considered trying to use a literal block,
::
, as a workaround, but without the ability to add classes there would be no way to discern a “code block” literal from a literal literal. My best idea for a workaround for now is, for HTML at least, do a post-processing phase that finds all code blocks and runs their contents through GNU unexpand (I have to disable Pygments anyhow since it doesn’t support or has parsing bug for languages I use so I’m already choosing to pass these blocks thru to a better syntax highlighter). This is obviously not ideal. Using thecode-block
will still keep the document readable & allows Tree-sitter to highlight the children, so this hack will have to do.Last edit: toastal 2023-07-16
Two minor points:
A patch-set was posted to the "docutils-develop" mail list on 2023-10-29. See the thread in the archive.