Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ac9fd9aaa | |||
| 5bbfb4606d | |||
| 37703e9bab | |||
| 3b920f4336 | |||
| abe151fdb7 | |||
| acc8beb3be | |||
| 9206b6de62 | |||
| cda4532833 | |||
| ff8c94bda5 | |||
| ded9c28096 | |||
| 0e6660a331 | |||
| 0143428114 | |||
| f48ef63956 | |||
| a4e670de43 | |||
| d466a29cd4 | |||
| 0f0e53ff34 | |||
| 30ac30082f | |||
| e4e7c44c3c | |||
| 75a8cf53f9 | |||
| 3dcaed0ede | |||
| c605ffb3db | |||
| aa5fd4faf8 |
@ -1,10 +1,7 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"keys": ["alt+m"],
|
"keys": ["alt+m"],
|
||||||
"command": "toggle_setting",
|
"command": "new_markdown_live_preview",
|
||||||
"args": {
|
|
||||||
"setting": "markdown_live_preview_enabled"
|
|
||||||
},
|
|
||||||
"context": [
|
"context": [
|
||||||
{
|
{
|
||||||
"key": "selector",
|
"key": "selector",
|
||||||
|
|||||||
@ -7,14 +7,27 @@
|
|||||||
"children": [
|
"children": [
|
||||||
{
|
{
|
||||||
"caption": "MarkdownLivePreview",
|
"caption": "MarkdownLivePreview",
|
||||||
"command": "open_file",
|
"children": [
|
||||||
"args": {
|
{
|
||||||
"file": "$packages/User/MarkdownLivePreview.css",
|
"caption": "Settings",
|
||||||
"contents": "/* See http://www.sublimetext.com/docs/3/minihtml.html#css to know which property you're able to use */\n\n$0"
|
"command": "edit_settings",
|
||||||
}
|
"args": {
|
||||||
}
|
"base_file": "$packages/MarkdownLivePreview/.sublime/MarkdownLivePreview.sublime-settings",
|
||||||
]
|
"default": "// Your settings for MarkdownLivePreview. See the default file to see the different options. \n{\n\t\n}\n"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption": "Style - CSS",
|
||||||
|
"command": "open_file",
|
||||||
|
"args": {
|
||||||
|
"file": "$packages/User/MarkdownLivePreview.css",
|
||||||
|
"contents": "/* See http://www.sublimetext.com/docs/3/minihtml.html#css to know which property you're able to use */\n\n$0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,9 +1,18 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"caption": "MarkdownLivePreview: Toggle",
|
"caption": "MarkdownLivePreview: Edit Current File",
|
||||||
"command": "toggle_setting",
|
"command": "new_markdown_live_preview"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption": "MarkdownLivePreview: Clear Cache",
|
||||||
|
"command": "markdown_live_preview_clear_cache"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"caption": "Preferences: MarkdownLivePreview Settings",
|
||||||
|
"command": "edit_settings",
|
||||||
"args": {
|
"args": {
|
||||||
"setting": "markdown_live_preview_enabled"
|
"base_file": "${packages}/MarkdownLivePreview/.sublime/MarkdownLivePreview.sublime-settings",
|
||||||
|
"default": "// Your settings for MarkdownLivePreview. See the default file to see the different options. \n{\n\t$0\n}\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
|
"markdown_live_preview_on_open": false,
|
||||||
"load_from_internet_when_starts": ["http://", "https://"]
|
"load_from_internet_when_starts": ["http://", "https://"]
|
||||||
}
|
}
|
||||||
|
|||||||
14
.sublime/MarkdownLivePreviewSyntax.hidden-tmLanguage
Normal file
14
.sublime/MarkdownLivePreviewSyntax.hidden-tmLanguage
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>name</key>
|
||||||
|
<string>MarkdownLivePreviewSyntax</string>
|
||||||
|
|
||||||
|
<key>patterns</key>
|
||||||
|
<array>
|
||||||
|
</array>
|
||||||
|
<key>scopeName</key>
|
||||||
|
<string>text.markdown-live-preview</string>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
||||||
109
MLPApi.py
109
MLPApi.py
@ -6,111 +6,54 @@ import sublime_plugin
|
|||||||
import os.path
|
import os.path
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
|
||||||
from .lib import markdown2
|
from .lib import markdown2 as md2
|
||||||
from .escape_amp import *
|
from .escape_amp import *
|
||||||
from .functions import *
|
from .functions import *
|
||||||
from .setting_names import *
|
from .setting_names import *
|
||||||
|
from .image_manager import CACHE_FILE
|
||||||
|
|
||||||
__folder__ = os.path.dirname(__file__)
|
__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/'
|
||||||
'default.css')
|
'default.css')
|
||||||
|
|
||||||
def get_preview_name(md_view):
|
def get_preview_name(md_view):
|
||||||
|
file_name = md_view.file_name()
|
||||||
name = md_view.name() \
|
name = md_view.name() \
|
||||||
or os.path.basename(md_view.file_name()) \
|
or os.path.basename(file_name) if file_name else None \
|
||||||
or 'Untitled'
|
or 'Untitled'
|
||||||
return name + ' - Preview'
|
return name + ' - Preview'
|
||||||
|
|
||||||
def find_preview(window):
|
def create_preview(window, file_name):
|
||||||
for view in window.views():
|
|
||||||
vsettings = view.settings()
|
|
||||||
if vsettings.get(IS_PREVIEW):
|
|
||||||
yield view, vsettings
|
|
||||||
|
|
||||||
def create_preview(md_view):
|
|
||||||
window = md_view.window()
|
|
||||||
md_view_settings = md_view.settings()
|
|
||||||
md_view_settings.set(JUST_CREATED, True)
|
|
||||||
|
|
||||||
preview = window.new_file()
|
preview = window.new_file()
|
||||||
|
|
||||||
psettings = preview.settings()
|
preview.set_name(get_preview_name(file_name))
|
||||||
psettings.set(IS_PREVIEW, True)
|
|
||||||
psettings.set(MD_VIEW_ID, md_view.id())
|
|
||||||
preview.set_name(get_preview_name(md_view))
|
|
||||||
preview.set_scratch(True)
|
preview.set_scratch(True)
|
||||||
md_view_settings.set(PREVIEW_ID, preview.id())
|
preview.set_syntax_file('Packages/MarkdownLivePreview/.sublime/'
|
||||||
def move_and_focus_md_view():
|
'MarkdownLivePreviewSyntax.hidden-tmLanguage')
|
||||||
window.run_command('new_pane')
|
|
||||||
sublime.set_timeout_async(lambda: window.focus_view(md_view), 250)
|
|
||||||
sublime.set_timeout_async(move_and_focus_md_view, 250)
|
|
||||||
|
|
||||||
return preview
|
return preview
|
||||||
|
|
||||||
def hide_preview(view):
|
|
||||||
window = view.window()
|
|
||||||
vsettings = view.settings()
|
|
||||||
if vsettings.get(IS_PREVIEW):
|
|
||||||
preview = view
|
|
||||||
psettings = vsettings
|
|
||||||
md_view_id = vsettings.get(MD_VIEW_ID)
|
|
||||||
md_view = get_view_from_id(window, md_view_id)
|
|
||||||
if md_view is None:
|
|
||||||
raise ValueError('Tried to get md_view from id {} but got None'.format(md_view_id))
|
|
||||||
mdvsettings = md_view.settings()
|
|
||||||
|
|
||||||
elif vsettings.get(PREVIEW_ENABLED):
|
|
||||||
md_view = view
|
|
||||||
preview_id = vsettings.get(PREVIEW_ID)
|
|
||||||
preview = get_view_from_id(window, preview_id)
|
|
||||||
mdvsettings = vsettings
|
|
||||||
if preview is None:
|
|
||||||
raise ValueError('Tried to get preview from id {} but got None'.format(preview_id))
|
|
||||||
psettings = preview.settings()
|
|
||||||
else:
|
|
||||||
raise ValueError('Call hide_preview with a view which is not the preview or the md_view')
|
|
||||||
psettings.set(IS_HIDDEN, True)
|
|
||||||
mdvsettings.erase(PREVIEW_ID)
|
|
||||||
sublime.set_timeout(lambda: preview.close(), 250)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window = md_view.window()
|
|
||||||
if window is None:
|
|
||||||
return
|
|
||||||
mdvsettings = md_view.settings()
|
|
||||||
preview_id = mdvsettings.get(PREVIEW_ID)
|
|
||||||
if not preview_id:
|
|
||||||
return
|
|
||||||
mdvsettings.erase(PREVIEW_ID)
|
|
||||||
preview = get_view_from_id(window, preview_id)
|
|
||||||
if preview is None:
|
|
||||||
raise ValueError('Tried to get view from id {} but got None'.format(preview_id))
|
|
||||||
psettings = preview.settings()
|
|
||||||
psettings.set(IS_HIDDEN, True)
|
|
||||||
sublime.set_timeout(preview.close(), 250)
|
|
||||||
|
|
||||||
def get_style():
|
def get_style():
|
||||||
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)}"
|
||||||
|
|
||||||
def show_html(md_view, preview):
|
def show_html(md_view, preview):
|
||||||
html = '<style>{}</style>\n{}'.format(get_style(),
|
html = []
|
||||||
pre_with_br(markdown2.markdown(get_view_content(md_view),
|
html.append('<style>\n{}\n</style>'.format(get_style()))
|
||||||
extras=['fenced-code-blocks',
|
html.append(pre_with_br(md2.markdown(get_view_content(md_view),
|
||||||
'no-code-highlighting'])))
|
extras=['fenced-code-blocks',
|
||||||
|
'no-code-highlighting'])))
|
||||||
# the option no-code-highlighting does not exists
|
# the option no-code-highlighting does not exists
|
||||||
# in the official version of markdown2 for now
|
# 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 = '\n'.join(html)
|
||||||
|
|
||||||
html = html.replace(' ', ' espace;') # save where are the spaces
|
html = html.replace(' ', ' espace;') # save where are the spaces
|
||||||
|
|
||||||
@ -120,7 +63,8 @@ def show_html(md_view, preview):
|
|||||||
|
|
||||||
# exception, again, because <pre> aren't supported by the phantoms
|
# exception, again, because <pre> aren't supported by the phantoms
|
||||||
html = html.replace(' espace;', '<i class="space">.</i>')
|
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.erase_phantoms('markdown_preview')
|
||||||
preview.add_phantom('markdown_preview',
|
preview.add_phantom('markdown_preview',
|
||||||
sublime.Region(-1),
|
sublime.Region(-1),
|
||||||
@ -129,16 +73,19 @@ def show_html(md_view, preview):
|
|||||||
lambda href: sublime.run_command('open_url',
|
lambda href: sublime.run_command('open_url',
|
||||||
{'url': href}))
|
{'url': href}))
|
||||||
|
|
||||||
# set viewport position
|
# get the "ratio" of the markdown view's position.
|
||||||
|
|
||||||
# sublime.set_clipboard(html)
|
|
||||||
|
|
||||||
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]
|
||||||
|
# set the vector (position) for the preview
|
||||||
vector = [0, y * preview.layout_extent()[1]]
|
vector = [0, y * preview.layout_extent()[1]]
|
||||||
# remove half of the viewport_extent.y to center it on the screen (verticaly)
|
# remove half of the viewport_extent.y to center it on the screen (verticaly)
|
||||||
vector[1] -= preview.viewport_extent()[1] / 2
|
vector[1] -= preview.viewport_extent()[1] / 2
|
||||||
vector[1] = mini(vector[1], 0)
|
# make sure the minimum is 0
|
||||||
|
vector[1] = 0 if vector < 0 else vector[1]
|
||||||
|
# the hide the first line
|
||||||
vector[1] += preview.line_height()
|
vector[1] += preview.line_height()
|
||||||
preview.set_viewport_position(vector, animate=False)
|
preview.set_viewport_position(vector, animate=False)
|
||||||
|
|
||||||
|
def clear_cache():
|
||||||
|
"""Removes the cache file"""
|
||||||
|
os.remove(CACHE_FILE)
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
import sys
|
|
||||||
import os.path
|
|
||||||
import sublime
|
import sublime
|
||||||
import sublime_plugin
|
import sublime_plugin
|
||||||
|
|
||||||
@ -9,43 +7,106 @@ from .MLPApi import *
|
|||||||
from .setting_names import *
|
from .setting_names import *
|
||||||
from .functions import *
|
from .functions import *
|
||||||
|
|
||||||
|
class NewMarkdownLivePreviewCommand(sublime_plugin.ApplicationCommand):
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
|
||||||
|
"""Inspired by the edit_settings command"""
|
||||||
|
|
||||||
|
current_view = sublime.active_window().active_view()
|
||||||
|
file_name = current_view.file_name()
|
||||||
|
current_view.close()
|
||||||
|
if file_name is None:
|
||||||
|
return sublime.error_message('MarkdownLivePreview: Not supporting '
|
||||||
|
'unsaved file for now')
|
||||||
|
|
||||||
|
sublime.run_command('new_window')
|
||||||
|
self.window = sublime.active_window()
|
||||||
|
self.window.settings().set(PREVIEW_WINDOW, True)
|
||||||
|
self.window.run_command('set_layout', {
|
||||||
|
'cols': [0.0, 0.5, 1.0],
|
||||||
|
'rows': [0.0, 1.0],
|
||||||
|
'cells': [[0, 0, 1, 1], [1, 0, 2, 1]]
|
||||||
|
})
|
||||||
|
self.window.focus_group(1)
|
||||||
|
preview = create_preview(self.window, current_view)
|
||||||
|
|
||||||
|
self.window.focus_group(0)
|
||||||
|
md_view = self.window.open_file(file_name)
|
||||||
|
mdsettings = md_view.settings()
|
||||||
|
|
||||||
|
mdsettings.set(PREVIEW_ENABLED, True)
|
||||||
|
mdsettings.set(PREVIEW_ID, preview.id())
|
||||||
|
|
||||||
|
def is_enabled(self):
|
||||||
|
return is_markdown_view(sublime.active_window().active_view())
|
||||||
|
|
||||||
class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
||||||
|
|
||||||
|
def update(self, view):
|
||||||
|
vsettings = view.settings()
|
||||||
|
if not vsettings.get(PREVIEW_ENABLED):
|
||||||
|
return
|
||||||
|
id = vsettings.get(PREVIEW_ID)
|
||||||
|
if id is None:
|
||||||
|
raise ValueError('The preview id is None')
|
||||||
|
preview = get_view_from_id(view.window(), id)
|
||||||
|
if preview is None:
|
||||||
|
raise ValueError('The preview is None (id: {})'.format(id))
|
||||||
|
|
||||||
|
show_html(view, preview)
|
||||||
|
return view, preview
|
||||||
|
|
||||||
def on_modified(self, view):
|
def on_modified(self, view):
|
||||||
window = view.window()
|
if not is_markdown_view(view): # faster than getting the settings
|
||||||
|
return
|
||||||
|
self.update(view)
|
||||||
|
|
||||||
|
def on_window_command(self, window, command, args):
|
||||||
|
if command == 'close' and window.settings().get(PREVIEW_WINDOW):
|
||||||
|
return 'close_window', {}
|
||||||
|
|
||||||
|
def on_activated_async(self, view):
|
||||||
vsettings = view.settings()
|
vsettings = view.settings()
|
||||||
if vsettings.get(PREVIEW_ENABLED):
|
|
||||||
id = vsettings.get(PREVIEW_ID)
|
|
||||||
preview = get_view_from_id(window, id)
|
|
||||||
if id is None or preview is None:
|
|
||||||
preview = create_preview(view)
|
|
||||||
sublime.set_timeout(lambda: show_html(view, preview), 1000)
|
|
||||||
else:
|
|
||||||
show_html(view, preview)
|
|
||||||
|
|
||||||
return
|
if (is_markdown_view(view)
|
||||||
|
and get_settings().get('markdown_live_preview_on_open')
|
||||||
|
and not vsettings.get(PREVIEW_ENABLED)
|
||||||
|
and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/'
|
||||||
|
'.sublime/MarkdownLivePreviewSyntax'
|
||||||
|
'.hidden-tmLanguage'):
|
||||||
|
sublime.run_command('new_markdown_live_preview')
|
||||||
|
|
||||||
def on_activated(self, view):
|
|
||||||
# if view is md_view and has no preview
|
|
||||||
# -> create preview
|
|
||||||
window = view.window()
|
|
||||||
vsettings = view.settings()
|
|
||||||
if vsettings.get(PREVIEW_ENABLED):
|
|
||||||
id = vsettings.get(PREVIEW_ID)
|
|
||||||
preview = get_view_from_id(window, id)
|
|
||||||
if id is None or preview is None:
|
|
||||||
preview = create_preview(view)
|
|
||||||
sublime.set_timeout(lambda: show_html(view, preview), 1000)
|
|
||||||
else:
|
|
||||||
show_html(view, preview)
|
|
||||||
return
|
|
||||||
|
|
||||||
# if view is preview
|
def on_load_async(self, view):
|
||||||
# -> do nothing
|
"""Check the settings to hide menu, minimap, etc"""
|
||||||
if vsettings.get(IS_PREVIEW):
|
try:
|
||||||
|
md_view, preview = self.update(view)
|
||||||
|
except TypeError:
|
||||||
|
# the function update has returned None
|
||||||
return
|
return
|
||||||
# if view is not the md_view or the preview
|
window = preview.window()
|
||||||
# remove preview if any
|
psettings = preview.settings()
|
||||||
for view, settings in find_preview(window):
|
|
||||||
settings.set(IS_HIDDEN, True)
|
show_tabs = psettings.get('show_tabs')
|
||||||
view.close()
|
show_minimap = psettings.get('show_minimap')
|
||||||
|
show_status_bar = psettings.get('show_status_bar')
|
||||||
|
show_sidebar = psettings.get('show_sidebar')
|
||||||
|
show_menus = psettings.get('show_menus')
|
||||||
|
|
||||||
|
if show_tabs is not None:
|
||||||
|
window.set_tabs_visible(show_tabs)
|
||||||
|
if show_minimap is not None:
|
||||||
|
window.set_minimap_visible(show_minimap)
|
||||||
|
if show_status_bar is not None:
|
||||||
|
window.set_status_bar_visible(show_status_bar)
|
||||||
|
if show_sidebar is not None:
|
||||||
|
window.set_sidebar_visible(show_sidebar)
|
||||||
|
if show_menus is not None:
|
||||||
|
window.set_menu_visible(show_menus)
|
||||||
|
|
||||||
|
|
||||||
|
class MarkdownLivePreviewClearCacheCommand(sublime_plugin.ApplicationCommand):
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
clear_cache()
|
||||||
|
|||||||
@ -1,18 +1,12 @@
|
|||||||
Fast:
|
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
|
|
||||||
☐ add clear cache command
|
|
||||||
|
|
||||||
Medium:
|
Medium:
|
||||||
☐ auto refresh preview if loading images
|
☐ auto refresh preview if loading images
|
||||||
☐ use alt attribute for 404 error
|
☐ use alt attribute for 404 error
|
||||||
☐ use MarkdownLivePreview syntax, so we can use syntax's settings
|
|
||||||
☐ listen for settings to change
|
|
||||||
|
|
||||||
Long:
|
Long:
|
||||||
☐ fix #4 @high
|
|
||||||
☐ support hanchor (TOC) @big
|
☐ support hanchor (TOC) @big
|
||||||
|
|
||||||
Unknown:
|
Unknown:
|
||||||
@ -21,6 +15,15 @@ Unknown:
|
|||||||
|
|
||||||
___________________
|
___________________
|
||||||
Archive:
|
Archive:
|
||||||
|
✔ fix #4 @high @done Mon 09 Jan 2017 at 18:42 @project(Long)
|
||||||
|
✔ use MarkdownLivePreview syntax, so we can use syntax's settings @done Mon 09 Jan 2017 at 18:41 @project(Medium)
|
||||||
|
✔ add clear cache command @done Mon 09 Jan 2017 at 18:41 @project(Fast)
|
||||||
|
✔ update README for settings in view @done Mon 09 Jan 2017 at 18:41 @project(Fast)
|
||||||
|
✔ add edit settings @done Mon 09 Jan 2017 at 18:41 @project(Fast)
|
||||||
|
✘ listen for settings to change @cancelled Mon 09 Jan 2017 at 18:41 @project(Medium)
|
||||||
|
✘ call settings listener on_new too - might be too heavy @cancelled Sun 08 Jan 2017 at 19:33 @project(Fast)
|
||||||
|
✔ 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)
|
✔ 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)
|
✔ try/except for 404 @done Mon 02 Jan 2017 at 18:03 @project(Fast)
|
||||||
✔ fix bug when empty `src` @done Mon 02 Jan 2017 at 17:15 @project(Fast)
|
✔ fix bug when empty `src` @done Mon 02 Jan 2017 at 17:15 @project(Fast)
|
||||||
|
|||||||
79
README.md
79
README.md
@ -8,31 +8,71 @@ This is a sublime text **3** plugin that allows you to preview your markdown ins
|
|||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Although MarkdownLivePreview is not available on the default channel of [PackageControl](http://packagecontrol.io), you can still use it to download this little package.
|
MarkdownLivePreview is available on the default channel of [PackageControl](http://packagecontrol.io), which means you just have to
|
||||||
|
|
||||||
1. Open the command palette (`ctrl+shift+p`)
|
|
||||||
2. Search for: `Package Control: Add Repository`
|
|
||||||
3. Enter in the input at the bottom of ST the path to this repo: <https://github.com/math2001/MarkdownLivePreview> (tip: just drag the link in)
|
|
||||||
4. Hit <kbd>enter</kbd>
|
|
||||||
|
|
||||||
What this does is simply adding this repo to the list of packages you get when you install a package using PC.
|
|
||||||
|
|
||||||
So, as you probably understood, now you just need to install MarkdownLivePreview as if it was available on the default channel:
|
|
||||||
|
|
||||||
1. Open the command palette (`ctrl+shift+p`)
|
1. Open the command palette (`ctrl+shift+p`)
|
||||||
2. Search for: `Package Control: Install Package`
|
2. Search for: `Package Control: Install Package`
|
||||||
3. Search for: `MarkdownLivePreview`
|
3. Search for: `MarkdownLivePreview`
|
||||||
4. hit <kbd>enter</kbd>
|
4. hit <kbd>enter</kbd>
|
||||||
|
|
||||||
Done!
|
to have MarkdownLivePreview working on your computer. Cool right? You can [thank package control](https://packagecontrol.io/say_thanks) for this.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Sometimes, you just want to open a markdown file to edit it quickly, you don't care about the preview, and even worse, **you don't want it**. So, if you want to have the preview, press `alt+m`, edit your file, and you'll get a nice preview.
|
You can choose to enable MarkdownLivePreview by pressing <kbd>alt+m</kbd> or selecting in the command palette `MarkdownLivePreview: Edit Current File`. Note that you need to be editing (simply having the focus on) a markdown file. Because [Markdown Extended][markdown-extended] did a good job, it's compatible with this plugin.
|
||||||
|
|
||||||
### In dev
|
So, once you've run it, it will open a new window, with only your markdown file, with the preview. Once you're done, close whichever file and it'll close the entire window.
|
||||||
|
|
||||||
This plugin is not finished, there's still some things to fix (custom css, focus, etc). So, don't run away if you have any trouble, just submit an issue [here](http://github.com/math2001/MarkdownLivePreview/issues).
|
*Notice that it will close the entire window if you close __whichever__ file. It means that if you open a random file in this window, and then close it, it'll close the entire window still*
|
||||||
|
|
||||||
|
### Settings
|
||||||
|
|
||||||
|
- `markdown_live_preview_on_open`: if set to `true`, as soon as you open a markdown file, the preview window will popup (thanks to [@ooing](https://github.com/ooing) for its [suggestion](https://github.com/math2001/MarkdownLivePreview/issues/7#issue-199464852)). Default to `false`
|
||||||
|
- `load_from_internet_when_starts`: every images that starts with any of the string specified in this list will be loaded from internet. Default to `["http://", "https://"]`
|
||||||
|
|
||||||
|
Note: To edit your settings, search up in the command palette `Preferences: MarkdownLivePreview Settings`, or by using the menu: `Preferences → Packages Settings → MarkdownLivePreview → Settings` ;. It's not your global settings, but only the `MarkdownLivePreview`'s one
|
||||||
|
|
||||||
|
### Syntax Specific Settings
|
||||||
|
|
||||||
|
This in an other "type" of setting. :laughing: If you have a look at the syntax of the preview file (not the markdown one, really the preview), you'll see that the syntax is `MarkdownLivePreviewSyntax`. This mean that you can specify specific settings for this specific syntax (such as `word_wrap: true`, `rulers: []`, etc).
|
||||||
|
|
||||||
|
To do so, you can
|
||||||
|
|
||||||
|
1. focus the *preview* (<kbd>ctrl+2</kbd> to focus the second group, so, by default, the preview's group)
|
||||||
|
2. search up in the command palette `Preferences: Settings Syntax Specific`. It's in the *right* file that you can add the settings you want (not the left one).
|
||||||
|
|
||||||
|
Note: MarkdownLivePreview will actualy look in this file for settings that aren't supported by default. Here they are:
|
||||||
|
|
||||||
|
- `show_tabs`
|
||||||
|
- `show_minimap`
|
||||||
|
- `show_status_bar`
|
||||||
|
- `show_sidebar`
|
||||||
|
- `show_menus`
|
||||||
|
|
||||||
|
They talk for themself, don't they? All of them takes a boolean (`true` or `false`). Note that those settings are *window* specific, not just view specific (that's why they aren't supported). It means that they'll affect the entire window, and every view in it.
|
||||||
|
|
||||||
|
Here is an example of syntax specific settings for MarkdownLivePreviewSyntax:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"show_menus": false,
|
||||||
|
"show_tabs": false,
|
||||||
|
"show_minimap": false,
|
||||||
|
"gutter": false,
|
||||||
|
"rulers": [],
|
||||||
|
"word_wrap": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
And here's what you'll get:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
*Note: to close a file, you can do <kbd>ctrl+w</kbd> (on Mac OS, it's <kbd>cmd+w</kbd>)*
|
||||||
|
|
||||||
|
### Clear the cache
|
||||||
|
|
||||||
|
MarkdownLivePreview caches every images it loads from internet (otherwise, you'd never see your images, or you'd need to have a *really* fast internet connection :smile:). So, if for some reason you want to clear the cache (a simple file), you can do so from the command palette by running `
|
||||||
|
|
||||||
### Demo
|
### Demo
|
||||||
|
|
||||||
@ -40,8 +80,17 @@ This plugin is not finished, there's still some things to fix (custom css, focus
|
|||||||
|
|
||||||
### Custom css
|
### Custom css
|
||||||
|
|
||||||
It is possible to set your own css. But, be carefull, you have to respect [those rules](http://www.sublimetext.com/docs/3/minihtml.html#css). Just go to `Preferences -> Package Settings -> MarkdownLivePreview`. It will open a css file, here: `$packages/User/MarkdownLivePreview.css`. Just save it and it will automatically use it instead of the default one.
|
It is possible to set your own css. But, be carefull, you have to respect [those rules](http://www.sublimetext.com/docs/3/minihtml.html#css). Just go to `Preferences → Package Settings → MarkdownLivePreview → Style - CSS`. It will open a css file, here: `$packages/User/MarkdownLivePreview.css`. Just save it and it will automatically use it instead of the default one.
|
||||||
|
|
||||||
|
### Somethings wrong!!
|
||||||
|
|
||||||
|
If you find that something's wrong with this package, you can let me know by raising an issue on the [GitHub issue tracker][github-issue-tracker]
|
||||||
|
|
||||||
### How to open the [README](http://github.com/math2001/MarkdownLivePreview/README.md)
|
### How to open the [README](http://github.com/math2001/MarkdownLivePreview/README.md)
|
||||||
|
|
||||||
Some of the package add a command in the menus, others in the command palette, or other nowhere. None of those options are really good, especially the last one on ST3 because the packages are compressed. But, fortunately, there is plugin that exists and **will solve this problem** for us (and he has a really cute name, don't you think?): [ReadmePlease](https://packagecontrol.io/packages/ReadmePlease).
|
Some of the package add a command in the menus, others in the command palette, or other nowhere. None of those options are really good, especially the last one on ST3 because the packages are compressed. But, fortunately, there is plugin that exists and **will solve this problem** for us (and he has a really cute name, don't you think?): [ReadmePlease](https://packagecontrol.io/packages/ReadmePlease).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[markdown-extended]: https://packagecontrol.io/packages/Markdown%20Extended
|
||||||
|
[github-issue-tracker]: https://github.com/math2001/MarkdownLivePreview/issues
|
||||||
|
|||||||
@ -1,9 +1,5 @@
|
|||||||
:root, html, body {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
html {
|
html {
|
||||||
--light-bg: color(var(--background) blend(#999 85%))
|
--light-bg: color(var(--background) blend(#999 85%));
|
||||||
height: 100%;
|
|
||||||
}
|
}
|
||||||
body {
|
body {
|
||||||
padding:10px;
|
padding:10px;
|
||||||
|
|||||||
@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
__all__ = [
|
__all__ = ['escape_amp']
|
||||||
'escape_amp'
|
|
||||||
]
|
|
||||||
|
|
||||||
RE_REPLACE_AMPERSAND = re.compile(r'&(\w*)(;)?')
|
RE_REPLACE_AMPERSAND = re.compile(r'&(\w*)(;)?')
|
||||||
|
|
||||||
@ -27,11 +25,14 @@ def run_tests():
|
|||||||
fails = 0
|
fails = 0
|
||||||
for i, (subject, result) in enumerate(tests):
|
for i, (subject, result) in enumerate(tests):
|
||||||
if RE_REPLACE_AMPERSAND.sub(replace, subject) != result:
|
if RE_REPLACE_AMPERSAND.sub(replace, subject) != result:
|
||||||
|
# CSW: ignore
|
||||||
print('TEST FAIL ({i}): {subject!r} escaped did not match {result!r}'.format(**locals()))
|
print('TEST FAIL ({i}): {subject!r} escaped did not match {result!r}'.format(**locals()))
|
||||||
fails += 1
|
fails += 1
|
||||||
if fails == 0:
|
if fails == 0:
|
||||||
|
# CSW: ignore
|
||||||
print("SUCCESS: every tests ({}) passed successfully!".format(len(tests)))
|
print("SUCCESS: every tests ({}) passed successfully!".format(len(tests)))
|
||||||
else:
|
else:
|
||||||
|
# CSW: ignore
|
||||||
print("{} test{} failed".format(fails, 's' if fails > 1 else ''))
|
print("{} test{} failed".format(fails, 's' if fails > 1 else ''))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@ -11,7 +11,7 @@ def plugin_loaded():
|
|||||||
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
|
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)"""
|
"""Really messy, but it works (should be updated)"""
|
||||||
index = -1
|
index = -1
|
||||||
tag_start = '<img src="'
|
tag_start = '<img src="'
|
||||||
@ -30,7 +30,9 @@ def replace_img_src_base64(html):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
# local image
|
# 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
|
html[index+len(tag_start):end] = image
|
||||||
shtml = ''.join(html)
|
shtml = ''.join(html)
|
||||||
return ''.join(html)
|
return ''.join(html)
|
||||||
@ -75,6 +77,8 @@ def get_view_content(view):
|
|||||||
return view.substr(sublime.Region(0, view.size()))
|
return view.substr(sublime.Region(0, view.size()))
|
||||||
|
|
||||||
def get_view_from_id(window, id):
|
def get_view_from_id(window, id):
|
||||||
|
if not isinstance(id, int):
|
||||||
|
return
|
||||||
for view in window.views():
|
for view in window.views():
|
||||||
if view.id() == id:
|
if view.id() == id:
|
||||||
return view
|
return view
|
||||||
|
|||||||
@ -1,11 +1,11 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import tempfile
|
||||||
|
import sublime
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import urllib.request, urllib.error
|
import urllib.request, urllib.error
|
||||||
import sublime
|
|
||||||
from .functions import *
|
from .functions import *
|
||||||
import tempfile
|
|
||||||
|
|
||||||
CACHE_FILE = os.path.join(tempfile.gettempdir(),
|
CACHE_FILE = os.path.join(tempfile.gettempdir(),
|
||||||
'MarkdownLivePreviewCache.txt')
|
'MarkdownLivePreviewCache.txt')
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
1
imgs/README.md
Normal file
1
imgs/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
There is images here, allthough they aren't of any use for the plugin. They're just the image that I used to generate the base64 (404.txt and loading.txt)
|
||||||
|
Before Width: | Height: | Size: 953 B After Width: | Height: | Size: 953 B |
6
messages.json
Normal file
6
messages.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"install": "messages/install.txt",
|
||||||
|
"1.1.2": "messages/1.1.2.txt",
|
||||||
|
"2.0.1": "messages/2.0.1.txt",
|
||||||
|
"2.2.0": "messages/2.2.0.txt"
|
||||||
|
}
|
||||||
12
messages/1.1.2.txt
Normal file
12
messages/1.1.2.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Sorry to interrupt you... :(
|
||||||
|
|
||||||
|
Small changes occured on MarkdownLivePreview.
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
Main callback is now async (prevent ST from crashing)
|
||||||
|
|
||||||
|
|
||||||
|
Tip of the day: Delete all the content till the end of the line: Ctrl+k, Ctrl+k
|
||||||
|
You'll use it much more than you think ;)
|
||||||
22
messages/2.0.1.txt
Normal file
22
messages/2.0.1.txt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
Sorry to interrupt you... :(
|
||||||
|
|
||||||
|
Some quite important changes have occured on MarkdownLivePreview.
|
||||||
|
|
||||||
|
The first version was quite buggy: it made Sublime Text 3 crash. So I released
|
||||||
|
a whole new version, which is working differently.
|
||||||
|
|
||||||
|
When you active MarkdownLivePreview, it'll open a new window with the markdown
|
||||||
|
view on the left, and the preview on the right.
|
||||||
|
|
||||||
|
When you'll close any file in this window, it'll close the *entire* window.
|
||||||
|
|
||||||
|
I hope you'll still enjoy using MarkdownLivePreview. If you have any request,
|
||||||
|
just let me know by raising an issue here:
|
||||||
|
|
||||||
|
github.com/math2001/MarkdownLivePreview/issues
|
||||||
|
|
||||||
|
Tip of the day: you can duplicate a line by pressing 'ctrl+d'
|
||||||
|
remove a line by pressing 'ctrl+shift+k'
|
||||||
|
join lines by pressing 'ctrl+j'
|
||||||
|
get use to use these few shortcuts, and you'll speed up
|
||||||
|
significantly.
|
||||||
8
messages/2.1.0.txt
Normal file
8
messages/2.1.0.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Sorry to interrupt you... :(
|
||||||
|
|
||||||
|
A settings is now available: `markdown_live_preview_on_open`. If set to true,
|
||||||
|
it opens the window preview as soon as you open a markdown file. See the
|
||||||
|
README for more infos.
|
||||||
|
|
||||||
|
Tip of the day: `ctrl+w`: closes the current file
|
||||||
|
`ctrl+shift+w`: closes the current window
|
||||||
8
messages/2.2.0.txt
Normal file
8
messages/2.2.0.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
Sorry to interrupt you... :(
|
||||||
|
|
||||||
|
Something changed on MarkdownLivePreview: the preview is now scrolled to where
|
||||||
|
you are editing your markdown file! It doesn't scroll back up all the time any
|
||||||
|
more!
|
||||||
|
|
||||||
|
Tip of the day: You can center the screen on your cursor by pressing:
|
||||||
|
`ctrl+k, ctrl+v` (on OSX `cmd+k, cmd+v`)
|
||||||
42
messages/install.txt
Normal file
42
messages/install.txt
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
__ __ _ _ _ _ _____ _
|
||||||
|
| \/ | | | | | | | (_) | __ \ (_)
|
||||||
|
| \ / | __ _ _ __| | ____| | _____ ___ __ | | ___ _____| |__) | __ _____ ___ _____ __
|
||||||
|
| |\/| |/ _` | '__| |/ / _` |/ _ \ \ /\ / / '_ \| | | \ \ / / _ \ ___/ '__/ _ \ \ / / |/ _ \ \ /\ / /
|
||||||
|
| | | | (_| | | | < (_| | (_) \ V V /| | | | |____| |\ V / __/ | | | | __/\ V /| | __/\ V V /
|
||||||
|
|_| |_|\__,_|_| |_|\_\__,_|\___/ \_/\_/ |_| |_|______|_| \_/ \___|_| |_| \___| \_/ |_|\___| \_/\_/
|
||||||
|
|
||||||
|
Thanks for installing MarkdownLivePreview! I hope you'll enjoy using it!
|
||||||
|
|
||||||
|
Quick Start:
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
|
To enable MarkdownLivePreview, you need to me on a markdown view (works with
|
||||||
|
Markdown Extended). Then just press `alt+m`, or search up in the command
|
||||||
|
palette: 'MarkdownLivePreview: Toggle'. Hit enter and you're done. As soon as
|
||||||
|
you'll type anything in, it'll show up the preview in a new group.
|
||||||
|
|
||||||
|
Say thanks:
|
||||||
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
Just letting me know you're enjoying this plugin is a great way to say thanks!
|
||||||
|
|
||||||
|
You can do so by staring the GitHub repo, or sending a tweet (@_math2001) for
|
||||||
|
example!
|
||||||
|
|
||||||
|
Troubles?
|
||||||
|
~~~~~~~~~
|
||||||
|
|
||||||
|
If you have any kind of trouble with it, just let me now by raising an issue on
|
||||||
|
the GitHub issue tracker here:
|
||||||
|
|
||||||
|
https://github.com/math2001/MarkdownLivePreview/issues
|
||||||
|
|
||||||
|
Tip of the day: Right click on a URL and choose 'Open <the url>' to open it in
|
||||||
|
your default browser.
|
||||||
|
|
||||||
|
Credits:
|
||||||
|
~~~~~~~~
|
||||||
|
|
||||||
|
The ASCII MLP has been generated using the ASCII Decorator.
|
||||||
|
|
||||||
|
https://github.com/viisual/ASCII-Decorator
|
||||||
56
sample.md
56
sample.md
@ -1,18 +1,54 @@
|
|||||||
# DuckDuckGo - The Search engine you'll fall in love with this is a test.
|
# DuckDuckGo - The Search engine you'll fall in love
|
||||||
|
|
||||||
This is a test, and this is pretty cool!
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
Hope you'll enjoy using MarkdownLivePreview!
|
Hope you'll enjoy using MarkdownLivePreview!
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||

|
```python
|
||||||
|
print('Hello world')
|
||||||
|
if DEBUG:
|
||||||
|
print('DEBUG_MODE on')
|
||||||
|
```
|
||||||
|
|
||||||
hello world
|
> Only a fool knows everything. A wise man knows how little he knows
|
||||||
|
|
||||||
This is a test dfsdf hello world, this is pretty cool.
|
The only think I know right now is that Boxy Theme's just awesome.
|
||||||
|
|
||||||
This is a test
|
t
|
||||||
|
|
||||||
|
h
|
||||||
|
|
||||||
|
i
|
||||||
|
|
||||||
|
s
|
||||||
|
|
||||||
|
-
|
||||||
|
|
||||||
|
i
|
||||||
|
|
||||||
|
s
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
-
|
||||||
|
|
||||||
|
a
|
||||||
|
|
||||||
|
-
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
t
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
e
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
s
|
||||||
|
|
||||||
|
t
|
||||||
|
|
||||||
|
sdfsdfsdf
|
||||||
|
|||||||
BIN
screenshoots/syntax-specific-settings.png
Normal file
BIN
screenshoots/syntax-specific-settings.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
@ -5,4 +5,4 @@ PREVIEW_ID = 'markdown_live_preview_id'
|
|||||||
IS_PREVIEW = 'is_markdown_live_preview'
|
IS_PREVIEW = 'is_markdown_live_preview'
|
||||||
IS_HIDDEN = 'is_hidden_markdown_live_preview'
|
IS_HIDDEN = 'is_hidden_markdown_live_preview'
|
||||||
MD_VIEW_ID = 'markdown_live_preview_md_id'
|
MD_VIEW_ID = 'markdown_live_preview_md_id'
|
||||||
JUST_CREATED = 'markdown_live_preview_just_created'
|
PREVIEW_WINDOW = 'markdown_live_preview_window'
|
||||||
|
|||||||
Reference in New Issue
Block a user