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',
|
STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User',
|
||||||
'MarkdownLivePreview.css')
|
'MarkdownLivePreview.css')
|
||||||
|
|
||||||
|
|
||||||
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/'
|
||||||
@ -98,10 +99,6 @@ 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):
|
|
||||||
with open(STYLE_FILE) as fp:
|
|
||||||
return fp.read()
|
|
||||||
|
|
||||||
content = ''.join([line.strip() for line in DEFAULT_STYLE_FILE.splitlines()])
|
content = ''.join([line.strip() for line in DEFAULT_STYLE_FILE.splitlines()])
|
||||||
return content + "pre code .space {color: var(--light-bg)}"
|
return content + "pre code .space {color: var(--light-bg)}"
|
||||||
|
|
||||||
@ -134,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]
|
||||||
|
|||||||
@ -3,6 +3,7 @@ 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
|
||||||
|
|||||||
@ -5,7 +5,9 @@ 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
|
||||||
|
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
|
||||||
|
|
||||||
|
|
||||||
def replace_img_src_base64(html):
|
def replace_img_src_base64(html):
|
||||||
@ -37,13 +39,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%--'
|
||||||
|
|||||||
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!
|
This is a test, and this is pretty cool!
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
Hope you'll enjoy using MarkdownLivePreview!
|
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