diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-05-05 14:41:18 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2023-05-08 14:34:56 +0200 |
commit | 5ab6873e1fff704b6dcc7f183e7bd67a8b5bf8c4 (patch) | |
tree | ff1dbc676eaf8605c5ecc3bbf3f3b66706619bb4 | |
parent | sphinxcontent: Rework label handling (diff) | |
download | rtems-central-5ab6873e1fff704b6dcc7f183e7bd67a8b5bf8c4.tar.bz2 |
sphinxcontent: Add section stack
-rw-r--r-- | rtemsspec/sphinxcontent.py | 11 | ||||
-rw-r--r-- | 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 |