Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandoc Markdown to Plain Text Formatting

There appears to be something amiss with the most recent installed version of Pandoc (pandoc 1.13.2.1) on my machines. With the previously installed version, conversion from markdown to plain text would generate 'Setext-style headers---'=' for H1 and '-' for H2---in plain text output. In addition, I have noticed two more iffy issues:

  • Pandoc now automatically generates uppercase letters for title
  • Pandoc now precedes title with what seems to be two new lines (\n)

I have spent the last few minutes playing around with different pandoc options with little luck.

How do I convert Illustration #1 to Illustration #3

Environment pandoc (pandoc 1.13.2.1) Kubuntu 15.10

Illustration #1: Input markdown file

# Title

## Section
* This is the section.

### Subsection
* This happens to be the subsection

Illustration #2: Output plain text after run pandoc -f markdown -t plain pandoc_markdown_issue.md

TITLE


Section

-   This is the section.

Subsection

-   This happens to be the subsection

Illustration #3: Desired Output

Title
=====

Section
-------
-   This is the section.

Subsection
----------
-   This happens to be the subsection
like image 795
lightonphiri Avatar asked Dec 07 '15 11:12

lightonphiri


2 Answers

The plain text writer was changed to use the general format of Project Gutenberg plain text books. Of course, no choice will please everyone. For the sample you give, using the markdown writer would work well.

like image 107
John MacFarlane Avatar answered Sep 22 '22 02:09

John MacFarlane


I'm able to achieve your desired output by leaving out the -f and -t flags altogether and letting Pandoc infer the conversion format from the output filename extension:

pandoc file.md -o file.txt

Alternatively, using -t plain also seems to work:

pandoc -f markdown -t plain file.md -o file.txt

Not really sure why the first example works. My guess would be it's one of the markdown readers, since there are multiple.

like image 37
rootbeersoup Avatar answered Sep 19 '22 02:09

rootbeersoup