X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=docs%2F_scripts%2Fsiphon%2Fprocess.py;fp=doxygen%2Fsiphon%2Fprocess.py;h=e3a70152487fcca1626f7d5c8f93243e76c20864;hb=9ad39c026c8a3c945a7003c4aa4f5cb1d4c80160;hp=ce70be5b3998a2d20582580207c9167e0646ad9d;hpb=f47122e07e1ecd0151902a3cabe46c60a99bee8e;p=vpp.git diff --git a/doxygen/siphon/process.py b/docs/_scripts/siphon/process.py similarity index 74% rename from doxygen/siphon/process.py rename to docs/_scripts/siphon/process.py index ce70be5b399..e3a70152487 100644 --- a/doxygen/siphon/process.py +++ b/docs/_scripts/siphon/process.py @@ -19,6 +19,7 @@ import json import logging import os import sys +import re import jinja2 @@ -57,10 +58,13 @@ class Siphon(object): """Directory to look for siphon rendering templates""" template_directory = None + """Directory to output parts in""" + outdir = None + """Template environment, if we're using templates""" _tplenv = None - def __init__(self, template_directory, format): + def __init__(self, template_directory, format, outdir, repository_link): super(Siphon, self).__init__() self.log = logging.getLogger("siphon.process.%s" % self.name) @@ -78,11 +82,12 @@ class Siphon(object): _tpldir(self.name), _tpldir("default"), ] + self.outdir = outdir loader = jinja2.FileSystemLoader(searchpath=searchpath) self._tplenv = jinja2.Environment( loader=loader, trim_blocks=True, - autoescape=True, + autoescape=False, keep_trailing_newline=True) # Convenience, get a reference to the internal escape and @@ -92,6 +97,9 @@ class Siphon(object): self.escape = html.escape self.unescape = html.unescape + # TODO: customize release + self.repository_link = repository_link + # Output renderers """Returns an object to be used as the sorting key in the item index.""" @@ -284,9 +292,90 @@ class Siphon(object): # Generate the item itself (save for later) contents += self.item_format(meta, o) + page_name = self.separate_page_names(group) + if page_name != "": + path = os.path.join(self.outdir, page_name) + with open(path, "w+") as page: + page.write(contents) + contents = "" + # Deliver the accumulated body output out.write(contents) + def do_cliexstart(self, matchobj): + title = matchobj.group(1) + title = ' '.join(title.splitlines()) + content = matchobj.group(2) + content = re.sub(r"\n", r"\n ", content) + return "\n\n.. code-block:: console\n\n %s\n %s\n\n" % (title, content) + + def do_clistart(self, matchobj): + content = matchobj.group(1) + content = re.sub(r"\n", r"\n ", content) + return "\n\n.. code-block:: console\n\n %s\n\n" % content + + def do_cliexcmd(self, matchobj): + content = matchobj.group(1) + content = ' '.join(content.splitlines()) + return "\n\n.. code-block:: console\n\n %s\n\n" % content + + def process_list(self, matchobj): + content = matchobj.group(1) + content = self.reindent(content, 2) + return "@@@@%s\nBBBB" % content + + def process_special(self, s): + # ----------- markers to remove + s = re.sub(r"@cliexpar\s*", r"", s) + s = re.sub(r"@parblock\s*", r"", s) + s = re.sub(r"@endparblock\s*", r"", s) + s = re.sub(r"
", "", s) + # ----------- emphasis + # + s = re.sub(r"\s*", "``", s) + s = re.sub(r"\s*", "``", s) + s = re.sub(r"\s*", "``", s) + # + s = re.sub(r"\s*", "**", s) + s = re.sub(r"\s*", "**", s) + # + s = re.sub(r"\s*", "``", s) + s = re.sub(r"\s*", "``", s) + # + s = re.sub(r"'?\s*", r"``", s) + s = re.sub(r"\s*'?", r"``", s) + # @c + s = re.sub(r"@c\s(\S+)", r"``\1``", s) + # ----------- todos + s = re.sub(r"@todo[^\n]*", "", s) + s = re.sub(r"@TODO[^\n]*", "", s) + # ----------- code blocks + s = re.sub(r"@cliexcmd{(.+?)}", self.do_cliexcmd, s, flags=re.DOTALL) + s = re.sub(r"@cliexstart{(.+?)}(.+?)@cliexend", self.do_cliexstart, s, flags=re.DOTALL) + s = re.sub(r"@clistart(.+?)@cliend", self.do_clistart, s, flags=re.DOTALL) + # ----------- lists + s = re.sub(r"^\s*-", r"\n@@@@", s, flags=re.MULTILINE) + s = re.sub(r"@@@@(.*?)\n\n+", self.process_list, s, flags=re.DOTALL) + s = re.sub(r"BBBB@@@@", r"-", s) + s = re.sub(r"@@@@", r"-", s) + s = re.sub(r"BBBB", r"\n\n", s) + # ----------- Cleanup remains + s = re.sub(r"@cliexend\s*", r"", s) + return s + + def separate_page_names(self, group): + return "" + + # This push the given textblock spaces right + def reindent(self, s, indent): + ind = " " * indent + s = re.sub(r"\n", "\n" + ind, s) + return s + + # This aligns the given textblock left (no indent) + def noindent(self, s): + s = re.sub(r"\n[ \f\v\t]*", "\n", s) + return s class Format(object): """Output format class"""