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 | b5e7981df0726d72f1c8205f957b5f197b8e48df (patch) | |
tree | b1c5944759a2643d3daa9350a73041b8c5985e4e | |
parent | sphinxcontent: Add add_rubric() (diff) | |
download | rtems-central-b5e7981df0726d72f1c8205f957b5f197b8e48df.tar.bz2 |
sphinxcontent: Add add_image()
-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"]) |