Last active
January 12, 2024 15:08
-
-
Save Neel738/06912a2ecbbad0679c7153b06afe810e to your computer and use it in GitHub Desktop.
do this if u wanna export from bubble
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| def handle_bold(text): | |
| return ( | |
| text.replace("[b]", "**") | |
| .replace("[/b]", "**") | |
| .replace("[B]", "**") | |
| .replace("[/B]", "**") | |
| ) | |
| def handle_italic(text): | |
| return ( | |
| text.replace("[i]", "*") | |
| .replace("[/i]", "*") | |
| .replace("[I]", "*") | |
| .replace("[/I]", "*") | |
| ) | |
| def handle_underline(text): | |
| return ( | |
| text.replace("[u]", "<u>") | |
| .replace("[/u]", "</u>") | |
| .replace("[U]", "<u>") | |
| .replace("[/U]", "</u>") | |
| ) | |
| def handle_subscript(text): | |
| return ( | |
| text.replace("[sub]", "<sub>") | |
| .replace("[/sub]", "</sub>") | |
| .replace("[SUB]", "<sub>") | |
| .replace("[/SUB]", "</sub>") | |
| ) | |
| def handle_size(text): | |
| # Simple size to header conversion (assuming size 4 to h2, adjust as needed) | |
| return re.sub( | |
| r"\[size=(\d+)\](.*?)\[/size\]", | |
| lambda m: "#" * (6 - int(m.group(1))) + " " + m.group(2), | |
| text, | |
| flags=re.IGNORECASE, | |
| ) | |
| def handle_list(text): | |
| text = text.replace("[list]", "\n").replace("[/list]", "") | |
| return re.sub(r"\[\*\]", "- ", text, flags=re.IGNORECASE) | |
| def handle_indent(text): | |
| # Markdown doesn't support indent, so we'll just remove these tags | |
| return ( | |
| text.replace("[indent]", "") | |
| .replace("[/indent]", "") | |
| .replace("[INDENT]", "") | |
| .replace("[/INDENT]", "") | |
| ) | |
| def handle_font(text): | |
| # Markdown doesn't support font changes, so we'll just remove these tags | |
| return re.sub(r"\[font=.*?\]", "", text, flags=re.IGNORECASE).replace("[/font]", "") | |
| def handle_url(text): | |
| return re.sub(r"\[url=(.*?)\](.*?)\[/url\]", r"[\2](\1)", text, flags=re.IGNORECASE) | |
| def bbcode_to_markdown(text): | |
| text = handle_bold(text) | |
| text = handle_italic(text) | |
| text = handle_underline(text) | |
| text = handle_subscript(text) | |
| text = handle_size(text) | |
| text = handle_list(text) | |
| text = handle_indent(text) | |
| text = handle_font(text) | |
| text = handle_url(text) | |
| return text | |
| import json | |
| with open("posts_from_bubble.json", "r") as f: | |
| posts = json.load(f) | |
| for post in posts: | |
| post["content"] = bbcode_to_markdown(post["content"]) | |
| with open("mdposts.json", "w") as f: | |
| json.dump(posts, f, indent=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment