{"name":"react-html-parser","version":"2.0.2","description":"Parse HTML into React components","main":"lib/index.js","jsnext:main":"src/index.js","scripts":{"clean":"rimraf coverage dist lib","check":"npm run lint && npm run test","test":"karma start --single-run","test:watch":"karma start","lint":"eslint src test demo/src","build":"npm run build:lib && npm run build:umd && npm run build:umd:min","build:lib":"rimraf lib && babel ./src -d lib","build:umd":"webpack src/index.js dist/react-html-parser.js --config webpack.config.development.js","build:umd:min":"webpack src/index.js -p dist/react-html-parser.min.js --config webpack.config.production.js","prerelease":"npm run clean && npm run check","release":"npm run build","postrelease":"git push --follow-tags && npm publish","release:patch":"npm version patch && npm run release","release:minor":"npm version minor && npm run release","release:major":"npm version major && npm run release","demo:clean":"rimraf demo/dist","demo:dev":"cd demo && node ./server.js","demo:build":"cd demo && npm run build","demo:push":"cd demo/dist && git init && git commit --allow-empty -m 'update demo' && git checkout -b gh-pages && git add . && git commit -am 'update demo' && git push git@github.com:wrakky/react-html-parser gh-pages --force","demo:publish":"npm run demo:clean && npm run demo:build && npm run demo:push"},"repository":{"type":"git","url":"git+https://github.com/wrakky/react-html-parser.git"},"keywords":["react","html","htmlparser","htmlparser2","inner html","dangerouslySetInnerHTML"],"author":{"name":"Peter Newnham"},"license":"MIT","devDependencies":{"babel":"^6.5.2","babel-cli":"^6.8.0","babel-core":"^6.8.0","babel-loader":"^6.2.4","babel-plugin-transform-object-assign":"^6.8.0","babel-plugin-transform-object-rest-spread":"^6.23.0","babel-preset-es2015":"^6.6.0","babel-preset-react":"^6.5.0","coveralls":"^2.11.9","eslint":"^2.10.1","eslint-plugin-react":"^5.1.1","inject-loader":"^2.0.1","isparta-loader":"^2.0.0","jasmine-core":"^2.4.1","json-loader":"^0.5.4","karma":"^0.13.22","karma-coverage":"^1.0.0","karma-es6-shim":"^1.0.0","karma-jasmine":"^1.0.2","karma-phantomjs-launcher":"^1.0.0","karma-phantomjs-shim":"^1.4.0","karma-spec-reporter":"^0.0.26","karma-webpack":"^1.7.0","phantomjs-prebuilt":"^2.1.7","react":"^16.0.0","react-dom":"^16.0.0","rimraf":"^2.5.2","webpack":"^1.13.0"},"dependencies":{"htmlparser2":"^3.9.0"},"peerDependencies":{"react":"^0.14.0 || ^15.0.0 || ^16.0.0-0"},"gitHead":"f28597ee0d010d4142d0077c911868de69535efd","bugs":{"url":"https://github.com/wrakky/react-html-parser/issues"},"homepage":"https://github.com/wrakky/react-html-parser#readme","_id":"react-html-parser@2.0.2","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"wrakky","email":"pete@blarg.co.uk"},"dist":{"integrity":"sha512-XeerLwCVjTs3njZcgCOeDUqLgNIt/t+6Jgi5/qPsO/krUWl76kWKXMeVs2LhY2gwM6X378DkhLjur0zUQdpz0g==","shasum":"6dbe1ddd2cebc1b34ca15215158021db5fc5685e","tarball":"http://registry-npm.ywwl.com/react-html-parser/download/react-html-parser-2.0.2.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCFyNM8M2yoCFs9Ycna7U5WwgxFZyvi6XhIA+mQOdf+0wIhALupxXO43xmlo5+glsG4MEXouKHrYr8OIL117ZcMighk"}],"size":618462,"noattachment":false,"key":"/react-html-parser/-/react-html-parser-2.0.2.tgz"},"maintainers":[{"name":"wrakky","email":"pete@blarg.co.uk"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/react-html-parser-2.0.2.tgz_1511999682520_0.9959713721182197"},"directories":{},"readme":"# React HTML Parser\n\nA utility for converting HTML strings into [React](https://facebook.github.io/react/) components. Avoids the use of dangerouslySetInnerHTML and converts standard HTML elements, attributes and inline styles into their React equivalents.\n\n[Try the Live Demo](https://wrakky.github.io/react-html-parser)\n\n[![Travis branch](https://img.shields.io/travis/wrakky/react-html-parser/master.svg)](https://travis-ci.org/wrakky/react-html-parser)\n[![Coveralls](https://img.shields.io/coveralls/wrakky/react-html-parser.svg)](https://coveralls.io/github/wrakky/react-html-parser)\n[![npm](https://img.shields.io/npm/v/react-html-parser.svg)](https://www.npmjs.com/package/react-html-parser)\n[![Downloads](https://img.shields.io/npm/dw/react-html-parser.svg)](https://www.npmjs.com/package/react-html-parser)\n[![David](https://img.shields.io/david/wrakky/react-html-parser.svg)](https://david-dm.org/wrakky/react-html-parser)\n\n## Install\n\n```bash\nnpm install react-html-parser\n# or\nyarn add react-html-parser\n```\n\n## Usage\n\n```javascript\nimport React from 'react';\nimport ReactHtmlParser, { processNodes, convertNodeToElement, htmlparser2 } from 'react-html-parser';\n\nclass HtmlComponent extends React.Component {\n  render() {\n    const html = '<div>Example HTML string</div>';\n    return <div>{ ReactHtmlParser(html) }</div>;\n  }\n}\n```\n\n## API\n\n### `function ReactHtmlParser(html, [options])`\nTakes an HTML string and returns equivalent React elements\n\n#### Usage\n```js\nimport ReactHtmlParser from 'react-html-parser';\n```\n#### Arguments\n- `html`: The HTML string to parse\n- `options`: Options object\n  - decodeEntities=true *(boolean)*: Whether to decode html entities (defaults to true)\n  - transform *(function)*: Transform function that is applied to every node\n  - preprocessNodes *(function)*: Pre-process the nodes generated by `htmlparser2`\n\n#### Transform Function\nThe transform function will be called for every node that is parsed by the library.\n\n`function transform(node, index)`\n##### Arguments\n- `node`: The node being parsed. This is the [htmlparser2](https://github.com/fb55/htmlparser2) node object. Full details can be found on their project page but important properties are:\n  - `type` (string): The type of node *(tag, text, style etc)*\n  - `name` (string): The name of the node\n  - `children` (array): Array of children nodes\n  - `next` (node): The node's next sibling\n  - `prev` (node): The node's previous sibling\n  - `parent` (node): The node's parent\n  - `data` (string): The text content, if the `type` is text\n- `index` (number): The index of the node in relation to it's parent\n\n#### Return Types\n`return null`\nReturning null will prevent the node and all of it's children from being rendered.\n```js\nfunction transform(node) {\n  // do not render any <span> tags\n  if (node.type === 'tag' && node.name === 'span') {\n    return null;\n  }\n}\n```\n`return undefined`\nIf the function does not return anything, or returns undefined, then the default behaviour will occur and the parser will continue was usual.\n\n`return React element`\nReact elements can be returned directly\n```js\nimport React from 'react';\nfunction transform(node) {\n  if (node.type === 'tag' && node.name === 'b') {\n    return <div>This was a bold tag</div>;\n  }\n}\n```\n\n#### preprocessNodes Function\nAllows pre-processing the nodes generated from the html by `htmlparser2` before being passed to the library and converted to React elements.\n\n`function preprocessNodes(nodes)`\n##### Arguments\n- `nodes`: The entire node tree generated by `htmlparser2`.\n\n##### Return type\nThe `preprocessNodes` function should return a valid `htmlparser2` node tree.\n\n### `function convertNodeToElement(node, index, transform)`\nProcesses a node and returns the React element to be rendered. This function can be used in conjunction with the previously described `transform` function to continue to process a node after modifying it.\n\n#### Usage\n```js\nimport { convertNodeToElement } from 'react-html-parser';\n```\n#### Arguments\n- `node`: The node to process\n- `index` (number): The index of the node in relation to it's parent\n- `transform`: The transform function as described above\n\n```js\nimport { convertNodeToElement } from 'react-html-parser';\nfunction transform(node, index) {\n  // convert <ul> to <ol>\n  if (node.type === 'tag' && node.name === 'ul') {\n    node.name = 'ol';\n    return convertNodeToElement(node, index, transform);\n  }\n}\n```\n\n### `htmlparser2`\nThe library exposes the `htmlparser2` library it uses. This allows consumers\nto use it without having to add it as a separate dependency.\n\nSee https://github.com/fb55/htmlparser2 for full details.\n","publish_time":1511999684178,"_cnpm_publish_time":1511999684178,"dist-tags":{"latest":"2.0.2"}}