enabled multiple values for one tag attribute

This commit is contained in:
Daniil Fajnberg 2021-07-25 17:33:06 +02:00
parent e92924e28a
commit 6a4efbd162
3 changed files with 10 additions and 5 deletions

View File

@ -53,7 +53,9 @@ target:
# Example: # Example:
#attrs: #attrs:
#id: firstHeading #id: firstHeading
#class: foo #class:
# - foo
# - example
#role: bar #role: bar
# Filter using a custom python function with the path specified in dot-notation. # Filter using a custom python function with the path specified in dot-notation.

View File

@ -148,15 +148,18 @@ def tag_filter(tag: Tag, name: str = None, text: str = None, attrs: TagAttrs = N
return False return False
if not string_matches(tag.text, text, regex): if not string_matches(tag.text, text, regex):
return False return False
for attr_name, attr_value in attrs.items(): for attr_name, attr_values in attrs.items():
try: try:
values = tag[attr_name] values = tag[attr_name]
except KeyError: except KeyError:
return False return False
if not isinstance(values, list): if not isinstance(values, list):
values = [values] values = [values]
if not any(string_matches(value, attr_value, regex) for value in values): if not isinstance(attr_values, list):
return False attr_values = [attr_values]
for attr_value in attr_values:
if not any(string_matches(value, attr_value, regex) for value in values):
return False
if func: if func:
return func(tag) return func(tag)
return True return True

View File

@ -9,8 +9,8 @@ import yaml
from soupjobs import SOUPJOBS, CONFIG_FILE_ENV_VAR, CONFIG_FILE_PLACEHOLDER from soupjobs import SOUPJOBS, CONFIG_FILE_ENV_VAR, CONFIG_FILE_PLACEHOLDER
TagAttrs = Dict[str, str]
StrListOrStr = Union[str, List[str]] StrListOrStr = Union[str, List[str]]
TagAttrs = Dict[str, StrListOrStr]
OptInt = Optional[int] OptInt = Optional[int]
OptStr = Optional[str] OptStr = Optional[str]
OptPyObj = Optional[PyObject] OptPyObj = Optional[PyObject]