AnkiConnect.py 文件源码

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

项目:anki-connect 作者: FooSoft 项目源码 文件源码
def modelFieldsOnTemplates(self, modelName):
        model = self.collection().models.byName(modelName)

        if model is not None:
            templates = {}
            for template in model['tmpls']:
                fields = []

                for side in ['qfmt', 'afmt']:
                    fieldsForSide = []

                    # based on _fieldsOnTemplate from aqt/clayout.py
                    matches = re.findall('{{[^#/}]+?}}', template[side])
                    for match in matches:
                        # remove braces and modifiers
                        match = re.sub(r'[{}]', '', match)
                        match = match.split(":")[-1]

                        # for the answer side, ignore fields present on the question side + the FrontSide field
                        if match == 'FrontSide' or side == 'afmt' and match in fields[0]:
                            continue
                        fieldsForSide.append(match)


                    fields.append(fieldsForSide)

                templates[template['name']] = fields

            return templates
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号