{"id":13583282,"url":"https://github.com/wooorm/emphasize","last_synced_at":"2025-04-04T19:12:46.828Z","repository":{"id":52502255,"uuid":"59288864","full_name":"wooorm/emphasize","owner":"wooorm","description":"ANSI syntax highlighting for the terminal","archived":false,"fork":false,"pushed_at":"2023-11-01T15:50:02.000Z","size":911,"stargazers_count":113,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T18:14:10.962Z","etag":null,"topics":["ansi","cli","highlight","syntax","syntax-highlighting","terminal","virtual"],"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/wooorm.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":"funding.yml","license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"wooorm"}},"created_at":"2016-05-20T11:23:37.000Z","updated_at":"2025-03-01T02:40:10.000Z","dependencies_parsed_at":"2024-06-18T13:40:00.084Z","dependency_job_id":"8e198640-824b-4a94-84f5-5ea738dfbe66","html_url":"https://github.com/wooorm/emphasize","commit_stats":{"total_commits":97,"total_committers":2,"mean_commits":48.5,"dds":0.04123711340206182,"last_synced_commit":"002bff25052a0d5e554eac5bd3df88584408707c"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Femphasize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Femphasize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Femphasize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wooorm%2Femphasize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wooorm","download_url":"https://codeload.github.com/wooorm/emphasize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247234923,"owners_count":20905854,"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":["ansi","cli","highlight","syntax","syntax-highlighting","terminal","virtual"],"created_at":"2024-08-01T15:03:22.648Z","updated_at":"2025-04-04T19:12:46.807Z","avatar_url":"https://github.com/wooorm.png","language":"JavaScript","readme":"# emphasize\n\n[![Build][badge-build-image]][badge-build-url]\n[![Coverage][badge-coverage-image]][badge-coverage-url]\n[![Downloads][badge-downloads-image]][badge-downloads-url]\n[![Size][badge-size-image]][badge-size-url]\n\nANSI syntax highlighting for the terminal.\n\n## Contents\n\n*   [What is this?](#what-is-this)\n*   [When should I use this?](#when-should-i-use-this)\n*   [Install](#install)\n*   [Use](#use)\n*   [API](#api)\n    *   [`all`](#all)\n    *   [`common`](#common)\n    *   [`createEmphasize(grammars?)`](#createemphasizegrammars)\n    *   [`emphasize.highlight(language, value[, options])`](#emphasizehighlightlanguage-value-options)\n    *   [`emphasize.highlightAuto(value[, options])`](#emphasizehighlightautovalue-options)\n    *   [`emphasize.listLanguages()`](#emphasizelistlanguages)\n    *   [`emphasize.register(grammars)`](#emphasizeregistergrammars)\n    *   [`emphasize.registerAlias(aliases)`](#emphasizeregisteraliasaliases)\n    *   [`emphasize.registered(aliasOrLanguage)`](#emphasizeregisteredaliasorlanguage)\n    *   [`AutoOptions`](#autooptions)\n    *   [`LanguageFn`](#languagefn)\n    *   [`Result`](#result)\n    *   [`Sheet`](#sheet)\n    *   [`Style`](#style)\n*   [Compatibility](#compatibility)\n*   [Security](#security)\n*   [Contribute](#contribute)\n*   [License](#license)\n\n## What is this?\n\nThis package wraps [`lowlight`][github-lowlight] to output ANSI syntax\nhighlighting instead of HTML.\nIt can support 190+ programming languages.\n\n## When should I use this?\n\nThis package is useful when you want to display code on a terminal.\n\n## Install\n\nThis package is [ESM only][github-gist-esm].\nIn Node.js (version 16+),\ninstall with [npm][npm-install]:\n\n```sh\nnpm install emphasize\n```\n\nIn Deno with [`esm.sh`][esm-sh]:\n\n```js\nimport {all, common, createEmphasize} from 'https://esm.sh/emphasize@7'\n```\n\nIn browsers with [`esm.sh`][esm-sh]:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import {all, common, createEmphasize} from 'https://esm.sh/emphasize@7?bundle'\n\u003c/script\u003e\n```\n\n## Use\n\nSay `example.css` looks as follows:\n\n```css\n@font-face {\n  font-family: Alpha;\n  src: url('Bravo.otf');\n}\n\nbody, .charlie, #delta {\n  color: #bada55;\n  background-color: rgba(33, 33, 33, 0.33);\n  font-family: \"Alpha\", sans-serif;\n}\n\n@import url(echo.css);\n\n@media print {\n  a[href^=http]::after {\n    content: attr(href)\n  }\n}\n```\n\n…and `example.js` contains the following:\n\n```js\nimport fs from 'node:fs/promises'\nimport {emphasize} from 'emphasize'\n\nconst doc = String(await fs.readFile('example.css'))\n\nconst output = emphasize.highlightAuto(doc).value\n\nconsole.log(output)\n```\n\n…now running `node example.js` yields:\n\n```txt\n\\x1B[32m@font-face\\x1B[39m {\n  \\x1B[33mfont-family\\x1B[39m: Alpha;\n  \\x1B[33msrc\\x1B[39m: \\x1B[31murl\\x1B[39m(\\x1B[36m'Bravo.otf'\\x1B[39m);\n}\n\n\\x1B[32mbody\\x1B[39m, \\x1B[34m.charlie\\x1B[39m, \\x1B[34m#delta\\x1B[39m {\n  \\x1B[33mcolor\\x1B[39m: \\x1B[36m#bada55\\x1B[39m;\n  \\x1B[33mbackground-color\\x1B[39m: \\x1B[31mrgba\\x1B[39m(\\x1B[36m33\\x1B[39m, \\x1B[36m33\\x1B[39m, \\x1B[36m33\\x1B[39m, \\x1B[36m0.33\\x1B[39m);\n  \\x1B[33mfont-family\\x1B[39m: \\x1B[36m\"Alpha\"\\x1B[39m, sans-serif;\n}\n\n\\x1B[32m@import\\x1B[39m url(echo.css);\n\n\\x1B[32m@media\\x1B[39m print {\n  \\x1B[32ma\\x1B[39m\\x1B[35m[href^=http]\\x1B[39m\\x1B[35m::after\\x1B[39m {\n    \\x1B[33mcontent\\x1B[39m: \\x1B[31mattr\\x1B[39m(href)\n  }\n}\n```\n\n…which looks as follows:\n\n![Screenshot showing the code in terminal](screenshot.png)\n\n## API\n\nThis package exports the identifiers\n[`all`][api-all],\n[`common`][api-common],\nand [`createEmphasize`][api-create-emphasize].\nThere is no default export.\n\nIt exports the [TypeScript][] types\n[`AutoOptions`][api-auto-options],\n[`LanguageFn`][api-language-fn],\n[`Result`][api-result],\n[`Sheet`][api-sheet],\nand [`Style`][api-style].\n\n### `all`\n\nMap of all (±190) grammars ([`Record\u003cstring, LanguageFn\u003e`][api-language-fn]).\n\nSee [`all` from `lowlight`][github-lowlight-all].\n\n### `common`\n\nMap of common (37) grammars ([`Record\u003cstring, LanguageFn\u003e`][api-language-fn]).\n\nSee [`common` from `lowlight`][github-lowlight-common].\n\n### `createEmphasize(grammars?)`\n\nCreate a `emphasize` instance.\n\n###### Parameters\n\n*   `grammars` ([`Record\u003cstring, LanguageFn\u003e`][api-language-fn], optional)\n    — grammars to add\n\n###### Returns\n\nEmphasize (`emphasize`).\n\n### `emphasize.highlight(language, value[, options])`\n\nHighlight `value` (code) as `language` (name).\n\n###### Parameters\n\n*   `language` (`string`)\n    — programming language [name][github-highlight-names]\n*   `value` (`string`)\n    — code to highlight\n*   `sheet` ([`Sheet`][api-sheet], optional)\n    — style sheet\n\n###### Returns\n\n[`Result`][api-result].\n\n### `emphasize.highlightAuto(value[, options])`\n\nHighlight `value` (code) and guess its programming language.\n\n###### Parameters\n\n*   `value` (`string`)\n    — code to highlight\n*   `options` ([`AutoOptions`][api-auto-options] or [`Sheet`][api-sheet],\n    optional)\n    — configuration or style sheet\n\n###### Returns\n\n[`Result`][api-result].\n\n### `emphasize.listLanguages()`\n\nList registered languages.\n\nSee [`lowlight.listLanguages`][github-lowlight-list-languages].\n\n### `emphasize.register(grammars)`\n\nRegister languages.\n\nSee [`lowlight.register`][github-lowlight-register].\n\n### `emphasize.registerAlias(aliases)`\n\nRegister aliases.\n\nSee [`lowlight.registerAlias`][github-lowlight-register-alias].\n\n### `emphasize.registered(aliasOrLanguage)`\n\nCheck whether an alias or name is registered.\n\nSee [`lowlight.registered`][github-lowlight-registered].\n\n### `AutoOptions`\n\nConfiguration for `highlightAuto` (TypeScript type).\n\n###### Fields\n\n*   `sheet` ([`Sheet`][api-sheet], optional)\n    — sheet\n*   `subset` (`Array\u003cstring\u003e`, default: all registered languages)\n    — list of allowed languages\n\n### `LanguageFn`\n\nHighlight.js grammar (TypeScript type).\n\nSee [`LanguageFn` from `lowlight`][github-lowlight-langauge-fn].\n\n### `Result`\n\nResult (TypeScript type).\n\n###### Fields\n\n*   `language` (`string` or `undefined`)\n    — detected programming language.\n*   `relevance` (`number` or `undefined`)\n    — how sure `lowlight` is that the given code is in the language\n*   `value` (`string`)\n    — highlighted code\n\n### `Sheet`\n\nMap [`highlight.js` classes][github-highlight-classes] to styles functions\n(TypeScript type).\n\nThe `hljs-` prefix must not be used in those classes.\nThe “descendant selector” (a space) is supported.\n\nFor convenience [chalk’s chaining of styles][github-chalk-styles] is suggested.\nAn abbreviated example is as follows:\n\n```js\n{\n  'comment': chalk.gray,\n  'meta meta-string': chalk.cyan,\n  'meta keyword': chalk.magenta,\n  'emphasis': chalk.italic,\n  'strong': chalk.bold,\n  'formula': chalk.inverse\n}\n```\n\n###### Type\n\n```ts\ntype Sheet = Record\u003cstring, Style\u003e\n```\n\n### `Style`\n\nColor something (TypeScript type).\n\n###### Parameters\n\n*   `value` (`string`)\n    — input\n\n###### Returns\n\nOutput (`string`).\n\n## Compatibility\n\nThis projects is compatible with maintained versions of Node.js.\n\nWhen we cut a new major release,\nwe drop support for unmaintained versions of Node.\nThis means we try to keep the current release line,\n`emphasize@7`,\ncompatible with Node.js 16.\n\n## Security\n\nThis package is safe.\n\n## Contribute\n\nYes please!\nSee [How to Contribute to Open Source][open-source-guide-contribute].\n\n## License\n\n[MIT][file-license] © [Titus Wormer][wooorm]\n\n\u003c!-- Definitions --\u003e\n\n[api-all]: #all\n\n[api-auto-options]: #autooptions\n\n[api-common]: #common\n\n[api-create-emphasize]: #createemphasizegrammars\n\n[api-language-fn]: #languagefn\n\n[api-result]: #result\n\n[api-sheet]: #sheet\n\n[api-style]: #style\n\n[badge-build-image]: https://github.com/wooorm/emphasize/workflows/main/badge.svg\n\n[badge-build-url]: https://github.com/wooorm/emphasize/actions\n\n[badge-coverage-image]: https://img.shields.io/codecov/c/github/wooorm/emphasize.svg\n\n[badge-coverage-url]: https://codecov.io/github/wooorm/emphasize\n\n[badge-downloads-image]: https://img.shields.io/npm/dm/emphasize.svg\n\n[badge-downloads-url]: https://www.npmjs.com/package/emphasize\n\n[badge-size-image]: https://img.shields.io/bundlejs/size/emphasize\n\n[badge-size-url]: https://bundlejs.com/?q=emphasize\n\n[npm-install]: https://docs.npmjs.com/cli/install\n\n[esm-sh]: https://esm.sh\n\n[file-license]: license\n\n[github-chalk-styles]: https://github.com/chalk/chalk#styles\n\n[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c\n\n[github-highlight-classes]: https://highlightjs.readthedocs.io/en/latest/css-classes-reference.html\n\n[github-highlight-names]: https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md\n\n[github-lowlight]: https://github.com/wooorm/lowlight\n\n[github-lowlight-all]: https://github.com/wooorm/lowlight#all\n\n[github-lowlight-common]: https://github.com/wooorm/lowlight#common\n\n[github-lowlight-langauge-fn]: https://github.com/wooorm/lowlight#languagefn\n\n[github-lowlight-list-languages]: https://github.com/wooorm/lowlight#lowlightlistlanguages\n\n[github-lowlight-register]: https://github.com/wooorm/lowlight#lowlightregistergrammars\n\n[github-lowlight-register-alias]: https://github.com/wooorm/lowlight#lowlightregisteraliasaliases\n\n[github-lowlight-registered]: https://github.com/wooorm/lowlight#lowlightregisteredaliasorlanguage\n\n[open-source-guide-contribute]: https://opensource.guide/how-to-contribute/\n\n[typescript]: https://www.typescriptlang.org\n\n[wooorm]: https://wooorm.com\n","funding_links":["https://github.com/sponsors/wooorm"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Femphasize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwooorm%2Femphasize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwooorm%2Femphasize/lists"}