Skip to content

Instantly share code, notes, and snippets.

@arnaud-lb
Created July 13, 2012 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaud-lb/3106073 to your computer and use it in GitHub Desktop.
Save arnaud-lb/3106073 to your computer and use it in GitHub Desktop.
html2haml code style fixed
#!/usr/bin/env python
import subprocess
import re
orig = subprocess.check_output(["/usr/local/bin/html2haml"])
result = orig
result = re.sub(r' ', ' ', result)
def replace(match):
def replace(match):
return '{0}="{1}"'.format(match.group(1), match.group(2))
args = match.group(2)
args = re.sub(r':(\w+) => "(([^\\"]+|\\\\|\\\")*)",?', replace, args)
return '{0}({1})'.format(match.group(1), args)
result = re.sub(r'^(\s*%[\w#.-]+){(.*?)}', replace, result, 0, re.MULTILINE)
print result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment