MLPApi.py 文件源码

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

项目:MarkdownLivePreview 作者: math2001 项目源码 文件源码
def show_html(md_view, preview):
    global windows_phantom_set
    html = markdown2html(get_view_content(md_view), os.path.dirname(md_view.file_name()), md_view.settings().get('color_scheme'))

    phantom_set = windows_phantom_set.setdefault(preview.window().id(),
                                             sublime.PhantomSet(preview, 'markdown_live_preview'))
    phantom_set.update([sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK,
                                    lambda href: sublime.run_command('open_url', {'url': href}))])

    # lambda href: sublime.run_command('open_url', {'url': href})
    # get the "ratio" of the markdown view's position.
    # 0 < y < 1
    y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1]
    # set the vector (position) for the preview
    vector = [0, y * preview.layout_extent()[1]]
    # remove half of the viewport_extent.y to center it on the screen (verticaly)
    vector[1] -= preview.viewport_extent()[1] / 2
    # make sure the minimum is 0
    vector[1] = 0 if vector[1] < 0 else vector[1]
    # the hide the first line
    vector[1] += preview.line_height()
    preview.set_viewport_position(vector, animate=False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号