From e616234519141f36fcd978a63578834709cef58d Mon Sep 17 00:00:00 2001 From: Mark Gillard Date: Mon, 26 Apr 2021 23:11:23 +0300 Subject: [PATCH] added empty tag prune step also: - added `NDEBUG` to default set of defines --- README.md | 4 ++++ poxy/fixers.py | 20 ++++++++++++++++++-- poxy/project.py | 1 + poxy/run.py | 3 ++- setup.py | 2 +- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 744e75c..7745ef1 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # poxy Documentation generator for C++ based on Doxygen and [mosra/m.css](https://mcss.mosra.cz/). + +``` +pip install poxy +``` diff --git a/poxy/fixers.py b/poxy/fixers.py index e683ec9..208677c 100644 --- a/poxy/fixers.py +++ b/poxy/fixers.py @@ -637,7 +637,7 @@ class Links(object): def __call__(self, doc, context): changed = False - for anchor in doc.body('a', recursive=True, href=True): + for anchor in doc.body('a', href=True): href = anchor['href'] # make sure links to external sources are correctly marked as such @@ -680,7 +680,7 @@ def __call__(self, doc, context): # make sure internal documentation #id links actually have somewhere to go if (is_mdoc and href.startswith(r'#') - and (len(href) == 1 or doc.body.find(id=href[1:], recursive=True) is None)): + and (len(href) == 1 or doc.body.find(id=href[1:]) is None)): changed = True soup.remove_class(anchor, 'm-doc') soup.add_class(anchor, 'm-doc-self') @@ -697,3 +697,19 @@ def __call__(self, doc, context): continue return changed + +#======================================================================================================================= +# empty tags +#======================================================================================================================= + +class EmptyTags(object): + ''' + Prunes the tree of various empty tags (happens as a side-effect of some other operations). + ''' + def __call__(self, doc, context): + changed = False + for tag in doc.body((r'p', r'span')): + if not tag.contents or (len(tag.contents) == 1 and isinstance(tag.contents[0], soup.NavigableString) and not tag.string): + soup.destroy_node(tag) + changed = True + return changed diff --git a/poxy/project.py b/poxy/project.py index 9daeb38..a6b8709 100644 --- a/poxy/project.py +++ b/poxy/project.py @@ -81,6 +81,7 @@ class _Defaults(object): r'[Mm]at(?:rix)?[1-4](?:[xX][1-4])?[hifd]?' } defines = { + r'NDEBUG' : 1, r'DOXYGEN' : 1, r'__DOXYGEN__' : 1, r'__doxygen__' : 1, diff --git a/poxy/run.py b/poxy/run.py index 8df2e5e..01ed0f3 100644 --- a/poxy/run.py +++ b/poxy/run.py @@ -716,7 +716,7 @@ def _postprocess_html_file(path, context=None): if fix(doc, context): doc.smooth() changed = True - if (changed): + if changed: doc.flush() return changed @@ -743,6 +743,7 @@ def _postprocess_html(context): , fixers.AutoDocLinks() , fixers.Links() , fixers.CustomTags() + , fixers.EmptyTags() ) context.verbose(rf'Post-processing {len(files)} HTML files...') if threads > 1: diff --git a/setup.py b/setup.py index b979c61..6270940 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ def enum_subdirs(root): setup_args = dict( name=r'poxy', - version=r'0.1.0', + version=r'0.1.1', description=r'Documentation generator for C++.', long_description_content_type=r'text/markdown', long_description=f'{README}\n\n{HISTORY}'.strip(),