首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将字符串中的HTML实体转换为React本机中的可读文本?

如何将字符串中的HTML实体转换为React本机中的可读文本?
EN

Stack Overflow用户
提问于 2022-03-08 05:37:54
回答 1查看 493关注 0票数 0

我从一个包含一些html实体的API中获得以下字符串。我要把它们转换成可读的文本。我该怎么做呢?是否有任何内置的方法在反应本机做同样的?在没有任何外部库的情况下这样做是更好的选择。

代码语言:javascript
复制
"This era of design where there was still some &quot;whimsy&quot; is some of my favorite Apple work too. The austere modern era where <i>everything</i> is a slab of glass fronted metal has lost so much of the joy that was found in their earlier computers.<p>If you want a touch screen computer that used this design optimized for sketching, Microsoft took it to the logical conclusion with the Surface Studio:<p><a href=\"https:&#x2F;&#x2F;www.microsoft.com&#x2F;en-us&#x2F;d&#x2F;surface-studio-2&#x2F;8sbjxm0m58t4?activetab=pivot:overviewtab\" rel=\"nofollow\">https:&#x2F;&#x2F;www.microsoft.com&#x2F;en-us&#x2F;d&#x2F;surface-studio-2&#x2F;8sbjxm0m5...</a><p>This is  much better for sketching, as can reach a much flatter angle than the G4 iMac ever could. It also holds its angle quite a bit more securely (I&#x27;ve used both). While I&#x27;m not a massive Windows user, the physical aspects of the Surface Studio are pretty nice and much more interesting to me than the latest iMacs."
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-08 06:38:09

您可以使用react-native-render-html来呈现html内容。

代码语言:javascript
复制
import React from 'react';
import { useWindowDimensions } from 'react-native';
import RenderHtml from 'react-native-render-html';

const source = {
  html: `
"This era of design where there was still some &quot;whimsy&quot; is some of my favorite Apple work too. The austere modern era where <i>everything</i> is a slab of glass fronted metal has lost so much of the joy that was found in their earlier computers.<p>If you want a touch screen computer that used this design optimized for sketching, Microsoft took it to the logical conclusion with the Surface Studio:<p><a href=\"https:&#x2F;&#x2F;www.microsoft.com&#x2F;en-us&#x2F;d&#x2F;surface-studio-2&#x2F;8sbjxm0m58t4?activetab=pivot:overviewtab\" rel=\"nofollow\">https:&#x2F;&#x2F;www.microsoft.com&#x2F;en-us&#x2F;d&#x2F;surface-studio-2&#x2F;8sbjxm0m5...</a><p>This is  much better for sketching, as can reach a much flatter angle than the G4 iMac ever could. It also holds its angle quite a bit more securely (I&#x27;ve used both). While I&#x27;m not a massive Windows user, the physical aspects of the Surface Studio are pretty nice and much more interesting to me than the latest iMacs."`
};

export default function App() {
  const { width } = useWindowDimensions();
  return (
    <RenderHtml source={source} contentWidth={width}/>
  );
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71390486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档