diff options
-rw-r--r-- | rtemsspec/sphinxcontent.py | 12 | ||||
-rw-r--r-- | rtemsspec/tests/test_content_sphinx.py | 16 |
2 files changed, 28 insertions, 0 deletions
diff --git a/rtemsspec/sphinxcontent.py b/rtemsspec/sphinxcontent.py index dd2fb308..f9849fc1 100644 --- a/rtemsspec/sphinxcontent.py +++ b/rtemsspec/sphinxcontent.py @@ -105,6 +105,18 @@ class SphinxContent(Content): """ Adds a rubric. """ self.add(f".. rubric:: {name}") + def add_image(self, base: str, width: Optional[str] = None) -> None: + """ + Adds an image associated with the base file name. + + The image will have the optional width. + """ + options = [":align: center"] + if width is not None: + options.append(f":width: {width}") + with self.directive("image", base, options): + pass + def add_index_entries(self, entries) -> None: """ Adds a list of index entries the content. """ self.add([".. index:: " + entry for entry in make_lines(entries)]) diff --git a/rtemsspec/tests/test_content_sphinx.py b/rtemsspec/tests/test_content_sphinx.py index 2176b332..82312157 100644 --- a/rtemsspec/tests/test_content_sphinx.py +++ b/rtemsspec/tests/test_content_sphinx.py @@ -191,6 +191,22 @@ def test_append(): """ +def test_add_image(): + content = SphinxContent() + content.add_image("abc") + assert str(content) == """.. image:: abc + :align: center +""" + content.add_image("def", "50%") + assert str(content) == """.. image:: abc + :align: center + +.. image:: def + :align: center + :width: 50% +""" + + def test_add_index_entries(): content = SphinxContent() content.add_index_entries(["x", "y"]) |