Compare commits

...

7 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
cda4532833 update messages 2017-01-09 12:13:36 +11:00
ff8c94bda5 add clear cache command 2017-01-09 12:04:12 +11:00
ded9c28096 fix loading image with relative paths 2017-01-08 19:22:58 +11:00
0e6660a331 add settings for the preview.
Need to update the README
2017-01-08 17:44:17 +11:00
0143428114 update README installation part 2017-01-08 16:17:46 +11:00
12 changed files with 136 additions and 37 deletions

View File

@ -2,5 +2,17 @@
{
"caption": "MarkdownLivePreview: Edit Current File",
"command": "new_markdown_live_preview"
},
{
"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

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>MarkdownLivePreviewSyntax</string>
<key>patterns</key>
<array>
</array>
<key>scopeName</key>
<string>text.markdown-live-preview</string>
</dict>
</plist>

View File

@ -10,6 +10,7 @@ from .lib import markdown2 as md2
from .escape_amp import *
from .functions import *
from .setting_names import *
from .image_manager import CACHE_FILE
__folder__ = os.path.dirname(__file__)
@ -34,6 +35,8 @@ 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/'
'MarkdownLivePreviewSyntax.hidden-tmLanguage')
return preview
@ -47,12 +50,10 @@ def show_html(md_view, preview):
html.append(pre_with_br(md2.markdown(get_view_content(md_view),
extras=['fenced-code-blocks',
'no-code-highlighting'])))
html = '\n'.join(html)
# the option no-code-highlighting does not exists
# in the official version of markdown2 for now
# I personaly edited the file (markdown2.py:1743)
html = '\n'.join(html)
html = html.replace('&nbsp;', '&nbspespace;') # save where are the spaces
@ -62,7 +63,8 @@ def show_html(md_view, preview):
# exception, again, because <pre> aren't supported by the phantoms
html = html.replace('&nbspespace;', '<i class="space">.</i>')
html = replace_img_src_base64(html)
html = replace_img_src_base64(html, basepath=os.path.dirname(
md_view.file_name()))
preview.erase_phantoms('markdown_preview')
preview.add_phantom('markdown_preview',
sublime.Region(-1),
@ -81,3 +83,7 @@ def show_html(md_view, preview):
vector[1] = mini(vector[1], 0)
vector[1] += preview.line_height()
preview.set_viewport_position(vector, animate=False)
def clear_cache():
"""Removes the cache file"""
os.remove(CACHE_FILE)

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()
@ -42,9 +43,7 @@ class NewMarkdownLivePreviewCommand(sublime_plugin.ApplicationCommand):
class MarkdownLivePreviewListener(sublime_plugin.EventListener):
def on_modified(self, view):
if not is_markdown_view(view): # faster than getting the settings
return
def update(self, view):
vsettings = view.settings()
if not vsettings.get(PREVIEW_ENABLED):
return
@ -56,10 +55,58 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
raise ValueError('The preview is None (id: {})'.format(id))
show_html(view, preview)
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):
self.on_modified(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()
show_tabs = psettings.get('show_tabs')
show_minimap = psettings.get('show_minimap')
show_status_bar = psettings.get('show_status_bar')
show_sidebar = psettings.get('show_sidebar')
show_menus = psettings.get('show_menus')
if show_tabs is not None:
window.set_tabs_visible(show_tabs)
if show_minimap is not None:
window.set_minimap_visible(show_minimap)
if show_status_bar is not None:
window.set_status_bar_visible(show_status_bar)
if show_sidebar is not None:
window.set_sidebar_visible(show_sidebar)
if show_menus is not None:
window.set_menu_visible(show_menus)
class MarkdownLivePreviewClearCacheCommand(sublime_plugin.ApplicationCommand):
def run(self):
clear_cache()

View File

@ -2,16 +2,15 @@ Fast:
☐ sync scroll @needsUpdate(because of images)
☐ cache image in object when used, so that it's faster @needsTest
☐ call settings listener on_new too - might be too heavy
☐ add clear cache command
add settings for the preview
update README for settings in view
☐ add edit settings
Medium:
☐ auto refresh preview if loading images
☐ use alt attribute for 404 error
☐ use MarkdownLivePreview syntax, so we can use syntax's settings
☐ listen for settings to change
☐ fix relative source
Long:
☐ fix #4 @high
@ -23,6 +22,9 @@ Unknown:
___________________
Archive:
✘ call settings listener on_new too - might be too heavy @cancelled Sun 08 Jan 2017 at 19:33 @project(Fast)
✔ fix relative source @done Sun 08 Jan 2017 at 19:22 @project(Medium)
✔ add settings for the preview @done Sun 08 Jan 2017 at 17:36 @project(Fast)
✔ regive focus to the right markdown view @done Mon 02 Jan 2017 at 18:34 @project(Fast)
✔ try/except for 404 @done Mon 02 Jan 2017 at 18:03 @project(Fast)
✔ fix bug when empty `src` @done Mon 02 Jan 2017 at 17:15 @project(Fast)

View File

@ -8,23 +8,14 @@ This is a sublime text **3** plugin that allows you to preview your markdown ins
## 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:
MarkdownLivePreview is available on the default channel of [PackageControl](http://packagecontrol.io), which means you just have to
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!
to have MarkdownLivePreview working on your computer. Cool right? You can [thank package control](https://packagecontrol.io/say_thanks) for this.
### Usage
@ -34,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).
@ -52,4 +48,4 @@ Some of the package add a command in the menus, others in the command palette, o
[markdown-extended]: https://packagecontrol.io/packages/Markdown
[markdown-extended]: https://packagecontrol.io/packages/Markdown%20Extended

View File

@ -11,7 +11,7 @@ def plugin_loaded():
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
def replace_img_src_base64(html):
def replace_img_src_base64(html, basepath):
"""Really messy, but it works (should be updated)"""
index = -1
tag_start = '<img src="'
@ -30,7 +30,9 @@ def replace_img_src_base64(html):
else:
# local image
image = to_base64(''.join(path))
path = ''.join(path)
path = os.path.join(basepath, path)
image = to_base64(path)
html[index+len(tag_start):end] = image
shtml = ''.join(html)
return ''.join(html)

View File

@ -1,4 +1,5 @@
{
"install": "messages/install.txt",
"1.1.2": "messages/1.1.2.txt"
"1.1.2": "messages/1.1.2.txt",
"2.0.1": "messages/2.0.1.txt"
}

View File

@ -1,4 +1,4 @@
Sorry to interupt you... :(
Sorry to interrupt you... :(
Small changes occured on MarkdownLivePreview.

22
messages/2.0.1.txt Normal file
View File

@ -0,0 +1,22 @@
Sorry to interrupt you... :(
Some quite important changes have occured on MarkdownLivePreview.
The first version was quite buggy: it made Sublime Text 3 crash. So I released
a whole new version, which is working differently.
When you active MarkdownLivePreview, it'll open a new window with the markdown
view on the left, and the preview on the right.
When you'll close any file in this window, it'll close the *entire* window.
I hope you'll still enjoy using MarkdownLivePreview. If you have any request,
just let me know by raising an issue here:
github.com/math2001/MarkdownLivePreview/issues
Tip of the day: you can duplicate a line by pressing 'ctrl+d'
remove a line by pressing 'ctrl+shift+k'
join lines by pressing 'ctrl+j'
get use to use these few shortcuts, and you'll speed up
significantly.

View File

@ -1,15 +1,11 @@
# DuckDuckGo - The Search engine you'll fall in love
This is cool. The stylesheet's back!
This is a test, and this is pretty cool!
Hope you'll enjoy using MarkdownLivePreview!
![Sublime Text Forum](https://forum.sublimetext.com/uploads/st-forum-wide.png)
```python
print(hello world)
print('Hello world')
if DEBUG:
print('DEBUG_MODE on')
```