将 markdown 转换为完整的 HTML 文件 (带 markdown/discount)

将 markdown 转换为完整的 HTML 文件 (带 markdown/discount)

有很多与 markdown 相关的包可用,至少这两个有一个markdown命令:

$apt search markdown
...
discount/jammy,now 2.2.7-2 amd64 [installed]
  implementation of the Markdown markup language in C
...
markdown/jammy,jammy 1.0.1-10.1 all
  Text-to-HTML conversion tool
...

$ apt show discount
Package: discount
Version: 2.2.7-2
Priority: optional
Section: universe/text
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Alessandro Ghedini <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 113 kB
Depends: libc6 (>= 2.34), libmarkdown2 (= 2.2.7-2)
Conflicts: libtext-markdown-perl, markdown
Homepage: http://www.pell.portland.or.us/~orc/Code/discount/
Download-Size: 26,0 kB
APT-Manual-Installed: yes
APT-Sources: http://de.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
Description: implementation of the Markdown markup language in C
 Discount is an implementation of John Gruber's Markdown markup language. It
 implements all of the language described in the Markdown syntax document and
 passes the Markdown 1.0 test suite.
 .
 This package provides the discount executables.

$ apt show markdown
Package: markdown
Version: 1.0.1-10.1
Priority: optional
Section: universe/web
Origin: Ubuntu
Maintainer: Ubuntu Developers <[email protected]>
Original-Maintainer: Matt Kraai <[email protected]>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 58,4 kB
Depends: perl (>= 5.6.0-0.1)
Homepage: http://daringfireball.net/projects/markdown/
Download-Size: 17,6 kB
APT-Sources: http://de.archive.ubuntu.com/ubuntu jammy/universe amd64 Packages
Description: Text-to-HTML conversion tool
 Markdown is a text-to-HTML conversion tool for web writers.  It
 allows you to write using an easy-to-read, easy-to-write plain text
 format, then convert it to structurally valid XHTML (or HTML).

$ discount
Command 'discount' not found, did you mean:

$ markdown --version
markdown: discount 2.2.7 GITHUB_CHECKBOX

前者有文档https://www.pell.portland.or.us/~orc/Code/discount/以及位于的代码镜像https://github.com/Orc/discount

markdown -o <out>.html <in>.md写入文件,但令我惊讶的是并没有生成完整的 HTML 文件(DOCTYPE<html>等)。

我是不是漏掉了一个选项?如何包装输出以使其成为有效的 HTML?

答案1

mkd2html <in> <out>

答案2

这个答案不起作用,但可能会激发想法,或节省其他人调查它的时间:

经过 'markdown' 处理的 Markdown 文件可以直接包含 HTML 标签,因此:将 HTML 页眉和页脚标签嵌入到您的 Markdown 文档中,如下所示:

$ cat mydoc.md
<html>
<head><title>My Title</title></head>
<body>

The rest of my markdown doc goes here

</body>
</html>

然后像平常一样用“markdown”处理它:

markdown mydoc.md >mydoc.html

几乎有效,但用段落标签包围给定的 HTML 页眉和页脚标签:

<p><html>
<head><title>hello</title></head>
<body></p>

The rest of my doc (Transformed to HTML)

<p></body>
</html></p>

Firefox 可以正常显示此文档,并在选项卡标题中显示给定的“标题”。但话又说回来,Firefox 默认正确显示“markdown”输出的简单 HTML 片段。

<p>无论我是否提供“-fhtml”命令行参数以允许提供这样的 HTML 标签,以及 mydoc.md 中的 HTML 标签是否被一整行空白包围(这是某些 markdown 解析器的要求),都会包含错误的标签。

诅咒!太接近了!

相关内容