From 5d557af3f4ac31157793907d0492c54e276e9a0b Mon Sep 17 00:00:00 2001 From: Paul Mucur Date: Thu, 15 Aug 2024 16:26:31 +0100 Subject: [PATCH 1/2] Re-implement page rendering Rather than trying to re-use the existing SectNode to implement arbitrary pages, introduce a dedicated PageNode type to handle them. This way, we don't introduce errant whitespace in the resulting Asciidoc. The trickiest thing here is that we now handle the level of section titles by using the existing depth keyword argument. The current source and expected output (minus extra whitespace) of our indexpage.xml and examples_page.xml are used as text fixtures to ensure there are no regressions there. --- nodes.py | 110 ++++++++++--------- tests/test_heading_node.py | 12 --- tests/test_node.py | 33 ------ tests/test_none_node.py | 12 --- tests/test_page_node.py | 197 ++++++++++++++++++++++++++++++++++ tests/test_sect_node.py | 26 +---- tests/test_simplesect_node.py | 15 --- tests/test_title_node.py | 12 ++- 8 files changed, 263 insertions(+), 154 deletions(-) delete mode 100644 tests/test_heading_node.py delete mode 100644 tests/test_none_node.py create mode 100644 tests/test_page_node.py diff --git a/nodes.py b/nodes.py index 5ffb520..7af4207 100644 --- a/nodes.py +++ b/nodes.py @@ -214,7 +214,29 @@ def next_node(self): def nodefor(self, element): """Return the appropriate Node class for a given element.""" - defaults = { + if element.name == "compounddef": + return {"group": GroupNode, "page": PageNode}[element["kind"]] + + if element.name == "sectiondef": + return { + "define": DefineSectiondefNode, + "enum": EnumSectiondefNode, + "typedef": TypedefSectiondefNode, + "func": FunctionSectiondefNode, + "var": VariableSectiondefNode, + "user-defined": UserDefinedSectiondefNode, + }[element["kind"]] + + if element.name == "memberdef": + return { + "define": DefineMemberdefNode, + "enum": EnumMemberdefNode, + "typedef": TypedefMemberdefNode, + "function": FunctionMemberdefNode, + "variable": VariableMemberdefNode, + }[element["kind"]] + + return { "anchor": AnchorNode, "bold": BoldNode, "briefdescription": Node, @@ -222,8 +244,6 @@ def nodefor(self, element): "description": Node, "codeline": CodelineNode, "compound": Node, - "compounddef": SectNode, - "compoundname": TitleNode, "computeroutput": ComputeroutputNode, "copy": CopyrightNode, "emphasis": EmphasisNode, @@ -235,7 +255,6 @@ def nodefor(self, element): "innerclass": InnerclassNode, "itemizedlist": ItemizedlistNode, "listitem": ListitemNode, - "location": Node, "mdash": MdashNode, "ndash": NdashNode, "nonbreakablespace": NonbreakablespaceNode, @@ -260,39 +279,7 @@ def nodefor(self, element): "ulink": UlinkNode, "verbatim": VerbatimNode, None: Node, - } - - if element.name == "compounddef": - return {"group": GroupNode, "page": SectNode}[element["kind"]] - - if element.name == "sectiondef": - return { - "define": DefineSectiondefNode, - "enum": EnumSectiondefNode, - "typedef": TypedefSectiondefNode, - "func": FunctionSectiondefNode, - "var": VariableSectiondefNode, - "user-defined": UserDefinedSectiondefNode, - }[element["kind"]] - - if element.name == "memberdef": - return { - "define": DefineMemberdefNode, - "enum": EnumMemberdefNode, - "typedef": TypedefMemberdefNode, - "function": FunctionMemberdefNode, - "variable": VariableMemberdefNode, - }[element["kind"]] - - special_cases = ["title", "detaileddescription", "compoundname"] - if element.name in special_cases and self.has_page_parent(element): - return { - "title": HeadingNode, - "detaileddescription": SimplesectNode, - "compoundname": NoneNode, - }[element.name] - - return defaults[element.name] + }[element.name] class DoxygenindexNode(Node): @@ -535,6 +522,34 @@ def __list_macro_details(self, **kwargs): return "\n\n".join(output) +class PageNode(Node): + def to_asciidoc(self, **kwargs): + output = [] + + title_ = self.__output_title(**kwargs) + if title_: + output.append(title_) + + detaileddescription = self.__output_detaileddescription(**kwargs) + if detaileddescription: + output.append(detaileddescription) + + return "\n\n".join(output) + + def __output_title(self, **kwargs): + title_ = self.text("title") + attributes = ["#" + self.id] + if title_: + return title(title_, 1 + kwargs.get("depth", 0), ",".join(attributes)) + return None + + def __output_detaileddescription(self, **kwargs): + kwargs["depth"] = 1 + kwargs.get("depth", 0) + return self.child("detaileddescription").to_asciidoc( + documentation=True, **kwargs + ) + + class InnergroupNode(Node): def to_asciidoc(self, **kwargs): with open( @@ -633,26 +648,14 @@ def to_asciidoc(self, **kwargs): class SectNode(Node): def to_asciidoc(self, **kwargs): + kwargs["depth"] = 1 + kwargs.get("depth", 0) attributes = f"[{self.attributes()}]" return "\n".join((attributes, super().to_asciidoc(**kwargs))) class TitleNode(Node): def to_asciidoc(self, **kwargs): - return "".join((".", super().to_asciidoc(**kwargs))) - - -class HeadingNode(Node): - def to_asciidoc(self, **kwargs): - levels = { - "compounddef": "== ", - "sect1": "=== ", - "sect2": "==== ", - "sect3": "===== ", - } - # get the parent section level - parent = self.node.parent - return "".join((levels[parent.name], super().to_asciidoc(**kwargs))) + return title(super().to_asciidoc(**kwargs), kwargs.get("depth", 0)) class SimplesectNode(Node): @@ -1219,8 +1222,3 @@ def to_asciidoc(self, **kwargs): members.append(memberdef.to_asciidoc(**kwargs)) output.append("\n".join(members)) return "\n\n".join(output) - - -class NoneNode(Node): - def to_asciidoc(self, **kwargs): - return "" diff --git a/tests/test_heading_node.py b/tests/test_heading_node.py deleted file mode 100644 index 6487b1b..0000000 --- a/tests/test_heading_node.py +++ /dev/null @@ -1,12 +0,0 @@ -from bs4 import BeautifulSoup -from doxygentoasciidoc.nodes import HeadingNode - - -def test_heading_node(tmp_path): - xml = """Examples Index""" - - asciidoc = HeadingNode( - BeautifulSoup(xml, "xml").title, xmldir=tmp_path - ).to_asciidoc() - - assert asciidoc == "=== Examples Index" diff --git a/tests/test_node.py b/tests/test_node.py index 4c3c17b..1a01ceb 100644 --- a/tests/test_node.py +++ b/tests/test_node.py @@ -326,36 +326,3 @@ def test_nodes_are_subscriptable(): assert node["kind"] == "group" assert node["id"] == "not__sanitized" - - -def test_indexpage(): - xml = """ - - - index - Page Title - - - - First paragraph. - - Section HeadSecond paragraph. - - - - """ - - asciidoc = Node(BeautifulSoup(xml, "xml").doxygen).to_asciidoc() - - assert asciidoc == dedent( - """\ - [#indexpage] - == Page Title - - [[my_anchor]] First paragraph. - - [#a_section] - === Section Head - - Second paragraph.""" - ) diff --git a/tests/test_none_node.py b/tests/test_none_node.py deleted file mode 100644 index a23fafc..0000000 --- a/tests/test_none_node.py +++ /dev/null @@ -1,12 +0,0 @@ -from bs4 import BeautifulSoup -from doxygentoasciidoc.nodes import Node, NoneNode - - -def test_none_node(tmp_path): - xml = """examples_page""" - - asciidoc = NoneNode( - BeautifulSoup(xml, "xml").compoundname, xmldir=tmp_path - ).to_asciidoc() - - assert asciidoc == "" diff --git a/tests/test_page_node.py b/tests/test_page_node.py new file mode 100644 index 0000000..444c0ab --- /dev/null +++ b/tests/test_page_node.py @@ -0,0 +1,197 @@ +# pylint: disable=line-too-long + +from textwrap import dedent +from bs4 import BeautifulSoup +from doxygentoasciidoc.nodes import PageNode + + +def test_page_node_with_example_page(tmp_path): + xml = """\ + + examples_page + Examples Index + + + + + This page links to the various example code fragments in this documentation. For more complete examples, please see the pico-examples repository, which contains complete buildable projects. + + RTC example + UART example + ADC example + I2C example + Clock example + Timer example + Flash programming example + Watchdog example + Divider example + PWM example + Multicore example + Reset example + + + All examples are "Copyright (c) 2020 Raspberry Pi (Trading) Ltd", and are released under a 3-Clause BSD licence. Briefly, this means you are free to use the example code as long as you retain the copyright notice. Full details on the licence can be found here. + + + + """ + + asciidoc = PageNode( + BeautifulSoup(xml, "xml").compounddef, xmldir=tmp_path + ).to_asciidoc() + + assert asciidoc == dedent( + """\ + [#examples_page] + == Examples Index + + [[examples_page_1md_2_users_2mudge_2_work_2raspberrypi_2databooks_2lib_2pico-sdk_2docs_2examples]] + + This page links to the various example code fragments in this documentation. For more complete examples, please see the https://github.com/raspberrypi/pico-examples[pico-examples] repository, which contains complete buildable projects. + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + * {empty} + + + -- + <> + -- + + All examples are "Copyright (c) 2020 Raspberry Pi (Trading) Ltd", and are released under a 3-Clause BSD licence. Briefly, this means you are free to use the example code as long as you retain the copyright notice. Full details on the licence can be found https://opensource.org/licenses/BSD-3-Clause[here].""" + ) + + +def test_page_node_with_indexpage(tmp_path): + xml = """\ + + index + Raspberry Pi Pico SDK + + + + + The Raspberry Pi Pico SDK (Software Development Kit), henceforth SDK, provides the headers, libraries and build system necessary to write programs for RP-series microcontroller devices such as the Raspberry Pi Pico in C, C++ or assembly language. The SDK is designed to provide an API (Application Programming Interface) and programming environment that is familiar both to non-embedded C developers and embedded C developers alike. + A single program runs on the device at a time with a conventional main() method. Standard C/C++ libraries are supported along with APIs for accessing the microcontroller's hardware, including DMA, IRQs, and the wide variety of fixed-function peripherals and PIO (Programmable IO). + Additionally the SDK provides higher-level libraries for dealing with timers, USB, synchronization and multi-core programming, along with additional high-level functionality built using PIO, such as audio. The SDK can be used to build anything from simple applications, or full-fledged runtime environments such as MicroPython, to low-level software such as the microcontroller's on-chip bootrom itself. + This documentation is generated from the SDK source tree using Doxygen. It provides basic information on the APIs used for each library, but does not provide usage information. Please refer to the Databooks for usage and more technical information. + + SDK DesignThe RP-series microcontroller range are powerful chips, however they are used in an embedded environment, so both RAM and program space are at premium. Additionally the trade-offs between performance and other factors (e.g. edge-case error handling, runtime vs compile-time configuration) are necessarily much more visible to the developer than they might be on other higher-level platforms. + The intention within the SDK has been for features to just work out of the box, with sensible defaults, but also to give the developer as much control and power as possible (if they want it) to fine-tune every aspect of the application they are building and the libraries used. + + + The Build SystemThe SDK uses CMake to manage the build. CMake is widely supported by IDEs (Integrated Development Environments), and allows a simple specification of the build (via CMakeLists.txt files), from which CMake can generate a build system (for use by make, ninja or other build tools) customized for the platform and by any configuration variables the developer chooses. + Apart from being a widely-used build system for C/C++ development, CMake is fundamental to the way the SDK is structured, and how applications are configured and built. + The SDK builds an executable which is bare-metal, i.e. it includes the entirety of the code needed to run on the device (other than device specific floating-point and other optimized code contained in the bootrom within the microcontroller). + + + ExamplesThis SDK documentation contains a number of example code fragments. An index of these examples can be found here. These examples, and any other source code included in this documentation, is Copyright 2020 Raspberry Pi Ltd and licensed under the 3-Clause BSD license. + + + + + """ + + asciidoc = PageNode( + BeautifulSoup(xml, "xml").compounddef, xmldir=tmp_path + ).to_asciidoc() + + assert asciidoc == dedent( + """\ + [#indexpage] + == Raspberry Pi Pico SDK + + [[index_1md_2_users_2mudge_2_work_2raspberrypi_2databooks_2lib_2pico-sdk_2docs_2mainpage]] + + The Raspberry Pi Pico SDK (Software Development Kit), henceforth SDK, provides the headers, libraries and build system necessary to write programs for RP-series microcontroller devices such as the Raspberry Pi Pico in C, C++ or assembly language. The SDK is designed to provide an API (Application Programming Interface) and programming environment that is familiar both to non-embedded C developers and embedded C developers alike. + + A single program runs on the device at a time with a conventional `main()` method. Standard C/C++ libraries are supported along with APIs for accessing the microcontroller's hardware, including DMA, IRQs, and the wide variety of fixed-function peripherals and PIO (Programmable IO). + + Additionally the SDK provides higher-level libraries for dealing with timers, USB, synchronization and multi-core programming, along with additional high-level functionality built using PIO, such as audio. The SDK can be used to build anything from simple applications, or full-fledged runtime environments such as MicroPython, to low-level software such as the microcontroller's on-chip bootrom itself. + + This documentation is generated from the SDK source tree using Doxygen. It provides basic information on the APIs used for each library, but does not provide usage information. Please refer to the Databooks for usage and more technical information. + + [#index_1autotoc_md3] + === SDK Design + + The RP-series microcontroller range are powerful chips, however they are used in an embedded environment, so both RAM and program space are at premium. Additionally the trade-offs between performance and other factors (e.g. edge-case error handling, runtime vs compile-time configuration) are necessarily much more visible to the developer than they might be on other higher-level platforms. + + The intention within the SDK has been for features to just work out of the box, with sensible defaults, but also to give the developer as much control and power as possible (if they want it) to fine-tune every aspect of the application they are building and the libraries used. + + [#index_1autotoc_md4] + === The Build System + + The SDK uses CMake to manage the build. CMake is widely supported by IDEs (Integrated Development Environments), and allows a simple specification of the build (via `CMakeLists.txt` files), from which CMake can generate a build system (for use by `make`, `ninja` or other build tools) customized for the platform and by any configuration variables the developer chooses. + + Apart from being a widely-used build system for C/C++ development, CMake is fundamental to the way the SDK is structured, and how applications are configured and built. + + The SDK builds an executable which is bare-metal, i.e. it includes the entirety of the code needed to run on the device (other than device specific floating-point and other optimized code contained in the bootrom within the microcontroller). + + [#index_1autotoc_md5] + === Examples + + This SDK documentation contains a number of example code fragments. An index of these examples can be found <>. These examples, and any other source code included in this documentation, is Copyright © 2020 Raspberry Pi Ltd and licensed under the https://opensource.org/licenses/BSD-3-Clause[3-Clause BSD] license.""" + ) diff --git a/tests/test_sect_node.py b/tests/test_sect_node.py index d892330..8e2481b 100644 --- a/tests/test_sect_node.py +++ b/tests/test_sect_node.py @@ -15,31 +15,7 @@ def test_sect_node(tmp_path): assert asciidoc == dedent( """\ [#foo] - .Interrupt Numbers + == Interrupt Numbers Interrupts _are_ numbered as follows.""" ) - - -def test_compounddef_kind_page_is_processed_as_sect(tmp_path): - xml = """\ - - examples_page - Examples Index - - - - First paragraph. - - """ - - asciidoc = Node( - BeautifulSoup(xml, "xml").compounddef, xmldir=tmp_path - ).to_asciidoc() - - assert asciidoc == dedent( - """\ - == Examples Index - - [[my_anchor]] First paragraph.""" - ) diff --git a/tests/test_simplesect_node.py b/tests/test_simplesect_node.py index 449e78a..b2c2a3c 100644 --- a/tests/test_simplesect_node.py +++ b/tests/test_simplesect_node.py @@ -36,21 +36,6 @@ def test_simplesect_with_note_kind(tmp_path): ) -def test_simplesect_with_page_kind(tmp_path): - xml = """\ - - - First paragraph. - - """ - - asciidoc = SimplesectNode( - BeautifulSoup(xml, "xml").detaileddescription, xmldir=tmp_path - ).to_asciidoc() - - assert asciidoc == "[[my_anchor]] First paragraph." - - def test_two_sibling_simplesects_with_note_kind(tmp_path): xml = """This does not work But this does""" diff --git a/tests/test_title_node.py b/tests/test_title_node.py index 2e4c964..66ef78e 100644 --- a/tests/test_title_node.py +++ b/tests/test_title_node.py @@ -7,4 +7,14 @@ def test_title_node(tmp_path): asciidoc = TitleNode(BeautifulSoup(xml, "xml").title, xmldir=tmp_path).to_asciidoc() - assert asciidoc == ".Interrupt Numbers" + assert asciidoc == "= Interrupt Numbers" + + +def test_title_node_with_depth(tmp_path): + xml = """Interrupt Numbers""" + + asciidoc = TitleNode(BeautifulSoup(xml, "xml").title, xmldir=tmp_path).to_asciidoc( + depth=2 + ) + + assert asciidoc == "=== Interrupt Numbers" From 28b49dbdd06395f28dacce2fcbfc6428e4338650 Mon Sep 17 00:00:00 2001 From: Paul Mucur Date: Tue, 20 Aug 2024 15:48:36 +0100 Subject: [PATCH 2/2] Pass an explicit depth when rendering nodes Rather than having a mix of depths and hard-coded levels for certain titles, rely entirely on a `depth` keyword argument passed to `to_asciidoc` which dictates the current level of any node. It is a parent node's responsibility to increase the depth when rendering a child that introduces a new level (e.g. a detailed description inside a module). This way, we can render the Doxygen index starting at depth 2 and any arbitrary pages (e.g. the Examples page) at depth 1. This also fixes the level of ``s within `<sect1>`s (e.g. the "Interrupt Numbers" section of hardware_irq). --- cli.py | 4 +- nodes.py | 257 +++++++++++---------- tests/test_define_memberdef_node.py | 6 +- tests/test_define_sectiondef_node.py | 4 +- tests/test_detaileddescription_node.py | 10 +- tests/test_doxygenindex_node.py | 2 +- tests/test_enum_memberdef_node.py | 6 +- tests/test_enum_sectiondef_node.py | 8 +- tests/test_function_memberdef_node.py | 6 +- tests/test_function_sectiondef_node.py | 8 +- tests/test_group_node.py | 2 +- tests/test_helpers.py | 20 ++ tests/test_page_node.py | 4 +- tests/test_typedef_memberdef_node.py | 2 +- tests/test_typedef_sectiondef_node.py | 8 +- tests/test_user_defined_sectiondef_node.py | 2 +- tests/test_variable_memberdef_node.py | 6 +- tests/test_variable_sectiondef_node.py | 14 +- 18 files changed, 198 insertions(+), 171 deletions(-) diff --git a/cli.py b/cli.py index 67a6a54..4ff4a42 100644 --- a/cli.py +++ b/cli.py @@ -32,11 +32,11 @@ def main(): if is_child: result = Node( BeautifulSoup(xml, "xml").doxygen, xmldir=xmldir - ).to_asciidoc() + ).to_asciidoc(depth=1) else: result = DoxygenindexNode( BeautifulSoup(xml, "xml").doxygenindex, xmldir=xmldir - ).to_asciidoc() + ).to_asciidoc(depth=2) if output_filename is not None: with open(output_filename, "w", encoding="utf-8") as output: output.write(result) diff --git a/nodes.py b/nodes.py index 7af4207..74f3606 100644 --- a/nodes.py +++ b/nodes.py @@ -285,7 +285,7 @@ def nodefor(self, element): class DoxygenindexNode(Node): """Return the AsciiDoc representation from a root Doxygen doxygenindex node.""" - def to_asciidoc(self, **kwargs): + def to_asciidoc(self, depth=0, **kwargs): output = [] for module in self.rootmodules(): title_ = module.node.text("title") @@ -296,15 +296,15 @@ def to_asciidoc(self, **kwargs): if self.attributes(skip=["id"]) is not None: attributes.append(self.attributes(skip=["id"])) output.append( - title(title_, 2, ",".join(attributes)), + title(title_, depth, ",".join(attributes)), ) briefdescription = module.node.child("briefdescription").to_asciidoc( - **kwargs + **kwargs, depth=depth ) if briefdescription: output.append(briefdescription) detaileddescription = module.node.child("detaileddescription").to_asciidoc( - documentation=True, **kwargs + **kwargs, documentation=True, depth=depth + 1 ) if detaileddescription: output.append(detaileddescription) @@ -315,7 +315,7 @@ def to_asciidoc(self, **kwargs): if len(table) > 3: output.append("\n".join(table)) for child in module.children: - output.append(child.to_asciidoc(**kwargs)) + output.append(child.to_asciidoc(**kwargs, depth=depth + 1)) return "\n\n".join(output) def rootmodules(self): @@ -359,11 +359,10 @@ def __init__(self, refid): def isroot(self): return self.parent is None - def to_asciidoc(self, **kwargs): - output = [self.node.to_asciidoc(**kwargs)] + def to_asciidoc(self, depth=0, **kwargs): + output = [self.node.to_asciidoc(**kwargs, depth=depth)] for child in self.children: - kwargs["depth"] = kwargs.get("depth", 0) + 1 - output.append(child.to_asciidoc(**kwargs)) + output.append(child.to_asciidoc(**kwargs, depth=depth + 1)) return "\n\n".join(output) def to_asciidoc_row(self, depth=0): @@ -381,77 +380,79 @@ def to_asciidoc_row(self, depth=0): class GroupNode(Node): - def to_asciidoc(self, **kwargs): + def to_asciidoc(self, depth=0, **kwargs): # pylint: disable=too-many-locals,too-many-branches - output = [self.__output_title(**kwargs)] - briefdescription = self.__output_briefdescription(**kwargs) + output = [self.__output_title(depth=depth)] + briefdescription = self.__output_briefdescription(**kwargs, depth=depth) if briefdescription: output.append(briefdescription) - detaileddescription = self.__output_detaileddescription(**kwargs) + detaileddescription = self.__output_detaileddescription( + **kwargs, depth=depth + 1 + ) if detaileddescription: output.append(detaileddescription) - modules = self.__list_modules(**kwargs) + modules = self.__list_modules(**kwargs, depth=depth + 1) if modules: output.append(modules) - macros = self.__list_macros(**kwargs) + macros = self.__list_macros(**kwargs, depth=depth + 1) if macros: output.append(macros) - typedefs = self.__list_typedefs(**kwargs) + typedefs = self.__list_typedefs(**kwargs, depth=depth + 1) if typedefs: output.append(typedefs) - enums = self.__list_enums(**kwargs) + enums = self.__list_enums(**kwargs, depth=depth + 1) if enums: output.append(enums) - functions = self.__list_functions(**kwargs) + functions = self.__list_functions(**kwargs, depth=depth + 1) if functions: output.append(functions) - variables = self.__list_variables(**kwargs) + variables = self.__list_variables(**kwargs, depth=depth + 1) if variables: output.append(variables) - userdefinedsections = self.__list_userdefined_sections(**kwargs) + userdefinedsections = self.__list_userdefined_sections( + **kwargs, depth=depth + 1 + ) if userdefinedsections: output.append(userdefinedsections) - macrodetails = self.__list_macro_details(**kwargs) + macrodetails = self.__list_macro_details(**kwargs, depth=depth + 1) if macrodetails: output.append(macrodetails) - typedefdetails = self.__list_typedef_details(**kwargs) + typedefdetails = self.__list_typedef_details(**kwargs, depth=depth + 1) if typedefdetails: output.append(typedefdetails) - enumdetails = self.__list_enum_details(**kwargs) + enumdetails = self.__list_enum_details(**kwargs, depth=depth + 1) if enumdetails: output.append(enumdetails) - functiondetails = self.__list_function_details(**kwargs) + functiondetails = self.__list_function_details(**kwargs, depth=depth + 1) if functiondetails: output.append(functiondetails) - variabledetails = self.__list_variable_details(**kwargs) + variabledetails = self.__list_variable_details(**kwargs, depth=depth + 1) if variabledetails: output.append(variabledetails) return "\n\n".join(output) - def __output_title(self, **kwargs): + def __output_title(self, depth=0): title_ = self.text("title") attributes = ["#" + self.id, f'reftext="{escape_text(title_)}"'] if self.attributes(skip=["id"]) is not None: attributes.append(self.attributes(skip=["id"])) - return title(title_, 3 + kwargs.get("depth", 0), ",".join(attributes)) + return title(title_, depth, ",".join(attributes)) def __output_briefdescription(self, **kwargs): - kwargs["depth"] = 2 + kwargs.get("depth", 0) return self.child("briefdescription").to_asciidoc(**kwargs) def __output_detaileddescription(self, **kwargs): - kwargs["depth"] = 2 + kwargs.get("depth", 0) return self.child("detaileddescription").to_asciidoc(**kwargs) - def __list_modules(self, **kwargs): + def __list_modules(self, depth=0, **kwargs): innergroups = self.children("innergroup") if not innergroups: return "" - output = [title("Modules", 4 + kwargs.get("depth", 0))] + output = [title("Modules", depth)] modules = [] for innergroup in innergroups: - modules.append(innergroup.to_asciidoc(**kwargs)) + modules.append(innergroup.to_asciidoc(**kwargs, depth=depth)) output.append("\n".join(modules)) return "\n\n".join(output) @@ -523,30 +524,29 @@ def __list_macro_details(self, **kwargs): class PageNode(Node): - def to_asciidoc(self, **kwargs): + def to_asciidoc(self, depth=0, **kwargs): output = [] - title_ = self.__output_title(**kwargs) + title_ = self.__output_title(depth=depth) if title_: output.append(title_) - detaileddescription = self.__output_detaileddescription(**kwargs) + detaileddescription = self.__output_detaileddescription(**kwargs, depth=depth) if detaileddescription: output.append(detaileddescription) return "\n\n".join(output) - def __output_title(self, **kwargs): + def __output_title(self, depth=0): title_ = self.text("title") attributes = ["#" + self.id] if title_: - return title(title_, 1 + kwargs.get("depth", 0), ",".join(attributes)) + return title(title_, depth, ",".join(attributes)) return None def __output_detaileddescription(self, **kwargs): - kwargs["depth"] = 1 + kwargs.get("depth", 0) return self.child("detaileddescription").to_asciidoc( - documentation=True, **kwargs + **kwargs, documentation=True ) @@ -647,15 +647,14 @@ def to_asciidoc(self, **kwargs): class SectNode(Node): - def to_asciidoc(self, **kwargs): - kwargs["depth"] = 1 + kwargs.get("depth", 0) + def to_asciidoc(self, depth=0, **kwargs): attributes = f"[{self.attributes()}]" - return "\n".join((attributes, super().to_asciidoc(**kwargs))) + return "\n".join((attributes, super().to_asciidoc(**kwargs, depth=depth + 1))) class TitleNode(Node): - def to_asciidoc(self, **kwargs): - return title(super().to_asciidoc(**kwargs), kwargs.get("depth", 0)) + def to_asciidoc(self, depth=0, **kwargs): + return title(super().to_asciidoc(**kwargs), depth) class SimplesectNode(Node): @@ -814,15 +813,15 @@ def to_asciidoc(self, **kwargs): class DetaileddescriptionNode(Node): - def to_asciidoc(self, **kwargs): + def to_asciidoc(self, depth=0, **kwargs): output = [] - contents = super().to_asciidoc(**kwargs) + contents = super().to_asciidoc(**kwargs, depth=depth) if contents: if not kwargs.get("documentation", False): output.append( title( "Detailed Description", - 2 + kwargs.get("depth", 0), + depth, self.attributes(), ) ) @@ -832,22 +831,20 @@ def to_asciidoc(self, **kwargs): class FunctionMemberdefNode(Node): - def to_asciidoc(self, **kwargs): - output = [ - title(self.text("name"), 5 + kwargs.get("depth", 0), self.attributes()) - ] + def to_asciidoc(self, depth=0, **kwargs): + output = [title(self.text("name"), depth, self.attributes())] if self.node["static"] == "yes": definition = ["[.memname]`static "] else: definition = ["[.memname]`"] - definition.append(self.child("type").to_asciidoc(**kwargs)) + definition.append(self.child("type").to_asciidoc(**kwargs, depth=depth)) definition.append(f" {escape_text(self.text('name'))} ") params = self.children("param") if params: args = [] for param in params: arg = [] - arg.append(param.child("type").to_asciidoc(**kwargs)) + arg.append(param.child("type").to_asciidoc(**kwargs, depth=depth)) declname = param.text("declname") if declname: arg.append(escape_text(declname)) @@ -865,52 +862,52 @@ def to_asciidoc(self, **kwargs): definition[-1] = definition[-1].rstrip() definition.append("`") output.append("".join(definition)) - kwargs["depth"] = 5 + kwargs.get("depth", 0) - kwargs["documentation"] = True - briefdescription = self.child("briefdescription").to_asciidoc(**kwargs) + briefdescription = self.child("briefdescription").to_asciidoc( + **kwargs, depth=depth + ) if briefdescription: output.append(briefdescription) - detaileddescription = self.child("detaileddescription").to_asciidoc(**kwargs) + detaileddescription = self.child("detaileddescription").to_asciidoc( + **kwargs, depth=depth + 1, documentation=True + ) if detaileddescription: output.append(detaileddescription) return "\n\n".join(output) class TypedefMemberdefNode(Node): - def to_asciidoc(self, **kwargs): - output = [ - title(self.text("name"), 5 + kwargs.get("depth", 0), self.attributes()) - ] + def to_asciidoc(self, depth=0, **kwargs): + output = [title(self.text("name"), depth, self.attributes())] output.append(f"[.memname]`{escape_text(self.text('definition'))}`") - kwargs["depth"] = 5 + kwargs.get("depth", 0) - kwargs["documentation"] = True - briefdescription = self.child("briefdescription").to_asciidoc(**kwargs) + briefdescription = self.child("briefdescription").to_asciidoc( + **kwargs, depth=depth + ) if briefdescription: output.append(briefdescription) - detaileddescription = self.child("detaileddescription").to_asciidoc(**kwargs) + detaileddescription = self.child("detaileddescription").to_asciidoc( + **kwargs, depth=depth + 1, documentation=True + ) if detaileddescription: output.append(detaileddescription) return "\n\n".join(output) class EnumMemberdefNode(Node): - def to_asciidoc(self, **kwargs): + def to_asciidoc(self, depth=0, **kwargs): name = self.text("name") - output = [ - title( - name or "anonymous enum", 5 + kwargs.get("depth", 0), self.attributes() - ) - ] + output = [title(name or "anonymous enum", depth, self.attributes())] if name: output.append(f"[.memname]`enum {escape_text(name)}`") else: output.append("[.memname]`anonymous enum`") - kwargs["depth"] = 5 + kwargs.get("depth", 0) - kwargs["documentation"] = True - briefdescription = self.child("briefdescription").to_asciidoc(**kwargs) + briefdescription = self.child("briefdescription").to_asciidoc( + **kwargs, depth=depth + ) if briefdescription: output.append(briefdescription) - detaileddescription = self.child("detaileddescription").to_asciidoc(**kwargs) + detaileddescription = self.child("detaileddescription").to_asciidoc( + **kwargs, depth=depth + 1, documentation=True + ) if detaileddescription: output.append(detaileddescription) @@ -937,10 +934,10 @@ def to_asciidoc(self, **kwargs): class VariableMemberdefNode(Node): - def to_asciidoc(self, **kwargs): + def to_asciidoc(self, depth=0, **kwargs): name = self.text("name") or self.text("qualifiedname") output = [ - title(name, 5 + kwargs.get("depth", 0), self.attributes()), + title(name, depth, self.attributes()), ] definition = self.text("definition") if self.text("initializer"): @@ -957,22 +954,22 @@ def to_asciidoc(self, **kwargs): ) else: output.append(f"[.memname]`{escape_text(definition)}`") - kwargs["depth"] = 5 + kwargs.get("depth", 0) - kwargs["documentation"] = True - briefdescription = self.child("briefdescription").to_asciidoc(**kwargs) + briefdescription = self.child("briefdescription").to_asciidoc( + **kwargs, depth=depth + ) if briefdescription: output.append(briefdescription) - detaileddescription = self.child("detaileddescription").to_asciidoc(**kwargs) + detaileddescription = self.child("detaileddescription").to_asciidoc( + **kwargs, depth=depth + 1, documentation=True + ) if detaileddescription: output.append(detaileddescription) return "\n\n".join(output) class DefineMemberdefNode(Node): - def to_asciidoc(self, **kwargs): - output = [ - title(self.text("name"), 5 + kwargs.get("depth", 0), self.attributes()) - ] + def to_asciidoc(self, depth=0, **kwargs): + output = [title(self.text("name"), depth, self.attributes())] name = self.text("name") params = [param.text() for param in self.children("param")] if params: @@ -1001,46 +998,50 @@ def to_asciidoc(self, **kwargs): output.append( f"[.memname]`#define {escape_text(name)}{escape_text(argsstring)}`" ) - kwargs["depth"] = 5 + kwargs.get("depth", 0) - kwargs["documentation"] = True - briefdescription = self.child("briefdescription").to_asciidoc(**kwargs) + briefdescription = self.child("briefdescription").to_asciidoc( + **kwargs, depth=depth + ) if briefdescription: output.append(briefdescription) - detaileddescription = self.child("detaileddescription").to_asciidoc(**kwargs) + detaileddescription = self.child("detaileddescription").to_asciidoc( + **kwargs, depth=depth + 1, documentation=True + ) if detaileddescription: output.append(detaileddescription) return "\n\n".join(output) class FunctionSectiondefNode(Node): - def to_details_asciidoc(self, **kwargs): + def to_details_asciidoc(self, depth=0, **kwargs): memberdefs = self.children("memberdef", kind="function") if not memberdefs: return "" - output = [title("Function Documentation", 4 + kwargs.get("depth", 0))] + output = [title("Function Documentation", depth)] functions = [] for memberdef in sorted( memberdefs, key=lambda memberdef: memberdef.text("name") ): - functions.append(memberdef.to_asciidoc(**kwargs)) + functions.append(memberdef.to_asciidoc(**kwargs, depth=depth + 1)) output.append("\n\n".join(functions)) return "\n\n".join(output) - def to_asciidoc(self, **kwargs): - output = [title("Functions", 4 + kwargs.get("depth", 0))] + def to_asciidoc(self, depth=0, **kwargs): + output = [title("Functions", depth)] functions = [] for memberdef in self.children("memberdef", kind="function"): if memberdef["static"] == "yes": function = ["`static "] else: function = ["`"] - function.append(memberdef.child("type").to_asciidoc(**kwargs)) + function.append(memberdef.child("type").to_asciidoc(**kwargs, depth=depth)) function.append( f" <<{memberdef.id},{escape_text(memberdef.text('name'))}>> " ) function.append(f"{escape_text(memberdef.text('argsstring'))}`:: ") - briefdescription = memberdef.child("briefdescription").to_asciidoc(**kwargs) + briefdescription = memberdef.child("briefdescription").to_asciidoc( + **kwargs, depth=depth + ) if briefdescription: function.append(briefdescription) else: @@ -1051,27 +1052,29 @@ def to_asciidoc(self, **kwargs): class TypedefSectiondefNode(Node): - def to_details_asciidoc(self, **kwargs): + def to_details_asciidoc(self, depth=0, **kwargs): memberdefs = self.children("memberdef", kind="typedef") if not memberdefs: return "" - output = [title("Typedef Documentation", 4 + kwargs.get("depth", 0))] + output = [title("Typedef Documentation", depth)] typedefs = [] for memberdef in memberdefs: - typedefs.append(memberdef.to_asciidoc(**kwargs)) + typedefs.append(memberdef.to_asciidoc(**kwargs, depth=depth + 1)) output.append("\n".join(typedefs)) return "\n\n".join(output) - def to_asciidoc(self, **kwargs): - output = [title("Typedefs", 4 + kwargs.get("depth", 0))] + def to_asciidoc(self, depth=0, **kwargs): + output = [title("Typedefs", depth)] typedefs = [] for memberdef in self.children("memberdef", kind="typedef"): - type_ = memberdef.child("type").to_asciidoc(**kwargs) + type_ = memberdef.child("type").to_asciidoc(**kwargs, depth=depth) typedef = [ f"`typedef {type_} <<{memberdef.id},{escape_text(memberdef.text('name'))}>>" f"{escape_text(memberdef.text('argsstring'))}`::" ] - briefdescription = memberdef.child("briefdescription").to_asciidoc(**kwargs) + briefdescription = memberdef.child("briefdescription").to_asciidoc( + **kwargs, depth=depth + ) if briefdescription: typedef.append(briefdescription) else: @@ -1082,20 +1085,20 @@ def to_asciidoc(self, **kwargs): class EnumSectiondefNode(Node): - def to_details_asciidoc(self, **kwargs): + def to_details_asciidoc(self, depth=0, **kwargs): memberdefs = self.children("memberdef", kind="enum") if not memberdefs: return "" - output = [title("Enumeration Type Documentation", 4 + kwargs.get("depth", 0))] + output = [title("Enumeration Type Documentation", depth)] enums = [] for memberdef in memberdefs: - enums.append(memberdef.to_asciidoc(**kwargs)) + enums.append(memberdef.to_asciidoc(**kwargs, depth=depth + 1)) output.append("\n".join(enums)) return "\n\n".join(output) - def to_asciidoc(self, **kwargs): - output = [title("Enumerations", 4 + kwargs.get("depth", 0))] + def to_asciidoc(self, depth=0, **kwargs): + output = [title("Enumerations", depth)] enums = [] for memberdef in self.children("memberdef", kind="enum"): enum = [] @@ -1121,7 +1124,9 @@ def to_asciidoc(self, **kwargs): enumvalues.append(" ".join(value)) enum.append(", ".join(enumvalues)) enum.append(" }`:: ") - briefdescription = memberdef.child("briefdescription").to_asciidoc(**kwargs) + briefdescription = memberdef.child("briefdescription").to_asciidoc( + **kwargs, depth=depth + ) if briefdescription: enum.append(briefdescription) else: @@ -1132,20 +1137,20 @@ def to_asciidoc(self, **kwargs): class DefineSectiondefNode(Node): - def to_details_asciidoc(self, **kwargs): + def to_details_asciidoc(self, depth=0, **kwargs): memberdefs = self.children("memberdef", kind="define") if not memberdefs: return "" - output = [title("Macro Definition Documentation", 4 + kwargs.get("depth", 0))] + output = [title("Macro Definition Documentation", depth)] macros = [] for memberdef in memberdefs: - macros.append(memberdef.to_asciidoc(**kwargs)) + macros.append(memberdef.to_asciidoc(**kwargs, depth=depth + 1)) output.append("\n".join(macros)) return "\n\n".join(output) - def to_asciidoc(self, **kwargs): - output = [title("Macros", 4 + kwargs.get("depth", 0))] + def to_asciidoc(self, depth=0, **kwargs): + output = [title("Macros", depth)] macros = [] for memberdef in self.children("memberdef", kind="define"): params = [param.text() for param in memberdef.children("param")] @@ -1173,24 +1178,24 @@ def to_asciidoc(self, **kwargs): class VariableSectiondefNode(Node): - def to_details_asciidoc(self, **kwargs): + def to_details_asciidoc(self, depth=0, **kwargs): memberdefs = self.children("memberdef", kind="variable") if not memberdefs: return "" - output = [title("Variable Documentation", 4 + kwargs.get("depth", 0))] + output = [title("Variable Documentation", depth)] variables = [] for memberdef in memberdefs: - variables.append(memberdef.to_asciidoc(**kwargs)) + variables.append(memberdef.to_asciidoc(**kwargs, depth=depth + 1)) output.append("\n".join(variables)) return "\n\n".join(output) - def to_asciidoc(self, **kwargs): - output = [title("Variables", 4 + kwargs.get("depth", 0))] + def to_asciidoc(self, depth=0, **kwargs): + output = [title("Variables", depth)] variables = [] for memberdef in self.children("memberdef", kind="variable"): variable = ["`"] - variable.append(memberdef.child("type").to_asciidoc(**kwargs)) + variable.append(memberdef.child("type").to_asciidoc(**kwargs, depth=depth)) variable.append( f" <<{memberdef.id},{escape_text(memberdef.text('name'))}>>" ) @@ -1198,7 +1203,9 @@ def to_asciidoc(self, **kwargs): if argsstring: variable.append(argsstring) variable.append("`:: ") - briefdescription = memberdef.child("briefdescription").to_asciidoc(**kwargs) + briefdescription = memberdef.child("briefdescription").to_asciidoc( + **kwargs, depth=depth + ) if briefdescription: variable.append(briefdescription) else: @@ -1209,16 +1216,16 @@ def to_asciidoc(self, **kwargs): class UserDefinedSectiondefNode(Node): - def to_asciidoc(self, **kwargs): + def to_asciidoc(self, depth=0, **kwargs): output = [] header = self.text("header") if header: - output.append(title(header, 4 + kwargs.get("depth", 0))) + output.append(title(header, depth)) description = self.child("description") if description: - output.append(description.to_asciidoc(**kwargs)) + output.append(description.to_asciidoc(**kwargs, depth=depth)) members = [] for memberdef in self.children("memberdef"): - members.append(memberdef.to_asciidoc(**kwargs)) + members.append(memberdef.to_asciidoc(**kwargs, depth=depth + 1)) output.append("\n".join(members)) return "\n\n".join(output) diff --git a/tests/test_define_memberdef_node.py b/tests/test_define_memberdef_node.py index 01377bb..fe107aa 100644 --- a/tests/test_define_memberdef_node.py +++ b/tests/test_define_memberdef_node.py @@ -22,7 +22,7 @@ def test_to_asciidoc(tmp_path): asciidoc = DefineMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ @@ -55,7 +55,7 @@ def test_to_asciidoc_with_no_initializer(tmp_path): asciidoc = DefineMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ @@ -94,7 +94,7 @@ def test_to_asciidoc_with_multiline_initializer(tmp_path): asciidoc = DefineMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ diff --git a/tests/test_define_sectiondef_node.py b/tests/test_define_sectiondef_node.py index d896356..52b3e78 100644 --- a/tests/test_define_sectiondef_node.py +++ b/tests/test_define_sectiondef_node.py @@ -54,7 +54,7 @@ def test_to_asciidoc(tmp_path): asciidoc = DefineSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -87,7 +87,7 @@ def test_to_details_asciidoc(tmp_path): asciidoc = DefineSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_details_asciidoc() + ).to_details_asciidoc(depth=4) assert asciidoc == dedent( """\ diff --git a/tests/test_detaileddescription_node.py b/tests/test_detaileddescription_node.py index b139b3f..3d569df 100644 --- a/tests/test_detaileddescription_node.py +++ b/tests/test_detaileddescription_node.py @@ -11,7 +11,7 @@ def test_to_asciidoc_includes_title(tmp_path): asciidoc = DetaileddescriptionNode( BeautifulSoup(xml, "xml").detaileddescription, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=2) assert asciidoc == dedent( """\ @@ -29,7 +29,7 @@ def test_to_asciidoc_respects_depth(tmp_path): asciidoc = DetaileddescriptionNode( BeautifulSoup(xml, "xml").detaileddescription, xmldir=tmp_path - ).to_asciidoc(depth=3) + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ @@ -46,7 +46,7 @@ def test_to_asciidoc_writes_nothing_if_the_description_is_empty(tmp_path): asciidoc = DetaileddescriptionNode( BeautifulSoup(xml, "xml").detaileddescription, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=2) assert asciidoc == "" @@ -59,7 +59,7 @@ def test_to_asciidoc_does_not_include_title_if_documentation_is_true(tmp_path): asciidoc = DetaileddescriptionNode( BeautifulSoup(xml, "xml").detaileddescription, xmldir=tmp_path - ).to_asciidoc(documentation=True) + ).to_asciidoc(depth=2, documentation=True) assert asciidoc == "The main `*pico_lwip* library`" @@ -74,7 +74,7 @@ def test_to_asciidoc_handling_whitespace(tmp_path): asciidoc = DetaileddescriptionNode( BeautifulSoup(xml, "xml").detaileddescription, xmldir=tmp_path - ).to_asciidoc(documentation=True) + ).to_asciidoc(depth=2, documentation=True) assert asciidoc == dedent( """\ diff --git a/tests/test_doxygenindex_node.py b/tests/test_doxygenindex_node.py index 19fa04a..4798d31 100644 --- a/tests/test_doxygenindex_node.py +++ b/tests/test_doxygenindex_node.py @@ -76,7 +76,7 @@ def test_to_asciidoc(tmp_path): asciidoc = DoxygenindexNode( BeautifulSoup(xml, "xml").doxygenindex, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=2) assert asciidoc == dedent( """\ diff --git a/tests/test_enum_memberdef_node.py b/tests/test_enum_memberdef_node.py index e199cd2..00e98b4 100644 --- a/tests/test_enum_memberdef_node.py +++ b/tests/test_enum_memberdef_node.py @@ -94,7 +94,7 @@ def test_to_asciidoc(tmp_path): asciidoc = EnumMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ @@ -190,7 +190,7 @@ def test_to_asciidoc_generates_a_table_if_enumvalues_have_descriptions(tmp_path) asciidoc = EnumMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ @@ -261,7 +261,7 @@ def test_to_asciidoc_with_anonymous_enum(tmp_path): asciidoc = EnumMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ diff --git a/tests/test_enum_sectiondef_node.py b/tests/test_enum_sectiondef_node.py index 224787a..6f684b3 100644 --- a/tests/test_enum_sectiondef_node.py +++ b/tests/test_enum_sectiondef_node.py @@ -47,7 +47,7 @@ def test_to_asciidoc(tmp_path): asciidoc = EnumSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -85,7 +85,7 @@ def test_to_asciidoc_with_no_description(tmp_path): asciidoc = EnumSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -123,7 +123,7 @@ def test_to_details_asciidoc(tmp_path): asciidoc = EnumSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_details_asciidoc() + ).to_details_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -174,7 +174,7 @@ def test_to_asciidoc_with_anonymous_enum(tmp_path): asciidoc = EnumSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ diff --git a/tests/test_function_memberdef_node.py b/tests/test_function_memberdef_node.py index c3a1260..365e4bb 100644 --- a/tests/test_function_memberdef_node.py +++ b/tests/test_function_memberdef_node.py @@ -50,7 +50,7 @@ def test_to_asciidoc_with_multiple_args(tmp_path): asciidoc = FunctionMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ @@ -109,7 +109,7 @@ def test_to_asciidoc_with_see_also(tmp_path): asciidoc = FunctionMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ @@ -185,7 +185,7 @@ def test_to_asciidoc_with_ref_in_type(tmp_path): asciidoc = FunctionMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ diff --git a/tests/test_function_sectiondef_node.py b/tests/test_function_sectiondef_node.py index 757d040..0656207 100644 --- a/tests/test_function_sectiondef_node.py +++ b/tests/test_function_sectiondef_node.py @@ -57,7 +57,7 @@ def test_to_asciidoc(tmp_path): asciidoc = FunctionSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -92,7 +92,7 @@ def test_to_asciidoc_with_no_description(tmp_path): asciidoc = FunctionSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -150,7 +150,7 @@ def test_to_asciidoc_with_ref_in_type(tmp_path): asciidoc = FunctionSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -185,7 +185,7 @@ def test_to_details_asciidoc(tmp_path): asciidoc = FunctionSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_details_asciidoc() + ).to_details_asciidoc(depth=4) assert asciidoc == dedent( """\ diff --git a/tests/test_group_node.py b/tests/test_group_node.py index 7fe6fb3..2457322 100644 --- a/tests/test_group_node.py +++ b/tests/test_group_node.py @@ -59,7 +59,7 @@ def test_to_asciidoc(tmp_path): </compounddef>""" asciidoc = GroupNode( BeautifulSoup(xml, "xml").compounddef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=3) assert asciidoc == dedent( """\ diff --git a/tests/test_helpers.py b/tests/test_helpers.py index 38ca6db..968d002 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -33,10 +33,26 @@ def test_sanitize_replaces_multiple_leading_underscores(): assert sanitize("___foo__bar") == "_foo_bar" +def test_title_with_level_0(): + assert title("Level 0 Section Title", 0) == "= Level 0 Section Title" + + def test_title_with_level_1(): assert title("Level 1 Section Title", 1) == "== Level 1 Section Title" +def test_title_with_level_2(): + assert title("Level 2 Section Title", 2) == "=== Level 2 Section Title" + + +def test_title_with_level_3(): + assert title("Level 3 Section Title", 3) == "==== Level 3 Section Title" + + +def test_title_with_level_4(): + assert title("Level 4 Section Title", 4) == "===== Level 4 Section Title" + + def test_title_with_level_5(): assert title("Level 5 Section Title", 5) == "====== Level 5 Section Title" @@ -45,6 +61,10 @@ def test_title_with_level_6(): assert title("Level 6 Section Title", 6) == "[.h6]\n*Level 6 Section Title*" +def test_title_with_level_7(): + assert title("Level 7 Section Title", 7) == "[.h6]\n*Level 7 Section Title*" + + def test_title_escapes_text(): assert title("3 * 2 = 6", 1) == "== 3 ++*++ 2 = 6" diff --git a/tests/test_page_node.py b/tests/test_page_node.py index 444c0ab..5fabd56 100644 --- a/tests/test_page_node.py +++ b/tests/test_page_node.py @@ -38,7 +38,7 @@ def test_page_node_with_example_page(tmp_path): asciidoc = PageNode( BeautifulSoup(xml, "xml").compounddef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=1) assert asciidoc == dedent( """\ @@ -157,7 +157,7 @@ def test_page_node_with_indexpage(tmp_path): asciidoc = PageNode( BeautifulSoup(xml, "xml").compounddef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=1) assert asciidoc == dedent( """\ diff --git a/tests/test_typedef_memberdef_node.py b/tests/test_typedef_memberdef_node.py index cf59100..a2f02ee 100644 --- a/tests/test_typedef_memberdef_node.py +++ b/tests/test_typedef_memberdef_node.py @@ -24,7 +24,7 @@ def test_to_asciidoc(tmp_path): asciidoc = TypedefMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ diff --git a/tests/test_typedef_sectiondef_node.py b/tests/test_typedef_sectiondef_node.py index caf8e6b..454eae6 100644 --- a/tests/test_typedef_sectiondef_node.py +++ b/tests/test_typedef_sectiondef_node.py @@ -26,7 +26,7 @@ def test_to_asciidoc(tmp_path): asciidoc = TypedefSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -58,7 +58,7 @@ def test_to_asciidoc_with_no_description(tmp_path): asciidoc = TypedefSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -90,7 +90,7 @@ def test_to_asciidoc_with_refs_in_type(tmp_path): asciidoc = TypedefSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -123,7 +123,7 @@ def test_to_details_asciidoc(tmp_path): asciidoc = TypedefSectiondefNode( BeautifulSoup(xml, "xml").sectiondef, xmldir=tmp_path - ).to_details_asciidoc() + ).to_details_asciidoc(depth=4) assert asciidoc == dedent( """\ diff --git a/tests/test_user_defined_sectiondef_node.py b/tests/test_user_defined_sectiondef_node.py index 70c6cf7..0888ea1 100644 --- a/tests/test_user_defined_sectiondef_node.py +++ b/tests/test_user_defined_sectiondef_node.py @@ -25,7 +25,7 @@ def test_to_asciidoc(): """ asciidoc = UserDefinedSectiondefNode( BeautifulSoup(xml, "xml").sectiondef - ).to_asciidoc() + ).to_asciidoc(depth=4) assert asciidoc == dedent( """\ diff --git a/tests/test_variable_memberdef_node.py b/tests/test_variable_memberdef_node.py index b6874f4..de0a39e 100644 --- a/tests/test_variable_memberdef_node.py +++ b/tests/test_variable_memberdef_node.py @@ -24,7 +24,7 @@ def test_to_asciidoc(tmp_path): asciidoc = VariableMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ @@ -59,7 +59,7 @@ def test_to_asciidoc_with_no_name(tmp_path): asciidoc = VariableMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ @@ -94,7 +94,7 @@ def test_to_asciidoc_with_initializer(tmp_path): asciidoc = VariableMemberdefNode( BeautifulSoup(xml, "xml").memberdef, xmldir=tmp_path - ).to_asciidoc() + ).to_asciidoc(depth=5) assert asciidoc == dedent( """\ diff --git a/tests/test_variable_sectiondef_node.py b/tests/test_variable_sectiondef_node.py index 4eac0f6..32cbfbf 100644 --- a/tests/test_variable_sectiondef_node.py +++ b/tests/test_variable_sectiondef_node.py @@ -24,9 +24,9 @@ def test_to_asciidoc(): </sectiondef> """ - asciidoc = VariableSectiondefNode( - BeautifulSoup(xml, "xml").sectiondef - ).to_asciidoc() + asciidoc = VariableSectiondefNode(BeautifulSoup(xml, "xml").sectiondef).to_asciidoc( + depth=4 + ) assert asciidoc == dedent( """\ @@ -57,7 +57,7 @@ def test_to_details_asciidoc(): asciidoc = VariableSectiondefNode( BeautifulSoup(xml, "xml").sectiondef - ).to_details_asciidoc() + ).to_details_asciidoc(depth=4) assert asciidoc == dedent( """\ @@ -115,9 +115,9 @@ def test_bug(): </sectiondef> """ - asciidoc = VariableSectiondefNode( - BeautifulSoup(xml, "xml").sectiondef - ).to_asciidoc() + asciidoc = VariableSectiondefNode(BeautifulSoup(xml, "xml").sectiondef).to_asciidoc( + depth=4 + ) assert asciidoc == dedent( """\