将标记转换为HTML的标记解析器

twomartens.markdown的Python项目详细描述


这个程序是在年it-tallents.com的代码竞赛中创建的。 2017年4月。它分为两个主要部分。解析器端接受标记 输入并创建内部表示。转换组件使用 表示并创建HTML输出。

一般来说,系统设计成模块化和可扩展的。例如转换 因为乳胶可以相对容易地添加。

安装

简易方式

使用python的包管理器:

pip install twomartens.markdown

有点复杂

  1. PyPi
  2. 下载包
  3. 提取文件
  4. 从解压文件的目录中运行python setup.py install

Git方式(无实际安装)

  1. 克隆GitHub repository
  2. 运行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`

列表

支持无序和有序列表。无序列表的列表项必须以 *-+后面紧跟空格。即使在一个列表中,这些符号也可以互换使用。 列表前面必须有空行。

示例:

* 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.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用tomcat时,如何加载JDBC驱动程序?   Spring数据Rest中嵌套资源的java分页   java从ImagesService创建URL需要多长时间。getServingUrl last   java的纸牌游戏战争与处理   内存不足的java解释探查器输出:PermGen空间错误   如何在java代码中等待scala的未来   java在安卓studio中通过if-else子句后,如何访问变量的新值   javascript DHTMLX甘特API   意图启动期间的java运行时异常   Java中的用户界面复合组件   java Hibernate更新调用在@OneToOne映射中生成新行   正则表达式在N个数的序列中计数零   java设置在何处查找audit4j的配置文件   maven JSR352:Annotation@Named在JavaSE中不起作用   java以更实用的方式对目录进行分组   JavaEclipse不再打开   java机器人按键VK_控件在Macbook上工作?   java如何等待所有线程完成执行?