Skip to content

Commit aed167d

Browse files
Merge pull request #44 from remarkablemark/react-16
Add `react-dom-core` to support react-dom@16
2 parents bb7e688 + d760c47 commit aed167d

File tree

7 files changed

+51
-45
lines changed

7 files changed

+51
-45
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com)
55
and this project adheres to [Semantic Versioning](http://semver.org).
66

7+
## [Unreleased](https://github.com/remarkablemark/html-react-parser/compare/v0.3.6...HEAD)
8+
### Added
9+
- [react-dom-core](https://github.com/remarkablemark/react-dom-core) to dependencies (closes #43)
10+
- `react-dom` 16 no longer exposes `lib`, which includes the DOM property configs
11+
- Upgrade devDependencies of `react` and `react-dom` to 16
12+
- Update README and examples
13+
714
## [0.3.6](https://github.com/remarkablemark/html-react-parser/compare/v0.3.5...v0.3.6) - 2017-09-30
815
### Changed
916
- Dependencies

README.md

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The parser converts an HTML string to [React Element(s)](https://facebook.github
1717

1818
There is also an option to [replace](#replacedomnode) element(s) with your own React Element(s) via the [parser options](#options).
1919

20-
#### Example
20+
## Example
2121

2222
```js
2323
var Parser = require('html-react-parser');
@@ -32,37 +32,36 @@ Parser('<p>Hello, world!</p>');
3232
[NPM](https://www.npmjs.com/package/html-react-parser):
3333

3434
```sh
35-
$ npm install html-react-parser
35+
npm install html-react-parser --save
3636
```
3737

38-
Or if you're using react <15.4:
38+
[Yarn](https://yarn.fyi/html-react-parser):
3939

4040
```sh
41-
$ npm install html-react-parser@0.2
41+
yarn add html-react-parser
4242
```
4343

4444
[CDN](https://unpkg.com/html-react-parser/):
4545

4646
```html
47-
<!-- HTMLReactParser depends on React and ReactDOM -->
48-
<script src="https://unpkg.com/react@latest/dist/react.min.js"></script>
49-
<script src="https://unpkg.com/react-dom@latest/dist/react-dom.min.js"></script>
47+
<!-- HTMLReactParser depends on React -->
48+
<script src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
5049
<script src="https://unpkg.com/html-react-parser@latest/dist/html-react-parser.min.js"></script>
5150
```
5251

53-
See more [examples](https://github.com/remarkablemark/html-react-parser/tree/master/examples).
52+
See [examples](https://github.com/remarkablemark/html-react-parser/tree/master/examples).
5453

5554
## Usage
5655

57-
Given that you have the following required:
56+
Given that you have the following imported:
5857

5958
```js
60-
// ES6
59+
// ES Modules
6160
import Parser from 'html-react-parser';
6261
import { render } from 'react-dom';
6362
```
6463

65-
You may render one element:
64+
You can render an element:
6665

6766
```js
6867
render(
@@ -71,7 +70,7 @@ render(
7170
);
7271
```
7372

74-
You may render adjacent elements:
73+
You can render multiple elements:
7574

7675
```js
7776
// with JSX
@@ -93,7 +92,7 @@ render(
9392
);
9493
```
9594

96-
You may render nested elements:
95+
You can render nested elements:
9796

9897
```js
9998
render(
@@ -117,7 +116,7 @@ render(
117116

118117
The `replace` method allows you to swap an element with your own React Element.
119118

120-
The first argument is `domNode`, which is an object that has the same output as [htmlparser2.parseDOM](https://github.com/fb55/domhandler#example).
119+
The first argument is `domNode`, which is an object that has the same output as [`htmlparser2.parseDOM`](https://github.com/fb55/domhandler#example).
121120

122121
The element is only replaced if a valid React Element is returned.
123122

@@ -137,7 +136,7 @@ Advanced example (keep the replaced children):
137136
```js
138137
// with ES6 and JSX
139138

140-
// converts dom object to React Elements
139+
// converts DOM object to React Elements
141140
import domToReact from 'html-react-parser/lib/dom-to-react';
142141

143142
const html = `
@@ -150,8 +149,7 @@ const html = `
150149
</div>
151150
`;
152151

153-
// parser config
154-
const options = {
152+
const parserOptions = {
155153
replace: (domNode) => {
156154
// do not replace if element has no attributes
157155
if (!domNode.attribs) return;
@@ -174,12 +172,12 @@ const options = {
174172
};
175173

176174
render(
177-
Parser(html, options),
175+
Parser(html, parserOptions),
178176
document.getElementById('root')
179177
);
180178
```
181179

182-
You will get the following:
180+
It will output the following:
183181

184182
```html
185183
<div>
@@ -200,8 +198,9 @@ $ npm run lint
200198

201199
## Special Thanks
202200

203-
- [html-dom-parser](https://github.com/remarkablemark/html-dom-parser)
204201
- [Contributors](https://github.com/remarkablemark/html-react-parser/graphs/contributors)
202+
- [html-dom-parser](https://github.com/remarkablemark/html-dom-parser)
203+
- [react-dom-core](https://github.com/remarkablemark/react-dom-core)
205204

206205
## License
207206

examples/requirejs.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
<div id="root"></div>
99

1010
<!-- Require.js -->
11-
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.min.js"></script>
11+
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script>
1212

1313
<script>
1414
requirejs.config({
1515
paths: {
1616
'html-react-parser': '../dist/html-react-parser.min',
17-
'react': 'https://unpkg.com/react@latest/dist/react.min',
18-
'react-dom': 'https://unpkg.com/react-dom@latest/dist/react-dom.min'
17+
'react': 'https://unpkg.com/react@16/umd/react.production.min',
18+
'react-dom': 'https://unpkg.com/react-dom@16/umd/react-dom.production.min'
1919
}
2020
});
2121

examples/script-tag.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
<body style="padding: 50px">
88
<div id="root"></div>
99

10-
<!-- HTMLReactParser depends on React and ReactDOM -->
11-
<script src="https://unpkg.com/react@latest/dist/react.min.js"></script>
12-
<script src="https://unpkg.com/react-dom@latest/dist/react-dom.min.js"></script>
10+
<!-- HTMLReactParser depends on React -->
11+
<script src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
1312
<script src="../dist/html-react-parser.min.js"></script>
1413

14+
<!-- ReactDOM -->
15+
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
16+
1517
<script>
1618
ReactDOM.render(
1719
HTMLReactParser(

lib/property-config.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
var utilities = require('./utilities');
77

88
// HTML and SVG DOM Property Configs
9-
var HTMLDOMPropertyConfig = require('react-dom/lib/HTMLDOMPropertyConfig');
10-
var SVGDOMPropertyConfig = require('react-dom/lib/SVGDOMPropertyConfig');
9+
var HTMLDOMPropertyConfig = require('react-dom-core/lib/HTMLDOMPropertyConfig');
10+
var SVGDOMPropertyConfig = require('react-dom-core/lib/SVGDOMPropertyConfig');
1111

1212
var config = {
1313
html: {},
@@ -18,44 +18,42 @@ var propertyName;
1818

1919
/**
2020
* HTML DOM property config.
21+
* https://github.com/facebook/react/blob/master/src/renderers/dom/shared/HTMLDOMPropertyConfig.js
2122
*/
2223

23-
// first map out the HTML DOM attribute names
24+
// first map out the HTML attribute names
2425
// e.g., { className: 'class' } => { 'class': 'className' }
25-
// https://github.com/facebook/react/blob/master/src/renderers/dom/shared/HTMLDOMPropertyConfig.js#L204
2626
config.html = utilities.invertObject(
2727
HTMLDOMPropertyConfig.DOMAttributeNames
2828
);
2929

30-
// then map out the rest of the HTML DOM properties
31-
// e.g., { charSet: 0 } => { charset: 'charSet' }
32-
// https://github.com/facebook/react/blob/master/src/renderers/dom/shared/HTMLDOMPropertyConfig.js#L28
30+
// then map out the rest of the HTML properties
31+
// e.g., { readOnly: 0 } => { readonly: 'readOnly' }
3332
for (propertyName in HTMLDOMPropertyConfig.Properties) {
3433
// lowercase to make matching property names easier
3534
config.html[propertyName.toLowerCase()] = propertyName;
3635
}
3736

3837
/**
3938
* SVG DOM property config.
39+
* https://github.com/facebook/react/blob/master/src/renderers/dom/shared/SVGDOMPropertyConfig.js
4040
*/
4141

42-
// first map out the SVG DOM attribute names
42+
// first map out the SVG attribute names
4343
// e.g., { fontSize: 'font-size' } => { 'font-size': 'fontSize' }
44-
// https://github.com/facebook/react/blob/master/src/renderers/dom/shared/SVGDOMPropertyConfig.js#L36
4544
config.svg = utilities.invertObject(
4645
SVGDOMPropertyConfig.DOMAttributeNames
4746
);
4847

49-
// then map out the rest of the SVG DOM properties
50-
// e.g., { preserveAlpha: 0 } => { preserveAlpha: 'preserveAlpha' }
51-
// https://github.com/facebook/react/blob/master/src/renderers/dom/shared/HTMLDOMPropertyConfig.js#L28
48+
// then map out the rest of the SVG properties
49+
// e.g., { fillRule: 0 } => { fillRule: 'fillRule' }
5250
for (propertyName in SVGDOMPropertyConfig.Properties) {
5351
// do not lowercase as some svg properties are camel cased
5452
config.html[propertyName] = propertyName;
5553
}
5654

5755
/**
58-
* Export React property configs.
56+
* Export property configs.
5957
*/
6058
module.exports = {
6159
config: config,

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@
2929
"converter"
3030
],
3131
"dependencies": {
32-
"html-dom-parser": "0.1.2"
32+
"html-dom-parser": "0.1.2",
33+
"react-dom-core": "0.0.2"
3334
},
3435
"devDependencies": {
3536
"coveralls": "^2.13.1",
3637
"eslint": "^4.1.1",
3738
"istanbul": "^0.4.5",
3839
"mocha": "^3.4.2",
39-
"react": "^15.4",
40-
"react-dom": "^15.4",
40+
"react": "^16",
41+
"react-dom": "^16",
4142
"webpack": "^3.0.0"
4243
},
4344
"peerDependencies": {
44-
"react": "^15.4",
45-
"react-dom": "^15.4"
45+
"react": "^0.14 || ^15 || ^16"
4646
},
4747
"license": "MIT"
4848
}

test/helpers/mocks.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"multiple": "<p>foo</p><p>bar</p>",
55
"nested": "<div><p>foo <em>bar</em></p></div>",
66
"attributes": "<hr id=\"foo\" class=\"bar baz\" style=\"background: #fff; text-align: center;\" data-foo=\"bar\" />",
7-
"complex": "<html><head><meta charset=\"utf-8\"/><title>Title</title><link rel=\"stylesheet\" href=\"style.css\"/></head><body><header id=\"header\">Header</header><h1 style=\"color:#000;font-size:42px;\">Heading</h1><hr/><p>Paragraph</p><img src=\"image.jpg\"/><div class=\"class1 class2\">Some <em>text</em>.</div><script>alert();</script></body></html>",
7+
"complex": "<html><head><meta charSet=\"utf-8\"/><title>Title</title><link rel=\"stylesheet\" href=\"style.css\"/></head><body><header id=\"header\">Header</header><h1 style=\"color:#000;font-size:42px\">Heading</h1><hr/><p>Paragraph</p><img src=\"image.jpg\"/><div class=\"class1 class2\">Some <em>text</em>.</div><script>alert();</script></body></html>",
88
"textarea": "<textarea>foo</textarea>",
99
"script": "<script>alert(1 < 2);</script>",
1010
"style": "<style>body > .foo { color: #f00; }</style>",

0 commit comments

Comments
 (0)