Code Monkey home page Code Monkey logo

react-native-html-render's Introduction

react-native-html-render

A html render for react-native. But don't Suitable for all html. Only Suitable for the html generator by markdown with minify.

Now it used by Noder.

Be careful to use, the performance is not good. If you want to improve the performance, be free to open a issue or send a PR.

Install

npm install react-native-html-render

Futures

  • Support img and code render.
  • Can set custom render function and styles.
  • More beautiful native View.

Demo

noder-demo

Example

var React = require('react-native')
var HtmlRender = require('react-native-html-render')

var {
    Component,
    View,
    Text,
    StyleSheet,
    Image
    }=React

var styles = StyleSheet.create({
    img: {
        width: 100,
        height: 100
    }
})


class HtmlContent extends Component {

    _renderNode(node, index, parent, type) {
      //Your code here
    }

    render() {
      const sample = "<H5>Hello World</H5>";
        return (
            <HtmlRender
                value={{sample}}
                stylesheet={styles}
                renderNode={this._renderNode}
                />
        )
    }

}

module.exports = HtmlContent

API

value

The value of html content.

stylesheet

Custom styles

onLinkPress

Handle the link click event.

renderNode

Custom render function.

The render function has three arguments.

node: A Object show the node of html.

Struct:

{
    name:'text',
    text: String,
    parent: Object,
    type: String
}

or If the node is not a text node:

{
    name: String,
    attribs: Object,
    type: String,
    parent: Object
}

index: The index of the node in the parent node.

parent: The parent of the node.

type: Only two types: block or inline.

Mor details:


var blockTagArr = ['div', 'p', 'img', 'address',
    'blockquote', 'dir', 'dl',
    'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
    'menu', 'ol', 'pre', 'table', 'ul', 'li', 'hr']

var inlineTagArr = ['a', 'abbr', 'b', 'big',
    'br', 'cite', 'code', 'em', 'label', 'span', 'strong']

FAQ

More details see Noder.

Licenses

MIT

react-native-html-render's People

Contributors

akiver avatar flyskywhy avatar nobalmohan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-html-render's Issues

Unable to resolve module Dimensions.

Hello, I've installed react-native-html-render "1.0.2".
When I run project I am getting:
Unable to resolve module Dimensions from /Users/r0st1k/SWAN/react-app/node_modules/react-native-html-render/lib/htmlRender.js: Invalid directory /Users/node_modules/Dimensions

When I've installed dimensions module through npm I get the same message.

I know this is not a right way to do, but when I've corrected
var Dimensions = require('Dimensions') to var Dimensions = require('dimensions') in htmlRender.js it finds dimensions but gives me next error:
Unable to resolve module fs from /Users/r0st1k/SWAN/react-app/node_modules/dimensions/index.js: Invalid directory /Users/node_modules/fs

Please advise what to do to use your module.

Now using node v5.2.0 (npm v3.5.1)

/r/n Not right displayed!

My json include \r symbol. With him a half of the text isn't displayed. Without him all of norms.In what there can be a problem.

Image will not be shown if there is an outer `figure` block.

I have data like this:

"<p>又更新了一点代码,下面是新的预览图:</p>
<img src="https://dn-python.qbox.me/images/4b9/56d18e93-rKvyC.png" alt="Python China ReactNative App" />
<figure><img src="https://dn-python.qbox.me/images/4b9/56d2754a-q9Q5a.png" alt="Python China ReactNative App" /></figure>
"

The first image renders nice, but the second one will disappear. I'm using the styles nearly the same as noder-react-native.

Confused by example!

Head lines of example here:

var React = require('react-native')

var HtmlRender = require('react-native-html-render')

var window = require('../../util/window')
var routes = require('../../configs/routes')

What's '../../configs/routes' and '../../util/window'? Should I install them before using this Render?

Table?

Hi, Do you plan to implement table at any point?

关于stylesheet的格式

image
我想减少 中间空白的大小应该怎么设定样式

<HtmlRender value={'<div>'+str+'</div>'} stylesheet={
                    {
                    p:{
                    margin:0,
                    padding:0,
                    fontSize:14,
                    lineHeight:16}
                    }}/>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.