Skip to content

Commit

Permalink
[deviantart] improve 'tiptap' to HTML conversion (#6686)
Browse files Browse the repository at this point in the history
- fix "KeyError: 'attrs'" for links without 'href'
- support 'strike' text markers
- support 'heading' content blocks
  • Loading branch information
mikf committed Dec 20, 2024
1 parent e051481 commit 6059ffc
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,26 @@ def _tiptap_process_content(self, html, content):
elif type == "text":
self._tiptap_process_text(html, content)

elif type == "heading":
attrs = content["attrs"]
level = str(attrs.get("level") or "3")

html.append("<h")
html.append(level)
html.append(' style="text-align:')
html.append(attrs.get("textAlign") or "left")
html.append('">')
html.append('<span style="margin-inline-start:0px">')

children = content.get("content")
if children:
for block in children:
self._tiptap_process_content(html, block)

html.append("</span></h")
html.append(level)
html.append(">")

elif type == "hardBreak":
html.append("<br/><br/>")

Expand Down Expand Up @@ -478,8 +498,9 @@ def _tiptap_process_text(self, html, content):
for mark in marks:
type = mark["type"]
if type == "link":
attrs = mark.get("attrs") or {}
html.append('<a href="')
html.append(text.escape(mark["attrs"]["href"]))
html.append(text.escape(attrs.get("href") or ""))
html.append('" rel="noopener noreferrer nofollow ugc">')
close.append("</a>")
elif type == "bold":
Expand All @@ -491,6 +512,9 @@ def _tiptap_process_text(self, html, content):
elif type == "underline":
html.append("<u>")
close.append("</u>")
elif type == "strike":
html.append("<s>")
close.append("</s>")
elif type == "textStyle" and len(mark) <= 1:
pass
else:
Expand Down

0 comments on commit 6059ffc

Please sign in to comment.