mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
#3998: Add optional section numbering in plain text output
Controlled by new config values: text_add_secnumbers and text_secnumber_suffix.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
.. toctree::
|
||||
:numbered:
|
||||
|
||||
doc1
|
||||
doc2
|
||||
maxwidth
|
||||
lineblock
|
||||
nonascii_title
|
||||
|
||||
2
tests/roots/test-build-text/doc1.txt
Normal file
2
tests/roots/test-build-text/doc1.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
Section A
|
||||
=========
|
||||
9
tests/roots/test-build-text/doc2.txt
Normal file
9
tests/roots/test-build-text/doc2.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
Section B
|
||||
=========
|
||||
|
||||
Sub Ba
|
||||
------
|
||||
|
||||
Sub Bb
|
||||
------
|
||||
|
||||
@@ -110,3 +110,57 @@ def test_list_items_in_admonition(app, status, warning):
|
||||
assert lines[2] == " * item 1"
|
||||
assert lines[3] == ""
|
||||
assert lines[4] == " * item 2"
|
||||
|
||||
|
||||
@with_text_app()
|
||||
def test_secnums(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
||||
expect = (
|
||||
"Section B\n"
|
||||
"*********\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"Sub Ba\n"
|
||||
"======\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"Sub Bb\n"
|
||||
"======\n"
|
||||
)
|
||||
assert result == expect
|
||||
|
||||
app.config.text_add_secnumbers = True
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
||||
expect = (
|
||||
"2. Section B\n"
|
||||
"************\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"2.1. Sub Ba\n"
|
||||
"===========\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"2.2. Sub Bb\n"
|
||||
"===========\n"
|
||||
)
|
||||
assert result == expect
|
||||
|
||||
app.config.text_secnumber_suffix = " "
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'doc2.txt').text(encoding='utf8')
|
||||
expect = (
|
||||
"2 Section B\n"
|
||||
"***********\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"2.1 Sub Ba\n"
|
||||
"==========\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"2.2 Sub Bb\n"
|
||||
"==========\n"
|
||||
)
|
||||
assert result == expect
|
||||
|
||||
|
||||
Reference in New Issue
Block a user