mathfence 0.1.3__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.
- mathfence/__init__.py +22 -0
- mathfence/cli.py +217 -0
- mathfence/core.py +150 -0
- mathfence/delimiters.py +168 -0
- mathfence/dollars.py +242 -0
- mathfence/i18n.py +188 -0
- mathfence/py.typed +0 -0
- mathfence/regions.py +264 -0
- mathfence/rules.py +123 -0
- mathfence/stream.py +76 -0
- mathfence-0.1.3.dist-info/METADATA +289 -0
- mathfence-0.1.3.dist-info/RECORD +15 -0
- mathfence-0.1.3.dist-info/WHEEL +4 -0
- mathfence-0.1.3.dist-info/entry_points.txt +2 -0
- mathfence-0.1.3.dist-info/licenses/LICENSE +21 -0
mathfence/dollars.py
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"""Decide, for every ``$`` outside protected regions, whether it is math or text.
|
|
2
|
+
|
|
3
|
+
A single ``$`` is paired with the next ``$`` of the same paragraph; the text
|
|
4
|
+
between them must look like a formula (see :mod:`mathfence.rules`). Anything
|
|
5
|
+
that is not math is escaped as ``\\$`` so no renderer can mistake it for math.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import re
|
|
11
|
+
|
|
12
|
+
from . import rules
|
|
13
|
+
from .regions import PARA, Region, RegionIndex
|
|
14
|
+
from .rules import Raw
|
|
15
|
+
|
|
16
|
+
_JUMP = re.compile(r"[\\$]")
|
|
17
|
+
_PREFIX = re.compile(r"^((?:[ \t]*>)*)([ \t]*)((?:(?:[-*+]|\d{1,9}[.)])[ \t]+)*)")
|
|
18
|
+
_ONLY_PREFIX = re.compile(r"[ \t>\r]*")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _currency_kind(text: str, after: int) -> str:
|
|
22
|
+
return "currency" if text[after : after + 1].isdigit() else "stray"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _Pass:
|
|
26
|
+
def __init__(
|
|
27
|
+
self,
|
|
28
|
+
text: str,
|
|
29
|
+
regions: tuple[Region, ...],
|
|
30
|
+
profile: str,
|
|
31
|
+
streaming: bool,
|
|
32
|
+
display_hints: set[int],
|
|
33
|
+
) -> None:
|
|
34
|
+
self.text = text
|
|
35
|
+
self.n = len(text)
|
|
36
|
+
self.idx = RegionIndex(regions)
|
|
37
|
+
self.profile = profile
|
|
38
|
+
self.streaming = streaming
|
|
39
|
+
self.display_hints = display_hints
|
|
40
|
+
self.out: list[str] = []
|
|
41
|
+
self.raws: list[Raw] = []
|
|
42
|
+
self._pe_from = 0
|
|
43
|
+
self._pe = -1
|
|
44
|
+
|
|
45
|
+
# -- helpers ---------------------------------------------------------
|
|
46
|
+
def para_end(self, i: int) -> int:
|
|
47
|
+
"""Offset where the paragraph containing ``i`` ends."""
|
|
48
|
+
if not (self._pe_from <= i <= self._pe):
|
|
49
|
+
m = PARA.search(self.text, i)
|
|
50
|
+
self._pe_from = i
|
|
51
|
+
self._pe = m.start() if m else self.n
|
|
52
|
+
return self._pe
|
|
53
|
+
|
|
54
|
+
def next_dollar(self, j: int, limit: int) -> int:
|
|
55
|
+
"""Next unescaped ``$`` in ``[j, limit)`` that is outside every region, or -1."""
|
|
56
|
+
text = self.text
|
|
57
|
+
while True:
|
|
58
|
+
m = _JUMP.search(text, j, limit)
|
|
59
|
+
if not m:
|
|
60
|
+
return -1
|
|
61
|
+
p = m.start()
|
|
62
|
+
r = self.idx.at(p)
|
|
63
|
+
if r:
|
|
64
|
+
j = r.end
|
|
65
|
+
continue
|
|
66
|
+
if text[p] == "\\":
|
|
67
|
+
j = p + 2
|
|
68
|
+
continue
|
|
69
|
+
return p
|
|
70
|
+
|
|
71
|
+
def run_at(self, p: int) -> int:
|
|
72
|
+
run = 1
|
|
73
|
+
while p + run < self.n and self.text[p + run] == "$":
|
|
74
|
+
run += 1
|
|
75
|
+
return run
|
|
76
|
+
|
|
77
|
+
def escape(self, p: int, run: int, rule: str) -> int:
|
|
78
|
+
self.out.append("\\$" * run)
|
|
79
|
+
self.raws.append(Raw(p, "$" * run, "escape", _currency_kind(self.text, p + run), rule))
|
|
80
|
+
return p + run
|
|
81
|
+
|
|
82
|
+
# -- main loop -------------------------------------------------------
|
|
83
|
+
def run(self) -> tuple[str, list[Raw]]:
|
|
84
|
+
text, i = self.text, 0
|
|
85
|
+
while True:
|
|
86
|
+
m = _JUMP.search(text, i)
|
|
87
|
+
if not m:
|
|
88
|
+
self.out.append(text[i:])
|
|
89
|
+
break
|
|
90
|
+
p = m.start()
|
|
91
|
+
r = self.idx.at(p)
|
|
92
|
+
if r:
|
|
93
|
+
self.out.append(text[i : r.end])
|
|
94
|
+
if r.rule == rules.STREAM_PENDING:
|
|
95
|
+
self.hold_pending(r, i)
|
|
96
|
+
i = r.end
|
|
97
|
+
continue
|
|
98
|
+
self.out.append(text[i:p])
|
|
99
|
+
if text[p] == "\\":
|
|
100
|
+
self.out.append(text[p : p + 2])
|
|
101
|
+
i = p + 2
|
|
102
|
+
continue
|
|
103
|
+
run = self.run_at(p)
|
|
104
|
+
if run >= 3:
|
|
105
|
+
i = self.escape(p, run, rules.DOLLAR_RUN)
|
|
106
|
+
elif run == 2:
|
|
107
|
+
i = self.double(p)
|
|
108
|
+
else:
|
|
109
|
+
i = self.single(p)
|
|
110
|
+
return "".join(self.out), self.raws
|
|
111
|
+
|
|
112
|
+
def hold_pending(self, r: Region, copied_from: int) -> None:
|
|
113
|
+
"""An unclosed code span at the end of a stream: show its ``$`` as text for now.
|
|
114
|
+
|
|
115
|
+
The region was just copied; replace that copy with an escaped one so the
|
|
116
|
+
renderer cannot pair these dollars into math that the finished answer
|
|
117
|
+
(where the span is code) will not have.
|
|
118
|
+
"""
|
|
119
|
+
text = self.text
|
|
120
|
+
piece = text[max(copied_from, r.start) : r.end]
|
|
121
|
+
head = text[copied_from : r.start] if copied_from < r.start else ""
|
|
122
|
+
del self.out[-1]
|
|
123
|
+
escaped = re.sub(r"(?<!\\)\$", lambda m: "\\$", piece)
|
|
124
|
+
self.out.append(head + escaped)
|
|
125
|
+
if escaped != piece:
|
|
126
|
+
self.raws.append(Raw(r.start, text[r.start : r.end], "escape", "stray", rules.STREAM_PENDING))
|
|
127
|
+
|
|
128
|
+
# -- single dollar ---------------------------------------------------
|
|
129
|
+
def single(self, p: int) -> int:
|
|
130
|
+
text = self.text
|
|
131
|
+
j = self.next_dollar(p + 1, self.para_end(p))
|
|
132
|
+
if j == -1:
|
|
133
|
+
return self.escape(p, 1, rules.NO_CLOSING)
|
|
134
|
+
if self.streaming and j + 1 == self.n:
|
|
135
|
+
return self.escape(p, 1, rules.STREAM_PENDING)
|
|
136
|
+
if self.run_at(j) >= 2:
|
|
137
|
+
return self.escape(p, 1, rules.CLOSE_FOLLOWED_BY_DOLLAR)
|
|
138
|
+
fail = rules.judge_single(text[p + 1 : j], text[j + 1 : j + 2])
|
|
139
|
+
if fail:
|
|
140
|
+
return self.escape(p, 1, fail)
|
|
141
|
+
self.out.append(text[p : j + 1])
|
|
142
|
+
self.raws.append(Raw(p, text[p : j + 1], "keep_math", "inline", rules.MATH_PAIR))
|
|
143
|
+
return j + 1
|
|
144
|
+
|
|
145
|
+
# -- double dollar ---------------------------------------------------
|
|
146
|
+
def double(self, p: int) -> int:
|
|
147
|
+
text = self.text
|
|
148
|
+
limit = self.para_end(p)
|
|
149
|
+
j = p + 2
|
|
150
|
+
close = -1
|
|
151
|
+
while True:
|
|
152
|
+
j = self.next_dollar(j, limit)
|
|
153
|
+
if j == -1:
|
|
154
|
+
break
|
|
155
|
+
rj = self.run_at(j)
|
|
156
|
+
if rj == 1:
|
|
157
|
+
j += 1
|
|
158
|
+
continue
|
|
159
|
+
if rj == 2:
|
|
160
|
+
close = j
|
|
161
|
+
break
|
|
162
|
+
if close == -1:
|
|
163
|
+
return self.escape(p, 2, rules.NO_CLOSING)
|
|
164
|
+
if self.streaming and close + 2 == self.n:
|
|
165
|
+
return self.escape(p, 2, rules.STREAM_PENDING)
|
|
166
|
+
fail = rules.judge_double(text[p + 2 : close])
|
|
167
|
+
if fail:
|
|
168
|
+
return self.escape(p, 2, fail)
|
|
169
|
+
self.raws.append(Raw(p, text[p : close + 2], "keep_math", "display", rules.MATH_PAIR))
|
|
170
|
+
if self.profile == "streamlit" or p in self.display_hints:
|
|
171
|
+
laid_out = self.layout(p, close, own_line_only=self.profile != "streamlit")
|
|
172
|
+
if laid_out is not None:
|
|
173
|
+
return laid_out
|
|
174
|
+
self.out.append(text[p : close + 2])
|
|
175
|
+
return close + 2
|
|
176
|
+
|
|
177
|
+
def layout(self, p: int, close: int, own_line_only: bool = False) -> int | None:
|
|
178
|
+
"""Put a display pair on its own lines, keeping ``>`` and list prefixes.
|
|
179
|
+
|
|
180
|
+
Returns the offset to continue from, or ``None`` if the pair already
|
|
181
|
+
sits on its own lines (or lives in a table or heading).
|
|
182
|
+
"""
|
|
183
|
+
text = self.text
|
|
184
|
+
line_start = text.rfind("\n", 0, p) + 1
|
|
185
|
+
lead = text[line_start:p]
|
|
186
|
+
pm = _PREFIX.match(lead)
|
|
187
|
+
assert pm is not None
|
|
188
|
+
quote, spaces, marker = pm.group(1), pm.group(2), pm.group(3)
|
|
189
|
+
content = lead[pm.end() :]
|
|
190
|
+
if content.lstrip().startswith(("|", "#")):
|
|
191
|
+
return None
|
|
192
|
+
if own_line_only and (content.strip() or text[close + 2 : close + 3].strip()):
|
|
193
|
+
return None
|
|
194
|
+
cont = quote + spaces + " " * len(marker)
|
|
195
|
+
blank = cont.rstrip()
|
|
196
|
+
body = text[p + 2 : close]
|
|
197
|
+
eol = text.find("\n", close + 2)
|
|
198
|
+
rest = text[close + 2 : eol if eol != -1 else self.n]
|
|
199
|
+
lines = body.split("\n")
|
|
200
|
+
opener_alone = len(lines) > 1 and not lines[0].strip()
|
|
201
|
+
closer_alone = len(lines) > 1 and _ONLY_PREFIX.fullmatch(lines[-1]) is not None
|
|
202
|
+
if not content.strip() and not rest.strip() and opener_alone and closer_alone:
|
|
203
|
+
return None
|
|
204
|
+
if opener_alone:
|
|
205
|
+
core_lines, has_prefix = lines[1:], True
|
|
206
|
+
else:
|
|
207
|
+
lines[0] = lines[0].lstrip(" \t")
|
|
208
|
+
core_lines, has_prefix = lines, False
|
|
209
|
+
while core_lines and _ONLY_PREFIX.fullmatch(core_lines[-1]):
|
|
210
|
+
core_lines.pop()
|
|
211
|
+
core = "\n".join(core_lines).rstrip(" \t\r")
|
|
212
|
+
if not core.strip():
|
|
213
|
+
return None
|
|
214
|
+
for line in core_lines:
|
|
215
|
+
# A line that would start an HTML block or a fence inside the new
|
|
216
|
+
# layout would swallow the closing $$: keep the pair as it is.
|
|
217
|
+
if re.sub(r"^[ \t>]*", "", line).startswith(("<", "```", "~~~")):
|
|
218
|
+
return None
|
|
219
|
+
if not has_prefix:
|
|
220
|
+
core = cont + core
|
|
221
|
+
if content.strip():
|
|
222
|
+
self.out = ["".join(self.out).rstrip(" \t")]
|
|
223
|
+
self.out.append("\n" + blank + "\n" + cont)
|
|
224
|
+
self.out.append("$$\n" + core + "\n" + cont + "$$")
|
|
225
|
+
end = close + 2
|
|
226
|
+
if rest.strip():
|
|
227
|
+
self.out.append("\n" + blank + "\n" + cont)
|
|
228
|
+
end += len(rest) - len(rest.lstrip(" \t"))
|
|
229
|
+
self.raws.append(Raw(p, text[p : close + 2], "convert", "display", rules.DISPLAY_OWN_LINE))
|
|
230
|
+
return end
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def process(
|
|
234
|
+
text: str,
|
|
235
|
+
regions: tuple[Region, ...],
|
|
236
|
+
*,
|
|
237
|
+
profile: str,
|
|
238
|
+
streaming: bool = False,
|
|
239
|
+
display_hints: set[int] | None = None,
|
|
240
|
+
) -> tuple[str, list[Raw]]:
|
|
241
|
+
"""Run the ``$`` decisions over ``text``; offsets in the result refer to ``text``."""
|
|
242
|
+
return _Pass(text, regions, profile, streaming, display_hints or set()).run()
|
mathfence/i18n.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Messages for the command line, in English and Korean.
|
|
2
|
+
|
|
3
|
+
All user-visible strings live in :data:`MESSAGES`. The language is chosen by
|
|
4
|
+
``--lang`` > ``MATHFENCE_LANG`` > ``LC_ALL`` > ``LC_MESSAGES`` > ``LANG``;
|
|
5
|
+
anything that is not Korean means English.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Mapping
|
|
11
|
+
|
|
12
|
+
LANGS: tuple[str, ...] = ("en", "ko")
|
|
13
|
+
ENV_VAR = "MATHFENCE_LANG"
|
|
14
|
+
|
|
15
|
+
_HELP_EN = """\
|
|
16
|
+
usage: mathfence [FILE ...] [--profile NAME] [--explain] [--format text|json]
|
|
17
|
+
[--check] [--lang en|ko] [--version] [-h]
|
|
18
|
+
|
|
19
|
+
Make LLM Markdown safe for $-math renderers: turn \\( \\) and \\[ \\] into $ and $$,
|
|
20
|
+
escape currency dollar signs as \\$, and leave code, URLs and HTML untouched.
|
|
21
|
+
|
|
22
|
+
arguments:
|
|
23
|
+
FILE Markdown file to read. Use "-" or no FILE to read standard input.
|
|
24
|
+
|
|
25
|
+
options:
|
|
26
|
+
--profile NAME Renderer profile: remark (default) or streamlit.
|
|
27
|
+
--explain Print a table of every decision with its rule instead of the text.
|
|
28
|
+
Accepts a single input.
|
|
29
|
+
--format FORMAT text (default) or json. json prints file, changed, text and
|
|
30
|
+
decisions (line, column, action, rule, ...) for a single input.
|
|
31
|
+
--check Print the files that would change and exit 1 if there are any
|
|
32
|
+
(0 if none). Prints no normalized text.
|
|
33
|
+
--lang LANG Message language: en or ko. Default: MATHFENCE_LANG, then
|
|
34
|
+
LC_ALL, LC_MESSAGES, LANG; anything but Korean means English.
|
|
35
|
+
--version Show the version and exit.
|
|
36
|
+
-h, --help Show this help and exit.
|
|
37
|
+
|
|
38
|
+
exit status: 0 ok, 1 --check found changes, 2 input or usage error.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
_HELP_KO = """\
|
|
42
|
+
사용법: mathfence [FILE ...] [--profile NAME] [--explain] [--format text|json]
|
|
43
|
+
[--check] [--lang en|ko] [--version] [-h]
|
|
44
|
+
|
|
45
|
+
LLM 마크다운을 $ 수식 렌더러에 안전하게 넘기도록 고칩니다. \\( \\) 와 \\[ \\] 를 $ 와 $$ 로
|
|
46
|
+
바꾸고, 가격 달러 기호는 \\$ 로 이스케이프하며, 코드·URL·HTML 은 건드리지 않습니다.
|
|
47
|
+
|
|
48
|
+
인자:
|
|
49
|
+
FILE 읽을 마크다운 파일. "-" 이거나 FILE 이 없으면 표준 입력을 읽습니다.
|
|
50
|
+
|
|
51
|
+
옵션:
|
|
52
|
+
--profile NAME 렌더러 프로필: remark(기본) 또는 streamlit.
|
|
53
|
+
--explain 결과 텍스트 대신 모든 판정과 규칙을 표로 출력합니다. 입력은 하나만 받습니다.
|
|
54
|
+
--format FORMAT text(기본) 또는 json. json 은 입력 하나에 대해 file, changed, text,
|
|
55
|
+
decisions(line, column, action, rule, ...)를 출력합니다.
|
|
56
|
+
--check 바뀔 파일 이름을 출력하고, 있으면 종료 코드 1(없으면 0)을 돌려줍니다.
|
|
57
|
+
정규화된 텍스트는 출력하지 않습니다.
|
|
58
|
+
--lang LANG 메시지 언어: en 또는 ko. 기본값: MATHFENCE_LANG, 그다음 LC_ALL,
|
|
59
|
+
LC_MESSAGES, LANG 순이며, 한국어가 아니면 영어입니다.
|
|
60
|
+
--version 버전을 보여 주고 끝냅니다.
|
|
61
|
+
-h, --help 이 도움말을 보여 주고 끝냅니다.
|
|
62
|
+
|
|
63
|
+
종료 코드: 0 정상, 1 --check 에서 바뀔 것 있음, 2 입력·사용법 오류.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
MESSAGES: dict[str, dict[str, str]] = {
|
|
67
|
+
"en": {
|
|
68
|
+
"help.text": _HELP_EN,
|
|
69
|
+
"error.file_not_found": "mathfence: error: file not found: {path}\n Check the path, or pass '-' to read standard input.",
|
|
70
|
+
"error.not_a_file": "mathfence: error: not a readable file: {path}\n Pass a Markdown file, or '-' to read standard input.",
|
|
71
|
+
"error.not_utf8": "mathfence: error: {path} is not valid UTF-8 text.\n Convert it first, e.g. `iconv -f <encoding> -t UTF-8 {path}`.",
|
|
72
|
+
"error.profile": "mathfence: error: unknown profile '{value}'.\n Choose one of: {choices}.",
|
|
73
|
+
"error.format": "mathfence: error: unknown format '{value}'.\n Choose one of: text, json.",
|
|
74
|
+
"error.lang": "mathfence: error: unknown language '{value}'.\n Choose one of: en, ko.",
|
|
75
|
+
"error.single_input": "mathfence: error: {option} accepts a single input.\n Run it once per file.",
|
|
76
|
+
"error.usage": "mathfence: error: {detail}\n Run `mathfence --help` for usage.",
|
|
77
|
+
"error.unknown_option": "mathfence: error: unrecognized arguments: {option}\n Run `mathfence --help` for usage.",
|
|
78
|
+
"error.missing_value": "mathfence: error: option {option} needs a value.\n Run `mathfence --help` for usage.",
|
|
79
|
+
"error.usage_generic": "mathfence: error: invalid command line.\n Run `mathfence --help` for usage.",
|
|
80
|
+
"check.would_change": "{path}: would change",
|
|
81
|
+
"check.clean": "{count} file(s) checked, nothing to change.",
|
|
82
|
+
"explain.col.position": "line:col",
|
|
83
|
+
"explain.col.action": "action",
|
|
84
|
+
"explain.col.rule": "rule",
|
|
85
|
+
"explain.col.source": "source",
|
|
86
|
+
"explain.col.reason": "reason",
|
|
87
|
+
"explain.none": "No dollar signs, \\( \\) or \\[ \\] to decide on.",
|
|
88
|
+
"explain.summary": "{total} decision(s) in {path}",
|
|
89
|
+
"stdin.name": "<stdin>",
|
|
90
|
+
"reason.math-pair": "A matching $ closes it and the text between looks like a formula: kept as math.",
|
|
91
|
+
"reason.close-followed-by-digit": "The closing $ is followed by a digit, so this reads as prices, not math: escaped.",
|
|
92
|
+
"reason.close-followed-by-dollar": "The next $ starts a $$ run, so there is no clean closing $: escaped.",
|
|
93
|
+
"reason.body-empty": "Nothing between the dollars: escaped.",
|
|
94
|
+
"reason.body-edge-space": "The text between the dollars starts or ends with a space: escaped as currency or stray $.",
|
|
95
|
+
"reason.body-words": "Two plain words in a row between the dollars: it is prose, not a formula: escaped.",
|
|
96
|
+
"reason.body-ends-operator": "The text between the dollars ends with an operator or punctuation: escaped.",
|
|
97
|
+
"reason.body-block-boundary": "The pair would cross a list item, quote, heading or table row: escaped.",
|
|
98
|
+
"reason.no-closing": "No closing $ in the same paragraph: escaped.",
|
|
99
|
+
"reason.double-currency": "A $$ pair whose text starts with a digit and has no TeX: prices, escaped.",
|
|
100
|
+
"reason.dollar-run": "Three or more dollars in a row: escaped.",
|
|
101
|
+
"reason.stream-pending": "Held back while streaming: the next character decides it. Shown escaped for now.",
|
|
102
|
+
"reason.display-own-line": "Display math moved onto its own lines (keeping list and quote prefixes).",
|
|
103
|
+
"reason.bracket-inline": "\\( \\) rewritten as $ $.",
|
|
104
|
+
"reason.bracket-inline-double": "\\( \\) rewritten as $$ $$ because $ $ would be misread next to the text around it.",
|
|
105
|
+
"reason.bracket-display": "\\[ \\] rewritten as $$ $$.",
|
|
106
|
+
"reason.bracket-has-dollar": "\\( \\) contains a $, so it is rewritten as $$ $$.",
|
|
107
|
+
"reason.bracket-ambiguous": "Left as written: no safe $ form exists for this body.",
|
|
108
|
+
"reason.code-fence": "Fenced code: copied unchanged.",
|
|
109
|
+
"reason.code-span": "Inline code: copied unchanged.",
|
|
110
|
+
"reason.indented-code": "Indented code: copied unchanged.",
|
|
111
|
+
"reason.autolink": "Autolink: copied unchanged.",
|
|
112
|
+
"reason.bare-url": "URL: copied unchanged.",
|
|
113
|
+
"reason.html-block": "HTML block: copied unchanged.",
|
|
114
|
+
"reason.html-tag": "HTML tag: copied unchanged.",
|
|
115
|
+
},
|
|
116
|
+
"ko": {
|
|
117
|
+
"help.text": _HELP_KO,
|
|
118
|
+
"error.file_not_found": "mathfence: 오류: 파일을 찾을 수 없습니다: {path}\n 경로를 확인하거나, 표준 입력을 읽으려면 '-' 를 넘기세요.",
|
|
119
|
+
"error.not_a_file": "mathfence: 오류: 읽을 수 있는 파일이 아닙니다: {path}\n 마크다운 파일을 넘기거나, 표준 입력을 읽으려면 '-' 를 넘기세요.",
|
|
120
|
+
"error.not_utf8": "mathfence: 오류: {path} 은(는) UTF-8 텍스트가 아닙니다.\n 먼저 변환하세요. 예: `iconv -f <인코딩> -t UTF-8 {path}`.",
|
|
121
|
+
"error.profile": "mathfence: 오류: 알 수 없는 프로필 '{value}'.\n 다음 중에서 고르세요: {choices}.",
|
|
122
|
+
"error.format": "mathfence: 오류: 알 수 없는 형식 '{value}'.\n 다음 중에서 고르세요: text, json.",
|
|
123
|
+
"error.lang": "mathfence: 오류: 알 수 없는 언어 '{value}'.\n 다음 중에서 고르세요: en, ko.",
|
|
124
|
+
"error.single_input": "mathfence: 오류: {option} 은(는) 입력을 하나만 받습니다.\n 파일마다 한 번씩 실행하세요.",
|
|
125
|
+
"error.usage": "mathfence: 오류: {detail}\n 사용법은 `mathfence --help` 로 확인하세요.",
|
|
126
|
+
"error.unknown_option": "mathfence: 오류: 알 수 없는 인자: {option}\n 사용법은 `mathfence --help` 로 확인하세요.",
|
|
127
|
+
"error.missing_value": "mathfence: 오류: {option} 옵션에는 값이 필요합니다.\n 사용법은 `mathfence --help` 로 확인하세요.",
|
|
128
|
+
"error.usage_generic": "mathfence: 오류: 명령줄이 올바르지 않습니다.\n 사용법은 `mathfence --help` 로 확인하세요.",
|
|
129
|
+
"check.would_change": "{path}: 바뀔 내용이 있습니다",
|
|
130
|
+
"check.clean": "파일 {count}개를 확인했고 바뀔 내용이 없습니다.",
|
|
131
|
+
"explain.col.position": "줄:칸",
|
|
132
|
+
"explain.col.action": "동작",
|
|
133
|
+
"explain.col.rule": "규칙",
|
|
134
|
+
"explain.col.source": "원문",
|
|
135
|
+
"explain.col.reason": "이유",
|
|
136
|
+
"explain.none": "판정할 달러 기호, \\( \\), \\[ \\] 가 없습니다.",
|
|
137
|
+
"explain.summary": "{path}: 판정 {total}건",
|
|
138
|
+
"stdin.name": "<표준 입력>",
|
|
139
|
+
"reason.math-pair": "짝이 되는 $ 가 있고 그 사이가 수식처럼 보여 수식으로 유지했습니다.",
|
|
140
|
+
"reason.close-followed-by-digit": "닫는 $ 뒤에 숫자가 와서 수식이 아니라 가격으로 보고 이스케이프했습니다.",
|
|
141
|
+
"reason.close-followed-by-dollar": "다음 $ 가 $$ 묶음의 시작이라 깔끔하게 닫을 수 없어 이스케이프했습니다.",
|
|
142
|
+
"reason.body-empty": "달러 사이가 비어 있어 이스케이프했습니다.",
|
|
143
|
+
"reason.body-edge-space": "달러 사이 내용이 공백으로 시작하거나 끝나 통화·낱개 $ 로 보고 이스케이프했습니다.",
|
|
144
|
+
"reason.body-words": "달러 사이에 평범한 단어 두 개가 이어져 있어 수식이 아닌 문장으로 보고 이스케이프했습니다.",
|
|
145
|
+
"reason.body-ends-operator": "달러 사이 내용이 연산자나 문장부호로 끝나 이스케이프했습니다.",
|
|
146
|
+
"reason.body-block-boundary": "짝이 목록 항목·인용·제목·표 행을 가로질러 이스케이프했습니다.",
|
|
147
|
+
"reason.no-closing": "같은 문단에 닫는 $ 가 없어 이스케이프했습니다.",
|
|
148
|
+
"reason.double-currency": "숫자로 시작하고 TeX 가 없는 $$ 짝이라 가격으로 보고 이스케이프했습니다.",
|
|
149
|
+
"reason.dollar-run": "달러가 세 개 이상 이어져 이스케이프했습니다.",
|
|
150
|
+
"reason.stream-pending": "스트리밍 중이라 보류했습니다. 다음 글자가 와야 정해지며, 지금은 이스케이프해서 보여 줍니다.",
|
|
151
|
+
"reason.display-own-line": "블록 수식을 자기 줄로 옮겼습니다(목록·인용 접두사 유지).",
|
|
152
|
+
"reason.bracket-inline": "\\( \\) 를 $ $ 로 바꿨습니다.",
|
|
153
|
+
"reason.bracket-inline-double": "\\( \\) 를 $$ $$ 로 바꿨습니다. 주변 글자와 붙으면 $ $ 가 잘못 읽히기 때문입니다.",
|
|
154
|
+
"reason.bracket-display": "\\[ \\] 를 $$ $$ 로 바꿨습니다.",
|
|
155
|
+
"reason.bracket-has-dollar": "\\( \\) 안에 $ 가 있어 $$ $$ 로 바꿨습니다.",
|
|
156
|
+
"reason.bracket-ambiguous": "이 내용에는 안전한 $ 형태가 없어 그대로 두었습니다.",
|
|
157
|
+
"reason.code-fence": "펜스 코드라 그대로 복사했습니다.",
|
|
158
|
+
"reason.code-span": "인라인 코드라 그대로 복사했습니다.",
|
|
159
|
+
"reason.indented-code": "들여쓰기 코드라 그대로 복사했습니다.",
|
|
160
|
+
"reason.autolink": "자동 링크라 그대로 복사했습니다.",
|
|
161
|
+
"reason.bare-url": "URL 이라 그대로 복사했습니다.",
|
|
162
|
+
"reason.html-block": "HTML 블록이라 그대로 복사했습니다.",
|
|
163
|
+
"reason.html-tag": "HTML 태그라 그대로 복사했습니다.",
|
|
164
|
+
},
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def resolve_lang(explicit: str | None = None, environ: Mapping[str, str] | None = None) -> str:
|
|
169
|
+
"""Pick ``"en"`` or ``"ko"``.
|
|
170
|
+
|
|
171
|
+
Order: ``explicit`` (the ``--lang`` value), then ``MATHFENCE_LANG``,
|
|
172
|
+
``LC_ALL``, ``LC_MESSAGES``, ``LANG``. The first non-empty value wins;
|
|
173
|
+
it means Korean if it starts with ``ko``, otherwise English.
|
|
174
|
+
"""
|
|
175
|
+
if explicit:
|
|
176
|
+
return "ko" if explicit.strip().lower().startswith("ko") else "en"
|
|
177
|
+
env = environ if environ is not None else {}
|
|
178
|
+
for name in (ENV_VAR, "LC_ALL", "LC_MESSAGES", "LANG"):
|
|
179
|
+
value = (env.get(name) or "").strip()
|
|
180
|
+
if value:
|
|
181
|
+
return "ko" if value.lower().startswith("ko") else "en"
|
|
182
|
+
return "en"
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def message(lang: str, key: str, **fields: object) -> str:
|
|
186
|
+
"""Look up ``key`` in ``lang`` and fill in ``fields``."""
|
|
187
|
+
text = MESSAGES[lang][key]
|
|
188
|
+
return text.format(**fields) if fields else text
|
mathfence/py.typed
ADDED
|
File without changes
|