Hex color codes are minimised to 3-character if possible

6 character color codes are reduced to 3 character color codes if possible e.g:

FFFFFF => #FFFF

112233 => #123

This is caused by cssutils parser having this as default behaviour, however this is a common mail-client issue: screen shot 2015-10-15 at 09 03 14

cssutils parser function (cssutils/serialize.py):

 python
def _hash(self, val, type_=None):
        """
        Short form of hash, e.g. #123 instead of #112233
        """
        # TODO: add pref for this!
        if len(val) == 7 and val[1] == val[2] and\
                             val[3] == val[4] and\
                             val[5] == val[6]:
            return u'#%s%s%s' % (val[1], val[3], val[5])
        else:
            return val

该提问来源于开源项目:peterbe/premailer

查看全部
weixin_39876595
weixin_39876595
2020/11/23 05:19
  • 点赞
  • 收藏
  • 回答
    私信

5个回复