Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa5fd4faf8 | |||
| 613e3fb1b2 | |||
| 057f770859 | |||
| 76d56deff6 |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
17
MLPApi.py
17
MLPApi.py
@ -15,7 +15,12 @@ __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')
|
||||||
DEFAULT_STYLE_FILE = os.path.join(__folder__, 'default.css')
|
|
||||||
|
|
||||||
|
def plugin_loaded():
|
||||||
|
global DEFAULT_STYLE_FILE
|
||||||
|
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/'
|
||||||
|
'default.css')
|
||||||
|
|
||||||
def get_preview_name(md_view):
|
def get_preview_name(md_view):
|
||||||
name = md_view.name() \
|
name = md_view.name() \
|
||||||
@ -94,13 +99,7 @@ def hide_preview(view):
|
|||||||
sublime.set_timeout(preview.close(), 250)
|
sublime.set_timeout(preview.close(), 250)
|
||||||
|
|
||||||
def get_style():
|
def get_style():
|
||||||
if os.path.exists(STYLE_FILE):
|
content = ''.join([line.strip() for line in DEFAULT_STYLE_FILE.splitlines()])
|
||||||
with open(STYLE_FILE) as fp:
|
|
||||||
return fp.read()
|
|
||||||
|
|
||||||
with open(DEFAULT_STYLE_FILE) as fp:
|
|
||||||
content = fp.read()
|
|
||||||
content = ''.join([line.strip() for line in content.splitlines()])
|
|
||||||
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):
|
||||||
@ -132,6 +131,8 @@ def show_html(md_view, preview):
|
|||||||
|
|
||||||
# set viewport position
|
# set viewport position
|
||||||
|
|
||||||
|
# sublime.set_clipboard(html)
|
||||||
|
|
||||||
return
|
return
|
||||||
# 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]
|
||||||
|
|||||||
@ -19,7 +19,7 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
|||||||
preview = get_view_from_id(window, id)
|
preview = get_view_from_id(window, id)
|
||||||
if id is None or preview is None:
|
if id is None or preview is None:
|
||||||
preview = create_preview(view)
|
preview = create_preview(view)
|
||||||
sublime.set_timeout(lambda: show_html(view, preview), 1000)
|
sublime.set_timeout_async(lambda: show_html(view, preview), 1000)
|
||||||
else:
|
else:
|
||||||
show_html(view, preview)
|
show_html(view, preview)
|
||||||
|
|
||||||
|
|||||||
@ -3,11 +3,13 @@ Fast:
|
|||||||
☐ sync scroll @needsUpdate(because of images)
|
☐ sync scroll @needsUpdate(because of images)
|
||||||
☐ cache image in object when used, so that it's faster @needsTest
|
☐ cache image in object when used, so that it's faster @needsTest
|
||||||
☐ call settings listener on_new too - might be too heavy
|
☐ call settings listener on_new too - might be too heavy
|
||||||
|
☐ add clear cache command
|
||||||
|
|
||||||
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
|
||||||
☐ use MarkdownLivePreview syntax, so we can use syntax's settings
|
☐ use MarkdownLivePreview syntax, so we can use syntax's settings
|
||||||
|
☐ listen for settings to change
|
||||||
|
|
||||||
Long:
|
Long:
|
||||||
☐ fix #4 @high
|
☐ fix #4 @high
|
||||||
|
|||||||
11
functions.py
11
functions.py
@ -5,7 +5,10 @@ import sublime
|
|||||||
import re
|
import re
|
||||||
from .image_manager import ImageManager
|
from .image_manager import ImageManager
|
||||||
|
|
||||||
file404 = os.path.join(os.path.dirname(__file__), '404.png')
|
def plugin_loaded():
|
||||||
|
global error404, loading
|
||||||
|
loading = sublime.load_resource('Packages/MarkdownLivePreview/loading.txt')
|
||||||
|
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
|
||||||
|
|
||||||
|
|
||||||
def replace_img_src_base64(html):
|
def replace_img_src_base64(html):
|
||||||
@ -23,7 +26,7 @@ def replace_img_src_base64(html):
|
|||||||
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 to_base64('loading.png')
|
image = image or loading
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# local image
|
# local image
|
||||||
@ -37,13 +40,13 @@ def is_markdown_view(view):
|
|||||||
|
|
||||||
def to_base64(path=None, content=None):
|
def to_base64(path=None, content=None):
|
||||||
if path is None and content is None:
|
if path is None and content is None:
|
||||||
return to_base64(file404)
|
return error404
|
||||||
elif content is None and path is not None:
|
elif content is None and path is not None:
|
||||||
try:
|
try:
|
||||||
with open(path, 'rb') as fp:
|
with open(path, 'rb') as fp:
|
||||||
content = fp.read()
|
content = fp.read()
|
||||||
except (FileNotFoundError, OSError):
|
except (FileNotFoundError, OSError):
|
||||||
return to_base64(file404)
|
return error404
|
||||||
|
|
||||||
return 'data:image/png;base64,' + ''.join([chr(el) for el in list(base64.standard_b64encode(content))])
|
return 'data:image/png;base64,' + ''.join([chr(el) for el in list(base64.standard_b64encode(content))])
|
||||||
|
|
||||||
|
|||||||
@ -5,8 +5,10 @@ from threading import Thread
|
|||||||
import urllib.request, urllib.error
|
import urllib.request, urllib.error
|
||||||
import sublime
|
import sublime
|
||||||
from .functions import *
|
from .functions import *
|
||||||
|
import tempfile
|
||||||
|
|
||||||
CACHE_FILE = os.path.join(os.path.dirname(__file__), 'cache.txt')
|
CACHE_FILE = os.path.join(tempfile.gettempdir(),
|
||||||
|
'MarkdownLivePreviewCache.txt')
|
||||||
TIMEOUT = 20 # seconds
|
TIMEOUT = 20 # seconds
|
||||||
|
|
||||||
SEPARATOR = '---%cache%--'
|
SEPARATOR = '---%cache%--'
|
||||||
|
|||||||
1
loading.txt
Normal file
1
loading.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
data:image/png;base64,R0lGODlhZABkAPU+AAAAAAwNDRweHyYpKzg8Pzo+QUBFSERJTEdMT05UV1NYXFVbX1hfY1lfZGFobWJpbmhvdGxzeHF5fnJ6gHV9g3Z+hHqDiXuEin+IjoCIjoKLkYKMkoSNk4eQl4iSmIqTmouUm42XnY+ZoJKco5OdpJOepZSeppahqJeiqZmjqpumrZ6psJ+qsqOutqSvt6SwuKezu6i0vKm1vay4wK66wq+7w6+8xLK+xrK/x7TAybXCy7bDy7jEzbjFzrzJ0gAAACH5BAUAAD4AIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAZABkAAAG/kCfcEgsGo/IpHLJbDqf0Kh0Sq1ar9isdsvter/gsHhMLpvP6LR6zW673/C4fE6v2+/4vH7P7/v/gIGCg4SFhoeIiW8IAAAUilUpjQABkEsmMUchkwBIOTOQBQICGUabk0ctFhYdiSajAgOZRKeNRjkYqxaghyuwAgxFtZ1FJBe6NokHvya0nEUzuhYgijG/B86oRCDSOZAPv6VCw0SquiiWNwOwAzfjz0I8uasYPIMvDQ0kRhm/Ee/afKiQ1sIIDBAgkuUxQKDhA29ERMHK9GJSJR85pLUiwkOELgx6Goo0sG/IK1gVhCig9MjHimOreAmBMU+XngciRTrAMSQB/qxmR6KtEjGko7Shey7kbGgA6A0GBz4oOUjCno8YNXWp6NOCwVICD6UYPQqiBiANDHNOkILiqIYVg2Y0yPlAikddICASQtuwJJQY9OAimqFCZpRPei0pPnKjg4fHkB936JBYyg4VmDNrVlH5zYMFoEOLZgDBSoejqDfQEc1atBXUsOl8bi26bpUNsKWpnlPjg+PIj32brZJjs/HOi5PjiMFzCo4ZyAWpqCBhwgspMFa9NZRjg4TvEjZCEQFzWvQ9KiiA/+73SVtpGAT7mcFh/XcPVqH0uCsNhDs+J9gnAQXX+cADCSDMggRVVtGE2lZ6fCAgfkPcdYFhRAhlAVHxxfCnC4d42EdghtII1hYGLgjxki6GOSiNHtR990F+QpymizcZ0SNEjquI1+FHetDHQYFEuCANhBpaMMRAuqRYxEEJDSLPR1YlWVRN9Vjy3ioFCWHlEC6Uh44iOcB0gQck2kSEB90o4sEFx1yY5irQ9JdIDdIANcSXRBiDzGAfVcbnELiwmEgHx3Q5p5JGmOPjIdAF9eIRnyRnhA1AWvqEn4pq6umnoIYq6qiklmrqqaimquqqrLbq6quwxirrrLTWauuttwYBADs=
|
||||||
@ -1,7 +1,13 @@
|
|||||||
# DuckDuckGo - The Search engine you'll fall in love with
|
# DuckDuckGo - The Search engine you'll fall in love with this is a test.
|
||||||
|
|
||||||
This is a test, and this is pretty cool!
|
This is a test, and this is pretty cool!
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Hope you'll enjoy using MarkdownLivePreview!
|
Hope you'll enjoy using MarkdownLivePreview!
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
this is a tets
|
||||||
|
|||||||
Reference in New Issue
Block a user