Skip to content

Commit

Permalink
fixed regression in [code_blocks] functionality
Browse files Browse the repository at this point in the history
also:
- fixed minor issues in syntax highlighter
- added symbols from tagfiles to the syntax highlighter
- added basic 'blog' functionality (experimental)
- minor style tweaks
  • Loading branch information
marzer committed May 31, 2021
1 parent a3f8a9a commit 8cc3b32
Show file tree
Hide file tree
Showing 13 changed files with 439 additions and 239 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.4.3 - 2020-05-31
- Fixed regression in `[code_blocks]` functionality
- Fixed minor issues in syntax highlighter
- Added symbols from doxygen tagfiles to the syntax highlighter
- Minor style tweaks

## v0.4.1 - 2020-05-30
- Fixed `.dirs` being glommed as source paths
- Added config option `scripts`
Expand Down
10 changes: 0 additions & 10 deletions __main__.py

This file was deleted.

9 changes: 8 additions & 1 deletion poxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
# See https://github.com/marzer/poxy/blob/master/LICENSE for the full license text.
# SPDX-License-Identifier: MIT

from .run import run, main
from .run import run
from .utils import lib_version, Error, WarningTreatedAsError

__all__ = [
r'run',
r'lib_version',
r'Error',
r'WarningTreatedAsError'
]

__version__ = r'.'.join(lib_version())
8 changes: 5 additions & 3 deletions poxy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
# SPDX-License-Identifier: MIT

try:
from poxy.run import main
from poxy.main import _run
except:
from run import main
from main import _run



if __name__ == '__main__':
main()
_run()
22 changes: 22 additions & 0 deletions poxy/data/poxy-light.css
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,28 @@ section > ol li:last-child
margin-top: 0.4rem;
}

/* figures and top-level images */
figure.m-figure
{
margin-top: 1.5rem !important;
}
section > img
{
margin-top: 2rem !important;
margin-bottom: 2rem !important;
}

/* solid m-success boxes */
.m-note.m-success a
{
color: #ffffff !important;
font-weight: bold;
}
.m-note.m-success a:hover
{
text-decoration: underline !important;
}

/* ====================================================
code blocks
==================================================== */
Expand Down
3 changes: 1 addition & 2 deletions poxy/data/poxy.css
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ pre > p.godbolt
figure.m-figure > figcaption
{
font-weight: initial !important;
font-size: initial !important;
font-size: 1rem !important;
text-align: center;
margin-top: initial;
}

figure.m-figure::before
{
border-style: none !important;
Expand Down
2 changes: 1 addition & 1 deletion poxy/data/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.1
0.4.3
55 changes: 32 additions & 23 deletions poxy/fixers.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,24 @@ def __colourize_compound_def(cls, tags, context):

return False

@classmethod
def __adjacent_maybe_by_whitespace(cls, a, b):
mid = a.next_sibling
if mid is b:
return True
if not mid.next_sibling is b:
return False
if not isinstance(mid, soup.NavigableString):
return False
if len(mid.string.strip()) > 0:
return False
return True

def __call__(self, doc, context):
changed = False

# fix up syntax highlighting
code_blocks = doc.body(('pre','code'), class_='m-code')
changed = False
changed_this_pass = True
while changed_this_pass:
changed_this_pass = False
Expand Down Expand Up @@ -490,10 +504,10 @@ def __call__(self, doc, context):
for i in range(0, len(spans)):

current = spans[i]
if current in compound_name_evaluated_tags:
if id(current) in compound_name_evaluated_tags:
continue

compound_name_evaluated_tags.add(current)
compound_name_evaluated_tags.add(id(current))
tags = [ current ]
while True:
prev = current.previous_sibling
Expand All @@ -506,7 +520,7 @@ def __call__(self, doc, context):
break
current = prev
tags.insert(0, current)
compound_name_evaluated_tags.add(current)
compound_name_evaluated_tags.add(id(current))

current = spans[i]
while True:
Expand All @@ -520,7 +534,7 @@ def __call__(self, doc, context):
break
current = nxt
tags.append(current)
compound_name_evaluated_tags.add(current)
compound_name_evaluated_tags.add(id(current))

full_str = ''.join([tag.get_text() for tag in tags])
if self.__ns_full_expr.fullmatch(full_str):
Expand Down Expand Up @@ -555,33 +569,30 @@ def __call__(self, doc, context):
spans = code_block('span', class_=('n', 'nl', 'kt', 'nc', 'nf'), string=True)
for span in spans:
if context.code_blocks.macros.fullmatch(span.get_text()):
soup.set_class(span, 'm')
soup.set_class(span, r'm')
changed_this_block = True

# misidentifed keywords
spans = code_block('span', class_=('nf', 'nb', 'kt', 'ut', 'kr'), string=True)
for span in spans:
if (span.string in self.__keywords):
span['class'] = 'k'
soup.set_class(span, r'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
if 1:
spans = code_block(r'span', class_=r'k', string=r'using')
for using in spans:
next_identifier = using.find_next_sibling(r'span', class_=r'n', string=True)
if next_identifier is None:
continue
if current.name != r'span' or r'class' not in current.attrs or r'n' not in current['class']:
next_assign = next_identifier.find_next_sibling(r'span', class_=r'o', string=r'=')
if next_assign is None:
continue
soup.set_class(current, r'ut')
if not (self.__adjacent_maybe_by_whitespace(using, next_identifier)
and self.__adjacent_maybe_by_whitespace(next_identifier, next_assign)):
continue
soup.set_class(next_identifier, r'ut')
changed_this_block = True

if changed_this_block:
Expand All @@ -591,7 +602,6 @@ def __call__(self, doc, context):

# fix doxygen butchering code blocks as inline nonsense
code_blocks = doc.body('code', class_=('m-code', 'm-console'))
changed = False
changed_this_pass = True
while changed_this_pass:
changed_this_pass = False
Expand All @@ -610,7 +620,6 @@ def __call__(self, doc, context):
or (len(parent.contents) == 1
and parent.contents[0].string.strip() == '')):
soup.destroy_node(parent)

changed = changed or changed_this_pass

return changed
Expand Down
Loading

0 comments on commit 8cc3b32

Please sign in to comment.