A pure Python markup converter supporting creole2html, html2creole, html2ReSt, and html2textile conversions
—
Command-line tools for file-based markup conversion with support for different text encodings and batch processing. python-creole provides several CLI commands for converting files between markup formats.
Base class for command-line conversion tools.
class CreoleCLI:
def __init__(self, convert_func): ...
def convert(self, sourcefile: str, destination: str, encoding: str): ...Parameters:
convert_func: Conversion function to use (creole2html, html2creole, etc.)Usage Examples:
from creole.cmdline import CreoleCLI
from creole import creole2html
# Create custom CLI tool
cli = CreoleCLI(creole2html)
cli.convert('input.creole', 'output.html', 'utf-8')Pre-configured CLI functions for each conversion type.
def cli_creole2html(): ...
def cli_html2creole(): ...
def cli_html2rest(): ...
def cli_html2textile(): ...Usage Examples:
# These are called by the installed command-line tools
from creole.cmdline import cli_creole2html, cli_html2creole
# Direct invocation (not typical usage)
import sys
sys.argv = ['creole2html', 'input.creole', 'output.html']
cli_creole2html()When python-creole is installed, these commands become available:
Convert Creole markup files to HTML.
creole2html input.creole output.html
creole2html --encoding=utf-8 source.txt dest.html
creole2html --helpOptions:
sourcefile: Input Creole file pathdestination: Output HTML file path--encoding: Text encoding (default: utf-8)--version: Show version information--help: Show help messageUsage Examples:
# Basic conversion
creole2html README.creole README.html
# Specify encoding
creole2html --encoding=latin1 old_file.creole new_file.html
# Convert multiple files with shell globbing
for file in *.creole; do
creole2html "$file" "${file%.creole}.html"
doneConvert HTML files to Creole markup.
html2creole input.html output.creole
html2creole --encoding=utf-8 source.html dest.txt
html2creole --helpOptions:
sourcefile: Input HTML file pathdestination: Output Creole file path--encoding: Text encoding (default: utf-8)--version: Show version information--help: Show help messageUsage Examples:
# Basic conversion
html2creole webpage.html content.creole
# Batch convert HTML files
find . -name "*.html" -exec html2creole {} {}.creole \;
# Convert with specific encoding
html2creole --encoding=iso-8859-1 legacy.html modern.creoleConvert HTML files to ReStructuredText.
html2rest input.html output.rst
html2rest --encoding=utf-8 source.html dest.rst
html2rest --helpOptions:
sourcefile: Input HTML file pathdestination: Output ReStructuredText file path--encoding: Text encoding (default: utf-8)--version: Show version information--help: Show help messageUsage Examples:
# Convert for Sphinx documentation
html2rest content.html docs/content.rst
# Convert README for PyPI
html2rest README.html README.rst
# Process documentation files
mkdir -p rst_docs
for html in docs/*.html; do
html2rest "$html" "rst_docs/$(basename "$html" .html).rst"
doneConvert HTML files to Textile markup.
html2textile input.html output.textile
html2textile --encoding=utf-8 source.html dest.txt
html2textile --helpOptions:
sourcefile: Input HTML file pathdestination: Output Textile file path--encoding: Text encoding (default: utf-8)--version: Show version information--help: Show help messageUsage Examples:
# Basic conversion
html2textile article.html article.textile
# Convert blog posts
html2textile blog_post.html blog_post.txt
# Batch process with custom encoding
html2textile --encoding=cp1252 windows_file.html output.textileUpdate ReStructuredText README from Creole source.
update_rst_readmeUsage Examples:
# Update README.rst from README.creole in current directory
cd /my/project
update_rst_readme
# Use in build scripts
#!/bin/bash
cd "$PROJECT_ROOT"
update_rst_readme
echo "README.rst updated"Publish python-creole package to PyPI (internal tool).
publishAll CLI tools provide consistent error handling:
# File not found
$ creole2html nonexistent.creole output.html
Error: Could not read input file 'nonexistent.creole'
# Permission denied
$ html2creole input.html /root/output.creole
Error: Could not write to output file '/root/output.creole'
# Encoding errors
$ creole2html --encoding=ascii unicode_file.creole output.html
Error: Encoding 'ascii' cannot decode input file#!/bin/bash
# build_docs.sh
echo "Converting documentation..."
# Convert all Creole files to HTML
for creole_file in docs/*.creole; do
html_file="${creole_file%.creole}.html"
echo "Converting $creole_file -> $html_file"
creole2html "$creole_file" "$html_file"
done
# Convert HTML to ReStructuredText for Sphinx
for html_file in docs/*.html; do
rst_file="sphinx_docs/$(basename "$html_file" .html).rst"
echo "Converting $html_file -> $rst_file"
html2rest "$html_file" "$rst_file"
done
echo "Documentation conversion complete"# Makefile
docs: README.html docs/manual.html
README.html: README.creole
creole2html README.creole README.html
docs/manual.html: docs/manual.creole
creole2html docs/manual.creole docs/manual.html
rst-docs: docs/*.html
mkdir -p rst-docs
for html in docs/*.html; do \
html2rest "$$html" "rst-docs/$$(basename "$$html" .html).rst"; \
done
clean:
rm -f README.html docs/*.html rst-docs/*.rst
.PHONY: docs rst-docs clean# .github/workflows/docs.yml
name: Update Documentation
on: [push, pull_request]
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install python-creole
run: pip install python-creole
- name: Update README.rst
run: update_rst_readme
- name: Convert documentation
run: |
creole2html docs/guide.creole docs/guide.html
html2rest docs/guide.html docs/guide.rst
- name: Commit updated files
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.rst docs/guide.html docs/guide.rst
git diff --staged --quiet || git commit -m "Update generated documentation"For large files or batch processing:
# Process files in parallel with GNU parallel
find docs -name "*.creole" | parallel creole2html {} {.}.html
# Use shell job control for concurrent processing
for file in *.creole; do
creole2html "$file" "${file%.creole}.html" &
done
wait # Wait for all background jobs to completeInstall with Tessl CLI
npx tessl i tessl/pypi-python-creole