nbsync 0.3.4__tar.gz → 0.3.6__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.
- {nbsync-0.3.4 → nbsync-0.3.6}/PKG-INFO +2 -2
- {nbsync-0.3.4 → nbsync-0.3.6}/pyproject.toml +2 -2
- {nbsync-0.3.4 → nbsync-0.3.6}/src/nbsync/cell.py +19 -8
- {nbsync-0.3.4 → nbsync-0.3.6}/src/nbsync/markdown.py +2 -2
- {nbsync-0.3.4 → nbsync-0.3.6}/tests/test_cell.py +45 -1
- {nbsync-0.3.4 → nbsync-0.3.6}/.devcontainer/devcontainer.json +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/.devcontainer/postCreate.sh +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/.devcontainer/starship.toml +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/.gitattributes +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/.github/workflows/ci.yaml +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/.github/workflows/docs.yaml +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/.github/workflows/publish.yaml +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/.gitignore +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/LICENSE +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/README.md +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/docs/index.md +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/mkdocs.yaml +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/src/nbsync/__init__.py +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/src/nbsync/logger.py +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/src/nbsync/notebook.py +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/src/nbsync/py.typed +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/src/nbsync/sync.py +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/tests/__init__.py +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/tests/conftest.py +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/tests/test_logger.py +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/tests/test_markdown.py +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/tests/test_notebook.py +0 -0
- {nbsync-0.3.4 → nbsync-0.3.6}/tests/test_sync.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nbsync
|
3
|
-
Version: 0.3.
|
3
|
+
Version: 0.3.6
|
4
4
|
Summary: A core library to synchronize Jupyter notebooks and Markdown documents, enabling seamless integration and dynamic content execution
|
5
5
|
Project-URL: Documentation, https://daizutabi.github.io/nbsync/
|
6
6
|
Project-URL: Source, https://github.com/daizutabi/nbsync
|
@@ -39,7 +39,7 @@ Classifier: Topic :: Documentation
|
|
39
39
|
Classifier: Topic :: Software Development :: Documentation
|
40
40
|
Classifier: Topic :: Text Processing :: Markup :: Markdown
|
41
41
|
Requires-Python: >=3.10
|
42
|
-
Requires-Dist: nbstore>=0.
|
42
|
+
Requires-Dist: nbstore>=0.5.2
|
43
43
|
Description-Content-Type: text/markdown
|
44
44
|
|
45
45
|
# nbsync
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "nbsync"
|
7
|
-
version = "0.3.
|
7
|
+
version = "0.3.6"
|
8
8
|
description = "A core library to synchronize Jupyter notebooks and Markdown documents, enabling seamless integration and dynamic content execution"
|
9
9
|
readme = "README.md"
|
10
10
|
license = { file = "LICENSE" }
|
@@ -31,7 +31,7 @@ classifiers = [
|
|
31
31
|
"Topic :: Text Processing :: Markup :: Markdown",
|
32
32
|
]
|
33
33
|
requires-python = ">=3.10"
|
34
|
-
dependencies = ["nbstore>=0.
|
34
|
+
dependencies = ["nbstore>=0.5.2"]
|
35
35
|
|
36
36
|
[project.urls]
|
37
37
|
Documentation = "https://daizutabi.github.io/nbsync/"
|
@@ -50,10 +50,8 @@ class Cell:
|
|
50
50
|
include_attrs=True,
|
51
51
|
include_identifier=bool(identifier),
|
52
52
|
)
|
53
|
-
|
54
|
-
result =
|
55
|
-
if escape and self.mime == "text/plain":
|
56
|
-
result = html.escape(result)
|
53
|
+
self.image.url = ""
|
54
|
+
result = get_text_markdown(self, escape=escape)
|
57
55
|
|
58
56
|
else:
|
59
57
|
source = get_source(
|
@@ -61,7 +59,7 @@ class Cell:
|
|
61
59
|
include_attrs=False,
|
62
60
|
include_identifier=bool(identifier),
|
63
61
|
)
|
64
|
-
result =
|
62
|
+
result = get_image_markdown(self)
|
65
63
|
|
66
64
|
if markdown := get_markdown(kind, source, result, tabs):
|
67
65
|
return textwrap.indent(markdown, self.image.indent)
|
@@ -77,7 +75,8 @@ def get_source(
|
|
77
75
|
) -> str:
|
78
76
|
attrs = [cell.language]
|
79
77
|
if include_attrs:
|
80
|
-
|
78
|
+
parts = cell.image.iter_parts(exclude_attributes=["result"])
|
79
|
+
attrs.extend(parts)
|
81
80
|
attr = " ".join(attrs)
|
82
81
|
|
83
82
|
source = cell.image.source
|
@@ -87,7 +86,19 @@ def get_source(
|
|
87
86
|
return f"```{attr}\n{source}\n```"
|
88
87
|
|
89
88
|
|
90
|
-
def
|
89
|
+
def get_text_markdown(cell: Cell, *, escape: bool = False) -> str:
|
90
|
+
text = str(cell.content.rstrip())
|
91
|
+
|
92
|
+
if lang := cell.image.attributes.get("result", ""):
|
93
|
+
return f"```{lang}\n{text}\n```"
|
94
|
+
|
95
|
+
if escape and cell.mime == "text/plain":
|
96
|
+
return html.escape(text)
|
97
|
+
|
98
|
+
return text
|
99
|
+
|
100
|
+
|
101
|
+
def get_image_markdown(cell: Cell) -> str:
|
91
102
|
msg = f"{cell.image.url}#{cell.image.identifier} [{cell.mime}]"
|
92
103
|
logger.debug(f"Converting image: {msg}")
|
93
104
|
|
@@ -115,7 +126,7 @@ def get_markdown(kind: str, source: str, result: str, tabs: str) -> str:
|
|
115
126
|
return f"{result}\n\n{source}"
|
116
127
|
|
117
128
|
if kind == "material-block":
|
118
|
-
result = f'<div class="result" markdown="1"
|
129
|
+
result = f'<div class="result" markdown="1">\n{result}\n</div>'
|
119
130
|
return f"{source}\n\n{result}"
|
120
131
|
|
121
132
|
if kind == "tabbed-left":
|
@@ -15,7 +15,7 @@ Element: TypeAlias = str | CodeBlock | Image
|
|
15
15
|
def convert_code_block(code_block: CodeBlock) -> Iterator[Element]:
|
16
16
|
for elem in _convert_code_block_tabbed(code_block):
|
17
17
|
if isinstance(elem, CodeBlock):
|
18
|
-
yield
|
18
|
+
yield _convert_code_block_attrs(elem)
|
19
19
|
else:
|
20
20
|
yield elem
|
21
21
|
|
@@ -35,7 +35,7 @@ def _convert_code_block_tabbed(code_block: CodeBlock) -> Iterator[Element]:
|
|
35
35
|
yield from nbstore.markdown.parse(text)
|
36
36
|
|
37
37
|
|
38
|
-
def
|
38
|
+
def _convert_code_block_attrs(code_block: CodeBlock) -> CodeBlock | Image:
|
39
39
|
exec_ = code_block.attributes.get("exec", None)
|
40
40
|
if exec_ != "1" or not code_block.classes:
|
41
41
|
return code_block
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import textwrap
|
2
|
+
|
1
3
|
import nbformat
|
2
4
|
import nbstore.notebook
|
3
5
|
import pytest
|
@@ -77,7 +79,7 @@ def test_below(convert):
|
|
77
79
|
|
78
80
|
def test_material_block(convert):
|
79
81
|
x = convert("{#fig source='material-block' a b=c}")
|
80
|
-
assert '<div class="result" markdown="1"
|
82
|
+
assert '<div class="result" markdown="1">\n![a]' in x
|
81
83
|
|
82
84
|
|
83
85
|
def test_tabbed_left(convert):
|
@@ -116,3 +118,45 @@ def test_code_block_exec_escape_print(convert):
|
|
116
118
|
def test_code_block_exec_escape_stream(convert):
|
117
119
|
x = convert('```python exec="1" source="1"\n"<1>"\n```')
|
118
120
|
assert x == '```python\n"<1>"\n```\n\n'<1>''
|
121
|
+
|
122
|
+
|
123
|
+
def test_code_block_exec_result(convert):
|
124
|
+
x = convert('```python exec="1" result="text"\nprint(1+1)\nprint("<1>")\n```')
|
125
|
+
assert x == "```text\n2\n<1>\n```"
|
126
|
+
|
127
|
+
|
128
|
+
def test_code_block_exec_result_source(convert):
|
129
|
+
t = '```python exec="1" source="material-block" result="text"\n'
|
130
|
+
t += 'print(1+1)\nprint("<1>")\n```'
|
131
|
+
x = convert(t)
|
132
|
+
y = textwrap.dedent("""\
|
133
|
+
```python
|
134
|
+
print(1+1)
|
135
|
+
print("<1>")
|
136
|
+
```
|
137
|
+
|
138
|
+
<div class="result" markdown="1">
|
139
|
+
```text
|
140
|
+
2
|
141
|
+
<1>
|
142
|
+
```
|
143
|
+
</div>""")
|
144
|
+
assert x == y
|
145
|
+
|
146
|
+
|
147
|
+
def test_code_block_html(convert):
|
148
|
+
src = textwrap.dedent("""\
|
149
|
+
from IPython.display import HTML
|
150
|
+
HTML("<div>a</div>")
|
151
|
+
""")
|
152
|
+
x = convert(f'```python exec="1"\n{src}```')
|
153
|
+
assert x == "<div>a</div>"
|
154
|
+
|
155
|
+
|
156
|
+
def test_code_block_html_result(convert):
|
157
|
+
src = textwrap.dedent("""\
|
158
|
+
from IPython.display import HTML
|
159
|
+
HTML("<div>a</div>")
|
160
|
+
""")
|
161
|
+
x = convert(f'```python exec="1" result="html"\n{src}```')
|
162
|
+
assert x == "```html\n<div>a</div>\n```"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|