Skip to content

Commit d29f180

Browse files
authored
🐛 FIX: parsing for unsupported builders
* Fix parsing for unsupported builders, inc pdf * Add test for building pdf with rinohtype
1 parent f16c3a0 commit d29f180

File tree

8 files changed

+80
-7
lines changed

8 files changed

+80
-7
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def get_version():
3535
"pygments",
3636
"sphinx_testing",
3737
"bs4",
38+
"rinohtype",
3839
],
3940
"code_style": ["pre-commit==2.6"],
4041
},

sphinx_tabs/tabs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,15 @@ def run(self):
183183
self.state.nested_parse(self.content[2:], self.content_offset, panel)
184184

185185
if self.env.app.builder.name not in get_compatible_builders(self.env.app):
186+
# Use base docutils classes
186187
outer_node = nodes.container()
187188
tab = nodes.container()
189+
tab_name = nodes.container()
190+
panel = nodes.container()
191+
192+
self.state.nested_parse(self.content[0:1], 0, tab_name)
193+
self.state.nested_parse(self.content[2:], self.content_offset, panel)
194+
188195
tab += tab_name
189196
outer_node += tab
190197
outer_node += panel

tests/conftest.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def auto_build_and_check(
2626
request,
2727
):
2828
"""
29-
Build and check build success and output regressions.
29+
Build and check build success and output regressions.
3030
Currently all tests start with this.
3131
Disable using a `noautobuild` mark.
3232
"""
@@ -80,12 +80,17 @@ def read(
8080
):
8181
content = get_sphinx_app_output(app, buildername, filename, encoding)
8282

83-
soup = BeautifulSoup(content, "html.parser")
84-
doc_div = soup.findAll("div", {"class": "documentwrapper"})[0]
85-
text = doc_div.prettify()
86-
for find, rep in (replace or {}).items():
87-
text = text.replace(find, rep)
88-
file_regression.check(text, extension=".html", encoding="utf8")
83+
if buildername == "html":
84+
soup = BeautifulSoup(content, "html.parser")
85+
doc_div = soup.findAll("div", {"class": "documentwrapper"})[0]
86+
doc = doc_div.prettify()
87+
for find, rep in (replace or {}).items():
88+
doc = text.replace(find, rep)
89+
else:
90+
doc = content
91+
file_regression.check(
92+
doc, extension="." + filename.split(".")[-1], encoding="utf8"
93+
)
8994

9095
return read
9196

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
project = "sphinx-tabs test"
2+
master_doc = "index"
3+
source_suffix = ".rst"
4+
extensions = ["sphinx_tabs.tabs", "rinoh.frontend.sphinx"]
5+
pygments_style = "sphinx"
6+
7+
rinoh_documents = [
8+
dict(doc=master_doc, target="test"),
9+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
TESTING PDF
3+
===========
4+
5+
.. toctree::
6+
:maxdepth: 2
7+
:caption: Contents:
8+
9+
tabs
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
============
2+
Testing Tabs
3+
============
4+
5+
The following should be rendered as a list of plain text items.
6+
7+
BEGIN_TEST
8+
9+
.. tabs::
10+
11+
.. tab:: Apples
12+
13+
Apples are green, or sometimes red.
14+
15+
.. tab:: Pears
16+
17+
Pears are green.
18+
19+
.. tab:: Oranges
20+
21+
Oranges are orange.
22+
23+
24+
END_of_TEST

tests/test_build.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from sphinx.application import Sphinx
23

34

45
@pytest.mark.sphinx(testroot="basic")
@@ -33,3 +34,14 @@ def test_nested_markup(app, check_asset_links):
3334
@pytest.mark.sphinx(testroot="customlexer")
3435
def test_custom_lexer(app, check_asset_links):
3536
check_asset_links(app)
37+
38+
39+
@pytest.mark.noautobuild
40+
@pytest.mark.sphinx("rinoh", testroot="rinohtype-pdf")
41+
def test_rinohtype_pdf(
42+
app, status, warning, check_build_success, get_sphinx_app_doctree
43+
):
44+
app.build()
45+
check_build_success(status, warning)
46+
get_sphinx_app_doctree(app, regress=True)
47+
# Doesn't currently regression pdf test output
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<document source="index.rst">
2+
<section ids="testing-pdf" names="testing\ pdf">
3+
<title>
4+
TESTING PDF
5+
<compound classes="toctree-wrapper">
6+
<toctree caption="Contents:" entries="(None,\ 'tabs')" glob="False" hidden="False" includefiles="tabs" includehidden="False" maxdepth="2" numbered="0" parent="index" rawcaption="Contents:" rawentries="" titlesonly="False">

0 commit comments

Comments
 (0)