New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pyhtmd

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyhtmd

A Python HTML to Markdown parser

  • 1.0.2
  • PyPI
  • Socket score

Maintainers
1

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

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

注意:

  • 无法解析多层级HTML
  • 只能是单Node
  • 这项目目前只针对 tensorflow-docs 项目
  • 存在个别自定义标签无法识别,基本可以适用平常场景
  • python官方html_parser https://docs.python.org/zh-cn/3.7/library/html.parser.html
  • html.parser 源码 https://github.com/python/cpython/blob/3.7/Lib/html/parser.py
  • 不支持美化后的HTML内容,需要内容紧凑

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

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc