diff --git a/md_in_popup.py b/md_in_popup.py index e27326a..3d4b7fa 100644 --- a/md_in_popup.py +++ b/md_in_popup.py @@ -2,6 +2,9 @@ import sublime import sublime_plugin from . import markdown2 import os.path +import re + +from html.parser import HTMLParser # Main sublime tools function @@ -14,9 +17,14 @@ def sm(*t, **kwargs): def em(*t, **kwargs): sublime.error_message(kwargs.get('sep', ' ').join([str(el) for el in t])) +STYLE_FILE = os.path.join(sublime.packages_path(), 'User', 'MarkdownLivePreview.css') def get_style(): """Of course, this is temporal, there will be an option to customize the CSS""" - return """""" + """ + +def pre_with_br(html): + """Because the phantoms of sublime text does not support
 blocks
+    this function replaces every \n with a 
in a
"""
+
+    while True:
+        obj = re.search(r'
.*?
', html, re.DOTALL) + if not obj: + break + html = list(html) + html[obj.start(0):obj.end(0)] = ''.join(html[obj.start(0):obj.end(0)]).replace('\n', '
').replace('
', '
')
+        html = ''.join(html)
+    return html
 
 def close_preview(md_view_settings, preview):
     preview.close()
@@ -54,7 +75,8 @@ def create_preview(window, md_view):
     return preview, preview_settings
 
 def show_html(md_view, preview):
-    html = get_style() + markdown2.markdown(get_view_content(md_view))
+    html = ''.format(get_style()) + pre_with_br(markdown2.markdown(get_view_content(md_view), extras=['fenced-code-blocks']))
+    html = HTMLParser().unescape(html)
     preview.erase_phantoms('markdown_preview')
     preview.add_phantom('markdown_preview',
                          sublime.Region(0),
diff --git a/sample.md b/sample.md
index 13dd15a..7fe125a 100644
--- a/sample.md
+++ b/sample.md
@@ -24,5 +24,23 @@ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
 > If the implementation is easy to explain, it may be a good idea.  
 > Namespaces are one honking great idea -- let's do more of those!  
 
-> Code tells you how, comments tells you why
+> Code tells you how, comments tells you why c
+
+
+    print('hello world')
+    print('hi')
+
+```python
+print('This is some pretty')
+print('cool stuff')
+```
+
+This is some `code`
+
+- a
+- list
+
+1. an
+2. other
+3. list
 
diff --git a/todo.md b/todo.md
index 2290c8a..0b1e1e4 100644
--- a/todo.md
+++ b/todo.md
@@ -1,9 +1,9 @@
 # todo
 
-- add **custom css** feature
 - sync scroll
+- add message in status bar 
+- add **custom css** feature
 - regive focus to the right markdown view @done
-- set the title of the preview
-- add message in status bar
-- disable previewing when the preview is closed
-- check when setting is activated and create panel and stuff
\ No newline at end of file
+- set the title of the preview @done
+- disable previewing when the preview is closed @done
+- check when setting is activated and create panel and stuff @done
\ No newline at end of file