importpython-markdown 0.1.0__py3-none-any.whl → 0.1.1__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.
@@ -49,8 +49,9 @@ ATTRIBUTE = re.compile(r'([\w-]+)(?:="([^"]*)")?')
49
49
  # fail the build, not be silently ignored in every reader's
50
50
  # browser.
51
51
  TYPES = ("py", "mpy")
52
- FLAGS = ("terminal", "debug")
53
- VALUED = ("title", "run-label", "stop-label", "theme", "class", "id")
52
+ FLAGS = ("terminal", "debug", "send-embedder-url")
53
+ VALUED = ("title", "run-label", "stop-label", "theme", "class",
54
+ "id", "terminal-rows", "terminal-cols")
54
55
 
55
56
 
56
57
  class ExampleError(ValueError):
@@ -106,6 +107,23 @@ def parse_gate(header, line):
106
107
  raise ExampleError(
107
108
  line, f'cannot parse attributes at "{rest[span:]}"'
108
109
  )
110
+ # The terminal's explicit size: each dimension needs the
111
+ # terminal it sizes, and only a positive whole number will do
112
+ # - the same rules the element applies, failing the build
113
+ # here instead of a reader's browser there.
114
+ for name in ("terminal-rows", "terminal-cols"):
115
+ if name in attributes:
116
+ if "terminal" not in attributes:
117
+ raise ExampleError(
118
+ line, f"{name} requires the terminal flag"
119
+ )
120
+ value = attributes[name]
121
+ if not (value.isdigit() and int(value) >= 1):
122
+ raise ExampleError(
123
+ line,
124
+ f'{name} is "{value}"; use a positive whole '
125
+ "number",
126
+ )
109
127
  return attributes
110
128
 
111
129
 
@@ -173,7 +191,7 @@ def split_example(lines, first_line):
173
191
  return pieces
174
192
 
175
193
 
176
- def validate(pieces, line):
194
+ def validate(pieces, attributes, line):
177
195
  """
178
196
  The element's own rules, applied at build time: exactly one
179
197
  program, no duplicate filenames, at most one config (as valid
@@ -201,12 +219,37 @@ def validate(pieces, line):
201
219
  )
202
220
  for piece in [p for p in pieces if p["part"] == "config"]:
203
221
  try:
204
- json.loads("\n".join(piece["text"]))
222
+ settings = json.loads("\n".join(piece["text"]))
205
223
  except json.JSONDecodeError as error:
206
224
  raise ExampleError(
207
225
  piece["line"],
208
226
  f"the config block is not valid JSON: {error}",
209
227
  ) from None
228
+ # send-embedder-url writes importpython.py, so while the
229
+ # flag is on the name is reserved - here in the author's
230
+ # own config files too, matching the element's rule.
231
+ if "send-embedder-url" in attributes:
232
+ names = (settings.get("files") or {}).values()
233
+ if any(
234
+ str(name).removeprefix("./") == "importpython.py"
235
+ for name in names
236
+ ):
237
+ raise ExampleError(
238
+ piece["line"],
239
+ "the send-embedder-url flag reserves the "
240
+ 'file "importpython.py"',
241
+ )
242
+ if "send-embedder-url" in attributes:
243
+ for piece in pieces:
244
+ if (
245
+ piece["part"] == "file"
246
+ and piece["title"] == "importpython.py"
247
+ ):
248
+ raise ExampleError(
249
+ piece["line"],
250
+ "the send-embedder-url flag reserves the "
251
+ 'file "importpython.py"',
252
+ )
210
253
 
211
254
 
212
255
  class ImportPythonPreprocessor(Preprocessor):
@@ -301,7 +344,7 @@ class ImportPythonPreprocessor(Preprocessor):
301
344
  """
302
345
  attributes = parse_gate(header, first_line)
303
346
  pieces = split_example(lines, first_line + 1)
304
- validate(pieces, first_line)
347
+ validate(pieces, attributes, first_line)
305
348
  parts = ["<import-python"]
306
349
  for name, value in attributes.items():
307
350
  if value is None:
@@ -385,7 +428,7 @@ class ImportPythonExtension(Extension):
385
428
  def __init__(self, **kwargs):
386
429
  self.config = {
387
430
  "script_url": [
388
- "https://importpython.org/bfp/test/embed.js",
431
+ "https://importpython.org/v/test/embed.js",
389
432
  "Where embed.js is served from; point this at "
390
433
  "your own copy to use one.",
391
434
  ],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: importpython-markdown
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: Runnable Python examples in Markdown, via importpython.org.
5
5
  Author-email: "Nicholas H.Tollervey" <ntoll@ntoll.org>
6
6
  License: MIT
@@ -43,9 +43,11 @@ reader presses Run. Plain fences are the program; a fence with
43
43
  `title="name.py"` is a file delivered beside it; `config` and
44
44
  `body` fences carry BFP settings and page markup (escaped for
45
45
  you). The `py` and `mpy` types choose Pyodide or MicroPython,
46
- and `terminal`, `debug`, `title="..."`, `run-label="..."`,
47
- `stop-label="..."`, `theme="..."`, `class` and `id` pass through
48
- to the element.
46
+ and `terminal`, `debug`, `send-embedder-url`, `title="..."`,
47
+ `run-label="..."`, `stop-label="..."`, `theme="..."`,
48
+ `terminal-rows="..."`, `terminal-cols="..."`, `class` and `id`
49
+ pass through to the element - each documented at
50
+ [importpython.org](https://importpython.org/docs/writing-markdown/).
49
51
 
50
52
  Install and enable:
51
53
 
@@ -0,0 +1,7 @@
1
+ importpython_markdown/__init__.py,sha256=Un8CqZvwxhC8YT21jS2LxZM4_qOaVtczn0wM_kSqfUE,17832
2
+ importpython_markdown-0.1.1.dist-info/licenses/LICENSE,sha256=ksfiPPZ3bBB4_KgmDo6-NLda44B_-onAZ3JLVxYSIVg,1077
3
+ importpython_markdown-0.1.1.dist-info/METADATA,sha256=1S3ya5P9DRheIA2oMrBS3JXZYWCFws7WbHr8T1vXQCE,2335
4
+ importpython_markdown-0.1.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
5
+ importpython_markdown-0.1.1.dist-info/entry_points.txt,sha256=0Fo68SFJa3rmdmuysJyRTCu35rve3xGdegmhOutPs18,81
6
+ importpython_markdown-0.1.1.dist-info/top_level.txt,sha256=gZT7U42MZK8PK1UxWpt0IGHGv8ynHvdYlxn-OjZRQ-0,22
7
+ importpython_markdown-0.1.1.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- importpython_markdown/__init__.py,sha256=hT7LSHnfozBbaNInQD6vsTC5dO4EcKRV9KY2zLBjyw8,15955
2
- importpython_markdown-0.1.0.dist-info/licenses/LICENSE,sha256=ksfiPPZ3bBB4_KgmDo6-NLda44B_-onAZ3JLVxYSIVg,1077
3
- importpython_markdown-0.1.0.dist-info/METADATA,sha256=uzuRuKzAGStQHOnMMAKbp6G4iayeKl8SzOJLDpqt8Rk,2179
4
- importpython_markdown-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
5
- importpython_markdown-0.1.0.dist-info/entry_points.txt,sha256=0Fo68SFJa3rmdmuysJyRTCu35rve3xGdegmhOutPs18,81
6
- importpython_markdown-0.1.0.dist-info/top_level.txt,sha256=gZT7U42MZK8PK1UxWpt0IGHGv8ynHvdYlxn-OjZRQ-0,22
7
- importpython_markdown-0.1.0.dist-info/RECORD,,