{"id":19063027,"url":"https://github.com/jakub-g/ansi2html-extended","last_synced_at":"2025-06-30T12:32:29.872Z","repository":{"id":27339920,"uuid":"30814779","full_name":"jakub-g/ansi2html-extended","owner":"jakub-g","description":"(WIP) Pipe your colored console output to HTML. Customizable.","archived":false,"fork":false,"pushed_at":"2016-11-16T10:24:52.000Z","size":14,"stargazers_count":3,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T15:03:17.119Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jakub-g.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-15T01:48:34.000Z","updated_at":"2022-06-16T07:52:32.000Z","dependencies_parsed_at":"2022-08-07T12:16:17.081Z","dependency_job_id":null,"html_url":"https://github.com/jakub-g/ansi2html-extended","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakub-g%2Fansi2html-extended","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakub-g%2Fansi2html-extended/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakub-g%2Fansi2html-extended/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakub-g%2Fansi2html-extended/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakub-g","download_url":"https://codeload.github.com/jakub-g/ansi2html-extended/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250593684,"owners_count":21455849,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T00:28:39.453Z","updated_at":"2025-04-25T09:16:33.177Z","avatar_url":"https://github.com/jakub-g.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ansi2html-extended\n [![Build Status](https://secure.travis-ci.org/jakub-g/ansi2html-extended.png?branch=master)](http://travis-ci.org/jakub-g/ansi2html-extended)\n\n [![Get it on npm](https://nodei.co/npm/ansi2html-extended.png?compact=true)](https://www.npmjs.org/package/ansi2html-extended)\n\n**Note that this module is a work in progress. It may contain bugs and not work cross-platform.**\n\nThis module, written in JavaScript, is an extended fork of [https://github.com/mmalecki/ansispan](ansispan).\nIt converts an input string with ANSI escape codes (for colored console output etc.) into its\nHTML equivalent. It can be used either as a nodejs module, or as a command-line utility.\n\nUnlike original module, this module wraps text with `\u003cspan\u003e`s with defined CSS classes,\ninstead of hardcoded inline CSS strings.\n\nApart from that, it allows to:\n\n- output either standalone HTML file, or just an HTML chunk\n- pre-process the text by escaping HTML special characters\n\nTested on Windows (Git Bash / MINGW).\n\nIt requires nodejs and npm. If you don't have node, grab it at [nodejs.org](https://nodejs.org).\nNode installer bundles npm (node package manager).\n\nTested on nodejs 0.10.\n\n## API\n\n##### `a2h.fromStream(cfg, inputStream, outputStream)`\n\nRead text from `inputStream` and write HTML to `outputStream`.\n\n##### `a2h.fromStream(cfg)`\n\nRead text from `stdin` and write HTML to `stdout`.\n\n##### `a2h.fromString(string)`\n##### `a2h.fromString(cfg, string)`\n\nRead input text String `string` and return HTML as `String`\n\n\n## Configuration\n\n##### `cfg.standalone` Boolean (default: `true` when input is stream, `false` when input is string)\n\nIf `true`, output will be a valid HTML file, and it will contain color palette in the `\u003chead\u003e`,\nas a `style` tag. Otherwise, only a HTML chunk will be generated.\n\n##### `cfg.wrapped` Boolean (defaults to value of `cfg.standalone`)\n\nWhether to wrap the passed string in `\u003cspan class=\"ansi_console_snippet\"\u003e\u003c/span\u003e`.\n\n##### `cfg.escapeHtml` Boolean (default: `true`)\n\nWhether HTML entities in input string should be escaped (`\u0026` -\u003e `\u0026amp;` etc.).\n\n##### `cfg.palette` Object (optional)\n\nThis allows you to override the default colors.\n\nBy default, it is assumed that console is `white` text on `black` background, and HTML\nnamed colors are used for escape codes, i.e. ANSI 34 and 44 will use HTML `blue` color.\n\nYou can override each of the colors by passing any of the following keys:\n`black`, `white`, `red`, `green`, `blue`, `yellow`, `purple`, `cyan`.\n\nYou can also override each of them *separately for foreground and background* using\n`fg_black`, `bg_black` and so on.\n\nYou can override default colors of the console by either overriding `black` and `white`,\nor directly via `bg` and `fg`.\n\nExample:\n\n```js\n    palette: {\n        bg: '#222222',\n        fg: '#eeeeee',\n        fg_red:'#ff0000',\n        bg_red:'#dd0000',\n        green: '#00cc3e'\n    }\n```\n\n## Usage as a nodejs module\n\n```sh\n$ npm install --save-dev ansi2html-extended\n```\n\n```js\nvar a2h = require('ansi2html-extended');\nvar cfg = {\n    standalone: true,\n    palette: {\n        black: '#222222',\n        white: '#eeeeee'\n    }\n}\n\n// read text from stdin and output HTML to stdout\na2h.fromStream(cfg);\n\n// you can also just pass a string and get a string returned\na2h.fromString(\"\u001b[33mcommit d0fb3a8a5487559e8a2d76735f04b5a02b242838\u001b[m\")\n// returns `\u003cspan class=\"ansi_fg_yellow\"\u003ecommit d0fb3a8a5487559e8a2d76735f04b5a02b242838\u003c/span\u003e`\n\n// you can pass cfg as a first parameter too\na2h.fromString({\n  wrapped: true\n}, \"\u001b[33mcommit d0fb3a8a5487559e8a2d76735f04b5a02b242838\u001b[m\")\n// returns `\u003cspan class=\"ansi_console_snippet\"\u003e\u003cspan class=\"ansi_fg_yellow\"\u003ecommit d0fb3a8a5487559e8a2d76735f04b5a02b242838\u003c/span\u003e\u003c/span\u003e`\n\n```\n\n\n## Usage from command line\n\n```sh\n# this will create two symlinks in PATH: `ansi2html` and `a2h`\n$ npm install -g ansi2html-extended\n\n# Ask git for colored summary of last commit, and pipe it to a2h\n# This prints to stdout by default\n# Note we explicitly ask for --color; git disables colors when piping\n$ git show --stat --color | a2h\n\n# It will be more interesting when we save it to a file...\n$ git show --stat --color | a2h \u003e examples/git-show-stat.html\n$ firefox examples/git-show-stat.html\n```\n\nSee the live rendered [`examples/git-show-stat.html`](https://rawgit.com/jakub-g/ansi2html-extended/master/examples/git-show-stat.html)\n\nThe following options are used when `a2h` is invoked from command line:\n\n```js\n{\n    standalone: true,\n    escapeHtml: true,\n    palette: {\n        black: '#222222',\n        white: '#eeeeee',\n        red:   '#dd0000',\n        green: '#00cc3e',\n        blue:  '#0099ff',\n        yellow:'#eeee00',\n        purple:'#bb00bb',\n        cyan:  '#eeeeee'\n    }\n}\n```\n\n## License\n\nMIT © [Jakub Gieryluk](http://jakub-g.github.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakub-g%2Fansi2html-extended","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakub-g%2Fansi2html-extended","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakub-g%2Fansi2html-extended/lists"}