Created
April 29, 2014 14:22
-
-
Save unhammer/11401866 to your computer and use it in GitHub Desktop.
parse html, print it out as-is (python3 boilerplate for html template like stuff)
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/python3 | |
from html.parser import HTMLParser | |
from sys import stdin | |
def p(*value): | |
print(*value, end='') | |
class MyHTMLParser(HTMLParser): | |
def handle_startendtag(self, tag, attrs): | |
p(self.get_starttag_text()) | |
def handle_starttag(self, tag, attrs): | |
p(self.get_starttag_text()) | |
def handle_endtag(self, tag): | |
p("</%s>" % (tag,)) | |
def handle_data(self, data): | |
p(data) | |
def handle_comment(self, data): | |
p("<!--%s-->" % (data,)) | |
def handle_entityref(self, name): | |
p("&%s;" % (name,)) | |
def handle_charref(self, name): | |
p("&#%s;" % (name,)) | |
def handle_decl(self, data): | |
p("<!%s>" % (data,)) | |
def handle_pi(self, data): | |
p("<?%s>" % (data,)) | |
parser = MyHTMLParser(convert_charrefs=False) | |
for line in stdin: | |
parser.feed(line) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment