-
Notifications
You must be signed in to change notification settings - Fork 11
/
backends.py
174 lines (130 loc) · 5.26 KB
/
backends.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import string
from utils import load_yaml
class LaTeX:
def __init__(self):
self.settings = load_yaml("LaTeX.yaml")
def lang_code(self, language):
return self.settings['languages'][language]
def preamble(self, typeface, language):
return """
\\documentclass[a4paper,12pt]{{scrartcl}}
\\usepackage{{setspace}}
\\usepackage{{fontspec}}
\\usepackage{{pfnote}}
\\usepackage{{polyglossia}}
\\setdefaultlanguage[variant=ancient]{{greek}}
\\setotherlanguage{{{language}}}
\\setromanfont{{{typeface}}}
\\newfontfamily\greekfont[Script=Greek]{{{typeface}}}
\\linespread{{1.5}}
\\onehalfspacing
\\makeatletter
\\renewcommand\\@makefntext[1]{{\\leftskip=2em\\hskip-2em\\@makefnmark#1}}
\\makeatother
\\begin{{document}}
""".format(typeface=typeface, language=self.lang_code(language))
def book_chapter_verse(self, book, chapter, verse):
return """
\\textbf{{\Large {}.{}.{}}}~""".format(book, chapter, verse)
def chapter_verse(self, chapter, verse):
return """
\\textbf{{\Large {}.{}}}~""".format(chapter, verse)
def verse(self, verse):
return "\\textbf{{{}}}~".format(verse)
def word(self, text, headword=None, parse=None, gloss=None, language=None):
if headword is None and parse is None and gloss is None:
return text + "\n"
else:
footnote = []
if headword:
footnote.append(headword)
if parse:
footnote.append("\\textendash\\ {}".format(parse))
if gloss:
footnote.append("\\textendash\\ \\text{}{{\\textit{{{}}}}}".format(self.lang_code(language), gloss))
return "{}\\footnote{{{}}}\n".format(text, " ".join(footnote))
def comment(self, text):
return "% {}".format(text)
def postamble(self):
return "\\end{document}"
class SILE:
def __init__(self):
self.settings = load_yaml("SILE.yaml")
def lang_code(self, language):
return self.settings['languages'][language]
def preamble(self, typeface, language):
return """\
\\begin[papersize=a4,class=book]{{document}}
\\font[family="{typeface}",size=12pt,language=el]
\\set[parameter=document.lineskip,value=6pt]
""".format(typeface=typeface)
def book_chapter_verse(self, book, chapter, verse):
return "\\font[size=16pt,weight=700]{{{}.{}.{}}} \\nobreak".format(
book, chapter, verse)
def chapter_verse(self, chapter, verse):
return "\\font[size=16pt,weight=700]{{{}.{}}} \\nobreak".format(chapter, verse)
def verse(self, verse):
return "\\font[weight=700]{{{}}} \\nobreak".format(verse)
def word(self, text, headword=None, parse=None, gloss=None, language=None):
if headword is None and parse is None and gloss is None:
return text + "\n"
else:
footnote = []
if headword:
footnote.append(headword)
if parse:
footnote.append("– {}".format(parse))
if gloss:
footnote.append("– \\font[style=italic,language={}]{{{}}}".format(self.lang_code(language), gloss))
return "{}\\footnote{{{}}} %\n".format(text, " ".join(footnote))
def comment(self, text):
return "% {}".format(text)
def postamble(self):
return "\\end{document}"
class MARKDOWN:
def __init__(self) -> None:
self.footnote_counter = 0
self.footnotes = []
self.footnote_to_counter_map = {}
def lang_code(self, language):
return language
def preamble(self, typeface, language):
return ""
def book_chapter_verse(self, book, chapter, verse):
return "**{}.{}.{}** ".format(book, chapter, verse)
def chapter_verse(self, chapter, verse):
return "**{}.{}** ".format(chapter, verse)
def verse(self, verse):
return "_{}_ ".format(verse)
def word(self, text, headword=None, parse=None, gloss=None, language=None):
if headword is None and parse is None and gloss is None:
return text + " "
else:
footnote_number = None
found = False
# get rid of all punctuation etc for text
stripped_text = text.translate(str.maketrans('', '', string.punctuation))
if stripped_text in self.footnote_to_counter_map:
found = True
footnote_number = self.footnote_to_counter_map[stripped_text]
else:
self.footnote_counter += 1
self.footnote_to_counter_map[stripped_text] = self.footnote_counter
footnote_number = self.footnote_counter
if not found:
footnote = []
footnote.append("[^{}]: ".format(self.footnote_counter))
if headword:
footnote.append(headword)
if parse:
footnote.append("– {}".format(parse))
if gloss:
footnote.append("– *{}*".format(gloss))
self.footnotes.append(" ".join(footnote))
return "{}[^{}] ".format(text, footnote_number)
def comment(self, text):
return ""
def postamble(self):
if self.footnotes:
footnotes = "\n\n".join(self.footnotes)
return "----\n{}".format(footnotes)