nbsync 0.3.4__tar.gz → 0.3.5__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.
Files changed (28) hide show
  1. {nbsync-0.3.4 → nbsync-0.3.5}/PKG-INFO +1 -1
  2. {nbsync-0.3.4 → nbsync-0.3.5}/pyproject.toml +1 -1
  3. {nbsync-0.3.4 → nbsync-0.3.5}/src/nbsync/cell.py +16 -6
  4. {nbsync-0.3.4 → nbsync-0.3.5}/tests/test_cell.py +25 -0
  5. {nbsync-0.3.4 → nbsync-0.3.5}/.devcontainer/devcontainer.json +0 -0
  6. {nbsync-0.3.4 → nbsync-0.3.5}/.devcontainer/postCreate.sh +0 -0
  7. {nbsync-0.3.4 → nbsync-0.3.5}/.devcontainer/starship.toml +0 -0
  8. {nbsync-0.3.4 → nbsync-0.3.5}/.gitattributes +0 -0
  9. {nbsync-0.3.4 → nbsync-0.3.5}/.github/workflows/ci.yaml +0 -0
  10. {nbsync-0.3.4 → nbsync-0.3.5}/.github/workflows/docs.yaml +0 -0
  11. {nbsync-0.3.4 → nbsync-0.3.5}/.github/workflows/publish.yaml +0 -0
  12. {nbsync-0.3.4 → nbsync-0.3.5}/.gitignore +0 -0
  13. {nbsync-0.3.4 → nbsync-0.3.5}/LICENSE +0 -0
  14. {nbsync-0.3.4 → nbsync-0.3.5}/README.md +0 -0
  15. {nbsync-0.3.4 → nbsync-0.3.5}/docs/index.md +0 -0
  16. {nbsync-0.3.4 → nbsync-0.3.5}/mkdocs.yaml +0 -0
  17. {nbsync-0.3.4 → nbsync-0.3.5}/src/nbsync/__init__.py +0 -0
  18. {nbsync-0.3.4 → nbsync-0.3.5}/src/nbsync/logger.py +0 -0
  19. {nbsync-0.3.4 → nbsync-0.3.5}/src/nbsync/markdown.py +0 -0
  20. {nbsync-0.3.4 → nbsync-0.3.5}/src/nbsync/notebook.py +0 -0
  21. {nbsync-0.3.4 → nbsync-0.3.5}/src/nbsync/py.typed +0 -0
  22. {nbsync-0.3.4 → nbsync-0.3.5}/src/nbsync/sync.py +0 -0
  23. {nbsync-0.3.4 → nbsync-0.3.5}/tests/__init__.py +0 -0
  24. {nbsync-0.3.4 → nbsync-0.3.5}/tests/conftest.py +0 -0
  25. {nbsync-0.3.4 → nbsync-0.3.5}/tests/test_logger.py +0 -0
  26. {nbsync-0.3.4 → nbsync-0.3.5}/tests/test_markdown.py +0 -0
  27. {nbsync-0.3.4 → nbsync-0.3.5}/tests/test_notebook.py +0 -0
  28. {nbsync-0.3.4 → nbsync-0.3.5}/tests/test_sync.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nbsync
3
- Version: 0.3.4
3
+ Version: 0.3.5
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
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nbsync"
7
- version = "0.3.4"
7
+ version = "0.3.5"
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" }
@@ -50,10 +50,8 @@ class Cell:
50
50
  include_attrs=True,
51
51
  include_identifier=bool(identifier),
52
52
  )
53
- result, self.image.url = self.content, ""
54
- result = result.rstrip()
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 = get_result(self)
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)
@@ -87,7 +85,19 @@ def get_source(
87
85
  return f"```{attr}\n{source}\n```"
88
86
 
89
87
 
90
- def get_result(cell: Cell) -> str:
88
+ def get_text_markdown(cell: Cell, *, escape: bool = False) -> str:
89
+ text = str(cell.content.rstrip())
90
+
91
+ if lang := cell.image.attributes.get("result", ""):
92
+ return f"```{lang}\n{text}\n```"
93
+
94
+ if escape and cell.mime == "text/plain":
95
+ return html.escape(text)
96
+
97
+ return text
98
+
99
+
100
+ def get_image_markdown(cell: Cell) -> str:
91
101
  msg = f"{cell.image.url}#{cell.image.identifier} [{cell.mime}]"
92
102
  logger.debug(f"Converting image: {msg}")
93
103
 
@@ -1,3 +1,5 @@
1
+ import textwrap
2
+
1
3
  import nbformat
2
4
  import nbstore.notebook
3
5
  import pytest
@@ -116,3 +118,26 @@ 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&#x27;&lt;1&gt;&#x27;'
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_html(convert):
129
+ src = textwrap.dedent("""\
130
+ from IPython.display import HTML
131
+ HTML("<div>a</div>")
132
+ """)
133
+ x = convert(f'```python exec="1"\n{src}```')
134
+ assert x == "<div>a</div>"
135
+
136
+
137
+ def test_code_block_html_result(convert):
138
+ src = textwrap.dedent("""\
139
+ from IPython.display import HTML
140
+ HTML("<div>a</div>")
141
+ """)
142
+ x = convert(f'```python exec="1" result="html"\n{src}```')
143
+ 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