-
Notifications
You must be signed in to change notification settings - Fork 0
/
roam_to_org.py
31 lines (24 loc) · 1.1 KB
/
roam_to_org.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# for f in `ls *.md`; do \n\n\n\tpandoc -f markdown -t org -o ${f}.org ${f};\ndone
import os, subprocess
path = '.'
# folder = os.fsencode(path)
# for file in os.listdir(folder):
# filename = os.fsdecode(file)
with os.scandir(path) as it:
for file in it:
filename = os.fsdecode(file)
if '.md' not in filename:
continue
subprocess.run(['pandoc', '-f', 'markdown', '-t', 'org', '-o', f'{filename[:-3]}.org', f'{filename}'],
shell=True)
# with tempfile.NamedTemporaryFile('w', delete=False) as outfile:
# outfile.write(f'# {filename[2:]}\n') #start the file with it's title like in Roam
# with open(filename, 'r+') as f:
# for line in f:
# line = line.replace("- ", "", 1) #removes Roam's - that break zettlr headgings
# line = line.replace('$$', '$') #fixes latex
# line = line.replace('# ', '### ', 1) #Zettlr's headgings are too big
# line = line.replace("{{[[DONE]]}}", "- [x]") #Done becomes a completed task
# line = line.replace("{{[[TODO]]}}", "- [ ]") #Todo becomes an incomplete task
# outfile.write(line)
# os.rename(outfile.name, filename)