commit 13ae044a349307551e8fb4c9db0a60d478517444
parent 7da9bfbaffcfa3dc531dbb1fafa4dedb350dbdb3
Author: Isak Lindhé <isak.e.lindhe@gmail.com>
Date: Sun, 6 Jan 2019 11:14:43 +0100
highlighted page numbers
Diffstat:
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/txtv.py b/txtv.py
@@ -59,7 +59,15 @@ def test_page_loop():
assert False
-def show_page(page: bs4.element.Tag):
+def show_page(page: bs4.element.Tag, parent_style=''):
+ def nodetext(node):
+ if isinstance(node, str):
+ return node
+ elif isinstance(node, bs4.element.Tag):
+ if node.name == 'a':
+ return Fore.RED + node.get_text() + Fore.RESET + parent_style
+ else:
+ return ''.join([nodetext(child) for child in node.children])
"""Prints the page contained by the specified tag in color."""
for node in page:
if isinstance(node, str):
@@ -72,7 +80,7 @@ def show_page(page: bs4.element.Tag):
style = Style.DIM
elif 'bgB' in node.attrs['class']:
style = Fore.BLUE
- print(style + node.get_text() + Style.RESET_ALL, end='')
+ print(style + nodetext(node) + Style.RESET_ALL, end='')
def show_headers():
from listing import list_all_articles