edwh-editorjs 2.3.0__py3-none-any.whl → 2.3.2__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.
editorjs/__about__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "2.3.0"
1
+ __version__ = "2.3.2"
editorjs/blocks.py CHANGED
@@ -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
  {
@@ -753,11 +746,7 @@ class EmbedBlock(EditorJSBlock):
753
746
  caption = node.get("caption", "")
754
747
  return f"""
755
748
  <div class="cdx-block embed-tool">
756
- <preloader class="embed-tool__preloader">
757
- <div class="embed-tool__url">{source}</div>
758
- </preloader>
759
- <iframe style="width:100%;" height="320" frameborder="0" allowfullscreen="" src="{embed}" class="embed-tool__content"></iframe>
760
- <div class="cdx-input embed-tool__caption" contenteditable="true" data-placeholder="Enter a caption" data-empty="false">{caption}</div>
749
+ <iframe title='{caption}' style="width:100%;" height="320" frameborder="0" allowfullscreen="" src="{embed}" class="embed-tool__content"></iframe>
761
750
  </div>
762
751
  """
763
752
 
@@ -781,7 +770,9 @@ class AttributeParser(HTMLParser):
781
770
 
782
771
  class EditorJSCustom(EditorJSBlock, markdown2.Extra):
783
772
  """
784
- 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!
785
776
  """
786
777
 
787
778
  name = "editorjs"
@@ -796,23 +787,31 @@ class EditorJSCustom(EditorJSBlock, markdown2.Extra):
796
787
 
797
788
  @classmethod
798
789
  def to_markdown(cls, data: EditorChildData) -> str:
799
- raise TODO()
790
+ raise Unreachable("Custom Blocks have their own to_markdown logic.")
800
791
 
801
792
  @classmethod
802
- def to_json(cls, node: MDChildNode) -> list[dict]:
803
- html = "".join(_["value"] for _ in node.get("children", []))
793
+ def _find_right_block(cls, html: str) -> tuple[EditorJSBlock, dict]:
804
794
  attrs, body = cls.parse_html(html)
805
795
  _type = attrs.get("type", "")
806
796
  attrs.setdefault("body", body) # only if there is no such attribute yet
807
797
 
808
- if not (handler := BLOCKS.get(_type)):
798
+ handler = BLOCKS.get(_type)
799
+
800
+ if not handler:
809
801
  raise ValueError(f"Unknown custom type {_type}")
810
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)
811
809
  return handler.to_json(attrs)
812
810
 
813
811
  @classmethod
814
812
  def to_text(cls, node: MDChildNode) -> str:
815
- raise TODO()
813
+ handler, attrs = cls._find_right_block(node.get("value", ""))
814
+ return handler.to_text(attrs)
816
815
 
817
816
  # markdown2:
818
817
  re_short = re.compile(r"<editorjs.*?/>")
@@ -820,13 +819,7 @@ class EditorJSCustom(EditorJSBlock, markdown2.Extra):
820
819
 
821
820
  def run(self, text: str) -> str:
822
821
  def replace_html(match):
823
- attrs, body = self.parse_html(match.group())
824
- _type = attrs.get("type", "")
825
- attrs.setdefault("body", body) # only if there is no such attribute yet
826
-
827
- if not (handler := BLOCKS.get(_type)):
828
- raise ValueError(f"Unknown custom type {_type}")
829
-
822
+ handler, attrs = self._find_right_block(match.group())
830
823
  return handler.to_text(attrs)
831
824
 
832
825
  # Substitute using the replacement functions
editorjs/exceptions.py CHANGED
@@ -1,3 +1,8 @@
1
1
  class TODO(NotImplementedError):
2
2
  def __init__(self, msg: str = "todo"):
3
3
  super().__init__(msg)
4
+
5
+
6
+ class Unreachable(NotImplementedError):
7
+ def __init__(self, msg: str = "unimplemented"):
8
+ super().__init__(msg)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: edwh-editorjs
3
- Version: 2.3.0
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,10 @@
1
+ editorjs/__about__.py,sha256=J4CRnpR3v72FGOMp8gqSua_XWZpAfXuqgVWiQFB-gTY,22
2
+ editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
3
+ editorjs/blocks.py,sha256=dT54-wCL4sm9fO7OiJO8Q0SgTuHq3wtv7KQiOF81oks,27138
4
+ editorjs/core.py,sha256=WSBmAIKwSqHIP_NFmUVUJiyHPgq7D8902Jm9HRf1nSk,3669
5
+ editorjs/exceptions.py,sha256=oKuWqi4CSnFGZfVZWtTZ2XZeHXm5xF-nAtX_1YLm6sI,230
6
+ editorjs/helpers.py,sha256=q861o5liNibMTp-Ozay17taF7CTNsRe901lYhhxdwHg,73
7
+ editorjs/types.py,sha256=W7IZWMWgzJaQulybIt0Gx5N63rVj4mEy73VJWo4VAQA,1029
8
+ edwh_editorjs-2.3.2.dist-info/METADATA,sha256=798OipvvgiexYoOa7x3KFac2MouJVMYQA5KzF6bR1ss,996
9
+ edwh_editorjs-2.3.2.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
+ edwh_editorjs-2.3.2.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- editorjs/__about__.py,sha256=CpK8IH_dCUAwg9tqv7zm9FxbBFkxCnED1JUiRe7cftU,22
2
- editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
3
- editorjs/blocks.py,sha256=WHxlQMLWLzM7EzNOznOUkpr4gmAoBLgoLlRpFIKLZ60,27342
4
- editorjs/core.py,sha256=WSBmAIKwSqHIP_NFmUVUJiyHPgq7D8902Jm9HRf1nSk,3669
5
- editorjs/exceptions.py,sha256=TyfHvk2Z5RbKxTDK7lrjgwAgVgInXIuDW63eO5jzVFw,106
6
- editorjs/helpers.py,sha256=q861o5liNibMTp-Ozay17taF7CTNsRe901lYhhxdwHg,73
7
- editorjs/types.py,sha256=W7IZWMWgzJaQulybIt0Gx5N63rVj4mEy73VJWo4VAQA,1029
8
- edwh_editorjs-2.3.0.dist-info/METADATA,sha256=cyn9LNNokE60J1r6eEtstPiAkXACF8b3DbLJMhnk5fY,996
9
- edwh_editorjs-2.3.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
- edwh_editorjs-2.3.0.dist-info/RECORD,,