From a22db8e3114e7a25266da3105ad61bf9030d2ea1 Mon Sep 17 00:00:00 2001 From: Josh Panter Date: Sun, 6 Oct 2019 13:26:12 -0400 Subject: [PATCH 1/4] add all "extras" Small change to include the Python-Markdown "extras" extensions by default, instead of loading them one at a time. Extra and all its supported extensions are included in the standard Markdown library. --- markdownpreview.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/markdownpreview.py b/markdownpreview.py index 295c739..da6023b 100644 --- a/markdownpreview.py +++ b/markdownpreview.py @@ -152,9 +152,8 @@ def buffer_changed(self, buffer, view): html = markdown( text, extensions=[ + 'extra', 'codehilite', - 'fenced_code', - 'tables', AutoDirectionExtension(), ], extension_configs={ From c4acb6263a6a7bf8485159ecd13b377cc910c8e3 Mon Sep 17 00:00:00 2001 From: Josh Panter Date: Sun, 6 Oct 2019 15:58:35 -0400 Subject: [PATCH 2/4] optional pymdownx This includes loading some optional extensions via the `pymdown-extensions` package, if it is installed --- markdownpreview.py | 48 +++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/markdownpreview.py b/markdownpreview.py index da6023b..128f71c 100644 --- a/markdownpreview.py +++ b/markdownpreview.py @@ -1,6 +1,8 @@ import os from string import Template +import importlib.util + import gi from markdown import markdown from markdown.extensions import Extension @@ -149,20 +151,40 @@ def buffer_changed(self, buffer, view): buffer.get_end_iter(), True, ) - html = markdown( - text, - extensions=[ - 'extra', - 'codehilite', - AutoDirectionExtension(), - ], - extension_configs={ - 'codehilite': { - 'linenums': False, - 'noclasses': True, + if importlib.util.find_spec('pymdownx') is not None: + html = markdown( + text, + extensions=[ + 'pymdownx.caret', + 'pymdownx.extra', + 'pymdownx.mark', + 'pymdownx.tasklist', + 'pymdownx.tilde', + 'codehilite', + AutoDirectionExtension(), + ], + extension_configs={ + 'codehilite': { + 'linenums': False, + 'noclasses': True, + } } - } - ) + ) + else: + html = markdown( + text, + extensions=[ + 'extra', + 'codehilite', + AutoDirectionExtension(), + ], + extension_configs={ + 'codehilite': { + 'linenums': False, + 'noclasses': True, + } + } + ) html = Template(self.html_template).substitute( content=html, style=self.style_template, From 16a872b648ad8c5771128a62bf4fac4895c73c73 Mon Sep 17 00:00:00 2001 From: Josh Panter Date: Sun, 6 Oct 2019 16:20:23 -0400 Subject: [PATCH 3/4] Update README.md include supported extras --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 22fc7cd..b09e041 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,37 @@ # Gedit Markdown Preview ## Install +This plugin depends on the `python3-markdown` package (install via your preferred method) ```sh mkdir -p ~/.local/share/gedit/plugins/ cd ~/.local/share/gedit/plugins/ git clone https://github.com/aliva/gedit-markdownpreview.git markdownpreview ``` - -You need to install `python3-markdown` for this plugin. +Optionally install `pymdown-extensions` for extra utility with: +`pip3 install pymdown-extensions` Tested on gedit 3.30.2 +## Features: +This plugin supports standard Markdown, plus: +- [Code Highlighting](https://python-markdown.github.io/extensions/code_hilite/) +- [Abbreviations](https://python-markdown.github.io/extensions/abbreviations/) +- [Attribute Lists](https://python-markdown.github.io/extensions/attr_list/) +- [Definition Lists](https://python-markdown.github.io/extensions/definition_lists/) +- [Fenced Code Blocks](https://python-markdown.github.io/extensions/fenced_code_blocks/) +- [Footnotes](https://python-markdown.github.io/extensions/footnotes/) +- [Tables](https://python-markdown.github.io/extensions/tables/) + +With 0ptional `pymdown-extensions` support: +- [Caret](https://facelessuser.github.io/pymdown-extensions/extensions/caret/) superscripting +- [Better Emphasis](https://facelessuser.github.io/pymdown-extensions/extensions/betterem/) for bold, itallic, and underscore +- [SuperFences](https://facelessuser.github.io/pymdown-extensions/extensions/superfences/) Improved Fenced Code Blocks +- [extrarawHTML](https://facelessuser.github.io/pymdown-extensions/extensions/extrarawhtml/) to Parse MD inside HTML blocks +- [Mark](https://facelessuser.github.io/pymdown-extensions/extensions/mark/) for simple highlighting +- [Task Lists](https://facelessuser.github.io/pymdown-extensions/extensions/tasklist/) +- [Tilde](https://facelessuser.github.io/pymdown-extensions/extensions/tilde/) for subscripting and strikethrough + ## Usage When viewing a markdown file press `ctrl+alt+m` to toggle markdown preview From d70c26ac923c57f2634697aeaa0e7c2f2b335aba Mon Sep 17 00:00:00 2001 From: Josh Panter Date: Sun, 6 Oct 2019 16:23:25 -0400 Subject: [PATCH 4/4] spelling --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b09e041..68bd10c 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ This plugin supports standard Markdown, plus: - [Footnotes](https://python-markdown.github.io/extensions/footnotes/) - [Tables](https://python-markdown.github.io/extensions/tables/) -With 0ptional `pymdown-extensions` support: +With optional `pymdown-extensions`: - [Caret](https://facelessuser.github.io/pymdown-extensions/extensions/caret/) superscripting - [Better Emphasis](https://facelessuser.github.io/pymdown-extensions/extensions/betterem/) for bold, itallic, and underscore - [SuperFences](https://facelessuser.github.io/pymdown-extensions/extensions/superfences/) Improved Fenced Code Blocks