Convert ANSI art to HTML
Project description
ansipants
A Python module and command-line utility for converting .ANS format ANSI art to HTML.
Installation
pip install ansipants
Command-line usage
python -m ansipants input.ans > output.html
For additional options, run python -m ansipants --help
.
The output is a fragment of HTML, in UTF-8 encoding, intended to be inserted into a preformatted text element such as <pre style="background-color: #000;">...</pre>
. Further styling is up to you - for the proper MS-DOS experience, The Ultimate Oldschool PC Font Pack by VileR is recommended.
Python API
Example code:
from ansipants import ANSIDecoder
with open('input.ans', 'rt', encoding='cp437') as f:
decoder = ANSIDecoder(f)
print(decoder.as_html())
class ansipants.ANSIDecoder(stream=None, width=80, strict=False)
Parameters:
stream
- the ANSI input data as a file-like object. This should be opened for reading in text mode, which means you'll need to specify the appropriate encoding - for ANSI art created for DOS this will most likely becp437
.width
- the number of columns the text should wrap atstrict
- If True, the decoder will raise anansipants.ANSIDecodeError
exception on any unrecognised or malformed escape codes; if False, it will skip past them.
ANSIDecoder.as_html()
Returns the HTML output as a string.
ANSIDecoder.as_html_lines()
Returns the HTML output as an iterator, yielding one line at a time.
Author
Matt Westcott matt@west.co.tt
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ansipants-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0a92c8054e52bc20621e93f0641937a5ff66ed64b17613d6beb7d84b88e28cd |
|
MD5 | e6d36f93dbc98af8a1593d0e5f813153 |
|
BLAKE2b-256 | b013b28023c0206b32857daa86e3453a9d9d59e2fca9bc553bbac480ac14f54a |