https://github.com/osteele/terminal-codes-to-html
Convert strings that include terminal color codes to HTML or plain text.
https://github.com/osteele/terminal-codes-to-html
html-formatter terminal-colors vt100
Last synced: 7 months ago
JSON representation
Convert strings that include terminal color codes to HTML or plain text.
- Host: GitHub
- URL: https://github.com/osteele/terminal-codes-to-html
- Owner: osteele
- License: mit
- Created: 2021-11-05T10:06:01.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-05T10:08:34.000Z (almost 4 years ago)
- Last Synced: 2025-02-25T09:18:40.641Z (8 months ago)
- Topics: html-formatter, terminal-colors, vt100
- Language: TypeScript
- Homepage:
- Size: 86.9 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# terminal-codes-to-html
Convert text that contains [ANSI/VT100 color terminal
codes](https://wiki.bash-hackers.org/scripting/terminalcodes) to HTML or plain
text.## History and Status
This package implements enough functionality to convert colored syntax error
output from [esprima](https://esprima.org/index.html), into HTML that can be
displayed in a web page.It was developed for use in
[osteele/p5-server](https://github.com/osteele/p5-server). That package now uses
[`@babel/parser](https://babel.dev/docs/en/babel-parser) instead of Esprima, so
it no longer uses this code.## Install
```sh
npm install --save-dev terminal-codes-to-html
``````sh
yarn add -D terminal-codes-to-html
```## Usage
### Convert codes to HTML
```js
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 | function draw() {`
```### Remove terminal codes
```js
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