Last active
March 10, 2024 08:39
-
-
Save RyujiAMANO/2918dc49cfe18409560b148558a24821 to your computer and use it in GitHub Desktop.
sb2md.py
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
#!/usr/bin/env python3 | |
import sys | |
import re | |
def scrapbox_to_markdown(): | |
scrapbox_text = sys.stdin.read() | |
markdown_text = "" | |
lines = scrapbox_text.split('\n') | |
for line in lines: | |
if line.startswith('\t'): | |
indent = len(line) - len(line.lstrip('\t')) | |
line = ' ' * (indent - 1) + '- ' + line.lstrip('\t') | |
# Replace [text url] to [text](url) | |
line = re.sub(r'\[([^]]*?) (.*?)\]', r'[\1](\2)', line) | |
markdown_text += line.replace("[", "[[").replace("]", "]]") + "\n" | |
return markdown_text | |
markdown_output = scrapbox_to_markdown() | |
print(markdown_output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment