From 18be724a5840145866f058dbf3b4c83a85d7b05d Mon Sep 17 00:00:00 2001 From: pennae Date: Wed, 27 Jul 2022 17:50:28 +0200 Subject: [PATCH] nixos/make-options-doc: give MD conversion error locations during docs conversion it can be very useful to know exactly *where* the error the script complained about is. the name of the option should be sufficient since option merging is rather rare, and won't merge doc attributes anyway. --- nixos/lib/make-options-doc/mergeJSON.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/nixos/lib/make-options-doc/mergeJSON.py b/nixos/lib/make-options-doc/mergeJSON.py index 33e5172270b5..e95352f4fe6f 100644 --- a/nixos/lib/make-options-doc/mergeJSON.py +++ b/nixos/lib/make-options-doc/mergeJSON.py @@ -53,12 +53,14 @@ def convertMD(options: Dict[str, Any]) -> str: '.note': 'note' } class Renderer(mistune.renderers.BaseRenderer): + def __init__(self, path): + self.path = path def _get_method(self, name): try: return super(Renderer, self)._get_method(name) except AttributeError: def not_supported(*args, **kwargs): - raise NotImplementedError("md node not supported yet", name, args, **kwargs) + raise NotImplementedError("md node not supported yet", self.path, name, args, **kwargs) return not_supported def text(self, text): @@ -166,8 +168,8 @@ def convertMD(options: Dict[str, Any]) -> str: md.block.rules.append('admonition') plugins.append(admonition) - def convertString(text: str) -> str: - rendered = mistune.markdown(text, renderer=Renderer(), plugins=plugins) + def convertString(path: str, text: str) -> str: + rendered = mistune.markdown(text, renderer=Renderer(path), plugins=plugins) # keep trailing spaces so we can diff the generated XML to check for conversion bugs. return rendered.rstrip() + text[len(text.rstrip()):] @@ -179,12 +181,12 @@ def convertMD(options: Dict[str, Any]) -> str: for (name, option) in options.items(): if optionIs(option, 'description', 'mdDoc'): - option['description'] = convertString(option['description']['text']) + option['description'] = convertString(name, option['description']['text']) if optionIs(option, 'example', 'literalMD'): - docbook = convertString(option['example']['text']) + docbook = convertString(name, option['example']['text']) option['example'] = { '_type': 'literalDocBook', 'text': docbook } if optionIs(option, 'default', 'literalMD'): - docbook = convertString(option['default']['text']) + docbook = convertString(name, option['default']['text']) option['default'] = { '_type': 'literalDocBook', 'text': docbook } return options