c# - 如何在不删除html标签的情况下将html转换为文本
问题描述
将此 转换为此] 2 我正在尝试使用 html 标签(p,ol,b)[!转换为普通文本(如运行代码片段的结果) - 我在 .net 核心中尝试使用以下代码,但结果是没有格式的纯 html(例如:p 标签应该显示段落,<ol 应该转换为数字,<b应该使文本加粗等。)
var doc = new HtmlDocument();
doc.LoadHtml(sampleHtml);
var innertext = doc.DocumentNode.InnerText;
也尝试使用 HTMLAgility 包,但没有运气。
Html.Raw(sampleHtml) works with mvc razor but not with .net core.
<p>Angular is a platform for building mobile and desktop web applications. It has a big community of millions of developers who choose Angular to build compelling user interfaces.:</p><ol><li>Angular is a JavaScript open-source front-end web application framework..</li><li>Angular solves many of the challenges faced when developing single page, cross platform, performant applications.</li></ol><p><b>Angular</b/></p><p><b>What's new</b/></p><p><b>Angular is a complete rewrite of AngularJS.</b/></p><p>Angular does not have a "scope" concept or controllers, instead, it uses a component hierarchy as its main architecture.</p><p><b>Warning</b/></p><p>Static Typing (<b>support</b>) for the purpose of study.
请评论您的想法和实现这一目标的方法。谢谢
解决方案
感谢您的所有回复。我能够在角度模板中做到这一点,而不是使用从 C# 获取转换后的 html <p [innerHTML]="sampleHtml">'. innerHTML></p>
,innerHTML 不适用于我试图做的 'textarea',所以我使用了一个段落,也可以使用 div。
推荐阅读
- smb - owncloud 10.3.2 SMB共享,一次只能一个用户访问
- node.js - 使用 HTML5 视频标签从 Node.js 服务器上的 MinIO 存储桶流式传输视频
- xcode - mac终端无法运行make命令
- azure-devops - 如何指定特定 Azure 作业需要作业级别的给定操作系统?
- sql - sql按天查询显示不同的结果
- android - 我需要为每个页面制作横幅广告吗?
- pandas - 如何连接到另一列具有特定值的一列下的单元格?
- reactjs - Nginx 子文件夹 admin react app 在 main react app 下
- python-3.x - 用 pack() tkinter 对齐东西
- .htaccess - .htaccess RewriteRule 条件规则