How to Easily Convert Markdown Document to HTML In Kate Text Editor [Linux]

Spread the love

There are plenty of reasons to draft writing in plain text, one reason being that text editors (generally) run light compared to other document applications such as word processors, and are mostly distraction-free. But many text editors hide some other clever tricks that can make them useful in different ways. In this article, we’ll use the “Build” feature of the Kate text editor in KDE to automatically generate output using pandoc as we did recently.

Activating the Kate Build Plugin

In order to make this pandoc output automagical, we’ll need to activate the “Build” plug-in.

  1. Go to the “Settings” menu, then select “Configure Kate.”
  2. From the items on the left, select “Plugins.” This will display the Plugin Manager.
  3. Check the “Build Plugin” item.
  4. Click “OK.”

If this worked correctly for you, you should see an item at the bottom of the screen labeled “Build Output.” This is where we’ll tell Kate how to generate the output from the currently-edited file via the pandoc command.

Setting Up Your Build Profile

Like the name suggests, this feature is generally targeted at developers writing code, and will compile that code for them. But there is a “Quick Compile” option that does nothing but run a command you configure, and that’s where we’ll be putting the pandoc options we want. Click on the “Build Output” item at the very bottom of the Kate window, and you’ll see a dialog like the one below.

The first tab “Errors & Warnings” will display the result of your command if something goes wrong, and the second, “Output,” will display nothing if everything goes to plan. The last tab, “Target Settings,” is the one we’re interested in. Let’s create what Kate calls a “Build Target” for pandoc. First, click the “New” button (it’s the one to the far left with the green plus). This will create a Build Profile that we can give a name to in the field above the “New” button – let’s call this “MD > HTML”, to signify we want this to automatically generate an HTML version of our Markdown document.

When you do so, Kate will fill in some of the setting to the right, including “Build” and “Clean.” These are items we don’t need to worry about for what we’re doing, so we can delete those “make” and “make clean” commands. Instead, put the following command in the “Quick comple” field:

pandoc -r markdown -w html -o %f.html %f

Here, the “%f” is a code that Kate will replace with the name of the file currently open in the window. Now, once you’ve completed your Markdown document, select the “Build” menu in the toolbar, then “Quick Compile.”

Voila! Check the directory your Markdown document was in, and you’ll see a file titled [name of your original file].html. Note that the “%f” code includes the entire filename, so if your original was called “myfile.md,” the newly-generated one will be called “myfile.md.html” (because the original extension is included).

Now, I like to assign this to a keyboard shortcut. You can do this in the “Settings -> Configure Shortcuts” dialog. Find the “Quick Compile” item, click on the “Shortcut” column for that row, select “Custom” when it opens, and click the “None” button. This will then change to say “Input” – the next keyboard combination you press will be assigned to this, so make sure you use a Control or Alt button. It may also warn you that another function is already assigned to that combination, but clearly this is more important, so you can override it. As shown in the figure below, I’ve assigned “Quick Compile” to Ctrl+B.

Now, whenever I want to take a look at the HTML that my Markdown will generate, all I need to do is hit Ctrl+B.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.
By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time. Subscribe


Aaron Peters

Aaron is an interactive business analyst, information architect, and project manager who has been using Linux since the days of Caldera. A KDE and Android fanboy, he’ll sit down and install anything at any time, just to see if he can make it work. He has a special interest in integration of Linux desktops with other systems, such as Android, small business applications and webapps, and even paper.

Comments (1)