mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
code-block: Pass list of strings ends with CR code to dedent_lines()
This commit is contained in:
parent
e2f141620d
commit
ff54f97aba
@ -58,7 +58,7 @@ class Highlight(SphinxDirective):
|
||||
|
||||
def dedent_lines(lines: List[str], dedent: int, location: Tuple[str, int] = None) -> List[str]:
|
||||
if dedent is None:
|
||||
return textwrap.dedent('\n'.join(lines)).split('\n')
|
||||
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)
|
||||
@ -138,9 +138,9 @@ class CodeBlock(SphinxDirective):
|
||||
|
||||
if 'dedent' in self.options:
|
||||
location = self.state_machine.get_source_and_line(self.lineno)
|
||||
lines = code.split('\n')
|
||||
lines = code.splitlines(True)
|
||||
lines = dedent_lines(lines, self.options['dedent'], location=location)
|
||||
code = '\n'.join(lines)
|
||||
code = ''.join(lines)
|
||||
|
||||
literal: Element = nodes.literal_block(code, code)
|
||||
if 'linenos' in self.options or 'lineno-start' in self.options:
|
||||
|
Loading…
Reference in New Issue
Block a user