This commit is contained in:
math2001
2016-11-24 18:18:02 +11:00
commit b573d96659
6 changed files with 2767 additions and 0 deletions

89
md_in_popup.py Normal file
View File

@ -0,0 +1,89 @@
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('<h1> hello </h1>', sublime.HIDE_ON_MOUSE_MOVE_AWAY, 1)
return
ph = sublime.Phantom(sublime.Region(0), "<h1> hello </h1>", 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 = """<style>
body {
padding:10px;
font-family: "Open Sans", sans-serif;
background-color: #fff;
font-size: 15px;
}
blockquote {
font-style: italic;
display: block;
margin-left: 20px;
border: 1px solid red;
}
</style>"""
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 = """
<style>
body {
margin:10px;
}
blockquote {
font-style: italic;
display: block;
margin: 10px;
}
</style>
"""
content += markdown2.markdown(view.substr(sublime.Region(0, view.size())))
# self.update_phantom(content)