1 Star 11 Fork 6

jianjun/interview_internal_reference

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
sync_link 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
lee 提交于 2019-10-15 16:57 . revert latest push
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: ileler@qq.com
import re
from shutil import move
from urllib import parse
from pathlib import Path
class REMatcher(object):
def __init__(self, matchstring):
self.matchstring = matchstring
def match(self,regexp):
self.rematch = re.match(regexp, self.matchstring)
return bool(self.rematch)
def group(self,i):
return self.rematch.group(i)
def get_path(name):
try:
files = Path('./').glob('**/%s.md' % name)
for file in files:
return str(file)
except:
pass
return None
prefix = '##### '
filepath = './README.md'
temppath = filepath + '.tmp'
with open(filepath, 'r') as lines:
with open(temppath, 'w') as file:
for line in lines:
m1 = REMatcher(line)
if not m1.match(r'%s(.*)' % prefix):
file.write(line)
continue
name = m1.group(1)
m2 = REMatcher(name)
if m2.match(r'\[(.*)\]\((.*)\)'):
name = m2.group(1)
path = get_path(name)
file.write(('%s[%s](%s)\n' % (prefix, name, parse.quote(path))) if path else line)
move(temppath, filepath)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jianjun5277/interview_internal_reference.git
git@gitee.com:jianjun5277/interview_internal_reference.git
jianjun5277
interview_internal_reference
interview_internal_reference
master

搜索帮助