diff options
author | rebortg <github@ghlr.de> | 2022-03-07 20:17:00 +0100 |
---|---|---|
committer | rebortg <github@ghlr.de> | 2022-03-07 20:17:00 +0100 |
commit | 682a1fa4dfa5b2625af5c2707ba9a515bfcb651b (patch) | |
tree | b503058689c0b24c348401389259eba0a0272c64 /docs/_ext | |
parent | 848d0372cc3fddb3408b0b91a17ab69efd27316d (diff) | |
download | vyos-documentation-682a1fa4dfa5b2625af5c2707ba9a515bfcb651b.tar.gz vyos-documentation-682a1fa4dfa5b2625af5c2707ba9a515bfcb651b.zip |
md: prepare include directive
Diffstat (limited to 'docs/_ext')
-rw-r--r-- | docs/_ext/vyos.py | 42 |
1 files changed, 42 insertions, 0 deletions
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 |