Skip to content

Commit

Permalink
remove unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
transcental committed Dec 1, 2024
1 parent bc21a36 commit d7e5783
Showing 1 changed file with 0 additions and 169 deletions.
169 changes: 0 additions & 169 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,175 +59,6 @@ def rich_text_to_md(input_data, indent_level=0, in_quote=False):
return markdown


def md_to_rich_text(md):
rich_text = []

# Convert code blocks
code_block_pattern = re.compile(r"```(.*?)```", re.DOTALL)
md = code_block_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_preformatted",
"elements": [{"type": "text", "text": m.group(1)}],
}
)
or "",
md,
)

# Convert blockquotes
blockquote_pattern = re.compile(r"^> (.*)", re.MULTILINE)
md = blockquote_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_quote",
"elements": [{"type": "text", "text": m.group(1)}],
}
)
or "",
md,
)

# Convert unordered lists
unordered_list_pattern = re.compile(r"^\s*-\s+(.*)", re.MULTILINE)
md = unordered_list_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_list",
"style": "bullet",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": m.group(1)}],
}
],
}
)
or "",
md,
)

# Convert ordered lists
ordered_list_pattern = re.compile(r"^\s*\d+\.\s+(.*)", re.MULTILINE)
md = ordered_list_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_list",
"style": "numbered",
"elements": [
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": m.group(1)}],
}
],
}
)
or "",
md,
)

# Convert inline code
inline_code_pattern = re.compile(r"`(.*?)`")
md = inline_code_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_section",
"elements": [
{"type": "text", "text": m.group(1), "style": {"code": True}}
],
}
)
or "",
md,
)

# Convert bold and italic text
bold_italic_pattern = re.compile(r"\*\*\*(.*?)\*\*\*")
md = bold_italic_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": m.group(1),
"style": {"bold": True, "italic": True},
}
],
}
)
or "",
md,
)

bold_pattern = re.compile(r"\*\*(.*?)\*\*")
md = bold_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_section",
"elements": [
{"type": "text", "text": m.group(1), "style": {"bold": True}}
],
}
)
or "",
md,
)

italic_pattern = re.compile(r"\*(.*?)\*")
md = italic_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_section",
"elements": [
{"type": "text", "text": m.group(1), "style": {"italic": True}}
],
}
)
or "",
md,
)

# Convert strikethrough text
strikethrough_pattern = re.compile(r"~~(.*?)~~")
md = strikethrough_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_section",
"elements": [
{"type": "text", "text": m.group(1), "style": {"strike": True}}
],
}
)
or "",
md,
)

# Convert links
link_pattern = re.compile(r"\[(.*?)\]\((.*?)\)")
md = link_pattern.sub(
lambda m: rich_text.append(
{
"type": "rich_text_section",
"elements": [{"type": "link", "url": m.group(2), "text": m.group(1)}],
}
)
or "",
md,
)

# Convert plain text
if md.strip():
rich_text.append(
{
"type": "rich_text_section",
"elements": [{"type": "text", "text": md.strip()}],
}
)

return rich_text


def md_to_mrkdwn(md):
# Convert bold and italic text (bold first to avoid conflicts)
md = re.sub(r"\*\*\*(.*?)\*\*\*", r"***\1***", md) # Bold and italic
Expand Down

0 comments on commit d7e5783

Please sign in to comment.