edwh-editorjs 2.1.0__py3-none-any.whl → 2.2.0__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.1.0"
1
+ __version__ = "2.2.0"
editorjs/blocks.py CHANGED
@@ -93,10 +93,25 @@ class HeadingBlock(EditorJSBlock):
93
93
  def to_markdown(cls, data: EditorChildData) -> str:
94
94
  level = data.get("level", 1)
95
95
  text = data.get("text", "")
96
+ tunes = data.get("tunes", {})
96
97
 
97
98
  if not (1 <= level <= 6):
98
99
  raise ValueError("Header level must be between 1 and 6.")
99
100
 
101
+ if (
102
+ tunes.get("alignmentTune")
103
+ and (alignment := tunes["alignmentTune"].get("alignment"))
104
+ and (alignment != "left")
105
+ ):
106
+ # can't just return regular HTML because then it will turn into a raw block
107
+ return AlignmentBlock.to_markdown(
108
+ {
109
+ "text": text,
110
+ "tag": f"h{level}",
111
+ "alignment": alignment,
112
+ }
113
+ )
114
+
100
115
  return f"{'#' * level} {text}\n"
101
116
 
102
117
  @classmethod
@@ -143,6 +158,21 @@ class ParagraphBlock(EditorJSBlock):
143
158
  @classmethod
144
159
  def to_markdown(cls, data: EditorChildData) -> str:
145
160
  text = data.get("text", "")
161
+ tunes = data.get("tunes", {})
162
+
163
+ if (
164
+ tunes.get("alignmentTune")
165
+ and (alignment := tunes["alignmentTune"].get("alignment"))
166
+ and (alignment != "left")
167
+ ):
168
+ return AlignmentBlock.to_markdown(
169
+ {
170
+ "text": text,
171
+ "tag": "p",
172
+ "alignment": alignment,
173
+ }
174
+ )
175
+
146
176
  return f"{text}\n\n"
147
177
 
148
178
  @classmethod
@@ -382,7 +412,7 @@ class ImageBlock(EditorJSBlock):
382
412
  def to_markdown(cls, data: EditorChildData) -> str:
383
413
  url = data.get("url", "") or data.get("file", {}).get("url", "")
384
414
  caption = data.get("caption", "")
385
- return f"""![{caption}]({url} "{caption}")\n"""
415
+ return f"""![{caption}]({url} "{caption}")\n\n"""
386
416
 
387
417
  @classmethod
388
418
  def to_json(cls, node: MDChildNode) -> list[dict]:
@@ -533,7 +563,7 @@ class LinkBlock(EditorJSBlock):
533
563
  title = meta.get("title", "")
534
564
  description = meta.get("description", "")
535
565
  image = meta.get("image", {}).get("url", "")
536
- return f"""<editorjs type="linkTool" href="{link}" title="{title}" image="{image}">{description}</editorjs>"""
566
+ return f"""<editorjs type="linkTool" href="{link}" title="{title}" image="{image}">{description}</editorjs>\n\n"""
537
567
 
538
568
  @classmethod
539
569
  def to_json(cls, node: MDChildNode) -> list[dict]:
@@ -582,7 +612,7 @@ class AttachmentBlock(EditorJSBlock):
582
612
  def to_markdown(cls, data: EditorChildData) -> str:
583
613
  file = data.get("file", {}).get("url", "")
584
614
  title = data.get("title", "")
585
- return f"""<editorjs type="attaches" file="{file}">{title}</editorjs>"""
615
+ return f"""<editorjs type="attaches" file="{file}">{title}</editorjs>\n\n"""
586
616
 
587
617
  @classmethod
588
618
  def to_json(cls, node: MDChildNode) -> list[dict]:
@@ -617,6 +647,49 @@ class AttachmentBlock(EditorJSBlock):
617
647
  """
618
648
 
619
649
 
650
+ @block("alignment")
651
+ class AlignmentBlock(EditorJSBlock):
652
+ @classmethod
653
+ def to_markdown(cls, data: EditorChildData) -> str:
654
+ tag = data["tag"]
655
+ alignment = data["alignment"]
656
+ content = data["text"]
657
+
658
+ return f"<editorjs type='alignment' tag='{tag}' alignment='{alignment}'>{content}</editorjs>\n\n"
659
+
660
+ @classmethod
661
+ def to_json(cls, node: MDChildNode) -> list[dict]:
662
+ # only paragraph and headers can be aligned
663
+ tag: str = node["tag"]
664
+ text: str = node["body"]
665
+ alignment = node["alignment"]
666
+ data = {"text": text}
667
+
668
+ if tag == "p":
669
+ _type = "paragraph"
670
+ elif tag.startswith("h"):
671
+ _type = "header"
672
+ data["level"] = int(tag.removeprefix("h"))
673
+ else:
674
+ # doesn't support alignment
675
+ raise TODO(f"Unsupported tag for alignment: {tag}")
676
+
677
+ return [
678
+ {
679
+ "type": _type,
680
+ "data": data,
681
+ "tunes": {"alignmentTune": {"alignment": alignment}},
682
+ }
683
+ ]
684
+
685
+ @classmethod
686
+ def to_text(cls, node: MDChildNode) -> str:
687
+ tag = node["tag"]
688
+ body = node["body"]
689
+ alignment = node["alignment"]
690
+ return f"<{tag} style='text-align: {alignment}'>{body}</{tag}>"
691
+
692
+
620
693
  class AttributeParser(HTMLParser):
621
694
  def __init__(self):
622
695
  super().__init__()
editorjs/core.py CHANGED
@@ -43,7 +43,11 @@ class EditorJS:
43
43
  if not (block := BLOCKS.get(_type)):
44
44
  raise TypeError(f"Unsupported block type `{_type}`")
45
45
 
46
- markdown_items.append(block.to_markdown(child.get("data", {})))
46
+ data = child.get("data", {})
47
+ # forward any 'tunes' via data:
48
+ data["tunes"] = data.get("tunes") or child.get("tunes") or {}
49
+
50
+ markdown_items.append(block.to_markdown(data))
47
51
 
48
52
  markdown = "".join(markdown_items)
49
53
  return cls.from_markdown(markdown)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: edwh-editorjs
3
- Version: 2.1.0
3
+ Version: 2.2.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,10 @@
1
+ editorjs/__about__.py,sha256=DKk-1b-rZsJFxFi1JoJ7TmEvIEQ0rf-C9HAZWwvjuM0,22
2
+ editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
3
+ editorjs/blocks.py,sha256=p5vPOM-YGbx_UL8b2pA2tXXmCrTMn4K-UaeUdsiZp5A,24528
4
+ editorjs/core.py,sha256=wAk6iSmajE5QJb0PLg5M6_XqL1mdBrYj6vGGuRPzZrA,3549
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.2.0.dist-info/METADATA,sha256=nL8_KaTUQEQqb4aTpzSPHQFBVCTXEfV5N9rLJvkbELU,972
9
+ edwh_editorjs-2.2.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
+ edwh_editorjs-2.2.0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- editorjs/__about__.py,sha256=Xybt2skBZamGMNlLuOX1IG-h4uIxqUDGAO8MIGWrJac,22
2
- editorjs/__init__.py,sha256=-OHUf7ZXfkbdFB1r85eIjpHRfql-GCNUCKuBEdEt2Rc,58
3
- editorjs/blocks.py,sha256=kQxmx8QDDVhb1YP6JTFOCKGTYHfcbGswtkryorp1Cn8,22285
4
- editorjs/core.py,sha256=T_7pOzLp7dBxxFSgfG0-ogZShVKaUBd5h_PEEuuSzdQ,3406
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.1.0.dist-info/METADATA,sha256=DmCP8FVdXpma3tupQeNLLTOKMSVpt6qYZTIAxaRo6qY,972
9
- edwh_editorjs-2.1.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
10
- edwh_editorjs-2.1.0.dist-info/RECORD,,