To convert a markdown file to an HTML file, you can use the markdown provided by the discount or Python-markdown software package:
Conversion in Ubuntu is as follows:
# Debian/Ubuntu
Sudo apt-Get install discount
Or:
# Debian/Ubuntu
Sudo apt-Get install Python-markdown
The conversion is simple:
# Use the markdown tool provided by discount
Markdown-O Release-Notes.html Release-Notes.md
# Use the markdown_py tool provided by Python-markdown
Markdown_py-O html4 Release-Notest.md> Release-Notes.html
To generate a PDF file, you can use the xhtml2pdf file provided by Python-Pisa:
# Debian/Ubuntu
Sudo apt-Get install Python-Pisa
# Converting HTML to PDF
Xhtml2pdf -- HTML Release-Notes.html Release-Notes.pdf
Therefore, you can place such a makefile in the document directory to automate this process:
# Makefile
MD = markdown
Mdflags =-T
H2p = xhtml2pdf
H2pflags = -- html
Sources: = $ (wildcard *. md)
Objects: = $ (patsubst %. md, example .html, $ (wildcard *. md ))
Objects_pdf: = $ (patsubst %. md, commandid, $ (wildcard *. md ))
ALL: Build
Build: HTML PDF
PDF: $ (objects_pdf)
HTML: $ (objects)
$ (Objects_pdf): objects.html
$ (H2p) $ (h2pflags) $ <>$ @
$ (Objects): Objects .html: %. md
$ (MD) $ (mdflags)-o $ @ $ <
Clean:
Rm-F $ (objects)
In this way, you can use a simple command to generate PDF or HTML output of all MD files in the current directory:
# HTML output
Make html
# PDF output
Make PDF
Note: The problem here is that if the markdown content is Chinese, the converted HTML cannot be automatically recognized when opened in the browser. The PDF is worse, but it is a bunch of garbled characters. In this case, we can use markdown's support for HTML tags to add encoding information to the markdown file. For example, to convert markdown to an HTML file, you can add a meta tag at the beginning of the file to specify the encoding format:
Sed-I '1i \ <meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"> '*. md
In this way, you can.
Reference: http://www.ituring.com.cn/article/10044