move resources.py to MarkdownLivePreview.py
Having an extra file is just a pain because you have to save it manually for ST to reload, and it was small and created way more trouble than it needed to... It fits really nicely in there anyway And add some nice CSS
This commit is contained in:
@ -6,16 +6,33 @@ from functools import partial
|
|||||||
|
|
||||||
from .markdown2html import markdown2html
|
from .markdown2html import markdown2html
|
||||||
from .utils import *
|
from .utils import *
|
||||||
from .resources import resources
|
|
||||||
|
|
||||||
def plugin_loaded():
|
|
||||||
pass
|
|
||||||
|
|
||||||
MARKDOWN_VIEW_INFOS = "markdown_view_infos"
|
MARKDOWN_VIEW_INFOS = "markdown_view_infos"
|
||||||
PREVIEW_VIEW_INFOS = "preview_view_infos"
|
PREVIEW_VIEW_INFOS = "preview_view_infos"
|
||||||
# FIXME: put this as a setting for the user to choose?
|
# FIXME: put this as a setting for the user to choose?
|
||||||
DELAY = 500 # ms
|
DELAY = 500 # ms
|
||||||
|
|
||||||
|
def get_resource(resource):
|
||||||
|
path = 'Packages/MarkdownLivePreview/resources/' + resource
|
||||||
|
abs_path = os.path.join(sublime.packages_path(), '..', path)
|
||||||
|
if os.path.isfile(abs_path):
|
||||||
|
with open(abs_path, 'r') as fp:
|
||||||
|
return fp.read()
|
||||||
|
return sublime.load_resource(path)
|
||||||
|
|
||||||
|
resources = {}
|
||||||
|
|
||||||
|
def plugin_loaded():
|
||||||
|
resources["base64_loading_image"] = get_resource('loading.base64')
|
||||||
|
resources["base64_404_image"] = get_resource('404.base64')
|
||||||
|
resources["stylesheet"] = get_resource('stylesheet.css')
|
||||||
|
|
||||||
|
# try to reload the resources if we save this file
|
||||||
|
try:
|
||||||
|
plugin_loaded()
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
# Terminology
|
# Terminology
|
||||||
# original_view: the view in the regular editor, without it's own window
|
# original_view: the view in the regular editor, without it's own window
|
||||||
# markdown_view: the markdown view, in the special window
|
# markdown_view: the markdown view, in the special window
|
||||||
@ -190,6 +207,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
|||||||
resources
|
resources
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(html)
|
||||||
|
|
||||||
self.phantom_sets[markdown_view.id()].update([
|
self.phantom_sets[markdown_view.id()].update([
|
||||||
sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK,
|
sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK,
|
||||||
lambda href: sublime.run_command('open_url', {'url': href}))
|
lambda href: sublime.run_command('open_url', {'url': href}))
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
# hello world
|
# hello world
|
||||||
|
|
||||||
This is a *test*. asdfas
|
This is a *test*. Some inline `[2]code()`.
|
||||||
|
|
||||||
```
|
```python
|
||||||
import this
|
import this
|
||||||
# you should try this
|
# you should try this
|
||||||
```
|
```
|
||||||
@ -10,3 +10,6 @@ import this
|
|||||||
<!-- some comment -->
|
<!-- some comment -->
|
||||||
|
|
||||||
this flickering is really annoying...
|
this flickering is really annoying...
|
||||||
|
|
||||||
|
|
||||||
|
It looks like it's gone... Oh wait nah, it's still here...
|
||||||
17
resources.py
17
resources.py
@ -1,17 +0,0 @@
|
|||||||
import os.path
|
|
||||||
import sublime
|
|
||||||
|
|
||||||
def get_resource(resource):
|
|
||||||
path = 'Packages/MarkdownLivePreview/resources/' + resource
|
|
||||||
abs_path = os.path.join(sublime.packages_path(), '..', path)
|
|
||||||
if os.path.isfile(abs_path):
|
|
||||||
with open(abs_path, 'r') as fp:
|
|
||||||
return fp.read()
|
|
||||||
return sublime.load_resource(path)
|
|
||||||
|
|
||||||
resources = {}
|
|
||||||
|
|
||||||
def plugin_loaded():
|
|
||||||
resources["base64_loading_image"] = get_resource('loading.base64')
|
|
||||||
resources["base64_404_image"] = get_resource('404.base64')
|
|
||||||
resources["stylesheet"] = get_resource('stylesheet.css')
|
|
||||||
@ -1,3 +1,40 @@
|
|||||||
body {
|
html {
|
||||||
font-family: "Open Sans", sans-serif, serif;
|
--light-bg: color(var(--background) blend(#fff 90%));
|
||||||
|
--very-light-bg: color(var(--background) blend(#fff 85%));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
font-family: "Ubuntu", "DejaVu Sans", "Open Sans", sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
blockquote {
|
||||||
|
font-style: italic;
|
||||||
|
display: block;
|
||||||
|
margin-left: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
display: block;
|
||||||
|
background-color: var(--very-light-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
padding-left: 0.2rem;
|
||||||
|
padding-right: 0.2rem;
|
||||||
|
margin: 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
background-color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
padding-left: 0.2rem;
|
||||||
|
padding-right: 0.2rem;
|
||||||
|
background-color: var(--very-light-bg);
|
||||||
|
margin: 0;
|
||||||
|
border-radius: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre code {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user