-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df761cd
commit ca3988c
Showing
2 changed files
with
291 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.