Pandoc Markdown转换为普通文本格式化

8

最近安装的Pandoc版本(pandoc 1.13.2.1)在我的机器上出现了一些问题。在先前安装的版本中,从markdown转换为纯文本会在纯文本输出中生成'Setext-style headers---'=' for H1 and '-' for H2---。此外,我还注意到两个更加棘手的问题:

  • Pandoc现在自动为标题生成大写字母
  • Pandoc现在在标题之前似乎添加了两个新行(\n)

我花了最后几分钟时间尝试不同的pandoc选项,但运气不佳。

如何将Illustration #1转换为Illustration #3

环境 pandoc (pandoc 1.13.2.1) Kubuntu 15.10

Illustration #1: 输入markdown文件

# Title

## Section
* This is the section.

### Subsection
* This happens to be the subsection

Illustration #2: 运行 pandoc -f markdown -t plain pandoc_markdown_issue.md 后输出纯文本。
TITLE


Section

-   This is the section.

Subsection

-   This happens to be the subsection

图解 #3: 期望输出

Title
=====

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

Subsection
----------
-   This happens to be the subsection
4个回答

8

如果您想让Pandoc根据输出文件名的扩展名自动推断转换格式,可以完全省略-f-t标志来获得您所需的输出:

pandoc file.md -o file.txt

另外,使用-t plain似乎也能起作用:

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

其实我不太确定为什么第一个示例有效。我猜测可能是其中一个Markdown阅读器导致的,因为有多个阅读器。


1
这个处理Markdown链接的能力不是很好。 - chovy

6

纯文本编辑器已更改为使用Project Gutenberg纯文本书籍的通用格式。当然,没有哪种选择能让每个人都满意。对于您提供的样本,使用Markdown编写器会很好。


非常感谢您。我从changelog中看到,这个更改是在1.13中实现的。 - lightonphiri

1

Pandoc现在自动为标题生成大写字母

我曾经遇到这样一个问题,使用-t plain将docx中的粗体转换成大写字母,通过一个小的lua过滤器解决了这个问题。首先我做了如下操作:

$ pandoc -t native foo.docx

我看到被转换成大写的文本被Strong标签所包含,例如[Para [Strong [Str "some text"]]]。非粗体文本类似于[Para [Str "moar", Space, Str "text"]]。因此,过滤器变为:

function Strong(element)
   return element.content
end

我把它放在一个名为weaken.lua的文件中,然后只需
$ pandoc --lua-filter=weaken.lua -f docx -t plain foo.docx -o foo.txt

0

虽然有些奇怪,但是你可以通过导出到 rst reStructuredText 来接近所需的输出,因为它使用了 setext-style 标题。 然而,你可能会遇到其他问题,但这只是以防有用。

$ pandoc pandoc_markdown_issue.md -t rst

Title
=====

Section
-------

-  This is the section.

Subsection
~~~~~~~~~~

-  This happens to be the subsection

3
这个无法很好地处理 Markdown 链接。 - chovy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接