From e3896a6b3d93c06dff28e042bd09c095fddb9a3d Mon Sep 17 00:00:00 2001 From: Mathieu PATUREL Date: Fri, 15 Nov 2019 15:02:31 +1100 Subject: [PATCH] fix indentation in pre in preview Again, this is a dodgy hack: replace spaces with dot with the color exactly like the background, because otherwise ST ignores it, even in pre --- MarkdownLivePreview.py | 2 +- live-testing/test.md | 4 +++- markdown2html.py | 14 ++++++++------ resources/stylesheet.css | 3 +++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/MarkdownLivePreview.py b/MarkdownLivePreview.py index 980a064..f7d5f78 100644 --- a/MarkdownLivePreview.py +++ b/MarkdownLivePreview.py @@ -207,7 +207,7 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): resources ) - # print(html) + print(repr(html)) self.phantom_sets[markdown_view.id()].update([ sublime.Phantom(sublime.Region(0), html, sublime.LAYOUT_BLOCK, diff --git a/live-testing/test.md b/live-testing/test.md index d829260..609f165 100644 --- a/live-testing/test.md +++ b/live-testing/test.md @@ -6,7 +6,9 @@ what the hell... ```python import this -# you should try this + +if input("answer yes") != 'yes': + print("Really?") ``` this flickering is really annoying... diff --git a/markdown2html.py b/markdown2html.py index 9b33dfb..2468b1f 100644 --- a/markdown2html.py +++ b/markdown2html.py @@ -64,15 +64,17 @@ def markdown2html(markdown, basepath, re_render, resources): # FIXME: how do tables look? should we use ascii tables? - # FIXME: pre aren't handled by ST3. The require manual adjustment - - br = soup.new_tag('br') + # pre aren't handled by ST3. The require manual adjustment for pre_element in soup.find_all('pre'): # select the first child, code_element = next(pre_element.children) - # FIXME: this line sucks, but can we do better? - code_element.replace_with( - bs4.BeautifulSoup(str(code_element).replace('\n', '
'), "html.parser")) + + # FIXME: this method sucks, but can we do better? + fixed_pre = str(code_element) \ + .replace('\n', '
')\ + .replace(' ', '.') + + code_element.replace_with(bs4.BeautifulSoup(fixed_pre, "html.parser")) # FIXME: highlight the code using Sublime's syntax diff --git a/resources/stylesheet.css b/resources/stylesheet.css index ac04e54..f8c119d 100644 --- a/resources/stylesheet.css +++ b/resources/stylesheet.css @@ -38,3 +38,6 @@ pre code { padding: 0; } +i.space { + color: var(--very-light-bg); +} \ No newline at end of file