跳转到主要内容

将ANSI艺术转换为HTML

项目描述

ansipants

一个Python模块和命令行实用程序,用于将.ANS格式的ANSI艺术转换为HTML。

安装

pip install ansipants

命令行用法

python -m ansipants input.ans > output.html

要获取更多信息,请运行 python -m ansipants --help

输出是HTML片段,UTF-8编码,旨在插入到预格式化文本元素(<pre>...</pre>)中。进一步的样式化由您自己决定 - 为了获得正确的MS-DOS体验,建议使用VileR的终极老式PC字体包

Python API

示例代码

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, palette='vga', width=80, strict=False)

参数

  • stream - ANSI输入数据作为文件类似对象。这应该在文本模式下打开,这意味着您需要指定适当的编码 - 对于为DOS创建的ANSI艺术,这很可能是 cp437
  • palette - 要使用的颜色表;要么是 'vga' 要么是 'workbench'
  • width - 文本应换行的列数
  • strict - 如果为True,解码器将在任何未识别或格式不正确的转义码上抛出 ansipants.ANSIDecodeError 异常;如果为False,它将跳过它们。

ANSIDecoder.as_html()

返回HTML输出的字符串。

ANSIDecoder.as_html_lines()

返回HTML输出的迭代器,一次一行。

作者

Matt Westcott matt@west.co.tt

支持