From d2159df64738df01474b248f572c23b735d9ed0e Mon Sep 17 00:00:00 2001 From: Robert Göhler Date: Sat, 4 Jan 2020 12:48:07 +0100 Subject: sphinx: implement latex layout --- docs/_ext/vyos.py | 60 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 11 deletions(-) (limited to 'docs/_ext') diff --git a/docs/_ext/vyos.py b/docs/_ext/vyos.py index 71b039d1..7a3d75ba 100644 --- a/docs/_ext/vyos.py +++ b/docs/_ext/vyos.py @@ -19,16 +19,22 @@ def setup(app): app.add_node( inlinecmd, html=(inlinecmd.visit_span, inlinecmd.depart_span), - latex=(inlinecmd.tex, inlinecmd.tex), + latex=(inlinecmd.visit_tex, inlinecmd.depart_tex), text=(inlinecmd.visit_span, inlinecmd.depart_span) ) app.add_node( CmdDiv, html=(CmdDiv.visit_div, CmdDiv.depart_div), - latex=(CmdDiv.tex, CmdDiv.tex), + latex=(CmdDiv.visit_tex, CmdDiv.depart_tex), text=(CmdDiv.visit_div, CmdDiv.depart_div) ) + app.add_node( + CmdBody, + html=(CmdBody.visit_div, CmdBody.depart_div), + latex=(CmdBody.visit_tex, CmdBody.depart_tex), + text=(CmdBody.visit_div, CmdBody.depart_div) + ) app.add_node( CmdHeader, html=(CmdHeader.visit_div, CmdHeader.depart_div), @@ -88,6 +94,38 @@ class CmdDiv(nodes.General, nodes.Element): def tex(self, node=None): pass + @staticmethod + def visit_tex(self, node=None): + self.body.append('\n\n\\begin{changemargin}{0cm}{0cm}\n') + + @staticmethod + def depart_tex(self, node=None): + self.body.append('\n\\end{changemargin}\n\n') + +class CmdBody(nodes.General, nodes.Element): + + @staticmethod + def visit_div(self, node): + self.body.append(self.starttag(node, 'div')) + + @staticmethod + def depart_div(self, node=None): + self.body.append('\n') + + @staticmethod + def visit_tex(self, node=None): + self.body.append('\n\n\\begin{changemargin}{0.5cm}{0.5cm}\n') + + + @staticmethod + def depart_tex(self, node=None): + self.body.append('\n\\end{changemargin}\n\n') + + + @staticmethod + def tex(self, node=None): + pass + class inlinecmd(nodes.inline): @@ -100,14 +138,14 @@ class inlinecmd(nodes.inline): self.body.append('\n') @staticmethod - def tex(self, node=None): - print('=====================') - #print(json.dumps(dir(self))) - print('---------------------') - print((self.visit_inline)) - exit() - #self.body.append('\\chapter') - pass + def visit_tex(self, node=None): + self.body.append(r'\sphinxbfcode{\sphinxupquote{') + #self.literal_whitespace += 1 + + @staticmethod + def depart_tex(self, node=None): + self.body.append(r'}}') + #self.literal_whitespace -= 1 class CfgcmdlistDirective(Directive): @@ -185,7 +223,7 @@ class CmdDirective(SphinxDirective): self.env.vyos_cfgcmd.append(append_list) if has_body: - body_element = CmdDiv(content_text) + body_element = CmdBody(content_text) self.state.nested_parse( content_list, self.content_offset, -- cgit v1.2.3