2 from pathlib
import Path
19 EQ_PATTERN = re.compile(
r'!eq\[([^\]]+)\]')
20 doc_folder = Path(
'doc')
21 src_files = [p
for p
in doc_folder.iterdir()
if p.suffix ==
'.md']
22 existing_gifs = [p
for p
in doc_folder.iterdir()
if p.suffix ==
'.gif']
23 gifs_to_remove = set(existing_gifs)
25 for src_file
in src_files:
27 with open(src_file)
as f:
29 m = EQ_PATTERN.search(s)
32 img_filename = doc_folder / (
clean(equation) +
'.gif')
33 if not img_filename.exists():
34 url =
'http://latex.codecogs.com/gif.download?' + equation
35 print(
'\t{} => {}'.format(m.group(0), img_filename))
36 img = requests.get(url)
37 with open(img_filename,
'wb')
as f:
39 if img_filename
in gifs_to_remove:
40 gifs_to_remove.remove(img_filename)
41 s = s.replace(m.group(0),
'![%s](%s)' % (equation, img_filename))
42 m = EQ_PATTERN.search(s)
44 with open(src_file.name,
'w')
as f:
47 for gif_to_remove
in gifs_to_remove:
48 print(
'Deleting {}'.format(gif_to_remove))
49 gif_to_remove.unlink()