Ansimarkup is a Python library that simplifies producing colored and styled terminal text using an XML-like markup syntax. It translates tags like `<red>Hello</red>` into appropriate ANSI escape codes, supporting various colors, styles (bold, italic, underline), and background colors. The library is currently at version 2.2.0, with stable, albeit infrequent, releases.
pip install ansimarkupVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing AnsiMarkup to parse text and using `ansiprint` for direct output, showcasing basic colored and styled text.
Instead of `am('text')`, use `am.parse('text')`. For direct printing to a stream, use the `ansiprint` function. If you need a custom stream for parsing, pass it to the `AnsiMarkup` constructor: `AnsiMarkup(stream=my_stream)`.Replace calls to `AnsiMarkup().strip_markup(text)` or `ansimarkup.strip_markup(text)` with `from ansimarkup import strip; strip(text)`.
Ensure consistent casing for your tags (e.g., always `<red>` not `<Red>`). If you require case-insensitive tags for backwards compatibility, initialize `AnsiMarkup(case_sensitive=False)`.
Explicitly use the `parse` method: `am.parse("<red>Error</red>")` instead of `am("<red>Error</red>")`.Import and use the new standalone `strip` function: `from ansimarkup import strip; plain_text = strip("<bold>Markup</bold>")`.Ensure you are running in an ANSI-compatible terminal (e.g., most Linux/macOS terminals, modern Windows Terminal). If you need to force colors even when output is redirected, you can initialize `AnsiMarkup(force_colors=True)`. However, this might result in raw escape codes in truly incompatible environments or files.
No dependency data recorded yet.