summaryrefslogtreecommitdiff
path: root/sphinx/directives/code.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-16 21:51:46 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2021-01-16 21:51:46 +0900
commit30f8640bab786b28e2fbc3a12a4cf212e6f953d1 (patch)
treef5cf23900a7bc509fe970262195995ddc526fda1 /sphinx/directives/code.py
parent5460ea103bd91ce910e50e11e05c1e5340c2a9e0 (diff)
parent7c340e1c1c43f173f11efc14feb29cd08cedb995 (diff)
downloadsphinx-git-30f8640bab786b28e2fbc3a12a4cf212e6f953d1.tar.gz
Merge branch '3.x'
Diffstat (limited to 'sphinx/directives/code.py')
-rw-r--r--sphinx/directives/code.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py
index d4f73f84f..f5cd92b82 100644
--- a/sphinx/directives/code.py
+++ b/sphinx/directives/code.py
@@ -7,6 +7,7 @@
"""
import sys
+import textwrap
from difflib import unified_diff
from typing import TYPE_CHECKING, Any, Dict, List, Tuple
@@ -17,6 +18,7 @@ from docutils.statemachine import StringList
from sphinx import addnodes
from sphinx.config import Config
+from sphinx.directives import optional_int
from sphinx.locale import __
from sphinx.util import logging, parselinenos
from sphinx.util.docutils import SphinxDirective
@@ -55,7 +57,7 @@ class Highlight(SphinxDirective):
def dedent_lines(lines: List[str], dedent: int, location: Tuple[str, int] = None) -> List[str]:
if not dedent:
- return lines
+ return textwrap.dedent(''.join(lines)).splitlines(True)
if any(s[:dedent].strip() for s in lines):
logger.warning(__('non-whitespace stripped by dedent'), location=location)
@@ -104,7 +106,7 @@ class CodeBlock(SphinxDirective):
option_spec = {
'force': directives.flag,
'linenos': directives.flag,
- 'dedent': int,
+ 'dedent': optional_int,
'lineno-start': int,
'emphasize-lines': directives.unchanged_required,
'caption': directives.unchanged_required,
@@ -378,7 +380,7 @@ class LiteralInclude(SphinxDirective):
optional_arguments = 0
final_argument_whitespace = True
option_spec = {
- 'dedent': int,
+ 'dedent': optional_int,
'linenos': directives.flag,
'lineno-start': int,
'lineno-match': directives.flag,