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)
评论列表
文章目录