{"id":15513542,"url":"https://github.com/posthtml/posthtml-highlight","last_synced_at":"2025-04-11T20:52:06.224Z","repository":{"id":35090256,"uuid":"127067640","full_name":"posthtml/posthtml-highlight","owner":"posthtml","description":":art: Syntax Highlighting for PostHTML","archived":false,"fork":false,"pushed_at":"2023-03-03T23:06:56.000Z","size":1330,"stargazers_count":9,"open_issues_count":14,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T21:06:05.251Z","etag":null,"topics":["highlight","highlightjs","posthtml","posthtml-plugin","syntax-highlighter","syntax-highlighting"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/posthtml.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-03-28T01:44:10.000Z","updated_at":"2023-11-07T09:52:08.000Z","dependencies_parsed_at":"2023-02-10T06:30:44.646Z","dependency_job_id":null,"html_url":"https://github.com/posthtml/posthtml-highlight","commit_stats":{"total_commits":556,"total_committers":5,"mean_commits":111.2,"dds":0.1960431654676259,"last_synced_commit":"c6448bd78cc49f0be2a4c1275501ac1109a2f60c"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-highlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-highlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-highlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-highlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-highlight/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247190228,"owners_count":20898704,"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":["highlight","highlightjs","posthtml","posthtml-plugin","syntax-highlighter","syntax-highlighting"],"created_at":"2024-10-02T09:54:24.861Z","updated_at":"2025-04-11T20:52:06.190Z","avatar_url":"https://github.com/posthtml.png","language":"TypeScript","readme":"# PostHTML Highlight Plugin \u003cimg align=\"right\" width=\"220\" height=\"200\" title=\"PostHTML logo\" src=\"http://posthtml.github.io/posthtml/logo.svg\"\u003e\n\n[![Version][npm-version-shield]][npm]\n[![License][wtfpl-shield]][wtfpl]\n[![TypeScript][typescript-shield]][typescript]\n[![Build Status][build-status-shield]][build-status]\n[![Coverage][codecov-shield]][codecov]\n[![Downloads][npm-stats-shield]][npm-stats]\n[![Chat][gitter-shield]][gitter]\n\nCompile-time syntax highlighting for code blocks via [highlight.js][]\n\nBefore:\n\n```html\n\u003cpre\u003e\u003ccode\u003e\n  const foo = 'foo'\n  console.log(foo)\n\u003c/code\u003e\u003c/pre\u003e\n```\n\nAfter:\n\n```html\n\u003cpre\u003e\u003ccode class=\"hljs\"\u003e\n  \u003cspan class=\"hljs-keyword\"\u003econst\u003c/span\u003e foo = \u003cspan class=\"hljs-string\"\u003e'foo'\u003c/span\u003e\n  console.\u003cspan class=\"hljs-built_in\"\u003elog\u003c/span\u003e(foo)\n\u003c/code\u003e\u003c/pre\u003e\n```\n\n## Install\n\n```\n$ yarn add -D posthtml posthtml-highlight\n```\n\n_or_\n\n```\n$ npm i posthtml posthtml-highlight\n```\n\nIf using TypeScript, additionally install `@types/highlight.js`\n\n## Usage\n\n```js\nconst fs = require('fs')\nconst posthtml = require('posthtml')\nconst highlight = require('posthtml-highlight')\n\nconst source = fs.readFileSync('./before.html')\n\nposthtml([\n  highlight(\n    /* optional */ {\n      /**\n       * By default, only code tags wrapped in pre tags are highlighted (i.e. \u003cpre\u003e\u003ccode\u003e\u003ccode/\u003e\u003cpre/\u003e)\n       *\n       * Set `inline: true` to highlight all code tags\n       */\n      inline: true,\n\n      /**\n       * You may also pass any highlight.js options (http://highlightjs.readthedocs.io/en/latest/api.html#configure-options)\n       */\n      useBR: true,\n    }\n  ),\n])\n  .process(source)\n  .then((result) =\u003e fs.writeFileSync('./after.html', result.html))\n```\n\n### Styling\n\nYou will also need to include a highlight.js stylesheet\n\nView the available color schemes [here](https://highlightjs.org/static/demo/), then  \na) include via a [CDN](https://cdnjs.com/libraries/highlight.js)  \nb) install via npm (`yarn add -D highlight.js`, `./node_modules/highlight.js/styles/*`)  \nc) download via the [highlight.js repo](https://github.com/isagalaev/highlight.js/tree/master/src/styles)\n\n### Specifying a language\n\nSpecifying a language as per [highlight.js's usage docs][] is supported, with the caveat that you must use the `lang-*` or `language-*` prefix\n\n### Skip highlighting on a node\n\nAdd the `nohighlight` class as per [highlight.js's usage docs][]\n\n[highlight.js]: https://highlightjs.org/\n[highlight.js's usage docs]: https://highlightjs.org/usage/\n[npm]: https://www.npmjs.com/package/posthtml-highlight\n[npm-version-shield]: https://img.shields.io/npm/v/posthtml-highlight.svg\n[npm-stats]: http://npm-stat.com/charts.html?package=posthtml-highlight\u0026author=\u0026from=\u0026to=\n[npm-stats-shield]: https://img.shields.io/npm/dt/posthtml-highlight.svg?maxAge=2592000\n[typescript]: https://www.typescriptlang.org/\n[typescript-shield]: https://img.shields.io/badge/definitions-TypeScript-blue.svg\n[build-status]: https://github.com/posthtml/posthtml-highlight/actions/workflows/nodejs.yml\n[build-status-shield]: https://img.shields.io/github/workflow/status/posthtml/posthtml-highlight/Node%20CI/master\n[codecov]: https://codecov.io/gh/posthtml/posthtml-highlight\n[codecov-shield]: https://img.shields.io/codecov/c/github/posthtml/posthtml-highlight.svg\n[gitter]: https://gitter.im/posthtml/posthtml\n[gitter-shield]: https://badges.gitter.im/posthtml/posthtml.svg\n[wtfpl]: ./LICENSE.md\n[wtfpl-shield]: https://img.shields.io/npm/l/posthtml-highlight.svg\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-highlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-highlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-highlight/lists"}