From 0dea8afba40719442d866925a33a2cc75f014ee2 Mon Sep 17 00:00:00 2001 From: Mathieu PATUREL Date: Fri, 15 Nov 2019 15:19:15 +1100 Subject: [PATCH] fix clipping of files after pre The aim is to replace every \n in a
 with a 
because st doesn't support pre. However, ST doesn't support
for some reason, only
or
. We use to add some
s, but BeautifulSoup automatically adds a
when it sees a
(close the tag), which causes the clipping of the rest of the file by ST. But if we replace every \n with a
, BeautifulSoup automatically replaces it with
(= ST bug) So, we do exactly that, except that at the very end, when markdown2html returns, we replace every
with a
--- MarkdownLivePreview.py | 2 -- markdown2html.py | 7 ++++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/MarkdownLivePreview.py b/MarkdownLivePreview.py index f7d5f78..ab7fa10 100644 --- a/MarkdownLivePreview.py +++ b/MarkdownLivePreview.py @@ -207,8 +207,6 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): resources ) - print(repr(html)) - self.phantom_sets[markdown_view.id()].update([ sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK, lambda href: sublime.run_command('open_url', {'url': href})) diff --git a/markdown2html.py b/markdown2html.py index 2468b1f..d053da6 100644 --- a/markdown2html.py +++ b/markdown2html.py @@ -71,14 +71,15 @@ def markdown2html(markdown, basepath, re_render, resources): # FIXME: this method sucks, but can we do better? fixed_pre = str(code_element) \ - .replace('\n', '
')\ - .replace(' ', '.') + .replace(' ', '.') \ + .replace('\n', '
') code_element.replace_with(bs4.BeautifulSoup(fixed_pre, "html.parser")) # FIXME: highlight the code using Sublime's syntax - return "\n\n{}".format(resources['stylesheet'], soup) + # FIXME: report that ST doesn't support
but does work with
... WTF? + return "\n\n{}".format(resources['stylesheet'], soup).replace('
', '
') def get_base64_image(path, re_render):