backend.py 文件源码

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

项目:zotero-cli 作者: jbaiter 项目源码 文件源码
def _make_note(self, note_data):
        """ Converts a note from HTML to the configured markup.

        If the note was previously edited with zotcli, the original markup
        will be restored. If it was edited with the Zotero UI, it will be
        converted from the HTML via pandoc.

        :param note_html:       HTML of the note
        :param note_version:    Library version the note was last edited
        :returns:               Dictionary with markup, format and version
        """
        data = None
        note_html = note_data['data']['note']
        note_version = note_data['version']
        if "title=\"b'" in note_html:
            # Fix for badly formatted notes from an earlier version (see #26)
            note_html = re.sub(r'title="b\'(.*?)\'"', r'title="\1"', note_html)
            note_html = note_html.replace("\\n", "")
        blobs = DATA_PAT.findall(note_html)
        # Previously edited with zotcli
        if blobs:
            data = decode_blob(blobs[0])
            if 'version' not in data:
                data['version'] = note_version
            note_html = DATA_PAT.sub("", note_html)
        # Not previously edited with zotcli or updated from the Zotero UI
        if not data or data['version'] < note_version:
            if data and data['version'] < note_version:
                self._logger.info("Note changed on server, reloading markup.")
            note_format = data['format'] if data else self.note_format
            data = {
                'format': note_format,
                'text': pypandoc.convert(
                    note_html, note_format, format='html'),
                'version': note_version}
        return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号