Skip to content

Commit

Permalink
added POXY_IMPLEMENTATION_DETAIL magic macro
Browse files Browse the repository at this point in the history
also:
- added basic `using` alias detection to syntax highlighter
- added missing badges for C++23, 26 and 29
  • Loading branch information
marzer committed May 28, 2021
1 parent 543bc10 commit ae25ce6
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 20 deletions.
1 change: 1 addition & 0 deletions poxy/data/poxy-badge-c++23.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions poxy/data/poxy-badge-c++26.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions poxy/data/poxy-badge-c++29.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions poxy/data/poxy.css
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,12 @@ ul.m-doc > li.m-doc-collapsible li
{
color: #CCCCCC !important;
}

/* implementation detail blocks */
.poxy-impl
{
padding: 0rem !important;
margin: 0rem 0.2rem !important;
font-weight: normal;
color: rgb(87,166,74) !important;
}
2 changes: 1 addition & 1 deletion poxy/data/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.3
0.3.4
70 changes: 60 additions & 10 deletions poxy/fixers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,22 @@



#=======================================================================================================================
# base classes
#=======================================================================================================================

class HTMLFixer(object):
pass

class PlainTextFixer(object):
pass


#=======================================================================================================================
# custom tags
#=======================================================================================================================

class CustomTags(object):
class CustomTags(HTMLFixer):
'''
Modifies HTML using custom square-bracket [tags].
'''
Expand Down Expand Up @@ -149,7 +160,7 @@ def __call__(self, doc, context):
# C++
#=======================================================================================================================

class _ModifiersBase(object):
class _ModifiersBase(HTMLFixer):
'''
Base type for modifier parsing fixers.
'''
Expand Down Expand Up @@ -241,7 +252,7 @@ def __call__(self, doc, context):



class TemplateTemplate(object):
class TemplateTemplate(HTMLFixer):
'''
Spreads consecutive template <> declarations out over multiple lines.
'''
Expand All @@ -262,7 +273,7 @@ def __call__(self, doc, context):



class StripIncludes(object):
class StripIncludes(HTMLFixer):
'''
Strips #include <paths/to/headers.h> based on context.sources.strip_includes.
'''
Expand Down Expand Up @@ -291,11 +302,31 @@ def __call__(self, doc, context):
return changed



class ImplementationDetails(PlainTextFixer):
'''
Replaces implementation details with appropriate shorthands.
'''
__shorthands = (
(r'POXY_IMPLEMENTATION_DETAIL', r'<code class="m-note m-dim poxy-impl">/* ... */</code>'),
)
def __call__(self, doc, context):
changed = False
for shorthand, replacement in self.__shorthands:
idx = doc[0].find(shorthand)
while idx >= 0:
doc[0] = doc[0][:idx] + replacement + doc[0][idx + len(shorthand):]
changed = True
idx = doc[0].find(shorthand)
return changed



#=======================================================================================================================
# index.html
#=======================================================================================================================

class IndexPage(object):
class IndexPage(HTMLFixer):
'''
Applies some basic fixes to index.html
'''
Expand Down Expand Up @@ -325,7 +356,7 @@ def __call__(self, doc, context):
# <code> blocks
#=======================================================================================================================

class CodeBlocks(object):
class CodeBlocks(HTMLFixer):
'''
Fixes various issues and improves syntax highlighting in <code> blocks.
'''
Expand Down Expand Up @@ -534,6 +565,25 @@ def __call__(self, doc, context):
span['class'] = 'k'
changed_this_block = True

# 'using' statements
spans = code_block('span', class_=('k'), string=r'using')
for using in spans:
assign = using.find_next_sibling('span', class_='o', string='=')
if assign is None:
continue
next = using.next_sibling
while next != assign:
current = next
next = current.next_sibling
if isinstance(current, soup.NavigableString):
if len(current.string.strip()) > 0:
break
continue
if current.name != r'span' or r'class' not in current.attrs or r'n' not in current['class']:
continue
soup.set_class(current, r'ut')
changed_this_block = True

if changed_this_block:
code_block.smooth()
changed_this_pass = True
Expand Down Expand Up @@ -580,7 +630,7 @@ def _m_doc_anchor_tags(tag):



class AutoDocLinks(object):
class AutoDocLinks(HTMLFixer):
'''
Adds links to additional sources where appropriate.
'''
Expand Down Expand Up @@ -645,7 +695,7 @@ def __call__(self, doc, context):



class Links(object):
class Links(HTMLFixer):
'''
Fixes various minor issues with anchor tags.
'''
Expand Down Expand Up @@ -723,7 +773,7 @@ def __call__(self, doc, context):
# empty tags
#=======================================================================================================================

class EmptyTags(object):
class EmptyTags(HTMLFixer):
'''
Prunes the tree of various empty tags (happens as a side-effect of some other operations).
'''
Expand All @@ -741,7 +791,7 @@ def __call__(self, doc, context):
# <head> tags
#=======================================================================================================================

class HeadTags(object):
class HeadTags(HTMLFixer):
'''
Injects poxy-specific tags into the document's <head> block.
'''
Expand Down
34 changes: 25 additions & 9 deletions poxy/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,16 +754,31 @@ def _postprocess_html_file(path, context=None):
assert context is not None
assert isinstance(context, project.Context)

html_fixers = [f for f in context.fixers if isinstance(f, fixers.HTMLFixer)]
plain_text_fixers = [f for f in context.fixers if isinstance(f, fixers.PlainTextFixer)]

context.verbose(rf'Post-processing {path}')
changed = False
doc = soup.HTMLDocument(path, logger=context.verbose_logger)
for fix in context.fixers:
if fix(doc, context):
doc.smooth()
changed = True
if changed:
doc.flush()
return changed
html_changed = False
if html_fixers:
doc = soup.HTMLDocument(path, logger=context.verbose_logger)
for fix in html_fixers:
if fix(doc, context):
doc.smooth()
html_changed = True
if html_changed:
doc.flush()

plain_text_changed = False
if plain_text_fixers:
doc = [ read_all_text_from_file(path, logger=context.verbose_logger) ]
for fix in plain_text_fixers:
if fix(doc, context):
plain_text_changed = True
if plain_text_changed:
with open(path, 'w', encoding='utf-8', newline='\n') as f:
f.write(doc[0])

return html_changed or plain_text_changed



Expand All @@ -790,6 +805,7 @@ def _postprocess_html(context):
, fixers.CustomTags()
, fixers.EmptyTags()
, fixers.HeadTags()
, fixers.ImplementationDetails()
)
context.verbose(rf'Post-processing {len(files)} HTML files...')
if threads > 1:
Expand Down

0 comments on commit ae25ce6

Please sign in to comment.