71 lines
1.4 KiB
Python
71 lines
1.4 KiB
Python
#!/usr/bin/env python
|
||
# coding: utf-8
|
||
|
||
# In[ ]:
|
||
|
||
|
||
import numpy as np
|
||
import pandas as pd
|
||
import re
|
||
import os
|
||
import subprocess
|
||
import io
|
||
|
||
|
||
# In[ ]:
|
||
|
||
|
||
os.system("dir .\*.md /B /S > mdfiles.txt")
|
||
|
||
|
||
# In[ ]:
|
||
|
||
|
||
# Поочерёдно открываем файлы, указанные в mdfiles.txt
|
||
# Заменяем содержимое с помощью функции:
|
||
def replace_zoom_img(markdown):
|
||
|
||
pattern = re.compile(r'!\[(.*?)\]\((.*?)\){: .zoom}', flags=re.IGNORECASE)
|
||
|
||
markdown = re.sub(pattern,
|
||
r'<figure class="figure-image">\n' + \
|
||
r' <img src="\2" alt="\1" class="zoom">\n' + \
|
||
r' <figcaption>\1</figcaption>\n' + \
|
||
r'</figure>',
|
||
markdown)
|
||
|
||
return markdown
|
||
|
||
|
||
# In[ ]:
|
||
|
||
|
||
# Считываем названия файлов в список
|
||
with open('mdfiles.txt', encoding='cp866', errors='ignore') as f:
|
||
lines = []
|
||
for line in f:
|
||
lines.append(line)
|
||
|
||
|
||
# In[ ]:
|
||
|
||
|
||
# Отрезаем '\n' от всех строк
|
||
files = [p[:-1] for p in lines]
|
||
|
||
|
||
# In[ ]:
|
||
|
||
|
||
for mdf in files:
|
||
# Read in the file
|
||
with open(mdf, 'r', encoding='cp866', errors='ignore') as file :
|
||
filedata = file.read()
|
||
|
||
# Replace the target string
|
||
filedata = replace_zoom_img(filedata)
|
||
|
||
# Write the file out again
|
||
with open(mdf, 'w', encoding='cp866', errors='ignore') as file:
|
||
file.write(filedata)
|