bash 如何将 Markdown 文档整体转换为 HTML?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 17:34:19  来源:igfitidea点击:

How can I convert Markdown documents to HTML en masse?

bashmarkdown

提问by Brock Boland

I'm writing some documentation in Markdown, and creating a separate file for each section of the doc. I would like to be able to convert all the files to HTML in one go, but I can't find anyone else who has tried the same thing. I'm on a Mac, so I would think a simple bash script should be able to handle it, but I've never done anything in bash and haven't had any luck. It seems like it should be simple to write something so I could just run:

我正在用 Markdown 编写一些文档,并为文档的每个部分创建一个单独的文件。我希望能够一次性将所有文件转换为 HTML,但我找不到其他尝试过相同方法的人。我在 Mac 上,所以我认为一个简单的 bash 脚本应该能够处理它,但我从来没有在 bash 中做过任何事情,也没有任何运气。写一些东西似乎应该很简单,所以我可以运行:

markdown-batch ./*.markdown

Any ideas?

有任何想法吗?

采纳答案by Patrick McElhaney

This is how you would do it in Bash.

这就是你在 Bash 中的做法。

for i in ./*.markdown; do perl markdown.pl --html4tags $i > $i.html; done;

Of course, you need the Markdown script.

当然,你需要Markdown 脚本

回答by

Use pandoc— it's a commandline tool that lets you convert from one format to another. This tool supports Markdown to HTML and back.

使用pandoc— 它是一个命令行工具,可让您从一种格式转换为另一种格式。此工具支持 Markdown 到 HTML 并返回。

E.g. to generate HTML from Markdown, run:

例如,要从 Markdown 生成 HTML,请运行:

pandoc -f markdown index.md > index.html

回答by Julio César

I use this in a .bat file:

我在 .bat 文件中使用它:

@echo off
for %i in (*.txt) python markdown.py "%i"

回答by Bruce Zu

// using Bash in mac

// 在 Mac 中使用 Bash

for i in *.md; do asciidoc  $i;  done;