fix <hr>s ref #17

Phantoms do not support <hr/>, but <hr />
This commit is contained in:
=
2017-02-02 18:30:42 +11:00
parent 30d75f159d
commit c92d78fb20
3 changed files with 12 additions and 5 deletions

View File

@ -77,7 +77,9 @@ def markdown2html(md, basepath):
html = replace_img_src_base64(html, basepath=os.path.dirname(basepath)) html = replace_img_src_base64(html, basepath=os.path.dirname(basepath))
# BeautifulSoup uses the <br/> but the sublime phantoms do not support them... # BeautifulSoup uses the <br/> but the sublime phantoms do not support them...
html = html.replace('<br/>', '<br />') html = html.replace('<br/>', '<br />').replace('<hr/>', '<hr />')
sublime.set_clipboard(html) # print
return html return html

View File

@ -26,7 +26,7 @@ def get_preview_name(md_view):
return name + ' - Preview' return name + ' - Preview'
def replace_img_src_base64(html, basepath): def replace_img_src_base64(html, basepath):
soup = BeautifulSoup(html) soup = BeautifulSoup(html, 'html.parser')
load_from_internet_starters = get_settings().get('load_from_internet_when_starts') load_from_internet_starters = get_settings().get('load_from_internet_when_starts')
for img in soup.find_all('img'): for img in soup.find_all('img'):
if img['src'].startswith('data:image/'): if img['src'].startswith('data:image/'):
@ -92,9 +92,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) soup = BeautifulSoup(html, 'html.parser')
for pre in soup.find_all('pre'): for pre in soup.find_all('pre'):
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) return str(soup)

View File

@ -1,3 +1,7 @@
---
title: Demo
description: Preview your markdown!
---
# Hello world # Hello world
<!-- supports comments --> <!-- supports comments -->
@ -20,6 +24,7 @@ if you is moods.curious:
- you need - you need
- todos - todos
| ID | Name | | ID | Name |
|-----------|-------| |-----------|-------|
| 56 | Matt | | 56 | Matt |
@ -28,7 +33,7 @@ if you is moods.curious:
| 45 | John | | 45 | John |
| `<table>` | `><` | | `<table>` | `><` |
![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*: