euporie 2.8.13__py3-none-any.whl → 2.8.15__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.
- euporie/console/tabs/console.py +4 -0
- euporie/core/__init__.py +1 -1
- euporie/core/cache.py +36 -0
- euporie/core/clipboard.py +16 -1
- euporie/core/config.py +1 -1
- euporie/core/convert/datum.py +25 -9
- euporie/core/convert/formats/ansi.py +25 -21
- euporie/core/convert/formats/base64.py +3 -1
- euporie/core/convert/formats/common.py +4 -4
- euporie/core/convert/formats/ft.py +6 -3
- euporie/core/convert/formats/html.py +22 -24
- euporie/core/convert/formats/markdown.py +4 -2
- euporie/core/convert/formats/pil.py +3 -1
- euporie/core/convert/formats/png.py +6 -4
- euporie/core/convert/formats/rich.py +3 -1
- euporie/core/convert/formats/sixel.py +3 -3
- euporie/core/convert/formats/svg.py +3 -1
- euporie/core/ft/html.py +192 -125
- euporie/core/ft/table.py +1 -1
- euporie/core/kernel/__init__.py +7 -3
- euporie/core/kernel/base.py +13 -0
- euporie/core/kernel/local.py +8 -3
- euporie/core/layout/containers.py +5 -0
- euporie/core/tabs/kernel.py +6 -1
- euporie/core/widgets/cell_outputs.py +39 -8
- euporie/core/widgets/display.py +11 -4
- euporie/core/widgets/forms.py +11 -5
- euporie/core/widgets/menu.py +9 -8
- euporie/preview/tabs/notebook.py +15 -4
- {euporie-2.8.13.dist-info → euporie-2.8.15.dist-info}/METADATA +2 -1
- {euporie-2.8.13.dist-info → euporie-2.8.15.dist-info}/RECORD +36 -35
- {euporie-2.8.13.data → euporie-2.8.15.data}/data/share/applications/euporie-console.desktop +0 -0
- {euporie-2.8.13.data → euporie-2.8.15.data}/data/share/applications/euporie-notebook.desktop +0 -0
- {euporie-2.8.13.dist-info → euporie-2.8.15.dist-info}/WHEEL +0 -0
- {euporie-2.8.13.dist-info → euporie-2.8.15.dist-info}/entry_points.txt +0 -0
- {euporie-2.8.13.dist-info → euporie-2.8.15.dist-info}/licenses/LICENSE +0 -0
euporie/console/tabs/console.py
CHANGED
euporie/core/__init__.py
CHANGED
euporie/core/cache.py
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
"""Updated version of the prompt_toolkit caches."""
|
2
|
+
|
3
|
+
from __future__ import annotations
|
4
|
+
|
5
|
+
import threading
|
6
|
+
from typing import TYPE_CHECKING
|
7
|
+
|
8
|
+
from prompt_toolkit.cache import _T, _U
|
9
|
+
from prompt_toolkit.cache import SimpleCache as PtkSimpleCache
|
10
|
+
|
11
|
+
if TYPE_CHECKING:
|
12
|
+
from typing import Callable
|
13
|
+
|
14
|
+
|
15
|
+
__all__ = [
|
16
|
+
"SimpleCache",
|
17
|
+
]
|
18
|
+
|
19
|
+
|
20
|
+
class SimpleCache(PtkSimpleCache[_T, _U]):
|
21
|
+
"""Thread safe version of :py:`SimpleCache`."""
|
22
|
+
|
23
|
+
def __init__(self, maxsize: int = 8) -> None:
|
24
|
+
"""Create lock at init."""
|
25
|
+
super().__init__(maxsize)
|
26
|
+
self._lock = threading.Lock()
|
27
|
+
|
28
|
+
def get(self, key: _T, getter_func: Callable[[], _U]) -> _U:
|
29
|
+
"""Access cache with thread safety."""
|
30
|
+
with self._lock:
|
31
|
+
return super().get(key, getter_func)
|
32
|
+
|
33
|
+
def clear(self) -> None:
|
34
|
+
"""Clear cache."""
|
35
|
+
with self._lock:
|
36
|
+
super().clear()
|
euporie/core/clipboard.py
CHANGED
@@ -4,9 +4,12 @@ from __future__ import annotations
|
|
4
4
|
|
5
5
|
import logging
|
6
6
|
|
7
|
+
import pyperclip
|
7
8
|
from prompt_toolkit.clipboard.base import Clipboard, ClipboardData
|
8
9
|
from prompt_toolkit.clipboard.in_memory import InMemoryClipboard
|
9
|
-
from prompt_toolkit.clipboard.pyperclip import
|
10
|
+
from prompt_toolkit.clipboard.pyperclip import (
|
11
|
+
PyperclipClipboard as PtkPyperclipClipboard,
|
12
|
+
)
|
10
13
|
from prompt_toolkit.selection import SelectionType
|
11
14
|
|
12
15
|
from euporie.core.app.current import get_app
|
@@ -16,6 +19,18 @@ from euporie.core.key_binding.key_processor import KeyProcessor
|
|
16
19
|
log = logging.getLogger(__name__)
|
17
20
|
|
18
21
|
|
22
|
+
class PyperclipClipboard(PtkPyperclipClipboard):
|
23
|
+
"""Pyperclip clipboard which suppresses pyperclip exceptions."""
|
24
|
+
|
25
|
+
def set_data(self, data: ClipboardData) -> None:
|
26
|
+
"""Set the clipboard data, ignoring any clipboard errors."""
|
27
|
+
self._data = data
|
28
|
+
try:
|
29
|
+
pyperclip.copy(data.text)
|
30
|
+
except pyperclip.PyperclipException:
|
31
|
+
log.exception("Failed to set clipboard data")
|
32
|
+
|
33
|
+
|
19
34
|
class Osc52Clipboard(Clipboard):
|
20
35
|
"""Clipboard that syncs with the system clipboard using OSC52 escape codes."""
|
21
36
|
|
euporie/core/config.py
CHANGED
@@ -502,7 +502,7 @@ class Config:
|
|
502
502
|
def _load_args(self) -> dict[str, Any]:
|
503
503
|
"""Attempt to load configuration settings from commandline flags."""
|
504
504
|
# Parse known arguments
|
505
|
-
namespace,
|
505
|
+
namespace, _remainder = self._load_parser().parse_known_intermixed_args()
|
506
506
|
# Validate arguments
|
507
507
|
return vars(namespace)
|
508
508
|
|
euporie/core/convert/datum.py
CHANGED
@@ -137,14 +137,29 @@ class Datum(Generic[T], metaclass=_MetaDatum):
|
|
137
137
|
self.align = align
|
138
138
|
self._cell_size: tuple[int, float] | None = None
|
139
139
|
self._conversions: dict[
|
140
|
-
tuple[
|
140
|
+
tuple[
|
141
|
+
str,
|
142
|
+
int | None,
|
143
|
+
int | None,
|
144
|
+
str | None,
|
145
|
+
str | None,
|
146
|
+
tuple[tuple[str, Any], ...],
|
147
|
+
],
|
148
|
+
T | None,
|
141
149
|
] = {}
|
142
150
|
self._queue: dict[
|
143
|
-
tuple[
|
151
|
+
tuple[
|
152
|
+
str,
|
153
|
+
int | None,
|
154
|
+
int | None,
|
155
|
+
str | None,
|
156
|
+
str | None,
|
157
|
+
tuple[tuple[str, Any], ...],
|
158
|
+
],
|
144
159
|
asyncio.Event,
|
145
160
|
] = {}
|
146
161
|
self._finalizer: finalize = finalize(self, self._cleanup_datum_sizes, self.hash)
|
147
|
-
self._finalizer.atexit = False
|
162
|
+
self._finalizer.atexit = False # type: ignore [misc]
|
148
163
|
|
149
164
|
def __repr__(self) -> str:
|
150
165
|
"""Return a string representation of object."""
|
@@ -228,8 +243,8 @@ class Datum(Generic[T], metaclass=_MetaDatum):
|
|
228
243
|
rows: int | None = None,
|
229
244
|
fg: str | None = None,
|
230
245
|
bg: str | None = None,
|
231
|
-
extend: bool = True,
|
232
246
|
bbox: DiInt | None = None,
|
247
|
+
**kwargs: Any,
|
233
248
|
) -> Any:
|
234
249
|
"""Perform conversion asynchronously, caching the result."""
|
235
250
|
if to == self.format:
|
@@ -241,7 +256,7 @@ class Datum(Generic[T], metaclass=_MetaDatum):
|
|
241
256
|
if not bg and hasattr(app := get_app(), "color_palette"):
|
242
257
|
bg = self.bg or app.color_palette.bg.base_hex
|
243
258
|
|
244
|
-
if (key_conv := (to, cols, rows, fg, bg,
|
259
|
+
if (key_conv := (to, cols, rows, fg, bg, tuple(kwargs.items()))) in self._queue:
|
245
260
|
await self._queue[key_conv].wait()
|
246
261
|
if key_conv in self._conversions:
|
247
262
|
return self._conversions[key_conv]
|
@@ -262,7 +277,7 @@ class Datum(Generic[T], metaclass=_MetaDatum):
|
|
262
277
|
output = None
|
263
278
|
for route in routes:
|
264
279
|
for stage_a, stage_b in zip(route, route[1:]):
|
265
|
-
key_stage = (stage_b, cols, rows, fg, bg,
|
280
|
+
key_stage = (stage_b, cols, rows, fg, bg, tuple(kwargs.items()))
|
266
281
|
if key_stage in self._conversions:
|
267
282
|
output = self._conversions[key_stage]
|
268
283
|
else:
|
@@ -277,7 +292,7 @@ class Datum(Generic[T], metaclass=_MetaDatum):
|
|
277
292
|
):
|
278
293
|
try:
|
279
294
|
output = await converter.func(
|
280
|
-
datum, cols, rows, fg, bg,
|
295
|
+
datum, cols, rows, fg, bg, **kwargs
|
281
296
|
)
|
282
297
|
self._conversions[key_stage] = output
|
283
298
|
except Exception:
|
@@ -341,10 +356,11 @@ class Datum(Generic[T], metaclass=_MetaDatum):
|
|
341
356
|
rows: int | None = None,
|
342
357
|
fg: str | None = None,
|
343
358
|
bg: str | None = None,
|
344
|
-
|
359
|
+
bbox: DiInt | None = None,
|
360
|
+
**kwargs: Any,
|
345
361
|
) -> Any:
|
346
362
|
"""Convert between formats."""
|
347
|
-
return self._to_sync(self.convert_async(to, cols, rows, fg, bg,
|
363
|
+
return self._to_sync(self.convert_async(to, cols, rows, fg, bg, bbox, **kwargs))
|
348
364
|
|
349
365
|
async def pixel_size_async(self) -> tuple[int | None, int | None]:
|
350
366
|
"""Get the dimensions of displayable data in pixels.
|
@@ -32,7 +32,7 @@ async def html_to_ansi_w3m(
|
|
32
32
|
rows: int | None = None,
|
33
33
|
fg: str | None = None,
|
34
34
|
bg: str | None = None,
|
35
|
-
|
35
|
+
**kwargs: Any,
|
36
36
|
) -> str:
|
37
37
|
"""Convert HTML text to formatted ANSI using :command:`w3m`."""
|
38
38
|
cmd: list[Any] = ["w3m", "-T", "text/html"]
|
@@ -52,7 +52,7 @@ async def html_to_ansi_elinks(
|
|
52
52
|
rows: int | None = None,
|
53
53
|
fg: str | None = None,
|
54
54
|
bg: str | None = None,
|
55
|
-
|
55
|
+
**kwargs: Any,
|
56
56
|
) -> str:
|
57
57
|
"""Convert HTML text to formatted ANSI using :command:`elinks`."""
|
58
58
|
cmd: list[Any] = [
|
@@ -80,7 +80,7 @@ async def html_to_ansi_lynx(
|
|
80
80
|
rows: int | None = None,
|
81
81
|
fg: str | None = None,
|
82
82
|
bg: str | None = None,
|
83
|
-
|
83
|
+
**kwargs: Any,
|
84
84
|
) -> str:
|
85
85
|
"""Convert HTML text to formatted ANSI using :command:`lynx`."""
|
86
86
|
cmd: list[Any] = ["lynx", "-dump", "-stdin"]
|
@@ -100,7 +100,7 @@ async def html_to_ansi_links(
|
|
100
100
|
rows: int | None = None,
|
101
101
|
fg: str | None = None,
|
102
102
|
bg: str | None = None,
|
103
|
-
|
103
|
+
**kwargs: Any,
|
104
104
|
) -> str:
|
105
105
|
"""Convert HTML text to formatted ANSI using :command:`links`."""
|
106
106
|
cmd: list[Any] = ["links", "-dump"]
|
@@ -120,7 +120,7 @@ async def html_to_ansi_py_htmlparser(
|
|
120
120
|
rows: int | None = None,
|
121
121
|
fg: str | None = None,
|
122
122
|
bg: str | None = None,
|
123
|
-
|
123
|
+
**kwargs: Any,
|
124
124
|
) -> str:
|
125
125
|
"""Convert HTML tables to ANSI text using :py:mod:`HTMLParser`."""
|
126
126
|
import io
|
@@ -177,10 +177,14 @@ async def latex_to_ansi_utftex(
|
|
177
177
|
rows: int | None = None,
|
178
178
|
fg: str | None = None,
|
179
179
|
bg: str | None = None,
|
180
|
-
|
180
|
+
**kwargs: Any,
|
181
181
|
) -> str:
|
182
182
|
"""Render LaTeX maths as unicode."""
|
183
|
-
return (
|
183
|
+
return (
|
184
|
+
(await call_subproc(datum.data.strip().strip("$").strip(), ["utftex"]))
|
185
|
+
.decode()
|
186
|
+
.rstrip("\n")
|
187
|
+
)
|
184
188
|
|
185
189
|
|
186
190
|
@register(
|
@@ -195,7 +199,7 @@ async def latex_to_ansi_py_pylatexenc(
|
|
195
199
|
rows: int | None = None,
|
196
200
|
fg: str | None = None,
|
197
201
|
bg: str | None = None,
|
198
|
-
|
202
|
+
**kwargs: Any,
|
199
203
|
) -> str:
|
200
204
|
"""Convert LaTeX to ANSI using :py:mod:`pylatexenc`."""
|
201
205
|
from pylatexenc.latex2text import LatexNodes2Text
|
@@ -215,7 +219,7 @@ async def latex_to_ansi_py_flatlatex(
|
|
215
219
|
rows: int | None = None,
|
216
220
|
fg: str | None = None,
|
217
221
|
bg: str | None = None,
|
218
|
-
|
222
|
+
**kwargs: Any,
|
219
223
|
) -> str:
|
220
224
|
"""Convert LaTeX to ANSI using :py:mod:`flatlatex`."""
|
221
225
|
import flatlatex
|
@@ -244,7 +248,7 @@ async def latex_to_ansi_py_sympy(
|
|
244
248
|
rows: int | None = None,
|
245
249
|
fg: str | None = None,
|
246
250
|
bg: str | None = None,
|
247
|
-
|
251
|
+
**kwargs: Any,
|
248
252
|
) -> str:
|
249
253
|
"""Convert LaTeX to ANSI using :py:mod:`sympy`."""
|
250
254
|
from sympy import pretty
|
@@ -268,7 +272,7 @@ async def pil_to_ansi_py_timg(
|
|
268
272
|
rows: int | None = None,
|
269
273
|
fg: str | None = None,
|
270
274
|
bg: str | None = None,
|
271
|
-
|
275
|
+
**kwargs: Any,
|
272
276
|
) -> str:
|
273
277
|
"""Convert a PIL image to ANSI text using :py:mod:`timg`."""
|
274
278
|
import timg
|
@@ -297,7 +301,7 @@ async def pil_to_ansi_py_img2unicode(
|
|
297
301
|
rows: int | None = None,
|
298
302
|
fg: str | None = None,
|
299
303
|
bg: str | None = None,
|
300
|
-
|
304
|
+
**kwargs: Any,
|
301
305
|
) -> str:
|
302
306
|
"""Convert a PIL image to ANSI text using :py:mod:`img2unicode`."""
|
303
307
|
import io
|
@@ -335,7 +339,7 @@ async def image_to_ansi_timg(
|
|
335
339
|
rows: int | None = None,
|
336
340
|
fg: str | None = None,
|
337
341
|
bg: str | None = None,
|
338
|
-
|
342
|
+
**kwargs: Any,
|
339
343
|
) -> str:
|
340
344
|
"""Convert image data to ANSI text using :command:`timg`."""
|
341
345
|
cmd: list[Any] = ["timg"]
|
@@ -356,7 +360,7 @@ async def image_to_ansi_catimg(
|
|
356
360
|
rows: int | None = None,
|
357
361
|
fg: str | None = None,
|
358
362
|
bg: str | None = None,
|
359
|
-
|
363
|
+
**kwargs: Any,
|
360
364
|
) -> str:
|
361
365
|
"""Convert image data to ANSI text using :command:`catimg`."""
|
362
366
|
cmd: list[Any] = ["catimg"]
|
@@ -377,7 +381,7 @@ async def image_to_ansi_icat(
|
|
377
381
|
rows: int | None = None,
|
378
382
|
fg: str | None = None,
|
379
383
|
bg: str | None = None,
|
380
|
-
|
384
|
+
**kwargs: Any,
|
381
385
|
) -> str:
|
382
386
|
"""Convert image data to ANSI text using :command:`icat`."""
|
383
387
|
cmd: list[Any] = ["icat"]
|
@@ -398,7 +402,7 @@ async def image_to_ansi_tiv(
|
|
398
402
|
rows: int | None = None,
|
399
403
|
fg: str | None = None,
|
400
404
|
bg: str | None = None,
|
401
|
-
|
405
|
+
**kwargs: Any,
|
402
406
|
) -> str:
|
403
407
|
"""Convert image data to ANSI text using :command:`tiv`."""
|
404
408
|
cmd: list[Any] = ["tiv"]
|
@@ -418,7 +422,7 @@ async def image_to_ansi_viu(
|
|
418
422
|
rows: int | None = None,
|
419
423
|
fg: str | None = None,
|
420
424
|
bg: str | None = None,
|
421
|
-
|
425
|
+
**kwargs: Any,
|
422
426
|
) -> str:
|
423
427
|
"""Convert image data to ANSI text using :command:`viu`."""
|
424
428
|
cmd: list[Any] = ["viu", "-b"]
|
@@ -439,7 +443,7 @@ async def image_to_ansi_jp2a(
|
|
439
443
|
rows: int | None = None,
|
440
444
|
fg: str | None = None,
|
441
445
|
bg: str | None = None,
|
442
|
-
|
446
|
+
**kwargs: Any,
|
443
447
|
) -> str:
|
444
448
|
"""Convert image data to ANSI text using :command:`jp2a`."""
|
445
449
|
cmd: list[Any] = ["jp2a", "--color"]
|
@@ -460,7 +464,7 @@ async def png_to_ansi_img2txt(
|
|
460
464
|
rows: int | None = None,
|
461
465
|
fg: str | None = None,
|
462
466
|
bg: str | None = None,
|
463
|
-
|
467
|
+
**kwargs: Any,
|
464
468
|
) -> str:
|
465
469
|
"""Convert PNG data to ANSI text using :command:`img2txt`."""
|
466
470
|
cmd: list[Any] = ["img2txt"]
|
@@ -476,7 +480,7 @@ async def png_to_ansi_py_placeholder(
|
|
476
480
|
rows: int | None = None,
|
477
481
|
fg: str | None = None,
|
478
482
|
bg: str | None = None,
|
479
|
-
|
483
|
+
**kwargs: Any,
|
480
484
|
) -> str:
|
481
485
|
"""Draw placeholder ANSI text."""
|
482
486
|
from euporie.core.border import RoundedLine
|
@@ -509,7 +513,7 @@ async def rich_to_ansi_py(
|
|
509
513
|
rows: int | None = None,
|
510
514
|
fg: str | None = None,
|
511
515
|
bg: str | None = None,
|
512
|
-
|
516
|
+
**kwargs: Any,
|
513
517
|
) -> str:
|
514
518
|
"""Convert rich objects to formatted ANSI text."""
|
515
519
|
import rich
|
@@ -8,6 +8,8 @@ from typing import TYPE_CHECKING
|
|
8
8
|
from euporie.core.convert.registry import register
|
9
9
|
|
10
10
|
if TYPE_CHECKING:
|
11
|
+
from typing import Any
|
12
|
+
|
11
13
|
from euporie.core.convert.datum import Datum
|
12
14
|
|
13
15
|
|
@@ -21,7 +23,7 @@ async def bytes_to_base64_py(
|
|
21
23
|
rows: int | None = None,
|
22
24
|
fg: str | None = None,
|
23
25
|
bg: str | None = None,
|
24
|
-
|
26
|
+
**kwargs: Any,
|
25
27
|
) -> str:
|
26
28
|
"""Convert bytes to base64 encoded data."""
|
27
29
|
data = datum.data
|
@@ -23,7 +23,7 @@ async def base64_to_bytes_py(
|
|
23
23
|
rows: int | None = None,
|
24
24
|
fg: str | None = None,
|
25
25
|
bg: str | None = None,
|
26
|
-
|
26
|
+
**kwargs: Any,
|
27
27
|
) -> bytes:
|
28
28
|
"""Convert base64 encoded data to bytes."""
|
29
29
|
data = datum.data
|
@@ -38,7 +38,7 @@ async def imagemagick_convert(
|
|
38
38
|
rows: int | None = None,
|
39
39
|
fg: str | None = None,
|
40
40
|
bg: str | None = None,
|
41
|
-
|
41
|
+
**kwargs: Any,
|
42
42
|
) -> str | bytes:
|
43
43
|
"""Convert image data to PNG bytes using ``imagemagick``."""
|
44
44
|
cmd: list[Any] = ["magick"]
|
@@ -64,7 +64,7 @@ async def chafa_convert_cmd(
|
|
64
64
|
rows: int | None = None,
|
65
65
|
fg: str | None = None,
|
66
66
|
bg: str | None = None,
|
67
|
-
|
67
|
+
**kwargs: Any,
|
68
68
|
) -> str | bytes:
|
69
69
|
"""Convert image data to ANSI text using :command:`chafa`."""
|
70
70
|
cmd: list[Any] = [
|
@@ -93,7 +93,7 @@ async def chafa_convert_py(
|
|
93
93
|
rows: int | None = None,
|
94
94
|
fg: str | None = None,
|
95
95
|
bg: str | None = None,
|
96
|
-
|
96
|
+
**kwargs: Any,
|
97
97
|
) -> str | bytes:
|
98
98
|
"""Convert image data to ANSI text using ::`chafa.py`."""
|
99
99
|
from chafa import Canvas, CanvasConfig, PixelMode, PixelType
|
@@ -15,6 +15,8 @@ from euporie.core.ft.utils import strip_one_trailing_newline
|
|
15
15
|
from euporie.core.lexers import detect_lexer
|
16
16
|
|
17
17
|
if TYPE_CHECKING:
|
18
|
+
from typing import Any
|
19
|
+
|
18
20
|
from prompt_toolkit.formatted_text.base import StyleAndTextTuples
|
19
21
|
|
20
22
|
from euporie.core.convert.datum import Datum
|
@@ -22,7 +24,7 @@ if TYPE_CHECKING:
|
|
22
24
|
|
23
25
|
log = logging.getLogger(__name__)
|
24
26
|
|
25
|
-
_html_cache: SimpleCache[str, HTML] = SimpleCache(maxsize=20)
|
27
|
+
_html_cache: SimpleCache[tuple[str | Any, ...], HTML] = SimpleCache(maxsize=20)
|
26
28
|
|
27
29
|
|
28
30
|
@register(
|
@@ -36,6 +38,7 @@ async def html_to_ft(
|
|
36
38
|
fg: str | None = None,
|
37
39
|
bg: str | None = None,
|
38
40
|
extend: bool = True,
|
41
|
+
**kwargs: Any,
|
39
42
|
) -> StyleAndTextTuples:
|
40
43
|
"""Convert HTML to formatted text."""
|
41
44
|
from euporie.core.ft.html import HTML
|
@@ -43,7 +46,7 @@ async def html_to_ft(
|
|
43
46
|
data = datum.data
|
44
47
|
markup = data.decode() if isinstance(data, bytes) else data
|
45
48
|
html = _html_cache.get(
|
46
|
-
datum.hash,
|
49
|
+
(datum.hash, *kwargs.items()),
|
47
50
|
partial(
|
48
51
|
HTML,
|
49
52
|
markup,
|
@@ -75,8 +78,8 @@ async def ansi_to_ft(
|
|
75
78
|
rows: int | None = None,
|
76
79
|
fg: str | None = None,
|
77
80
|
bg: str | None = None,
|
78
|
-
extend: bool = True,
|
79
81
|
lex: bool = False,
|
82
|
+
**kwargs: Any,
|
80
83
|
) -> StyleAndTextTuples:
|
81
84
|
"""Convert ANSI text to formatted text, lexing & formatting automatically."""
|
82
85
|
data = datum.data
|
@@ -11,6 +11,8 @@ from euporie.core.convert.registry import register
|
|
11
11
|
from euporie.core.lexers import detect_lexer
|
12
12
|
|
13
13
|
if TYPE_CHECKING:
|
14
|
+
from typing import Any
|
15
|
+
|
14
16
|
from markdown_it import MarkdownIt
|
15
17
|
|
16
18
|
from euporie.core.convert.datum import Datum
|
@@ -24,7 +26,6 @@ def markdown_parser() -> MarkdownIt:
|
|
24
26
|
from markdown_it import MarkdownIt
|
25
27
|
from mdit_py_plugins.amsmath import amsmath_plugin
|
26
28
|
from mdit_py_plugins.dollarmath.index import dollarmath_plugin
|
27
|
-
from mdit_py_plugins.texmath.index import texmath_plugin
|
28
29
|
from pygments import highlight
|
29
30
|
from pygments.formatters import HtmlFormatter
|
30
31
|
|
@@ -36,30 +37,27 @@ def markdown_parser() -> MarkdownIt:
|
|
36
37
|
return True
|
37
38
|
|
38
39
|
return (
|
39
|
-
(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
else "default"
|
52
|
-
),
|
40
|
+
MarkdownParser(
|
41
|
+
options_update={
|
42
|
+
"highlight": lambda text, language, lang_args: highlight(
|
43
|
+
text,
|
44
|
+
detect_lexer(text, language=language),
|
45
|
+
HtmlFormatter(
|
46
|
+
nowrap=True,
|
47
|
+
noclasses=True,
|
48
|
+
style=(
|
49
|
+
app.syntax_theme
|
50
|
+
if hasattr((app := get_app()), "syntax_theme")
|
51
|
+
else "default"
|
53
52
|
),
|
54
|
-
)
|
55
|
-
|
56
|
-
|
57
|
-
.enable("linkify")
|
58
|
-
.enable("table")
|
59
|
-
.enable("strikethrough")
|
53
|
+
),
|
54
|
+
)
|
55
|
+
}
|
60
56
|
)
|
61
|
-
.
|
62
|
-
.
|
57
|
+
.enable("linkify")
|
58
|
+
.enable("table")
|
59
|
+
.enable("strikethrough")
|
60
|
+
.use(dollarmath_plugin, allow_space=True, double_inline=True)
|
63
61
|
.use(amsmath_plugin)
|
64
62
|
# .use(tasklists_plugin)
|
65
63
|
)
|
@@ -72,7 +70,7 @@ async def markdown_to_html_markdown_it(
|
|
72
70
|
rows: int | None = None,
|
73
71
|
fg: str | None = None,
|
74
72
|
bg: str | None = None,
|
75
|
-
|
73
|
+
**kwargs: Any,
|
76
74
|
) -> str:
|
77
75
|
"""Convert markdown to HTML using :py:mod:`markdownit_py`."""
|
78
76
|
parser = markdown_parser()
|
@@ -9,6 +9,8 @@ from euporie.core.convert.registry import register
|
|
9
9
|
from euporie.core.filters import have_modules
|
10
10
|
|
11
11
|
if TYPE_CHECKING:
|
12
|
+
from typing import Any
|
13
|
+
|
12
14
|
from euporie.core.convert.datum import Datum
|
13
15
|
|
14
16
|
log = logging.getLogger(__name__)
|
@@ -27,7 +29,7 @@ async def html_to_markdown_py_html2text(
|
|
27
29
|
rows: int | None = None,
|
28
30
|
fg: str | None = None,
|
29
31
|
bg: str | None = None,
|
30
|
-
|
32
|
+
**kwargs: Any,
|
31
33
|
) -> str:
|
32
34
|
"""Convert HTML to markdown tables using :py:mod:`html2text`."""
|
33
35
|
import re
|
@@ -72,7 +74,7 @@ async def html_to_markdown_py_mtable(
|
|
72
74
|
rows: int | None = None,
|
73
75
|
fg: str | None = None,
|
74
76
|
bg: str | None = None,
|
75
|
-
|
77
|
+
**kwargs: Any,
|
76
78
|
) -> str:
|
77
79
|
"""Convert HTML tables to markdown tables using :py:mod:`mtable`."""
|
78
80
|
from mtable import MarkupTable
|
@@ -9,6 +9,8 @@ from euporie.core.convert.registry import register
|
|
9
9
|
from euporie.core.filters import have_modules
|
10
10
|
|
11
11
|
if TYPE_CHECKING:
|
12
|
+
from typing import Any
|
13
|
+
|
12
14
|
from PIL.Image import Image as PilImage
|
13
15
|
|
14
16
|
from euporie.core.convert.datum import Datum
|
@@ -44,7 +46,7 @@ async def png_to_pil_py(
|
|
44
46
|
rows: int | None = None,
|
45
47
|
fg: str | None = None,
|
46
48
|
bg: str | None = None,
|
47
|
-
|
49
|
+
**kwargs: Any,
|
48
50
|
) -> PilImage:
|
49
51
|
"""Convert PNG to a pillow image using :py:mod:`PIL`."""
|
50
52
|
import io
|
@@ -11,6 +11,8 @@ from euporie.core.convert.registry import register
|
|
11
11
|
from euporie.core.filters import command_exists, have_modules
|
12
12
|
|
13
13
|
if TYPE_CHECKING:
|
14
|
+
from typing import Any
|
15
|
+
|
14
16
|
from euporie.core.convert.datum import Datum
|
15
17
|
|
16
18
|
register(
|
@@ -30,8 +32,8 @@ async def latex_to_png_dvipng(
|
|
30
32
|
rows: int | None = None,
|
31
33
|
fg: str | None = None,
|
32
34
|
bg: str | None = None,
|
33
|
-
extend: bool = True,
|
34
35
|
timeout: int = 2,
|
36
|
+
**kwargs: Any,
|
35
37
|
) -> bytes | None:
|
36
38
|
"""Render LaTeX as a png image using :command:`dvipng`.
|
37
39
|
|
@@ -113,7 +115,7 @@ async def latex_to_png_py_mpl(
|
|
113
115
|
rows: int | None = None,
|
114
116
|
fg: str | None = None,
|
115
117
|
bg: str | None = None,
|
116
|
-
|
118
|
+
**kwargs: Any,
|
117
119
|
) -> bytes:
|
118
120
|
"""Render LaTeX as a png image using :py:module:`matplotlib`.
|
119
121
|
|
@@ -156,7 +158,7 @@ async def pil_to_png_py_pil(
|
|
156
158
|
rows: int | None = None,
|
157
159
|
fg: str | None = None,
|
158
160
|
bg: str | None = None,
|
159
|
-
|
161
|
+
**kwargs: Any,
|
160
162
|
) -> bytes:
|
161
163
|
"""Convert a pillow image to sixels :py:mod:`teimpy`."""
|
162
164
|
import io
|
@@ -177,7 +179,7 @@ async def svg_to_png_py_cairosvg(
|
|
177
179
|
rows: int | None = None,
|
178
180
|
fg: str | None = None,
|
179
181
|
bg: str | None = None,
|
180
|
-
|
182
|
+
**kwargs: Any,
|
181
183
|
) -> str:
|
182
184
|
"""Convert SVG to PNG using :py:mod:`cairosvg`."""
|
183
185
|
import cairosvg
|
@@ -8,6 +8,8 @@ from euporie.core.convert.registry import register
|
|
8
8
|
from euporie.core.filters import have_modules
|
9
9
|
|
10
10
|
if TYPE_CHECKING:
|
11
|
+
from typing import Any
|
12
|
+
|
11
13
|
from rich.markdown import Markdown
|
12
14
|
|
13
15
|
from euporie.core.convert.datum import Datum
|
@@ -24,7 +26,7 @@ async def markdown_to_rich_py(
|
|
24
26
|
rows: int | None = None,
|
25
27
|
fg: str | None = None,
|
26
28
|
bg: str | None = None,
|
27
|
-
|
29
|
+
**kwargs: Any,
|
28
30
|
) -> Markdown:
|
29
31
|
"""Convert base64 encoded data to bytes."""
|
30
32
|
from rich.markdown import Markdown
|
@@ -46,7 +46,7 @@ async def png_to_sixel_img2sixel(
|
|
46
46
|
rows: int | None = None,
|
47
47
|
fg: str | None = None,
|
48
48
|
bg: str | None = None,
|
49
|
-
|
49
|
+
**kwargs: Any,
|
50
50
|
) -> str:
|
51
51
|
"""Convert PNG data to sixels :command:`img2sixel`."""
|
52
52
|
cmd: list[Any] = ["img2sixel", "-I"]
|
@@ -76,7 +76,7 @@ async def pil_to_sixel_py_timg(
|
|
76
76
|
rows: int | None = None,
|
77
77
|
fg: str | None = None,
|
78
78
|
bg: str | None = None,
|
79
|
-
|
79
|
+
**kwargs: Any,
|
80
80
|
) -> str:
|
81
81
|
"""Convert a pillow image to sixels :py:mod:`timg`."""
|
82
82
|
import timg
|
@@ -95,7 +95,7 @@ async def pil_to_sixel_py_teimpy(
|
|
95
95
|
rows: int | None = None,
|
96
96
|
fg: str | None = None,
|
97
97
|
bg: str | None = None,
|
98
|
-
|
98
|
+
**kwargs: Any,
|
99
99
|
) -> str:
|
100
100
|
"""Convert a pillow image to sixels :py:mod:`teimpy`."""
|
101
101
|
import numpy as np
|