taro render html


taro render html


html = `<h1 style='color: red'>Wallace is way taller than other reporters.</h1>`;
// "<h1 style='color: red'>Wallace is way taller than other reporters.</h1>"

text = html.replace(/<h1/ig, '<Text').replace(/<\/h1>/ig, '</Text>');
// "<Text style='color: red'>Wallace is way taller than other reporters.</Text>"


  const html = `<h1 style='color: red'>Wallace is way taller than other reporters.</h1>`;
  const htmlRender = (html = ``) => {
    const text = html.replace(/<h1/ig, '<Text').replace(/<\/h1>/ig, '</Text>');
    return (
      <View>{text}</View>
    );
  }

AST parse html ???



RichText

https://nervjs.github.io/taro/docs/components/base/rich-text.html#htmlelement

https://developers.weixin.qq.com/miniprogram/dev/component/rich-text.html

    const html = `<h1 style='color: red'>Wallace is way taller than other reporters.</h1>`;
    const htmlRender = (html = ``) => {
      const text = html.replace(/<h1/ig, '<Text').replace(/<\/h1>/ig, '</Text>');
      return (
        <View>{text}</View>
      );
    }
    return (
      <View className='index-box'>
        <Text>index</Text>
        {/* {htmlRender(html)} */}
        <RichText nodes={html} />
      </View>
    )

    const detailDesc = `<p><span style=\"font-size:18px\"><span style=\"color:#008000\">指針測試社群字段</span></span></p>\n\n<p><span style=\"font-size:18px\"><span style=\"color:#008000\"><img alt=\"\" src=\"https://o8qg9birw.qnssl.com/content/2b493805ac28efdd4c31562f52b5306256f6978c.jpg\" style=\"height:736px; width:414px\" /></span></span></p>\n`;
    return (
      <View className='index-box'>
        <RichText nodes={detailDesc} />
      </View>
    )


H5 OK

alipay Error

wx ??? html tag filter



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM