reference-handler 0.9.1__py2.py3-none-any.whl → 0.9.3__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- reference_handler/__init__.py +2 -2
- reference_handler/_version.py +3 -3
- reference_handler/latex_utf8.py +45 -48
- reference_handler/reference_handler.py +323 -284
- reference_handler/tests/test_exceptions.py +9 -12
- reference_handler/tests/test_latex.py +135 -135
- reference_handler/tests/test_reference_handler.py +138 -111
- reference_handler/utils.py +9 -10
- reference_handler-0.9.3.dist-info/METADATA +180 -0
- reference_handler-0.9.3.dist-info/RECORD +16 -0
- {reference_handler-0.9.1.dist-info → reference_handler-0.9.3.dist-info}/WHEEL +1 -1
- reference_handler/tests/scratch/database.db +0 -0
- reference_handler/tests/scratch/outfile.bib +0 -0
- reference_handler/tests/scratch/tmp.db +0 -0
- reference_handler-0.9.1.dist-info/METADATA +0 -142
- reference_handler-0.9.1.dist-info/RECORD +0 -19
- {reference_handler-0.9.1.dist-info → reference_handler-0.9.3.dist-info/licenses}/LICENSE +0 -0
- {reference_handler-0.9.1.dist-info → reference_handler-0.9.3.dist-info}/top_level.txt +0 -0
reference_handler/__init__.py
CHANGED
|
@@ -12,6 +12,6 @@ from .latex_utf8 import encode_latex # noqa: F401
|
|
|
12
12
|
from ._version import get_versions
|
|
13
13
|
|
|
14
14
|
versions = get_versions()
|
|
15
|
-
__version__ = versions[
|
|
16
|
-
__git_revision__ = versions[
|
|
15
|
+
__version__ = versions["version"]
|
|
16
|
+
__git_revision__ = versions["full-revisionid"]
|
|
17
17
|
del get_versions, versions
|
reference_handler/_version.py
CHANGED
|
@@ -8,11 +8,11 @@ import json
|
|
|
8
8
|
|
|
9
9
|
version_json = '''
|
|
10
10
|
{
|
|
11
|
-
"date": "
|
|
11
|
+
"date": "2026-10-17T13:57:51-0400",
|
|
12
12
|
"dirty": false,
|
|
13
13
|
"error": null,
|
|
14
|
-
"full-revisionid": "
|
|
15
|
-
"version": "0.9.
|
|
14
|
+
"full-revisionid": "96f322852777846d0aefaa5f66e71ba58794b5ee",
|
|
15
|
+
"version": "0.9.3"
|
|
16
16
|
}
|
|
17
17
|
''' # END VERSION_JSON
|
|
18
18
|
|
reference_handler/latex_utf8.py
CHANGED
|
@@ -70,54 +70,53 @@ import re
|
|
|
70
70
|
import typing
|
|
71
71
|
import unicodedata
|
|
72
72
|
|
|
73
|
-
alphabet =
|
|
73
|
+
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
74
74
|
|
|
75
75
|
# LaTeX characters in accent macros of form \<char>{<letter>}, i.e. \"{u}
|
|
76
76
|
accent = {
|
|
77
|
-
'"':
|
|
78
|
-
"'":
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
'"': "\N{COMBINING DIAERESIS}",
|
|
78
|
+
"'": "\N{COMBINING ACUTE ACCENT}",
|
|
79
|
+
".": "\N{COMBINING DOT ABOVE}",
|
|
80
|
+
"=": "\N{COMBINING MACRON}",
|
|
81
|
+
"^": "\N{COMBINING CIRCUMFLEX ACCENT}",
|
|
82
|
+
"`": "\N{COMBINING GRAVE ACCENT}",
|
|
83
|
+
"|": "\N{COMBINING VERTICAL LINE ABOVE}",
|
|
84
|
+
"~": "\N{COMBINING TILDE}",
|
|
85
|
+
"b": "\N{COMBINING MACRON BELOW}",
|
|
86
|
+
"c": "\N{COMBINING CEDILLA}",
|
|
87
|
+
"C": "\N{COMBINING DOUBLE GRAVE ACCENT}",
|
|
88
|
+
"d": "\N{COMBINING DOT BELOW}",
|
|
89
|
+
"f": "\N{COMBINING INVERTED BREVE}",
|
|
90
|
+
"h": "\N{COMBINING HOOK ABOVE}",
|
|
91
|
+
"H": "\N{COMBINING DOUBLE ACUTE ACCENT}",
|
|
92
|
+
"k": "\N{COMBINING OGONEK}",
|
|
93
|
+
"r": "\N{COMBINING RING ABOVE}",
|
|
94
|
+
"t": "\N{COMBINING DOUBLE INVERTED BREVE}",
|
|
95
|
+
"u": "\N{COMBINING BREVE}",
|
|
96
|
+
"U": "\N{COMBINING DOUBLE VERTICAL LINE ABOVE}",
|
|
97
|
+
"v": "\N{COMBINING CARON}",
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
# The regexp to detect the LaTeX accent commands. The two added characters
|
|
101
101
|
# are the dotless i and j.
|
|
102
|
-
accent_re = re.compile(
|
|
103
|
-
r'\\([' + ''.join(accent.keys()) + r']){([a-zA-Z\u0131\u0237])}'
|
|
104
|
-
)
|
|
102
|
+
accent_re = re.compile(r"\\([" + "".join(accent.keys()) + r"]){([a-zA-Z\u0131\u0237])}")
|
|
105
103
|
|
|
106
104
|
# Invert the accent dictionary for each letter in the alphabet to make
|
|
107
105
|
# a dictionary of LaTeX encodings.
|
|
108
106
|
encoding = {}
|
|
109
107
|
for key, val in accent.items():
|
|
110
108
|
for char in list(alphabet):
|
|
111
|
-
encoding[char + val] =
|
|
109
|
+
encoding[char + val] = "\\" + key + "{" + char + "}"
|
|
112
110
|
# handle any precombined versions of the character
|
|
113
|
-
string = unicodedata.normalize(
|
|
111
|
+
string = unicodedata.normalize("NFC", char + val)
|
|
114
112
|
if len(string) == 1:
|
|
115
113
|
encoding[string] = encoding[char + val]
|
|
116
114
|
for char in [
|
|
117
|
-
|
|
115
|
+
"\N{LATIN SMALL LETTER DOTLESS I}",
|
|
116
|
+
"\N{LATIN SMALL LETTER DOTLESS J}",
|
|
118
117
|
]:
|
|
119
|
-
encoding[char + val] = r
|
|
120
|
-
string = unicodedata.normalize(
|
|
118
|
+
encoding[char + val] = r"\%s{%s}" % (key, char)
|
|
119
|
+
string = unicodedata.normalize("NFC", char + val)
|
|
121
120
|
# These characters have no precombined versions, but check anyway
|
|
122
121
|
if len(string) == 1:
|
|
123
122
|
encoding[string] = encoding[char + val]
|
|
@@ -137,20 +136,20 @@ def _decode_latex_accent(match: typing.Match) -> str:
|
|
|
137
136
|
|
|
138
137
|
# LaTeX single character symbols
|
|
139
138
|
symbol = {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
139
|
+
"i": "\N{LATIN SMALL LETTER DOTLESS I}",
|
|
140
|
+
"j": "\N{LATIN SMALL LETTER DOTLESS J}",
|
|
141
|
+
"l": "\N{LATIN SMALL LETTER L WITH STROKE}",
|
|
142
|
+
"L": "\N{LATIN CAPITAL LETTER L WITH STROKE}",
|
|
143
|
+
"o": "\N{LATIN SMALL LETTER O WITH STROKE}",
|
|
144
|
+
"O": "\N{LATIN CAPITAL LETTER O WITH STROKE}",
|
|
146
145
|
}
|
|
147
146
|
|
|
148
147
|
# The regexp to detect the LaTeX commands for special characters
|
|
149
|
-
symbol_re = re.compile(r
|
|
148
|
+
symbol_re = re.compile(r"\\([" + "".join(symbol.keys()) + "])")
|
|
150
149
|
|
|
151
150
|
# Invert the symbol dictionary to make a dictionary of LaTeX encodings.
|
|
152
151
|
for key, val in symbol.items():
|
|
153
|
-
encoding[val] =
|
|
152
|
+
encoding[val] = "\\" + key
|
|
154
153
|
|
|
155
154
|
|
|
156
155
|
def _decode_latex_symbol(match: typing.Match) -> str:
|
|
@@ -166,10 +165,10 @@ def _decode_latex_symbol(match: typing.Match) -> str:
|
|
|
166
165
|
|
|
167
166
|
|
|
168
167
|
# LaTeX dashes
|
|
169
|
-
dash = {
|
|
168
|
+
dash = {"--": "\N{EN DASH}", "---": "\N{EM DASH}"}
|
|
170
169
|
|
|
171
170
|
# The regexp to detect the LaTeX commands for dashes
|
|
172
|
-
dash_re = re.compile(r
|
|
171
|
+
dash_re = re.compile(r"([^-]?)(-{2,3})([^-]?)")
|
|
173
172
|
|
|
174
173
|
# Invert the dictionary tomake a dictionary of LaTeX encodings.
|
|
175
174
|
for key, val in dash.items():
|
|
@@ -205,13 +204,11 @@ def decode_latex(text: str) -> str:
|
|
|
205
204
|
"""
|
|
206
205
|
|
|
207
206
|
return brace_re.sub(
|
|
208
|
-
r
|
|
207
|
+
r"\1",
|
|
209
208
|
accent_re.sub(
|
|
210
209
|
_decode_latex_accent,
|
|
211
|
-
symbol_re.sub(
|
|
212
|
-
|
|
213
|
-
)
|
|
214
|
-
)
|
|
210
|
+
symbol_re.sub(_decode_latex_symbol, dash_re.sub(_decode_latex_dash, text)),
|
|
211
|
+
),
|
|
215
212
|
)
|
|
216
213
|
|
|
217
214
|
|
|
@@ -228,7 +225,7 @@ def encode_latex(text: str) -> str:
|
|
|
228
225
|
"""
|
|
229
226
|
|
|
230
227
|
# Map the double character representations
|
|
231
|
-
text2 =
|
|
228
|
+
text2 = ""
|
|
232
229
|
char1 = text[0]
|
|
233
230
|
i = 1
|
|
234
231
|
len_text = len(text)
|
|
@@ -250,7 +247,7 @@ def encode_latex(text: str) -> str:
|
|
|
250
247
|
text2 += char1
|
|
251
248
|
|
|
252
249
|
# Map the single characters representations
|
|
253
|
-
result =
|
|
250
|
+
result = ""
|
|
254
251
|
for char in list(text2):
|
|
255
252
|
if char in encoding:
|
|
256
253
|
result += encoding[char]
|
|
@@ -260,7 +257,7 @@ def encode_latex(text: str) -> str:
|
|
|
260
257
|
return result
|
|
261
258
|
|
|
262
259
|
|
|
263
|
-
if __name__ ==
|
|
260
|
+
if __name__ == "__main__": # pragma: no cover
|
|
264
261
|
text = r"""
|
|
265
262
|
(Vorlova_2015) Barbora Vorlov{\'{a}} and Dana Nachtigallov{\'{a}} and Jana
|
|
266
263
|
Jir{\'{a}}skov{\'{a}}-Van{\'{\i}}{\v{c}}kov{\'{a}} and Haresh Ajani and Petr
|