Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb48b1c79f | |||
| 8317fa738c | |||
| 3be12b0539 | |||
| c92d78fb20 | |||
| 30d75f159d | |||
| 52e4b917e5 | |||
| 48a68b2a79 | |||
| 8eb0172eb4 | |||
| 52e35fb610 | |||
| 84f809e57f | |||
| 351e8bd355 | |||
| 5babc862b4 | |||
| dc7139fbe7 | |||
| bbbeae6fe9 | |||
| 271c7c619a |
@ -1,4 +1,16 @@
|
||||
{
|
||||
// As soon as you open a markdown file, it opens the window preview
|
||||
"markdown_live_preview_on_open": false,
|
||||
"load_from_internet_when_starts": ["http://", "https://"]
|
||||
|
||||
// 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"
|
||||
}
|
||||
|
||||
44
MLPApi.py
44
MLPApi.py
@ -30,13 +30,6 @@ def plugin_loaded():
|
||||
else:
|
||||
DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/default.css')
|
||||
|
||||
def get_preview_name(md_view):
|
||||
file_name = md_view.file_name()
|
||||
name = md_view.name() \
|
||||
or os.path.basename(file_name) if file_name else None \
|
||||
or 'Untitled'
|
||||
return name + ' - Preview'
|
||||
|
||||
def create_preview(window, file_name):
|
||||
preview = window.new_file()
|
||||
|
||||
@ -55,20 +48,43 @@ def get_style():
|
||||
return content
|
||||
|
||||
def markdown2html(md, basepath):
|
||||
html = ''
|
||||
html += '<style>\n{}\n</style>\n'.format(get_style())
|
||||
# pre_with_br
|
||||
html += pre_with_br(pre_tables(md2.markdown(md, extras=['fenced-code-blocks',
|
||||
'no-code-highlighting', 'tables'])))
|
||||
# removes/format the header.
|
||||
md = manage_header(md, get_settings().get('header_action'))
|
||||
|
||||
html = '<style>\n{}\n</style>\n'.format(get_style())
|
||||
|
||||
|
||||
# the option no-code-highlighting does not exists in the official version of markdown2 for now
|
||||
# I personaly edited the file (markdown2.py:1743)
|
||||
html += md2.markdown(md, extras=['fenced-code-blocks', 'no-code-highlighting', 'tables'])
|
||||
|
||||
html = html.replace(' ', ' espace;') # save where are the spaces
|
||||
# tables aren't supported by the Phantoms
|
||||
# This function transforms them into aligned ASCII tables and displays them in a <pre> 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 <br> 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 `<!-- hey hey! -->`, these one
|
||||
# won't be stripped!
|
||||
html = strip_html_comments(html)
|
||||
|
||||
# exception, again, because <pre> aren't supported by the phantoms
|
||||
html = html.replace(' espace;', '<i class="space">.</i>')
|
||||
# so, because this is monosaped font, I just replace it with a '.' and make transparent ;)
|
||||
html = html.replace(' ', '<i class="space">.</i>')
|
||||
|
||||
# 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=os.path.dirname(basepath))
|
||||
|
||||
# BeautifulSoup uses the <br/> but the sublime phantoms do not support them...
|
||||
html = html.replace('<br/>', '<br />').replace('<hr/>', '<hr />')
|
||||
|
||||
sublime.set_clipboard(html) # print
|
||||
|
||||
return html
|
||||
|
||||
def show_html(md_view, preview):
|
||||
|
||||
@ -15,7 +15,8 @@ class NewMarkdownLivePreviewCommand(sublime_plugin.ApplicationCommand):
|
||||
|
||||
current_view = sublime.active_window().active_view()
|
||||
file_name = current_view.file_name()
|
||||
current_view.close()
|
||||
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')
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
Fast:
|
||||
☐ cache image in object when used, so that it's faster @needsTest
|
||||
☐ add settings to keep md view open #13
|
||||
|
||||
Medium:
|
||||
☐ auto refresh preview if loading images
|
||||
|
||||
84
README.md
84
README.md
@ -4,44 +4,73 @@ This is a sublime text **3** plugin that allows you to preview your markdown ins
|
||||
|
||||
### 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
|
||||
|
||||
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`)
|
||||
2. Search for: `Package Control: Install Package`
|
||||
3. Search for: `MarkdownLivePreview`
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
- `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://"]`
|
||||
To edit MarkdownLivePreview's settings, you just need to look in the command palette
|
||||
`Preferences: MarkdownLivePreview Settings`, or from the menus:
|
||||
*Preferences → Package Settings → MarkdownLivePreview → Settings*
|
||||
|
||||
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
|
||||
Do not edit the left file (by default, you cannot), but edit the right file. This last 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](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://"]`
|
||||
- `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 set the value to `remove`
|
||||
- `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`
|
||||
|
||||
### 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
|
||||
|
||||
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).
|
||||
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:
|
||||
Note: MarkdownLivePreview will actualy look in this file for settings that aren't supported by
|
||||
default. Here they are:
|
||||
|
||||
- `show_tabs`
|
||||
- `show_minimap`
|
||||
@ -49,7 +78,9 @@ Note: MarkdownLivePreview will actualy look in this file for settings that aren'
|
||||
- `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.
|
||||
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:
|
||||
|
||||
@ -72,7 +103,9 @@ And here's what you'll get:
|
||||
|
||||
### 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
|
||||
|
||||
@ -80,17 +113,26 @@ MarkdownLivePreview caches every images it loads from internet (otherwise, you'd
|
||||
|
||||
### 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!!
|
||||
|
||||
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).
|
||||
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
|
||||
|
||||
12
default.css
12
default.css
@ -4,12 +4,11 @@ html {
|
||||
}
|
||||
|
||||
body {
|
||||
padding:10px;
|
||||
padding: 10px;
|
||||
padding-top: 0px;
|
||||
font-family: "Open Sans", sans-serif;
|
||||
background-color: var(--background);
|
||||
font-size: 15px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
@ -43,14 +42,19 @@ pre code {
|
||||
pre code .space {
|
||||
color: var(--light-bg);
|
||||
}
|
||||
|
||||
pre.table {
|
||||
background-color: var(--backgroud);
|
||||
background-color: var(--background);
|
||||
}
|
||||
pre.table code {
|
||||
background-color: var(--backgroud);
|
||||
background-color: var(--background);
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
pre.table code .space {
|
||||
color: var(--background);
|
||||
}
|
||||
|
||||
|
||||
kbd {
|
||||
padding: 0 5px;
|
||||
|
||||
@ -7,7 +7,6 @@ import os.path
|
||||
class MLPDevListener(sublime_plugin.EventListener):
|
||||
|
||||
def on_post_save(self, view):
|
||||
# return
|
||||
if not (os.path.dirname(__file__) in view.file_name() and
|
||||
view.file_name().endswith('.py')):
|
||||
return
|
||||
|
||||
@ -139,10 +139,10 @@ Here's what I'd recommend (and use):
|
||||
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
|
||||
about it, and even myself by sending me a [tweet][] or staring the repo!
|
||||
<iframe
|
||||
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
|
||||
[Markdown Extended]: https://packagecontrol.io/packages/Markdown%20Extended
|
||||
|
||||
24
docs/license.md
Normal file
24
docs/license.md
Normal 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 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.
|
||||
67
functions.py
67
functions.py
@ -4,39 +4,54 @@ import os.path
|
||||
import sublime
|
||||
import re
|
||||
from .image_manager import ImageManager
|
||||
from bs4 import BeautifulSoup
|
||||
from bs4 import BeautifulSoup, Comment as html_comment
|
||||
|
||||
def plugin_loaded():
|
||||
global error404, loading
|
||||
loading = sublime.load_resource('Packages/MarkdownLivePreview/loading.txt')
|
||||
error404 = sublime.load_resource('Packages/MarkdownLivePreview/404.txt')
|
||||
|
||||
MATCH_YAML_HEADER = re.compile(r'^([\-\+])\1{2}\n(?P<content>.+)\n\1{3}\n', re.DOTALL)
|
||||
|
||||
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 manage_header(md, action):
|
||||
matchobj = MATCH_YAML_HEADER.match(md)
|
||||
if not matchobj:
|
||||
return md
|
||||
if action == 'remove':
|
||||
return md[len(matchobj.group(0)):]
|
||||
elif action == 'wrap_in_pre':
|
||||
return '<pre><code>' + matchobj.group('content') + '</code></pre>' \
|
||||
+ md[len(matchobj.group(0)):]
|
||||
|
||||
raise ValueError('Got an unknown action: "{}"'.format(action))
|
||||
|
||||
def get_preview_name(md_view):
|
||||
file_name = md_view.file_name()
|
||||
name = md_view.name() \
|
||||
or os.path.basename(file_name) if file_name else None \
|
||||
or 'Untitled'
|
||||
return name + ' - Preview'
|
||||
|
||||
def replace_img_src_base64(html, basepath):
|
||||
"""Really messy, but it works (should be updated)"""
|
||||
index = -1
|
||||
tag_start = '<img src="'
|
||||
shtml, html = html, list(html)
|
||||
while True:
|
||||
index = shtml.find(tag_start, index + 1)
|
||||
if index == -1:
|
||||
break
|
||||
path, end = get_content_till(html, '"', start=index + len(tag_start))
|
||||
if ''.join(path).startswith('data:image/'):
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
load_from_internet_starters = get_settings().get('load_from_internet_when_starts')
|
||||
for img in soup.find_all('img'):
|
||||
if img['src'].startswith('data:image/'):
|
||||
continue
|
||||
if ''.join(path).startswith(tuple(get_settings().get('load_from_internet' + \
|
||||
'_when_starts', []))):
|
||||
image = ImageManager.get(''.join(path))
|
||||
image = image or loading
|
||||
elif img['src'].startswith(tuple(load_from_internet_starters)):
|
||||
image = ImageManager.get(img['src']) or loading
|
||||
else: # this is a local image
|
||||
image = to_base64(os.path.join(basepath, src))
|
||||
|
||||
else:
|
||||
# local image
|
||||
path = ''.join(path)
|
||||
path = os.path.join(basepath, path)
|
||||
image = to_base64(path)
|
||||
html[index+len(tag_start):end] = image
|
||||
shtml = ''.join(html)
|
||||
return ''.join(html)
|
||||
img['src'] = image
|
||||
|
||||
return str(soup)
|
||||
|
||||
def is_markdown_view(view):
|
||||
return 'markdown' in view.scope_name(0)
|
||||
@ -90,9 +105,9 @@ def get_settings():
|
||||
def pre_with_br(html):
|
||||
"""Because the phantoms of sublime text does not support <pre> blocks
|
||||
this function replaces every \n with a <br> in a <pre>"""
|
||||
soup = BeautifulSoup(html)
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
for pre in soup.find_all('pre'):
|
||||
code = pre.find('code')
|
||||
code.replaceWith(BeautifulSoup(''.join(str(node) for node in pre.contents) \
|
||||
.replace('\n', '<br/>').replace(' ', '<i class="space">.</i>'), 'html.parser'))
|
||||
return str(soup).replace('<br/>', '<br />')
|
||||
.replace('\n', '<br/>').replace(' ', '<i class="space">.</i>'), 'html.parser'))
|
||||
return str(soup)
|
||||
|
||||
@ -29,8 +29,18 @@ def pre_table(s_table):
|
||||
text += '|\n'
|
||||
|
||||
for j, cell in enumerate(row):
|
||||
text += '| ' + ''.join(str(node) for node in cell.contents) \
|
||||
+ ' ' * (cols_width[j] - len(cell.text) + 1)
|
||||
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
|
||||
@ -40,7 +50,3 @@ def pre_tables(html):
|
||||
for table in soup.find_all('table'):
|
||||
table.replace_with(BeautifulSoup(pre_table(table), 'html.parser'))
|
||||
return str(soup)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# CSW: ignore
|
||||
print(pre_tables(html))
|
||||
|
||||
16
sample.md
16
sample.md
@ -1,5 +1,15 @@
|
||||
---
|
||||
title: Demo
|
||||
description: Preview your markdown right in Sublime Text!
|
||||
hope: You'll enjoy using it!
|
||||
---
|
||||
|
||||
# Hello world
|
||||
|
||||
<!-- supports comments -->
|
||||
|
||||
And `<!-- vicious ones ;) -->`
|
||||
|
||||
Some `inline code` with *italic* and **bold** text.
|
||||
|
||||
```python
|
||||
@ -8,7 +18,6 @@ if you is moods.curious:
|
||||
print('then do it!')
|
||||
```
|
||||
|
||||
|
||||
<kbd>ctrl+\`</kbd> or *View → Show Console* and paste `import this`!
|
||||
|
||||
> Perfect programmers do NOT need comments.
|
||||
@ -17,6 +26,7 @@ if you is moods.curious:
|
||||
- you need
|
||||
- todos
|
||||
|
||||
|
||||
| ID | Name |
|
||||
|-----------|-------|
|
||||
| 56 | Matt |
|
||||
@ -25,9 +35,7 @@ if you is moods.curious:
|
||||
| 45 | John |
|
||||
| `<table>` | `><` |
|
||||
|
||||
[Sublime Text Logo](https://upload.wikimedia.org/wikipedia/en/4/4c/Sublime_Text_Logo.png)
|
||||
|
||||
|
||||

|
||||
|
||||
Some plugin I just *need*:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user