thoughts/move_links.py
Tommy Skaug 7153372aed
All checks were successful
Export / Explore-GitHub-Actions (push) Successful in 33s
chore: add missing scripts
2024-08-05 22:16:30 +02:00

30 lines
562 B
Python

#!/usr/bin/python3
import sys
import re
lines = ''.join(sys.stdin.readlines())
link = re.compile("(\[[^\]]*\]\([^\)]+\))")
link_split = re.compile("\[([^\]]*)\]\(([^\)]+)\)")
marginnotes = re.compile("(\[\^.*?\]\:.*?\n\n)",re.DOTALL|re.MULTILINE)
_lines = marginnotes.sub("",lines)
lines = _lines
links = link.findall(lines)
i = 1
for _link in links:
lines = lines.replace(_link, "[%s]"%i)
i+=1
i = 1
lines += "\n\n"
for _link in links:
ls = link_split.match(_link)
lines += "=> %s %s\n"%(ls[2],ls[1])
i += 1
sys.stdout.write(lines)