Skip to content

Commit

Permalink
Hyphenate paragraphs only.
Browse files Browse the repository at this point in the history
  • Loading branch information
czerwonamaupa committed Dec 20, 2018
1 parent df761cd commit ca3988c
Show file tree
Hide file tree
Showing 2 changed files with 291 additions and 287 deletions.
10 changes: 7 additions & 3 deletions filters/hyphenate.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import re
from pandocfilters import Str, toJSONFilter
from pandocfilters import Para, Str, toJSONFilter, walk
from pyphen import Pyphen

dic = Pyphen(lang='en_GB', left=3, right=3)
dic = Pyphen(lang='en_US', left=3, right=3)

word_detection_pattern = re.compile(r'\w{7,}', re.UNICODE)

def inpara(key, value, format, meta):
if key == 'Para':
return Para(walk(value, hyphenate, format, meta))

def hyphenate(key, value, format, meta):
if key == 'Str':
return Str(word_detection_pattern.sub(
lambda match: dic.inserted(match.group(0), hyphen='­'),
value))

if __name__ == "__main__":
toJSONFilter(hyphenate)
toJSONFilter(inpara)
Loading

0 comments on commit ca3988c

Please sign in to comment.