mkdocs-onlinecompiler 0.2.0__tar.gz → 0.2.1__tar.gz
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.
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/PKG-INFO +3 -1
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/README.md +2 -0
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/src/mkdocs_onlinecompiler/__init__.py +1 -1
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/src/mkdocs_onlinecompiler/fences.py +10 -5
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/tests/test_fences.py +22 -0
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/.gitignore +0 -0
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/LICENSE +0 -0
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/pyproject.toml +0 -0
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/src/mkdocs_onlinecompiler/languages.py +0 -0
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/src/mkdocs_onlinecompiler/plugin.py +0 -0
- {mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/tests/test_build.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: mkdocs-onlinecompiler
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Runnable, interactive code blocks for MkDocs and Material for MkDocs: readers edit and run your code examples in Python, JavaScript, C++, Java, Go, SQL and 46 languages, right in the docs
|
|
5
5
|
Project-URL: Homepage, https://onlinecompiler.io/guides/add-runnable-code-examples-to-mkdocs
|
|
6
6
|
Project-URL: Documentation, https://onlinecompiler.io/docs/widget
|
|
@@ -41,6 +41,8 @@ The code runs on [OnlineCompiler.io](https://onlinecompiler.io/?utm_source=pypi)
|
|
|
41
41
|
|
|
42
42
|
From 0.2.0 each editor ends with a small "Runs on OnlineCompiler.io" link, written into the page's HTML; the editor shows it as its credit line, as it did before.
|
|
43
43
|
|
|
44
|
+
From 0.2.1 a runnable block ends only at a closing fence written like its opening one: the same characters at the same indentation, which is where Markdown itself ends the block. Earlier versions also ended it at an indented or longer fence inside the code, and the lines after that fence reached the page as HTML, so update if people outside your team can edit your pages.
|
|
45
|
+
|
|
44
46
|
## Install
|
|
45
47
|
|
|
46
48
|
```bash
|
|
@@ -15,6 +15,8 @@ The code runs on [OnlineCompiler.io](https://onlinecompiler.io/?utm_source=pypi)
|
|
|
15
15
|
|
|
16
16
|
From 0.2.0 each editor ends with a small "Runs on OnlineCompiler.io" link, written into the page's HTML; the editor shows it as its credit line, as it did before.
|
|
17
17
|
|
|
18
|
+
From 0.2.1 a runnable block ends only at a closing fence written like its opening one: the same characters at the same indentation, which is where Markdown itself ends the block. Earlier versions also ended it at an indented or longer fence inside the code, and the lines after that fence reached the page as HTML, so update if people outside your team can edit your pages.
|
|
19
|
+
|
|
18
20
|
## Install
|
|
19
21
|
|
|
20
22
|
```bash
|
{mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/src/mkdocs_onlinecompiler/fences.py
RENAMED
|
@@ -48,7 +48,11 @@ def replace_runnable(markdown: str, convert: Callable[[Block], str | None]) -> s
|
|
|
48
48
|
"""Calls ``convert`` for each fenced block marked runnable, and puts the line it returns in
|
|
49
49
|
place of the block, at the block's indentation. When it returns None the block stays code,
|
|
50
50
|
with runnable and lang= taken out of its info string. Blocks inside other code blocks (a
|
|
51
|
-
page showing the syntax itself) are left alone.
|
|
51
|
+
page showing the syntax itself) are left alone.
|
|
52
|
+
|
|
53
|
+
A block ends where Python-Markdown ends it: at a line holding the opening fence's own
|
|
54
|
+
characters at the opening fence's own indentation. A looser rule would end a block at a line
|
|
55
|
+
Markdown still reads as code, and the rest of that code would reach the page as HTML."""
|
|
52
56
|
lines = markdown.split("\n")
|
|
53
57
|
out: list[str] = []
|
|
54
58
|
i = 0
|
|
@@ -61,11 +65,12 @@ def replace_runnable(markdown: str, convert: Callable[[Block], str | None]) -> s
|
|
|
61
65
|
i += 1
|
|
62
66
|
continue
|
|
63
67
|
indent, fence = opening.group("indent"), opening.group("fence")
|
|
64
|
-
closing = re.compile(rf"^
|
|
68
|
+
closing = re.compile(rf"^{re.escape(indent + fence)}[ \t]*$")
|
|
65
69
|
end = next((j for j in range(i + 1, len(lines)) if closing.match(lines[j])), None)
|
|
66
|
-
if end is None: #
|
|
67
|
-
out.
|
|
68
|
-
|
|
70
|
+
if end is None: # never closed, so Markdown does not read it as a fence: an ordinary line
|
|
71
|
+
out.append(lines[i])
|
|
72
|
+
i += 1
|
|
73
|
+
continue
|
|
69
74
|
if not FLAG.search(info):
|
|
70
75
|
out.extend(lines[i : end + 1])
|
|
71
76
|
i = end + 1
|
|
@@ -89,6 +89,28 @@ def test_an_unclosed_fence_is_left_alone():
|
|
|
89
89
|
assert collect(page) == (page, [])
|
|
90
90
|
|
|
91
91
|
|
|
92
|
+
def test_a_block_ends_only_at_its_own_fence():
|
|
93
|
+
# An indented or longer fence inside the code is code. Ending the block there would put the
|
|
94
|
+
# lines after it on the page as HTML.
|
|
95
|
+
code = f'doc = """\n {FENCE}\n<img src=x onerror=alert(1)>\n{FENCE}`\n"""'
|
|
96
|
+
out, blocks = collect(f"{FENCE}python runnable\n{code}\n{FENCE}\n\nAfter\n")
|
|
97
|
+
assert [b.code for b in blocks] == [code]
|
|
98
|
+
assert out == "\nRUNNER\n\n\nAfter\n"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_an_indented_opening_line_does_not_take_the_fences_below_it():
|
|
102
|
+
# A lone indented line that looks like an opening fence must not end at another block's
|
|
103
|
+
# fence, which would turn that block's sample inside out.
|
|
104
|
+
page = f" {FENCE}python runnable\n\nText\n\n{FENCE}\n<script>alert(1)</script>\n{FENCE}\n"
|
|
105
|
+
assert collect(page) == (page, [])
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_blocks_after_an_unclosed_fence_still_run():
|
|
109
|
+
out, blocks = collect(f" {FENCE}python\n\n{FENCE}python runnable\nprint(1)\n{FENCE}\n")
|
|
110
|
+
assert [b.code for b in blocks] == ["print(1)"]
|
|
111
|
+
assert out == f" {FENCE}python\n\n\nRUNNER\n\n"
|
|
112
|
+
|
|
113
|
+
|
|
92
114
|
def test_a_backtick_fence_cannot_have_backticks_in_its_info():
|
|
93
115
|
page = "``` runnable `x`\ncode\n```\n"
|
|
94
116
|
out, blocks = collect(page)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/src/mkdocs_onlinecompiler/languages.py
RENAMED
|
File without changes
|
{mkdocs_onlinecompiler-0.2.0 → mkdocs_onlinecompiler-0.2.1}/src/mkdocs_onlinecompiler/plugin.py
RENAMED
|
File without changes
|
|
File without changes
|