How To Add Markdown Support To Gedit Using `Markdown Preview` Plugin

If you like Gedit text editor and would like to add Markdown preview support to it, there's a plugin you can use to easily do that.

Gedit Markdown Preview plugin

Gedit, the default GNOME text editor, doesn't support Markdown by default. It does support plugins though, and with the help of a plugin called Gedit Markdown Preview, you can add Markdown support to modern Gedit versions (3.22 and newer).

Gedit Markdown Preview is a work in progress plugin that automatically detects when opening .md files in Gedit, and when it does it open a pane in the left sidebar or at the bottom of the window with a preview of the Markdown file. You can disable this pane from opening automatically, and manually run it from the Gedit View menu, or using a key (F9 for the side pane and Ctrl + F9 for the bottom pane).

Gedit markdown menu
Gedit Markdown Preview plugin menu

This Markdown preview allows zooming in or out, searching, and opening links and images. The preview is not automatically refreshed by default but you can click the 3-dotted menu at the bottom right-hand side of the preview area and enable Automatically reload from there to have the preview refresh automatically each time you make modifications to the source .md file; you may also manually refresh the preview by using the refresh button from the left-hand side of the preview window, or via the right click context menu.

The preview doesn't scroll automatically when scrolling the source .md document, this being my only issue so far with this plugin.

Gedit markdown tags


While it has "preview" in its name, this Gedit plugin also helps with Markdown editing. It adds a right click menu to documents from where you can easily insert Markdown tags like bold, italic, ordered or unordered list, and more, as well as easily insert an image into the file. Markdown tags may also be inserted using keyboard shortcuts, although you'll only find a few tags / shortcuts right now in the plugin settings, because this feature is work in progress.

Under the hood, this plugin makes use of python3-markdown or pandoc as its backends. For python3-markdown there are some extensions available that you can enable from the plugin settings, including CodeHilite, New Line To Break, Smarty Pants, Sane Lists, Admonition and WikiLinks, with the possibility of adding extra extensions.

The preview can be printed or exported. Markdown files can be exported using the Gedit Markdown Preview plugin to HTML when using python3-markdown, or to PDF, TEX, DOCX, ODT, TXT, PPTX, RTF or HTML/JS (using reveal.js slideshow - this is work in progress) using pandoc. A stylesheet can be applied to the exported HTML.

[[Edit]] The plugin developer explained on GitHub what's currently not working (as a reminder, this plugin is a work in progress): unusable settings dialog for pandoc and revealjs, broken CSS with pandoc, you can only add Markdowntags but can't toggle/remove them, and inconsistent behavior regarding splitters with HTML files.

You may also want to check out Marker if you're looking for a stand-alone GTK3 Markdown editor, and Mark Text for a feature-packed Markdown editor (which uses Electron).

How to install Gedit Markdown Preview plugin


Arch Linux / Manjaro: The Gedit Markdown Preview plugin can be installed from AUR (link updated to the actual Gedit Markdown Preview plugin, the other one was to another plugin; thanks to yochananmarqos for creating the AUR package) so for you the installation is quite easy. Skip to step 3 after installing the AUR package since all you have to do after that is to enable the plugin.

For other Linux distributions follow the steps below to install and enable the Gedit Markdown Preview plugin. Gedit needs to be installed before installing this plugin; install it from your Linux distribution's repositories if it's not already installed. As a side note, you can use Gedit with any desktop environment, and not just GNOME, but it will pull some GNOME dependencies (only a few dependencies are installed if you're using a GNOME-based desktop environment like Xfce, Cinnamon, etc.).

1. Install required dependencies.

To use Gedit Markdown Preview you must install its dependencies (and Git to grab the latest code).

Debian, Ubuntu and Linux distributions based on these, like Pop!_OS, Linux Mint, elementary OS, Kali Linux, etc.:

sudo apt install python3-markdown pandoc gir1.2-webkit2-4.0 git

Fedora:

sudo dnf install python3-markdown pandoc webkit2gtk3 git

Solus OS:

sudo eopkg install python-markdown pandoc libwebkit-gtk git

If you use some other Linux distribution, search for python-markdown, pandoc, webkit2gtk3 (gir bindings) and git in the repositories and install the packages from there (the names can differ between Linux distributions).

2. Grab the latest Gedit Markdown Preview code from Git and install it.

After installing the dependencies, grab the latest Gedit Markdown Preview code from Git and install the plugin for your user by using:

git clone https://github.com/maoschanz/gedit-plugin-markdown_preview

cd gedit-plugin-markdown_preview

./install.sh

The install.sh script that's available in the plugin repository can be used to install Gedit Markdown Preview both with and without super user privileges (e.g. using sudo). When installed without sudo, the plugin is only available for the current user (under ~/.local/share/gedit/plugins/), while using sudo installs this for all users, in /usr/lib/x86_64-linux-gnu/gedit/plugins (I recommend installing it for your user only).

In the cloned Gedit Markdown Preview plugin directory you'll also find an update.sh script that you can use to update the plugin, and an uninstall.sh script to remove the Gedit plugin, in case you decide you no longer want to have it installed on your system.

3. Restart Gedit.

In case Gedit was running when installing the plugin, close it and start Gedit again.

4. Enable the Gedit Markdown Preview plugin.

Enable Markdown preview plugin in Gedit

To enable the Markdown Preview plugin, go to the Gedit Preferences (can be accessed by clicking the menu icon in the Gedit header bar), click on the Plugins tab and enable the Markdown Preview plugin. After it's enabled you can access its settings by clicking the Preferences button at the bottom of the Plugins window.