• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

dlon/html2markdown: Conservatively convert html to markdown

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

dlon/html2markdown

开源软件地址:

https://github.com/dlon/html2markdown

开源编程语言:

Python 100.0%

开源软件介绍:

html2markdown

https://travis-ci.com/dlon/html2markdown.svg?branch=master

Experimental

Purpose: Converts html to markdown while preserving unsupported html markup. The goal is to generate markdown that can be converted back into html. This is the major difference between html2markdown and html2text. The latter doesn't purport to be reversible.

Usage example

import html2markdown
print html2markdown.convert('<h2>Test</h2><pre><code>Here is some code</code></pre>')

Output:

## Test

    Here is some code

Information and caveats

Does not convert the content of block-type tags other than <p> -- such as <div> tags -- into Markdown

It does convert to markdown the content of inline-type tags, e.g. <span>.

Input: <div>this is stuff. <strong>stuff</strong></div>

Result: <div>this is stuff. <strong>stuff</strong></div>

Input: <p>this is stuff. <strong>stuff</strong></p>

Result: this is stuff. __stuff__ (surrounded by a newline on either side)

Input: <span style="text-decoration:line-through;">strike <strong>through</strong> some text</span> here

Result: <span style="text-decoration:line-through;">strike __through__ some text</span> here

Except in unprocessed block-type tags, formatting characters are escaped

Input: <p>**escape me?**</p> (in html, we would use <strong> here)

Result: \*\*escape me?\*\*

Input: <span>**escape me?**</span>

Result: <span>\*\*escape me?\*\*</span>

Input: <div>**escape me?**</div>

Result: <div>**escape me?**</div> (block-type)

Attributes not supported by Markdown are kept

Example: <a href="http://myaddress" title="click me"><strong>link</strong></a>

Result: [__link__](http://myaddress "click me")

Example: <a onclick="javascript:dostuff()" href="http://myaddress" title="click me"><strong>link</strong></a>

Result: <a onclick="javascript:dostuff()" href="http://myaddress" title="click me">__link__</a> (the attribute onclick is not supported, so the tag is left alone)

Limitations

  • Tables are kept as html.

Changes

0.1.7:

  • Improved handling of inline tags.
  • Fix: Ignore <a> tags without an href attribute.
  • Improve escaping.

0.1.6: Added tests and support for Python versions below 2.7.

0.1.5: Fix Unicode issue in Python 3.

0.1.0: First version.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
chinatjnet/htmljs: 前端乱炖博客的repo。http://www.html-js.com发布时间:2022-06-19
下一篇:
SuperSimpleDev/html-css-course-2022发布时间:2022-06-19
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap