diff --git a/MLPApi.py b/MLPApi.py index 4956bd4..36dca8a 100644 --- a/MLPApi.py +++ b/MLPApi.py @@ -7,6 +7,7 @@ import os.path from html.parser import HTMLParser from .lib import markdown2 as md2 +from .lib.pre_tables import pre_tables from .escape_amp import * from .functions import * from .setting_names import * @@ -20,6 +21,7 @@ USER_STYLE_FILE = os.path.join(os.path.dirname(__folder__), 'User', 'MarkdownLiv # used to store the phantom's set windows_phantom_set = {} + def plugin_loaded(): global DEFAULT_STYLE_FILE DEFAULT_STYLE_FILE = sublime.load_resource('Packages/MarkdownLivePreview/default.css') @@ -48,35 +50,32 @@ def get_style(): content += '\n' + fp.read() + '\n' return content -def show_html(md_view, preview): - global windows_phantom_set - html = [] - html.append(''.format(get_style())) - html.append(pre_with_br(md2.markdown(get_view_content(md_view), - extras=['fenced-code-blocks', - 'no-code-highlighting']))) - # the option no-code-highlighting does not exists - # in the official version of markdown2 for now +def markdown2html(md, basepath): + html = '' + html += '\n'.format(get_style()) + # pre_with_br + html += pre_with_br(pre_tables(md2.markdown(md, extras=['fenced-code-blocks', + 'no-code-highlighting', 'tables']))) + # 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 = '\n'.join(html) html = html.replace(' ', ' espace;') # save where are the spaces - html = HTMLParser().unescape(html) - - html = escape_amp(html) # exception, again, because
aren't supported by the phantoms
html = html.replace(' espace;', '.')
- html = replace_img_src_base64(html, basepath=os.path.dirname(
- md_view.file_name()))
+ html = replace_img_src_base64(html, basepath=os.path.dirname(basepath))
+ sublime.set_clipboard(html)
+ 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(),
- sublime.PhantomSet(preview,
- 'markdown_live_preview'))
+ 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}))])
# lambda href: sublime.run_command('open_url', {'url': href})
# get the "ratio" of the markdown view's position.
diff --git a/default.css b/default.css
index 4142fb0..888dfcd 100644
--- a/default.css
+++ b/default.css
@@ -9,13 +9,13 @@ body {
font-family: "Open Sans", sans-serif;
background-color: var(--background);
font-size: 15px;
+ color: #333;
}
blockquote {
font-style: italic;
display: block;
margin-left: 30px;
- border: 1px solid red;
}
code {
diff --git a/dependencies.json b/dependencies.json
new file mode 100644
index 0000000..d0b3031
--- /dev/null
+++ b/dependencies.json
@@ -0,0 +1,7 @@
+{
+ "*": {
+ "*": [
+ "bs4"
+ ]
+ }
+}
diff --git a/devListener.py b/devListener.py
index ae4c06d..10b1bb8 100644
--- a/devListener.py
+++ b/devListener.py
@@ -16,5 +16,6 @@ class MLPDevListener(sublime_plugin.EventListener):
'MarkdownLivePreview.py'),
'scripts': ['image_manager', 'functions', 'MLPApi',
'setting_names'],
+ 'folders': ['lib'],
'quiet': True
})
diff --git a/functions.py b/functions.py
index 8a113b4..dda3699 100644
--- a/functions.py
+++ b/functions.py
@@ -5,6 +5,7 @@ import sublime
import re
from .image_manager import ImageManager
+
def plugin_loaded():
global error404, loading
loading = sublime.load_resource('Packages/MarkdownLivePreview/loading.txt')
diff --git a/lib/pre_tables.py b/lib/pre_tables.py
new file mode 100644
index 0000000..b041831
--- /dev/null
+++ b/lib/pre_tables.py
@@ -0,0 +1,72 @@
+# -*- encoding: utf-8 -*-
+
+from bs4 import BeautifulSoup
+
+html = """
+
+| ID | +Name | +
|---|---|
| 56 | +Matt | +
| 42 | +Colin | +
| 23 | +Lisa | +
| 45 | +John | +
<table> |
+ <e> |
+
'
+ for i, row in enumerate(rows):
+ for j, cell in enumerate(row):
+ text += '| ' + ''.join(str(node) for node in cell.contents) + ' ' * (cols_width[j] - len(cell.text))
+ text += '|\n'
+ text += ''
+ 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)
+
+if __name__ == "__main__":
+ # CSW: ignore
+ print(pre_tables(html))
diff --git a/sample.md b/sample.md
index 51bd651..1bddc52 100644
--- a/sample.md
+++ b/sample.md
@@ -16,7 +16,17 @@ if you is moods.curious:
- you need
- todos
-
+| ID | Name |
+|-----------|-------|
+| 56 | Matt |
+| 42 | Colin |
+| 23 | Lisa |
+| 45 | John |
+| `