-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #412 from ihabunek/rich
Rich text simplification
- Loading branch information
Showing
16 changed files
with
548 additions
and
574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
[flake8] | ||
exclude=build,tests,tmp,venv,toot/tui/scroll.py | ||
ignore=E128,W503 | ||
per-file-ignores=toot/tui/stubs/urwidgets.py:F401 | ||
max-line-length=120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from urwid import Divider, Filler, Pile | ||
from toot.tui.richtext import url_to_widget | ||
from urwidgets import Hyperlink, TextEmbed | ||
|
||
from toot.tui.richtext.richtext import html_to_widgets | ||
|
||
|
||
def test_url_to_widget(): | ||
url = "http://foo.bar" | ||
embed_widget = url_to_widget(url) | ||
assert isinstance(embed_widget, TextEmbed) | ||
|
||
[(filler, length)] = embed_widget.embedded | ||
assert length == len(url) | ||
assert isinstance(filler, Filler) | ||
|
||
link_widget: Hyperlink = filler.base_widget | ||
assert isinstance(link_widget, Hyperlink) | ||
|
||
assert link_widget.attrib == "link" | ||
assert link_widget.text == url | ||
assert link_widget.uri == url | ||
|
||
|
||
def test_html_to_widgets(): | ||
html = """ | ||
<p>foo</p> | ||
<p>foo <b>bar</b> <i>baz</i></p> | ||
""".strip() | ||
|
||
[foo, divider, bar] = html_to_widgets(html) | ||
|
||
assert isinstance(foo, Pile) | ||
assert isinstance(divider, Divider) | ||
assert isinstance(bar, Pile) | ||
|
||
[foo_embed] = foo.widget_list | ||
assert foo_embed.embedded == [] | ||
assert foo_embed.attrib == [] | ||
assert foo_embed.text == "foo" | ||
|
||
[bar_embed] = bar.widget_list | ||
assert bar_embed.embedded == [] | ||
assert bar_embed.attrib == [(None, 4), ("b", 3), (None, 1), ("i", 3)] | ||
assert bar_embed.text == "foo bar baz" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.