跳转到主要内容

将基本HTML转换为DraftJS JSON格式。

项目描述

HTML到DraftJS

将HTML转换为DraftJS JSON格式。

Requirement Status Coverage Status Version

Commits since latest release Supported versions Supported implementations

安装

pip install html-to-draftjs

用法

from html_to_draftjs import html_to_draftjs


json = html_to_draftjs("""
    <h1>My Page</h1>

    <h2>Introduction</h2>

    <p>Some <em>content</em> that is pretty <strong>interesting</strong></p>
    <p>Don't forget to <a href="https://example.com">follow me!</a></p>

    <h2>Illustration</h2>
    <p><img src="https://example.com/image.png" alt="image" /></p>
""")

API

html_to_draftjs(raw_html_content: str[, features="lxml", strict=False]) -> dict

将给定的HTML输入转换为JSON。

  • features:HTML树构建器的功能。默认设置为lxml,它既快又强大。
  • strict(布尔值),如果为false,则只警告无效操作。如果为true,则引发错误。

soup_to_draftjs(bs_object: BeautifulSoup[, strict=False]) -> dict

将给定的BeautifulSoup转换为JSON。如果你需要选择HTML内容的一部分进行转换(例如,#content),则非常有用。

  • strict(布尔值),如果为false,则只警告无效操作。如果为true,则引发错误。

支持的标签和属性

  • <div>, <p>
  • <h1> ... <h6>
  • <blockquote>
  • <li><ol>(不支持<ul>分组)
  • 不支持align属性。

内联样式

  • <strong>, <b>
  • <em>, <i>

实体

  • <img src="url" [alt="alt"] [height="123"] [width="123"]>
  • <a href="url">
  • <br/>
  • 不支持title和align属性。

开发

./setup.py develop
pip install -r requirements_dev.txt

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

html-to-draftjs-1.0.1.tar.gz (6.7 kB 查看哈希值)

上传时间

由以下组织支持