diff --git a/.gitignore b/.gitignore index 4c99b5d..21a36b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ Thumbs.db __pycache__/ cache.txt +venv/ diff --git a/.sublime/MarkdownLivePreview.sublime-commands b/.sublime/MarkdownLivePreview.sublime-commands index f092fa7..9f3dfca 100644 --- a/.sublime/MarkdownLivePreview.sublime-commands +++ b/.sublime/MarkdownLivePreview.sublime-commands @@ -4,7 +4,7 @@ "command": "new_markdown_live_preview" }, { - "caption": "MarkdownLivePreview: Clear Cache", + "caption": "MarkdownLivePreview: Clear the cache", "command": "markdown_live_preview_clear_cache" }, { diff --git a/MLPApi.py b/MLPApi.py index d958b76..6a4acc0 100644 --- a/MLPApi.py +++ b/MLPApi.py @@ -19,7 +19,7 @@ STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User', 'MarkdownLivePreview.css') # used to store the phantom's set -views = {} +windows_phantom_set = {} def plugin_loaded(): global DEFAULT_STYLE_FILE @@ -47,7 +47,7 @@ def get_style(): return content + "pre code .space {color: var(--light-bg)}" def show_html(md_view, preview): - global views + global windows_phantom_set html = [] html.append(''.format(get_style())) html.append(pre_with_br(md2.markdown(get_view_content(md_view), @@ -69,8 +69,9 @@ def show_html(md_view, preview): html = replace_img_src_base64(html, basepath=os.path.dirname( md_view.file_name())) - phantom_set = views.setdefault(preview.id(), - sublime.PhantomSet(preview, 'markdown_live_preview')) + phantom_set = windows_phantom_set.setdefault(preview.window().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}))]) @@ -93,5 +94,9 @@ def clear_cache(): """Removes the cache file""" os.remove(CACHE_FILE) -def release_phantoms_set(): - global views +def release_phantoms_set(view_id=None): + global windows_phantom_set + if view_id is None: + windows_phantom_set = {} + else: + del windows_phantom_set[view_id] diff --git a/MarkdownLivePreview.py b/MarkdownLivePreview.py index 391880b..5f377bb 100644 --- a/MarkdownLivePreview.py +++ b/MarkdownLivePreview.py @@ -64,6 +64,7 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): def on_window_command(self, window, command, args): if command == 'close' and window.settings().get(PREVIEW_WINDOW): + release_phantoms_set(window.id()) return 'close_window', {} def on_activated_async(self, view): @@ -105,13 +106,7 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): if show_menus is not None: window.set_menu_visible(show_menus) - class MarkdownLivePreviewClearCacheCommand(sublime_plugin.ApplicationCommand): def run(self): clear_cache() - -class MarkdownLivePreviewReleasePhantomSetCommand(sublime_plugin.ApplicationCommand): - - def run(self): - release_phantoms_set() diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..d424af9 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,129 @@ +Welcome to MarkdownLivePreview's documentation! + +MarkdownLivePreview is a [Sublime Text 3][st] plugin to preview your markdown as you type, +*right in Sublime Text itself*, without *any* dependency! + +It's very easy to use, but there's a few things that you might want to be aware of... So, let's +get started + +## Installation + +### Using Package Control + +You can really easily install MarkdownLivePreview by using [Package Control][pck-con]. + +If it's not already, you need to [install it][install-pck-con] first. + +!!! note + If you're using the latest build of Sublime Text 3, you can just do + *Tools → Install Package Control…* + +- Open up the command palette (ctrl+shift+p) +- Search up `Package Control: Install Package` (might take a few seconds) +- In the panel that just showed up, search for `MarkdownLivePreview` + +Done! You have now access to every single features of MarkdownLivePreview! :wink: + +### Using `git` + +```sh +$ cd "%APPDATA%\Sublime Text 3\Packages" # on Windows +$ cd ~/Library/Application\ Support/Sublime\ Text\ 3 # on Mac +$ cd ~/.config/sublime-text-3 # on Linux + +$ git clone "https://github.com/math2001/MarkdownLivePreview" +``` + +> So, which one do I pick?! + +I depends of what you want to do. If you want to just use MarkdownLivePreview, pick the first +solution, you'll get every update automatically. But if you want to contribute, then choose the +second solution. + +## Usage + +### Previewing + +As told in the introduction, MarkdownLivePreview is very easy to use: + +- open a markdown file +- press alt+m +- or select in the command palette `MarkdownLivePreview: Edit Current File` + +!!! note + The preview of unsaved markdown files is currently not supported. It should be fixed soon. + +!!! tip + [Markdown Extended][] is supported too! + +That's it. + +### Clearing the cache + +MarkdownLivePreview has a cache system to store images you load from internet. You can clear this +cache by searching up in the command palette `MarkdownLivePreview: Clear the cache`. + +!!! tip + The cache is one simple file called `MarkdownLivePreviewCache`, which is located in your temp + folder. To know where it is, you can open the Sublime Text console (ctrl+` or + *View → Show Console*), and paste this in: + + ```python + import tempfile; print(tempfile.gettempdir()) + ``` + +### Custom settings for the preview + +Sublime Text makes it easy to set custom settings for a specific *type* of view. For example, +`markdown`, `python`, etc. MarkdownLivePreview takes advantage of that: the preview view (the view +on the right) is a specific syntax (called — sorry for the originality — +`MarkdownLivePreviewSyntax`). So, to change this, you can focus the right view, open up the command +palette (ctrl+shift+p), and search up `Preferences: Settings — Syntax Specific`. In here, +you can specify any settings that is going to be applied only to this view. + +### The hacky part + +In fact, MarkdownLivePreview parses those settings, and looks for specific ones: + +- `show_tabs` +- `show_minimap` +- `show_status_bar` +- `show_sidebar` +- `show_menus` + +Those settings aren't supported by default because they affect the entire *window* instead of just +the view. But MarkdownLivePreview will look for them in your *preview*'s settings, and hide/show the +tabs, the minimap, etc... + +As you probably guessed those settings takes a bool for value (`true` or `false`). + +### Recommendation + +Here's what I'd recommend (and use): + +```json +{ + "show_menus": false, + "show_tabs": false, + "show_minimap": false, + "gutter": false, + "rulers": [], + "word_wrap": true +} +``` + +!!! note + On Windows at least, you can press alt to focus (so show) the menu, even if they're + originally hidden + +That's it! I hope you'll enjoy using this package! If it's the case, please let your friends know +about it, and even myself by sending me a [tweet][] or staring the repo +! + +[st]: https://sublimetext.com +[Markdown Extended]: https://packagecontrol.io/packages/Markdown%20Extended +[pck-con]: https://packagecontrol.io +[pck-con-ins]: https://packagecontrol.io/installation +[tweet]: https://twitter.com/_math2001 diff --git a/mkdocs.yml b/mkdocs.yml new file mode 100644 index 0000000..fd031b1 --- /dev/null +++ b/mkdocs.yml @@ -0,0 +1,34 @@ +site_name: MarkdownLivePreview +theme: material +repo_name: math2001/MarkdownLivePreview +repo_url: https://github.com/math2001/MarkdownLivePreview +site_description: Sublime Text 3 Plugin MarkdownLivePreview's documentation +site_author: math2001 + +markdown_extensions: + - toc(permalink=true) + - pymdownx.arithmatex + - pymdownx.betterem(smart_enable=all) + - pymdownx.caret + - pymdownx.critic + - pymdownx.emoji: + emoji_generator: !!python/name:pymdownx.emoji.to_svg + - pymdownx.inlinehilite + - pymdownx.magiclink + - pymdownx.mark + - pymdownx.smartsymbols + - pymdownx.superfences + - pymdownx.tasklist(custom_checkbox=true) + - pymdownx.tilde + - admonition + - codehilite + +extra: + palette: + primary: Blue + accent: Indigo + social: + - type: github + link: https://github.com/math2001 + - type: twitter + link: https://twitter.com/_math2001 diff --git a/sample.md b/sample.md index 79fc3a4..bfd5a5c 100644 --- a/sample.md +++ b/sample.md @@ -1,8 +1,8 @@ -# sample +# Hello world -sdfdsf - -![std](https://www.grafikart.fr/uploads/users/46570/2015/01/offtime-screens-11_1_.jpg) - -sdfd -sdf +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod +tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, +quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo +consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse +cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non +proident, sunt in culpa qui officia deserunt mollit anim id est laborum.