summaryrefslogtreecommitdiff
path: root/lib/gir.py
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-10-22 18:43:17 +0000
committerAylur <[email protected]>2024-10-23 01:31:01 +0200
commit9a6c776f8fb145a602bcfe9046955d0d2f268416 (patch)
treee716c94d76cd69d84a983a0b45bb4b8e3df6f85a /lib/gir.py
parente220873b5a9c124b742b221c209334045e2b783c (diff)
docs: notifd doc comments
Diffstat (limited to 'lib/gir.py')
-rw-r--r--lib/gir.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/gir.py b/lib/gir.py
new file mode 100644
index 0000000..8ec786f
--- /dev/null
+++ b/lib/gir.py
@@ -0,0 +1,43 @@
+"""
+Vala's generated gir does not contain comments,
+so we use valadoc to generate them. However, they are formatted
+for valadoc and not gi-docgen so we need to fix it.
+"""
+
+import xml.etree.ElementTree as ET
+import html
+import sys
+import subprocess
+
+
+def fix_gir(gir: str):
+ namespaces = {
+ "": "http://www.gtk.org/introspection/core/1.0",
+ "c": "http://www.gtk.org/introspection/c/1.0",
+ "glib": "http://www.gtk.org/introspection/glib/1.0",
+ }
+ for prefix, uri in namespaces.items():
+ ET.register_namespace(prefix, uri)
+
+ tree = ET.parse(gir)
+ root = tree.getroot()
+
+ for doc in root.findall(".//doc", namespaces):
+ if doc.text:
+ doc.text = (
+ html.unescape(doc.text).replace("<para>", "").replace("</para>", "")
+ )
+
+ tree.write(gir, encoding="utf-8", xml_declaration=True)
+
+
+def valadoc(gir: str, args: list[str]):
+ subprocess.run(["valadoc", "-o", "docs", "--gir", gir, *args])
+
+
+if __name__ == "__main__":
+ gir = sys.argv[1]
+ args = sys.argv[2:]
+
+ valadoc(gir, args)
+ fix_gir(gir)