Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 82ad98085f | |||
| dd184c5fdd | |||
| c334c49592 | |||
| 41c28e2b24 | |||
| e1eb17fe96 | |||
| 823d22afee | |||
| 91f4bc5052 | |||
| 7126c0e090 | |||
| 6a3dd6ac2f | |||
| 1542e5e898 | |||
| 05c471b5d9 | |||
| 76f580ba29 |
@ -12,5 +12,8 @@
|
|||||||
|
|
||||||
// Choose what to do with YAML/TOML (---/+++ respectively) headers
|
// Choose what to do with YAML/TOML (---/+++ respectively) headers
|
||||||
// Valid values: "wrap_in_pre", "remove".
|
// Valid values: "wrap_in_pre", "remove".
|
||||||
"header_action": "wrap_in_pre"
|
"header_action": "wrap_in_pre",
|
||||||
|
|
||||||
|
// Wait at least the specified *seconds* before updating the preview.
|
||||||
|
"update_preview_every": 0
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ def markdown2html(md, basepath, color_scheme):
|
|||||||
|
|
||||||
# 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', 'tables'])
|
html += md2.markdown(md, extras=['fenced-code-blocks', 'tables', 'strike'])
|
||||||
|
|
||||||
# tables aren't supported by the Phantoms
|
# tables aren't supported by the Phantoms
|
||||||
# This function transforms them into aligned ASCII tables and displays them in a <pre> block
|
# This function transforms them into aligned ASCII tables and displays them in a <pre> block
|
||||||
@ -73,8 +73,7 @@ def markdown2html(md, basepath, color_scheme):
|
|||||||
|
|
||||||
def show_html(md_view, preview):
|
def show_html(md_view, preview):
|
||||||
global windows_phantom_set
|
global windows_phantom_set
|
||||||
html = markdown2html(get_view_content(md_view), os.path.dirname(md_view.file_name()),
|
html = markdown2html(get_view_content(md_view), os.path.dirname(md_view.file_name()), md_view.settings().get('color_scheme'))
|
||||||
os.path.join(sublime.packages_path(), '..', md_view.settings().get('color_scheme')))
|
|
||||||
|
|
||||||
phantom_set = windows_phantom_set.setdefault(preview.window().id(),
|
phantom_set = windows_phantom_set.setdefault(preview.window().id(),
|
||||||
sublime.PhantomSet(preview, 'markdown_live_preview'))
|
sublime.PhantomSet(preview, 'markdown_live_preview'))
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import sublime
|
import sublime
|
||||||
import sublime_plugin
|
import sublime_plugin
|
||||||
|
import time
|
||||||
|
|
||||||
from .MLPApi import *
|
from .MLPApi import *
|
||||||
from .setting_names import *
|
from .setting_names import *
|
||||||
@ -46,6 +47,11 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
|||||||
|
|
||||||
def update(self, view):
|
def update(self, view):
|
||||||
vsettings = view.settings()
|
vsettings = view.settings()
|
||||||
|
now = time.time()
|
||||||
|
|
||||||
|
if now - vsettings.get(LAST_UPDATE, 0) < get_settings().get('update_preview_every'):
|
||||||
|
return
|
||||||
|
vsettings.set(LAST_UPDATE, now)
|
||||||
if not vsettings.get(PREVIEW_ENABLED):
|
if not vsettings.get(PREVIEW_ENABLED):
|
||||||
return
|
return
|
||||||
id = vsettings.get(PREVIEW_ID)
|
id = vsettings.get(PREVIEW_ID)
|
||||||
@ -58,10 +64,14 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
|||||||
show_html(view, preview)
|
show_html(view, preview)
|
||||||
return view, preview
|
return view, preview
|
||||||
|
|
||||||
def on_modified(self, view):
|
def on_modified_async(self, view):
|
||||||
if not is_markdown_view(view): # faster than getting the settings
|
if not is_markdown_view(view): # faster than getting the settings
|
||||||
return
|
return
|
||||||
|
delay = get_settings().get('update_preview_every')
|
||||||
|
if not delay:
|
||||||
self.update(view)
|
self.update(view)
|
||||||
|
else:
|
||||||
|
sublime.set_timeout(lambda: self.update(view), delay * 1000)
|
||||||
|
|
||||||
def on_window_command(self, window, command, args):
|
def on_window_command(self, window, command, args):
|
||||||
if command == 'close' and window.settings().get(PREVIEW_WINDOW):
|
if command == 'close' and window.settings().get(PREVIEW_WINDOW):
|
||||||
@ -78,7 +88,6 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
|||||||
'.hidden-tmLanguage'
|
'.hidden-tmLanguage'
|
||||||
and not any(filter(lambda window: window.settings().get(PREVIEW_WINDOW) is True,
|
and not any(filter(lambda window: window.settings().get(PREVIEW_WINDOW) is True,
|
||||||
sublime.windows()))):
|
sublime.windows()))):
|
||||||
# print("MarkdownLivePreview.py:81", 'open window')
|
|
||||||
sublime.run_command('new_markdown_live_preview')
|
sublime.run_command('new_markdown_live_preview')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,7 @@ hope: You'll enjoy using it!
|
|||||||
|
|
||||||
And `<!-- vicious ones ;) -->`
|
And `<!-- vicious ones ;) -->`
|
||||||
|
|
||||||
Some `inline code` with *italic* and **bold** text.
|
Some `inline code` with *italic*, **bold** text, and ~~strike through~~.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import this
|
import this
|
||||||
|
|||||||
@ -128,5 +128,12 @@ def get_style(color_scheme):
|
|||||||
with open(USER_STYLE_FILE) as fp:
|
with open(USER_STYLE_FILE) as fp:
|
||||||
css += '\n' + fp.read() + '\n'
|
css += '\n' + fp.read() + '\n'
|
||||||
if color_scheme:
|
if color_scheme:
|
||||||
css += pygments_from_theme(color_scheme)
|
css += pygments_from_theme(get_resource(color_scheme))
|
||||||
return ''.join([line.strip() + ' ' for line in css.splitlines()])
|
return ''.join([line.strip() + ' ' for line in css.splitlines()])
|
||||||
|
|
||||||
|
def get_resource(resource):
|
||||||
|
if os.path.exists(os.path.join(sublime.packages_path(), '..', resource)):
|
||||||
|
with open(os.path.join(sublime.packages_path(), '..', resource), encoding='utf-8') as fp:
|
||||||
|
return fp.read()
|
||||||
|
else:
|
||||||
|
return sublime.load_resource(resource)
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from xml.dom.minidom import parse
|
from xml.dom.minidom import parseString
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
class Style:
|
class Style:
|
||||||
@ -55,9 +55,9 @@ class Style:
|
|||||||
# colors and font styles from colortheme file
|
# colors and font styles from colortheme file
|
||||||
|
|
||||||
|
|
||||||
def get_settings(file_name):
|
def get_settings(color_scheme_content):
|
||||||
settings = defaultdict(lambda: [])
|
settings = defaultdict(lambda: [])
|
||||||
dom = parse(file_name)
|
dom = parseString(color_scheme_content)
|
||||||
arr = dom.getElementsByTagName('array')[0]
|
arr = dom.getElementsByTagName('array')[0]
|
||||||
editor_cfg = arr.getElementsByTagName('dict')[0].getElementsByTagName('dict')[0]
|
editor_cfg = arr.getElementsByTagName('dict')[0].getElementsByTagName('dict')[0]
|
||||||
editor_vals = editor_cfg.getElementsByTagName('string')
|
editor_vals = editor_cfg.getElementsByTagName('string')
|
||||||
@ -82,8 +82,8 @@ def get_settings(file_name):
|
|||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def pygments_from_theme(file):
|
def pygments_from_theme(color_scheme_content):
|
||||||
settings = get_settings(file)
|
settings = get_settings(color_scheme_content)
|
||||||
styles = []
|
styles = []
|
||||||
|
|
||||||
#Generic
|
#Generic
|
||||||
|
|||||||
@ -7,3 +7,4 @@ IS_HIDDEN = 'is_hidden_markdown_live_preview'
|
|||||||
MD_VIEW_ID = 'markdown_live_preview_md_id'
|
MD_VIEW_ID = 'markdown_live_preview_md_id'
|
||||||
PREVIEW_WINDOW = 'markdown_live_preview_window'
|
PREVIEW_WINDOW = 'markdown_live_preview_window'
|
||||||
ON_OPEN = 'markdown_live_preview_on_open'
|
ON_OPEN = 'markdown_live_preview_on_open'
|
||||||
|
LAST_UPDATE = 'markdonw_live_preview_last_run'
|
||||||
|
|||||||
Reference in New Issue
Block a user