-
-
Save chkk525/3dcdffc5b6a4441b5f618a12398a63f7 to your computer and use it in GitHub Desktop.
Convert Scrapbox export file to Markdown files for Obsidian
This file contains 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 json | |
import os | |
import re | |
os.makedirs('./scrapbox', exist_ok=True) | |
json_open = open('./motto_19700119_222252.json', 'r') | |
data = json.load(json_open) | |
pages = data["pages"] | |
for entry in pages: | |
page = entry["lines"] | |
title = entry["title"].replace('/', '-') | |
path_w = './scrapbox/'+title+'.md' | |
file = open(path_w, mode='w') | |
for lines in page: | |
## Heading 1-4 | |
lines = re.sub(r'\[([\*]+?) (.+?)\]', r'\1 \2', lines) | |
lines = re.sub(r'\*\*\* ', '# ', lines) | |
lines = re.sub(r'\*\* ', '## ', lines) | |
lines = re.sub(r'\* ', '### ', lines) | |
## Indent (\t => -) | |
lines = re.sub(r'^ ', r'- ', lines) | |
lines = re.sub(r'^- \t\t\t\t', r'----- ', lines) | |
lines = re.sub(r'^- \t\t\t', r'---- ', lines) | |
lines = re.sub(r'^- \t\t', r'--- ', lines) | |
lines = re.sub(r'^- \t', r'-- ', lines) | |
## [] => [[]] | |
lines = lines.replace('[', '[[') | |
lines = lines.replace(']', ']]') | |
## Gyazo URLs | |
lines = re.sub(r'(\[https:\/\/gyazo.+?\])(\[https:\/\/gyazo.+?\])', r'\1\n\2', lines) | |
lines = re.sub(r'\[\[https:\/\/gyazo.com\/(.+?)\]\]', r'![Gyazo Image](https://i.gyazo.com/\1/raw)', lines) | |
## Exteral URLs | |
lines = re.sub(r'\[\[(.+?) (http.+?)\]\]', r'[\1](\2)', lines) | |
file.write(lines+'\n') | |
file.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment