[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 10/23] docs/qapidoc: add visit_freeform() method
From: |
John Snow |
Subject: |
[PATCH v2 10/23] docs/qapidoc: add visit_freeform() method |
Date: |
Tue, 14 Jan 2025 13:58:27 -0500 |
Signed-off-by: John Snow <jsnow@redhat.com>
---
docs/sphinx/qapidoc.py | 47 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py
index 658eae3e386..c42cc3705aa 100644
--- a/docs/sphinx/qapidoc.py
+++ b/docs/sphinx/qapidoc.py
@@ -133,6 +133,53 @@ def visit_module(self, path: str) -> None:
self.add_line_raw(f".. qapi:module:: {name}", path, 1)
self.ensure_blank_line()
+ def visit_freeform(self, doc) -> None:
+ # TODO: Once the old qapidoc transformer is deprecated, freeform
+ # sections can be updated to pure rST, and this transformed removed.
+ #
+ # For now, translate our micro-format into rST. Code adapted
+ # from Peter Maydell's freeform().
+
+ assert len(doc.all_sections) == 1, doc.all_sections
+ body = doc.all_sections[0]
+ text = body.text
+ info = doc.info
+
+ if re.match(r"=+ ", text):
+ # Section/subsection heading (if present, will always be the
+ # first line of the block)
+ (heading, _, text) = text.partition("\n")
+ (leader, _, heading) = heading.partition(" ")
+ level = len(leader) + 1 # Implicit +1 for heading in .rST stub
+
+ #
https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#sections
+ markers = {
+ 1: "#",
+ 2: "*",
+ 3: "=",
+ 4: "-",
+ 5: "^",
+ 6: '"',
+ }
+ overline = level <= 2
+ marker = markers[level]
+
+ self.ensure_blank_line()
+ # This credits all 2 or 3 lines to the single source line.
+ if overline:
+ self.add_line(marker * len(heading), info)
+ self.add_line(heading, info)
+ self.add_line(marker * len(heading), info)
+ self.ensure_blank_line()
+
+ # Eat blank line(s) and advance info
+ trimmed = text.lstrip("\n")
+ text = trimmed
+ info = info.next_line(len(text) - len(trimmed) + 1)
+
+ self.add_lines(text, info)
+ self.ensure_blank_line()
+
# Disable black auto-formatter until re-enabled:
# fmt: off
--
2.47.1
- [PATCH v2 04/23] qapi: expand tags to all doc sections, (continued)
- [PATCH v2 04/23] qapi: expand tags to all doc sections, John Snow, 2025/01/14
- [PATCH v2 09/23] qapi/source: allow multi-line QAPISourceInfo advancing, John Snow, 2025/01/14
- [PATCH v2 11/23] docs/qapidoc: add preamble() method, John Snow, 2025/01/14
- [PATCH v2 19/23] docs/qapidoc: add visit_member() method, John Snow, 2025/01/14
- [PATCH v2 05/23] qapi/schema: add __repr__ to QAPIDoc.Section, John Snow, 2025/01/14
- [PATCH v2 12/23] docs/qapidoc: add visit_paragraph() method, John Snow, 2025/01/14
- [PATCH v2 17/23] docs/qapidoc: prepare to record entity being transmogrified, John Snow, 2025/01/14
- [PATCH v2 22/23] docs/qapidoc: implement transmogrify() method, John Snow, 2025/01/14
- [PATCH v2 03/23] docs/qapidoc: remove example section support, John Snow, 2025/01/14
- [PATCH v2 07/23] docs/qapidoc: add transmogrifier class stub, John Snow, 2025/01/14
- [PATCH v2 10/23] docs/qapidoc: add visit_freeform() method,
John Snow <=
- [PATCH v2 18/23] docs/qapidoc: add visit_returns() method, John Snow, 2025/01/14
- [PATCH v2 20/23] docs/qapidoc: add visit_sections() method, John Snow, 2025/01/14
- [PATCH v2 16/23] docs/qapidoc: add visit_feature() method, John Snow, 2025/01/14
- [PATCH v2 21/23] docs/qapidoc: add visit_entity(), John Snow, 2025/01/14
- [PATCH v2 23/23] docs/qapidoc: add transmogrifier test document, John Snow, 2025/01/14