mkdocs-entangled-plugin 0.2.0__tar.gz → 0.4.0__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_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/PKG-INFO +42 -17
- {mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/README.md +38 -11
- {mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/mkdocs_entangled/on_page_markdown.py +2 -30
- {mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/pyproject.toml +4 -2
- mkdocs_entangled_plugin-0.2.0/mkdocs_entangled/mawk.py +0 -100
- {mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/LICENSE +0 -0
- {mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/mkdocs_entangled/__init__.py +0 -0
- {mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/mkdocs_entangled/config.py +0 -0
- {mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/mkdocs_entangled/plugin.py +0 -0
- {mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/mkdocs_entangled/properties.py +0 -0
- {mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/mkdocs_entangled/py.typed +0 -0
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mkdocs-entangled-plugin
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Plugin for MkDocs helping with rendering Entangled (entangled.github.io) projects.
|
|
5
5
|
License: Apache 2.0
|
|
6
6
|
Author: Johan Hidding
|
|
7
7
|
Author-email: j.hidding@esciencecenter.nl
|
|
8
|
-
Requires-Python: >=3.
|
|
8
|
+
Requires-Python: >=3.11,<4.0
|
|
9
9
|
Classifier: License :: Other/Proprietary License
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
15
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Requires-Dist: entangled-cli (>=2.0.0a6,<3.0.0)
|
|
13
|
+
Requires-Dist: mawk (>=0.1.4,<0.2.0)
|
|
16
14
|
Requires-Dist: mkdocs (>=1.4.2,<2.0.0)
|
|
17
15
|
Description-Content-Type: text/markdown
|
|
18
16
|
|
|
19
17
|
# Welcome to MkDocs Entangled Plugin
|
|
20
18
|
Using this plugin, you can make your Entangled documents look better.
|
|
21
19
|
|
|
20
|
+
## Examples
|
|
21
|
+
Detailed examples are found in the [entangled/mkdocs-examples repository](https://entangled.github.io/mkdocs-examples).
|
|
22
|
+
|
|
22
23
|
## Install
|
|
23
24
|
|
|
24
25
|
Install this with `pip install mkdocs-entangled-plugin`. To use the entangled plugin, add the following lines to your `mkdocs.yml`:
|
|
@@ -33,11 +34,19 @@ markdown_extensions:
|
|
|
33
34
|
alternate_style: true
|
|
34
35
|
```
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
For more information, see [the documentation](https://entangled.github.io/mkdocs-plugin).
|
|
38
|
+
|
|
39
|
+
## Components
|
|
40
|
+
This plugin bundles functionality for literate programming with Entangled.
|
|
41
|
+
|
|
42
|
+
- Annotate code blocks with titles.
|
|
43
|
+
- Build artifacts using Make.
|
|
44
|
+
|
|
45
|
+
### Annotate code blocks
|
|
37
46
|
The default markdown syntax that Entangled supports has fenced code blocks as follows
|
|
38
47
|
|
|
39
48
|
~~~markdown
|
|
40
|
-
``` {.python file=hello_world.py}
|
|
49
|
+
``` {.python file=examples/hello_world.py}
|
|
41
50
|
if __name__ == "__main__":
|
|
42
51
|
<<hello-world>>
|
|
43
52
|
```
|
|
@@ -45,7 +54,7 @@ if __name__ == "__main__":
|
|
|
45
54
|
|
|
46
55
|
Which renders like this:
|
|
47
56
|
|
|
48
|
-
``` {.python file=hello_world.py}
|
|
57
|
+
``` {.python file=examples/hello_world.py}
|
|
49
58
|
if __name__ == "__main__":
|
|
50
59
|
<<hello-world>>
|
|
51
60
|
```
|
|
@@ -61,10 +70,10 @@ print("Hello, World!")
|
|
|
61
70
|
that render like this:
|
|
62
71
|
|
|
63
72
|
``` {.python #hello-world}
|
|
64
|
-
print("Hello,
|
|
73
|
+
print("Hello, Universe!")
|
|
65
74
|
```
|
|
66
75
|
|
|
67
|
-
|
|
76
|
+
### Build Artifacts
|
|
68
77
|
|
|
69
78
|
Build artifacts by specifying a Makefile.
|
|
70
79
|
|
|
@@ -73,14 +82,18 @@ Build artifacts by specifying a Makefile.
|
|
|
73
82
|
|
|
74
83
|

|
|
75
84
|
|
|
76
|
-
=== "
|
|
85
|
+
=== "Source"
|
|
86
|
+
|
|
87
|
+
``` {.gnuplot file=examples/plot.gp}
|
|
88
|
+
# enter your plotting commands here
|
|
89
|
+
```
|
|
77
90
|
|
|
78
91
|
``` {.make .build-artifact}
|
|
79
92
|
.RECIPEPREFIX = >
|
|
80
93
|
|
|
81
|
-
docs/fig/plot.svg:
|
|
94
|
+
docs/fig/plot.svg: examples/plot.gp
|
|
82
95
|
> mkdir -p $(@D)
|
|
83
|
-
> gnuplot
|
|
96
|
+
> gnuplot $^ > $@
|
|
84
97
|
```
|
|
85
98
|
~~~
|
|
86
99
|
|
|
@@ -88,14 +101,26 @@ Build artifacts by specifying a Makefile.
|
|
|
88
101
|
|
|
89
102
|

|
|
90
103
|
|
|
91
|
-
=== "
|
|
104
|
+
=== "Source"
|
|
105
|
+
|
|
106
|
+
``` {.gnuplot file=examples/plot.gp}
|
|
107
|
+
set term svg background rgb 'white' size 700, 500
|
|
108
|
+
sinc(r) = sin(pi*r) / (pi*r)
|
|
109
|
+
set isosamples 50, 50
|
|
110
|
+
set hidden3d
|
|
111
|
+
set xrange [-4:4]
|
|
112
|
+
set yrange [-4:4]
|
|
113
|
+
set xyplane 0
|
|
114
|
+
set title "Sinc function"
|
|
115
|
+
splot sinc(sqrt(x**2 + y**2)) t'' lc rgb '#5533cc'
|
|
116
|
+
```
|
|
92
117
|
|
|
93
118
|
``` {.make .build-artifact}
|
|
94
119
|
.RECIPEPREFIX = >
|
|
95
120
|
|
|
96
|
-
docs/fig/plot.svg:
|
|
121
|
+
docs/fig/plot.svg: examples/plot.gp
|
|
97
122
|
> mkdir -p $(@D)
|
|
98
|
-
> gnuplot
|
|
123
|
+
> gnuplot $^ > $@
|
|
99
124
|
```
|
|
100
125
|
|
|
101
126
|
## License
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Welcome to MkDocs Entangled Plugin
|
|
2
2
|
Using this plugin, you can make your Entangled documents look better.
|
|
3
3
|
|
|
4
|
+
## Examples
|
|
5
|
+
Detailed examples are found in the [entangled/mkdocs-examples repository](https://entangled.github.io/mkdocs-examples).
|
|
6
|
+
|
|
4
7
|
## Install
|
|
5
8
|
|
|
6
9
|
Install this with `pip install mkdocs-entangled-plugin`. To use the entangled plugin, add the following lines to your `mkdocs.yml`:
|
|
@@ -15,11 +18,19 @@ markdown_extensions:
|
|
|
15
18
|
alternate_style: true
|
|
16
19
|
```
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
For more information, see [the documentation](https://entangled.github.io/mkdocs-plugin).
|
|
22
|
+
|
|
23
|
+
## Components
|
|
24
|
+
This plugin bundles functionality for literate programming with Entangled.
|
|
25
|
+
|
|
26
|
+
- Annotate code blocks with titles.
|
|
27
|
+
- Build artifacts using Make.
|
|
28
|
+
|
|
29
|
+
### Annotate code blocks
|
|
19
30
|
The default markdown syntax that Entangled supports has fenced code blocks as follows
|
|
20
31
|
|
|
21
32
|
~~~markdown
|
|
22
|
-
``` {.python file=hello_world.py}
|
|
33
|
+
``` {.python file=examples/hello_world.py}
|
|
23
34
|
if __name__ == "__main__":
|
|
24
35
|
<<hello-world>>
|
|
25
36
|
```
|
|
@@ -27,7 +38,7 @@ if __name__ == "__main__":
|
|
|
27
38
|
|
|
28
39
|
Which renders like this:
|
|
29
40
|
|
|
30
|
-
``` {.python file=hello_world.py}
|
|
41
|
+
``` {.python file=examples/hello_world.py}
|
|
31
42
|
if __name__ == "__main__":
|
|
32
43
|
<<hello-world>>
|
|
33
44
|
```
|
|
@@ -43,10 +54,10 @@ print("Hello, World!")
|
|
|
43
54
|
that render like this:
|
|
44
55
|
|
|
45
56
|
``` {.python #hello-world}
|
|
46
|
-
print("Hello,
|
|
57
|
+
print("Hello, Universe!")
|
|
47
58
|
```
|
|
48
59
|
|
|
49
|
-
|
|
60
|
+
### Build Artifacts
|
|
50
61
|
|
|
51
62
|
Build artifacts by specifying a Makefile.
|
|
52
63
|
|
|
@@ -55,14 +66,18 @@ Build artifacts by specifying a Makefile.
|
|
|
55
66
|
|
|
56
67
|

|
|
57
68
|
|
|
58
|
-
=== "
|
|
69
|
+
=== "Source"
|
|
70
|
+
|
|
71
|
+
``` {.gnuplot file=examples/plot.gp}
|
|
72
|
+
# enter your plotting commands here
|
|
73
|
+
```
|
|
59
74
|
|
|
60
75
|
``` {.make .build-artifact}
|
|
61
76
|
.RECIPEPREFIX = >
|
|
62
77
|
|
|
63
|
-
docs/fig/plot.svg:
|
|
78
|
+
docs/fig/plot.svg: examples/plot.gp
|
|
64
79
|
> mkdir -p $(@D)
|
|
65
|
-
> gnuplot
|
|
80
|
+
> gnuplot $^ > $@
|
|
66
81
|
```
|
|
67
82
|
~~~
|
|
68
83
|
|
|
@@ -70,14 +85,26 @@ Build artifacts by specifying a Makefile.
|
|
|
70
85
|
|
|
71
86
|

|
|
72
87
|
|
|
73
|
-
=== "
|
|
88
|
+
=== "Source"
|
|
89
|
+
|
|
90
|
+
``` {.gnuplot file=examples/plot.gp}
|
|
91
|
+
set term svg background rgb 'white' size 700, 500
|
|
92
|
+
sinc(r) = sin(pi*r) / (pi*r)
|
|
93
|
+
set isosamples 50, 50
|
|
94
|
+
set hidden3d
|
|
95
|
+
set xrange [-4:4]
|
|
96
|
+
set yrange [-4:4]
|
|
97
|
+
set xyplane 0
|
|
98
|
+
set title "Sinc function"
|
|
99
|
+
splot sinc(sqrt(x**2 + y**2)) t'' lc rgb '#5533cc'
|
|
100
|
+
```
|
|
74
101
|
|
|
75
102
|
``` {.make .build-artifact}
|
|
76
103
|
.RECIPEPREFIX = >
|
|
77
104
|
|
|
78
|
-
docs/fig/plot.svg:
|
|
105
|
+
docs/fig/plot.svg: examples/plot.gp
|
|
79
106
|
> mkdir -p $(@D)
|
|
80
|
-
> gnuplot
|
|
107
|
+
> gnuplot $^ > $@
|
|
81
108
|
```
|
|
82
109
|
|
|
83
110
|
## License
|
{mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/mkdocs_entangled/on_page_markdown.py
RENAMED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
from dataclasses import dataclass
|
|
3
|
-
from pathlib import Path
|
|
4
3
|
import re
|
|
5
|
-
import tempfile
|
|
6
|
-
import subprocess
|
|
7
|
-
import sys
|
|
8
4
|
|
|
9
5
|
from mkdocs.config.defaults import MkDocsConfig
|
|
10
6
|
from mkdocs.structure.pages import Page
|
|
11
7
|
from mkdocs.structure.files import Files
|
|
12
8
|
|
|
13
|
-
from .
|
|
14
|
-
|
|
15
|
-
from . import mawk
|
|
9
|
+
from .properties import read_properties, Id, Attribute
|
|
10
|
+
import mawk
|
|
16
11
|
|
|
17
12
|
|
|
18
13
|
@dataclass
|
|
19
14
|
class EntangledFilter(mawk.RuleSet):
|
|
20
15
|
add_title: bool = True
|
|
21
|
-
build_artifacts: bool = True
|
|
22
|
-
|
|
23
|
-
_collect_make_script: bool = False
|
|
24
16
|
_ignore: bool = False
|
|
25
17
|
|
|
26
18
|
@mawk.on_match(r"~~~markdown")
|
|
@@ -58,31 +50,11 @@ class EntangledFilter(mawk.RuleSet):
|
|
|
58
50
|
if title is not None:
|
|
59
51
|
props.append(Attribute("title", title))
|
|
60
52
|
|
|
61
|
-
if self.build_artifacts and Class("build-artifact") in props:
|
|
62
|
-
self._collect_make_script = True
|
|
63
|
-
self._make_script: list[str] = []
|
|
64
|
-
self._make_props = props
|
|
65
|
-
self._indent = indent
|
|
66
|
-
|
|
67
53
|
prop_str = " ".join(str(p) for p in props)
|
|
68
54
|
return [f"{indent}``` {{{prop_str}}}"]
|
|
69
55
|
|
|
70
56
|
@mawk.on_match(r"\s*```\s*$")
|
|
71
57
|
def close_code_block(self, m: re.Match) -> Optional[list[str]]:
|
|
72
|
-
if not self._ignore and self._collect_make_script:
|
|
73
|
-
self._collect_make_script = False
|
|
74
|
-
script = "\n".join(self._make_script)
|
|
75
|
-
with tempfile.TemporaryDirectory() as _tmpdir:
|
|
76
|
-
tmpdir = Path(_tmpdir)
|
|
77
|
-
with open(tmpdir / "Makefile", "w") as makefile:
|
|
78
|
-
makefile.write(script)
|
|
79
|
-
subprocess.run(["make", "-f", str(tmpdir / "Makefile")])
|
|
80
|
-
return None
|
|
81
|
-
|
|
82
|
-
@mawk.always
|
|
83
|
-
def add_line_to_script(self, line: str) -> Optional[list[str]]:
|
|
84
|
-
if not self._ignore and self._collect_make_script:
|
|
85
|
-
self._make_script.append(line.removeprefix(self._indent))
|
|
86
58
|
return None
|
|
87
59
|
|
|
88
60
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "mkdocs-entangled-plugin"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.4.0"
|
|
4
4
|
description = "Plugin for MkDocs helping with rendering Entangled (entangled.github.io) projects."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = ["Johan Hidding <j.hidding@esciencecenter.nl>"]
|
|
@@ -13,8 +13,10 @@ packages = [
|
|
|
13
13
|
entangled = "mkdocs_entangled:EntangledPlugin"
|
|
14
14
|
|
|
15
15
|
[tool.poetry.dependencies]
|
|
16
|
-
python = "
|
|
16
|
+
python = "^3.11"
|
|
17
17
|
mkdocs = "^1.4.2"
|
|
18
|
+
entangled-cli = "^2.0.0a6"
|
|
19
|
+
mawk = "^0.1.4"
|
|
18
20
|
|
|
19
21
|
[tool.poetry.dev-dependencies]
|
|
20
22
|
mypy = "^1.2.0"
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
μAwk, a tiny awk-like interface in Python
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from typing import Callable, Optional
|
|
6
|
-
from functools import wraps, partial
|
|
7
|
-
import re
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"""Global counter to sort filters by the order in which they appear
|
|
11
|
-
in a class."""
|
|
12
|
-
_filter_creation_order = 0
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def match_filter(expr: str, handler: Callable[[re.Match], Optional[list[str]]], inp: str) -> Optional[list[str]]:
|
|
16
|
-
if m := re.match(expr, inp):
|
|
17
|
-
return handler(m)
|
|
18
|
-
return None
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def on_match(expr: str):
|
|
22
|
-
"""Decorator for doing search-and-replace based on a given regex.
|
|
23
|
-
|
|
24
|
-
The inner function should take as argument a `re.Match` object
|
|
25
|
-
and return a list of strings. The resulting decorated function
|
|
26
|
-
then becomes a function from string to list of strings.
|
|
27
|
-
|
|
28
|
-
If the input doesn't match the given regex, the original string
|
|
29
|
-
is returned.
|
|
30
|
-
|
|
31
|
-
The inner function may still decide to do nothing by returning None.
|
|
32
|
-
|
|
33
|
-
To erase the matched input return the empty list.
|
|
34
|
-
|
|
35
|
-
This decorator also works on class methods. It is then assumed that
|
|
36
|
-
the method has signature `(self, m: re.Match)`.
|
|
37
|
-
"""
|
|
38
|
-
def _decorator(f):
|
|
39
|
-
global _filter_creation_order
|
|
40
|
-
method = len(f.__qualname__.split('.')) > 1
|
|
41
|
-
if method:
|
|
42
|
-
@wraps(f)
|
|
43
|
-
def _impl(self, inp):
|
|
44
|
-
return match_filter(expr, partial(f, self), inp)
|
|
45
|
-
_impl._is_rule = _filter_creation_order # add tag to method
|
|
46
|
-
_filter_creation_order += 1
|
|
47
|
-
return _impl
|
|
48
|
-
else:
|
|
49
|
-
return wraps(f)(partial(match_filter, expr, f))
|
|
50
|
-
return _decorator
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def always(f):
|
|
54
|
-
"""Suppose you have a rule with `@on_match(r".*")`, then it is better
|
|
55
|
-
not to run the regex machinery at all and just pass on the string.
|
|
56
|
-
In that case it is better to use `@always`."""
|
|
57
|
-
global _filter_creation_order
|
|
58
|
-
method = len(f.__qualname__.split('.')) > 1
|
|
59
|
-
if method:
|
|
60
|
-
f._is_rule = _filter_creation_order # add tag to method
|
|
61
|
-
_filter_creation_order += 1
|
|
62
|
-
return f
|
|
63
|
-
else:
|
|
64
|
-
return f
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
Rule = Callable[[str], list[str]]
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def run(rules: list[Rule], inp: str, exclusive=True) -> str:
|
|
71
|
-
"""Takes a list of rules, being function from `str` to `list[str]`.
|
|
72
|
-
The input string is split into lines, after which each line is fed
|
|
73
|
-
through the list of rules. All the results are colected into a list
|
|
74
|
-
of strings and then joined by newline.
|
|
75
|
-
"""
|
|
76
|
-
lines = inp.splitlines()
|
|
77
|
-
result = []
|
|
78
|
-
for l in lines:
|
|
79
|
-
for r in rules:
|
|
80
|
-
v = r(l)
|
|
81
|
-
if v is not None:
|
|
82
|
-
result.extend(v)
|
|
83
|
-
if exclusive:
|
|
84
|
-
break
|
|
85
|
-
else:
|
|
86
|
-
result.append(l)
|
|
87
|
-
return "\n".join(result)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
class RuleSet:
|
|
91
|
-
"""To be used as a base class for classes that contain `on_match`
|
|
92
|
-
decorated methods."""
|
|
93
|
-
def list_rules(self):
|
|
94
|
-
members = (getattr(self, m) for m in dir(self) if m[0] != '_')
|
|
95
|
-
rules = [m for m in members if hasattr(m, '_is_rule')]
|
|
96
|
-
return sorted(rules, key=lambda r: r._is_rule)
|
|
97
|
-
|
|
98
|
-
def run(self, inp: str, exclusive=True) -> str:
|
|
99
|
-
"""Runs all rules in the class on input."""
|
|
100
|
-
return run(self.list_rules(), inp, exclusive)
|
|
File without changes
|
{mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/mkdocs_entangled/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{mkdocs_entangled_plugin-0.2.0 → mkdocs_entangled_plugin-0.4.0}/mkdocs_entangled/properties.py
RENAMED
|
File without changes
|
|
File without changes
|