How do I parse an HTML file in React Native?

后端 未结 3 840
借酒劲吻你
借酒劲吻你 2021-02-09 21:49

How can I get an HTML file from file system and parse specific elements from it.

For example, given the html snippet below, how can I extract the table content and rende

3条回答
  •  天涯浪人
    2021-02-09 22:37

    I would recommend using this library: react-native-htmlviewer. It takes html and renders it as native views. You can also customize the way elements get rendered.

    // only render the  nodes in your html
    function renderNode(node, index, siblings, parent, defaultRenderer) {
      if (node.name !== 'table'){
        return (
          
            {defaultRenderer(node.children, parent)}
          
        )l
      }
    
    }
    
    // your html
    const htmlContent = ``;
    
    class App extends React.Component {
      render() {
        return (
          
        );
      }
    }
    
        

    提交回复
    热议问题