From de22a26b4c66fc27b0dbb1f48ed2082305c3de23 Mon Sep 17 00:00:00 2001 From: pennae Date: Wed, 25 Jan 2023 00:21:13 +0100 Subject: [PATCH] nixos/make-options-doc: render option types through md no changes to rendered output, but options.xml loses a few spaces. --- .../lib/make-options-doc/optionsToDocbook.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/nixos/lib/make-options-doc/optionsToDocbook.py b/nixos/lib/make-options-doc/optionsToDocbook.py index 4fedf9edbe19..f9b7dd7f2c49 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"""""") print(opt['description']) if typ := opt.get('type'): - ro = " (read only)" if opt.get('readOnly', False) else "" - print(f"""Type: {escape(typ)}{ro}""") + print(typ) if default := opt.get('default'): print(default) if example := opt.get('example'):