#!/usr/bin/env python3 # coding: utf8 # # Generate all-in-one Markdown file for ``doc-cn`` # Tip: 不支持中文文件名 # readme.md 中的目录引用的md多次(或者md的sub heading),以第一次出现为主 from __future__ import print_function, unicode_literals import re import os followups = [] in_toc = False contents = [] hyper_link_pattern = re.compile(r'\[(.*?)\]\((.*?)(#.*?)?\)') toc_line_pattern = re.compile(r'([\-\+]+)\s\[(.*?)\]\((.*?)(#.*?)?\)') image_link_pattern = re.compile(r'!\[(.*?)\]\((.*?)\)') level_pattern = re.compile(r'(\s*[\-\+]+)\s') # match all headings heading_patthern = re.compile(r'(^#+|\n#+)\s') # match copyable snippet code copyable_snippet_pattern = re.compile(r'{{< copyable .* >}}') entry_file = "TOC.md" # stage 1, parse toc with open(entry_file) as fp: level = 0 current_level = "" for line in fp: if not in_toc and not line.startswith("