import re


def wrap_slice(rule_slice, status):
    """Wrap the changed rules text in tags for JSON to parse.

    This allows us to highlight changes programmatically. Javascript can
    replace the old_start, new_start, etc tags with their proper <span>
    tags in the generated HTML. Easier to handle there than here.

    Note this does NOT differentiate between inserts, replaces, deletions
    like a general diff tool.

    Keyword arguments:
    rule_slice -- the chunk of the rule that indicates a change
    status -- whether the slice belongs to an 'old' rule or a 'new' rule.
    """
    if not rule_slice:
        return ''
    if re.match('^^(?:rules? )?'
                '\d{3}(?:\.\d+[a-z]*)*'
                '(?:–\d{3}(?:\.\d+[a-z]?)?)?\)?\.?',
                ' '.join(rule_slice)):
        return rule_slice

    if status == 'old':
        return ['old_start', *rule_slice, 'old_end']
    else:
        return ['new_start', *rule_slice, 'new_end']