Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8eb0172eb4 |
16
MLPApi.py
16
MLPApi.py
@ -63,15 +63,17 @@ def markdown2html(md, basepath):
|
|||||||
# I personaly edited the file (markdown2.py:1743)
|
# I personaly edited the file (markdown2.py:1743)
|
||||||
html = strip_html_comments(html)
|
html = strip_html_comments(html)
|
||||||
|
|
||||||
# Beautiful uses the <br/> but the sublime phantoms do not support them...
|
# exception, again, because <pre> aren't supported by the phantoms
|
||||||
|
# so, because this is monosaped font, I just replace it with a '.' and make transparent ;)
|
||||||
|
html = html.replace(' ', '<i class="space">.</i>')
|
||||||
|
|
||||||
|
# Phantoms have problem with images size when they're loaded from an url/path
|
||||||
|
# So, the solution is to convert them to base64
|
||||||
|
html = replace_img_src_base64(html, basepath=os.path.dirname(basepath))
|
||||||
|
|
||||||
|
# BeautifulSoup uses the <br/> but the sublime phantoms do not support them...
|
||||||
html = html.replace('<br/>', '<br />')
|
html = html.replace('<br/>', '<br />')
|
||||||
|
|
||||||
html = html.replace(' ', ' espace;') # save where are the spaces
|
|
||||||
|
|
||||||
# exception, again, because <pre> aren't supported by the phantoms
|
|
||||||
html = html.replace(' espace;', '<i class="space">.</i>')
|
|
||||||
html = replace_img_src_base64(html, basepath=os.path.dirname(basepath))
|
|
||||||
sublime.set_clipboard(html)
|
|
||||||
return html
|
return html
|
||||||
|
|
||||||
def show_html(md_view, preview):
|
def show_html(md_view, preview):
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
Fast:
|
Fast:
|
||||||
☐ cache image in object when used, so that it's faster @needsTest
|
☐ cache image in object when used, so that it's faster @needsTest
|
||||||
|
☐ add settings to keep md view open #13
|
||||||
|
|
||||||
Medium:
|
Medium:
|
||||||
☐ auto refresh preview if loading images
|
☐ auto refresh preview if loading images
|
||||||
|
|||||||
36
functions.py
36
functions.py
@ -19,29 +19,21 @@ def strip_html_comments(html):
|
|||||||
|
|
||||||
def replace_img_src_base64(html, basepath):
|
def replace_img_src_base64(html, basepath):
|
||||||
"""Really messy, but it works (should be updated)"""
|
"""Really messy, but it works (should be updated)"""
|
||||||
index = -1
|
|
||||||
tag_start = '<img src="'
|
|
||||||
shtml, html = html, list(html)
|
|
||||||
while True:
|
|
||||||
index = shtml.find(tag_start, index + 1)
|
|
||||||
if index == -1:
|
|
||||||
break
|
|
||||||
path, end = get_content_till(html, '"', start=index + len(tag_start))
|
|
||||||
if ''.join(path).startswith('data:image/'):
|
|
||||||
continue
|
|
||||||
if ''.join(path).startswith(tuple(get_settings().get('load_from_internet' + \
|
|
||||||
'_when_starts', []))):
|
|
||||||
image = ImageManager.get(''.join(path))
|
|
||||||
image = image or loading
|
|
||||||
|
|
||||||
else:
|
|
||||||
# local image
|
soup = BeautifulSoup(html)
|
||||||
path = ''.join(path)
|
load_from_internet_starters = get_settings().get('load_from_internet_when_starts')
|
||||||
path = os.path.join(basepath, path)
|
for img in soup.find_all('img'):
|
||||||
image = to_base64(path)
|
if img['src'].startswith('data:image/'):
|
||||||
html[index+len(tag_start):end] = image
|
continue
|
||||||
shtml = ''.join(html)
|
elif img['src'].startswith(tuple(load_from_internet_starters)):
|
||||||
return ''.join(html)
|
image = ImageManager.get(img['src']) or loading
|
||||||
|
else: # this is a local image
|
||||||
|
image = to_base64(os.path.join(basepath, src))
|
||||||
|
|
||||||
|
img['src'] = image
|
||||||
|
|
||||||
|
return str(soup)
|
||||||
|
|
||||||
def is_markdown_view(view):
|
def is_markdown_view(view):
|
||||||
return 'markdown' in view.scope_name(0)
|
return 'markdown' in view.scope_name(0)
|
||||||
|
|||||||
@ -26,7 +26,7 @@ if you is moods.curious:
|
|||||||
| 45 | John |
|
| 45 | John |
|
||||||
| `<table>` | `><` |
|
| `<table>` | `><` |
|
||||||
|
|
||||||
[Sublime Text Logo](https://upload.wikimedia.org/wikipedia/en/4/4c/Sublime_Text_Logo.png)
|

|
||||||
|
|
||||||
Some plugin I just *need*:
|
Some plugin I just *need*:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user