Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new lxml_html_clean package when available. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Changelog
2.3 (unreleased)
----------------

- Nothing changed yet.
* Use new ``lxml_html_clean`` package when available.
You need this when you are using ``lxml`` 5.2 or later.
We don't want to make this a hard dependency.
When you use Plone 6.0.11 or later, you must use this new ``htmllaundry`` version.
Fine for older Plone versions as well.


2.2 (2020-01-28)
Expand Down
13 changes: 10 additions & 3 deletions htmllaundry/cleaners.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from lxml.html.clean import Cleaner
from lxml.html.clean import _find_external_links
try:
from lxml_html_clean.clean import _find_external_links
from lxml_html_clean.clean import Cleaner
except ImportError:
# BBB for lxml 5.1 or earlier
from lxml.html.clean import _find_external_links
from lxml.html.clean import Cleaner


marker = []
Expand All @@ -18,6 +23,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 Expand Up @@ -71,7 +78,7 @@ def force_link_target(self, doc, target):
processing_instructions=False,
frames=False,
annoying_tags=False,
link_target="_blank")
link_target=["_blank"])


__all__ = ['DocumentCleaner', 'LineCleaner', 'CommentCleaner']
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.4',
'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Text Processing :: Markup :: HTML',
],
Expand Down