edwh-editorjs 2.3.1__tar.gz → 2.3.2__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 (31) hide show
  1. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/CHANGELOG.md +6 -0
  2. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/PKG-INFO +1 -1
  3. edwh_editorjs-2.3.2/editorjs/__about__.py +1 -0
  4. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/editorjs/blocks.py +22 -25
  5. edwh_editorjs-2.3.2/editorjs/exceptions.py +8 -0
  6. edwh_editorjs-2.3.1/editorjs/__about__.py +0 -1
  7. edwh_editorjs-2.3.1/editorjs/exceptions.py +0 -3
  8. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/.github/workflows/build_documentation.yml +0 -0
  9. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/.github/workflows/publish_to_pypi.yml +0 -0
  10. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/.github/workflows/pytest.yml +0 -0
  11. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/.gitignore +0 -0
  12. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/README.md +0 -0
  13. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/editorjs/__init__.py +0 -0
  14. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/editorjs/core.py +0 -0
  15. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/editorjs/helpers.py +0 -0
  16. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/editorjs/types.py +0 -0
  17. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/.gitignore +0 -0
  18. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/class_index.html +0 -0
  19. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/favicon_32_cb_58284776.png +0 -0
  20. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/function_index.html +0 -0
  21. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/index.html +0 -0
  22. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/keybd_closed_cb_ce680311.png +0 -0
  23. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/status.json +0 -0
  24. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/style_cb_8e611ae1.css +0 -0
  25. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/z_a93c8aeb4b8fa1f9___init___py.html +0 -0
  26. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/z_a93c8aeb4b8fa1f9_blocks_py.html +0 -0
  27. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/z_a93c8aeb4b8fa1f9_exceptions_py.html +0 -0
  28. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/htmlcov/z_a93c8aeb4b8fa1f9_parser_py.html +0 -0
  29. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/pyproject.toml +0 -0
  30. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/tests/__init__.py +0 -0
  31. {edwh_editorjs-2.3.1 → edwh_editorjs-2.3.2}/tests/test_core.py +0 -0
@@ -2,6 +2,12 @@
2
2
 
3
3
  <!--next-version-placeholder-->
4
4
 
5
+ ## v2.3.2 (2024-11-27)
6
+
7
+ ### Fix
8
+
9
+ * (refactor) clean up todo's, add `Unreachable` for when some branch/function should never be used ([`3226642`](https://github.com/educationwarehouse/edwh-editorjs/commit/3226642cfc8adb9a3cad6052d02ea6fc6c048058))
10
+
5
11
  ## v2.3.1 (2024-11-27)
6
12
 
7
13
  ### Fix
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: edwh-editorjs
3
- Version: 2.3.1
3
+ Version: 2.3.2
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.3.2"
@@ -4,7 +4,6 @@ mdast to editorjs
4
4
 
5
5
  import abc
6
6
  import re
7
- import traceback
8
7
  import typing as t
9
8
  from html.parser import HTMLParser
10
9
  from urllib.parse import urlparse
@@ -12,7 +11,7 @@ from urllib.parse import urlparse
12
11
  import humanize
13
12
  import markdown2
14
13
 
15
- from .exceptions import TODO
14
+ from .exceptions import TODO, Unreachable
16
15
  from .types import EditorChildData, MDChildNode
17
16
 
18
17
 
@@ -62,7 +61,6 @@ def process_styled_content(item: MDChildNode, strict: bool = True) -> str:
62
61
  "strongEmphasis": "<b><i>{value}</i></b>",
63
62
  "link": '<a href="{url}">{value}</a>',
64
63
  "inlineCode": '<code class="inline-code">{value}</code>',
65
- # todo: <mark>, linktool
66
64
  }
67
65
 
68
66
  if _type in BLOCKS:
@@ -314,12 +312,6 @@ class ListBlock(EditorJSBlock):
314
312
  }
315
313
  )
316
314
 
317
- # todo: detect 'checklist':
318
- """
319
- type: checklist
320
- data: {items: [{text: "a", checked: false}, {text: "b", checked: false}, {text: "c", checked: true},…]}
321
- """
322
-
323
315
  if could_be_checklist:
324
316
  return [
325
317
  {
@@ -482,10 +474,10 @@ class RawBlock(EditorJSBlock):
482
474
 
483
475
  @classmethod
484
476
  def to_json(cls, node: MDChildNode) -> list[dict]:
485
- # todo: apply same logic as paragraph block to find <editorjs/> items!!!
486
477
  raw = cls.to_text(node)
487
478
 
488
479
  if raw.startswith("<editorjs"):
480
+ # not a raw block but (probably) a self-closing editorjs block
489
481
  return EditorJSCustom.to_json({"children": [node]})
490
482
  else:
491
483
  return [raw_block(raw)]
@@ -559,7 +551,8 @@ class TableBlock(EditorJSBlock):
559
551
 
560
552
  @classmethod
561
553
  def to_text(cls, node: MDChildNode) -> str:
562
- raise TODO(node)
554
+ # I think this might be triggered if there is a table (deeply) within a paragraph block?
555
+ raise TODO(["TableBlock.to_text", node])
563
556
 
564
557
 
565
558
  @block("linkTool")
@@ -712,7 +705,7 @@ class AlignmentBlock(EditorJSBlock):
712
705
  data["level"] = int(tag.removeprefix("h"))
713
706
  else:
714
707
  # doesn't support alignment
715
- raise TODO(f"Unsupported tag for alignment: {tag}")
708
+ raise NotImplementedError(f"Unsupported tag for alignment: {tag}")
716
709
 
717
710
  return [
718
711
  {
@@ -777,7 +770,9 @@ class AttributeParser(HTMLParser):
777
770
 
778
771
  class EditorJSCustom(EditorJSBlock, markdown2.Extra):
779
772
  """
780
- Special type of block to deal with custom attributes
773
+ Special type of block to deal with custom attributes.
774
+
775
+ This is both a special editorjs block as well as a markdown2 plugin!
781
776
  """
782
777
 
783
778
  name = "editorjs"
@@ -792,23 +787,31 @@ class EditorJSCustom(EditorJSBlock, markdown2.Extra):
792
787
 
793
788
  @classmethod
794
789
  def to_markdown(cls, data: EditorChildData) -> str:
795
- raise TODO()
790
+ raise Unreachable("Custom Blocks have their own to_markdown logic.")
796
791
 
797
792
  @classmethod
798
- def to_json(cls, node: MDChildNode) -> list[dict]:
799
- html = "".join(_["value"] for _ in node.get("children", []))
793
+ def _find_right_block(cls, html: str) -> tuple[EditorJSBlock, dict]:
800
794
  attrs, body = cls.parse_html(html)
801
795
  _type = attrs.get("type", "")
802
796
  attrs.setdefault("body", body) # only if there is no such attribute yet
803
797
 
804
- if not (handler := BLOCKS.get(_type)):
798
+ handler = BLOCKS.get(_type)
799
+
800
+ if not handler:
805
801
  raise ValueError(f"Unknown custom type {_type}")
806
802
 
803
+ return handler, attrs
804
+
805
+ @classmethod
806
+ def to_json(cls, node: MDChildNode) -> list[dict]:
807
+ html = "".join(_["value"] for _ in node.get("children", []))
808
+ handler, attrs = cls._find_right_block(html)
807
809
  return handler.to_json(attrs)
808
810
 
809
811
  @classmethod
810
812
  def to_text(cls, node: MDChildNode) -> str:
811
- raise TODO()
813
+ handler, attrs = cls._find_right_block(node.get("value", ""))
814
+ return handler.to_text(attrs)
812
815
 
813
816
  # markdown2:
814
817
  re_short = re.compile(r"<editorjs.*?/>")
@@ -816,13 +819,7 @@ class EditorJSCustom(EditorJSBlock, markdown2.Extra):
816
819
 
817
820
  def run(self, text: str) -> str:
818
821
  def replace_html(match):
819
- attrs, body = self.parse_html(match.group())
820
- _type = attrs.get("type", "")
821
- attrs.setdefault("body", body) # only if there is no such attribute yet
822
-
823
- if not (handler := BLOCKS.get(_type)):
824
- raise ValueError(f"Unknown custom type {_type}")
825
-
822
+ handler, attrs = self._find_right_block(match.group())
826
823
  return handler.to_text(attrs)
827
824
 
828
825
  # Substitute using the replacement functions
@@ -0,0 +1,8 @@
1
+ class TODO(NotImplementedError):
2
+ def __init__(self, msg: str = "todo"):
3
+ super().__init__(msg)
4
+
5
+
6
+ class Unreachable(NotImplementedError):
7
+ def __init__(self, msg: str = "unimplemented"):
8
+ super().__init__(msg)
@@ -1 +0,0 @@
1
- __version__ = "2.3.1"
@@ -1,3 +0,0 @@
1
- class TODO(NotImplementedError):
2
- def __init__(self, msg: str = "todo"):
3
- super().__init__(msg)
File without changes
File without changes