{"name":"prismjs-terminal","version":"1.2.4","description":"PrismJS syntax highlighting for the terminal","keywords":["terminal","code","syntax","highlight","highlighter","highlighting","hilite","cli"],"author":{"name":"Isaac Z. Schlueter","email":"i@izs.me","url":"https://blog.izs.me"},"type":"module","module":"./dist/esm/index.js","tshy":{"exports":{"./package.json":"./package.json",".":"./src/index.ts","./themes":"./src/themes/index.ts"},"selfLink":false},"license":"BlueOak-1.0.0","scripts":{"preversion":"npm test","postversion":"npm publish","prepublishOnly":"git push origin --follow-tags","prepare":"tshy","pretest":"npm run prepare","presnap":"npm run prepare","test":"tap","snap":"tap","format":"prettier --write . --log-level warn","typedoc":"typedoc"},"devDependencies":{"@types/node":"^24.10.1","@types/prismjs":"^1.26.5","prettier":"^2.8.6","tap":"^21.1.6","tshy":"^3.1.0","typedoc":"^0.28.14"},"engines":{"node":">=16"},"funding":{"url":"https://github.com/sponsors/isaacs"},"repository":{"type":"git","url":"git+https://github.com/isaacs/prismjs-terminal.git"},"dependencies":{"chalk":"^5.2.0","prismjs":"^1.30.0","string-length":"^6.0.0"},"exports":{"./package.json":"./package.json",".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./themes":{"import":{"types":"./dist/esm/themes/index.d.ts","default":"./dist/esm/themes/index.js"},"require":{"types":"./dist/commonjs/themes/index.d.ts","default":"./dist/commonjs/themes/index.js"}}},"main":"./dist/commonjs/index.js","types":"./dist/commonjs/index.d.ts","gitHead":"fd7187ead3c046f8722c39f8c39f0c55de81f4fa","_id":"prismjs-terminal@1.2.4","bugs":{"url":"https://github.com/isaacs/prismjs-terminal/issues"},"homepage":"https://github.com/isaacs/prismjs-terminal#readme","_nodeVersion":"24.4.1","_npmVersion":"11.6.3","dist":{"integrity":"sha512-S2nsjy6s2x2jF4uTW8ulX19rvmRfe9R1wmnNwI5wmBgQEErB0vuKueVPMzN6KsFRCCJ2IQrWUS0BqhcNsrR9xg==","shasum":"e79747acdf428bda8ea56efb81d75f699bdb0657","tarball":"http://registry-npm.ywwl.com/prismjs-terminal/download/prismjs-terminal-1.2.4.tgz","fileCount":69,"unpackedSize":130632,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIFtyEJ5GpGIarBcFmF/QPAJAOnd0SBZsMWaaYaYaz1RhAiEAgV9HNzfeJOb+VWO1GqItp03bcsufmu1jdxc+qJVGubI="}],"size":21729,"noattachment":false,"key":"/prismjs-terminal/-/prismjs-terminal-1.2.4.tgz"},"_npmUser":{"name":"isaacs","email":"i@izs.me"},"directories":{},"maintainers":[{"name":"isaacs","email":"i@izs.me"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/prismjs-terminal_1.2.4_1764045456523_0.8258756456918721"},"_hasShrinkwrap":false,"readme":"# prismjs-terminal\n\n[PrismJS](https://prismjs.com), but for terminal output.\n\n## USAGE\n\n```js\n// ESM only, sorry, blame chalk\n// But less reason to use CommonJS for new CLI apps anyway\nimport { highlight } from 'prismjs-terminal'\n\n// get some code somehow\nimport { readFileSync } from 'fs'\nconst code = readFileSync('some-file.ts', 'utf8')\n\n// highlight it\nconsole.log(highlight(code, 'typescript'))\n```\n\n## Custom Themes\n\nInstead of CSS, themes are defined using an object with\nstyling functions that take a string and return a string.\n\nThe `_` style rule applies to the block as a whole, and is used\nas the default style. This is where you'd usually port a PrismJS\ntheme's `code[class*=\"language-\"]` css rule.\n\nThe `lineNumber` style rule will apply to line numbers, if they\nare used.\n\nThe semantics are similar to CSS, where a nested property will be\napplied to nodes within that nesting stack with a higher\npriority the more tags that match, and later rules taking\nprecedence over earlier ones. It's _not_ a full CSS selector\nsyntax though, so things like `.token.italic.bold` aren't\nsupported. Just individual token class names, possibly nested.\nAlso, chalk is not CSS, and a terminal is not a browser, so\nthere are some differences and limitations of course.\n\nAliases are also not supported, styles have to be applied to the\nactual parsed class names PrismJS provides.\n\nFor example:\n\n```js\nimport { defaultTheme, Theme } from 'prismjs-terminal'\nimport chalk from 'chalk'\nconst theme: Theme = {\n  // any (s:string)=>string function is allowed\n  comment: chalk.hex('#d75fff').italic,\n\n  // can provide multiple functions, which is useful if they\n  // aren't chainable chalk methods\n  function: [chalk.hex('#f08'), s => ` >${s}< `],\n\n  // nest by separating with a space\n  // will turn `/abc/gm` into:\n  // chalk.bold('/' + chalk.green('abc') + '/' + chalk.blue('gm'))\n  regex: chalk.bold,\n  'regex regex-source': chalk.green,\n  'regex regex-flags': chalk.blue,\n\n  // apply one style to multiple token names by separating with `,`\n  'string, number': chalk.green,\n\n  // See the defaultTheme export for more examples.\n}\nconsole.log(highlight(code, 'typescript', { theme }))\n\n// can also use one of the included ones\nconsole.log(highlight(code, 'typescript', { theme: 'xonokai' }))\n```\n\nSee [the themes directory in this repo](./themes) for more\nexamples.\n\n## API\n\n- interface `PrismJSTerminalOpts`\n\n  - `theme` The theme to use. Either a Theme object, or a\n    string identifying one of the built-in themes. Defaults to\n    `'moria'`.\n  - `language` The language of the supplied code to highlight.\n    Defaults to `tsx` if no filename is provided, or else\n    tries to infer the language from the filename. You must\n    have previously called `loadLanguages([...])` from\n    `PrismJS` in order to highlight a given language, if you\n    want something that is not automatically included when\n    `tsx` and `typescript` are included.\n  - `minWidth` The minimum width to make the block on the\n    screen. Defaults to `0`.\n  - `maxWidth` The maximum width to make the block on the\n    screen. Defaults to `process.stdout.columns` or `80`.\n  - `padding` How many spaces to horizontally pad the code\n    block. Defaults to `1`.\n  - `lineNumbers` Whether or not to prepend a line number to each\n    line. Defaults to `false`.\n\n- `highlight(code: string, opts?: PrismJSTerminalOpts): string`\n\n  Highlight the string of code provided, returning the string of\n  highlighted code.\n\n- `highlightFile(filename: string, opts?: PrismJSTerminalOpts): Promise<string>`\n\n  Read the filename provided, and highlight its code. If a\n  language is not provided in the opts, it will attempt to infer\n  from the filename.\n\n- `highlightFileSync(filename: string, opts?: PrismJSTerminalOpts): string`\n\n  Synchronous `highlightFile`.\n\n- Themes:\n\n  More are welcome! If you have a PrismJS theme you like, do\n  send a PR. Of course not everything translates, but it's quite\n  straightforward to take a PrismJS CSS file and turn all the\n  `color: #...` lines into `chalk.hex('#...')` calls.\n\n  Theme objects can be either a Map or object where the keys are\n  the selectors and the values are either a styling function or\n  an array of styling functions to be applied in order.\n\n  - `debug` This just dumps the code wrapped in `<tag>...</tag>`\n    to see what the token names are. Useful for tests and such.\n  - `plain` No styling, just the code as plain text.\n  - `github` Port of GHColors prismjs theme.\n  - `moria` Inspired by Vim Moria color scheme.\n  - `prismDark` Port of the `prism-dark` PrismJS theme.\n  - `xonokai` Port of the `xonokai` PrismJS theme.\n","publish_time":1764045456706,"_cnpm_publish_time":1764045456706,"dist-tags":{"latest":"1.2.4"}}