Skip to content

Commit

Permalink
Added support of wbr tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-nikolaev committed Jan 11, 2024
1 parent 087d0d9 commit 8acd246
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/sulguk/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"ListItem",
"NewLine",
"HorizontalLine",
"ZeroWidthSpace",
"Progress",
"Stub",
"Text",
Expand All @@ -41,7 +42,7 @@
)
from .emoji import Emoji
from .list import ListGroup, ListItem
from .no_contents import HorizontalLine, NewLine
from .no_contents import HorizontalLine, NewLine, ZeroWidthSpace
from .progress import Progress
from .stub import Stub
from .text import Text
5 changes: 5 additions & 0 deletions src/sulguk/entities/no_contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ def render(self, state: State) -> None:
state.canvas.add_new_line_soft()
state.canvas.add_text("⎯" * 10)
state.canvas.add_new_line_soft()


class ZeroWidthSpace(NoContents):
def render(self, state: State) -> None:
state.canvas.add_text("\u200b")
5 changes: 4 additions & 1 deletion src/sulguk/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Text,
Underline,
Uppercase,
ZeroWidthSpace,
)

Attrs = List[Tuple[str, Optional[str]]]
Expand All @@ -39,7 +40,7 @@

LANG_CLASS_PREFIX = "language-"

NO_CLOSING_TAGS = ("br", "hr", "meta", "link", "img")
NO_CLOSING_TAGS = ("br", "wbr", "hr", "meta", "link", "img")


class Transformer(HTMLParser):
Expand Down Expand Up @@ -196,6 +197,8 @@ def _get_tg_emoji(self, attrs: Attrs) -> Entity:
def handle_startendtag(self, tag: str, attrs: Attrs) -> None:
if tag == "br":
entity = NewLine()
elif tag == "wbr":
entity = ZeroWidthSpace()
elif tag == "hr":
entity = HorizontalLine()
elif tag in ("img",):
Expand Down

0 comments on commit 8acd246

Please sign in to comment.