From 8394e18f4ec6b5b045cf74422b13b1354c34df2a Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 27 Jan 2021 17:39:10 +0800 Subject: [PATCH] bugfix --- ahserver/baseProcessor.py | 33 +++++---------------------------- 1 file changed, 5 insertions(+), 28 deletions(-) diff --git a/ahserver/baseProcessor.py b/ahserver/baseProcessor.py index 52aba68..bef7669 100644 --- a/ahserver/baseProcessor.py +++ b/ahserver/baseProcessor.py @@ -174,36 +174,13 @@ class MarkdownProcessor(BaseProcessor): data = '' with codecs.open(self.real_path,'rb','utf-8') as f: data = f.read() - b = data - b = self.urlreplace(b,request) - ret = { - "__widget__":"markdown", - "data":{ - "md_text":b - } - } - config = getConfig() - self.content = json.dumps(ret,indent=4) + self.content = self.urlreplace(data, request) def urlreplace(self,mdtxt,request): - def replaceURL(s): - p1 = '\[.*?\]\((.*?)\)' - url = re.findall(p1,s)[0] - txts = s.split(url) - url = self.resource.absUrl(request,url) - return url.join(txts) - - p = '\[.*?\]\(.*?\)' - textarray = re.split(p,mdtxt) - links = re.findall(p,mdtxt) - newlinks = [ replaceURL(link) for link in links] - if len(links)>0: - mdtxt = '' - for i in range(len(newlinks)): - mdtxt = mdtxt + textarray[i] - mdtxt = mdtxt + newlinks[i] - mdtxt = mdtxt + textarray[i+1] - return mdtxt + p = '\[(.*)\]\((.*)\)' + return re.sub(p, + lambda x:'['+x.group(1)+'](' + self.resource.entireUrl(request, x.group(2)) + ')', + mdtxt) def getProcessor(name): return _getProcessor(BaseProcessor,name)