Пример #1
0
Файл: pur.py Проект: Cloudef/PUR
def markup(data):
    '''parse content markup'''
    def replace_urltable(expr, start, end, data):
        '''replace data from urltable'''
        parse = expr.group(1).split(':')
        if parse and parse[0] in MLURLTABLE:
            data = replace.replace_range(data, start, end, '<a href="{}">{}</a>'.format(MLURLTABLE[parse[0]], parse[1]))
        return data
    replace.html_escape(data)
    data = replace.iter_replace(r'\[([^\]]+)\]', data, replace_urltable)
    return comment_markup(data, False)
Пример #2
0
Файл: pur.py Проект: Cloudef/PUR
def comment_markup(data, escape=True):
    '''parse comment markup'''
    if escape:
        data = replace.html_escape(data)
    data = replace.iter_replace(r'\[([^\]]+)\]', data, replace_recipe)
    data = replace.iter_replace_compiled(replace.LINKREX, data, replace.replace_link)
    data = replace.iter_replace(r'```([^\n]+)\n([^`]+)\n```', data, replace_togglable_code, re.M)
    data = replace.iter_replace(r'```([^`]+)```', data, replace.replace_block, re.M)
    data = replace.iter_replace(r'~~([^~]+)~~', data, replace.replace_strike, re.M)
    data = replace.iter_replace(r'\b__([^_]+)__\b', data, replace.replace_strong, re.M)
    data = replace.iter_replace(r'\b_([^_]+)_\b', data, replace.replace_italic, re.M)
    return data