Source for: hyphen.py [raw]

 1import pyphen
 2
 3dic = pyphen.Pyphen(lang="en_US")
 4
 5
 6def insert_soft_hyphens(text, hyphen="\xad"):
 7    """Insert the hyphen in breaking pointsaccording to the dictionary.
 8    
 9    '\xad' is the Soft Hyphen (SHY) character
10    """
11    lines = []
12    for line in text.splitlines():
13        hyph_words = [
14            dic.inserted(word, hyphen) for word in line.split()
15        ]
16        lines.append(" ".join(hyph_words))
17    return "\n".join(lines)
18