View Single Post
Old 10-09-2007, 10:24 PM   #16
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,429
Karma: 27757236
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Since I'm on a roll here's one for HTML it might need a little adjustment

Code:
import re
from hyphenate import hyphenate_word as hyphenate

def process_text(match):
    src = match.group(1)
    return re.sub('\S+', lambda match : u'\u00ad'.join(hyphenate(match.group())), src)

src = open('file', 'rb').read()
result = re.sub(r'>([^><]+)<', process_text, src)
kovidgoyal is offline   Reply With Quote