about summary refs log tree commit diff
path: root/nixos/lib
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2023-01-25 00:21:13 +0100
committerpennae <github@quasiparticle.net>2023-01-26 00:38:06 +0100
commitde22a26b4c66fc27b0dbb1f48ed2082305c3de23 (patch)
tree3d9e639f6befbac38586bb6a21eed5ff11e07f89 /nixos/lib
parent6b677d91489589d7147292c1aaf5f5bea3c54f9d (diff)
nixos/make-options-doc: render option types through md
no changes to rendered output, but options.xml loses a few spaces.
Diffstat (limited to 'nixos/lib')
-rw-r--r--nixos/lib/make-options-doc/optionsToDocbook.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/nixos/lib/make-options-doc/optionsToDocbook.py b/nixos/lib/make-options-doc/optionsToDocbook.py
index 4fedf9edbe192..f9b7dd7f2c496 100644
--- a/nixos/lib/make-options-doc/optionsToDocbook.py
+++ b/nixos/lib/make-options-doc/optionsToDocbook.py
@@ -263,6 +263,10 @@ def convertMD(options: Dict[str, Any]) -> str:
             convertCode(name, option, 'example')
             convertCode(name, option, 'default')
 
+            if typ := option.get('type'):
+                ro = " *(read only)*" if option.get('readOnly', False) else ""
+                option['type'] = md.render(f'*Type:* {md_escape(typ)}{ro}')
+
             if 'relatedPackages' in option:
                 option['relatedPackages'] = md.render(option['relatedPackages'])
         except Exception as e:
@@ -281,6 +285,19 @@ id_translate_table = {
     ord('"'): ord('_'),
 }
 
+md_escape_table = {
+    ord('*'): '\\*',
+    ord('<'): '\\<',
+    ord('['): '\\[',
+    ord('`'): '\\`',
+    ord('.'): '\\.',
+    ord('#'): '\\#',
+    ord('&'): '\\&',
+    ord('\\'): '\\\\',
+}
+def md_escape(s: str) -> str:
+    return s.translate(md_escape_table)
+
 def need_env(n):
     if n not in os.environ:
         raise RuntimeError("required environment variable not set", n)
@@ -358,8 +375,7 @@ for name in keys:
     print(f"""<listitem>""")
     print(opt['description'])
     if typ := opt.get('type'):
-        ro = " <emphasis>(read only)</emphasis>" if opt.get('readOnly', False) else ""
-        print(f"""<para><emphasis>Type:</emphasis> {escape(typ)}{ro}</para>""")
+        print(typ)
     if default := opt.get('default'):
         print(default)
     if example := opt.get('example'):