{"id":18563211,"url":"https://github.com/compulim/react-sanitized-html","last_synced_at":"2025-04-10T03:32:39.653Z","repository":{"id":18402722,"uuid":"84204949","full_name":"compulim/react-sanitized-html","owner":"compulim","description":"A React component that will sanitize user-inputted HTML code, using the popular sanitize-html package","archived":false,"fork":false,"pushed_at":"2023-01-03T19:48:50.000Z","size":892,"stargazers_count":19,"open_issues_count":24,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-14T19:22:57.561Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/compulim.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}},"created_at":"2017-03-07T13:55:01.000Z","updated_at":"2022-09-14T03:04:17.000Z","dependencies_parsed_at":"2023-01-13T19:48:49.129Z","dependency_job_id":null,"html_url":"https://github.com/compulim/react-sanitized-html","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Freact-sanitized-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Freact-sanitized-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Freact-sanitized-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/compulim%2Freact-sanitized-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/compulim","download_url":"https://codeload.github.com/compulim/react-sanitized-html/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248151399,"owners_count":21056087,"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-06T22:12:04.972Z","updated_at":"2025-04-10T03:32:39.280Z","avatar_url":"https://github.com/compulim.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-sanitized-html\n\n[![npm version](https://badge.fury.io/js/react-sanitized-html.svg)](https://npmjs.com/package/react-sanitized-html) [![Build Status](https://travis-ci.org/compulim/react-sanitized-html.svg?branch=master)](https://travis-ci.org/compulim/react-sanitized-html) [![Node.js dependencies](https://david-dm.org/compulim/react-sanitized-html.svg)](https://david-dm.org/compulim/react-sanitized-html) [![npm downloads](https://img.shields.io/npm/dm/react-sanitized-html.svg)](https://npmjs.com/package/react-sanitized-html)\n\nA React component that will sanitize user-inputted HTML code, using the popular [`sanitize-html`](https://npmjs.com/package/sanitize-html) package.\n\n# Install\n\nThis React component requires both [`react`](https://npmjs.com/package/react) and [`sanitize-html`](https://npmjs.com/package/sanitize-html) to be installed to work. We marked both as peer dependency so you could use the version of React as it fit.\n\nRun `npm install react-sanitized-html sanitize-html --save` to install this package.\n\n\u003e Because both [`htmlparser2`](https://npmjs.com/packages/htmlparser2) and [`domhandler`](https://npmjs.com/packages/domhandler) (dependencies of [`sanitize-html`](https://npmjs.com/packages/sanitize-html)) requires [ES2015 Property Accessors](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors) for shorthanded properties. Thus, this component cannot be used in IE8.\n\n\u003e In [`sanitize-html@1.14.1`](https://npmjs.com/packages/sanitize-html), shorthands are not used. Thus, it is possible to build a workaround for IE8 by customizing both [`htmlparser2`] and [`domhandler`] without shorthands.\n\n# Example usage\n\n```jsx\nimport SanitizedHTML from 'react-sanitized-html';\n\nconst HTML_FROM_USER = '\u003ca href=\"http://bing.com/\"\u003eBing\u003c/a\u003e';\n\nReactDOM.render(\n  \u003cSanitizedHTML html={ HTML_FROM_USER } /\u003e,\n  document.getElementById('reactRoot')\n);\n```\n\nIt will output as:\n\n```html\n\u003cdiv\u003e\n  \u003ca href=\"http://bing.com/\"\u003eBing\u003c/a\u003e\n\u003c/div\u003e\n```\n\n# Options\n\nYou can add [`sanitize-html`](https://npmjs.com/package/sanitize-html) options as props. For example,\n\n```html\n\u003cSanitizedHTML\n  allowedAttributes={{ 'a': ['href'] }}\n  allowedTags={['a']}\n  html={ `\u003ca href=\"http://bing.com/\"\u003eBing\u003c/a\u003e` }\n/\u003e\n```\n\nYou can find more options [here](https://npmjs.com/package/sanitize-html).\n\n# Development\n\nTo setup your development environment, after cloning the repository, run the following steps.\n\n```\nnpm install react sanitize-html\nnpm install --only=development\n```\n\nThen run `npm test` to run all tests.\n\n# Contribution\n\nLike us? [Star](https://github.com/compulim/react-sanitized-html/stargazers) us.\n\nFound an issue? [File](https://github.com/compulim/react-sanitized-html/issues) us an issue.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompulim%2Freact-sanitized-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcompulim%2Freact-sanitized-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcompulim%2Freact-sanitized-html/lists"}