将基本HTML转换为DraftJS JSON格式。
项目描述
安装
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