-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added --plaintext option to command line tools
Now we default to markdown when displaying status messages; the --plaintext option reverts to previous behavior. This switch is used in test_console.py so existing tests will pass; we can add tests in future without --plaintext to test the markdown rendering.
- Loading branch information
1 parent
8cb294f
commit 4be27f8
Showing
7 changed files
with
52 additions
and
45 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
from toot.exceptions import ConsoleError | ||
from pypandoc import convert_text | ||
from toot.richtext.plaintext import html_to_plaintext | ||
from typing import List | ||
|
||
|
||
def html_to_text(html: str, columns=80, highlight_tags=False) -> List: | ||
return [convert_text( | ||
html, | ||
format="html", | ||
to="gfm-raw_html", | ||
extra_args=["--wrap=auto", f"--columns={columns}"], | ||
)] | ||
def html_to_text(html: str, columns=80, render_mode: str = "", highlight_tags=False) -> List: | ||
if render_mode == "plaintext": | ||
return html_to_plaintext(html, columns, highlight_tags) | ||
elif render_mode == "markdown" or render_mode == "": | ||
return [convert_text( | ||
html, | ||
format="html", | ||
to="gfm-raw_html", | ||
extra_args=["--wrap=auto", f"--columns={columns}"], | ||
)] | ||
raise ConsoleError("Unknown render mode; specify 'plaintext' or 'markdown'") |