Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0505ca30bc | |||
| c49ae26720 | |||
| c2618ead1d | |||
| 6e113fef6e | |||
| e5378e2300 | |||
| caf932b536 | |||
| fa106c8206 | |||
| 0ac9fd9aaa | |||
| 5bbfb4606d | |||
| 37703e9bab | |||
| 3b920f4336 | |||
| abe151fdb7 |
@ -7,6 +7,17 @@
|
||||
"children": [
|
||||
{
|
||||
"caption": "MarkdownLivePreview",
|
||||
"children": [
|
||||
{
|
||||
"caption": "Settings",
|
||||
"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",
|
||||
@ -18,3 +29,5 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
34
MLPApi.py
34
MLPApi.py
@ -11,17 +11,19 @@ from .escape_amp import *
|
||||
from .functions import *
|
||||
from .setting_names import *
|
||||
from .image_manager import CACHE_FILE
|
||||
from random import randint as rnd
|
||||
|
||||
__folder__ = os.path.dirname(__file__)
|
||||
|
||||
STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User',
|
||||
'MarkdownLivePreview.css')
|
||||
|
||||
# used to store the phantom's set
|
||||
views = {}
|
||||
|
||||
def plugin_loaded():
|
||||
global DEFAULT_STYLE_FILE
|
||||
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()
|
||||
@ -35,7 +37,7 @@ def create_preview(window, file_name):
|
||||
|
||||
preview.set_name(get_preview_name(file_name))
|
||||
preview.set_scratch(True)
|
||||
preview.set_syntax_file('Packages/MarkdownLivePreview/.sublime/'
|
||||
preview.set_syntax_file('Packages/MarkdownLivePreview/.sublime/' + \
|
||||
'MarkdownLivePreviewSyntax.hidden-tmLanguage')
|
||||
|
||||
return preview
|
||||
@ -45,6 +47,7 @@ def get_style():
|
||||
return content + "pre code .space {color: var(--light-bg)}"
|
||||
|
||||
def show_html(md_view, preview):
|
||||
global views
|
||||
html = []
|
||||
html.append('<style>\n{}\n</style>'.format(get_style()))
|
||||
html.append(pre_with_br(md2.markdown(get_view_content(md_view),
|
||||
@ -65,25 +68,30 @@ def show_html(md_view, preview):
|
||||
html = html.replace(' espace;', '<i class="space">.</i>')
|
||||
html = replace_img_src_base64(html, basepath=os.path.dirname(
|
||||
md_view.file_name()))
|
||||
preview.erase_phantoms('markdown_preview')
|
||||
preview.add_phantom('markdown_preview',
|
||||
sublime.Region(-1),
|
||||
html,
|
||||
sublime.LAYOUT_BLOCK,
|
||||
lambda href: sublime.run_command('open_url',
|
||||
{'url': href}))
|
||||
|
||||
return
|
||||
# set viewport position
|
||||
phantom_set = views.setdefault(preview.id(),
|
||||
sublime.PhantomSet(preview, 'markdown_live_preview'))
|
||||
phantom_set.update([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})
|
||||
# get the "ratio" of the markdown view's position.
|
||||
# 0 < y < 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]]
|
||||
# remove half of the viewport_extent.y to center it on the screen (verticaly)
|
||||
vector[1] -= preview.viewport_extent()[1] / 2
|
||||
vector[1] = mini(vector[1], 0)
|
||||
# make sure the minimum is 0
|
||||
vector[1] = 0 if vector[1] < 0 else vector[1]
|
||||
# the hide the first line
|
||||
vector[1] += preview.line_height()
|
||||
preview.set_viewport_position(vector, animate=False)
|
||||
|
||||
def clear_cache():
|
||||
"""Removes the cache file"""
|
||||
os.remove(CACHE_FILE)
|
||||
|
||||
def release_phantoms_set():
|
||||
global views
|
||||
|
||||
@ -72,8 +72,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener):
|
||||
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'
|
||||
and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/' + \
|
||||
'.sublime/MarkdownLivePreviewSyntax' + \
|
||||
'.hidden-tmLanguage'):
|
||||
sublime.run_command('new_markdown_live_preview')
|
||||
|
||||
@ -110,3 +110,8 @@ class MarkdownLivePreviewClearCacheCommand(sublime_plugin.ApplicationCommand):
|
||||
|
||||
def run(self):
|
||||
clear_cache()
|
||||
|
||||
class MarkdownLivePreviewReleasePhantomSetCommand(sublime_plugin.ApplicationCommand):
|
||||
|
||||
def run(self):
|
||||
release_phantoms_set()
|
||||
|
||||
@ -1,19 +1,13 @@
|
||||
Fast:
|
||||
|
||||
☐ sync scroll @needsUpdate(because of images)
|
||||
☐ cache image in object when used, so that it's faster @needsTest
|
||||
☐ add clear cache command
|
||||
☐ update README for settings in view
|
||||
☐ add edit settings
|
||||
|
||||
Medium:
|
||||
☐ auto refresh preview if loading images
|
||||
☐ use alt attribute for 404 error
|
||||
☐ use MarkdownLivePreview syntax, so we can use syntax's settings
|
||||
☐ listen for settings to change
|
||||
☐ fix custom css @bug
|
||||
|
||||
Long:
|
||||
☐ fix #4 @high
|
||||
☐ support hanchor (TOC) @big
|
||||
|
||||
Unknown:
|
||||
@ -22,6 +16,12 @@ Unknown:
|
||||
|
||||
___________________
|
||||
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)
|
||||
|
||||
57
README.md
57
README.md
@ -21,18 +21,58 @@ to have MarkdownLivePreview working on your computer. Cool right? You can [thank
|
||||
|
||||
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.
|
||||
|
||||
It will open a new window, with only your markdown file, with the preview. Once your done, close whichever file and it'll close the entire window.
|
||||
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.
|
||||
|
||||
*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*
|
||||
*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 it's [suggestion](https://github.com/math2001/MarkdownLivePreview/issues/7#issue-199464852)). Default to `false`
|
||||
- `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://"]`
|
||||
|
||||
### In dev
|
||||
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
|
||||
|
||||
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).
|
||||
### 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
|
||||
|
||||
@ -40,7 +80,11 @@ This plugin is not finished, there's still some things to fix (custom css, focus
|
||||
|
||||
### 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)
|
||||
|
||||
@ -49,3 +93,4 @@ Some of the package add a command in the menus, others in the command palette, o
|
||||
|
||||
|
||||
[markdown-extended]: https://packagecontrol.io/packages/Markdown%20Extended
|
||||
[github-issue-tracker]: https://github.com/math2001/MarkdownLivePreview/issues
|
||||
|
||||
@ -23,8 +23,8 @@ def replace_img_src_base64(html, basepath):
|
||||
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'))):
|
||||
if ''.join(path).startswith(tuple(get_settings().get('load_from_internet' + \
|
||||
'_when_starts', []))):
|
||||
image = ImageManager.get(''.join(path))
|
||||
image = image or loading
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"install": "messages/install.txt",
|
||||
"1.1.2": "messages/1.1.2.txt",
|
||||
"2.0.1": "messages/2.0.1.txt"
|
||||
"2.0.1": "messages/2.0.1.txt",
|
||||
"2.2.1": "messages/2.2.0.txt"
|
||||
}
|
||||
|
||||
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`)
|
||||
@ -10,10 +10,10 @@ 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
|
||||
To enable MarkdownLivePreview, you need to be 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.
|
||||
you type anything in, it'll show up with the preview in a new group.
|
||||
|
||||
Say thanks:
|
||||
~~~~~~~~~~~
|
||||
|
||||
17
sample.md
17
sample.md
@ -1,15 +1,8 @@
|
||||
# DuckDuckGo - The Search engine you'll fall in love
|
||||
# sample
|
||||
|
||||
Hope you'll enjoy using MarkdownLivePreview!
|
||||
sdfdsf
|
||||
|
||||

|
||||

|
||||
|
||||
```python
|
||||
print('Hello world')
|
||||
if DEBUG:
|
||||
print('DEBUG_MODE on')
|
||||
```
|
||||
|
||||
> Only a fool knows everything. A wise man knows how little he knows
|
||||
|
||||
The only think I know right now is that Boxy Theme's just awesome.
|
||||
sdfd
|
||||
sdf
|
||||
|
||||
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 |
Reference in New Issue
Block a user