fix loading 404 from resource
This commit is contained in:
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
@ -16,6 +16,7 @@ __folder__ = os.path.dirname(__file__)
|
||||
STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User',
|
||||
'MarkdownLivePreview.css')
|
||||
|
||||
|
||||
def plugin_loaded():
|
||||
global DEFAULT_STYLE_FILE
|
||||
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/'
|
||||
@ -98,10 +99,6 @@ def hide_preview(view):
|
||||
sublime.set_timeout(preview.close(), 250)
|
||||
|
||||
def get_style():
|
||||
if os.path.exists(STYLE_FILE):
|
||||
with open(STYLE_FILE) as fp:
|
||||
return fp.read()
|
||||
|
||||
content = ''.join([line.strip() for line in DEFAULT_STYLE_FILE.splitlines()])
|
||||
return content + "pre code .space {color: var(--light-bg)}"
|
||||
|
||||
@ -134,6 +131,8 @@ def show_html(md_view, preview):
|
||||
|
||||
# set viewport position
|
||||
|
||||
# sublime.set_clipboard(html)
|
||||
|
||||
return
|
||||
# 0 < y < 1
|
||||
y = md_view.text_to_layout(md_view.sel()[0].begin())[1] / md_view.layout_extent()[1]
|
||||
|
||||
@ -3,6 +3,7 @@ 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
|
||||
|
||||
Medium:
|
||||
☐ auto refresh preview if loading images
|
||||
|
||||
@ -5,7 +5,9 @@ import sublime
|
||||
import re
|
||||
from .image_manager import ImageManager
|
||||
|
||||
file404 = os.path.join(os.path.dirname(__file__), '404.png')
|
||||
def plugin_loaded():
|
||||
global error404
|
||||
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
|
||||
|
||||
|
||||
def replace_img_src_base64(html):
|
||||
@ -37,13 +39,13 @@ def is_markdown_view(view):
|
||||
|
||||
def to_base64(path=None, content=None):
|
||||
if path is None and content is None:
|
||||
return to_base64(file404)
|
||||
return error404
|
||||
elif content is None and path is not None:
|
||||
try:
|
||||
with open(path, 'rb') as fp:
|
||||
content = fp.read()
|
||||
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))])
|
||||
|
||||
|
||||
@ -5,8 +5,10 @@ from threading import Thread
|
||||
import urllib.request, urllib.error
|
||||
import sublime
|
||||
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
|
||||
|
||||
SEPARATOR = '---%cache%--'
|
||||
@ -22,7 +24,7 @@ def get_base64_saver(loading, url):
|
||||
content.reason.strerror == 'getaddrinfo failed'):
|
||||
loading[url] = 404
|
||||
return
|
||||
return sublime.error_message('An unexpected error has occured: ' +
|
||||
return sublime.error_message('An unexpected error has occured: ' +
|
||||
str(content))
|
||||
loading[url] = to_base64(content=content)
|
||||
|
||||
|
||||
10
sample.md
10
sample.md
@ -1,7 +1,15 @@
|
||||
# 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!
|
||||
|
||||

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

|
||||
|
||||

|
||||
|
||||
hello world
|
||||
|
||||
This is a test dfsdf hello world, this is pretty cool.
|
||||
|
||||
Reference in New Issue
Block a user