Created
July 13, 2012 17:15
-
-
Save arnaud-lb/3106073 to your computer and use it in GitHub Desktop.
html2haml code style fixed
This file contains hidden or 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 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