Science and technology

Convert Markdown recordsdata to phrase processor docs utilizing pandoc

If you reside your life in plaintext, there invariably comes a time when somebody asks for a phrase processor doc. I run into this challenge regularly, particularly on the Day JobTM. Although I’ve launched one of many growth groups I work with to a Docs Like Code workflow for writing and reviewing launch notes, there are a small quantity of people that have no real interest in GitHub or working with Markdown. They desire paperwork formatted for a sure proprietary software.

The excellent news is that you simply’re not caught copying and pasting unformatted textual content right into a phrase processor doc. Using pandoc, you may rapidly give individuals what they need. Let’s check out tips on how to convert a doc from Markdown to a phrase processor format in Linux utilizing pandoc. ​​​​

Note that pandoc can be out there for all kinds of working techniques, starting from two flavors of BSD (NetBSD and FreeBSD) to Chrome OS, MacOS, and Windows.

Converting fundamentals

To start, install pandoc in your pc. Then, crack open a console terminal window and navigate to the listing containing the file that you simply need to convert.

Type this command to create an ODT file (which you’ll open with a phrase processor like LibreOffice Writer or AbiWord):

pandoc -t odt -o filename.odt

Remember to interchange filename with the file’s precise title. And if you must create a file for that different phrase processor (you already know the one I imply), substitute odt on the command line with docx. Here’s what this text appears to be like like when transformed to an ODT file:

These outcomes are serviceable, however a bit bland. Let’s have a look at tips on how to add a bit extra model to the transformed paperwork.

Converting with model

pandoc has a nifty function enabling you to specify a mode template when changing a marked-up plaintext file to a phrase processor format. In this file, you may edit a small variety of kinds within the doc, together with people who management the look of paragraphs, headings, captions, titles and subtitles, a primary desk, and hyperlinks.

Let’s have a look at the chances.

Creating a template

In order to model your paperwork, you may’t simply use any template. You must generate what pandoc calls a reference template, which is the template it makes use of when changing textual content recordsdata to phrase processor paperwork. To create this file, kind the next in a terminal window:

pandoc -o custom-reference.odt –print-default-data-file reference.odt

This command creates a file known as custom-reference.odt. If you are utilizing that different phrase processor, change the references to odt on the command line to docx.

Open the template file in LibreOffice Writer, after which press F11 to open LibreOffice Writer’s Styles pane. Although the pandoc manual advises in opposition to making different adjustments to the file, I alter the web page dimension and add headers and footers when mandatory.

Using the template

So, how do you employ that template you simply created? There are two methods to do that.

The easiest method is to drop the template in your /dwelling listing’s .pandoc folder—you might need to create the folder first if it would not exist. When it is time to convert a doc, pandoc makes use of this template file. See the following part on how to select from a number of templates should you want a couple of.

The different approach to make use of your template is to kind this set of conversion choices on the command line:

pandoc -t odt –reference-doc=path-to-your-file/reference.odt -o file-name.odt

If you are questioning what a transformed file appears to be like like with a personalized template, this is an instance:

Choosing from a number of templates

Many individuals solely want one pandoc template. Some individuals, nonetheless, want a couple of.

At my day job, for instance, I take advantage of a number of templates—one with a DRAFT watermark, one with a watermark stating FOR INTERNAL USE, and one for a doc’s closing variations. Each kind of doc wants a distinct template.

If you’ve gotten related wants, begin the identical approach you do for a single template, by creating the file custom-reference.odt. Rename the ensuing file—for instance, to custom-reference-draft.odt—then open it in LibreOffice Writer and modify the kinds. Repeat this course of for every template you want.

Next, copy the recordsdata into your /dwelling listing. You may even put them within the .pandoc folder if you wish to.

To choose a selected template at conversion time, you will must run this command in a terminal:

pandoc -t odt –reference-doc=path-to-your-file/custom-template.odt -o file-name.odt

Change custom-template.odt to your template file’s title.

Wrapping up

To keep away from having to recollect a set of choices I do not repeatedly use, I cobbled collectively some easy, very lame one-line scripts that encapsulate the choices for every template. For instance, I run the script to create a phrase processor doc utilizing the template with a DRAFT watermark. You may need to do the identical.

Here’s an instance of a script utilizing the template containing a DRAFT watermark:

pandoc -t odt $ -o $1.odt --reference-doc=~/Documents/pandoc-templates/custom-reference-draft.odt

Using pandoc is an effective way to offer paperwork within the format that individuals ask for, with out having to surrender the command line life. This software would not simply work with Markdown, both. What I’ve mentioned on this article additionally permits you to create and convert paperwork between all kinds of markup languages. See the pandoc website linked earlier for extra particulars.

Most Popular features the latest multimedia technologies, from live video streaming to audio packages to searchable archives of news features and background information. The site is updated continuously throughout the day.

Copyright © 2017 Breaking Express, Green Media Corporation

To Top