Browse Source

fix: markdown escape characters

master
Dnomd343 2 years ago
parent
commit
34834cdc24
  1. 12
      src/release/gitbook.py

12
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))

Loading…
Cancel
Save