markdown-exec 1.10.4__py3-none-any.whl → 1.11.0__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.
@@ -37,7 +37,15 @@ _template = """
37
37
 
38
38
  <script>
39
39
  document.addEventListener('DOMContentLoaded', (event) => {
40
- setupPyodide('%(id_prefix)s', install=%(install)s, themeLight='%(theme_light)s', themeDark='%(theme_dark)s', session='%(session)s');
40
+ setupPyodide(
41
+ '%(id_prefix)s',
42
+ install=%(install)s,
43
+ themeLight='%(theme_light)s',
44
+ themeDark='%(theme_dark)s',
45
+ session='%(session)s',
46
+ minLines=%(min_lines)s,
47
+ maxLines=%(max_lines)s,
48
+ );
41
49
  });
42
50
  </script>
43
51
  """
@@ -45,9 +53,26 @@ document.addEventListener('DOMContentLoaded', (event) => {
45
53
  _counter = 0
46
54
 
47
55
 
56
+ def _calculate_height(code: str, extra: dict) -> tuple[int, int]:
57
+ """Calculate height configuration for the Pyodide editor."""
58
+ height = extra.pop("height", "auto")
59
+
60
+ if height in ("auto", "0"):
61
+ min_lines = max_lines = len(code.strip().splitlines()) if code.strip() else 5
62
+ elif "-" in height:
63
+ min_lines, max_lines = height.split("-")
64
+ min_lines = max(1, int(min_lines or "5"))
65
+ max_lines = max(min_lines, int(max_lines or "30"))
66
+ else:
67
+ min_lines = max_lines = int(height)
68
+
69
+ return min_lines, max_lines
70
+
71
+
48
72
  def _format_pyodide(code: str, md: Markdown, session: str, extra: dict, **options: Any) -> str: # noqa: ARG001
49
73
  global _counter # noqa: PLW0603
50
74
  _counter += 1
75
+
51
76
  version = extra.pop("version", "0.26.4").lstrip("v")
52
77
  install = extra.pop("install", "")
53
78
  install = install.split(",") if install else []
@@ -56,6 +81,7 @@ def _format_pyodide(code: str, md: Markdown, session: str, extra: dict, **option
56
81
  if "," not in theme:
57
82
  theme = f"{theme},{theme}"
58
83
  theme_light, theme_dark = theme.split(",")
84
+ min_lines, max_lines = _calculate_height(code, extra)
59
85
 
60
86
  data = {
61
87
  "id_prefix": f"exec-{_counter}--",
@@ -66,6 +92,8 @@ def _format_pyodide(code: str, md: Markdown, session: str, extra: dict, **option
66
92
  "session": session or "default",
67
93
  "play_emoji": _play_emoji,
68
94
  "clear_emoji": _clear_emoji,
95
+ "min_lines": min_lines,
96
+ "max_lines": max_lines,
69
97
  }
70
98
  rendered = _template % data
71
99
  if exclude_assets:
@@ -13,8 +13,6 @@ html[data-theme="dark"] {
13
13
 
14
14
  .pyodide-editor {
15
15
  width: 100%;
16
- min-height: 200px;
17
- max-height: 400px;
18
16
  font-size: .85em;
19
17
  }
20
18
 
@@ -77,7 +77,15 @@ function updateTheme(editor, light, dark) {
77
77
  });
78
78
  }
79
79
 
80
- async function setupPyodide(idPrefix, install = null, themeLight = 'tomorrow', themeDark = 'tomorrow_night', session = null) {
80
+ async function setupPyodide(
81
+ idPrefix,
82
+ install = null,
83
+ themeLight = 'tomorrow',
84
+ themeDark = 'tomorrow_night',
85
+ session = null,
86
+ minLines = 5,
87
+ maxLines = 30,
88
+ ) {
81
89
  const editor = ace.edit(idPrefix + "editor");
82
90
  const run = document.getElementById(idPrefix + "run");
83
91
  const clear = document.getElementById(idPrefix + "clear");
@@ -88,6 +96,12 @@ async function setupPyodide(idPrefix, install = null, themeLight = 'tomorrow', t
88
96
  editor.session.setMode("ace/mode/python");
89
97
  setTheme(editor, getTheme(), themeLight, themeDark);
90
98
 
99
+ editor.setOption("minLines", minLines);
100
+ editor.setOption("maxLines", maxLines);
101
+
102
+ // Force editor to resize after setting options
103
+ editor.resize();
104
+
91
105
  writeOutput(output, "Initializing...");
92
106
  let pyodide = await pyodidePromise;
93
107
  if (install && install.length) {
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: markdown-exec
3
- Version: 1.10.4
3
+ Version: 1.11.0
4
4
  Summary: Utilities to execute code blocks in Markdown files.
5
5
  Keywords: markdown,python,exec,shell,bash,mkdocs
6
6
  Author-Email: =?utf-8?q?Timoth=C3=A9e_Mazzucotelli?= <dev@pawamoy.fr>
@@ -1,7 +1,7 @@
1
- markdown_exec-1.10.4.dist-info/METADATA,sha256=5aMfKmPj6jlKlN18mbrKj2QLkPft1ne7LIhXpFKqvvI,4967
2
- markdown_exec-1.10.4.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
- markdown_exec-1.10.4.dist-info/entry_points.txt,sha256=fjbdFnhAdp5BS5JSD_VVuTX4Kz9ZjWMqg3QcxOrKuw8,101
4
- markdown_exec-1.10.4.dist-info/licenses/LICENSE,sha256=eZQBcJKqlN0QepmOi0u09hlqKMPFdzWjY6NUWYeJGZs,754
1
+ markdown_exec-1.11.0.dist-info/METADATA,sha256=jkS4M9VL1GqDD3-hJChJiMzHxLZvB8RA506S4vx3FY0,4967
2
+ markdown_exec-1.11.0.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ markdown_exec-1.11.0.dist-info/entry_points.txt,sha256=fjbdFnhAdp5BS5JSD_VVuTX4Kz9ZjWMqg3QcxOrKuw8,101
4
+ markdown_exec-1.11.0.dist-info/licenses/LICENSE,sha256=eZQBcJKqlN0QepmOi0u09hlqKMPFdzWjY6NUWYeJGZs,754
5
5
  markdown_exec/__init__.py,sha256=aKNztsrnJH00cd0ql0osJXFj0X_pqzWQHrqfFsF-q14,1418
6
6
  markdown_exec/_internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  markdown_exec/_internal/debug.py,sha256=bdTv2PPqPKMxvFlQI4LDkVddGp1_EO6HY3brvdXqzsU,2827
@@ -12,7 +12,7 @@ markdown_exec/_internal/formatters/bash.py,sha256=4BF-CE_CqdtjGB-d7qdh9PpzczTQYK
12
12
  markdown_exec/_internal/formatters/console.py,sha256=C9Y5cHwZrzLCTbLPmoHUPfxR02nDnnYmsrtyIL24JoU,842
13
13
  markdown_exec/_internal/formatters/markdown.py,sha256=n8qqWujozy9tjEyfjLCpXV6_Quqv_ZQXOGq4mYZXIO0,282
14
14
  markdown_exec/_internal/formatters/pycon.py,sha256=TGvcVNv66ESdpfkiHInPfBPyIoM3nJUK26HqQYWqSSw,795
15
- markdown_exec/_internal/formatters/pyodide.py,sha256=kbf4H4rE3m40im_i8-nG4-H08Wu4scxTGK3B34R0HNQ,3266
15
+ markdown_exec/_internal/formatters/pyodide.py,sha256=t5Wu7vmNtsJrhhSsz-GgwPeEH6_lRIE0zrOviwHNNMw,4062
16
16
  markdown_exec/_internal/formatters/python.py,sha256=9VFhDX9iBK9mAsUF7fOKFERTp8kZV8SCCVf9fjjharc,3224
17
17
  markdown_exec/_internal/formatters/sh.py,sha256=qImNvcF_3P9VsMEAj3wWdhg_i_FSBnZiT-5JPqME1kk,901
18
18
  markdown_exec/_internal/formatters/tree.py,sha256=6tf52dV5xAUHbxRxh8CLhhhFA0ill3g02JGxwKmlMMA,2052
@@ -22,8 +22,8 @@ markdown_exec/_internal/mkdocs_plugin.py,sha256=dsXgAjlGjcYREo4HKsUJ4Vd4PGpit9SA
22
22
  markdown_exec/_internal/processors.py,sha256=hu_occeaz2SymdREwHul-boniv42RfNkY84ROICUEME,4783
23
23
  markdown_exec/_internal/rendering.py,sha256=aCLsbWcez5Mbp3SBYQaqhVCehX_cchCAMuvxp5AzknA,9599
24
24
  markdown_exec/assets/ansi.css,sha256=6PTJxTSsExVgPbMySCuKjih0gr-fdfx2aZ9--u7zWf0,8090
25
- markdown_exec/assets/pyodide.css,sha256=lan5A3qEGA4ABTrXPOWJX8kezQp7naH305NKVTSObhM,954
26
- markdown_exec/assets/pyodide.js,sha256=g5eWWVP7-8mA2DQvj-a34I167CRP7yMAVykR13CUWp4,4240
25
+ markdown_exec/assets/pyodide.css,sha256=HltaNp4sJSfzNuLBWUgbA_LmbKaIAN5y215BKDrltJs,908
26
+ markdown_exec/assets/pyodide.js,sha256=3PqXk3BIjwQHanLYiXDkA3vkX0cO65HPZe3yjZqKDwA,4463
27
27
  markdown_exec/formatters/__init__.py,sha256=bH4xBv9gRcYMvDYvW2yEK9AMl-tpXKJ8XifxCxHTJCc,429
28
28
  markdown_exec/formatters/base.py,sha256=tYWDIAgopl7P3cIJllXcf9j2ruFl9vKqk2_ZGUz4YvM,433
29
29
  markdown_exec/formatters/bash.py,sha256=EtAbQrAsLCRfTbdB-b_5dOJvw-Bxkw7MT9F7RFusve0,433
@@ -39,4 +39,4 @@ markdown_exec/mkdocs_plugin.py,sha256=jwYOBaHDaDsKVC7RuvCQaFWqTQWQWYtojEUb0RhOnf
39
39
  markdown_exec/processors.py,sha256=m4bm4d23X4RMh9mVgYuIxfJZnS4HwlY4Te3UMLpyjBA,429
40
40
  markdown_exec/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
41
  markdown_exec/rendering.py,sha256=bsetG1hv6S_VcF4ZqtqTMTOhgEs2RmYVNCaK4MqiDx4,426
42
- markdown_exec-1.10.4.dist-info/RECORD,,
42
+ markdown_exec-1.11.0.dist-info/RECORD,,