terminal-codes-to-html
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

terminal-codes-to-html

Convert text that contains ANSI/VT100 color terminal codes to HTML.

History and Status

This package implements enough functionality to convert colored syntax error output from esprima, into HTML that can be displayed in a web page.

It was developed for use in osteele/p5-server. That package now uses `@babel/parser instead of Esprima, so it no longer uses this code.

Install

npm install --save-dev terminal-codes-to-html
yarn add -D terminal-codes-to-html

Usage

Convert codes to HTML

import { terminalCodesToHtml } from "terminal-codes-to-html";

const html = terminalCodesToHtml(
        "\x1b[0m \x1b[90m 5 |\x1b[39m \x1b[36mfunction\x1b[39m draw() {\x1b[0m"
      );
// =>
`  5 | <span style="color: cyan">function</span> draw() {`

Remove terminal codes

import { removeTerminalCodes } from "terminal-codes-to-html";

const text = removeTerminalCodes(
        "\x1b[0m \x1b[90m 5 |\x1b[39m \x1b[36mfunction\x1b[39m draw() {\x1b[0m"
      );
// =>
`  5 | function draw() {`

License

MIT

Package Sidebar

Install

npm i terminal-codes-to-html

Weekly Downloads

642

Version

0.0.1

License

MIT

Unpacked Size

8.29 kB

Total Files

8

Last publish

Collaborators

  • osteele