preview.py 文件源码

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

项目:RST-vscode 作者: tht13 项目源码 文件源码
def main(argv=None):
    # Some sanity checks on if the path exists.
    filepath = argv[1] if argv is not None else sys.argv[1]
    filepath = os.path.abspath(filepath)
    if not os.path.exists(filepath):
        return 'File Not Found'

    # open in binary, decode utf-8, and live in unicode
    with codecs.open(filepath, 'r', 'utf8') as f:
        page_string = f.read()

    overrides = {
        'initial_header_level': 1,
        'halt_level': 5,
    }

    parts = core.publish_parts(
        source=page_string,
        source_path=filepath,
        writer_name='html',
        settings_overrides=overrides,
    )

    html_document = parts['html_body']
    html_document = html_document.replace('\ufeff', '')

    # the REAL print function in python 2, now... see top of file
    print(html_document)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号