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

16
Default.sublime-keymap Normal file
View File

@ -0,0 +1,16 @@
[
{
"keys": ["alt+m"],
"command": "toggle_setting",
"args": {
"setting": "markdown_preview_enabled"
},
"context": [
{
"key": "selector",
"operator": "equal",
"operand": "text.html.markdown"
}
]
}
]

31
README.md Normal file
View File

@ -0,0 +1,31 @@
# MarkdownLivePreview
This is a sublime text **3** plugin that allows you to preview your markdown insensately *in* it!
### Dependencies
**None**! There is no dependency! It uses [markdown2](https://github.com/trentm/python-markdown2) but it's a one file plugin, so it's included in the package.
## Installation
Although MarkdownLivePreview is not available on the default channel of [PackageControl](http://packagecontrol.io), you can still use it to download this little package.
1. Open the command palette (`ctrl+shift+p`)
2. Search for: `Package Control: Add Repository`
3. Enter in the input at the bottom of ST the path to this repo: <https://github.com/math2001/MarkdownLivePreview> (tip: just drag the link in)
4. Hit <kbd>enter</kbd>
What this does is simply adding this repo to the list of packages you get when you install a package using PC.
So, as you probably understood, now you just need to install MarkdownLivePreview as if it was available on the default channel:
1. Open the command palette (`ctrl+shift+p`)
2. Search for: `Package Control: Install Package`
3. Search for: `MarkdownLivePreview`
4. hit <kbd>enter</kbd>
Done!
### How to open the [README](http://github.com/math2001/MarkdownLivePreview/README.md)
Some of the package add a command in the menus, others in the command palette, or other nowhere. None of those options are really good, especially the last one on ST3 because the packages are compressed. But, fortunately, there is plugin that exists and **will solve this problem** for us (and he has a really cute name, don't you think?): [ReadmePlease](https://packagecontrol.io/packages/ReadmePlease).

2612
markdown2.py Normal file

File diff suppressed because it is too large Load Diff

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)

14
sample.md Normal file
View File

@ -0,0 +1,14 @@
# hello world
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
> Explicit is better than implicit
hello
hi
This is *awsome*, yes!
I love it so much

5
todo.md Normal file
View File

@ -0,0 +1,5 @@
# todo
Add a key binding hello world
This is awesome!