mirror of
https://github.com/ihabunek/toot.git
synced 2024-09-22 04:25:55 -04:00
Extract palette names to a constant
to avoid calculating it each time the class is constructed.
This commit is contained in:
parent
b99a193704
commit
9efac32228
@ -10,12 +10,10 @@ from .constants import PALETTE
|
|||||||
from bs4.element import NavigableString, Tag
|
from bs4.element import NavigableString, Tag
|
||||||
|
|
||||||
|
|
||||||
class ContentParser:
|
PALETTE_NAMES = [name for name, _, _ in PALETTE]
|
||||||
def __init__(self):
|
|
||||||
self.palette_names = []
|
|
||||||
for p in PALETTE:
|
|
||||||
self.palette_names.append(p[0])
|
|
||||||
|
|
||||||
|
|
||||||
|
class ContentParser:
|
||||||
"""Parse a limited subset of HTML and create urwid widgets."""
|
"""Parse a limited subset of HTML and create urwid widgets."""
|
||||||
|
|
||||||
def html_to_widgets(self, html) -> List[urwid.Widget]:
|
def html_to_widgets(self, html) -> List[urwid.Widget]:
|
||||||
@ -23,6 +21,7 @@ class ContentParser:
|
|||||||
widgets: List[urwid.Widget] = []
|
widgets: List[urwid.Widget] = []
|
||||||
html = unicodedata.normalize("NFKC", html)
|
html = unicodedata.normalize("NFKC", html)
|
||||||
soup = bs4_parse(html)
|
soup = bs4_parse(html)
|
||||||
|
|
||||||
for e in soup.body or soup:
|
for e in soup.body or soup:
|
||||||
if isinstance(e, NavigableString):
|
if isinstance(e, NavigableString):
|
||||||
continue
|
continue
|
||||||
@ -121,7 +120,7 @@ class ContentParser:
|
|||||||
style_name = "class_" + "_".join(clss)
|
style_name = "class_" + "_".join(clss)
|
||||||
# return the class name, only if we
|
# return the class name, only if we
|
||||||
# find it as a defined palette name
|
# find it as a defined palette name
|
||||||
if style_name in self.palette_names:
|
if style_name in PALETTE_NAMES:
|
||||||
return style_name
|
return style_name
|
||||||
|
|
||||||
# fallback to returning the tag name
|
# fallback to returning the tag name
|
||||||
|
Loading…
Reference in New Issue
Block a user