Skip to content

Commit

Permalink
cherry pick #4281 to release-3.0 (#4283)
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>

Co-authored-by: Yini Xu <34967660+YiniXu9506@users.noreply.github.com>
  • Loading branch information
ti-srebot and YiniXu9506 authored Nov 25, 2020
1 parent 1f2bc3b commit 0c820d5
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions scripts/merge_by_toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
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"

Expand Down Expand Up @@ -138,14 +140,9 @@ def replace_heading(match):

return replace_heading

def replace_img_link(match):
full = match.group(0)
link_name = match.group(1)
link = match.group(2)

if link.endswith('.png'):
fname = os.path.basename(link)
return '![%s](./media/%s)' % (link_name, fname)
# remove copyable snippet code
def remove_copyable(match):
return ''

# stage 3, concat files
for type_, level, name in followups:
Expand All @@ -158,7 +155,7 @@ def replace_img_link(match):
with open(name) as fp:
chapter = fp.read()
chapter = replace_link_wrap(chapter, name)
# chapter = image_link_pattern.sub(replace_img_link, chapter)
chapter = copyable_snippet_pattern.sub(remove_copyable, chapter)

# fix heading level
diff_level = level - heading_patthern.findall(chapter)[0].count('#')
Expand Down

0 comments on commit 0c820d5

Please sign in to comment.