Compare commits

..

10 Commits

Author SHA1 Message Date
0505ca30bc Use phantomSet #11 2017-01-22 11:23:14 +11:00
c49ae26720 tiny update 2017-01-20 18:52:01 +11:00
c2618ead1d Merge pull request #9 from jimperio/master
Fix a typo and some minor copy errors
2017-01-14 09:23:17 +11:00
6e113fef6e fix trailing commas in Main.sublime-menu 2017-01-14 09:21:59 +11:00
e5378e2300 Fix a typo and some minor copy errors 2017-01-13 23:15:48 +08:00
caf932b536 update messages 2017-01-12 11:25:36 +11:00
fa106c8206 fix bug when settings preview's position 2017-01-12 11:24:51 +11:00
0ac9fd9aaa add messages for sync scroll 2017-01-12 09:37:44 +11:00
5bbfb4606d comment code 2017-01-12 09:22:40 +11:00
37703e9bab enable sync scroll #8 2017-01-12 08:48:33 +11:00
10 changed files with 55 additions and 37 deletions

View File

@ -23,11 +23,11 @@
"file": "$packages/User/MarkdownLivePreview.css", "file": "$packages/User/MarkdownLivePreview.css",
"contents": "/* See http://www.sublimetext.com/docs/3/minihtml.html#css to know which property you're able to use */\n\n$0" "contents": "/* See http://www.sublimetext.com/docs/3/minihtml.html#css to know which property you're able to use */\n\n$0"
} }
}, }
] ]
}, }
], ]
}, }
] ]
} }
] ]

View File

@ -11,17 +11,19 @@ from .escape_amp import *
from .functions import * from .functions import *
from .setting_names import * from .setting_names import *
from .image_manager import CACHE_FILE from .image_manager import CACHE_FILE
from random import randint as rnd
__folder__ = os.path.dirname(__file__) __folder__ = os.path.dirname(__file__)
STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User', STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User',
'MarkdownLivePreview.css') 'MarkdownLivePreview.css')
# used to store the phantom's set
views = {}
def plugin_loaded(): def plugin_loaded():
global DEFAULT_STYLE_FILE global DEFAULT_STYLE_FILE
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/' DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/default.css')
'default.css')
def get_preview_name(md_view): def get_preview_name(md_view):
file_name = md_view.file_name() file_name = md_view.file_name()
@ -35,7 +37,7 @@ def create_preview(window, file_name):
preview.set_name(get_preview_name(file_name)) preview.set_name(get_preview_name(file_name))
preview.set_scratch(True) preview.set_scratch(True)
preview.set_syntax_file('Packages/MarkdownLivePreview/.sublime/' preview.set_syntax_file('Packages/MarkdownLivePreview/.sublime/' + \
'MarkdownLivePreviewSyntax.hidden-tmLanguage') 'MarkdownLivePreviewSyntax.hidden-tmLanguage')
return preview return preview
@ -45,6 +47,7 @@ def get_style():
return content + "pre code .space {color: var(--light-bg)}" return content + "pre code .space {color: var(--light-bg)}"
def show_html(md_view, preview): def show_html(md_view, preview):
global views
html = [] html = []
html.append('<style>\n{}\n</style>'.format(get_style())) html.append('<style>\n{}\n</style>'.format(get_style()))
html.append(pre_with_br(md2.markdown(get_view_content(md_view), html.append(pre_with_br(md2.markdown(get_view_content(md_view),
@ -65,25 +68,30 @@ def show_html(md_view, preview):
html = html.replace('&nbspespace;', '<i class="space">.</i>') html = html.replace('&nbspespace;', '<i class="space">.</i>')
html = replace_img_src_base64(html, basepath=os.path.dirname( html = replace_img_src_base64(html, basepath=os.path.dirname(
md_view.file_name())) md_view.file_name()))
preview.erase_phantoms('markdown_preview')
preview.add_phantom('markdown_preview',
sublime.Region(-1),
html,
sublime.LAYOUT_BLOCK,
lambda href: sublime.run_command('open_url',
{'url': href}))
return phantom_set = views.setdefault(preview.id(),
# set viewport position sublime.PhantomSet(preview, 'markdown_live_preview'))
phantom_set.update([sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK,
lambda href: sublime.run_command('open_url',
{'url': href}))])
# lambda href: sublime.run_command('open_url', {'url': href})
# get the "ratio" of the markdown view's position.
# 0 < y < 1 # 0 < y < 1
y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1] y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1]
# set the vector (position) for the preview
vector = [0, y * preview.layout_extent()[1]] vector = [0, y * preview.layout_extent()[1]]
# remove half of the viewport_extent.y to center it on the screen (verticaly) # remove half of the viewport_extent.y to center it on the screen (verticaly)
vector[1] -= preview.viewport_extent()[1] / 2 vector[1] -= preview.viewport_extent()[1] / 2
vector[1] = mini(vector[1], 0) # make sure the minimum is 0
vector[1] = 0 if vector[1] < 0 else vector[1]
# the hide the first line
vector[1] += preview.line_height() vector[1] += preview.line_height()
preview.set_viewport_position(vector, animate=False) preview.set_viewport_position(vector, animate=False)
def clear_cache(): def clear_cache():
"""Removes the cache file""" """Removes the cache file"""
os.remove(CACHE_FILE) os.remove(CACHE_FILE)
def release_phantoms_set():
global views

View File

@ -72,8 +72,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
if (is_markdown_view(view) if (is_markdown_view(view)
and get_settings().get('markdown_live_preview_on_open') and get_settings().get('markdown_live_preview_on_open')
and not vsettings.get(PREVIEW_ENABLED) and not vsettings.get(PREVIEW_ENABLED)
and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/' and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/' + \
'.sublime/MarkdownLivePreviewSyntax' '.sublime/MarkdownLivePreviewSyntax' + \
'.hidden-tmLanguage'): '.hidden-tmLanguage'):
sublime.run_command('new_markdown_live_preview') sublime.run_command('new_markdown_live_preview')
@ -110,3 +110,8 @@ class MarkdownLivePreviewClearCacheCommand(sublime_plugin.ApplicationCommand):
def run(self): def run(self):
clear_cache() clear_cache()
class MarkdownLivePreviewReleasePhantomSetCommand(sublime_plugin.ApplicationCommand):
def run(self):
release_phantoms_set()

View File

@ -5,6 +5,7 @@ Fast:
Medium: Medium:
☐ auto refresh preview if loading images ☐ auto refresh preview if loading images
☐ use alt attribute for 404 error ☐ use alt attribute for 404 error
☐ fix custom css @bug
Long: Long:
☐ support hanchor (TOC) @big ☐ support hanchor (TOC) @big

View File

@ -23,8 +23,8 @@ def replace_img_src_base64(html, basepath):
path, end = get_content_till(html, '"', start=index + len(tag_start)) path, end = get_content_till(html, '"', start=index + len(tag_start))
if ''.join(path).startswith('data:image/'): if ''.join(path).startswith('data:image/'):
continue continue
if ''.join(path).startswith(tuple(get_settings().get('load_from_internet' if ''.join(path).startswith(tuple(get_settings().get('load_from_internet' + \
'_when_starts'))): '_when_starts', []))):
image = ImageManager.get(''.join(path)) image = ImageManager.get(''.join(path))
image = image or loading image = image or loading

View File

@ -2,5 +2,5 @@
"install": "messages/install.txt", "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", "2.0.1": "messages/2.0.1.txt",
"2.1.1": "messages/2.0.1.txt" "2.2.1": "messages/2.2.0.txt"
} }

View File

@ -3,3 +3,6 @@ Sorry to interrupt you... :(
A settings is now available: `markdown_live_preview_on_open`. If set to true, A settings is now available: `markdown_live_preview_on_open`. If set to true,
it opens the window preview as soon as you open a markdown file. See the it opens the window preview as soon as you open a markdown file. See the
README for more infos. README for more infos.
Tip of the day: `ctrl+w`: closes the current file
`ctrl+shift+w`: closes the current window

8
messages/2.2.0.txt Normal file
View File

@ -0,0 +1,8 @@
Sorry to interrupt you... :(
Something changed on MarkdownLivePreview: the preview is now scrolled to where
you are editing your markdown file! It doesn't scroll back up all the time any
more!
Tip of the day: You can center the screen on your cursor by pressing:
`ctrl+k, ctrl+v` (on OSX `cmd+k, cmd+v`)

View File

@ -10,10 +10,10 @@ Thanks for installing MarkdownLivePreview! I hope you'll enjoy using it!
Quick Start: Quick Start:
~~~~~~~~~~~~ ~~~~~~~~~~~~
To enable MarkdownLivePreview, you need to me on a markdown view (works with To enable MarkdownLivePreview, you need to be on a markdown view (works with
Markdown Extended). Then just press `alt+m`, or search up in the command Markdown Extended). Then just press `alt+m`, or search up in the command
palette: 'MarkdownLivePreview: Toggle'. Hit enter and you're done. As soon as palette: 'MarkdownLivePreview: Toggle'. Hit enter and you're done. As soon as
you'll type anything in, it'll show up the preview in a new group. you type anything in, it'll show up with the preview in a new group.
Say thanks: Say thanks:
~~~~~~~~~~~ ~~~~~~~~~~~

View File

@ -1,15 +1,8 @@
# DuckDuckGo - The Search engine you'll fall in love # sample
Hope you'll enjoy using MarkdownLivePreview! sdfdsf
![Sublime Text Forum](https://forum.sublimetext.com/uploads/st-forum-wide.png) ![std](https://www.grafikart.fr/uploads/users/46570/2015/01/offtime-screens-11_1_.jpg)
```python sdfd
print('Hello world') sdf
if DEBUG:
print('DEBUG_MODE on')
```
> Only a fool knows everything. A wise man knows how little he knows
The only think I know right now is that Boxy Theme's just awesome.