diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..dcc40d8
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,3 @@
+docs/ export-ignore
+resources/*.png export-ignore
+resources/*.py export-ignore
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 418af2e..bee8a64 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1 @@
-Thumbs.db
-__pycache__/
-cache.txt
-venv/
-site/
+__pycache__
diff --git a/.sublime/Default.sublime-keymap b/.sublime/Default.sublime-keymap
deleted file mode 100644
index 8808ee0..0000000
--- a/.sublime/Default.sublime-keymap
+++ /dev/null
@@ -1,13 +0,0 @@
-[
- {
- "keys": ["alt+m"],
- "command": "new_markdown_live_preview",
- "context": [
- {
- "key": "selector",
- "operator": "equal",
- "operand": "text.html.markdown"
- }
- ]
- }
-]
diff --git a/.sublime/Main.sublime-menu b/.sublime/Main.sublime-menu
deleted file mode 100644
index 2af2e98..0000000
--- a/.sublime/Main.sublime-menu
+++ /dev/null
@@ -1,33 +0,0 @@
-[
- {
- "id": "preferences",
- "children": [
- {
- "id": "package-settings",
- "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",
- "contents": "/* See http://www.sublimetext.com/docs/3/minihtml.html#css to know which property you're able to use */\n\n$0"
- }
- }
- ]
- }
- ]
- }
- ]
- }
-]
diff --git a/.sublime/MarkdownLivePreview.sublime-commands b/.sublime/MarkdownLivePreview.sublime-commands
deleted file mode 100644
index 01ab39c..0000000
--- a/.sublime/MarkdownLivePreview.sublime-commands
+++ /dev/null
@@ -1,25 +0,0 @@
-[
- {
- "caption": "MarkdownLivePreview: Edit Current File",
- "command": "new_markdown_live_preview"
- },
- {
- "caption": "MarkdownLivePreview: Clear the cache",
- "command": "markdown_live_preview_clear_cache"
- },
- {
- "caption": "MarkdownLivePreview: Edit Custom CSS File",
- "command": "open_file",
- "args": {
- "file": "$packages/User/MarkdownLivePreview.css"
- }
- },
- {
- "caption": "Preferences: MarkdownLivePreview 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$0\n}\n"
- }
- }
-]
diff --git a/.sublime/MarkdownLivePreview.sublime-settings b/.sublime/MarkdownLivePreview.sublime-settings
deleted file mode 100644
index b3f67a3..0000000
--- a/.sublime/MarkdownLivePreview.sublime-settings
+++ /dev/null
@@ -1,19 +0,0 @@
-{
- // As soon as you open a markdown file, it opens the window preview
- "markdown_live_preview_on_open": false,
-
- // If an image starts with one of those strings, then it will be loaded from internet
- "load_from_internet_when_starts": ["http://", "https://"],
-
- // When the preview is opened, the markdown file is closed in the origin window and reopend in
- // the preview window. If this option is set to 'true', then the markdown file will NOT be
- // closed in the origin window
- "keep_open_when_opening_preview": false,
-
- // Choose what to do with YAML/TOML (---/+++ respectively) headers
- // Valid values: "wrap_in_pre", "remove".
- "header_action": "wrap_in_pre",
-
- // Wait at least the specified *seconds* before updating the preview.
- "update_preview_every": 0
-}
diff --git a/.sublime/MarkdownLivePreviewSyntax.hidden-tmLanguage b/.sublime/MarkdownLivePreviewSyntax.hidden-tmLanguage
deleted file mode 100644
index af0511f..0000000
--- a/.sublime/MarkdownLivePreviewSyntax.hidden-tmLanguage
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
block - # (the ironic thing is that they aren't supported either :D) - html = pre_tables(html) - - # pre block are not supported by the Phantoms. - # This functions replaces the \n in them with
so that it does (1/2) - html = pre_with_br(html) - - # comments aren't supported by the Phantoms - # Simply removes them using bs4, so you can be sadic and type ``, these one - # won't be stripped! - html = strip_html_comments(html) - - # exception, again, becausearen't supported by the phantoms - # so, because this is monosaped font, I just replace it with a '.' and make transparent ;) - html = html.replace(' ', '.') - - # Phantoms have problem with images size when they're loaded from an url/path - # So, the solution is to convert them to base64 - html = replace_img_src_base64(html, basepath=basepath) - - # BeautifulSoup uses the
but the sublime phantoms do not support them... - html = html.replace('
', '
').replace('
', '
') - - return html - -def show_html(md_view, preview): - global windows_phantom_set - html = markdown2html(get_view_content(md_view), os.path.dirname(md_view.file_name()), md_view.settings().get('color_scheme')) - - 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}))]) - - # 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 - # 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(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 9dd992a..3b09249 100644 --- a/MarkdownLivePreview.py +++ b/MarkdownLivePreview.py @@ -1,124 +1,223 @@ -# -*- encoding: utf-8 -*- - +import os.path import sublime import sublime_plugin -import time -from .MLPApi import * -from .setting_names import * -from .functions import * +from functools import partial -class NewMarkdownLivePreviewCommand(sublime_plugin.ApplicationCommand): +from .markdown2html import markdown2html +from .utils import * - def run(self): +MARKDOWN_VIEW_INFOS = "markdown_view_infos" +PREVIEW_VIEW_INFOS = "preview_view_infos" +# FIXME: put this as a setting for the user to choose? +DELAY = 100 # ms - """Inspired by the edit_settings command""" +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) - current_view = sublime.active_window().active_view() - file_name = current_view.file_name() - if get_settings().get('keep_open_when_opening_preview') is False: - current_view.close() - if file_name is None: - return sublime.error_message('MarkdownLivePreview: Not supporting ' - 'unsaved file for now') +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 +# original_view: the view in the regular editor, without it's own window +# markdown_view: the markdown view, in the special window +# preview_view: the preview view, in the special window +# original_window: the regular window +# preview_window: the window with the markdown file and the preview + +class MdlpInsertCommand(sublime_plugin.TextCommand): + + def run(self, edit, point, string): + self.view.insert(edit, point, string) + +class OpenMarkdownPreviewCommand(sublime_plugin.TextCommand): + + def run(self, edit): + + """ If the file is saved exists on disk, we close it, and reopen it in a new + window. Otherwise, we copy the content, erase it all (to close the file without + a dialog) and re-insert it into a new view into a new window """ + + original_view = self.view + original_window_id = original_view.window().id() + file_name = original_view.file_name() + + syntax_file = original_view.settings().get('syntax') + + if file_name: + original_view.close() + else: + # the file isn't saved, we need to restore the content manually + total_region = sublime.Region(0, original_view.size()) + content = original_view.substr(total_region) + original_view.erase(edit, total_region) + original_view.close() + # FIXME: save the document to a temporary file, so that if we crash, + # the user doesn't lose what he wrote sublime.run_command('new_window') - self.window = sublime.active_window() - self.window.settings().set(PREVIEW_WINDOW, True) - self.window.run_command('set_layout', { + preview_window = sublime.active_window() + + preview_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() + preview_window.focus_group(1) + preview_view = preview_window.new_file() + preview_view.set_scratch(True) + preview_view.settings().set(PREVIEW_VIEW_INFOS, {}) + preview_view.set_name('Preview') - mdsettings.set(PREVIEW_ENABLED, True) - mdsettings.set(PREVIEW_ID, preview.id()) + + preview_window.focus_group(0) + if file_name: + markdown_view = preview_window.open_file(file_name) + else: + markdown_view = preview_window.new_file() + markdown_view.run_command('mdlp_insert', {'point': 0, 'string': content}) + markdown_view.set_scratch(True) + + markdown_view.set_syntax_file(syntax_file) + markdown_view.settings().set(MARKDOWN_VIEW_INFOS, { + "original_window_id": original_window_id + }) def is_enabled(self): - return is_markdown_view(sublime.active_window().active_view()) + # FIXME: is this the best way there is to check if the current syntax is markdown? + # should we only support default markdown? + # what about "md"? + # FIXME: what about other languages, where markdown preview roughly works? + return 'markdown' in self.view.settings().get('syntax').lower() class MarkdownLivePreviewListener(sublime_plugin.EventListener): - def update(self, view): - vsettings = view.settings() - now = time.time() + phantom_sets = { + # markdown_view.id(): phantom set + } - 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): - 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)) + # we schedule an update for every key stroke, with a delay of DELAY + # then, we update only if now() - last_update > DELAY + last_update = 0 - show_html(view, preview) - return view, preview + # FIXME: maybe we shouldn't restore the file in the original window... - def on_modified_async(self, view): - if not is_markdown_view(view): # faster than getting the settings + def on_pre_close(self, markdown_view): + """ Close the view in the preview window, and store information for the on_close + listener (see doc there) + """ + if not markdown_view.settings().get(MARKDOWN_VIEW_INFOS): return - delay = get_settings().get('update_preview_every') - if not delay: - self.update(view) + + self.markdown_view = markdown_view + self.preview_window = markdown_view.window() + self.file_name = markdown_view.file_name() + + if self.file_name is None: + total_region = sublime.Region(0, markdown_view.size()) + self.content = markdown_view.substr(total_region) + markdown_view.erase(edit, total_region) else: - sublime.set_timeout(lambda: self.update(view), delay * 1000) + self.content = None - 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): - vsettings = view.settings() - - if (is_markdown_view(view) and get_settings().get(ON_OPEN) - and not vsettings.get(PREVIEW_ENABLED) - and vsettings.get('syntax') != 'Packages/MarkdownLivePreview/' + \ - '.sublime/MarkdownLivePreviewSyntax' + \ - '.hidden-tmLanguage' - and not any(filter(lambda window: window.settings().get(PREVIEW_WINDOW) is True, - sublime.windows()))): - sublime.run_command('new_markdown_live_preview') - - - def on_load_async(self, view): - """Check the settings to hide menu, minimap, etc""" - try: - md_view, preview = self.update(view) - except TypeError: - # the function update has returned None + def on_load_async(self, markdown_view): + infos = markdown_view.settings().get(MARKDOWN_VIEW_INFOS) + if not infos: return - window = preview.window() - psettings = preview.settings() - show_tabs = psettings.get('show_tabs') - 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') + preview_view = markdown_view.window().active_view_in_group(1) - 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) + self.phantom_sets[markdown_view.id()] = sublime.PhantomSet(preview_view) + self._update_preview(markdown_view) -class MarkdownLivePreviewClearCacheCommand(sublime_plugin.ApplicationCommand): + def on_close(self, markdown_view): + """ Use the information saved to restore the markdown_view as an original_view + """ + infos = markdown_view.settings().get(MARKDOWN_VIEW_INFOS) + if not infos: + return - def run(self): - clear_cache() + assert markdown_view.id() == self.markdown_view.id(), \ + "pre_close view.id() != close view.id()" + + del self.phantom_sets[markdown_view.id()] + + self.preview_window.run_command('close_window') + + # find the window with the right id + original_window = next(window for window in sublime.windows() \ + if window.id() == infos['original_window_id']) + if self.file_name: + original_window.open_file(self.file_name) + else: + assert markdown_view.is_scratch(), "markdown view of an unsaved file should " \ + "be a scratch" + # note here that this is called original_view, because it's what semantically + # makes sense, but this original_view.id() will be different than the one + # that we closed first to reopen in the preview window + # shouldn't cause any trouble though + original_view = original_window.new_file() + original_view.run_command('mdlp_insert', {'point': 0, 'string': self.content}) + + original_view.set_syntax_file(markdown_view.settings().get('syntax')) + + + # here, views are NOT treated independently, which is theoretically wrong + # but in practice, you can only edit one markdown file at a time, so it doesn't really + # matter. + # @min_time_between_call(.5) + def on_modified_async(self, markdown_view): + + infos = markdown_view.settings().get(MARKDOWN_VIEW_INFOS) + if not infos: + return + + # we schedule an update, which won't run if an + sublime.set_timeout(partial(self._update_preview, markdown_view), DELAY) + + def _update_preview(self, markdown_view): + # if the buffer id is 0, that means that the markdown_view has been closed + # This check is needed since a this function is used as a callback for when images + # are loaded from the internet (ie. it could finish loading *after* the user + # closes the markdown_view) + if time.time() - self.last_update < DELAY / 1000: + return + + if markdown_view.buffer_id() == 0: + return + + self.last_update = time.time() + + total_region = sublime.Region(0, markdown_view.size()) + markdown = markdown_view.substr(total_region) + + basepath = os.path.dirname(markdown_view.file_name()) + html = markdown2html( + markdown, + basepath, + partial(self._update_preview, markdown_view), + resources + ) + + self.phantom_sets[markdown_view.id()].update([ + sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK, + lambda href: sublime.run_command('open_url', {'url': href})) + ]) + + \ No newline at end of file diff --git a/MarkdownLivePreview.sublime-commands b/MarkdownLivePreview.sublime-commands new file mode 100644 index 0000000..cdca348 --- /dev/null +++ b/MarkdownLivePreview.sublime-commands @@ -0,0 +1,7 @@ +[ + + { + "caption": "MarkdownLivePreview: Open Preview", + "command": "open_markdown_preview" + } +] \ No newline at end of file diff --git a/README.md b/README.md index 02daa1f..5a8cef2 100644 --- a/README.md +++ b/README.md @@ -1,63 +1,18 @@ # MarkdownLivePreview -This is a sublime text **3** plugin that allows you to preview your markdown instantly *in* it! +A simple plugin to preview your markdown as you type right in Sublime Text. +No dependencies! -## Unmaintained +## How to install -I am now using vim. I don't have the energy or the time to maintain this plugin anymore. +It's available on package control! -If anyone is interested in maintaining it, fork it, and submit a PR to package control to make it point to your fork. +## How to contribute -### Dependencies +1. Fork this repo +2. Make your own branch (the name of the branch should be the feature you are + implementing eg. `improve-tables`, `fix-crash-on-multiple-preview` +3. All your code should be formated by black. +4. Send a PR! -**None! There is no dependency!** It uses [markdown2](https://github.com/trentm/python-markdown2) but it's a one file plugin, so it's included in the package. -## Installation - -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: Install Package` -3. Search for: `MarkdownLivePreview` -4. hit enter - -to have MarkdownLivePreview working on your computer. Cool right? You can -[thank package control](https://packagecontrol.io/say_thanks) for this. :wink: - -### Usage - -You can choose to enable MarkdownLivePreview by pressing alt+m 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. - -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* - -For further infos, please [read the docs](https://math2001.github.io/MarkdownLivePreview/)! - -### Demo - - - -### 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][] - -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 -[st-css-rules]: http://www.sublimetext.com/docs/3/minihtml.html#css -[README]: http://github.com/math2001/MarkdownLivePreview/README.md diff --git a/default.css b/default.css deleted file mode 100644 index 64bde6f..0000000 --- a/default.css +++ /dev/null @@ -1,63 +0,0 @@ -html { - --light-bg: color(var(--background) blend(#999 85%)); - --very-light-bg: color(var(--background) blend(#999 92%)); -} - -body { - padding: 10px; - padding-top: 0px; - font-family: "Open Sans", sans-serif; - background-color: var(--background); - font-size: 15px; -} - -blockquote { - font-style: italic; - display: block; - margin-left: 30px; -} - -code { - padding-left: 0.2rem; - padding-right: 0.2rem; - background-color: var(--light-bg); - margin: 0; - border-radius: 3px; -} - -div.codehilite { - display: block; - margin-top: 20px; - background-color: var(--light-bg); - padding-left: 10px; - padding-top: 5px; - padding-bottom: 5px; - width: 100%; - border-radius: 3px; -} -pre code { - padding: 0; -} - -pre code .space { - color: var(--light-bg); -} - -pre.table { - background-color: var(--background); -} -pre.table code { - background-color: var(--background); - padding: 0; - margin: 0; -} -pre.table code .space { - color: var(--background); -} - - -kbd { - padding: 0 5px; - background-color: var(--very-light-bg); - font-family: "Roboto Mono","Courier New",Courier,monospace; -} diff --git a/demo.gif b/demo.gif deleted file mode 100644 index d4ddb92..0000000 Binary files a/demo.gif and /dev/null differ diff --git a/dependencies.json b/dependencies.json index e7e714a..d0b3031 100644 --- a/dependencies.json +++ b/dependencies.json @@ -1,8 +1,7 @@ { "*": { "*": [ - "bs4", - "pygments" + "bs4" ] } } diff --git a/devListener.py b/devListener.py deleted file mode 100644 index 34e32ff..0000000 --- a/devListener.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- encoding: utf-8 -*- - -import sublime -import sublime_plugin -import os.path - -class MLPDevListener(sublime_plugin.EventListener): - - def on_post_save(self, view): - if not (os.path.dirname(__file__) in view.file_name() and - view.file_name().endswith('.py')): - return - sublime.run_command('reload_plugin', { - 'main': os.path.join(sublime.packages_path(), 'MarkdownLivePreview', - 'MarkdownLivePreview.py'), - 'scripts': ['image_manager', 'functions', 'MLPApi', - 'setting_names'], - 'folders': ['lib'], - 'quiet': True - }) diff --git a/docs/imgs/MarkdownLivePreview-opposite.svg b/docs/imgs/MarkdownLivePreview-opposite.svg deleted file mode 100644 index b11987c..0000000 --- a/docs/imgs/MarkdownLivePreview-opposite.svg +++ /dev/null @@ -1,92 +0,0 @@ - - - - diff --git a/docs/imgs/MarkdownLivePreview.svg b/docs/imgs/MarkdownLivePreview.svg deleted file mode 100644 index 37f19e4..0000000 --- a/docs/imgs/MarkdownLivePreview.svg +++ /dev/null @@ -1,92 +0,0 @@ - - - - diff --git a/docs/imgs/syntax-specific-settings.png b/docs/imgs/syntax-specific-settings.png deleted file mode 100644 index dc0dccf..0000000 Binary files a/docs/imgs/syntax-specific-settings.png and /dev/null differ diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index ddcd7a2..0000000 --- a/docs/index.md +++ /dev/null @@ -1,184 +0,0 @@ -# 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. That's all you need to do to preview your markdown! - -### Settings - -To edit MarkdownLivePreview's settings, you just need to search in the command palette -`Preferences: MarkdownLivePreview Settings`, or from the menus: -*Preferences → Package Settings → MarkdownLivePreview → Settings* - -Do not edit the left file (by default, you cannot), but the right one. This right file will -override the default one (on the left), and will be saved in your `User` folder, which makes it easy -to back up. - -- `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][] for its [suggestion][@ooing suggestion]). 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://"]` -- `header_action`: If you're writing a blog with some markdown and a static website generator, you -probably have a YAML header. By default, this header will be displayed in a `pre` block. If you want -to hide it, then just change the value to `remove`. Thanks to [@tanhanjay][] for -[letting me know][front-matter-issue]! -- `keep_open_when_opening_preview`: Each time the preview window is opened, the original markdown -view is closed. If you want to keep it opened, just set this setting to `true` - -### Custom CSS - -If you want to, you can add custom `CSS` to the MarkdownLivePreview's default stylesheet. - -Just search for `MarkdownLivePreview: Edit Custom CSS File` in the command palette -(ctrl+shift+p). It will open a file in which you can add some CSS that will be *added* to -the normal CSS. - -!!! bug - Comments in the CSS is interpreted weirdly by Sublime Text's phantoms. After a few tests, I - think that everything that is bellow a comment is ignored. - - If you want to be sure that your CSS works, don't put any comments in it - -#### Share your tweaks! - -If you think that other users would enjoy your added CSS, then raise an issue, or PR the -[GitHub repo][] to share your tweaks! - -### 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 for your MarkdownLivePreviewSyntax's settings (and what I use): - -```json -{ - "show_menus": false, - "show_tabs": false, - "show_minimap": false, - "gutter": false, - "rulers": [], - "word_wrap": true -} -``` - -And here's what you'll get (With the awesome [Boxy Theme][] and its [Monokai Color Scheme][]): - - - -!!! tip - On Windows at least, you can press alt to focus (so show) the menus, 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 -[install-pck-con]: https://packagecontrol.io/installation -[tweet]: https://twitter.com/_math2001 -[GitHub repo]: https://github.com/math2001/MarkdownLivePreview/issues -[@ooing]: https://github.com/ooing -[@ooing suggestion]: https://github.com/math2001/MarkdownLivePreview/issues/7#issue-199464852 -[@tanhanjay]: https://github.com/tanhanjay -[front-matter-issue]: https://github.com/math2001/MarkdownLivePreview/issues/17 -[Boxy Theme]: https://packagecontrol.io/packages/Boxy%20Theme -[Monokai Color Scheme]: https://github.com/ihodev/sublime-boxy#boxy-monokai--predawn diff --git a/docs/license.md b/docs/license.md deleted file mode 100644 index 0bf6cd0..0000000 --- a/docs/license.md +++ /dev/null @@ -1,24 +0,0 @@ -This project is published under MIT license. - -> The MIT License is a permissive license that is short and to the point. It lets people do anything -> they want with your code as long as they provide attribution back to you and don’t hold you -> liable. -> -> — *from [choosealicense.com](http://choosealicense.com), by [GitHub](https://github.com)* - -Copyright 2017 Mathieu PATUREL - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software -andassociated documentation files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, publish, distribute, -sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial -portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES -OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/escape_amp.py b/escape_amp.py deleted file mode 100644 index 5b3c078..0000000 --- a/escape_amp.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- encoding: utf-8 -*- - -import re - -__all__ = ['escape_amp'] - -RE_REPLACE_AMPERSAND = re.compile(r'&(\w*)(;)?') - -def replace(matchobj): - if matchobj.group(2): - return matchobj.group(0) - else: - return matchobj.group(0).replace('&', '&') - -def escape_amp(text): - return RE_REPLACE_AMPERSAND.sub(replace, text) - -def run_tests(): - tests = [ - ['&', '&'], - ['&', '&'], - ['&', '&'], - ['& &hello &bonjour;', '& &hello &bonjour;'] - ] - fails = 0 - for i, (subject, result) in enumerate(tests): - if RE_REPLACE_AMPERSAND.sub(replace, subject) != result: - # CSW: ignore - print('TEST FAIL ({i}): {subject!r} escaped did not match {result!r}'.format(**locals())) - fails += 1 - if fails == 0: - # CSW: ignore - print("SUCCESS: every tests ({}) passed successfully!".format(len(tests))) - else: - # CSW: ignore - print("{} test{} failed".format(fails, 's' if fails > 1 else '')) - -if __name__ == '__main__': - run_tests() diff --git a/example.md b/example.md deleted file mode 100644 index 8b3e57c..0000000 --- a/example.md +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: Demo -description: Preview your markdown right in Sublime Text! -hope: You'll enjoy using it! ---- - -# Hello world - - - -And `` - -Some `inline code` with *italic*, **bold** text, and ~~strike through~~. - -```python -import this -if you is moods.curious: - print('then do it!') -``` - -ctrl+\` or *View → Show Console* and paste `import this`! - -> Perfect programmers do NOT need comments. - -- to be efficient -- you need -- todos - - -| ID | Name | -|-----------|-------| -| 56 | Matt | -| 42 | Colin | -| 23 | Lisa | -| 45 | John | -| `