Closed AceofSpades5757 closed 7 months ago
Hi, Can I kindly request a release to pypi with this fix?
@tardyp This is out on PyPI. I tested it and it works fine.
There's an issue with your earlier snippet that might be the issue. When it's given invalid HTML, it won't raise an exception or warn the user in any way, instead, it just won't work when trying to paste somewhere.
Try this instead. It fixes the missing forward slash in the closing body tag.
from clipboard import Clipboard
with Clipboard() as clipboard:
clipboard.set_clipboard("<html><body><b>hello world</b></body></html>", 'html')
print(clipboard.available_formats())
with Clipboard() as clipboard:
print(clipboard['html'])
@tardyp If it would help, I could add a simple validator using lxml to log a warning to the user when they try to use invalid HTML. Or I could even use it to try and resolve issues with the user's given HTML.
>>> # This is in a REPL, like `py` or `ipython`
>>> from clipboard import set_clipboard
>>> set_clipboard("<h1>invalid", format="html", warn_invalid_html=True)
WARNING - Invalid HTML detected => XMLSyntaxError: htmlParseStartTag: misplaced <html> tag, line 1, column 40
AND/OR
from clipboard import set_clipboard
# The default would be `True` to assist users with invalid HTML
# This would change it to "<html><body><h1>invalid</h1></body></html>" before setting it to the clipboard.
set_clipboard("<h1>invalid", format="html", recover=True)
Note: I don't want to raise an exception if invalid HTML is given, unless I added something like a strict
parameter.
fix #28