edwh-editorjs 2.0.0b4__tar.gz → 2.0.0b5__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.
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/CHANGELOG.md +6 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/PKG-INFO +1 -1
- edwh_editorjs-2.0.0b5/editorjs/__about__.py +1 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/editorjs/blocks.py +109 -4
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/editorjs/core.py +2 -4
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/tests/test_core.py +16 -5
- edwh_editorjs-2.0.0b4/editorjs/__about__.py +0 -1
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/.github/workflows/build_documentation.yml +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/.github/workflows/publish_to_pypi.yml +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/.github/workflows/pytest.yml +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/.gitignore +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/LICENSE +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/README.md +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/editorjs/__init__.py +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/editorjs/exceptions.py +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/editorjs/helpers.py +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/editorjs/types.py +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/.gitignore +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/class_index.html +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/favicon_32_cb_58284776.png +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/function_index.html +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/index.html +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/keybd_closed_cb_ce680311.png +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/status.json +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/style_cb_8e611ae1.css +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/z_a93c8aeb4b8fa1f9___init___py.html +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/z_a93c8aeb4b8fa1f9_blocks_py.html +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/z_a93c8aeb4b8fa1f9_exceptions_py.html +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/z_a93c8aeb4b8fa1f9_parser_py.html +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/pyproject.toml +0 -0
- {edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/tests/__init__.py +0 -0
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
<!--next-version-placeholder-->
|
|
4
4
|
|
|
5
|
+
## v2.0.0-beta.5 (2024-11-07)
|
|
6
|
+
|
|
7
|
+
### Feature
|
|
8
|
+
|
|
9
|
+
* Add markdown2 extra to deal with custom `<editorjs />` blocks ([`31d8647`](https://github.com/educationwarehouse/edwh-editorjs/commit/31d8647b7275e245dabf27a99c43d400217705be))
|
|
10
|
+
|
|
5
11
|
## v2.0.0-beta.4 (2024-11-07)
|
|
6
12
|
|
|
7
13
|
### Feature
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: edwh-editorjs
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.0b5
|
|
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.0.0-beta.5"
|
|
@@ -6,6 +6,9 @@ import abc
|
|
|
6
6
|
import re
|
|
7
7
|
import typing as t
|
|
8
8
|
from html.parser import HTMLParser
|
|
9
|
+
from urllib.parse import urlparse
|
|
10
|
+
|
|
11
|
+
import markdown2
|
|
9
12
|
|
|
10
13
|
from .exceptions import TODO
|
|
11
14
|
from .types import EditorChildData, MDChildNode
|
|
@@ -217,7 +220,7 @@ class ListBlock(EditorJSBlock):
|
|
|
217
220
|
|
|
218
221
|
return "\n".join(markdown_items)
|
|
219
222
|
|
|
220
|
-
return "\n" + parse_items(items) + "\n"
|
|
223
|
+
return "\n" + parse_items(items) + "\n\n"
|
|
221
224
|
|
|
222
225
|
@classmethod
|
|
223
226
|
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
@@ -311,7 +314,7 @@ class ChecklistBlock(ListBlock):
|
|
|
311
314
|
char = "x" if item.get("checked", False) else " "
|
|
312
315
|
markdown_items.append(f"- [{char}] {text}")
|
|
313
316
|
|
|
314
|
-
return "\n" + "\n".join(markdown_items) + "\n"
|
|
317
|
+
return "\n" + "\n".join(markdown_items) + "\n\n"
|
|
315
318
|
|
|
316
319
|
|
|
317
320
|
@block("thematicBreak", "delimiter")
|
|
@@ -419,6 +422,22 @@ class QuoteBlock(EditorJSBlock):
|
|
|
419
422
|
return default_to_text(node)
|
|
420
423
|
|
|
421
424
|
|
|
425
|
+
@block("raw")
|
|
426
|
+
class RawBlock(EditorJSBlock):
|
|
427
|
+
|
|
428
|
+
@classmethod
|
|
429
|
+
def to_markdown(cls, data: EditorChildData) -> str:
|
|
430
|
+
return data.get("html", "")
|
|
431
|
+
|
|
432
|
+
@classmethod
|
|
433
|
+
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
434
|
+
raise TODO(node)
|
|
435
|
+
|
|
436
|
+
@classmethod
|
|
437
|
+
def to_text(cls, node: MDChildNode) -> str:
|
|
438
|
+
raise TODO(node)
|
|
439
|
+
|
|
440
|
+
|
|
422
441
|
@block("table")
|
|
423
442
|
class TableBlock(EditorJSBlock):
|
|
424
443
|
|
|
@@ -515,7 +534,66 @@ class LinkBlock(EditorJSBlock):
|
|
|
515
534
|
|
|
516
535
|
@classmethod
|
|
517
536
|
def to_text(cls, node: MDChildNode) -> str:
|
|
518
|
-
|
|
537
|
+
url = node.get("href", "")
|
|
538
|
+
image = node.get("image", "")
|
|
539
|
+
title = node.get("title", "")
|
|
540
|
+
body = node.get("body", "")
|
|
541
|
+
domain = urlparse(url).netloc
|
|
542
|
+
|
|
543
|
+
return f"""
|
|
544
|
+
<div class="link-tool">
|
|
545
|
+
<a class="link-tool__content link-tool__content--rendered" target="_blank"
|
|
546
|
+
rel="nofollow noindex noreferrer" href="{url}">
|
|
547
|
+
<div class="link-tool__image"
|
|
548
|
+
style="background-image: url("{image}");"></div>
|
|
549
|
+
<div class="link-tool__title">{title}</div>
|
|
550
|
+
<p class="link-tool__description">{body}</p>
|
|
551
|
+
<span class="link-tool__anchor">{domain}</span>
|
|
552
|
+
</a>
|
|
553
|
+
</div>
|
|
554
|
+
"""
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
@block("attaches")
|
|
558
|
+
class AttachmentBlock(EditorJSBlock):
|
|
559
|
+
|
|
560
|
+
@classmethod
|
|
561
|
+
def to_markdown(cls, data: EditorChildData) -> str:
|
|
562
|
+
file = data.get("file", {}).get("url", "")
|
|
563
|
+
title = data.get("title", "")
|
|
564
|
+
return f"""<editorjs type="attaches" file="{file}">{title}</editorjs>"""
|
|
565
|
+
|
|
566
|
+
@classmethod
|
|
567
|
+
def to_json(cls, node: MDChildNode) -> list[dict]:
|
|
568
|
+
return [
|
|
569
|
+
{
|
|
570
|
+
"type": "attaches",
|
|
571
|
+
"data": {
|
|
572
|
+
"file": {"url": node.get("file", "")},
|
|
573
|
+
"title": node.get("body", ""),
|
|
574
|
+
},
|
|
575
|
+
}
|
|
576
|
+
]
|
|
577
|
+
|
|
578
|
+
@classmethod
|
|
579
|
+
def to_text(cls, node: MDChildNode) -> str:
|
|
580
|
+
return f"""
|
|
581
|
+
<div class="cdx-attaches cdx-attaches--with-file">
|
|
582
|
+
<div class="cdx-attaches__file-icon">
|
|
583
|
+
<div class="cdx-attaches__file-icon-background">
|
|
584
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.3236 8.43554L9.49533 12.1908C9.13119 12.5505 8.93118 13.043 8.9393 13.5598C8.94741 14.0767 9.163 14.5757 9.53862 14.947C9.91424 15.3182 10.4191 15.5314 10.9422 15.5397C11.4653 15.5479 11.9637 15.3504 12.3279 14.9908L16.1562 11.2355C16.8845 10.5161 17.2845 9.53123 17.2682 8.4975C17.252 7.46376 16.8208 6.46583 16.0696 5.72324C15.3184 4.98066 14.3086 4.55425 13.2624 4.53782C12.2162 4.52138 11.2193 4.91627 10.4911 5.63562L6.66277 9.39093C5.57035 10.4699 4.97032 11.9473 4.99467 13.4979C5.01903 15.0485 5.66578 16.5454 6.79264 17.6592C7.9195 18.7731 9.43417 19.4127 11.0034 19.4374C12.5727 19.462 14.068 18.8697 15.1604 17.7907L18.9887 14.0354"></path></svg>
|
|
585
|
+
</div>
|
|
586
|
+
</div>
|
|
587
|
+
<div class="cdx-attaches__file-info">
|
|
588
|
+
<div class="cdx-attaches__title" contenteditable="true" data-placeholder="File title" data-empty="false">
|
|
589
|
+
{node.get("body", "")}
|
|
590
|
+
</div>
|
|
591
|
+
</div>
|
|
592
|
+
<a class="cdx-attaches__download-button" href="{node.get('file', '')}" target="_blank" rel="nofollow noindex noreferrer">
|
|
593
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="M7 10L11.8586 14.8586C11.9367 14.9367 12.0633 14.9367 12.1414 14.8586L17 10"></path></svg>
|
|
594
|
+
</a>
|
|
595
|
+
</div>
|
|
596
|
+
"""
|
|
519
597
|
|
|
520
598
|
|
|
521
599
|
class AttributeParser(HTMLParser):
|
|
@@ -532,11 +610,14 @@ class AttributeParser(HTMLParser):
|
|
|
532
610
|
self.data = data
|
|
533
611
|
|
|
534
612
|
|
|
535
|
-
class EditorJSCustom(EditorJSBlock):
|
|
613
|
+
class EditorJSCustom(EditorJSBlock, markdown2.Extra):
|
|
536
614
|
"""
|
|
537
615
|
Special type of block to deal with custom attributes
|
|
538
616
|
"""
|
|
539
617
|
|
|
618
|
+
name = "editorjs"
|
|
619
|
+
order = (), (markdown2.Stage.POSTPROCESS,)
|
|
620
|
+
|
|
540
621
|
@classmethod
|
|
541
622
|
def parse_html(cls, html: str):
|
|
542
623
|
parser = AttributeParser()
|
|
@@ -563,3 +644,27 @@ class EditorJSCustom(EditorJSBlock):
|
|
|
563
644
|
@classmethod
|
|
564
645
|
def to_text(cls, node: MDChildNode) -> str:
|
|
565
646
|
raise TODO()
|
|
647
|
+
|
|
648
|
+
# markdown2:
|
|
649
|
+
re_short = re.compile(r"<editorjs.*?/>")
|
|
650
|
+
re_long = re.compile(r"<editorjs.*?>.*?</editorjs>")
|
|
651
|
+
|
|
652
|
+
def run(self, text: str) -> str:
|
|
653
|
+
def replace_html(match):
|
|
654
|
+
attrs, body = self.parse_html(match.group())
|
|
655
|
+
_type = attrs.get("type", "")
|
|
656
|
+
attrs.setdefault("body", body) # only if there is no such attribute yet
|
|
657
|
+
|
|
658
|
+
if not (handler := BLOCKS.get(_type)):
|
|
659
|
+
raise ValueError(f"Unknown custom type {_type}")
|
|
660
|
+
|
|
661
|
+
return handler.to_text(attrs)
|
|
662
|
+
|
|
663
|
+
# Substitute using the replacement functions
|
|
664
|
+
text = self.re_long.sub(replace_html, text)
|
|
665
|
+
text = self.re_short.sub(replace_html, text)
|
|
666
|
+
|
|
667
|
+
return text
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
EditorJSCustom.register()
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import json
|
|
2
|
-
import textwrap
|
|
3
2
|
import typing as t
|
|
4
3
|
|
|
5
4
|
import markdown2
|
|
@@ -7,7 +6,6 @@ import mdast
|
|
|
7
6
|
from typing_extensions import Self
|
|
8
7
|
|
|
9
8
|
from .blocks import BLOCKS
|
|
10
|
-
from .exceptions import TODO
|
|
11
9
|
from .helpers import unix_timestamp
|
|
12
10
|
from .types import MDRootNode
|
|
13
11
|
|
|
@@ -21,7 +19,7 @@ class EditorJS:
|
|
|
21
19
|
def __init__(
|
|
22
20
|
self,
|
|
23
21
|
_mdast: str | dict,
|
|
24
|
-
extras: list = ("task_list", "fenced-code-blocks", "tables"),
|
|
22
|
+
extras: list = ("task_list", "fenced-code-blocks", "tables", "editorjs"),
|
|
25
23
|
):
|
|
26
24
|
if not isinstance(_mdast, str | dict):
|
|
27
25
|
raise TypeError("Only `str` or `dict` is supported!")
|
|
@@ -102,7 +100,7 @@ class EditorJS:
|
|
|
102
100
|
Export HTML string
|
|
103
101
|
"""
|
|
104
102
|
md = self.to_markdown()
|
|
105
|
-
# todo: deal with custom elements like linktool
|
|
103
|
+
# todo: deal with custom elements like linktool, attaches
|
|
106
104
|
return self._md.convert(md)
|
|
107
105
|
|
|
108
106
|
def __repr__(self):
|
|
@@ -89,13 +89,24 @@ def test_linktool():
|
|
|
89
89
|
TABLE1_JSON = r"""{"time":1730984047714,"blocks":[{"id":"SNXL5vru_a","type":"table","data":{"withHeadings":false,"stretched":false,"content":[["1.1","2.1"],["1.2","2.2"]]}},{"id":"q0IC_sL8P5","type":"paragraph","data":{"text":"<mark class=\"cdx-marker\">marked</mark>"}}],"version":"2.30.6"}"""
|
|
90
90
|
TABLE2_JSON = r"""{"time":1730984305796,"blocks":[{"id":"vBf5hT3jeR","type":"linkTool","data":{"link":"https://fb.me","meta":{"title":"","description":"Meld je aan bij Facebook om te delen en contact te maken met je vrienden, familie en mensen die je kent.","image":{"url":"https://www.facebook.com/images/fb_icon_325x325.png"}}}},{"id":"7bP-0bw1OT","type":"table","data":{"withHeadings":true,"stretched":false,"content":[["Yeah","Okay"],["<i>1</i>","<code class=\"inline-code\">2</code>"]]}}],"version":"2.30.6"}"""
|
|
91
91
|
|
|
92
|
+
|
|
92
93
|
def test_table():
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
e = EditorJS.from_json(TABLE1_JSON)
|
|
95
|
+
print(e.to_markdown())
|
|
96
|
+
print(e.to_json())
|
|
97
|
+
print(e.to_html())
|
|
97
98
|
|
|
98
99
|
e = EditorJS.from_json(TABLE2_JSON)
|
|
99
100
|
print(e.to_markdown())
|
|
100
101
|
print(e.to_json())
|
|
101
|
-
print(e.to_html())
|
|
102
|
+
print(e.to_html())
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
ATTACHMENT_JSON = r"""{"time":1730989152705,"blocks":[{"id":"s3k3WCp1da","type":"header","data":{"text":"Hi","level":2}},{"id":"EehvyuBEKx","type":"paragraph","data":{"text":"<b>Paragraph</b> <i>met</i> <a href=\"http://g.co\">mooie</a> <code class=\"inline-code\">markup </code><mark class=\"cdx-marker\">asdf</mark>"}},{"id":"S1ENjQ6XEw","type":"list","data":{"style":"unordered","items":[{"content":"u","items":[]},{"content":"l","items":[]}]}},{"id":"ezy6f8-7gj","type":"list","data":{"style":"ordered","items":[{"content":"o","items":[]},{"content":"l","items":[]}]}},{"id":"DsHJI0tccS","type":"image","data":{"caption":"streamers","withBorder":false,"withBackground":false,"stretched":false,"file":{"url":"https://py4web.leiden.dockers.local/img/upload/17.txt?hash=3ef2d77e2f4f493651119f65d1657b01de939adb"}}},{"id":"VhvLUtaKcB","type":"quote","data":{"text":"ik ben een streamer","caption":"Frank Lammers","alignment":"left"}},{"id":"yrQLgdrYWC","type":"delimiter","data":{}},{"id":"88cMVCXNZF","type":"table","data":{"withHeadings":true,"stretched":false,"content":[["Tafels","Deuren"],["1 * 1","1"],["2 * 2","4"]]}},{"id":"vlSOey3tKF","type":"code","data":{"code":"if crash: don't"}},{"id":"zPzINXsico","type":"raw","data":{"html":"<marquee>Wheeeee</marquee>"}},{"id":"rbc6buobti","type":"checklist","data":{"items":[{"text":"check","checked":false},{"text":"one","checked":true},{"text":"two","checked":false}]}},{"id":"0JGAjTs_77","type":"linkTool","data":{"link":"https://trialandsuccess.nl","meta":{"title":"Trial and Success","description":"Welkom op de website van Trial and Success! Ik, Robin van der Noord, ontwerp en bouw websites en webapplicaties, helemaal toegespitst op de wensen van de klant. Ook kan ik de hosting en het onderhoud van uw website verzorgen.","image":{"url":"https://trialandsuccess.nl/static/images/og.png"}}}},{"id":"h8Zt0aKD5p","type":"attaches","data":{"file":{"url":"https://py4web.leiden.dockers.local/img/upload/18.txt?hash=f114bad0e27c84eb1f70ba2d6168d2a76b9efca9"},"title":"Attachment, Download nu!"}}],"version":"2.30.6"}"""
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_attachment():
|
|
109
|
+
e = EditorJS.from_json(ATTACHMENT_JSON)
|
|
110
|
+
print(e.to_markdown())
|
|
111
|
+
print(e.to_json())
|
|
112
|
+
print(e.to_html())
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "2.0.0-beta.4"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{edwh_editorjs-2.0.0b4 → edwh_editorjs-2.0.0b5}/htmlcov/z_a93c8aeb4b8fa1f9_exceptions_py.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|