Skip to content

Commit

Permalink
htmllaundry: if link_target is a list, use only the first item.
Browse files Browse the repository at this point in the history
And it *must* be a list with lxml 5.2 (new lxml_html_cleaner package), otherwise you get an error when instantiating the cleaner:

```
TypeError: Expected a collection, got str: link_target='_blank'
```
  • Loading branch information
mauritsvanrees committed May 17, 2024
1 parent 7f3aab0 commit 93e5f5b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/euphorie/htmllaundry/cleaners.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
try:
from lxml_html_clean.clean import _find_external_links
except ImportError:
# lxml 4, Plone 6.0.10 or earlier
# lxml 5.1 or earlier, Plone 6.0.10 or earlier
from lxml.html.clean import _find_external_links


Expand All @@ -24,6 +24,8 @@ def force_link_target(self, doc, target):
if target is None:
if "target" in el.attrib:
del el.attrib["target"]
elif isinstance(target, (list, tuple)):
el.set("target", target[0])
else:
el.set("target", target)

Expand Down

0 comments on commit 93e5f5b

Please sign in to comment.