mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
#3998: Toctree section numbering in plain text output
This commit is contained in:
parent
7fac34bb44
commit
604db47228
@ -1002,7 +1002,10 @@ class TextTranslator(nodes.NodeVisitor):
|
|||||||
|
|
||||||
def visit_reference(self, node):
|
def visit_reference(self, node):
|
||||||
# type: (nodes.Node) -> None
|
# type: (nodes.Node) -> None
|
||||||
pass
|
if self.add_secnumbers:
|
||||||
|
numbers = node.get("secnumber")
|
||||||
|
if numbers is not None:
|
||||||
|
self.add_text('.'.join(map(str, numbers)) + self.secnumber_suffix)
|
||||||
|
|
||||||
def depart_reference(self, node):
|
def depart_reference(self, node):
|
||||||
# type: (nodes.Node) -> None
|
# type: (nodes.Node) -> None
|
||||||
|
@ -115,7 +115,20 @@ def test_list_items_in_admonition(app, status, warning):
|
|||||||
@with_text_app()
|
@with_text_app()
|
||||||
def test_secnums(app, status, warning):
|
def test_secnums(app, status, warning):
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
result = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
contents = (app.outdir / 'contents.txt').text(encoding='utf8')
|
||||||
|
expect = (
|
||||||
|
"* Section A\n"
|
||||||
|
"\n"
|
||||||
|
"* Section B\n"
|
||||||
|
"\n"
|
||||||
|
" * Sub Ba\n"
|
||||||
|
"\n"
|
||||||
|
" * Sub Bb\n"
|
||||||
|
"\n"
|
||||||
|
"* 日本語\n"
|
||||||
|
)
|
||||||
|
assert contents == expect
|
||||||
|
doc2 = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
||||||
expect = (
|
expect = (
|
||||||
"Section B\n"
|
"Section B\n"
|
||||||
"*********\n"
|
"*********\n"
|
||||||
@ -128,11 +141,24 @@ def test_secnums(app, status, warning):
|
|||||||
"Sub Bb\n"
|
"Sub Bb\n"
|
||||||
"======\n"
|
"======\n"
|
||||||
)
|
)
|
||||||
assert result == expect
|
assert doc2 == expect
|
||||||
|
|
||||||
app.config.text_add_secnumbers = True
|
app.config.text_add_secnumbers = True
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
result = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
contents = (app.outdir / 'contents.txt').text(encoding='utf8')
|
||||||
|
expect = (
|
||||||
|
"* 1. Section A\n"
|
||||||
|
"\n"
|
||||||
|
"* 2. Section B\n"
|
||||||
|
"\n"
|
||||||
|
" * 2.1. Sub Ba\n"
|
||||||
|
"\n"
|
||||||
|
" * 2.2. Sub Bb\n"
|
||||||
|
"\n"
|
||||||
|
"* 3. 日本語\n"
|
||||||
|
)
|
||||||
|
assert contents == expect
|
||||||
|
doc2 = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
||||||
expect = (
|
expect = (
|
||||||
"2. Section B\n"
|
"2. Section B\n"
|
||||||
"************\n"
|
"************\n"
|
||||||
@ -145,11 +171,24 @@ def test_secnums(app, status, warning):
|
|||||||
"2.2. Sub Bb\n"
|
"2.2. Sub Bb\n"
|
||||||
"===========\n"
|
"===========\n"
|
||||||
)
|
)
|
||||||
assert result == expect
|
assert doc2 == expect
|
||||||
|
|
||||||
app.config.text_secnumber_suffix = " "
|
app.config.text_secnumber_suffix = " "
|
||||||
app.builder.build_all()
|
app.builder.build_all()
|
||||||
result = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
contents = (app.outdir / 'contents.txt').text(encoding='utf8')
|
||||||
|
expect = (
|
||||||
|
"* 1 Section A\n"
|
||||||
|
"\n"
|
||||||
|
"* 2 Section B\n"
|
||||||
|
"\n"
|
||||||
|
" * 2.1 Sub Ba\n"
|
||||||
|
"\n"
|
||||||
|
" * 2.2 Sub Bb\n"
|
||||||
|
"\n"
|
||||||
|
"* 3 日本語\n"
|
||||||
|
)
|
||||||
|
assert contents == expect
|
||||||
|
doc2 = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
||||||
expect = (
|
expect = (
|
||||||
"2 Section B\n"
|
"2 Section B\n"
|
||||||
"***********\n"
|
"***********\n"
|
||||||
@ -162,5 +201,5 @@ def test_secnums(app, status, warning):
|
|||||||
"2.2 Sub Bb\n"
|
"2.2 Sub Bb\n"
|
||||||
"==========\n"
|
"==========\n"
|
||||||
)
|
)
|
||||||
assert result == expect
|
assert doc2 == expect
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user