Compare commits

..

7 Commits

Author SHA1 Message Date
52e35fb610 Remove comments. Fix #14
Phantom's do not support them.
2017-01-26 18:12:34 +11:00
84f809e57f [docs] add license and fix iframe in index.md 2017-01-26 14:35:20 +11:00
351e8bd355 fix spaces (dot) color in pre.table 2017-01-26 14:19:21 +11:00
5babc862b4 format README 2017-01-26 14:12:12 +11:00
dc7139fbe7 fix background color in tables 2017-01-26 12:59:23 +11:00
bbbeae6fe9 center tables <th>s #12 2017-01-26 12:24:09 +11:00
271c7c619a fix bug: remove hard-coded color in CSS 2017-01-26 11:47:18 +11:00
9 changed files with 116 additions and 42 deletions

View File

@ -55,20 +55,23 @@ def get_style():
return content return content
def markdown2html(md, basepath): def markdown2html(md, basepath):
html = '' html = '<style>\n{}\n</style>\n'.format(get_style())
html += '<style>\n{}\n</style>\n'.format(get_style())
# pre_with_br # pre_with_br
html += pre_with_br(pre_tables(md2.markdown(md, extras=['fenced-code-blocks', html += pre_with_br(pre_tables(md2.markdown(md, extras=['fenced-code-blocks',
'no-code-highlighting', 'tables']))) 'no-code-highlighting', 'tables'])))
# 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 = strip_html_comments(html)
# Beautiful uses the <br/> but the sublime phantoms do not support them...
html = html.replace('<br/>', '<br />')
html = html.replace('&nbsp;', '&nbspespace;') # save where are the spaces html = html.replace('&nbsp;', '&nbspespace;') # save where are the spaces
# exception, again, because <pre> aren't supported by the phantoms # exception, again, because <pre> aren't supported by the phantoms
html = html.replace('&nbspespace;', '<i class="space">.</i>') html = html.replace('&nbspespace;', '<i class="space">.</i>')
html = replace_img_src_base64(html, basepath=os.path.dirname(basepath)) html = replace_img_src_base64(html, basepath=os.path.dirname(basepath))
sublime.set_clipboard(html)
return html return html
def show_html(md_view, preview): def show_html(md_view, preview):

View File

@ -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

View File

@ -4,12 +4,11 @@ html {
} }
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);
font-size: 15px; font-size: 15px;
color: #333;
} }
blockquote { blockquote {
@ -43,14 +42,19 @@ pre code {
pre code .space { pre code .space {
color: var(--light-bg); color: var(--light-bg);
} }
pre.table { pre.table {
background-color: var(--backgroud); background-color: var(--background);
} }
pre.table code { pre.table code {
background-color: var(--backgroud); background-color: var(--background);
padding: 0; padding: 0;
margin: 0; margin: 0;
} }
pre.table code .space {
color: var(--background);
}
kbd { kbd {
padding: 0 5px; padding: 0 5px;

View File

@ -7,7 +7,6 @@ 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

View File

@ -139,10 +139,10 @@ Here's what I'd recommend (and use):
originally hidden originally hidden
That's it! I hope you'll enjoy using this package! If it's the case, please let your friends know 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 about it, and even myself by sending me a [tweet][] or staring the repo!
<iframe <iframe
src="https://ghbtns.com/github-btn.html?user=math2001&repo=MarkdownLivePreview&type=star&count=true&size=large" src="https://ghbtns.com/github-btn.html?user=math2001&repo=MarkdownLivePreview&type=star&count=true&size=large"
frameborder="0" scrolling="0" width="160px" height="30px"></iframe>! frameborder="0" scrolling="0" style="width: 120px; height: 30px; vertical-align: bottom"></iframe>
[st]: https://sublimetext.com [st]: https://sublimetext.com
[Markdown Extended]: https://packagecontrol.io/packages/Markdown%20Extended [Markdown Extended]: https://packagecontrol.io/packages/Markdown%20Extended

24
docs/license.md Normal file
View File

@ -0,0 +1,24 @@
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 dont 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.

View File

@ -4,13 +4,18 @@ 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 from bs4 import BeautifulSoup, Comment as html_comment
def plugin_loaded(): def plugin_loaded():
global error404, loading global error404, loading
loading = sublime.load_resource('Packages/MarkdownLivePreview/loading.txt') loading = sublime.load_resource('Packages/MarkdownLivePreview/loading.txt')
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt') error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
def strip_html_comments(html):
soup = BeautifulSoup(html, 'html.parser')
for element in soup.find_all(text=lambda text: isinstance(text, html_comment)):
element.extract()
return str(soup)
def replace_img_src_base64(html, basepath): def replace_img_src_base64(html, basepath):
"""Really messy, but it works (should be updated)""" """Really messy, but it works (should be updated)"""
@ -95,4 +100,4 @@ def pre_with_br(html):
code = pre.find('code') code = pre.find('code')
code.replaceWith(BeautifulSoup(''.join(str(node) for node in pre.contents) \ code.replaceWith(BeautifulSoup(''.join(str(node) for node in pre.contents) \
.replace('\n', '<br/>').replace(' ', '<i class="space">.</i>'), 'html.parser')) .replace('\n', '<br/>').replace(' ', '<i class="space">.</i>'), 'html.parser'))
return str(soup).replace('<br/>', '<br />') return str(soup)

View File

@ -29,7 +29,17 @@ def pre_table(s_table):
text += '|\n' text += '|\n'
for j, cell in enumerate(row): for j, cell in enumerate(row):
text += '| ' + ''.join(str(node) for node in cell.contents) \ 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) + ' ' * (cols_width[j] - len(cell.text) + 1)
text += '|\n' text += '|\n'
text += '</pre></code>' text += '</pre></code>'
@ -40,7 +50,3 @@ def pre_tables(html):
for table in soup.find_all('table'): for table in soup.find_all('table'):
table.replace_with(BeautifulSoup(pre_table(table), 'html.parser')) table.replace_with(BeautifulSoup(pre_table(table), 'html.parser'))
return str(soup) return str(soup)
if __name__ == "__main__":
# CSW: ignore
print(pre_tables(html))

View File

@ -1,5 +1,7 @@
# Hello world # Hello world
<!-- supports comments -->
Some `inline code` with *italic* and **bold** text. Some `inline code` with *italic* and **bold** text.
```python ```python
@ -8,7 +10,6 @@ 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. > Perfect programmers do NOT need comments.
@ -27,8 +28,6 @@ if you is moods.curious:
[Sublime Text Logo](https://upload.wikimedia.org/wikipedia/en/4/4c/Sublime_Text_Logo.png) [Sublime Text Logo](https://upload.wikimedia.org/wikipedia/en/4/4c/Sublime_Text_Logo.png)
Some plugin I just *need*: Some plugin I just *need*:
- [PackageResourceReviewer](https://packagecontrol.io/packages/PackageResourceViewer) - [PackageResourceReviewer](https://packagecontrol.io/packages/PackageResourceViewer)