editor.py 文件源码

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

项目:txt2evernote 作者: Xunius 项目源码 文件源码
def checklistInENMLtoSoup(soup):
        '''
        Transforms Evernote checklist elements to github `* [ ]` task list style
        '''
        transform_tags = ['p','div']

        # soup.select cant be used with dashes: https://bugs.launchpad.net/beautifulsoup/+bug/1276211
        for todo in soup.find_all('en-todo'):
            parent = todo.parent
            transform = parent.find() == todo and parent.name in transform_tags

            checked = todo.attrs.get('checked',None) == "true"
            todo.replace_with("[x] " if checked else "[ ] ")

            # EN checklist can appear anywhere, but if they appear at the beggining
            # of a block element, transform it so it ressembles github markdown syntax
            if transform:
                content = ''.join(unicode(child) for child in parent.children
                    if isinstance(child, NavigableString)
                ).strip()

                new_tag = soup.new_tag("li")
                new_tag.string = content
                parent.replace_with(new_tag)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号