Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08b3e59

Browse files
committed
replace match/case with if/else for compatiblity with python 3.11 & below
1 parent 8852feb commit 08b3e59

1 file changed

Lines changed: 40 additions & 41 deletions

File tree

  • src/plone/restapi/renderer/blocks

src/plone/restapi/renderer/blocks/slate.py

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -48,46 +48,45 @@ def extract_text(
4848

4949
node_type = node.get("type", "") if isinstance(node, dict) else ""
5050

51-
match node_type:
52-
case "p":
53-
return f"{children}\n"
54-
case "blockquote":
55-
return f"> {children}\n"
56-
case "h1":
57-
return f"# {children}\n"
58-
case "h2":
59-
return f"## {children}\n"
60-
case "h3":
61-
return f"### {children}\n"
62-
case "h4":
63-
return f"#### {children}\n"
64-
case "h5":
65-
return f"##### {children}\n"
66-
case "h6":
67-
return f"###### {children}\n"
68-
case "hr":
69-
return "---\n"
70-
case "strong":
71-
return f"**{children}**"
72-
case "em":
73-
return f"*{children}*"
74-
case "del":
75-
return f"~~{children}~~"
76-
case "sub":
77-
return f"~{children}~"
78-
case "sup":
79-
return f"^{children}^"
80-
case "link":
81-
url = node.get("data", {}).get("url", "") if "data" in node else ""
82-
return f"[{children}]({url})"
83-
case "li":
84-
indent = " " * (depth - 1)
85-
if parent == "ol":
86-
return f"{indent}{index}. {children}\n"
87-
return f"{indent}- {children}\n"
88-
case "ul" | "ol":
89-
return f"{children}{NEWLINE if depth == 0 else ''}"
90-
case _:
91-
return children
51+
if node_type == "p":
52+
return f"{children}\n"
53+
elif node_type == "blockquote":
54+
return f"> {children}\n"
55+
elif node_type == "h1":
56+
return f"# {children}\n"
57+
elif node_type == "h2":
58+
return f"## {children}\n"
59+
elif node_type == "h3":
60+
return f"### {children}\n"
61+
elif node_type == "h4":
62+
return f"#### {children}\n"
63+
elif node_type == "h5":
64+
return f"##### {children}\n"
65+
elif node_type == "h6":
66+
return f"###### {children}\n"
67+
elif node_type == "hr":
68+
return "---\n"
69+
elif node_type == "strong":
70+
return f"**{children}**"
71+
elif node_type == "em":
72+
return f"*{children}*"
73+
elif node_type == "del":
74+
return f"~~{children}~~"
75+
elif node_type == "sub":
76+
return f"~{children}~"
77+
elif node_type == "sup":
78+
return f"^{children}^"
79+
elif node_type == "link":
80+
url = node.get("data", {}).get("url", "") if "data" in node else ""
81+
return f"[{children}]({url})"
82+
elif node_type == "li":
83+
indent = " " * (depth - 1)
84+
if parent == "ol":
85+
return f"{indent}{index}. {children}\n"
86+
return f"{indent}- {children}\n"
87+
elif node_type in ("ul", "ol"):
88+
return f"{children}{NEWLINE if depth == 0 else ''}"
89+
else:
90+
return children
9291

9392
return extract_text(slate_data)

0 commit comments

Comments
 (0)