Skip to content

Instantly share code, notes, and snippets.

@eliasdorneles
Created June 28, 2016 17:29
Show Gist options
  • Save eliasdorneles/64a0a62e5473ac6bf39d9dc5c39c0eac to your computer and use it in GitHub Desktop.
Save eliasdorneles/64a0a62e5473ac6bf39d9dc5c39c0eac to your computer and use it in GitHub Desktop.
>>> js_with_html_comments = u'<!-- some... --> alert("oi"); <!-- ...comments -->'
>>> import js2xml
>>> from lxml import etree
>>> def strip_comments(js):
....: node = etree.fromstring(u'<node>%s</node>' % js)
....: etree.strip_tags(node, etree.Comment)
....: return node.text
....:
>>> strip_comments(js_with_html_comments)
' alert("oi"); '
>>> js2xml.parse(strip_comments(js_with_html_comments))
<Element program at 0x7fca876e6d88>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment