Skip to content

Instantly share code, notes, and snippets.

@RyujiAMANO
Last active March 10, 2024 08:39
Show Gist options
  • Save RyujiAMANO/2918dc49cfe18409560b148558a24821 to your computer and use it in GitHub Desktop.
Save RyujiAMANO/2918dc49cfe18409560b148558a24821 to your computer and use it in GitHub Desktop.
sb2md.py
#!/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