Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0505ca30bc | |||
| c49ae26720 | |||
| c2618ead1d | |||
| 6e113fef6e | |||
| e5378e2300 |
@ -23,11 +23,11 @@
|
||||
"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"
|
||||
}
|
||||
},
|
||||
}
|
||||
]
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
26
MLPApi.py
26
MLPApi.py
@ -11,17 +11,19 @@ from .escape_amp import *
|
||||
from .functions import *
|
||||
from .setting_names import *
|
||||
from .image_manager import CACHE_FILE
|
||||
from random import randint as rnd
|
||||
|
||||
__folder__ = os.path.dirname(__file__)
|
||||
|
||||
STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User',
|
||||
'MarkdownLivePreview.css')
|
||||
|
||||
# used to store the phantom's set
|
||||
views = {}
|
||||
|
||||
def plugin_loaded():
|
||||
global DEFAULT_STYLE_FILE
|
||||
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/'
|
||||
'default.css')
|
||||
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/default.css')
|
||||
|
||||
def get_preview_name(md_view):
|
||||
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_scratch(True)
|
||||
preview.set_syntax_file('Packages/MarkdownLivePreview/.sublime/'
|
||||
preview.set_syntax_file('Packages/MarkdownLivePreview/.sublime/' + \
|
||||
'MarkdownLivePreviewSyntax.hidden-tmLanguage')
|
||||
|
||||
return preview
|
||||
@ -45,6 +47,7 @@ def get_style():
|
||||
return content + "pre code .space {color: var(--light-bg)}"
|
||||
|
||||
def show_html(md_view, preview):
|
||||
global views
|
||||
html = []
|
||||
html.append('<style>\n{}\n</style>'.format(get_style()))
|
||||
html.append(pre_with_br(md2.markdown(get_view_content(md_view),
|
||||
@ -65,14 +68,14 @@ def show_html(md_view, preview):
|
||||
html = html.replace(' espace;', '<i class="space">.</i>')
|
||||
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),
|
||||
html,
|
||||
sublime.LAYOUT_BLOCK,
|
||||
lambda href: sublime.run_command('open_url',
|
||||
{'url': href}))
|
||||
|
||||
phantom_set = views.setdefault(preview.id(),
|
||||
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
|
||||
y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1]
|
||||
@ -89,3 +92,6 @@ def show_html(md_view, preview):
|
||||
def clear_cache():
|
||||
"""Removes the cache file"""
|
||||
os.remove(CACHE_FILE)
|
||||
|
||||
def release_phantoms_set():
|
||||
global views
|
||||
|
||||
@ -72,8 +72,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
||||
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'
|
||||
and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/' + \
|
||||
'.sublime/MarkdownLivePreviewSyntax' + \
|
||||
'.hidden-tmLanguage'):
|
||||
sublime.run_command('new_markdown_live_preview')
|
||||
|
||||
@ -110,3 +110,8 @@ class MarkdownLivePreviewClearCacheCommand(sublime_plugin.ApplicationCommand):
|
||||
|
||||
def run(self):
|
||||
clear_cache()
|
||||
|
||||
class MarkdownLivePreviewReleasePhantomSetCommand(sublime_plugin.ApplicationCommand):
|
||||
|
||||
def run(self):
|
||||
release_phantoms_set()
|
||||
|
||||
@ -5,6 +5,7 @@ Fast:
|
||||
Medium:
|
||||
☐ auto refresh preview if loading images
|
||||
☐ use alt attribute for 404 error
|
||||
☐ fix custom css @bug
|
||||
|
||||
Long:
|
||||
☐ support hanchor (TOC) @big
|
||||
|
||||
@ -23,8 +23,8 @@ def replace_img_src_base64(html, basepath):
|
||||
path, end = get_content_till(html, '"', start=index + len(tag_start))
|
||||
if ''.join(path).startswith('data:image/'):
|
||||
continue
|
||||
if ''.join(path).startswith(tuple(get_settings().get('load_from_internet'
|
||||
'_when_starts'))):
|
||||
if ''.join(path).startswith(tuple(get_settings().get('load_from_internet' + \
|
||||
'_when_starts', []))):
|
||||
image = ImageManager.get(''.join(path))
|
||||
image = image or loading
|
||||
|
||||
@ -38,7 +38,7 @@ def replace_img_src_base64(html, basepath):
|
||||
return ''.join(html)
|
||||
|
||||
def is_markdown_view(view):
|
||||
return 'markdown' in view.scope_name(0)
|
||||
return 'markdown' in view.scope_name(0)
|
||||
|
||||
def to_base64(path=None, content=None):
|
||||
if path is None and content is None:
|
||||
|
||||
@ -10,10 +10,10 @@ Thanks for installing MarkdownLivePreview! I hope you'll enjoy using it!
|
||||
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
|
||||
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:
|
||||
~~~~~~~~~~~
|
||||
|
||||
54
sample.md
54
sample.md
@ -1,52 +1,8 @@
|
||||
# DuckDuckGo - The Search engine you'll fall in love
|
||||
# sample
|
||||
|
||||
Hope you'll enjoy using MarkdownLivePreview!
|
||||
sdfdsf
|
||||
|
||||

|
||||
|
||||
```python
|
||||
print('Hello world')
|
||||
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.
|
||||
|
||||
t
|
||||
|
||||
h
|
||||
|
||||
i
|
||||
|
||||
s
|
||||
|
||||
-
|
||||
|
||||
i
|
||||
|
||||
s
|
||||
|
||||

|
||||
|
||||
-
|
||||
|
||||
a
|
||||
|
||||
-
|
||||

|
||||
|
||||

|
||||
|
||||
t
|
||||
|
||||

|
||||
|
||||
|
||||
e
|
||||
|
||||

|
||||
|
||||
s
|
||||
|
||||
t
|
||||
sdfd
|
||||
sdf
|
||||
|
||||
Reference in New Issue
Block a user