优化markdown2html函数

This commit is contained in:
Meekdai 2024-03-13 10:03:18 +08:00
parent 519af2d118
commit 7a13c48a9d

View File

@ -78,13 +78,15 @@ class GMEEK():
def get_repo(self,user:Github, repo:str): def get_repo(self,user:Github, repo:str):
return user.get_repo(repo) return user.get_repo(repo)
def markdown2html(self,mdstr): def markdown2html(self, mdstr):
payload = {"text": mdstr, "mode": "gfm"} payload = {"text": mdstr, "mode": "gfm"}
ret=requests.post("https://api.github.com/markdown", json=payload,headers={"Authorzation":"token {}".format(self.options.github_token)}) headers = {"Authorization": "token {}".format(self.options.github_token)}
if ret.status_code==200: try:
return ret.text response = requests.post("https://api.github.com/markdown", json=payload, headers=headers)
else: response.raise_for_status() # Raises an exception if status code is not 200
raise Exception("markdown2html error status_code=%d"%(ret.status_code)) return response.text
except requests.RequestException as e:
raise Exception("markdown2html error: {}".format(e))
def renderHtml(self,template,blogBase,postListJson,htmlDir): def renderHtml(self,template,blogBase,postListJson,htmlDir):
file_loader = FileSystemLoader('templates') file_loader = FileSystemLoader('templates')