import se def render(text, info = None): finder = se.Finder() patterns = ["c(> \n>)v()c(\n )","#v(range 0,9)c(\s \r \n )","[v()]","https://v()c( \n \s)"] p_green, p_tlink, p_title, p_link = patterns form_green = '{text}' form_tlink = '{text}' form_smartlink = '''{text}''' form_title = '{text}' form_link = '{text}' ps = text.split("\n") for n, p in enumerate(ps): #green indexes = finder.get_indexes_tuples(p,p_green) matches = [p[i[0]:i[1]] for i in indexes] for match in matches: p = p.replace(match, form_green.format(text = match)) #replies indexes = finder.get_indexes_tuples(p,p_tlink) matches = [p[i[0]:i[1]] for i in indexes] for match in matches: link = f"/{info['board']}/{info['thread']}{match}" number = match while not number[0] in "0123456789": number = number[1:] while not number[-1] in "0123456789": number = number[:-1] p = p.replace(match, form_smartlink.format( text = match , id = number, thread_link = link, linkstart = "javascript:for (const post of document.getElementsByClassName('post')) {post.firstElementChild.style.backgroundColor='white';};"))#form_tlink.format(text = match, thread_link = link) #titles indexes = finder.get_indexes_tuples(p,p_title) matches = [p[i[0]:i[1]] for i in indexes] for match in matches: p = p.replace(match, form_title.format(text = match)) #outer links indexes = finder.get_indexes_tuples(p,p_link) matches = [p[i[0]:i[1]] for i in indexes] for match in matches: link = match if not match[-1] in [" ","\n"] else match[:-1] p = p.replace(match, form_link.format(text = match, link = link)) ps[n] = f"

{p}

" return "\n".join(ps) if __name__=="__main__": d = {"board": "ran", "thread": 1} print(render(">Sample Text\n>Amongus\n#11\n[SUS]\nhttps://www.litechan.org/ran/67", d))