保守地将html转换为markdown

html2markdown的Python项目详细描述


实验性

purpose:将HTML转换为标记,同时保留不受支持的HTML标记。目标是生成可以转换回HTML的标记。这是html2markdown和html2text之间的主要区别。后者并不声称是可逆的。

用法示例

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

输出:

## Test

    Here is some code

信息和注意事项

不将<p>以外的块类型标记(例如<div>标记)的内容转换为标记

它确实转换为标记内联类型标记的内容,例如<span>

输入<div>this is stuff. <strong>stuff</strong></div>

结果<div>this is stuff. <strong>stuff</strong></div>

输入<p>this is stuff. <strong>stuff</strong></p>

结果this is stuff. __stuff__(两边有一个换行符包围)

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

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

除未处理的块类型标记外,格式化字符将转义

input<p>**escapeme?**</p>(在html中,我们将在此处使用<;strong>;)

结果\*\*escapeme?\*\*

输入<span>**escapeme?**</span>

结果<span>\*\*escapeme?\*\*</span>

输入<div>**escapeme?**</div>

结果<div>**escapeme?**</div>(块类型)

保留标记不支持的属性

示例<a href="http://myaddress"title="clickme"><strong>link</strong></a>

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

示例<a onclick="javascript:dostuff()"href="http://myaddress"title="clickme"><strong>link</strong></a>

result<a onclick="javascript:dostuff()"href="http://myaddress"title="clickme">__link__</a>(不支持属性onclick,因此不支持标记)

限制

  • 表保存为html。

更改

0.1.7:

  • 改进了内联标签的处理。
  • 修复:忽略不带ref属性的<a>标记。
  • 改进逃跑。

0.1.6:增加了对低于2.7版本的python的测试和支持。

0.1.5:修复Python3中的Unicode问题。

0.1.0:第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java GridBagLayout不填充区域   java Memozied Fibonacci未运行与常规Fibonacci解决方案   Java Web启动未启动问题   Java中异常和if-then的区别   java从命令提示符运行批处理文件获取错误   socket在Java中验证SSL证书的公共名称   如何在JAVA中检查字符串数组中的相等字   用java语言将音频文件转换成文本文件的语音识别   java为什么foo(1,2,3)没有传递给varargs方法foo(对象…)作为整数[]   java通过蓝牙将奇怪的数据从Arduino传输到Android   java ContainerRequestFilter获取空entitystream   java如何从安卓 studio中删除不兼容类型错误   基本Java错误   在Spring引导中使用REST API时发生java错误   javascript通过从SQL查询派生的URL打开页面