import sublime
import sublime_plugin
from sublimetools import *
import html
from . import markdown2
class MarkdownInPopupCommand(sublime_plugin.EventListener):
def run(self, view):
view.show_popup('
hello
', sublime.HIDE_ON_MOUSE_MOVE_AWAY, 1)
return
ph = sublime.Phantom(sublime.Region(0), " hello
", sublime.LAYOUT_INLINE, None)
ph_set = sublime.PhantomSet(sublime.active_window().active_view(), 'tests')
ph_set.update([ph])
def get_view_content(self, view):
return view.substr(sublime.Region(0, view.size()))
def on_modified(self, current_view):
current_view_settings = current_view.settings()
if 'markdown' not in current_view_settings.get('syntax').lower():
return
if current_view_settings.get('markdown_preview_enabled', False) is not True:
return
w = current_view.window()
html = """"""
html += markdown2.markdown(self.get_view_content(current_view))
view_id = current_view_settings.get('markdown_preview_id', None)
def create_preview_panel():
preview = w.new_file()
w.run_command('new_pane')
view_id = preview.id()
current_view_settings.set('markdown_preview_id', view_id)
return preview
def show_html(view, html):
view.settings().set('gutter', False)
view.erase_phantoms('markdown_preview')
self.phantom_id = view.add_phantom('markdown_preview',
sublime.Region(0),
html,
sublime.LAYOUT_INLINE,
lambda href: sublime.run_command('open_url', {'url': href}))
for view in w.views():
if view.id() == view_id:
show_html(view, html)
break
else:
preview = create_preview_panel()
show_html(preview, html)
# class MarkdownInPopupCommand(sublime_plugin.EventListener):
class MarkdownInPopupCommandc:
def update_phantom(self, content, preview_view):
ph = sublime.Phantom(sublime.Region(0), content, sublime.LAYOUT_BLOCK)
self.phantom_set.update([ph])
def on_modified(self, view):
content = """
"""
content += markdown2.markdown(view.substr(sublime.Region(0, view.size())))
# self.update_phantom(content)