Creole markup tools written in Python.
python-creole is a OpenSource (GPL) Python lib for converting markups. python-creole is pure python. No external libs needed.
Compatible Python Versions (see tox config in pyproject.toml):
Existing converters:
The creole2html part based on the creole markup parser and emitter from the MoinMoin project by Radomir Dopieralski and Thomas Waldmann.
| | | | | | | |
Python packages available on: http://pypi.python.org/pypi/python-creole/
~$ pip install python-creole
To setup a virtualenv via Poetry, see unittests
section below.
Convert creole markup to html code:
>>> from creole import creole2html
>>> creole2html("This is **creole //markup//**")
'<p>This is <strong>creole <i>markup</i></strong></p>\n'
Convert html code back into creole markup:
>>> from creole import html2creole
>>> html2creole('<p>This is <strong>creole <i>markup</i></strong></p>\n')
'This is **creole //markup//**'
Convert ReStructuredText into clean html code (needs docutils):
>>> from creole.rest2html.clean_writer import rest2html
>>> rest2html(u"A ReSt link to `PyLucid CMS <http://www.pylucid.org>`_ :)")
'<p>A ReSt link to <a href="http://www.pylucid.org">PyLucid CMS</a> :)</p>\\n'
(more information: rest2html wiki page)
Convert html code into ReStructuredText markup:
>>> from creole import html2rest
>>> html2rest('<p>This is <strong>ReStructuredText</strong> <em>markup</em>!</p>')
'This is **ReStructuredText** *markup*!'
Convert html code into textile markup
>>> from creole import html2textile
>>> html2textile('<p>This is <strong>textile <i>markup</i></strong>!</p>')
'This is *textile __markup__*!'
See also: http://github.com/jedie/python-creole/blob/master/demo.py
Convert html code into textile markup
>>> from creole import html2markdown
>>> html2markdown('<p>This is <strong>markdown <i>markup</i></strong>!</p>')
'This is **markdown _markup_**!'
See also: http://github.com/jedie/python-creole/blob/main/demo.py
You can pass image width/height in image tags, e.g.:
>>> 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>'
The third part (90x160
) is not in creole standard, you can force a strict mode, e.g.:
>>> creole2html(creole_markup, strict=True)
'<p><img src="foobar.jpg" title="image title|90x160" alt="image title|90x160" /></p>'
You can find a example macro which highlight source code thanks to the pygments library. It is located here: /creole/shared/example_macros.py. Here is how to use it:
>>> 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})
If you have python-creole installed, you will get these simple CLI scripts:
Here the --help
output from html2creole
:
$ 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)
Example to convert a html file into a creole file:
$ html2creole foobar.html foobar.creole
We store documentation/examples into the project wiki:
How to handle unknown html tags in html2creole:
Contributers should take a look at this page:
Creole Markup Cheat Sheet can be found here: http://www.wikicreole.org/wiki/CheatSheet
# 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
To see all make targets, just call make
:
~/python-creole$ make
help List all commands
install-poetry install or update poetry
install install python-creole via poetry
update Update the dependencies as according to the pyproject.toml file
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
pytest Run pytest
update-readmes update README.rst and README.md from README.creole
publish Release new version to PyPi
With python-creole you can convert a README on-the-fly from creole into ReStructuredText in setup.py How to do this, read: https://github.com/jedie/python-creole/wiki/Use-In-Setup
Note: In this case you must install docutils! See above.
<tt>
with <code>
master
branch to main
.join()
list comprehension with generatorsREADME.rst
with readme-renderer
update_rst_readme()
will touch README.rst
if there are not change (timestamp will not changed in file)creole.setup_utils.assert_rst_readme
for project setup testspoetry-publish
to dev-dependencies
and lower docutils
requirement to ^0.15
make publish
Makefile
: add make publish
and make update-rst-readme
README.rst
in repository to fix install problems about missing readme%-formatted
and .format(...)
strings into Python 3.6+'s f-strings
with flyntMakefile
<<code>>
example macro (Source code highlighting with pygments) - implemented by Julien Enselme<<toc>>
macro to create a table of contents listftp:/broken
(Only one slash) to be a link.AttributeError: 'module' object has no attribute 'interesting_cdata'
from HTMLParser patch. Thanks to Wen Heping for reporting this.GetLongDescription(...)
to get_long_description(...)
<th>
header----
to <hr>
in html2restfrom creole.rest2html.clean_writer import rest2html
<tt>
when {{{ ... }}} is inline and not <pre>
, see: PyLucid Forum Thread
<a href="/url/">Search & Destroy</a>
first source code was written 27.11.2008: Forum thread (de)
| GitHub | https://github.com/jedie/python-creole | | Wiki | https://github.com/jedie/python-creole/wiki | | PyPi | https://pypi.org/project/python-creole/ |
Note: this file is generated from README.creole 2022-08-23 07:57:12 with "python-creole"