rst2ansi
rst2ansi is a Python library designed to convert reStructuredText (RST) documents into ANSI-decorated strings suitable for display in a terminal. The current version is 0.1.5, released in 2016. The project appears to be in maintenance mode with infrequent updates and known compatibility issues with newer dependencies.
Common errors
-
ImportError: cannot import name 'SafeString' from 'docutils.utils.error_reporting'
cause The rst2ansi library attempts to import `SafeString` or `ErrorString` from `docutils.utils.error_reporting`, which was deprecated in docutils 0.19 and removed in docutils 0.22.3 and later versions.fixDowngrade your `docutils` package to a version older than 0.19 (e.g., `pip install 'docutils<0.19'`) or a version older than 0.22.3 (e.g., `pip install 'docutils<0.22.3'`) to ensure compatibility with rst2ansi. -
ImportError: No module named docutils
cause The `docutils` package, which is a core dependency for `rst2ansi` to parse reStructuredText, is not installed in your Python environment.fixInstall the `docutils` package using pip: `pip install docutils`.
Warnings
- breaking The rst2ansi library is incompatible with recent versions of docutils (e.g., 0.19 and 0.22.3+). Specifically, docutils versions 0.19 and later deprecated and then removed the `docutils.utils.error_reporting` module, leading to `ImportError` or crashes when rst2ansi attempts to use `SafeString` or `ErrorString` from it.
- gotcha The library is largely unmaintained. The last official release was in May 2016, and its development status is listed as '4 - Beta' on PyPI. Critical dependency compatibility issues, such as those with docutils, have not been addressed in official releases.
Install
-
pip install rst2ansi
Imports
- rst2ansi
from rst2ansi import rst2ansi
Quickstart
from rst2ansi import rst2ansi rst_text = """ Heading ======= This is **bold** and *italic* text. * List item 1 * List item 2 """ print(rst2ansi(rst_text))