File size: 358 Bytes
2be028b
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
import re

def format_paragraph(text):
    
    text = text.replace("**", "</b>").replace("**", "<b>")
    
    
    pattern = re.compile(r'</b>')
    
    text = re.sub(pattern, lambda m: "<b>" if pattern.subn('', text[:m.start()])[1] % 2 == 0 else m.group(0), text)
    text = text.replace('\n','<br>')
    text = text.replace('*','&#8226')
    return text