之前打HTB靶场时,我用语雀记录了一些笔记,但是在导出为md文件时,却出现了图片无法显示的问题。
在语雀的右上角,可以将文档导出为Markdown文件
但是导出为md后,默认的Markdown工具是无法显示图片的(如Typora),这里会在png的后面加一串字符串。
因此我们可以写一个脚本来修改图片地址。
// yq_fix_md_pics.py
// Author: David Wu
import os
import re
import sys
import argparse
def rewrite_file(filename):
with open(filename, 'r', encoding='utf-8', errors='igonre') as f:
text = f.read()
text = re.sub(r'png#(.*)+', 'png)', text)
with open(filename, 'w+', encoding='utf-8', errors='igonre') as f:
f.write(text)
def fix_md_files(path):
for filename in os.listdir(path):
rewrite_file(path + '\\' + filename)
def fix_specified_md_file(filename):
rewrite_file(filename)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Fix wrong pictures\' type of md file(s) from yuque.\nNote: If your string has spaces, you need to enclose it in double quotes.')
parser.add_argument('-p', '--path', type=str, dest='path', help='Path where your md files are loacted')
parser.add_argument('-m', '--md', type=str, dest='md', help='Specify the md file you wanna fix.')
args = parser.parse_args()
if args.path != None and args.md != None:
sys.exit('You must input just one argument like -p path or -m mdfile. \ne.g. python3 yq_fix_md_pics.py -p C:\\Test')
if args.path != None:
fix_md_files(args.path)
sys.exit(0)
if args.md != None:
fix_specified_md_file(args.md)
sys.exit(0)
用法:
第一种:直接修改该目录下的所有.md文件内的图片格式。
python3 yq_fix_md_pics.py -p C:\Test
python3 yq_fix_md_pics.py --path C:\Test
第二种:修改单个md文件
python3 yq_fix_md_pics.py -m C:\Test\a.md
python3 yq_fix_md_pics.py --md C:\Test\a.md
如果出什么错误,欢迎大家在评论区交流。