跳转到主要内容

python-creole 是一个纯Python编写的开源(GPL)标记转换器,用于:creole2html,html2creole,html2ReSt,html2textile

项目描述

关于python-creole

python-creole 是一个开源(GPL)Python库,用于转换标记。python-creole 是纯Python编写的。不需要外部库。

兼容Python版本(请参阅 tox.ini

  • 3.9, 3.8, 3.7, 3.6

  • PyPy3

现有转换器

  • creole -> html

  • html -> creole markup

  • reSt -> html(用于干净的HTML代码)

  • html -> reStructuredText markup(仅支持reSt的一个子集)

  • html -> textile markup(尚未完成)

基于Radomir Dopieralski和Thomas Waldmann的MoinMoin项目中的creole标记解析器和发射器构建的creole2html部分。

Build Status on github

Coverage Status on coveralls.io

Status on landscape.io

PyPi version

安装

Python包可在以下地址获取: http://pypi.python.org/pypi/python-creole/

~$ pip install python-creole

要通过Poetry设置虚拟环境,请参阅下面的unittests部分。

依赖项

对于大多数部分(creole2htmlhtml2creole),不需要外部库。

为了实现所有功能(以及运行unittests),需要以下模块

  • docutils(用于ReStructuredText功能)

  • textile(用于html2textile测试)

示例

creole2html

将creole标记转换为html代码

>>> from creole import creole2html
>>> creole2html("This is **creole //markup//**")
u'<p>This is <strong>creole <i>markup</i></strong></p>\n'

html2creole

将html代码转换回creole标记

>>> from creole import html2creole
>>> html2creole(u'<p>This is <strong>creole <i>markup</i></strong></p>\n')
u'This is **creole //markup//**'

rest2html

将ReStructuredText转换为干净的html代码(需要docutils

>>> from creole.rest2html.clean_writer import rest2html
>>> rest2html(u"A ReSt link to `PyLucid CMS <http://www.pylucid.org>`_ :)")
u'<p>A ReSt link to <a href="http://www.pylucid.org">PyLucid CMS</a> :)</p>\\n'

(更多信息:rest2html wiki页面

html2rest

将html代码转换为ReStructuredText标记

>>> from creole import html2rest
>>> html2rest(u'<p>This is <strong>ReStructuredText</strong> <em>markup</em>!</p>')
u'This is **ReStructuredText** *markup*!'

html2textile

将html代码转换为textile标记

>>> from creole import html2textile
>>> html2textile(u'<p>This is <strong>textile <i>markup</i></strong>!</p>')
u'This is *textile __markup__*!'

参见:http://github.com/jedie/python-creole/blob/master/demo.py

图像尺寸额外

您可以在图像标签中传递图像宽度和高度,例如

>>> from creole import creole2html
>>> creole_markup="""{{foobar.jpg|image title|90x160}}"""
>>> creole2html(creole_markup)
'<p><img src="foobar.jpg" title="image title" alt="image title" width="90" height="160" /></p>'

第三部分(90x160)不在creole标准中,您可以强制使用strict模式,例如

>>> creole2html(creole_markup, strict=True)
'<p><img src="foobar.jpg" title="image title|90x160" alt="image title|90x160" /></p>'

源代码高亮支持

您可以在以下位置找到使用pygments库突出显示源代码的示例宏: /creole/shared/example_macros.py。下面是如何使用它

>>> from creole import creole2html
>>> from creole.shared.example_macros import code
>>> creole_markup="""<<code ext=".py">>#some code\nprint('coucou')\n<</code>>"""
>>> creole2html(creole_markup, macros={'code': code})

命令行界面

如果您已安装python-creole,您将获得这些简单的CLI脚本

  • creole2html

  • html2creole

  • html2rest

  • html2textile

以下是从html2creole获得的--help输出

$ html2creole --help
usage: html2creole [-h] [-v] [--encoding ENCODING] sourcefile destination

python-creole is an open-source (GPL) markup converter in pure Python for:
creole2html, html2creole, html2ReSt, html2textile

positional arguments:
  sourcefile           source file to convert
  destination          Output filename

optional arguments:
  -h, --help           show this help message and exit
  -v, --version        show program's version number and exit
  --encoding ENCODING  Codec for read/write file (default encoding: utf-8)

示例:将html文件转换为creole文件

$ html2creole foobar.html foobar.creole

文档

我们将文档/示例存储在项目wiki中

如何在html2creole中处理未知html标签

贡献者应查看此页面

Creole Markup Cheat Sheet可以在以下位置找到: http://www.wikicreole.org/wiki/CheatSheet

Creole Markup Cheat Sheet

unittests

# clone repository (or use your fork):
~$ git clone https://github.com/jedie/python-creole.git
~$ cd python-creole

# install or update poetry:
~/python-creole$ make install-poetry

# install python-creole via poetry:
~/python-creole$ make install

# Run pytest:
~/python-creole$ make pytest

# Run pytest via tox with all environments:
~/python-creole$ make tox

# Run pytest via tox with one Python version:
~/python-creole$ make tox-py38
~/python-creole$ make tox-py37
~/python-creole$ make tox-py36

make目标

要查看所有make目标,只需调用make

~/python-creole$ make
help                 List all commands
install-poetry       install or update poetry
install              install python-creole via poetry
lint                 Run code formatters and linter
fix-code-style       Fix code formatting
tox-listenvs         List all tox test environments
tox                  Run pytest via tox with all environments
tox-py36             Run pytest via tox with *python v3.6*
tox-py37             Run pytest via tox with *python v3.7*
tox-py38             Run pytest via tox with *python v3.8*
tox-py39             Run pytest via tox with *python v3.9*
pytest               Run pytest
update-rst-readme    update README.rst from README.creole
publish              Release new version to PyPi

在README中使用creole

使用python-creole,您可以在setup.py中即时将README从creole转换为ReStructuredText。如何做到这一点,请阅读:https://github.com/jedie/python-creole/wiki/Use-In-Setup

注意:在这种情况下,您必须安装docutils!请参阅上述内容。

历史记录

  • dev - 比较v1.4.10…master

    • TBC

  • v1.4.10 - 2021-05-11 - 比较v1.4.9…v1.4.10

    • 更新一些字符串格式化为f-strings

    • 将一些join()列表推导式替换为生成器

    • 在github actions下也进行测试(在macOS上)

    • 移除Travis CI(所有测试已通过github actions运行)

  • v1.4.9 - 2020-11-4 - 比较v1.4.8…v1.4.9

    • 添加Python 3.9的缺失分类器(由jugmac00贡献)

    • 更新README测试

  • v1.4.8 - 2020-10-17 - 比较v1.4.7…v1.4.8

  • v1.4.7 - 2020-10-17 - 比较v1.4.6…v1.4.7

    • update_rst_readme()会在文件没有变化时修改README.rst(文件中的时间戳不会更改)

    • 使用 Python 3.9 运行测试。

    • 项目设置的一些元数据更新。

  • v1.4.6 - 2020-02-13 - 比较 v1.4.5…v1.4.6

    • 更宽松的依赖项规范。

  • v1.4.5 - 2020-02-13 - 比较 v1.4.4…v1.4.5

  • v1.4.4 - 2020-02-07 - 比较 v1.4.3…v1.4.4

    • 修复 #44:将 poetry-publish 移动到 dev-dependencies 并降低 docutils 的要求至 ^0.15

    • 一些代码风格更新。

    • 发布前始终更新 README.rst。

  • v1.4.3 - 2020-02-01 - 比较 v1.4.2…v1.4.3

  • v1.4.2 - 2020-02-01 - 比较 v1.4.1…v1.4.2

    • 更新 github 和 travis 上的 CI 配置。

    • 更新 Makefile:添加 make publishmake update-rst-readme

    • 将生成的 README.rst 添加到仓库中,以解决缺少说明书的安装问题。

  • v1.4.1 - 2020-01-19 - 比较 v1.4.0…v1.4.1

  • v1.4.0 - 2020-01-19 - 比较 v1.3.2…v1.4.0

    • 使项目现代化。

      • 使用 poetry。

      • 添加 Makefile

      • 使用 pytest 和 tox。

      • 移除 Python v2 支持。

      • 使用 Python v3.6、v3.7 和 v3.8 进行测试。

  • v1.3.2 - 2018-02-27 - 比较 v1.3.1…v1.3.2

    • 添加可选的 img 大小到 creole2html 和 html2creole,由 John Dupuy 贡献。

    • 使用 python 3.5 和 3.6 运行测试。

  • v1.3.1 - 2015-08-15 - 比较 v1.3.0…v1.3.1

    • 修复“构建 wheel 失败”的 Bug。

  • v1.3.0 - 2015-06-02 - 比较 v1.2.2…v1.3.0

    • 重构内部文件结构。

    • 使用 nose 运行 unittests 和 doctests。

    • 重构 CLI 测试。

    • 跳过对 Python 2.6 的官方支持。

    • 一些小的代码清理和修复。

    • 在某些情况下使用 json.dumps() 代替 repr()

  • v1.2.2 - 2015-04-05 - 比较 v1.2.1…v1.2.2

    • 修复如果 URL 方案未知时 textile unittests 的 Bug。

    • 将 google-code Wiki 迁移到 github 并删除 google-code 链接。

  • v1.2.1 - 2014-09-14 - 比较 v1.2.0…v1.2.1

    • 使用原始 PyPi 代码在 setup.py 中检查生成的 reStructuredText。

    • 更新 textile v2.1.8 的 unittest。

  • v1.2.0 - 2014-05-15 - 比较 v1.1.1…v1.2.0

    • 新增:添加 <<code>> 示例宏(使用 pygments 的代码高亮)- 由 Julien Enselme 实现

    • 新增:添加 <<toc>> 宏以创建目录列表

    • 修复:AttributeError: ‘CreoleParser’ 对象没有属性 ‘_escaped_char_repl’

    • 修复:AttributeError: ‘CreoleParser’ 对象没有属性 ‘_escaped_url_repl’

    • API 变更:可调用宏将引发 TypeError 而不是 DeprecationWarning(已在 v0.5 中删除)

  • v1.1.1 - 2013-11-08

    • 修复:设置脚本退出时出错:无法复制‘README.creole’:不存在或不是常规文件

  • v1.1.0 - 2013-10-28

    • 新增:添加简单的命令行界面。

  • v1.0.7 - 2013-08-07

    • 修复:当 docutils => v0.11 时,‘clean reStructuredText html writer’ 中的错误

    • 修复 PyPy 2.1 使用中的错误

  • v1.0.6 - 2012-10-15

    • rest2html 中的安全修复:默认禁用“file_insertion_enabled”和“raw_enabled”。

  • v1.0.5 - 2012-09-03

    • 使自动协议链接更严格:只允许开头和结尾有空格。

    • 修复:不允许 ftp:/broken(只有一个斜杠)作为链接。

  • v1.0.4 - 2012-06-11

    • html2rest:处理双链接/图片替换,并引发更好的错误信息

    • 修复 unittests 中的错误(包括在 python 包中的测试 README 文件)。感谢 Wen Heping 报告此问题。

  • v1.0.3 - 2012-06-11

    • 修复:来自 HTMLParser 补丁的 AttributeError: 'module' 对象没有属性 'interesting_cdata'。感谢 Wen Heping 报告此问题。

    • 修复 get_long_description() ReSt 测试中的错误,适用于 Py3k 及其 unittests。

    • 使用 Travis CI。

  • v1.0.2 - 2012-04-04

    • 修复 html2creole 中的“AttributeError: ‘NoneType’ 对象没有属性 ‘parent’”。

  • v1.0.1 - 2011-11-16

  • v1.0.0 - 2011-10-20

    • 更改 API:将‘parser_kwargs’和‘emitter_kwargs’替换为单独的参数。(有关 API 的更多信息,请参阅 API Wiki 页面

  • v0.9.2

    • 在 setup.py 中启用 zip_safe 并更改 unittests API。

  • v0.9.1

    • 许多错误修复,已在 CPython 2.6、2.7、3.2 和 PyPy v1.6 上进行测试

  • v0.9.0

    • 添加 Python v3 支持(如 http://python3porting.com/noconv.html 策略)

    • 将 unittests 移入 creole/tests/

    • 在 Python 2.7.1、3.2 和 PyPy v1.6.1 15798ab8cf48 jit 上进行测试

  • v0.8.5

    • html2creole 中的错误修复:忽略没有 href 的链接

  • v0.8.4

  • v0.8.3

  • v0.8.2

    • get_long_description() 错误处理中的错误修复(局部变量‘long_description_origin’在赋值之前引用

  • v0.8.1

    • 修复在 python 2.5 下安装的错误

    • 注意:设置辅助程序 已更改:将 GetLongDescription(...) 重命名为 get_long_description(...)

  • v0.8

  • v0.7.3

    • html2rest 中的错误修复

      • 没有 <th> 标题的表格

      • 表格后的新行

      • 在表格单元格中创建引用超链接,而不是嵌入的 URL。

      • 不要始终使用 raise_unknown_node()

    • 将子内容添加到 raise_unknown_node()

  • v0.7.2

    • 激活 html2rest 中的 ---- 到 <hr>

    • 更新 demo.py

  • v0.7.1

    • 如果 docutils 未安装,则修复错误

    • API变更:rest2html现在已加入: from creole.rest2html.clean_writer import rest2html

  • v0.7.0

    • 新增:添加html2reStructuredText转换器(仅支持reSt的部分功能)

  • v0.6.1

    • 错误修复:在“wiki风格换行”模式下,使用一个空格分隔行

  • v0.6

    • 新增:html2textile转换器

    • 一些 API 已更改

  • v0.5

    • API已更改:

      • Html2CreoleEmitter可选参数‘unknown_emit’现在接受一个可调用对象来处理未知html标签。

      • 在creole2html转换中,默认不使用宏。

      • 我们移除了对可调用宏的支持。只允许使用字典和模块。

    • 在html2creole转换中,移除未知html标签是默认行为。

    • 重构和清理源代码文件。

  • v0.4

    • 仅发出div和span等空标签的子标签(由Eric O’Connell贡献)

    • 移除内部wiki链接,并且不检查协议

  • v0.3.3

    • 当{{{ … }}}内联且不是

      时,使用,参见: PyLucid 论坛主题

    • html2creole中的错误修复:在新列表前插入换行。待办事项:应用于所有块标签: 问题16

  • v0.3.2

    • 修复标题后的空格错误: 问题15

  • v0.3.1

    • 将Parser()中的‘block_rules’参数设置为可选

  • v0.3.0

    • creole2html()有一个可选参数‘blog_line_breaks’,用于从默认的博客换行切换到wiki换行

  • v0.2.8

    • 修复setup.py中的错误

  • v0.2.7

    • 处理过时的未关闭的
      标签

  • v0.2.6

    • 修复setup.py中的错误

    • 清理DocStrings

    • 添加单元测试

  • v0.2.5

    • creole2html:修复了如果“–”,“//”等独立存在时的错误,也参见:问题12

    • 注意:粗体、斜体等不再可以跨行。

  • v0.2.4

    • creole2html:忽略图像标签中的文件扩展名

  • v0.2.3

    • html2creole错误修复/增强:转换没有alt属性的图像标签

      • 也参见:问题6

      • 感谢Betz Stefan别名‘encbladexp’

  • v0.2.2

    • html2creole错误修复:转换<a href="/url/">搜索 & 销毁</a>

  • v0.2.1

    • html2creole错误修复

      • 在转换表格时:忽略tbody标签,并在td中更好地处理p和a标签

      • 转换命名实体

  • v0.2

    • 移除所有django模板标签内容: 问题3

    • html代码始终被转义

  • v0.1.1

    • 改进宏功能,由Vitja Makarov提供的补丁: 问题2

  • v0.1.0

第一个源代码编写于2008年11月27日: 论坛主题(德语)

捐赠


注意:此文件由README.creole于2021-05-11 16:58:01生成,使用“python-creole”

项目详情


发布历史 发布通知 | RSS源

下载文件

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

源代码分布

python-creole-1.4.10.tar.gz (71.8 kB 查看哈希值)

上传时间 源代码

构建分布

python_creole-1.4.10-py3-none-any.whl (86.1 kB 查看哈希值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面