Skip to content

Commit 60d5359

Browse files
authored
Merge pull request meliorence#101 from archriss/dev
v3.9.0
2 parents bb8fbfa + 72468b8 commit 60d5359

File tree

8 files changed

+25
-14
lines changed

8 files changed

+25
-14
lines changed

Demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"react": "16.2.0",
1111
"react-native": "0.52.0",
12-
"react-native-render-html": "3.8.1"
12+
"react-native-render-html": "3.9.0"
1313
},
1414
"devDependencies": {
1515
"babel-jest": "22.0.6",

Demo/src/HTMLDemo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export default class Demo extends Component {
2424
this.setCurrentExample = this.setCurrentExample.bind(this);
2525
}
2626

27-
onLinkPress (evt, href) {
28-
alert(`Opened ${href} !`);
27+
onLinkPress (evt, href, htmlAttribs) {
28+
alert(`Opened ${href} ! Attributes: ${JSON.stringify(htmlAttribs)}`);
2929
}
3030

3131
setCurrentExample (currentExample) {

Demo/src/snippets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const paragraphs = `
99
<p style="padding:10%;">This one features a padding <strong>in percentage !</strong></p>
1010
<hr />
1111
<i>Here, we have a style set on the "i" tag with the "tagsStyles" prop.</i>
12-
<p>And <a href="http://google.fr">This is a link !</a></p>
12+
<p>And <a href="http://google.fr" title="Google FR">This is a link !</a></p>
1313
<a href="http://google.fr"><div style="background-color: red; height: 20px; width:40px;"></div></a>
1414
<p class="last-paragraph">Finally, this paragraph is styled through the classesStyles prop</p>
1515
`;

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ An iOS/Android pure javascript react-native component that renders your HTML int
44

55
> Based on the original work of [Thomas Beverley](https://github.com/Thomas101), props to him.
66
7+
![platforms](https://img.shields.io/badge/platforms-Android%20%7C%20iOS-brightgreen.svg?style=flat-square&colorB=191A17)
8+
[![npm](https://img.shields.io/npm/v/react-native-render-html.svg?style=flat-square)](https://www.npmjs.com/package/react-native-render-html)
9+
[![npm](https://img.shields.io/npm/dm/react-native-render-html.svg?style=flat-square&colorB=007ec6)](https://www.npmjs.com/package/react-native-render-html)
10+
<!-- [![github release](https://img.shields.io/github/release/archriss/react-native-render-html.svg?style=flat-square)](https://github.com/archriss/react-native-render-html/releases) -->
11+
[![github issues](https://img.shields.io/github/issues/archriss/react-native-render-html.svg?style=flat-square)](https://github.com/archriss/react-native-render-html/issues)
12+
[![github closed issues](https://img.shields.io/github/issues-closed/archriss/react-native-render-html.svg?style=flat-square&colorB=44cc11)](https://github.com/archriss/react-native-render-html/issues?q=is%3Aissue+is%3Aclosed)
13+
714
![react-native-render-html](http://i.giphy.com/26tkmjBLvThP0TSak.gif)
815

916
## Table of contents
@@ -66,8 +73,9 @@ Prop | Description | Type | Required/Default
6673
`uri` | *(experimental)* remote website to parse and render | `string` | Optional
6774
`decodeEntities` | Decode HTML entities of your content | `bool` | Optional, defaults to `true`
6875
`imagesMaxWidth` | Resize your images to this maximum width, see [images](#images) | `number` | Optional
76+
`staticContentMaxWidth` | Set a maximum width to non-responsive content (`<iframe> for instance`) | `number` | Optional
6977
`imagesInitialDimensions` | Default width and height to display while image's dimensions are being retrieved, see [images](#images) | `{ width: 100, height: 100 }` | Optional
70-
`onLinkPress` | Fired with the event and the href as its arguments when tapping a link | `function` | Optional
78+
`onLinkPress` | Fired with the event, the href and an object with all attributes of the tag as its arguments when tapping a link | `function` | Optional
7179
`onParsed` | Fired when your HTML content has been parsed. Also useful to tweak your rendering, see [onParsed](#onparsed) | `function` | Optional
7280
`tagsStyles` | Provide your styles for specific HTML tags, see [styling](#styling) | `object` | Optional
7381
`classesStyles` | Provide your styles for specific HTML classes, see [styling](#styling) | `object` | Optional
@@ -83,6 +91,7 @@ Prop | Description | Type | Required/Default
8391
`alterChildren` | Target some specific nested children and change them, see [altering content](#altering-content) | `function` | Optional
8492
`alterNode` | Target a specific node and change it, see [altering content](#altering-content) | `function` | Optional
8593
`ignoredTags` | HTML tags you don't want rendered, see [ignoring HTML content](#ignoring-html-content) | `array` | Optional, `['head', 'scripts', ...]`
94+
`allowedStyles`| Allow render only certain CSS style properties and ignore every other. If you have some property both in `allowedStyles` and `ignoredStyles`, it will be ignored anyway. | `array` | Optional, everything is allowed by default
8695
`ignoredStyles` | CSS styles from the `style` attribute you don't want rendered, see [ignoring HTML content](#ignoring-html-content) | `array` | Optional
8796
`ignoreNodesFunction` | Return true in this custom function to ignore nodes very precisely, see [ignoring HTML content](#ignoring-html-content) | `function` | Optional
8897
`debug` | Prints the parsing result from htmlparser2 and render-html after the initial render | `bool` | Optional, defaults to `false`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-render-html",
3-
"version": "3.8.1",
3+
"version": "3.9.0",
44
"author": "Archriss",
55
"license": "BSD-2-Clause",
66
"repository": "https://github.com/archriss/react-native-render-html",

src/HTML.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class HTML extends PureComponent {
1212
renderers: PropTypes.object.isRequired,
1313
ignoredTags: PropTypes.array.isRequired,
1414
ignoredStyles: PropTypes.array.isRequired,
15+
allowedStyles: PropTypes.array,
1516
decodeEntities: PropTypes.bool.isRequired,
1617
debug: PropTypes.bool.isRequired,
1718
listsPrefixesRenderers: PropTypes.object,
@@ -28,6 +29,7 @@ export default class HTML extends PureComponent {
2829
onLinkPress: PropTypes.func,
2930
onParsed: PropTypes.func,
3031
imagesMaxWidth: PropTypes.number,
32+
staticContentMaxWidth: PropTypes.number,
3133
imagesInitialDimensions: PropTypes.shape({
3234
width: PropTypes.number,
3335
height: PropTypes.number
@@ -393,7 +395,7 @@ export default class HTML extends PureComponent {
393395
* @memberof HTML
394396
*/
395397
renderRNElements (RNElements, parentWrapper = 'root', parentIndex = 0, props = this.props) {
396-
const { tagsStyles, classesStyles, emSize, ignoredStyles } = props;
398+
const { tagsStyles, classesStyles, emSize, ignoredStyles, allowedStyles } = props;
397399
return RNElements && RNElements.length ? RNElements.map((element, index) => {
398400
const { attribs, data, tagName, parentTag, children, nodeIndex, wrapper } = element;
399401
const Wrapper = wrapper === 'Text' ? Text : View;
@@ -403,7 +405,7 @@ export default class HTML extends PureComponent {
403405
cssStringToRNStyle(
404406
attribs.style,
405407
Wrapper === Text ? STYLESETS.TEXT : STYLESETS.VIEW, // proper prop-types validation
406-
{ parentTag: tagName, emSize, ignoredStyles }
408+
{ parentTag: tagName, emSize, ignoredStyles, allowedStyles }
407409
) :
408410
{};
409411

src/HTMLRenderers.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export function a (htmlAttribs, children, convertedCSSStyles, passProps) {
1414
// the passed props might be altered by it !!
1515
const { parentWrapper, onLinkPress, key, data } = passProps;
1616
const onPress = (evt) => onLinkPress && htmlAttribs && htmlAttribs.href ?
17-
onLinkPress(evt, htmlAttribs.href) :
17+
onLinkPress(evt, htmlAttribs.href, htmlAttribs) :
1818
undefined;
1919

2020
if (parentWrapper === 'Text') {
@@ -116,8 +116,7 @@ export function iframe (htmlAttribs, children, convertedCSSStyles, passProps) {
116116
if (!htmlAttribs.src) {
117117
return false;
118118
}
119-
120-
const viewportWidth = Dimensions.get('window').width;
119+
const { staticContentMaxWidth } = passProps;
121120
const style = _constructStyles({
122121
tagName: 'iframe',
123122
htmlAttribs,
@@ -130,9 +129,9 @@ export function iframe (htmlAttribs, children, convertedCSSStyles, passProps) {
130129
undefined
131130
},
132131
{
133-
width: htmlAttribs.width && htmlAttribs.width <= viewportWidth ?
132+
width: staticContentMaxWidth && htmlAttribs.width && htmlAttribs.width <= staticContentMaxWidth ?
134133
parseInt(htmlAttribs.width, 10) :
135-
viewportWidth
134+
staticContentMaxWidth
136135
}
137136
]
138137
});

src/HTMLStyles.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ export function _getElementCSSClasses (htmlAttribs) {
101101
* @param {object} { parentTag, emSize, ignoredStyles }
102102
* @returns {object}
103103
*/
104-
function cssToRNStyle (css, styleset, { parentTag, emSize, ignoredStyles }) {
104+
function cssToRNStyle (css, styleset, { parentTag, emSize, ignoredStyles, allowedStyles }) {
105105
const styleProps = stylePropTypes[styleset];
106106
return Object.keys(css)
107+
.filter((key) => allowedStyles ? allowedStyles.indexOf(key) !== -1 : true)
107108
.filter((key) => (ignoredStyles || []).indexOf(key) === -1)
108109
.map((key) => [key, css[key]])
109110
.map(([key, value]) => {

0 commit comments

Comments
 (0)