{"id":19028668,"url":"https://github.com/researchgate/react-fast-highlight","last_synced_at":"2025-04-15T21:23:36.582Z","repository":{"id":41551104,"uuid":"49300568","full_name":"researchgate/react-fast-highlight","owner":"researchgate","description":"A fast react component wrapper for highlight.js","archived":false,"fork":false,"pushed_at":"2023-07-18T20:17:22.000Z","size":3807,"stargazers_count":40,"open_issues_count":15,"forks_count":6,"subscribers_count":10,"default_branch":"main","last_synced_at":"2024-10-30T04:55:53.284Z","etag":null,"topics":["highlightjs","react"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/researchgate.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"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}},"created_at":"2016-01-08T22:37:52.000Z","updated_at":"2024-05-04T03:37:14.000Z","dependencies_parsed_at":"2024-06-18T18:36:29.608Z","dependency_job_id":null,"html_url":"https://github.com/researchgate/react-fast-highlight","commit_stats":{"total_commits":547,"total_committers":13,"mean_commits":42.07692307692308,"dds":"0.44789762340036565","last_synced_commit":"1e99ce8bbb60b2a3d086962bdc693cf4bfed1f86"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/researchgate%2Freact-fast-highlight","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/researchgate%2Freact-fast-highlight/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/researchgate%2Freact-fast-highlight/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/researchgate%2Freact-fast-highlight/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/researchgate","download_url":"https://codeload.github.com/researchgate/react-fast-highlight/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249155167,"owners_count":21221552,"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":["highlightjs","react"],"created_at":"2024-11-08T21:12:00.098Z","updated_at":"2025-04-15T21:23:36.560Z","avatar_url":"https://github.com/researchgate.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-fast-highlight\n\n###### A fast react component wrapper for highlight.js\n\n[![codecov](https://codecov.io/gh/researchgate/react-fast-highlight/branch/master/graph/badge.svg)](https://codecov.io/gh/researchgate/react-fast-highlight)\n\n## Requirements\n\n- Requires `react` version 16\n- Requires `highlight.js` version 9 or 10\n\n## Install\n\n`npm install --save react-fast-highlight react highlight.js`\n\nor\n\n`yarn add react-fast-highlight react highlight.js`\n\n## Usage\n\n```js\nimport React, { Component } from 'react';\nimport { Highlight } from 'react-fast-highlight';\n\nclass App extends Component {\n\n  render() {\n    const code = 'let t = 0.5 * 5 * 4;';\n\n    return (\n      {/*\n            `languages` is an optional property to set the languages that highlight.js should pick from.\n            By default it is empty, which means highlight.js will pick from all available languages.\n            If only one language is provided, this language will be used without doing checks beforehand.\n            (Be aware that automatic language detection is not as fast as when specifing a language.)\n\n            `worker` is used to take advantage of the possibility to do the highlighting work in a\n            web-worker. As different module-bundlers use different ways to load web-workers, it is up\n            to you to load the webworker and supply it to the highlight component. (see example)\n            Currently every instance of the highlight component needs its own web-worker.\n\n            `className` sets additional class names on the generated html markup.\n       */}\n      \u003cHighlight\n        languages={['js']}\n        className=\"my-class\"\n      \u003e\n        {code}\n      \u003c/Highlight\u003e\n    );\n}\n```\n\n### Advanced Usage\n\n#### Custom highlight.js distribution\n\nIn cases where you bundle this component with a module bundler such as webpack,\nrollup or browserify and you know upfront which languages you want to support\nyou can supply a custom distribution of `highlight.js`. This ensures you are not\nbundling all available languages of `highlight.js` which reduces the size of\nyour bundle.\n\nA custom distribution might look like this\n\n```js\nimport hljs from 'highlight.js/lib/highlight';\n\n// Lets only register javascript, scss, html/xml\nhljs.registerLanguage('scss', require('highlight.js/lib/languages/scss'));\nhljs.registerLanguage(\n  'javascript',\n  require('highlight.js/lib/languages/javascript')\n);\nhljs.registerLanguage('xml', require('highlight.js/lib/languages/xml'));\n\nexport default hljs;\n```\n\nTo actually use a custom distribution you need to use the `BareHighlight`\ncomponent. With it you can build your wrapper for highlighting code.\n\n```js\nimport React, { Component } from 'react';\nimport BareHighlight from 'react-fast-highlight/lib/js/BareHighlight';\nimport hljs from './customhljs';\n\nclass CustomHighlight extends Component {\n  render() {\n    const { children, ...props } = this.props;\n    return (\n      \u003cBareHighlight {...props} highlightjs={hljs}\u003e\n        {children}\n      \u003c/BareHighlight\u003e\n    );\n}\n```\n\nNow you can use this wrapper the same way as the default `Highlight` component\nwith only support for certain languages included.\n\n\u003e In case you also want to use a webworker you should not use the supplied\n\u003e worker, as it includes all languages. Instead you will need to copy the worker\n\u003e from this repo and adjust the `highlight.js` import.\n\n#### Webworker\n\nIt wasn't tested with browserify and rollup but it should work. If you managed\nto get it working please open a PR with the necessary changes and the\ndocumentation.\n\n##### Webpack\n\nTo make web-workers working with webpack you additionally need to install\n`worker-loader`.\n\n`npm install --save worker-loader react-fast-highlight`\n\n```js\nimport React from 'react';\nimport { Highlight } from 'react-fast-highlight';\nimport Worker from 'worker!react-fast-highlight/lib/js/worker';\n\nclass App extends React.Component {\n\n  render() {\n    const code = 'let t = 0.5 * 5 * 4;';\n\n    return (\n      \u003cHighlight\n        languages={['js']}\n        worker={new Worker}\n      \u003e\n        {code}\n      \u003c/Highlight\u003e\n    );\n}\n```\n\n## License\n\nreact-fast-highlight is licensed under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresearchgate%2Freact-fast-highlight","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fresearchgate%2Freact-fast-highlight","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresearchgate%2Freact-fast-highlight/lists"}