ccampbell / html-muncher

renames classes and ids in your css, javascript, and html to save bytes and obfuscate your code
http://htmlmuncher.com
177 stars 40 forks source link

CSS classes with dash are not renamed #6

Open calummoore opened 10 years ago

calummoore commented 10 years ago

The following will not be re-named because there is a dash between 'btn' and 'default'

 /* Not renamed */
.btn-default {
   ...
}

/* Renamed */
.btndefault {
  ...
}
calummoore commented 10 years ago

You can fix this issue by modifying line 272-273 to:

    ids_found = re.findall(r'((?<!\:\s)(?<!\:)#[\w-]+)(\.|\{|,|\s|#)', contents, re.DOTALL)
    classes_found = re.findall(r'(?!\.[0-9])\.[\w-]+', contents)

All I've done is add [\w-] instead of \w - allowing for the dash in class or id name.

softmonkeyjapan commented 9 years ago

Not sure it's related to Python 2.7 or my Mac OSX Yosemite but this snippet does not works. I've got the following error :

searching for classes and ids...
mapping classes and ids to new names...
Traceback (most recent call last):
  File "/usr/local/bin/munch", line 5, in <module>
    pkg_resources.run_script('htmlmuncher==1.0', 'munch')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 492, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 1357, in run_script
    exec_(script_code, namespace, namespace)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 47, in exec_
    exec("""exec code in globs, locs""")
  File "<string>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/htmlmuncher-1.0-py2.7.egg/EGG-INFO/scripts/munch", line 24, in <module>

  File "build/bdist.macosx-10.10-intel/egg/muncher/muncher.py", line 104, in run
  File "build/bdist.macosx-10.10-intel/egg/muncher/muncher.py", line 395, in processMaps
  File "build/bdist.macosx-10.10-intel/egg/muncher/varfactory.py", line 35, in getNext
  File "build/bdist.macosx-10.10-intel/egg/muncher/varfactory.py", line 75, in getSmallName
Exception: until my math skillz get better we can only support 702 possibilities!
jgthms commented 6 years ago

@calummoore Thanks so much!

For those using that trick, you can't run the binary package anymore (unless you know how to create an .egg file and replace the one in /Library/Python/2.7/site-packages/htmlmuncher-1.0-py2.7.egg).

So you can't do:

munch --css path/to/main.css --html path/to/index.html

But you have to run your own local munch version:

python munch --css path/to/main.css --html path/to/index.html
proxypunker commented 3 years ago

Not sure it's related to Python 2.7 or my Mac OSX Yosemite but this snippet does not works. I've got the following error :

File "build/bdist.macosx-10.10-intel/egg/muncher/varfactory.py", line 75, in getSmallName Exception: until my math skillz get better we can only support 702 possibilities!


Happened to me as well after fixing the missing dash-support with the lines above in my muncher.py file.
This is due to limitations of the html-muncher script. 26*27 (or vice versa) combinations are possible. Everything above will lead to funny unicode characters instead of letters. This is - indeed - is a pitty. As I understand, the current structure for renaming classes and ids is a to zz. But this won't be a challenge for a mediocre Python Summoner, will it?