From 682a1fa4dfa5b2625af5c2707ba9a515bfcb651b Mon Sep 17 00:00:00 2001 From: rebortg Date: Mon, 7 Mar 2022 20:17:00 +0100 Subject: md: prepare include directive --- docs/_ext/vyos.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/_ext/vyos.py b/docs/_ext/vyos.py index 667f2777..ff30ef3c 100644 --- a/docs/_ext/vyos.py +++ b/docs/_ext/vyos.py @@ -77,6 +77,7 @@ def setup(app): app.add_directive('cfgcmd', CfgCmdDirective) app.add_directive('opcmd', OpCmdDirective) app.add_directive('cmdinclude', CfgInclude) + app.add_directive('cmdincludemd', CmdInclude) app.connect('doctree-resolved', process_cmd_nodes) app.connect('doctree-read', handle_document_meta_data) @@ -319,6 +320,47 @@ class CfgInclude(SphinxDirective): self.state_machine.insert_input(new_include_lines, path) return [] +class CmdInclude(SphinxDirective): + ''' + 2nd CMDInclude only for Markdown, just the migration process + ''' + + has_content = False + required_arguments = 1 + optional_arguments = 0 + option_spec = { + 'var0': str, + 'var1': str, + 'var2': str, + 'var3': str, + 'var4': str, + 'var5': str, + 'var6': str, + 'var7': str, + 'var8': str, + 'var9': str + } + + def run(self): + include_file = self.env.relfn2path(self.arguments[0]) + + f = open(include_file[1], "r") + file_content = f.readlines() + f.close() + + new_include_lines = [] + for line in file_content: + for i in range(10): + value = self.options.get(f'var{i}','') + if value == '': + line = re.sub('\s?{{\s?var' + str(i) + '\s?}}',value,line) + else: + line = re.sub('{{\s?var' + str(i) + '\s?}}',value,line) + new_include_lines.append(line) + + self.state._renderer.nested_render_text(''.join(new_include_lines), self.lineno) + return [] + class CfgcmdlistDirective(Directive): has_content = False -- cgit v1.2.3