nbsync 0.1.2__py3-none-any.whl → 0.1.4__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.
- nbsync/markdown.py +43 -18
- nbsync/sync.py +22 -8
- {nbsync-0.1.2.dist-info → nbsync-0.1.4.dist-info}/METADATA +1 -1
- {nbsync-0.1.2.dist-info → nbsync-0.1.4.dist-info}/RECORD +7 -7
- {nbsync-0.1.2.dist-info → nbsync-0.1.4.dist-info}/WHEEL +0 -0
- {nbsync-0.1.2.dist-info → nbsync-0.1.4.dist-info}/entry_points.txt +0 -0
- {nbsync-0.1.2.dist-info → nbsync-0.1.4.dist-info}/licenses/LICENSE +0 -0
nbsync/markdown.py
CHANGED
@@ -12,6 +12,49 @@ if TYPE_CHECKING:
|
|
12
12
|
Element: TypeAlias = str | CodeBlock | Image
|
13
13
|
|
14
14
|
|
15
|
+
def convert_code_block(code_block: CodeBlock) -> Iterator[Element]:
|
16
|
+
for elem in _convert_code_block_tabbed(code_block):
|
17
|
+
if isinstance(elem, CodeBlock):
|
18
|
+
yield _convert_code_block_exec(elem)
|
19
|
+
else:
|
20
|
+
yield elem
|
21
|
+
|
22
|
+
|
23
|
+
def _convert_code_block_tabbed(code_block: CodeBlock) -> Iterator[Element]:
|
24
|
+
source = code_block.attributes.get("source", None)
|
25
|
+
if source != "tabbed-nbsync":
|
26
|
+
yield code_block
|
27
|
+
return
|
28
|
+
|
29
|
+
markdown = code_block.text.replace('source="tabbed-nbsync"', "")
|
30
|
+
markdown = textwrap.indent(markdown, " ")
|
31
|
+
yield f'===! "Markdown"\n\n{markdown}\n\n'
|
32
|
+
|
33
|
+
text = textwrap.indent(code_block.source, " ")
|
34
|
+
text = f'=== "Rendered"\n\n{text}'
|
35
|
+
yield from nbstore.markdown.parse(text)
|
36
|
+
|
37
|
+
|
38
|
+
def _convert_code_block_exec(code_block: CodeBlock) -> CodeBlock | Image:
|
39
|
+
exec_ = code_block.attributes.get("exec", None)
|
40
|
+
if exec_ != "1" or not code_block.classes:
|
41
|
+
return code_block
|
42
|
+
|
43
|
+
if code_block.classes[0] != "python":
|
44
|
+
return code_block
|
45
|
+
|
46
|
+
del code_block.attributes["exec"]
|
47
|
+
return Image(
|
48
|
+
code_block.indent,
|
49
|
+
"",
|
50
|
+
code_block.classes[1:],
|
51
|
+
code_block.attributes,
|
52
|
+
code_block.source,
|
53
|
+
url=".md",
|
54
|
+
indent=code_block.indent,
|
55
|
+
)
|
56
|
+
|
57
|
+
|
15
58
|
def convert_image(image: Image, index: int | None = None) -> Iterator[Element]:
|
16
59
|
if image.source:
|
17
60
|
if not image.identifier and index is None:
|
@@ -29,24 +72,6 @@ def convert_image(image: Image, index: int | None = None) -> Iterator[Element]:
|
|
29
72
|
yield image.text
|
30
73
|
|
31
74
|
|
32
|
-
def convert_code_block(code_block: CodeBlock) -> Iterator[Element]:
|
33
|
-
source = code_block.attributes.get("source", None)
|
34
|
-
if source == "tabbed-nbsync":
|
35
|
-
yield from _convert_code_block_tabbed(code_block)
|
36
|
-
else:
|
37
|
-
yield code_block
|
38
|
-
|
39
|
-
|
40
|
-
def _convert_code_block_tabbed(code_block: CodeBlock) -> Iterator[Element]:
|
41
|
-
markdown = code_block.text.replace('source="tabbed-nbsync"', "")
|
42
|
-
markdown = textwrap.indent(markdown, " ")
|
43
|
-
yield f'===! "Markdown"\n\n{markdown}\n\n'
|
44
|
-
|
45
|
-
text = textwrap.indent(code_block.source, " ")
|
46
|
-
text = f'=== "Rendered"\n\n{text}'
|
47
|
-
yield from nbstore.markdown.parse(text)
|
48
|
-
|
49
|
-
|
50
75
|
SUPPORTED_EXTENSIONS = (".ipynb", ".md", ".py")
|
51
76
|
|
52
77
|
|
nbsync/sync.py
CHANGED
@@ -35,7 +35,7 @@ class Synchronizer:
|
|
35
35
|
yield elem
|
36
36
|
|
37
37
|
if isinstance(elem, Image | CodeBlock):
|
38
|
-
update_notebooks(
|
38
|
+
update_notebooks(elem, notebooks, self.store)
|
39
39
|
|
40
40
|
for url, notebook in notebooks.items():
|
41
41
|
if url not in self.notebooks or not self.notebooks[url].equals(notebook):
|
@@ -58,17 +58,13 @@ class Synchronizer:
|
|
58
58
|
if isinstance(elem, str):
|
59
59
|
yield elem
|
60
60
|
|
61
|
-
elif
|
62
|
-
|
63
|
-
nb = self.notebooks[elem.url].nb
|
64
|
-
yield convert_image(elem, nb)
|
65
|
-
else:
|
66
|
-
yield convert_code_block(elem)
|
61
|
+
elif cell := convert(elem, self.notebooks):
|
62
|
+
yield cell
|
67
63
|
|
68
64
|
|
69
65
|
def update_notebooks(
|
70
|
-
notebooks: dict[str, Notebook],
|
71
66
|
elem: Image | CodeBlock,
|
67
|
+
notebooks: dict[str, Notebook],
|
72
68
|
store: Store,
|
73
69
|
) -> None:
|
74
70
|
url = elem.url
|
@@ -93,6 +89,24 @@ def update_notebooks(
|
|
93
89
|
notebook.add_cell(elem.identifier, source)
|
94
90
|
|
95
91
|
|
92
|
+
def convert(
|
93
|
+
elem: Image | CodeBlock,
|
94
|
+
notebooks: dict[str, Notebook],
|
95
|
+
) -> str | Cell:
|
96
|
+
if elem.identifier not in [".", "_"]:
|
97
|
+
if isinstance(elem, Image):
|
98
|
+
if elem.url not in notebooks:
|
99
|
+
logger.warning(f"Notebook not found: {elem.url}")
|
100
|
+
return ""
|
101
|
+
|
102
|
+
nb = notebooks[elem.url].nb
|
103
|
+
return convert_image(elem, nb)
|
104
|
+
|
105
|
+
return convert_code_block(elem)
|
106
|
+
|
107
|
+
return ""
|
108
|
+
|
109
|
+
|
96
110
|
def convert_image(image: Image, nb: NotebookNode) -> Cell:
|
97
111
|
try:
|
98
112
|
image.source = get_source(nb, image.identifier)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nbsync
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: MkDocs plugin treating Jupyter notebooks, Python scripts and Markdown files as first-class citizens for documentation with dynamic execution and real-time synchronization
|
5
5
|
Project-URL: Documentation, https://daizutabi.github.io/nbsync/
|
6
6
|
Project-URL: Source, https://github.com/daizutabi/nbsync
|
@@ -1,13 +1,13 @@
|
|
1
1
|
nbsync/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
2
|
nbsync/cell.py,sha256=HNgMDwA1KrMxyoxAL2wUrg3zdA1glveoXY5YbO_uFeM,3788
|
3
3
|
nbsync/logger.py,sha256=tQK8Z8HdWQNhVohQYLwZtJhdaj2w0UTyhHQak3mPqNc,119
|
4
|
-
nbsync/markdown.py,sha256=
|
4
|
+
nbsync/markdown.py,sha256=xcPhQKWpFDyVQ_xtZCpFrnR0QED_hYs4PAyaT7dF3t4,3830
|
5
5
|
nbsync/notebook.py,sha256=Voh-e8RQsoYmWKnaHzAn4bm6Ud5v-aHwmng2Uc0rUts,1009
|
6
6
|
nbsync/plugin.py,sha256=YywBAD7fcrPg3-_9T_kSuvD8RBzsc_ovlIviGlKR9po,2835
|
7
7
|
nbsync/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
-
nbsync/sync.py,sha256=
|
9
|
-
nbsync-0.1.
|
10
|
-
nbsync-0.1.
|
11
|
-
nbsync-0.1.
|
12
|
-
nbsync-0.1.
|
13
|
-
nbsync-0.1.
|
8
|
+
nbsync/sync.py,sha256=M21moADW2dgvQB46ahbcd2aXOHHqwx9CwfjNO7GR2mQ,3835
|
9
|
+
nbsync-0.1.4.dist-info/METADATA,sha256=EzIqH3hnebqKZ0N1pFzGuE0zL-LNzyVYUyDKBNaRmRQ,6287
|
10
|
+
nbsync-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
11
|
+
nbsync-0.1.4.dist-info/entry_points.txt,sha256=bSqmJTDmrUoSm4yDjk8YDWxI71SShx16judadGdiKbA,47
|
12
|
+
nbsync-0.1.4.dist-info/licenses/LICENSE,sha256=wy1pqn52upuo_qYwY-epWmspwE-3UWJso0xodciGXYc,1062
|
13
|
+
nbsync-0.1.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|