fix loading image with relative paths
This commit is contained in:
@ -49,12 +49,10 @@ def show_html(md_view, preview):
|
||||
html.append(pre_with_br(md2.markdown(get_view_content(md_view),
|
||||
extras=['fenced-code-blocks',
|
||||
'no-code-highlighting'])))
|
||||
|
||||
html = '\n'.join(html)
|
||||
|
||||
# the option no-code-highlighting does not exists
|
||||
# in the official version of markdown2 for now
|
||||
# I personaly edited the file (markdown2.py:1743)
|
||||
html = '\n'.join(html)
|
||||
|
||||
html = html.replace(' ', ' espace;') # save where are the spaces
|
||||
|
||||
@ -64,7 +62,8 @@ def show_html(md_view, preview):
|
||||
|
||||
# exception, again, because <pre> aren't supported by the phantoms
|
||||
html = html.replace(' espace;', '<i class="space">.</i>')
|
||||
html = replace_img_src_base64(html)
|
||||
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),
|
||||
|
||||
@ -4,13 +4,13 @@ Fast:
|
||||
☐ 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
|
||||
☐ update README for settings in view
|
||||
|
||||
Medium:
|
||||
☐ auto refresh preview if loading images
|
||||
☐ use alt attribute for 404 error
|
||||
☐ use MarkdownLivePreview syntax, so we can use syntax's settings
|
||||
☐ listen for settings to change
|
||||
☐ fix relative source
|
||||
|
||||
Long:
|
||||
☐ fix #4 @high
|
||||
@ -22,6 +22,7 @@ Unknown:
|
||||
|
||||
___________________
|
||||
Archive:
|
||||
✔ fix relative source @done Sun 08 Jan 2017 at 19:22 @project(Medium)
|
||||
✔ add settings for the preview @done Sun 08 Jan 2017 at 17:36 @project(Fast)
|
||||
✔ regive focus to the right markdown view @done Mon 02 Jan 2017 at 18:34 @project(Fast)
|
||||
✔ try/except for 404 @done Mon 02 Jan 2017 at 18:03 @project(Fast)
|
||||
|
||||
@ -11,7 +11,7 @@ def plugin_loaded():
|
||||
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
|
||||
|
||||
|
||||
def replace_img_src_base64(html):
|
||||
def replace_img_src_base64(html, basepath):
|
||||
"""Really messy, but it works (should be updated)"""
|
||||
index = -1
|
||||
tag_start = '<img src="'
|
||||
@ -30,7 +30,9 @@ def replace_img_src_base64(html):
|
||||
|
||||
else:
|
||||
# local image
|
||||
image = to_base64(''.join(path))
|
||||
path = ''.join(path)
|
||||
path = os.path.join(basepath, path)
|
||||
image = to_base64(path)
|
||||
html[index+len(tag_start):end] = image
|
||||
shtml = ''.join(html)
|
||||
return ''.join(html)
|
||||
|
||||
Reference in New Issue
Block a user