将标记转换为HTML的标记解析器
twomartens.markdown的Python项目详细描述
这个程序是在年it-tallents.com的代码竞赛中创建的。 2017年4月。它分为两个主要部分。解析器端接受标记 输入并创建内部表示。转换组件使用 表示并创建HTML输出。
一般来说,系统设计成模块化和可扩展的。例如转换 因为乳胶可以相对容易地添加。
安装
简易方式
使用python的包管理器:
pip install twomartens.markdown
有点复杂
- 从PyPi 下载包
- 提取文件
- 从解压文件的目录中运行python setup.py install。
Git方式(无实际安装)
- 克隆GitHub repository
- 运行python markdown-runner.py以使用该工具
用法
使用起来很容易。安装后,您可以使用tm-parse-markdown访问该程序。交替使用 python markdown-runner.py如果你遵循git的方式。其余的同样适用于这两种形式。 程序接受两个参数。第一个必须是包含标记代码的文件名。第二次 参数必须是输出文件的名称。该文件不一定已经存在,但如果是这样,它将是 完全覆盖。输出文件将包含选定输出格式的标记(从现在起它始终是 HTML)。
为了便于扩展,程序接受-f,--format选项。它可以用来指定输出 格式。目前只支持HTML,这也是默认选择。因此,无需指定 程序工作的选项。
示例:
tm-parse-markdown my-markdown-file.md my-html-file.html
示例(带选项):
tm-parse-markdown --format html my-markdown-file.md my-html-file.html
标记语法
标记解析器支持以下语法。稍后可能会添加更多内容。
标题
支持从h1到h6的所有标题。
示例:
# H1 heading ## H2 heading ### H3 heading #### H4 heading ##### H5 heading ###### H6 heading
粗体文本
支持粗体文本。
示例:
**bold text** the **bold text** can even appear in normal paragraphs
斜体文本
支持斜体文本。
示例:
*some italic text* the *italic text* can also appear in paragraphs
内联代码
支持内联代码段。
示例:
a paragraph with `inline code`
链接
解析器支持链接。
示例:
a paragraph with [a link](https://example.com "title") another with another [link](https://example.com) or for change an automatic link <https://example.com>
列表
支持无序和有序列表。无序列表的列表项必须以 *、-或+后面紧跟空格。即使在一个列表中,这些符号也可以互换使用。 列表前面必须有空行。
示例:
* this starts a list * which continues here * and here - even here + and here * but this is a new list * which even contains **bold text** and *italic text* * or an `inline code segment` * or a [link](https://example.com), <https://example.com>
有序列表的列表项必须以数字(0-9)开头,然后是点(.)和空格。 哪一个数字在点的前面对输出来说无关紧要。
示例:
1. this starts an ordered list 2. which is continued here 9. and here 0. it can also contain **bold text** 11. and *italic text* 99. and `inline code` 42. and a [link](https://example.com "title"), <https://example.com> 0. a new list is started here
报价
到目前为止,只支持块引号。以后可能会添加内联引号。
示例:
> This starts a one line quote. > A new quote starts here > and continues in the next line. > It can contain **bold text** and *italic text*. > inline `code blocks` are also possible > The same goes for [links](https://example.com), <https://example.com>
代码块
支持代码块。它们前面和后面必须有一个空行。每行必须以4开头 空格或一个制表符。文本是经过编码的,因此您可以很容易地在代码块中使用例如html标记。更多空间 超过这四个空格或一个制表符在输出中表示不变。
示例:
<!DOCTYPE html> <html> <head> <title>Test</title> </head> <body> </body> </html>
段落
段落自然也得到支持。它们用空行隔开。
示例:
A paragraph starts here. It contains **bold text** or *italic text*. It continues in the next line with a `code segment`. Finally there are also [links](https://example.com "title") This text belongs to a new paragraph.