Last active
August 19, 2016 09:22
-
-
Save jonasws/48c3fc4cd4bfef7774d3c0fc45814991 to your computer and use it in GitHub Desktop.
Filter that converts HTML to something XML compliant (closing tags++)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' | |
NOTE: This script requires beautifulsoup4 to be installed. | |
Use this script as a filter to convert HTML to XML compliant markup. Useful when pasting raw HTML where XML is expected. | |
Combine with tools like clipcopy to make for a nice copy-and-paste utility, for example: | |
./convert_to_valid_xml.py < index.html | clipcopy | |
''' | |
import sys | |
from bs4 import BeautifulSoup | |
soup = BeautifulSoup(sys.stdin, 'html.parser') | |
print(soup.prettify(formatter='xml')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment