python-markdown用法

11145阅读 0评论2009-08-22 crook
分类:Python/Ruby

markdown工具,可以将txt转化成html格式。这一类工具的作用是将按一定格式写成的可读性强的文本文件
转化为结构化的标准xhtml或html。markdown最初用perl写成,后来移植到python,java,php.这里主要
介绍下python-markdown的用法。

python-markdown模块使用有两个模式,一种是做为独立的命令行,另外一种是做为python的模块使用。
1. 命令行模式
在Fedora下,命令行名称是markdown:

[ray@localhost markdown]$ markdown
Usage: markdown INPUTFILE [options]

Options:
  -h, --help            show this help message and exit
  -f OUTPUT_FILE, --file=OUTPUT_FILE
                        write output to OUTPUT_FILE
  -e ENCODING, --encoding=ENCODING
                        encoding for input and output files
  -q, --quiet           suppress all messages
  -v, --verbose         print info messages
  -s SAFE_MODE, --safe=SAFE_MODE
                        same mode ('replace', 'remove' or 'escape'  user's
                        HTML tag)
  --noisy               print debug messages
  -x EXTENSION, --extension=EXTENSION
                        load extension EXTENSION

使用起来很简单, 直接运行markdown input.txt > output.html即可。例如:
[ray@localhost markdown]$ cat notes.txt
Who am I?
===========
This is Ray Chen speaking.

Where am I from?
====================
I'm from SH, China. I love this place.

What's next?
=================
  * nothing
  * sleep
  * study
  * reading book


[ray@localhost markdown]$ markdown notes.txt > notes.html
[ray@localhost markdown]$ cat notes.html

Who am I?


This is Ray Chen speaking.



Where am I from?


I'm from SH, China. I love this place.



What's next?


上一篇:ubuntu tweak使用小记
下一篇:linux软件包管理器杂谈