parser.py 文件源码

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

项目:mfnf-pdf-export 作者: Lodifice 项目源码 文件源码
def transform_template(self, obj):
            if obj["name"].startswith("#lst:"):
                article_name = remove_prefix(obj["name"], "#lst:")
                article = self.api.get_content(article_name)

                section_name = obj["params"]["1"]
                begin = r"\<section\s+begin\=[\"']?" + re.escape(section_name) + \
                        r"[\"']?\s*\/>"
                end = r"\<section\s+end\=[\"']?" + re.escape(section_name) + \
                        r"[\"']?\s*\/\>"

                section = re.search(begin + "(.*)" + end, article, re.DOTALL)

                if section:
                    section = section.group(1).strip()
                    content = parse_content(self.api, self.title, section)

                    return {"type": "included_section", "content": content}
                else:
                    message = "section '{}' of '{}' cannot be included" \
                              .format(section_name, article_name)

                    return {"type": "error", "message": message}
            else:
                raise NotInterested()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号