Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the superscript and subscript tags as optional feature
Browse files Browse the repository at this point in the history
cowboysync committed Jan 25, 2024
1 parent 8d907d4 commit b2a1dda
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion html2text/__init__.py
Original file line number Diff line number Diff line change
@@ -86,6 +86,7 @@ def __init__(
self.tag_callback = None
self.open_quote = config.OPEN_QUOTE # covered in cli
self.close_quote = config.CLOSE_QUOTE # covered in cli
self.ignore_sup_sub = config.IGNORE_SUP_SUB # covered in cli

if out is None:
self.out = self.outtextf
@@ -716,7 +717,7 @@ def link_url(self: HTML2Text, link: str, title: str = "") -> None:
self.out("\n[/code]")
self.p()

if tag in ["sup", "sub"]:
if not self.ignore_sup_sub and tag in ["sup", "sub"]:
if start:
self.o("<{}>".format(tag))
else:
6 changes: 6 additions & 0 deletions html2text/cli.py
Original file line number Diff line number Diff line change
@@ -264,6 +264,12 @@ class bcolors:
)
p.add_argument("filename", nargs="?")
p.add_argument("encoding", nargs="?", default="utf-8")
p.add_argument(
"--ignore-sup-sub",
dest="ignore_sup_sub",
default=config.IGNORE_SUP_SUB,
help="Ignore the sup and sub tags",
)
args = p.parse_args()

if args.filename and args.filename != "-":
3 changes: 3 additions & 0 deletions html2text/config.py
Original file line number Diff line number Diff line change
@@ -163,3 +163,6 @@
# Use double quotation marks when converting the <q> tag.
OPEN_QUOTE = '"'
CLOSE_QUOTE = '"'

# Ignore the sup and sub tags
IGNORE_SUP_SUB = True

0 comments on commit b2a1dda

Please sign in to comment.