- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
:dedent: 0
not respected and :dedent: without argument seems broken
#9636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't think this is a bug because your goal is not "dedenting" the content by 0. I think you'd like to use the But, at this moment, supporting 0 value is a good workaround for your case. And it is low cost to implement it and it does not harm anybody. So I can agree to add the change as a "secret" feature.
It must be help us. Could you make a PR? |
I agree that I use the feature in a hacky way, however, – nitpick – I don't agree that it is not a bug as the implementation does not follow the documentation, which states:
and (to me) N = 0 is a perfectly fine number. But lets not talk about distinctions without difference and instead focus on a more important issue: Could you have a look at the second part of this report: .. code-block::
:dedent:
first line
second line The above produces
to the newline preserving:
|
Oops... it must be a bug! |
Due to how Python converts ints to bool the numeric argument ``0`` to the :dedent: option of the code-block directive was handled like if no argument was given to :dedent:. Check properly for None in the options argument processing, so ``0`` is treated as numeric argument to :dedent:. Bug: sphinx-doc#9636
Describe the bug
:dedent: 0
not respectedThe
.. code-block::
(and probably related directives, too) does not respect the:dedent: 0
option.Instead of doing nothing, it does the same as
:dedent:
(without argument).I believe
:dedent: 0
should be a noop to be in line with the expectation of dedenting by 0 characters.Use case:
Without the :dedent: the code block would (by I think the ReST parser, not the renderer) be read with ONE 7 space indent (instead of ONE 3 space indent and a 4 space indent inside the code block). Thus, messing up the code layout. The :dedent: 0 would help in such cases as it indicates ONE 3 space indent for the directive.
As a workaround
:class: dummy
can also be used, however, this pollutes the class attribute of the node.Proposed solution:
Instead of
if not dedent:
useif dedent is None:
in sphinx/directives/code.py line 60:dedent: (without argument)
Also, I noticed that :dedent: (without any argument) seemingly produces garbage, namely it removes all newlines and only the indent of the first line, producing a single long line.
Proposed solution
The reason seems to be that the function dedent_lines() (sphinx/directives/code.py line 59) uses
instead of the line preserving
Closing words
If the above analysis is correct and you agree with the proposed solutions, I'm happy to provide a PR if that reduces the workload for you.
How to Reproduce
MWE is given above in the use case.
Expected behavior
No response
Your project
Sorry that's a private one, the MWE above should do.
Screenshots
No response
OS
Linux
Python version
3.9
Sphinx version
4
Sphinx extensions
No response
Extra tools
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: