nixos/make-options-doc: render option types through md

no changes to rendered output, but options.xml loses a few spaces.
This commit is contained in:
pennae 2023-01-25 00:21:13 +01:00
parent 6b677d9148
commit de22a26b4c

View file

@ -263,6 +263,10 @@ def convertMD(options: Dict[str, Any]) -> str:
convertCode(name, option, 'example') convertCode(name, option, 'example')
convertCode(name, option, 'default') 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: if 'relatedPackages' in option:
option['relatedPackages'] = md.render(option['relatedPackages']) option['relatedPackages'] = md.render(option['relatedPackages'])
except Exception as e: except Exception as e:
@ -281,6 +285,19 @@ id_translate_table = {
ord('"'): ord('_'), 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): def need_env(n):
if n not in os.environ: if n not in os.environ:
raise RuntimeError("required environment variable not set", n) raise RuntimeError("required environment variable not set", n)
@ -358,8 +375,7 @@ for name in keys:
print(f"""<listitem>""") print(f"""<listitem>""")
print(opt['description']) print(opt['description'])
if typ := opt.get('type'): if typ := opt.get('type'):
ro = " <emphasis>(read only)</emphasis>" if opt.get('readOnly', False) else "" print(typ)
print(f"""<para><emphasis>Type:</emphasis> {escape(typ)}{ro}</para>""")
if default := opt.get('default'): if default := opt.get('default'):
print(default) print(default)
if example := opt.get('example'): if example := opt.get('example'):