# Blog-HTML -> DokuWiki-Text (Absaetze, Zitate, Kursiv)
import re, html as H
def blog2wiki(h):
h = re.sub(r'(.*?)', r'//\1//', h, flags=re.S)
parts = re.findall(r'<(div|blockquote)[^>]*>(.*?)\1>', h, flags=re.S)
out = []
for tag, inner in parts:
inner = re.sub(r'
', '\n', inner)
t = H.unescape(re.sub(r'<[^>]+>', '', inner)).replace('\xa0', ' ')
lines = [re.sub(r'[ \t]+', ' ', l).strip() for l in t.split('\n')]
lines = [l for l in lines if l]
if not lines:
continue
if tag == 'blockquote':
out.append('\n'.join('> ' + l for l in lines))
else:
out += lines
return '\n\n'.join(out)