postprocessing.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:geekbook 作者: mmagnus 项目源码 文件源码
def unhighlight(text):
    hits = re.findall(
        '<div class="highlight"><pre><span></span>(?P<text>.+?)</pre></div>', text, re.M | re.S)
    for h in hits:
        # print 'h',h.strip()
        if h.strip():
            if h.find('<span') == -1:  # it's note
                # print 'no span'
                h_and_context = re.findall(
                    r'<div class="highlight"><pre><span></span>' + re.escape(h) + '</pre></div>', text, re.M | re.S)
                if h_and_context:
                    h_and_context = h_and_context[0]
                    h_and_context_unhigh = h_and_context.replace(
                        '<div class="highlight">', '').replace('</pre></div>', '</pre>')
                    text = text.replace(h_and_context, h_and_context_unhigh)
            else:
                h_and_context = re.findall(
                    r'<div class="highlight"><pre><span></span>' + re.escape(h) + '</pre></div>', text, re.M | re.S)
                # print h_and_context
    return text
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号