首页 > 解决方案 > 如何在不删除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.netasp.net-corehtml-parsing

解决方案


感谢您的所有回复。我能够在角度模板中做到这一点,而不是使用从 C# 获取转换后的 html <p [innerHTML]="sampleHtml">'. innerHTML></p>,innerHTML 不适用于我试图做的 'textarea',所以我使用了一个段落,也可以使用 div。


推荐阅读