From 7a13c48a9dc4c7e1643b99916ee243adb6a8a7ab Mon Sep 17 00:00:00 2001 From: Meekdai Date: Wed, 13 Mar 2024 10:03:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96markdown2html=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gmeek.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Gmeek.py b/Gmeek.py index 19ade9c..2a20bf4 100644 --- a/Gmeek.py +++ b/Gmeek.py @@ -78,13 +78,15 @@ class GMEEK(): def get_repo(self,user:Github, repo:str): return user.get_repo(repo) - def markdown2html(self,mdstr): + def markdown2html(self, mdstr): payload = {"text": mdstr, "mode": "gfm"} - ret=requests.post("https://api.github.com/markdown", json=payload,headers={"Authorzation":"token {}".format(self.options.github_token)}) - if ret.status_code==200: - return ret.text - else: - raise Exception("markdown2html error status_code=%d"%(ret.status_code)) + headers = {"Authorization": "token {}".format(self.options.github_token)} + try: + response = requests.post("https://api.github.com/markdown", json=payload, headers=headers) + response.raise_for_status() # Raises an exception if status code is not 200 + return response.text + except requests.RequestException as e: + raise Exception("markdown2html error: {}".format(e)) def renderHtml(self,template,blogBase,postListJson,htmlDir): file_loader = FileSystemLoader('templates')