Compare commits

...

2 Commits

Author SHA1 Message Date
acc8beb3be update README #7 2017-01-09 15:14:38 +11:00
9206b6de62 auto open up preview window #7 2017-01-09 15:08:13 +11:00
7 changed files with 35 additions and 5 deletions

View File

@ -6,5 +6,13 @@
{
"caption": "MarkdownLivePreview: Clear Cache",
"command": "markdown_live_preview_clear_cache"
},
{
"caption": "Preferences: MarkdownLivePreview Settings",
"command": "edit_settings",
"args": {
"base_file": "${packages}/MarkdownLivePreview/.sublime/MarkdownLivePreview.sublime-settings",
"default": "// Your settings for MarkdownLivePreview. See the default file to see the different options. \n{\n\t$0\n}\n"
}
}
]

View File

@ -1,3 +1,4 @@
{
"markdown_live_preview_on_open": false,
"load_from_internet_when_starts": ["http://", "https://"]
}

View File

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>name</key>
<string>MarkdownLivePreview</string>
<string>MarkdownLivePreviewSyntax</string>
<key>patterns</key>
<array>

View File

@ -36,7 +36,7 @@ def create_preview(window, file_name):
preview.set_name(get_preview_name(file_name))
preview.set_scratch(True)
preview.set_syntax_file('Packages/MarkdownLivePreview/.sublime/'
'MarkdownLivePreview.hidden-tmLanguage')
'MarkdownLivePreviewSyntax.hidden-tmLanguage')
return preview

View File

@ -17,7 +17,8 @@ class NewMarkdownLivePreviewCommand(sublime_plugin.ApplicationCommand):
file_name = current_view.file_name()
current_view.close()
if file_name is None:
return sublime.error_message('Not supporting unsaved file for now')
return sublime.error_message('MarkdownLivePreview: Not supporting '
'unsaved file for now')
sublime.run_command('new_window')
self.window = sublime.active_window()
@ -43,8 +44,6 @@ class NewMarkdownLivePreviewCommand(sublime_plugin.ApplicationCommand):
class MarkdownLivePreviewListener(sublime_plugin.EventListener):
def update(self, view):
if not is_markdown_view(view): # faster than getting the settings
return
vsettings = view.settings()
if not vsettings.get(PREVIEW_ENABLED):
return
@ -59,16 +58,32 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
return view, preview
def on_modified(self, view):
if not is_markdown_view(view): # faster than getting the settings
return
self.update(view)
def on_window_command(self, window, command, args):
if command == 'close' and window.settings().get(PREVIEW_WINDOW):
return 'close_window', {}
def on_activated_async(self, view):
vsettings = view.settings()
if (is_markdown_view(view)
and get_settings().get('markdown_live_preview_on_open')
and not vsettings.get(PREVIEW_ENABLED)
and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/'
'.sublime/MarkdownLivePreviewSyntax'
'.hidden-tmLanguage'):
sublime.run_command('new_markdown_live_preview')
def on_load_async(self, view):
"""Check the settings to hide menu, minimap, etc"""
try:
md_view, preview = self.update(view)
except TypeError:
# the function update has returned None
return
window = preview.window()
psettings = preview.settings()

View File

@ -4,6 +4,7 @@ Fast:
☐ cache image in object when used, so that it's faster @needsTest
☐ add clear cache command
☐ update README for settings in view
☐ add edit settings
Medium:
☐ auto refresh preview if loading images

View File

@ -25,6 +25,11 @@ It will open a new window, with only your markdown file, with the preview. Once
*Notice that it will close the entire window if you close **whichever** file. It means that if you open a random file in this window, and then close it, it'll close the entire window still*
### Settings
- `markdown_live_preview_on_open`: if set to `true`, as soon as you open a markdown file, the preview window will popup (thanks to [@ooing](https://github.com/ooing) for it's [suggestion](https://github.com/math2001/MarkdownLivePreview/issues/7#issue-199464852)). Default to `false`
- `load_from_internet_when_starts`: every images that starts with any of the string specified in this list will be loaded from internet. Default to `["http://", "https://"]`
### In dev
This plugin is not finished, there's still some things to fix (custom css, focus, etc). So, don't run away if you have any trouble, just submit an issue [here](http://github.com/math2001/MarkdownLivePreview/issues).