import re def mid_pas(data, fol_num, include, in_c, toc_y): syntax = 0 folding_test = 0 p = re.compile('{{{((?:(?:(?:\+|-)[0-5])|(?:#|@)(?:(?:[0-9a-f-A-F]{3}){1,2}|(?:\w+))|(?:#!(?:html|wiki|noin|folding|syntax)))(?:(?!{{{|}}}).)+)}}}', re.DOTALL) while 1: m = p.search(data) if m: data = p.sub('###' + m.groups()[0] + '/###', data, 1) else: break com = re.compile("{{{((?:(?!{{{|}}}).)*)}}}", re.DOTALL) while 1: m = com.search(data) if m: data = com.sub('' + m.groups()[0] + '', data, 1) else: break com3 = re.compile('###((?:(?!\/###).)+)\/###', re.DOTALL) m = com3.search(data) while 1: m = com3.search(data) if m: data = com3.sub('{{{' + m.groups()[0] + '}}}', data, 1) else: break com2 = re.compile("((?:(?!(?:|<\/code>)).)*)<\/code>", re.DOTALL) da_com = com2.findall(data) for com_da in da_com: mid_data = com_da.replace('<', '<').replace('>', '>') mid_data = re.sub("(?P.)", "#no#\g#/no#", mid_data) data = com2.sub(mid_data, data, 1) while 1: is_it = com.search(data) if is_it: it_d = is_it.groups()[0] big_a = re.compile("^\+([1-5]) (.*)$", re.DOTALL) big = big_a.search(it_d) small_a = re.compile("^\-([1-5]) (.*)$", re.DOTALL) small = small_a.search(it_d) color_b = re.compile("^(#(?:[0-9a-f-A-F]{3}){1,2}) (.*)$", re.DOTALL) color_2 = color_b.search(it_d) color_c = re.compile("^#(\w+) (.*)$", re.DOTALL) color_3 = color_c.search(it_d) back_a = re.compile("^@((?:[0-9a-f-A-F]{3}){1,2}) (.*)$", re.DOTALL) back = back_a.search(it_d) back_c = re.compile("^@(\w+) (.*)$", re.DOTALL) back_3 = back_c.search(it_d) include_out_a = re.compile("^#!noin ?(.*)$", re.DOTALL) include_out = include_out_a.search(it_d) div_a = re.compile("^#!wiki style=(?:"|')((?:(?!"|').)*)(?:"|')\r\n(.*)$", re.DOTALL) div = div_a.search(it_d) html_a = re.compile("^#!html ?(.*)$", re.DOTALL) html_d = html_a.search(it_d) fol_a = re.compile("^#!folding ((?:(?!\n).)*)\n(.*)$", re.DOTALL) fol = fol_a.search(it_d) syn_a = re.compile("^#!syntax ((?:(?!\n).)*)\n(.*)$", re.DOTALL) syn = syn_a.search(it_d) if big: big_d = big.groups() data = com.sub('' + big_d[1] + '', data, 1) elif small: sm_d = small.groups() data = com.sub('' + sm_d[1] + '', data, 1) elif color_2: c_d_2 = color_2.groups() data = com.sub('' + c_d_2[1] + '', data, 1) elif color_3: c_d_3 = color_3.groups() data = com.sub('' + c_d_3[1] + '', data, 1) elif back: back_d_1 = back.groups() data = com.sub('' + back_d_1[1] + '', data, 1) elif back_3: back_d_3 = back_3.groups() data = com.sub('' + back_d_3[1] + '', data, 1) elif div: div_d = div.groups() data = com.sub('
' + div_d[1] + '
', data, 1) elif html_d: data = com.sub(html_d.groups()[0], data, 1) elif fol: fol_d = fol.groups() if toc_y != 0: if folding_test == 0: data += '' data = com.sub("
" + fol_d[0] + "
" + \ "[펼치기]
" + \ "
", data, 1) fol_num += 3 else: data = com.sub("
" + fol_d[0] + "

" + fol_d[1] + "
", data, 1) elif syn: if syntax == 0: data += ' \ \ ' syntax = 1 syn_d = syn.groups() tax_d = syn_d[1].replace(' ', '') tax_d = tax_d.replace('\r\n', '') data = com.sub('
' + tax_d + '
', data, 1) elif include_out: if (include or in_c) == 1: data = com.sub("", data, 1) else: data = com.sub(include_out.groups()[0], data, 1) else: data = com.sub(it_d, data, 1) else: break com2 = re.compile("((?:(?!(?:|<\/code>)).)*)<\/code>", re.DOTALL) da_com = com2.findall(data) for com_da in da_com: mid_data = com_da.replace('<', '<').replace('>', '>') mid_data = re.sub("(?P.)", "#no#\g#/no#", mid_data) data = com2.sub(mid_data, data, 1) return [data, fol_num]