[rtems-central commit] sphinxcontent: Add section stack
Sebastian Huber
sebh at rtems.org
Tue May 9 13:45:26 UTC 2023
Module: rtems-central
Branch: master
Commit: 5ab6873e1fff704b6dcc7f183e7bd67a8b5bf8c4
Changeset: http://git.rtems.org/rtems-central/commit/?id=5ab6873e1fff704b6dcc7f183e7bd67a8b5bf8c4
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Fri May 5 14:41:18 2023 +0200
sphinxcontent: Add section stack
---
rtemsspec/sphinxcontent.py | 11 ++++++++---
rtemsspec/tests/test_content_sphinx.py | 7 +++++++
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/rtemsspec/sphinxcontent.py b/rtemsspec/sphinxcontent.py
index 42cf6430..c55802ce 100644
--- a/rtemsspec/sphinxcontent.py
+++ b/rtemsspec/sphinxcontent.py
@@ -78,6 +78,11 @@ class SphinxContent(Content):
self._tab = " "
self._section_level = section_level
self._label_stack = [""]
+ self._section_stack: List[str] = []
+
+ def get_sections(self) -> List[str]:
+ """ Gets the list of sections of the current scope. """
+ return self._section_stack
@property
def label(self) -> str:
@@ -200,14 +205,14 @@ class SphinxContent(Content):
else:
self.push_label(label)
self.add_label(label)
- self.add_header(name, self._section_level)
- self._section_level += 1
+ self.add_header(name, self._section_level + len(self._section_stack))
+ self._section_stack.append(name)
return label
def close_section(self) -> None:
""" Closes a section. """
- self._section_level -= 1
self.pop_label()
+ self._section_stack.pop()
@contextmanager
def section(self,
diff --git a/rtemsspec/tests/test_content_sphinx.py b/rtemsspec/tests/test_content_sphinx.py
index 07724c30..5979d3c5 100644
--- a/rtemsspec/tests/test_content_sphinx.py
+++ b/rtemsspec/tests/test_content_sphinx.py
@@ -87,12 +87,19 @@ def test_make_label():
def test_section():
content = SphinxContent()
+ assert content.get_sections() == []
with content.section("ab cd") as label:
+ assert content.get_sections() == ["ab cd"]
content.add(label)
with content.section("ef gh") as label2:
+ assert content.get_sections() == ["ab cd", "ef gh"]
content.add(label2)
with content.section("ij kl", "mn") as label2:
+ assert content.get_sections() == ["ab cd", "ef gh", "ij kl"]
content.add(label2)
+ assert content.get_sections() == ["ab cd", "ef gh"]
+ assert content.get_sections() == ["ab cd"]
+ assert content.get_sections() == []
assert str(content) == """.. _AbCd:
ab cd
More information about the vc
mailing list