edwh-editorjs 2.0.2__tar.gz → 2.1.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.
Files changed (30) hide show
  1. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/CHANGELOG.md +10 -0
  2. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/PKG-INFO +1 -1
  3. edwh_editorjs-2.1.0/editorjs/__about__.py +1 -0
  4. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/editorjs/blocks.py +13 -6
  5. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/editorjs/core.py +4 -3
  6. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/tests/test_core.py +50 -7
  7. edwh_editorjs-2.0.2/editorjs/__about__.py +0 -1
  8. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/.github/workflows/build_documentation.yml +0 -0
  9. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/.github/workflows/publish_to_pypi.yml +0 -0
  10. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/.github/workflows/pytest.yml +0 -0
  11. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/.gitignore +0 -0
  12. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/README.md +0 -0
  13. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/editorjs/__init__.py +0 -0
  14. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/editorjs/exceptions.py +0 -0
  15. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/editorjs/helpers.py +0 -0
  16. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/editorjs/types.py +0 -0
  17. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/.gitignore +0 -0
  18. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/class_index.html +0 -0
  19. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/favicon_32_cb_58284776.png +0 -0
  20. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/function_index.html +0 -0
  21. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/index.html +0 -0
  22. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/keybd_closed_cb_ce680311.png +0 -0
  23. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/status.json +0 -0
  24. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/style_cb_8e611ae1.css +0 -0
  25. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/z_a93c8aeb4b8fa1f9___init___py.html +0 -0
  26. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/z_a93c8aeb4b8fa1f9_blocks_py.html +0 -0
  27. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/z_a93c8aeb4b8fa1f9_exceptions_py.html +0 -0
  28. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/htmlcov/z_a93c8aeb4b8fa1f9_parser_py.html +0 -0
  29. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/pyproject.toml +0 -0
  30. {edwh_editorjs-2.0.2 → edwh_editorjs-2.1.0}/tests/__init__.py +0 -0
@@ -2,6 +2,16 @@
2
2
 
3
3
  <!--next-version-placeholder-->
4
4
 
5
+ ## v2.1.0 (2024-11-26)
6
+
7
+ ### Feature
8
+
9
+ * `EditorJS.from_json` now also accepts a (json) list of blocks instead of the full object (dictionary with time, version, blocks) ([`9f24c15`](https://github.com/educationwarehouse/edwh-editorjs/commit/9f24c15983948db96153901e804b9a2b11029f49))
10
+
11
+ ### Fix
12
+
13
+ * Better separation between raw and paragraph blocks ([`f7620cf`](https://github.com/educationwarehouse/edwh-editorjs/commit/f7620cf6f34a0a9b9a218fb1c78a67a04f15b78e))
14
+
5
15
  ## v2.0.2 (2024-11-26)
6
16
 
7
17
  ### Fix
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: edwh-editorjs
3
- Version: 2.0.2
3
+ Version: 2.1.0
4
4
  Summary: EditorJS.py
5
5
  Project-URL: Homepage, https://github.com/educationwarehouse/edwh-EditorJS
6
6
  Author-email: SKevo <skevo.cw@gmail.com>, Robin van der Noord <robin.vdn@educationwarehouse.nl>
@@ -0,0 +1 @@
1
+ __version__ = "2.1.0"
@@ -143,7 +143,7 @@ class ParagraphBlock(EditorJSBlock):
143
143
  @classmethod
144
144
  def to_markdown(cls, data: EditorChildData) -> str:
145
145
  text = data.get("text", "")
146
- return f"{text}\n"
146
+ return f"{text}\n\n"
147
147
 
148
148
  @classmethod
149
149
  def to_json(cls, node: MDChildNode) -> list[dict]:
@@ -173,7 +173,7 @@ class ParagraphBlock(EditorJSBlock):
173
173
  else:
174
174
  # <editorjs>something</editorjs> = 3 children
175
175
  result.extend(
176
- EditorJSCustom.to_json({"children": nodes[idx: idx + 2]})
176
+ EditorJSCustom.to_json({"children": nodes[idx : idx + 2]})
177
177
  )
178
178
 
179
179
  skip = 2
@@ -182,7 +182,11 @@ class ParagraphBlock(EditorJSBlock):
182
182
  elif _type == "image":
183
183
  if current_text:
184
184
  # {"id":"zksvpxQTDD","type":"raw","data":{"html":"<marquee> raw </marquee>"}}
185
- result.append(raw_block(current_text) if any_html else paragraph_block(current_text))
185
+ result.append(
186
+ raw_block(current_text)
187
+ if any_html
188
+ else paragraph_block(current_text)
189
+ )
186
190
  current_text = ""
187
191
  any_html = False # reset
188
192
 
@@ -203,7 +207,9 @@ class ParagraphBlock(EditorJSBlock):
203
207
 
204
208
  # final text after image:
205
209
  if current_text:
206
- result.append(raw_block(current_text) if any_html else paragraph_block(current_text))
210
+ result.append(
211
+ raw_block(current_text) if any_html else paragraph_block(current_text)
212
+ )
207
213
 
208
214
  return result
209
215
 
@@ -439,7 +445,8 @@ class RawBlock(EditorJSBlock):
439
445
 
440
446
  @classmethod
441
447
  def to_markdown(cls, data: EditorChildData) -> str:
442
- return data.get("html", "")
448
+ text = data.get("html", "")
449
+ return f"{text}\n\n"
443
450
 
444
451
  @classmethod
445
452
  def to_json(cls, node: MDChildNode) -> list[dict]:
@@ -508,7 +515,7 @@ class TableBlock(EditorJSBlock):
508
515
  "data": {
509
516
  "content": table,
510
517
  "withHeadings": with_headings,
511
- }
518
+ },
512
519
  }
513
520
  ]
514
521
 
@@ -31,13 +31,14 @@ class EditorJS:
31
31
  self._md = markdown2.Markdown(extras=extras) # todo: striketrough, ?
32
32
 
33
33
  @classmethod
34
- def from_json(cls, data: str | dict) -> Self:
34
+ def from_json(cls, data: str | dict | list) -> Self:
35
35
  """
36
36
  Load from EditorJS JSON Blocks
37
37
  """
38
- data = data if isinstance(data, dict) else json.loads(data)
38
+ data = data if isinstance(data, (dict, list)) else json.loads(data)
39
+ blocks = data["blocks"] if isinstance(data, dict) else data
39
40
  markdown_items = []
40
- for child in data["blocks"]:
41
+ for child in blocks:
41
42
  _type = child["type"]
42
43
  if not (block := BLOCKS.get(_type)):
43
44
  raise TypeError(f"Unsupported block type `{_type}`")
@@ -114,15 +114,33 @@ def test_attachment():
114
114
 
115
115
 
116
116
  def test_raw_html():
117
- e = EditorJS.from_markdown(textwrap.dedent("""
118
- # Raw HTML
119
-
120
- <marquee>This ain't no paragraph</marquee>
121
- """))
122
-
117
+ # e = EditorJS.from_markdown(textwrap.dedent("""
118
+ # # Raw HTML
119
+ #
120
+ # <marquee>This ain't no paragraph</marquee>
121
+ #
122
+ # This is a paragraph
123
+ # """))
124
+ #
125
+ # blocks = json.loads(e.to_json())
126
+ #
127
+ # print(blocks)
128
+ #
129
+ # assert blocks["blocks"][1]["type"] == "raw", blocks["blocks"][1]["type"]
130
+ # assert blocks["blocks"][2]["type"] == "paragraph", blocks["blocks"][2]["type"]
131
+ #
132
+
133
+ raw_html_json = r"""{"time":1730989152705,"blocks":[{"id":"DGQwRibbof","type":"paragraph","data":{"text":"The Start"}},{"id":"NrvWoJ2bVI","type":"raw","data":{"html":" <marquee> <kaas>mannetje </kaas> </marquee>Einde!"}},{"id":"DGQwRibbof","type":"paragraph","data":{"text":"The End!"}}],"version":"2.30.6"}"""
134
+
135
+ e = EditorJS.from_json(raw_html_json)
123
136
  blocks = json.loads(e.to_json())
124
137
 
138
+ print(blocks)
139
+
140
+ assert blocks["blocks"][0]["type"] == "paragraph", blocks["blocks"][0]["type"]
125
141
  assert blocks["blocks"][1]["type"] == "raw", blocks["blocks"][1]["type"]
142
+ assert blocks["blocks"][2]["type"] == "paragraph", blocks["blocks"][2]["type"]
143
+
126
144
 
127
145
  def test_code():
128
146
  e = EditorJS.from_markdown(textwrap.dedent("""
@@ -131,8 +149,33 @@ def test_code():
131
149
  ```
132
150
  <marquee> code </marquee>
133
151
  ```
152
+
153
+ End of code
134
154
  """))
135
155
 
136
156
  blocks = json.loads(e.to_json())
137
157
 
138
- print(blocks)
158
+ assert blocks["blocks"][0]["type"] == "paragraph", blocks["blocks"][0]["type"]
159
+ assert blocks["blocks"][1]["type"] == "code", blocks["blocks"][1]["type"]
160
+ assert blocks["blocks"][2]["type"] == "paragraph", blocks["blocks"][2]["type"]
161
+
162
+ # check if it's still the same after export and import:
163
+
164
+ e = EditorJS.from_json(blocks)
165
+
166
+ blocks = json.loads(e.to_json())
167
+
168
+ assert blocks["blocks"][0]["type"] == "paragraph", blocks["blocks"][0]["type"]
169
+ assert blocks["blocks"][1]["type"] == "code", blocks["blocks"][1]["type"]
170
+ assert blocks["blocks"][2]["type"] == "paragraph", blocks["blocks"][2]["type"]
171
+
172
+ # note: without `time` and `version` boilerplate:
173
+ blocks_json = r"""[{"id":"DD966BQf_t","type":"paragraph","data":{"text":"Pre"}},{"id":"sjr2JyuC1y","type":"code","data":{"code":"html"}},{"id":"aJN_wgBv7b","type":"paragraph","data":{"text":"Post"}}]"""
174
+
175
+ e = EditorJS.from_json(blocks_json)
176
+
177
+ blocks = json.loads(e.to_json())
178
+
179
+ assert blocks["blocks"][0]["type"] == "paragraph", blocks["blocks"][0]["type"]
180
+ assert blocks["blocks"][1]["type"] == "code", blocks["blocks"][1]["type"]
181
+ assert blocks["blocks"][2]["type"] == "paragraph", blocks["blocks"][2]["type"]
@@ -1 +0,0 @@
1
- __version__ = "2.0.2"
File without changes
File without changes