diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2020-05-27 14:14:47 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2020-05-28 10:38:23 +0200 |
commit | f156ed10afd9125e0dfe1a0b9edb69bf828f4887 (patch) | |
tree | 3ddecfd5e7c8097ec09db303c5e93f99e9e6c079 /rtemsqual/sphinxcontent.py | |
parent | sphinxcontent: Move Sphinx content to new module (diff) | |
download | rtems-central-f156ed10afd9125e0dfe1a0b9edb69bf828f4887.tar.bz2 |
sphinxcontent: Make label/reference functions
Diffstat (limited to 'rtemsqual/sphinxcontent.py')
-rw-r--r-- | rtemsqual/sphinxcontent.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/rtemsqual/sphinxcontent.py b/rtemsqual/sphinxcontent.py index fbcbd22f..670b32b5 100644 --- a/rtemsqual/sphinxcontent.py +++ b/rtemsqual/sphinxcontent.py @@ -45,6 +45,18 @@ def _to_camel_case(name: str) -> str: name[1:])) +def get_reference(label: str, name: Optional[str] = None) -> str: + """ Returns the reference to the specified label. """ + if name: + return f":ref:`{name} <{label}>`" + return f":ref:`{label}`" + + +def get_section_label(name: str, prefix: str = "Section") -> str: + """ Returns the section label for the specified section name. """ + return prefix + _to_camel_case(name.strip()) + + class SphinxContent(Content): """ This class builds Sphinx content. """ def __init__(self, section_level: int = 2): @@ -52,22 +64,10 @@ class SphinxContent(Content): self._tab = " " self._section_level = section_level - def get_reference(self, label: str, name: Optional[str] = None) -> str: - """ Returns the reference to the specified label. """ - # pylint: disable=no-self-use - if name: - return f":ref:`{name} <{label}>`" - return f":ref:`{label}`" - def add_label(self, label: str) -> None: """ Adds a label. """ self.add(".. _" + label.strip() + ":") - def get_section_label(self, name: str, prefix: str = "Section") -> str: - """ Returns the section label for the specified section name. """ - # pylint: disable=no-self-use - return prefix + _to_camel_case(name.strip()) - def add_header(self, name, level=2) -> None: """ Adds a header. """ name = name.strip() @@ -78,7 +78,7 @@ class SphinxContent(Content): level: int = 2, label_prefix: str = "Section") -> str: """ Adds a header with label. """ - label = self.get_section_label(name, label_prefix) + label = get_section_label(name, label_prefix) self.add_label(label) self.add_header(name, level) return label |