-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpandoc-xepersian.py
executable file
·45 lines (35 loc) · 1.17 KB
/
pandoc-xepersian.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
"""
Pandoc filter to convert English text to xepersian compatible format
"""
from pandocfilters import toJSONFilter, Str, RawInline
import locale
import logging
import os
log = logging.getLogger(os.path.basename(__file__))
ignored_words = ['a4paper']
def configure_logging():
format_string = "%(name)s: [%(levelname)s] %(message)s"
logging.basicConfig(format=format_string, level=logging.DEBUG)
#log.debug("Debug logging enabled.")
def IsNumber(x):
import re
if re.match("^\d*.?\d*$", x) == None:
return False
return True
def behead(key, value, format, meta):
if format == 'latex':
if key == 'Str':
try:
# if there is no exception this is english text
value.encode('ascii')
# Just change non numeric values
if not IsNumber(value):
if value not in ignored_words:
return RawInline('latex', '\\lr{'+value+'}')
except UnicodeEncodeError:
#log.info( "string is UTF-8")
pass
if __name__ == "__main__":
configure_logging()
toJSONFilter(behead)