def length_expand(name, value, unit, options=None):
    if options is None:
        options = {}

    if unit and 'percents'.startswith(unit):
        unit = '%'

    if isinstance(value, float):
        full_unit = options.get('CSS_default_unit_decimal', 'em')
    else:
        full_unit = options.get('CSS_default_unit', 'px')

    if '<number>' in [val for prop, val in get_flat_css() if prop == name] and not options.get('CSS_units_for_unitless_numbers'):
        full_unit = ''

    if value == 0:
        return '0'
    if value == '':
        return ''

    if unit:
        units = (val[1:] for key, val in get_flat_css() if key == name and val.startswith('.'))
        req_units = [u for u in units if sub_string(u, unit)]

        PRIORITY = ("em", "ex", "vw", "vh", "vmin", "vmax" "vm", "ch", "rem",
            "px", "cm", "mm", "in", "pt", "pc")
        full_unit = hayaku_extract(unit, req_units, PRIORITY)
        if not full_unit:
            return


    return '{0}{1}'.format(value, full_unit)
示例#2
0
def length_expand(name, value, unit, options=None):
    if options is None:
        options = {}

    if unit and "percents".startswith(unit):
        unit = "%"

    if isinstance(value, float):
        full_unit = options.get("CSS_default_unit_decimal", "em")
    else:
        full_unit = options.get("CSS_default_unit", "px")

    if "<number>" in [val for prop, val in get_flat_css() if prop == name] and not options.get(
        "CSS_units_for_unitless_numbers"
    ):
        full_unit = ""

    if value == 0:
        return "0"
    if value == "":
        return ""

    if unit:
        units = (val[1:] for key, val in get_flat_css() if key == name and val.startswith("."))
        req_units = [u for u in units if sub_string(u, unit)]

        PRIORITY = ("em", "ex", "vw", "vh", "vmin", "vmax" "vm", "ch", "rem", "px", "cm", "mm", "in", "pt", "pc")
        full_unit = hayaku_extract(unit, req_units, PRIORITY)
        if not full_unit:
            return

    return "{0}{1}".format(value, full_unit)
示例#3
0
def length_expand(name, value, unit, options=None):
    if options is None:
        options = {}

    if unit and 'percents'.startswith(unit):
        unit = '%'

    if isinstance(value, float):
        full_unit = options.get('CSS_default_unit_decimal', 'em')
    else:
        full_unit = options.get('CSS_default_unit', 'px')

    if '<number>' in [val for prop, val in get_flat_css() if prop == name
                      ] and not options.get('CSS_units_for_unitless_numbers'):
        full_unit = ''

    if value == 0:
        return '0'
    if value == '':
        return ''

    if unit:
        units = (val[1:] for key, val in get_flat_css()
                 if key == name and val.startswith('.'))
        req_units = [u for u in units if sub_string(u, unit)]

        PRIORITY = ("em", "ex", "vw", "vh", "vmin", "vmax"
                    "vm", "ch", "rem", "px", "cm", "mm", "in", "pt", "pc")
        full_unit = hayaku_extract(unit, req_units, PRIORITY)
        if not full_unit:
            return

    return '{0}{1}'.format(value, full_unit)
示例#4
0
def expand_value(args, options=None):
    if 'keyword-value' in args:
        return args['keyword-value']
    if args['property-name'] in set(p for p, v in get_flat_css() if v == '<color_values>'):
        if 'color' in args and not args['color']:
            return '#'
        return color_expand(args.get('color', ''),args.get('color_alpha', 1))
    elif args['property-name'] in set(p for p, v in get_flat_css() if v.startswith('.')) and 'keyword-value' not in args:
        ret = length_expand(args['property-name'], args.get('type-value', ''), args.get('type-name', ''), options)
        return ret
    elif 'type-value' in args:
        return str(args['type-value'])
    return args.get('keyword-value', '')
示例#5
0
def expand_value(args, options=None):
    if "keyword-value" in args:
        return args["keyword-value"]
    if args["property-name"] in set(p for p, v in get_flat_css() if v == "<color_values>"):
        if "color" in args and not args["color"]:
            return "#"
        return color_expand(args.get("color", ""), args.get("color_alpha", 1))
    elif (
        args["property-name"] in set(p for p, v in get_flat_css() if v.startswith(".")) and "keyword-value" not in args
    ):
        ret = length_expand(args["property-name"], args.get("type-value", ""), args.get("type-name", ""), options)
        return ret
    elif "type-value" in args:
        return str(args["type-value"])
    return args.get("keyword-value", "")
示例#6
0
def expand_value(args, options=None):
    if 'keyword-value' in args:
        return args['keyword-value']
    if args['property-name'] in set(p for p, v in get_flat_css()
                                    if v == '<color_values>'):
        if 'color' in args and not args['color']:
            return '#'
        return color_expand(args.get('color', ''), args.get('color_alpha', 1))
    elif args['property-name'] in set(
            p for p, v in get_flat_css()
            if v.startswith('.')) and 'keyword-value' not in args:
        ret = length_expand(args['property-name'], args.get('type-value', ''),
                            args.get('type-name', ''), options)
        return ret
    elif 'type-value' in args:
        return str(args['type-value'])
    return args.get('keyword-value', '')
示例#7
0
def make_template(args, options):
    whitespace        = options.get('CSS_whitespace_after_colon', '')
    disable_semicolon = options.get('CSS_syntax_no_semicolons', False)
    disable_colon     = options.get('CSS_syntax_no_colons', False)
    disable_prefixes  = options.get('CSS_prefixes_disable', False)
    clipboard = sublime.get_clipboard()

    if not whitespace and disable_colon:
        whitespace = ' '

    value = expand_value(args, options)
    if value is None:
        return

    if value.startswith('[') and value.endswith(']'):
        value = False

    semicolon = ';'
    colon = ':'

    if disable_semicolon:
        semicolon = ''
    if disable_colon:
        colon = ''

    snippet_parts = {
        'colon': colon,
        'semicolon': semicolon,
        'space': whitespace,
        'default': args.get('default-value',''),
        'important': args.get('important'),
        'before': [],
        'after': [],
        'autovalues': '',
    }

    # Handling prefixes
    property_ = (args['property-name'],)
    if not disable_prefixes:
        property_ = align_prefix(
            args['property-name'],
            args.get('prefixes', []),
            args.get('no-unprefixed-property', False) or options.get('CSS_prefixes_no_unprefixed', False),
            options.get('CSS_prefixes_align', True),
            options.get('CSS_prefixes_only', []),
            )

    # Replace the parens with a tabstop snippet
    # TODO: Move the inside snippets to the corresponding snippets dict
    if value and '()' in value:
        if value.replace('()', '') in ['rotate','rotateX','rotateY','rotateZ','skew','skewX','skewY']:
            value = value.replace('()', '($1${1/^((?!0$)-?(\d*.)?\d+)?.*$/(?1:deg)/m})')
        else:
            value = value.replace('()', '($1)')

    # Do things when there is no value expanded
    if not value or value == "#":
        if not options.get('CSS_disable_postexpand', False):
            auto_values = [val for prop, val in get_flat_css() if prop == args['property-name']]
            if auto_values:
                units = []
                values = []

                for p_value in (v for v in auto_values if len(v) > 1):
                    if p_value.startswith('.'):
                        units.append(p_value[1:])
                    elif not p_value.startswith('<'):
                        values.append(p_value)

                values_splitted = split_for_snippet(values)
                snippet_values = ''
                for index in range(0,len(values_splitted[0])):
                    snippet_values += ''.join([
                        '${1/^\s*',
                        values_splitted[0][index],
                        '.*/',
                        values_splitted[1][index],
                        '/m}',
                        ])
                snippet_parts['autovalues'] += snippet_values

                snippet_units = ''
                # TODO: find out when to use units or colors
                # TODO: Rewrite using after
                if units and value != "#":
                    units_splitted = split_for_snippet(units, 4)
                    snippet_parts['before'].append({
                        "match":  "%$",
                        "insert": "100"
                        })
                    snippet_units = ''.join([
                        '${1/^\s*((?!0$)(?=.)[\d\-]*(\.)?(\d+)?((?=.)',
                        units_splitted[0][0],
                        ')?$)?.*/(?4:',
                        units_splitted[1][0],
                        ':(?1:(?2:(?3::0)em:px)))/m}',
                        ])
                    snippet_parts['autovalues'] += snippet_units

                # Adding snippets for colors
                if value == "#":
                    value = ''
                    # Insert hash and doubling letters
                    snippet_parts['before'].append({
                        "match":  "([0-9a-fA-F]{1,6}|[0-9a-fA-F]{3,6}\s*(!\w*\s*)?)$",
                        "insert": "#"
                        })
                    snippet_parts['after'].append({
                        "match": "#?([0-9a-fA-F]{1,2})$",
                        "insert": "(?1:$1$1)"
                        })
                    # Insert `rgba` thingies
                    snippet_parts['before'].append({
                        "match":  "(\d{1,3}%?),(\.)?.*$",
                        "insert": "rgba\((?2:$1,$1,)"
                        })
                    snippet_parts['after'].append({
                        "match": "(\d{1,3}%?),(\.)?(.+)?$",
                        "insert": "(?2:(?3::5):(?3::$1,$1,1))\)"
                        })

                    # Getting the value from the clipboard
                    # TODO: Move to the whole clipboard2default function
                    check_clipboard_for_color = COMPLEX_COLOR_REGEX.match(clipboard)
                    if check_clipboard_for_color and 'colors' in options.get('CSS_clipboard_defaults'):
                        snippet_parts['default'] = check_clipboard_for_color.group(1)
                # TODO: move this out of `if not value`,
                #       so we could use it for found `url()` values
                if '<url>' in auto_values:
                    snippet_parts['before'].append({
                        "match":  "[^\s]+\.(jpg|jpeg|gif|png)$",
                        "insert": "url\("
                        })
                    snippet_parts['after'].append({
                        "match": "[^\s]+\.(jpg|jpeg|gif|png)$",
                        "insert": "\)"
                        })
                    check_clipboard_for_image = IMAGE_REGEX.match(clipboard)
                    if check_clipboard_for_image and 'images' in options.get('CSS_clipboard_defaults'):
                        snippet_parts['default'] = 'url(' + check_clipboard_for_image.group(1) + ')'


    snippet_parts['value'] = value or ''

    snippet = generate_snippet(snippet_parts)

    # Apply settings to the colors in the values
    def restyle_colors(match):
        color = match.group(1)
        # Change case of the colors in the value
        if options.get('CSS_colors_case').lower() in ('uppercase' 'upper'):
            color = color.upper()
        elif options.get('CSS_colors_case').lower() in ('lowercase' 'lower'):
            color = color.lower()
        # Make colors short or longhand
        if options.get('CSS_colors_length').lower() in ('short' 'shorthand') and len(color) == 6:
            if color[0] == color[1] and color[2] == color[3] and color[4] == color[5]:
                color = color[0] + color[2] + color[4]
        elif options.get('CSS_colors_length').lower() in ('long' 'longhand') and len(color) == 3:
            color = color[0] * 2 + color[1] * 2 + color[2] * 2
        return '#' + color
    snippet = COLOR_REGEX.sub(restyle_colors, snippet)

    newline_ending = ''
    if options.get('CSS_newline_after_expand'):
        newline_ending = '\n'
    return '\n'.join(snippet.format(prop) for prop in property_) + newline_ending
示例#8
0
def extract(s1):
    """В зависимости от найденных компонент в аббревиатуре применяет функцию extract"""
    # print repr(s1)
    prop_iter = []
    parts = segmentation(s1)
    abbr_value = False
    if 'property-name' in parts:
        if parts['important']:
            s1 = s1[:-1]
        if s1[-1] != ':' and s1 != parts['property-name']:
            abbr_value = True

    if 'color' in parts:
        prop_iter.extend(prop for prop, val in get_flat_css() if val == '<color_values>')

    if isinstance(parts.get('type-value'), int):
        prop_iter.extend(prop for prop, val in get_flat_css() if val == '<integer>')

    if isinstance(parts.get('type-value'), float):
        # TODO: добавить deg, grad, time
        prop_iter.extend(prop for prop, val in get_flat_css() if val in ('<length>', '<number>', 'percentage'))

    if 'keyword-value' in parts and not parts['keyword-value']:
        prop_iter.extend(get_all_properties())

    if 'keyword-value' in parts:
        prop_iter.extend(prop_value(parts['property-name'], parts['keyword-value']))
    elif 'color' not in parts or 'type-value' in parts:
        prop_iter.extend(get_all_properties())

    assert parts.get('property-name', '') or parts.get('property-value', '')
    abbr = ' '.join([
        parts.get('property-name', '') or parts.get('property-value', ''),
        parts.get('keyword-value', ''),
    ])

    # предустановленные правила
    abbr = abbr.strip()
    if abbr in STATIC_ABBR:
        property_ = STATIC_ABBR[abbr]
    else:
        starts_properties = []
        # todo: переделать механизм PAIRS
        # надо вынести константы в css-dict
        # по две буквы (bd, bg, ba)
        pair = PAIRS.get(abbr[:2], None)
        if pair is not None:
            starts_properties = [prop for prop in prop_iter if prop.startswith(pair) and sub_string(prop, abbr)]
        if not starts_properties:
            starts_properties = [prop for prop in prop_iter if prop[0] == abbr[0] and sub_string(prop, abbr)]

        if 'type-value' in parts:
            starts_properties = [i for i in starts_properties if ' ' not in i]

        property_ = hayaku_extract(abbr, starts_properties, PRIORITY_PROPERTIES, string_score)

    property_, value = property_.split(' ') if ' ' in property_ else (property_, None)
    # print property_, value
    if not property_:
        return {}

    parts['property-name'] = property_

    if value is not None:
        parts['keyword-value'] = value

    # Проверка соответствия свойства и значения

    allow_values = [val for prop, val in get_flat_css() if prop == parts['property-name']]

    if 'color' in parts and '<color_values>' not in allow_values:
        del parts['color']
    if 'type-value' in parts and not any((t in allow_values) for t in ['<integer>', 'percentage', '<length>', '<number>', '<alphavalue>']):
        del parts['type-value']
    if 'keyword-value' in parts and parts['keyword-value'] not in allow_values:
        del parts['keyword-value']

    if all([
            'keyword-value' not in parts,
            'type-value' not in parts,
            'color' not in parts,
        ]) and abbr_value:
        return {}

    # Добавить значение по-умолчанию
    if parts['property-name'] in get_css_dict():
        default_value = css_defaults(parts['property-name'], get_css_dict())
        if default_value is not None:
            parts['default-value'] = default_value
        obj = get_css_dict()[parts['property-name']]
        if 'prefixes' in obj:
            parts['prefixes'] = obj['prefixes']
            if 'no-unprefixed-property' in obj:
                parts['no-unprefixed-property'] = obj['no-unprefixed-property']

    if parts['abbr'] == parts.get('property-value'):
        del parts['property-value']

    return parts
示例#9
0
def make_template(args, options):
    whitespace = options.get("CSS_whitespace_after_colon", "")
    disable_semicolon = options.get("CSS_syntax_no_semicolons", False)
    disable_colon = options.get("CSS_syntax_no_colons", False)
    disable_prefixes = options.get("CSS_prefixes_disable", False)
    clipboard = sublime.get_clipboard()

    if not whitespace and disable_colon:
        whitespace = " "

    value = expand_value(args, options)
    if value is None:
        return

    if value.startswith("[") and value.endswith("]"):
        value = False

    semicolon = ";"
    colon = ":"

    if disable_semicolon:
        semicolon = ""
    if disable_colon:
        colon = ""

    snippet_parts = {
        "colon": colon,
        "semicolon": semicolon,
        "space": whitespace,
        "default": args.get("default-value", ""),
        "important": args.get("important"),
        "before": [],
        "after": [],
        "autovalues": "",
    }

    # Handling prefixes
    property_ = (args["property-name"],)
    if not disable_prefixes:
        property_ = align_prefix(
            args["property-name"],
            args.get("prefixes", []),
            args.get("no-unprefixed-property", False) or options.get("CSS_prefixes_no_unprefixed", False),
            options.get("CSS_prefixes_align", True),
            options.get("CSS_prefixes_only", []),
        )

    # Replace the parens with a tabstop snippet
    # TODO: Move the inside snippets to the corresponding snippets dict
    if value and "()" in value:
        if value.replace("()", "") in ["rotate", "rotateX", "rotateY", "rotateZ", "skew", "skewX", "skewY"]:
            value = value.replace("()", "($1${1/^((?!0$)-?(\d*.)?\d+)?.*$/(?1:deg)/m})")
        else:
            value = value.replace("()", "($1)")

    # Do things when there is no value expanded
    if not value or value == "#":
        if not options.get("CSS_disable_postexpand", False):
            auto_values = [val for prop, val in get_flat_css() if prop == args["property-name"]]
            if auto_values:
                units = []
                values = []

                for p_value in (v for v in auto_values if len(v) > 1):
                    if p_value.startswith("."):
                        units.append(p_value[1:])
                    elif not p_value.startswith("<"):
                        values.append(p_value)

                values_splitted = split_for_snippet(values)
                snippet_values = ""
                for index in range(0, len(values_splitted[0])):
                    snippet_values += "".join(
                        ["${1/^\s*", values_splitted[0][index], ".*/", values_splitted[1][index], "/m}"]
                    )
                snippet_parts["autovalues"] += snippet_values

                snippet_units = ""
                # TODO: find out when to use units or colors
                # TODO: Rewrite using after
                if units and value != "#":
                    units_splitted = split_for_snippet(units, 4)
                    snippet_parts["before"].append({"match": "%$", "insert": "100"})
                    # If there can be `number` in value, don't add `em` automatically
                    optional_unit_for_snippet = "(?2:(?3::0)em:px)"
                    if "<number>" in auto_values and not options.get("CSS_units_for_unitless_numbers"):
                        optional_unit_for_snippet = "(?2:(?3::0):)"
                    snippet_units = "".join(
                        [
                            "${1/^\s*((?!0$)(?=.)[\d\-]*(\.)?(\d+)?((?=.)",
                            units_splitted[0][0],
                            ")?$)?.*/(?4:",
                            units_splitted[1][0],
                            ":(?1:" + optional_unit_for_snippet + "))/m}",
                        ]
                    )
                    snippet_parts["autovalues"] += snippet_units

                # Adding snippets for colors
                if value == "#":
                    value = ""
                    # Insert hash and doubling letters
                    snippet_parts["before"].append(
                        {"match": "([0-9a-fA-F]{1,6}|[0-9a-fA-F]{3,6}\s*(!\w*\s*)?)$", "insert": "#"}
                    )
                    snippet_parts["after"].append({"match": "#?([0-9a-fA-F]{1,2})$", "insert": "(?1:$1$1)"})
                    # Insert `rgba` thingies
                    snippet_parts["before"].append({"match": "(\d{1,3}%?),(\.)?.*$", "insert": "rgba\((?2:$1,$1,)"})
                    snippet_parts["after"].append(
                        {"match": "(\d{1,3}%?),(\.)?(.+)?$", "insert": "(?2:(?3::5):(?3::$1,$1,1))\)"}
                    )

                    # Getting the value from the clipboard
                    # TODO: Move to the whole clipboard2default function
                    check_clipboard_for_color = COMPLEX_COLOR_REGEX.match(clipboard)
                    if check_clipboard_for_color and "colors" in options.get("CSS_clipboard_defaults"):
                        snippet_parts["default"] = check_clipboard_for_color.group(1)
                        if COLOR_WO_HASH_REGEX.match(snippet_parts["default"]):
                            snippet_parts["default"] = "#" + snippet_parts["default"]
                # TODO: move this out of `if not value`,
                #       so we could use it for found `url()` values
                if "<url>" in auto_values:
                    snippet_parts["before"].append({"match": "[^\s]+\.(jpg|jpeg|gif|png)$", "insert": "url\("})
                    snippet_parts["after"].append({"match": "[^\s]+\.(jpg|jpeg|gif|png)$", "insert": "\)"})
                    check_clipboard_for_image = IMAGE_REGEX.match(clipboard)
                    if check_clipboard_for_image and "images" in options.get("CSS_clipboard_defaults"):
                        quote_symbol = ""
                        if options.get("CSS_syntax_url_quotes"):
                            quote_symbol = options.get("CSS_syntax_quote_symbol")
                        snippet_parts["default"] = (
                            "url(" + quote_symbol + check_clipboard_for_image.group(1) + quote_symbol + ")"
                        )

    snippet_parts["value"] = value or ""

    snippet = generate_snippet(snippet_parts)

    # Apply settings to the colors in the values
    def restyle_colors(match):
        color = match.group(1)
        # Change case of the colors in the value
        if options.get("CSS_colors_case").lower() in ("uppercase" "upper"):
            color = color.upper()
        elif options.get("CSS_colors_case").lower() in ("lowercase" "lower"):
            color = color.lower()
        # Make colors short or longhand
        if options.get("CSS_colors_length").lower() in ("short" "shorthand") and len(color) == 6:
            if color[0] == color[1] and color[2] == color[3] and color[4] == color[5]:
                color = color[0] + color[2] + color[4]
        elif options.get("CSS_colors_length").lower() in ("long" "longhand") and len(color) == 3:
            color = color[0] * 2 + color[1] * 2 + color[2] * 2
        return "#" + color

    snippet = COLOR_REGEX.sub(restyle_colors, snippet)

    # Apply setting of the prefered quote symbol

    if options.get("CSS_syntax_quote_symbol") == "'" and '"' in snippet:
        snippet = snippet.replace('"', "'")
    if options.get("CSS_syntax_quote_symbol") == '"' and "'" in snippet:
        snippet = snippet.replace("'", '"')

    newline_ending = ""
    if options.get("CSS_newline_after_expand"):
        newline_ending = "\n"
    return "\n".join(snippet.format(prop) for prop in property_) + newline_ending
示例#10
0
def make_template(args, options):
    whitespace = options.get('CSS_whitespace_after_colon', '')
    disable_semicolon = options.get('CSS_syntax_no_semicolons', False)
    disable_colon = options.get('CSS_syntax_no_colons', False)
    disable_prefixes = options.get('CSS_prefixes_disable', False)
    clipboard = sublime.get_clipboard()

    if not whitespace and disable_colon:
        whitespace = ' '

    value = expand_value(args, options)
    if value is None:
        return

    if value.startswith('[') and value.endswith(']'):
        value = False

    semicolon = ';'
    colon = ':'

    if disable_semicolon:
        semicolon = ''
    if disable_colon:
        colon = ''

    snippet_parts = {
        'colon': colon,
        'semicolon': semicolon,
        'space': whitespace,
        'default': args.get('default-value', ''),
        'important': args.get('important'),
        'before': [],
        'after': [],
        'autovalues': '',
    }

    # Handling prefixes
    property_ = (args['property-name'], )
    if not disable_prefixes:
        property_ = align_prefix(
            args['property-name'],
            args.get('prefixes', []),
            args.get('no-unprefixed-property', False)
            or options.get('CSS_prefixes_no_unprefixed', False),
            options.get('CSS_prefixes_align', True),
            options.get('CSS_prefixes_only', []),
        )

    # Replace the parens with a tabstop snippet
    # TODO: Move the inside snippets to the corresponding snippets dict
    if value and '()' in value:
        if value.replace('()', '') in [
                'rotate', 'rotateX', 'rotateY', 'rotateZ', 'skew', 'skewX',
                'skewY'
        ]:
            value = value.replace(
                '()', '($1${1/^((?!0$)-?(\d*.)?\d+)?.*$/(?1:deg)/m})')
        else:
            value = value.replace('()', '($1)')

    # Do things when there is no value expanded
    if not value or value == "#":
        if not options.get('CSS_disable_postexpand', False):
            auto_values = [
                val for prop, val in get_flat_css()
                if prop == args['property-name']
            ]
            if auto_values:
                units = []
                values = []

                for p_value in (v for v in auto_values if len(v) > 1):
                    if p_value.startswith('.'):
                        units.append(p_value[1:])
                    elif not p_value.startswith('<'):
                        values.append(p_value)

                values_splitted = split_for_snippet(values)
                snippet_values = ''
                for index in range(0, len(values_splitted[0])):
                    snippet_values += ''.join([
                        '${1/^\s*',
                        values_splitted[0][index],
                        '.*/',
                        values_splitted[1][index],
                        '/m}',
                    ])
                snippet_parts['autovalues'] += snippet_values

                snippet_units = ''
                # TODO: find out when to use units or colors
                # TODO: Rewrite using after
                if units and value != "#":
                    units_splitted = split_for_snippet(units, 4)
                    snippet_parts['before'].append({
                        "match": "%$",
                        "insert": "100"
                    })
                    # If there can be `number` in value, don't add `em` automatically
                    optional_unit_for_snippet = '(?2:(?3::0)em:px)'
                    if '<number>' in auto_values and not options.get(
                            'CSS_units_for_unitless_numbers'):
                        optional_unit_for_snippet = '(?2:(?3::0):)'
                    snippet_units = ''.join([
                        '${1/^\s*((?!0$)(?=.)[\d\-]*(\.)?(\d+)?((?=.)',
                        units_splitted[0][0],
                        ')?$)?.*/(?4:',
                        units_splitted[1][0],
                        ':(?1:' + optional_unit_for_snippet + '))/m}',
                    ])
                    snippet_parts['autovalues'] += snippet_units

                # Adding snippets for colors
                if value == "#":
                    value = ''
                    # Insert hash and doubling letters
                    snippet_parts['before'].append({
                        "match":
                        "([0-9a-fA-F]{1,6}|[0-9a-fA-F]{3,6}\s*(!\w*\s*)?)$",
                        "insert": "#"
                    })
                    snippet_parts['after'].append({
                        "match": "#?([0-9a-fA-F]{1,2})$",
                        "insert": "(?1:$1$1)"
                    })
                    # Insert `rgba` thingies
                    snippet_parts['before'].append({
                        "match":
                        "(\d{1,3}%?),(\.)?.*$",
                        "insert":
                        "rgba\((?2:$1,$1,)"
                    })
                    snippet_parts['after'].append({
                        "match":
                        "(\d{1,3}%?),(\.)?(.+)?$",
                        "insert":
                        "(?2:(?3::5):(?3::$1,$1,1))\)"
                    })

                    # Getting the value from the clipboard
                    # TODO: Move to the whole clipboard2default function
                    check_clipboard_for_color = COMPLEX_COLOR_REGEX.match(
                        clipboard)
                    if check_clipboard_for_color and 'colors' in options.get(
                            'CSS_clipboard_defaults'):
                        snippet_parts[
                            'default'] = check_clipboard_for_color.group(1)
                # TODO: move this out of `if not value`,
                #       so we could use it for found `url()` values
                if '<url>' in auto_values:
                    snippet_parts['before'].append({
                        "match": "[^\s]+\.(jpg|jpeg|gif|png)$",
                        "insert": "url\("
                    })
                    snippet_parts['after'].append({
                        "match": "[^\s]+\.(jpg|jpeg|gif|png)$",
                        "insert": "\)"
                    })
                    check_clipboard_for_image = IMAGE_REGEX.match(clipboard)
                    if check_clipboard_for_image and 'images' in options.get(
                            'CSS_clipboard_defaults'):
                        quote_symbol = ''
                        if options.get('CSS_syntax_url_quotes'):
                            quote_symbol = options.get(
                                'CSS_syntax_quote_symbol')
                        snippet_parts[
                            'default'] = 'url(' + quote_symbol + check_clipboard_for_image.group(
                                1) + quote_symbol + ')'

    snippet_parts['value'] = value or ''

    snippet = generate_snippet(snippet_parts)

    # Apply settings to the colors in the values
    def restyle_colors(match):
        color = match.group(1)
        # Change case of the colors in the value
        if options.get('CSS_colors_case').lower() in ('uppercase' 'upper'):
            color = color.upper()
        elif options.get('CSS_colors_case').lower() in ('lowercase' 'lower'):
            color = color.lower()
        # Make colors short or longhand
        if options.get('CSS_colors_length').lower() in (
                'short'
                'shorthand') and len(color) == 6:
            if color[0] == color[1] and color[2] == color[3] and color[
                    4] == color[5]:
                color = color[0] + color[2] + color[4]
        elif options.get('CSS_colors_length').lower() in (
                'long'
                'longhand') and len(color) == 3:
            color = color[0] * 2 + color[1] * 2 + color[2] * 2
        return '#' + color

    snippet = COLOR_REGEX.sub(restyle_colors, snippet)

    # Apply setting of the prefered quote symbol

    if options.get('CSS_syntax_quote_symbol') == "'" and '"' in snippet:
        snippet = snippet.replace('"', "'")
    if options.get('CSS_syntax_quote_symbol') == '"' and "'" in snippet:
        snippet = snippet.replace("'", '"')

    newline_ending = ''
    if options.get('CSS_newline_after_expand'):
        newline_ending = '\n'
    return '\n'.join(snippet.format(prop)
                     for prop in property_) + newline_ending