From 685f75d76b73fa2ab15d322f4af14d5d1d6a64f2 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 4 Nov 2023 14:45:54 -0500 Subject: [PATCH] Added markdown check guard to plugin --- plugins/markdown_preview/plugin.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/plugins/markdown_preview/plugin.py b/plugins/markdown_preview/plugin.py index 1dffb30..0c56caa 100644 --- a/plugins/markdown_preview/plugin.py +++ b/plugins/markdown_preview/plugin.py @@ -27,6 +27,7 @@ class Plugin(MarkdownTemplateMixin, PluginBase): self._GLADE_FILE = f"{self.path}/markdown_preview.glade" self.is_preview_paused = False + self.is_md_file = False def run(self): @@ -54,23 +55,25 @@ class Plugin(MarkdownTemplateMixin, PluginBase): self._event_system.subscribe("set_active_src_view", self._set_active_src_view) self._event_system.subscribe("buffer_changed", self._do_markdown_translate) + def _buffer_changed_first_load(self, buffer): + self._buffer = buffer + + self._do_markdown_translate(buffer) + def _set_active_src_view(self, source_view): self._active_src_view = source_view self._buffer = self._active_src_view.get_buffer() - + + self._do_markdown_translate(self._buffer) + def _handle_settings(self, widget = None, eve = None): ... - - def _buffer_changed_first_load(self, buffer): - self._buffer = buffer - self._do_markdown_translate(buffer) - def _tggle_preview_updates(self, widget = None, eve = None): self.is_preview_paused = not self.is_preview_paused widget.set_active(self.is_preview_paused) - if notself.is_preview_paused: + if not self.is_preview_paused: self._do_markdown_translate(self._buffer) def _tggle_markdown_preview(self, widget = None, eve = None): @@ -89,9 +92,12 @@ class Plugin(MarkdownTemplateMixin, PluginBase): def _do_markdown_translate(self, buffer): if self.is_preview_paused: return + self.is_markdown_check() is_visible = self._markdown_dialog.is_visible() - if not is_visible: return + if not is_visible or not self.is_md_file: return + self.render_markdown(buffer) + def render_markdown(self, buffer): start_iter = buffer.get_start_iter() end_iter = buffer.get_end_iter() text = buffer.get_text(start_iter, end_iter, include_hidden_chars = False) @@ -99,4 +105,10 @@ class Plugin(MarkdownTemplateMixin, PluginBase): path = self._active_src_view.get_current_filepath().get_parent().get_path() data = self.wrap_html_to_body(html) - self._markdown_view.load_html(content = data, base_uri = f"file://{path}/") \ No newline at end of file + self._markdown_view.load_html(content = data, base_uri = f"file://{path}/") + + def is_markdown_check(self): + self.is_md_file = self._active_src_view.get_filetype() == "markdown" + if not self.is_md_file: + data = self.wrap_html_to_body("