pyhtmd

A Python HTML to Markdown parser


Keywords
html, markdown, parser, pyhtmd
Install
pip install pyhtmd==1.0.2

Documentation

一款Python版本的HTML转markdown解析器,不使用任何第三方工具,实验demo

请勿使用于生成环境,这个只是一次尝试demo项目

注意:

parser

  • single html node element
  • infinite html list node element
  • img
  • head html node element

todo 开发中

  • 核心的问题是,粘在一起的代码如何拆分?
  • 本质还是要分割的,但具体怎么分割呢?
  • table

bug

  • 已解决list算法问题:
    • 当前的list 标签算法无法解析这种结构:
    • 因为算法中,假定是依次序性ul组成结束的标签
    • 核心算法一:算出开始标签的level
    • 核心算法二:根据左边的开始标签索引值算出其所对应的右边索引值序列,我自己给他起了一个炫酷拽炸天的名字:标记逆序奇偶互斥算法
    • 上面两个算法我自己算出来的,第一个花了两天,第二个花了1-2周

install

pip install pyhtmd

usage

from pyhtmd import Pyhtmd
html="<code> Hello, world ! by Pyhtmd. </code>"
md= Pyhtmd(html)
content=md.markdown()
print(content) # `Hello, world ! by Pyhtmd.`

API

Pyhtmd(html, language="", img=True )

  • language:类型 string (js、python、java等)
  • img:{Boolean},默认True,可以不需要img渲染
from pyhtmd import Pyhtmd
html="<pre><code>import time\n print(time.time()) </code><pre>"
md= Pyhtmd(html,language="python")
content=md.markdown()
print(content) # `Hello, world ! by Pyhtmd.`