From 8c1012eb8c057bb4952cd99a334b5789fa176702 Mon Sep 17 00:00:00 2001 From: Mathieu PATUREL Date: Thu, 14 Nov 2019 21:17:22 +1100 Subject: [PATCH] Remove entry in phantom_sets when markdown_view is closed Otherwise the object would keep on growing forever. It probably would never ever be a problem for anyone, but it just makes me feel better --- MarkdownLivePreview.py | 10 ++++++++++ live-testing/images.md | 16 ++++++++++++++++ live-testing/test.md | 19 +++---------------- markdown2html.py | 6 ++++-- 4 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 live-testing/images.md diff --git a/MarkdownLivePreview.py b/MarkdownLivePreview.py index f330712..5bc40fb 100644 --- a/MarkdownLivePreview.py +++ b/MarkdownLivePreview.py @@ -15,6 +15,7 @@ PREVIEW_VIEW_INFOS = "preview_view_infos" # FIXME: put this as a setting for the user to choose? DELAY = 500 # ms +# Terminology # original_view: the view in the regular editor, without it's own window # markdown_view: the markdown view, in the special window # preview_view: the preview view, in the special window @@ -92,6 +93,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): # markdown_view.id(): phantom set } + # FIXME: maybe we shouldn't restore the file in the original window... + def on_pre_close(self, markdown_view): """ Close the view in the preview window, and store information for the on_close listener (see doc there) @@ -118,6 +121,7 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): preview_view = markdown_view.window().active_view_in_group(1) + # FIXME: set the preview title self.phantom_sets[markdown_view.id()] = sublime.PhantomSet(preview_view) self._update_preview(markdown_view) @@ -131,6 +135,8 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): assert markdown_view.id() == self.markdown_view.id(), \ "pre_close view.id() != close view.id()" + del self.phantom_sets[markdown_view.id()] + self.preview_window.run_command('close_window') # find the window with the right id @@ -150,11 +156,15 @@ class MarkdownLivePreviewListener(sublime_plugin.EventListener): original_view.set_syntax_file(markdown_view.settings().get('syntax')) + # here, views are NOT treated independently, which is theoretically wrong # but in practice, you can only edit one markdown file at a time, so it doesn't really # matter. # @min_time_between_call(.5) def on_modified_async(self, markdown_view): + + # FIXME: it keeps on flickering, it's really annoying + infos = markdown_view.settings().get(MARKDOWN_VIEW_INFOS) if not infos: return diff --git a/live-testing/images.md b/live-testing/images.md new file mode 100644 index 0000000..268e112 --- /dev/null +++ b/live-testing/images.md @@ -0,0 +1,16 @@ +I'm not sure that it **actually** going to work, but it seems nicer than the [previous version][prev] + +This is the first image from the local file system (absolute path, sorry, it's not going +to work on your system unless your username is math2001): + +![The sublime text logo!](file:///home/math2001/.config/sublime-text-3/Packages/MarkdownLivePreview2/live-testing/sublime_text.png) + +This is the first image from the local file system, *relative* path! + +![The sublime text logo!](sublime_merge.png) + +This is the first image from the internet! + +![math2001's logo](https://avatars1.githubusercontent.com/u/15224242?s=400&u=53324cf4e303d15032ba53aa41673a2046b3284b&v=4) + +[prev]: https://github.com/math2001/MarkdownLivePreview/tree/d4c477749ce7e77b8e9fc85464a2488f003c45bc \ No newline at end of file diff --git a/live-testing/test.md b/live-testing/test.md index 50be7cf..24d3981 100644 --- a/live-testing/test.md +++ b/live-testing/test.md @@ -1,25 +1,12 @@ # hello world -This is a *test*. +This is a *test*. asdfas ``` import this # you should try this ``` -I'm not sure that it **actually** going to work, but it seems nicer than the [previous version][prev] + -This is the first image from the local file system (absolute path, sorry, it's not going -to work on your system unless your username is math2001): - -![The sublime text logo!](file:///home/math2001/.config/sublime-text-3/Packages/MarkdownLivePreview2/live-testing/sublime_text.png) - -This is the first image from the local file system, *relative* path! - -![The sublime text logo!](sublime_merge.png) - -This is the first image from the internet! - -![math2001's logo](https://avatars1.githubusercontent.com/u/15224242?s=400&u=53324cf4e303d15032ba53aa41673a2046b3284b&v=4) - -[prev]: https://github.com/math2001/MarkdownLivePreview/tree/d4c477749ce7e77b8e9fc85464a2488f003c45bc \ No newline at end of file +this flickering is really annoying... \ No newline at end of file diff --git a/markdown2html.py b/markdown2html.py index ad16814..3d4792c 100644 --- a/markdown2html.py +++ b/markdown2html.py @@ -62,14 +62,16 @@ def markdown2html(markdown, basepath, re_render): img_element['src'] = base64 + # remove comments, because they pollute the console with error messages + for comment_element in soup.find_all(text=lambda text: isinstance(text, bs4.Comment)): + comment_element.extract() + # FIXME: how do tables look? should we use ascii tables? # FIXME: pre aren't handled by ST3. The require manual adjustment # FIXME: include a stylesheet - # FIXME: remove the comments, because they pollute the console with error messages - return str(soup) def get_base64_image(path, re_render):