From 34834cdc2420ab51c4f4041dd18bd63f70aae02c Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 11 Mar 2023 19:41:01 +0800 Subject: [PATCH] fix: markdown escape characters --- src/release/gitbook.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/release/gitbook.py b/src/release/gitbook.py index 907f668..177d90c 100755 --- a/src/release/gitbook.py +++ b/src/release/gitbook.py @@ -18,10 +18,22 @@ def initFolder() -> None: createFolder(os.path.join(releaseInfo['gitbookDir'], './content/')) +def markdownTransfer(content: str) -> str: + symbols = [ + '\\', '`', '*', '_', '~', + '{', '}', '[', ']', '(', ')', + '#', '+', '-', '.', '!', '|', + ] + for symbol in symbols: + content = content.replace(symbol, '\\' + symbol) # add `\` before symbol + return content + + def loadChapter(caption: str, content: list) -> str: chapterNum = re.search(r'^第(\d+)章', caption)[1] chapterNum = '0' * (3 - len(chapterNum)) + chapterNum # add `0` prefix fileName = 'chapter-%s.md' % chapterNum + content = [markdownTransfer(x) for x in content] saveFile( os.path.join(releaseInfo['gitbookDir'], './content/', fileName), '# %s\n\n%s\n' % (caption, '\n\n'.join(content))