{"name":"react-html-parser","version":"1.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: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.3.26","babel-cli":"^6.4.0","babel-core":"^6.4.0","babel-loader":"^6.2.1","babel-plugin-transform-object-assign":"^6.3.13","babel-preset-es2015":"^6.3.13","babel-preset-react":"^6.3.13","coveralls":"^2.11.6","eslint":"^1.10.3","eslint-plugin-react":"3.15.0","html-webpack-plugin":"^1.7.0","inject-loader":"2.0.1","isparta-loader":"^2.0.0","jasmine-core":"^2.4.1","json-loader":"^0.5.4","karma":"^0.13.19","karma-coverage":"^0.5.3","karma-jasmine":"^0.3.6","karma-phantomjs-launcher":"^0.2.3","karma-phantomjs-shim":"^1.2.0","karma-spec-reporter":"0.0.23","karma-webpack":"^1.7.0","phantomjs":"^1.9.19","react":"^0.14.6","react-addons-test-utils":"^0.14.6","react-dom":"^0.14.6","rimraf":"^2.5.0","webpack":"^1.12.11","webpack-dev-server":"^1.14.1"},"dependencies":{"htmlparser2":"^3.9.0"},"peerDependencies":{"react":"^0.13.0 || ^0.14.0"},"gitHead":"86d876c33880bdf54c03d84948d7d36539f5b3ed","bugs":{"url":"https://github.com/wrakky/react-html-parser/issues"},"homepage":"https://github.com/wrakky/react-html-parser#readme","_id":"react-html-parser@1.0.2","_shasum":"7b0992e49087af81db647ed9184ed4d23ade212d","_from":".","_npmVersion":"3.5.3","_nodeVersion":"4.1.1","_npmUser":{"name":"wrakky","email":"pete@blarg.co.uk"},"dist":{"shasum":"7b0992e49087af81db647ed9184ed4d23ade212d","tarball":"http://registry-npm.ywwl.com/react-html-parser/download/react-html-parser-1.0.2.tgz","integrity":"sha512-cxalRahPd5ht5b6s5yq+zl3rQqf6Sq2XxRVu/rHa5UedDX+afLKoSQfINqvz2iDoRBE3FDNyV0fiqyL+2ac64g==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIG+E0WMrsVeLidPXlGglUlVeJmcXStN4Sk91EK2ePSovAiEAu3z81fzpJsWvjGi8VgcSLm0JC7ZO4uhO3FRASnK4Mdo="}],"size":514527,"noattachment":false,"key":"/react-html-parser/-/react-html-parser-1.0.2.tgz"},"maintainers":[{"name":"wrakky","email":"pete@blarg.co.uk"}],"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":1454111629865,"_cnpm_publish_time":1454111629865,"dist-tags":{"latest":"2.0.2"}}