Skip to content
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

code-block: Fix handling of :dedent: and add unit tests #9661

Merged
merged 8 commits into from Jan 15, 2022

Conversation

latosha-maltba
Copy link
Contributor

Subject: code-block: Fix handling of :dedent: and add unit tests

Feature or Bugfix

Depending on the point of view this is one or a combination of:

  • Feature
  • Bugfix
  • Refactoring

Purpose

  • an argument of 0 to dedent is handled as numeric argument and not as "no argument".
  • Preserve newlines in the literal block when :dedent: without argument is given.

Relates

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
If the option :dedent: (without numeric argument) was given to
code-block then all newlines where striped from the resulting code.
Preserve newlines when stripping common whitespace at the beginning of
code blocks.
doc/usage/restructuredtext/directives.rst Show resolved Hide resolved
doc/usage/restructuredtext/directives.rst Outdated Show resolved Hide resolved
@tk0miya tk0miya added this to the 4.3.0 milestone Sep 23, 2021
The presence or absence of the ``:dedent: 4`` option in the example

.. code-block:: ruby
   :dedent: 4

       some ruby code

makes no difference for the output due to how ReST handles whitespace.
If it is present, then ReST indent is 3 and the 4 spaces of the code are
stripped by the :dedent: option.  If the dedent option is missing, then
the ReST indent is 7 and all whitespace is stripped again.

Add a dummy option to fixate the ReST indent to 3, so adding and
removing of the option in the example has an effect on the output.
@tk0miya tk0miya merged commit a55a765 into sphinx-doc:4.x Jan 15, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants