Minor fixes and code style consistency

This commit is contained in:
faildev_mode 2023-07-19 18:19:27 +02:00
parent 3ec60dbfcb
commit 1a86cafd38
No known key found for this signature in database
GPG Key ID: 70845C70C0F5E205
1 changed files with 10 additions and 8 deletions

View File

@ -66,9 +66,11 @@ def evaluate_this(content: str, global_ns: dict, local_ns: dict = {}) -> str:
use namespace_from() to generate one.
"""
return REGEX['evaluation'].sub(
partial(evaluate, global_ns=global_ns, local_ns=local_ns),
content)
return REGEX['evaluation'].sub(partial(
evaluate,
global_ns=global_ns,
local_ns=local_ns
), content)
def evaluate(match: re.Match, global_ns: dict, local_ns: dict) -> str:
"""Callable for re.sub, returns value of the last Python expression line,
@ -138,8 +140,8 @@ def gemtext2html(parser: GemtextParser, rotate_extension=True) -> BeautifulSoup:
elif item.type == 'preformatted':
el = soup.new_tag('pre')
el.append(item.content)
if el.alt:
el.attrs['title'] = el.alt
if item.alt:
el.attrs['title'] = item.alt
elif item.type == 'list':
el = soup.new_tag('ul')
@ -185,7 +187,7 @@ def convert_href(href: str, path: str) -> str:
), href)
else: output = href
# print(' M', href, '->', output)
# if href != output: print(' M', href, '->', output)
return output
if __name__ == '__main__':
@ -298,7 +300,7 @@ if __name__ == '__main__':
soup = gemtext2html(parser)
content = soup.prettify()
if html_path.endswith('.html'):
if html_path.endswith('.html'):
# TODO: html template
if template := template_for(html_path):
...
@ -308,7 +310,7 @@ if __name__ == '__main__':
for attr in 'href', 'src', 'action':
for node in soup.css.select('['+attr+']'):
node[attr] = convert_href(node[attr], path)
content = str(soup)
content = soup.prettify()
save_this('../html/'+html_path, content)