nbsync 0.3.3__py3-none-any.whl → 0.3.5__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/cell.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import html
3
4
  import textwrap
4
5
  import uuid
5
6
  from dataclasses import dataclass
@@ -26,7 +27,7 @@ class Cell:
26
27
  content: bytes | str
27
28
  """The content of the image."""
28
29
 
29
- def convert(self) -> str:
30
+ def convert(self, *, escape: bool = False) -> str:
30
31
  kind = self.image.attributes.pop("source", "")
31
32
  tabs = self.image.attributes.pop("tabs", "")
32
33
  identifier = self.image.attributes.pop("identifier", "")
@@ -49,8 +50,8 @@ class Cell:
49
50
  include_attrs=True,
50
51
  include_identifier=bool(identifier),
51
52
  )
52
- result, self.image.url = self.content, ""
53
- result = result.rstrip()
53
+ self.image.url = ""
54
+ result = get_text_markdown(self, escape=escape)
54
55
 
55
56
  else:
56
57
  source = get_source(
@@ -58,7 +59,7 @@ class Cell:
58
59
  include_attrs=False,
59
60
  include_identifier=bool(identifier),
60
61
  )
61
- result = get_result(self)
62
+ result = get_image_markdown(self)
62
63
 
63
64
  if markdown := get_markdown(kind, source, result, tabs):
64
65
  return textwrap.indent(markdown, self.image.indent)
@@ -84,7 +85,19 @@ def get_source(
84
85
  return f"```{attr}\n{source}\n```"
85
86
 
86
87
 
87
- 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:
88
101
  msg = f"{cell.image.url}#{cell.image.identifier} [{cell.mime}]"
89
102
  logger.debug(f"Converting image: {msg}")
90
103
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nbsync
3
- Version: 0.3.3
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
@@ -1,11 +1,11 @@
1
1
  nbsync/__init__.py,sha256=3NuWx9D0LcBnXjEKrC-uypNDOz8rLWXI7mIjdN9xSeE,126
2
- nbsync/cell.py,sha256=C7VqQO3mxZ7Nj4ufywTnaqZAegT7zqA6iN2WV6X5X5c,3786
2
+ nbsync/cell.py,sha256=cloyTpAbZDCwvdA463-7ZBPiYfpk8NO7XjhJ77VkU-4,4141
3
3
  nbsync/logger.py,sha256=snNRqi9xESj4B-Z9GQffCBlgqeVujvuXuBveWAebIWM,736
4
4
  nbsync/markdown.py,sha256=xcPhQKWpFDyVQ_xtZCpFrnR0QED_hYs4PAyaT7dF3t4,3830
5
5
  nbsync/notebook.py,sha256=4F3V1KDHfJnIR5ZSb1xWdN9JGiC6mWUVimXXK1BFsbc,1450
6
6
  nbsync/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  nbsync/sync.py,sha256=vISzn8D_Dae-jdJABRnvvD02aL35bYIWx52OinAORVo,3990
8
- nbsync-0.3.3.dist-info/METADATA,sha256=d4Qp0dekZlvGHU797Q8NuZdEdl07FTXxh2lUbmveB9Q,6552
9
- nbsync-0.3.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
- nbsync-0.3.3.dist-info/licenses/LICENSE,sha256=wy1pqn52upuo_qYwY-epWmspwE-3UWJso0xodciGXYc,1062
11
- nbsync-0.3.3.dist-info/RECORD,,
8
+ nbsync-0.3.5.dist-info/METADATA,sha256=5XZaO_etW_QhKUkqLiPb1Ll5tDUQP-P6pyRqDpM0d54,6552
9
+ nbsync-0.3.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
10
+ nbsync-0.3.5.dist-info/licenses/LICENSE,sha256=wy1pqn52upuo_qYwY-epWmspwE-3UWJso0xodciGXYc,1062
11
+ nbsync-0.3.5.dist-info/RECORD,,
File without changes