Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5babc862b4 | |||
| dc7139fbe7 | |||
| bbbeae6fe9 | |||
| 271c7c619a | |||
| 8cc6b2b263 | |||
| c7961ce94c | |||
| eae91fa428 | |||
| 6f18e8e4a2 | |||
| 48c1800065 | |||
| bad1cb74c6 | |||
| 4198504fd1 | |||
| 1bef00de14 | |||
| d707cf7a47 |
@ -7,6 +7,13 @@
|
|||||||
"caption": "MarkdownLivePreview: Clear the cache",
|
"caption": "MarkdownLivePreview: Clear the cache",
|
||||||
"command": "markdown_live_preview_clear_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",
|
"caption": "Preferences: MarkdownLivePreview Settings",
|
||||||
"command": "edit_settings",
|
"command": "edit_settings",
|
||||||
|
|||||||
50
MLPApi.py
50
MLPApi.py
@ -7,6 +7,7 @@ import os.path
|
|||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
|
||||||
from .lib import markdown2 as md2
|
from .lib import markdown2 as md2
|
||||||
|
from .lib.pre_tables import pre_tables
|
||||||
from .escape_amp import *
|
from .escape_amp import *
|
||||||
from .functions import *
|
from .functions import *
|
||||||
from .setting_names import *
|
from .setting_names import *
|
||||||
@ -15,15 +16,19 @@ from random import randint as rnd
|
|||||||
|
|
||||||
__folder__ = os.path.dirname(__file__)
|
__folder__ = os.path.dirname(__file__)
|
||||||
|
|
||||||
STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User',
|
USER_STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User', 'MarkdownLivePreview.css')
|
||||||
'MarkdownLivePreview.css')
|
|
||||||
|
|
||||||
# used to store the phantom's set
|
# used to store the phantom's set
|
||||||
windows_phantom_set = {}
|
windows_phantom_set = {}
|
||||||
|
|
||||||
|
|
||||||
def plugin_loaded():
|
def plugin_loaded():
|
||||||
global DEFAULT_STYLE_FILE
|
global DEFAULT_STYLE_FILE
|
||||||
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/default.css')
|
if os.path.exists(os.path.join(__folder__, 'default.css')):
|
||||||
|
with open(os.path.join(__folder__, 'default.css')) as fp:
|
||||||
|
DEFAULT_STYLE_FILE = fp.read()
|
||||||
|
else:
|
||||||
|
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/default.css')
|
||||||
|
|
||||||
def get_preview_name(md_view):
|
def get_preview_name(md_view):
|
||||||
file_name = md_view.file_name()
|
file_name = md_view.file_name()
|
||||||
@ -44,37 +49,36 @@ def create_preview(window, file_name):
|
|||||||
|
|
||||||
def get_style():
|
def get_style():
|
||||||
content = ''.join([line.strip() + ' ' for line in DEFAULT_STYLE_FILE.splitlines()])
|
content = ''.join([line.strip() + ' ' for line in DEFAULT_STYLE_FILE.splitlines()])
|
||||||
return content + "pre code .space {color: var(--light-bg)}"
|
if os.path.exists(USER_STYLE_FILE):
|
||||||
|
with open(USER_STYLE_FILE) as fp:
|
||||||
|
content += '\n' + fp.read() + '\n'
|
||||||
|
return content
|
||||||
|
|
||||||
def show_html(md_view, preview):
|
def markdown2html(md, basepath):
|
||||||
global windows_phantom_set
|
html = ''
|
||||||
html = []
|
html += '<style>\n{}\n</style>\n'.format(get_style())
|
||||||
html.append('<style>\n{}\n</style>'.format(get_style()))
|
# pre_with_br
|
||||||
html.append(pre_with_br(md2.markdown(get_view_content(md_view),
|
html += pre_with_br(pre_tables(md2.markdown(md, extras=['fenced-code-blocks',
|
||||||
extras=['fenced-code-blocks',
|
'no-code-highlighting', 'tables'])))
|
||||||
'no-code-highlighting'])))
|
# 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 = '\n'.join(html)
|
|
||||||
|
|
||||||
html = html.replace(' ', ' espace;') # save where are the spaces
|
html = html.replace(' ', ' espace;') # save where are the spaces
|
||||||
|
|
||||||
html = HTMLParser().unescape(html)
|
|
||||||
|
|
||||||
html = escape_amp(html)
|
|
||||||
|
|
||||||
# exception, again, because <pre> aren't supported by the phantoms
|
# exception, again, because <pre> aren't supported by the phantoms
|
||||||
html = html.replace(' espace;', '<i class="space">.</i>')
|
html = html.replace(' espace;', '<i class="space">.</i>')
|
||||||
html = replace_img_src_base64(html, basepath=os.path.dirname(
|
html = replace_img_src_base64(html, basepath=os.path.dirname(basepath))
|
||||||
md_view.file_name()))
|
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()))
|
||||||
|
|
||||||
phantom_set = windows_phantom_set.setdefault(preview.window().id(),
|
phantom_set = windows_phantom_set.setdefault(preview.window().id(),
|
||||||
sublime.PhantomSet(preview,
|
sublime.PhantomSet(preview, 'markdown_live_preview'))
|
||||||
'markdown_live_preview'))
|
|
||||||
phantom_set.update([sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK,
|
phantom_set.update([sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK,
|
||||||
lambda href: sublime.run_command('open_url',
|
lambda href: sublime.run_command('open_url', {'url': href}))])
|
||||||
{'url': href}))])
|
|
||||||
|
|
||||||
# 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.
|
# get the "ratio" of the markdown view's position.
|
||||||
|
|||||||
@ -1,21 +1,21 @@
|
|||||||
Fast:
|
Fast:
|
||||||
☐ sync scroll @needsUpdate(because of images)
|
|
||||||
☐ cache image in object when used, so that it's faster @needsTest
|
☐ cache image in object when used, so that it's faster @needsTest
|
||||||
|
|
||||||
Medium:
|
Medium:
|
||||||
☐ auto refresh preview if loading images
|
☐ auto refresh preview if loading images
|
||||||
☐ use alt attribute for 404 error
|
☐ use alt attribute for 404 error
|
||||||
☐ fix custom css @bug
|
|
||||||
|
|
||||||
Long:
|
Long:
|
||||||
☐ support hanchor (TOC) @big
|
☐ support anchor (TOC) @big
|
||||||
|
|
||||||
Unknown:
|
Unknown:
|
||||||
☐ check how many times is the show_html function called
|
|
||||||
|
|
||||||
|
|
||||||
___________________
|
___________________
|
||||||
Archive:
|
Archive:
|
||||||
|
✔ fix custom css @bug @done Sun 22 Jan 2017 at 18:40 @project(Medium)
|
||||||
|
✘ check how many times is the show_html function called @cancelled Sun 22 Jan 2017 at 18:40 @project(Unknown)
|
||||||
|
✔ sync scroll @needsUpdate(because of images) @done Sun 22 Jan 2017 at 18:39 @project(Fast)
|
||||||
✔ fix #4 @high @done Mon 09 Jan 2017 at 18:42 @project(Long)
|
✔ 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)
|
✔ 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)
|
✔ add clear cache command @done Mon 09 Jan 2017 at 18:41 @project(Fast)
|
||||||
|
|||||||
76
README.md
76
README.md
@ -4,44 +4,65 @@ This is a sublime text **3** plugin that allows you to preview your markdown ins
|
|||||||
|
|
||||||
### Dependencies
|
### Dependencies
|
||||||
|
|
||||||
**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.
|
**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
|
## Installation
|
||||||
|
|
||||||
MarkdownLivePreview is available on the default channel of [PackageControl](http://packagecontrol.io), which means you just have to
|
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`)
|
1. Open the command palette (`ctrl+shift+p`)
|
||||||
2. Search for: `Package Control: Install Package`
|
2. Search for: `Package Control: Install Package`
|
||||||
3. Search for: `MarkdownLivePreview`
|
3. Search for: `MarkdownLivePreview`
|
||||||
4. hit <kbd>enter</kbd>
|
4. hit <kbd>enter</kbd>
|
||||||
|
|
||||||
to have MarkdownLivePreview working on your computer. Cool right? You can [thank package control](https://packagecontrol.io/say_thanks) for this.
|
to have MarkdownLivePreview working on your computer. Cool right? You can
|
||||||
|
[thank package control](https://packagecontrol.io/say_thanks) for this.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
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.
|
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
|
### 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 its [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
|
||||||
- `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://"]`
|
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://"]`
|
||||||
|
|
||||||
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
|
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
|
||||||
|
|
||||||
### Syntax Specific Settings
|
### 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).
|
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
|
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)
|
1. focus the *preview* (<kbd>ctrl+2</kbd> to focus the second group, so, by default, the
|
||||||
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).
|
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:
|
Note: MarkdownLivePreview will actualy look in this file for settings that aren't supported by
|
||||||
|
default. Here they are:
|
||||||
|
|
||||||
- `show_tabs`
|
- `show_tabs`
|
||||||
- `show_minimap`
|
- `show_minimap`
|
||||||
@ -49,7 +70,9 @@ Note: MarkdownLivePreview will actualy look in this file for settings that aren'
|
|||||||
- `show_sidebar`
|
- `show_sidebar`
|
||||||
- `show_menus`
|
- `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.
|
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:
|
Here is an example of syntax specific settings for MarkdownLivePreviewSyntax:
|
||||||
|
|
||||||
@ -72,7 +95,9 @@ And here's what you'll get:
|
|||||||
|
|
||||||
### Clear the cache
|
### 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 `
|
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
|
### Demo
|
||||||
|
|
||||||
@ -80,17 +105,26 @@ MarkdownLivePreview caches every images it loads from internet (otherwise, you'd
|
|||||||
|
|
||||||
### Custom css
|
### 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 → 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.
|
It is possible to set your own css. But, be carefull, you have to respect
|
||||||
|
[those rules][st-css-rules]. 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!!
|
### 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]
|
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)
|
|
||||||
|
|
||||||
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).
|
|
||||||
|
|
||||||
|
### 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
|
[markdown-extended]: https://packagecontrol.io/packages/Markdown%20Extended
|
||||||
[github-issue-tracker]: https://github.com/math2001/MarkdownLivePreview/issues
|
[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
|
||||||
|
|||||||
31
default.css
31
default.css
@ -1,8 +1,10 @@
|
|||||||
html {
|
html {
|
||||||
--light-bg: color(var(--background) blend(#999 85%));
|
--light-bg: color(var(--background) blend(#999 85%));
|
||||||
|
--very-light-bg: color(var(--background) blend(#999 92%));
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
padding:10px;
|
padding: 10px;
|
||||||
padding-top: 0px;
|
padding-top: 0px;
|
||||||
font-family: "Open Sans", sans-serif;
|
font-family: "Open Sans", sans-serif;
|
||||||
background-color: var(--background);
|
background-color: var(--background);
|
||||||
@ -13,7 +15,6 @@ blockquote {
|
|||||||
font-style: italic;
|
font-style: italic;
|
||||||
display: block;
|
display: block;
|
||||||
margin-left: 30px;
|
margin-left: 30px;
|
||||||
border: 1px solid red;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code {
|
code {
|
||||||
@ -22,28 +23,36 @@ code {
|
|||||||
background-color: var(--light-bg);
|
background-color: var(--light-bg);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
margin: 5px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
pre {
|
||||||
display: block;
|
display: block;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
line-height: 1.7;
|
|
||||||
background-color: var(--light-bg);
|
background-color: var(--light-bg);
|
||||||
padding-left: 10px;
|
padding-left: 10px;
|
||||||
|
padding-top: 5px;
|
||||||
|
padding-bottom: 5px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
}
|
}
|
||||||
pre code {
|
pre code {
|
||||||
padding-left: 0;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
kbd {
|
kbd {
|
||||||
padding: 0 .29412em;
|
padding: 0 5px;
|
||||||
border-radius: .2rem;
|
background-color: var(--very-light-bg);
|
||||||
background-color: #f5f5f5;
|
|
||||||
color: #555;
|
|
||||||
box-shadow: 0 0.1rem 0 #b0b0b0;
|
|
||||||
word-break: break-word;
|
|
||||||
font-family: "Roboto Mono","Courier New",Courier,monospace;
|
font-family: "Roboto Mono","Courier New",Courier,monospace;
|
||||||
}
|
}
|
||||||
|
|||||||
7
dependencies.json
Normal file
7
dependencies.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"*": {
|
||||||
|
"*": [
|
||||||
|
"bs4"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,14 +7,14 @@ import os.path
|
|||||||
class MLPDevListener(sublime_plugin.EventListener):
|
class MLPDevListener(sublime_plugin.EventListener):
|
||||||
|
|
||||||
def on_post_save(self, view):
|
def on_post_save(self, view):
|
||||||
return
|
|
||||||
if not (os.path.dirname(__file__) in view.file_name() and
|
if not (os.path.dirname(__file__) in view.file_name() and
|
||||||
view.file_name().endswith('.py')):
|
view.file_name().endswith('.py')):
|
||||||
return
|
return
|
||||||
sublime.run_command('reload_plugin', {
|
sublime.run_command('reload_plugin', {
|
||||||
'main': os.path.join(sublime.packages_path(),
|
'main': os.path.join(sublime.packages_path(), 'MarkdownLivePreview',
|
||||||
'MarkdownLivePreview', 'md_in_popup.py'),
|
'MarkdownLivePreview.py'),
|
||||||
'scripts': ['image_manager', 'functions', 'MLPApi',
|
'scripts': ['image_manager', 'functions', 'MLPApi',
|
||||||
'setting_names'],
|
'setting_names'],
|
||||||
|
'folders': ['lib'],
|
||||||
'quiet': True
|
'quiet': True
|
||||||
})
|
})
|
||||||
|
|||||||
@ -59,7 +59,26 @@ As told in the introduction, MarkdownLivePreview is very easy to use:
|
|||||||
!!! tip
|
!!! tip
|
||||||
[Markdown Extended][] is supported too!
|
[Markdown Extended][] is supported too!
|
||||||
|
|
||||||
That's it.
|
That's it. That's all you need to do to preview your markdown!
|
||||||
|
|
||||||
|
### 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
|
||||||
|
(<kbd>ctrl+shift+p</kbd>). 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
|
### Clearing the cache
|
||||||
|
|
||||||
@ -115,7 +134,7 @@ Here's what I'd recommend (and use):
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
!!! note
|
!!! tip
|
||||||
On Windows at least, you can press <kbd>alt</kbd> to focus (so show) the menu, even if they're
|
On Windows at least, you can press <kbd>alt</kbd> to focus (so show) the menu, even if they're
|
||||||
originally hidden
|
originally hidden
|
||||||
|
|
||||||
@ -130,3 +149,4 @@ frameborder="0" scrolling="0" width="160px" height="30px"></iframe>!
|
|||||||
[pck-con]: https://packagecontrol.io
|
[pck-con]: https://packagecontrol.io
|
||||||
[install-pck-con]: https://packagecontrol.io/installation
|
[install-pck-con]: https://packagecontrol.io/installation
|
||||||
[tweet]: https://twitter.com/_math2001
|
[tweet]: https://twitter.com/_math2001
|
||||||
|
[GitHub repo]: https://github.com/math2001/MarkdownLivePreview/issues
|
||||||
|
|||||||
18
functions.py
18
functions.py
@ -4,6 +4,7 @@ import os.path
|
|||||||
import sublime
|
import sublime
|
||||||
import re
|
import re
|
||||||
from .image_manager import ImageManager
|
from .image_manager import ImageManager
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
def plugin_loaded():
|
def plugin_loaded():
|
||||||
global error404, loading
|
global error404, loading
|
||||||
@ -89,14 +90,9 @@ def get_settings():
|
|||||||
def pre_with_br(html):
|
def pre_with_br(html):
|
||||||
"""Because the phantoms of sublime text does not support <pre> blocks
|
"""Because the phantoms of sublime text does not support <pre> blocks
|
||||||
this function replaces every \n with a <br> in a <pre>"""
|
this function replaces every \n with a <br> in a <pre>"""
|
||||||
|
soup = BeautifulSoup(html)
|
||||||
while True:
|
for pre in soup.find_all('pre'):
|
||||||
obj = re.search(r'<pre>(.*?)</pre>', html, re.DOTALL)
|
code = pre.find('code')
|
||||||
if not obj:
|
code.replaceWith(BeautifulSoup(''.join(str(node) for node in pre.contents) \
|
||||||
break
|
.replace('\n', '<br/>').replace(' ', '<i class="space">.</i>'), 'html.parser'))
|
||||||
html = list(html)
|
return str(soup).replace('<br/>', '<br />')
|
||||||
html[obj.start(0):obj.end(0)] = '<pre >' + ''.join(html[obj.start(1):obj.end(1)]) \
|
|
||||||
.replace('\n', '<br>') \
|
|
||||||
.replace(' ', ' ') + '</pre>'
|
|
||||||
html = ''.join(html)
|
|
||||||
return html
|
|
||||||
|
|||||||
52
lib/pre_tables.py
Normal file
52
lib/pre_tables.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
'pre_tables' transform *html* tables into markdown tables, and put them in some <pre><code> tags
|
||||||
|
"""
|
||||||
|
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
def python_table(s_table):
|
||||||
|
"""Transform BeautifulSoup table into list of list"""
|
||||||
|
rows = []
|
||||||
|
for row in s_table.find_all('tr'):
|
||||||
|
# rows.append(list(map( lambda td: td.text, row.find_all(['th', 'td']) )))
|
||||||
|
rows.append(row.find_all(['th', 'td']))
|
||||||
|
return rows
|
||||||
|
|
||||||
|
def pre_table(s_table):
|
||||||
|
rows = python_table(s_table)
|
||||||
|
cols_width = [len(cell) for cell in rows[0]]
|
||||||
|
for j, row in enumerate(rows):
|
||||||
|
for i, cell in enumerate(row):
|
||||||
|
if cols_width[i] < len(cell.text):
|
||||||
|
cols_width[i] = len(cell.text)
|
||||||
|
text = '<pre class="table"><code>'
|
||||||
|
for i, row in enumerate(rows):
|
||||||
|
if i == 1:
|
||||||
|
for j, cell in enumerate(row):
|
||||||
|
text += '|' + '-' * (cols_width[j] + 2)
|
||||||
|
text += '|\n'
|
||||||
|
|
||||||
|
for j, cell in enumerate(row):
|
||||||
|
text += '| '
|
||||||
|
if cell.name == 'th':
|
||||||
|
title = ' ' * ((cols_width[j] - len(cell.text)) // 2) \
|
||||||
|
+ ''.join(str(node) for node in cell.contents) \
|
||||||
|
+ ' ' * int(round((cols_width[j] - len(cell.text)) / 2 ) + 1)
|
||||||
|
# + 1 because of the added space before the closing | of each cell
|
||||||
|
if cols_width[j] + 1 != len(title):
|
||||||
|
title += ' '
|
||||||
|
text += title
|
||||||
|
else:
|
||||||
|
text += ''.join(str(node) for node in cell.contents) \
|
||||||
|
+ ' ' * (cols_width[j] - len(cell.text) + 1)
|
||||||
|
text += '|\n'
|
||||||
|
text += '</pre></code>'
|
||||||
|
return text
|
||||||
|
|
||||||
|
def pre_tables(html):
|
||||||
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
|
for table in soup.find_all('table'):
|
||||||
|
table.replace_with(BeautifulSoup(pre_table(table), 'html.parser'))
|
||||||
|
return str(soup)
|
||||||
27
sample.md
27
sample.md
@ -4,8 +4,33 @@ Some `inline code` with *italic* and **bold** text.
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
import this
|
import this
|
||||||
if you('are', 'curious'):
|
if you is moods.curious:
|
||||||
print('then do it!')
|
print('then do it!')
|
||||||
```
|
```
|
||||||
|
|
||||||
<kbd>ctrl+\`</kbd> or *View → Show Console* and paste `import this`!
|
<kbd>ctrl+\`</kbd> 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 |
|
||||||
|
| `<table>` | `><` |
|
||||||
|
|
||||||
|
[Sublime Text Logo](https://upload.wikimedia.org/wikipedia/en/4/4c/Sublime_Text_Logo.png)
|
||||||
|
|
||||||
|
Some plugin I just *need*:
|
||||||
|
|
||||||
|
- [PackageResourceReviewer](https://packagecontrol.io/packages/PackageResourceViewer)
|
||||||
|
- [Boxy Theme](https://packagecontrol.io/packages/Boxy%20Theme)
|
||||||
|
- [Markdown Preview](https://packagecontrol.io/packages/Markdown%20Preview)
|
||||||
|
- [FileManager](https://packagecontrol.io/packages/FileManager)
|
||||||
|
- [PlainTasks](https://packagecontrol.io/packages/PlainTasks)
|
||||||
|
- [JSONComma](https://packagecontrol.io/packages/JSONComma)
|
||||||
|
|||||||
Reference in New Issue
Block a user