Skip to content

Commit

Permalink
Merge pull request #328 from tatuylonen/find-html
Browse files Browse the repository at this point in the history
find_html: allow list of tags to find.
  • Loading branch information
xxyzz authored Oct 22, 2024
2 parents a709d4b + 3400f75 commit d2151af
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/wikitextprocessor/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def filter_empty_str_child(self) -> Iterator[Union[str, "WikiNode"]]:
@overload
def find_html(
self,
target_tag: str,
target_tags: str | list[str],
with_index: Literal[True],
attr_name: str,
attr_value: str,
Expand All @@ -505,15 +505,15 @@ def find_html(
@overload
def find_html(
self,
target_tag: str,
target_tags: str | list[str],
with_index: Literal[False] = ...,
attr_name: str = ...,
attr_value: str = ...,
) -> Iterator["HTMLNode"]: ...

def find_html(
self,
target_tag: str,
target_tags: str | list[str],
with_index: bool = False,
attr_name: str = "",
attr_value: str = "",
Expand All @@ -523,7 +523,9 @@ def find_html(
if TYPE_CHECKING:
assert isinstance(node, HTMLNode)
# node.tag is an alias for node.sarg defined in HTMLNode
if node.tag == target_tag:
if isinstance(target_tags, str):
target_tags = [target_tags]
if node.tag in target_tags:
if len(attr_name) > 0 and attr_value not in node.attrs.get(
attr_name, {}
):
Expand Down

0 comments on commit d2151af

Please sign in to comment.