Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 30d75f159d | |||
| 52e4b917e5 | |||
| 48a68b2a79 |
@ -1,4 +1,12 @@
|
|||||||
{
|
{
|
||||||
|
// As soon as you open a markdown file, it opens the window preview
|
||||||
"markdown_live_preview_on_open": false,
|
"markdown_live_preview_on_open": false,
|
||||||
"load_from_internet_when_starts": ["http://", "https://"]
|
|
||||||
|
// If an image starts with one of those strings, then it will be loaded from internet
|
||||||
|
"load_from_internet_when_starts": ["http://", "https://"],
|
||||||
|
|
||||||
|
// When the preview is opened, the markdown file is closed in the origin window and reopend in
|
||||||
|
// the preview window. If this option is set to 'true', then the markdown file will NOT be
|
||||||
|
// closed in the origin window
|
||||||
|
"keep_open_when_opening_preview": false
|
||||||
}
|
}
|
||||||
|
|||||||
25
MLPApi.py
25
MLPApi.py
@ -30,13 +30,6 @@ def plugin_loaded():
|
|||||||
else:
|
else:
|
||||||
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/default.css')
|
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/default.css')
|
||||||
|
|
||||||
def get_preview_name(md_view):
|
|
||||||
file_name = md_view.file_name()
|
|
||||||
name = md_view.name() \
|
|
||||||
or os.path.basename(file_name) if file_name else None \
|
|
||||||
or 'Untitled'
|
|
||||||
return name + ' - Preview'
|
|
||||||
|
|
||||||
def create_preview(window, file_name):
|
def create_preview(window, file_name):
|
||||||
preview = window.new_file()
|
preview = window.new_file()
|
||||||
|
|
||||||
@ -56,11 +49,23 @@ def get_style():
|
|||||||
|
|
||||||
def markdown2html(md, basepath):
|
def markdown2html(md, basepath):
|
||||||
html = '<style>\n{}\n</style>\n'.format(get_style())
|
html = '<style>\n{}\n</style>\n'.format(get_style())
|
||||||
# pre_with_br
|
|
||||||
html += pre_with_br(pre_tables(md2.markdown(md, extras=['fenced-code-blocks',
|
|
||||||
'no-code-highlighting', 'tables'])))
|
|
||||||
# the option no-code-highlighting does not exists in the official version of markdown2 for now
|
# the option no-code-highlighting does not exists in the official version of markdown2 for now
|
||||||
# I personaly edited the file (markdown2.py:1743)
|
# I personaly edited the file (markdown2.py:1743)
|
||||||
|
html += md2.markdown(md, extras=['fenced-code-blocks', 'no-code-highlighting', 'tables'])
|
||||||
|
|
||||||
|
# tables aren't supported by the Phantoms
|
||||||
|
# This function transforms them into aligned ASCII tables and displays them in a <pre> block
|
||||||
|
# (the ironic thing is that they aren't supported either :D)
|
||||||
|
html = pre_tables(html)
|
||||||
|
|
||||||
|
# pre block are not supported by the Phantoms.
|
||||||
|
# This functions replaces the \n in them with <br> so that it does (1/2)
|
||||||
|
html = pre_with_br(html)
|
||||||
|
|
||||||
|
# comments aren't supported by the Phantoms
|
||||||
|
# Simply removes them using bs4, so you can be sadic and type `<!-- hey hey! -->`, these one
|
||||||
|
# won't be stripped!
|
||||||
html = strip_html_comments(html)
|
html = strip_html_comments(html)
|
||||||
|
|
||||||
# exception, again, because <pre> aren't supported by the phantoms
|
# exception, again, because <pre> aren't supported by the phantoms
|
||||||
|
|||||||
@ -15,7 +15,8 @@ class NewMarkdownLivePreviewCommand(sublime_plugin.ApplicationCommand):
|
|||||||
|
|
||||||
current_view = sublime.active_window().active_view()
|
current_view = sublime.active_window().active_view()
|
||||||
file_name = current_view.file_name()
|
file_name = current_view.file_name()
|
||||||
current_view.close()
|
if get_settings().get('keep_open_when_opening_preview') is False:
|
||||||
|
current_view.close()
|
||||||
if file_name is None:
|
if file_name is None:
|
||||||
return sublime.error_message('MarkdownLivePreview: Not supporting '
|
return sublime.error_message('MarkdownLivePreview: Not supporting '
|
||||||
'unsaved file for now')
|
'unsaved file for now')
|
||||||
|
|||||||
11
functions.py
11
functions.py
@ -17,10 +17,15 @@ def strip_html_comments(html):
|
|||||||
element.extract()
|
element.extract()
|
||||||
return str(soup)
|
return str(soup)
|
||||||
|
|
||||||
|
|
||||||
|
def get_preview_name(md_view):
|
||||||
|
file_name = md_view.file_name()
|
||||||
|
name = md_view.name() \
|
||||||
|
or os.path.basename(file_name) if file_name else None \
|
||||||
|
or 'Untitled'
|
||||||
|
return name + ' - Preview'
|
||||||
|
|
||||||
def replace_img_src_base64(html, basepath):
|
def replace_img_src_base64(html, basepath):
|
||||||
"""Really messy, but it works (should be updated)"""
|
|
||||||
|
|
||||||
|
|
||||||
soup = BeautifulSoup(html)
|
soup = BeautifulSoup(html)
|
||||||
load_from_internet_starters = get_settings().get('load_from_internet_when_starts')
|
load_from_internet_starters = get_settings().get('load_from_internet_when_starts')
|
||||||
for img in soup.find_all('img'):
|
for img in soup.find_all('img'):
|
||||||
|
|||||||
Reference in New Issue
Block a user