fix loading image with relative paths

This commit is contained in:
Mathieu PATUREL
2017-01-08 19:22:58 +11:00
parent 0e6660a331
commit ded9c28096
4 changed files with 9 additions and 11 deletions

View File

@ -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(' ', '&nbspespace;') # 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('&nbspespace;', '<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),

View File

@ -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)

View File

@ -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)

View File

@ -13,7 +13,3 @@ if DEBUG:
> 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.
this is a test, hello world, I know this, it's cool
Hello world, this is a test, and it's working also.