读取并解析markdown文件,返回内容二级标题及其子标题 :param file_path: markdown文件路径 :return: 字典,key为二级标题,value为其下的子标题列表 注:只返回包含子标题的部分
(file_path)
| 197 | f2.write(new_content2) |
| 198 | |
| 199 | def read_md(file_path): |
| 200 | """ |
| 201 | 读取并解析markdown文件,返回内容二级标题及其子标题 |
| 202 | :param file_path: markdown文件路径 |
| 203 | :return: 字典,key为二级标题,value为其下的子标题列表 |
| 204 | 注:只返回包含子标题的部分 |
| 205 | """ |
| 206 | with open(file_path, 'r', encoding="utf-8") as f: |
| 207 | file_content = f.read() |
| 208 | origin_content = parse_md(file_content) |
| 209 | # 过滤掉没有子标题的部分 |
| 210 | new_content = {key: value for key, value in origin_content.items() if value} |
| 211 | return new_content |
| 212 | |
| 213 | def parse_md(file_content): |
| 214 | """ |
no test coverage detected