diff --git a/util/html.py b/util/html.py --- a/util/html.py +++ b/util/html.py @@ -13,7 +13,9 @@ self._tag_stack: dict[str, tuple[str, dict[str, str | None]]] = {} self.in_pre: bool = False self.in_code: bool = False - self.invisible: bool = False + + self.invisible: str | None = None + self.invisible_depth: int = 0 def handle_a_endtag(self): label, _attr = self._tag_stack.pop("a") @@ -39,13 +41,16 @@ def handle_starttag(self, tag: str, attrs: list[tuple[str, str | None]]) -> None: _attr = dict(attrs) if self.invisible: + if self.invisible == tag: + self.invisible_depth += 1 + return + + cls = _attr.get("class", "") + if cls and "quote-inline" in cls: + self.invisible = tag return match tag: - case "p": - cls = _attr.get("class", "") - if cls and "quote-inline" in cls: - self.invisible = True case "a": self._tag_stack["a"] = ("", _attr) case "code": @@ -77,8 +82,11 @@ @override def handle_endtag(self, tag: str) -> None: if self.invisible: - if tag == "p": - self.invisible = False + if tag == self.invisible: + if self.invisible_depth == 0: + self.invisible = None + else: + self.invisible_depth = -1 return match tag: