Skip to main content

A Python HTML to Markdown parser

Project description

一款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.`

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhtmd-1.0.1.tar.gz (11.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page