简体   繁体   English

将Html渲染或转换为'格式'文本(.NET)

[英]Render or convert Html to 'formatted' Text (.NET)

I'm importing some data from another test/bug tracking tool into tfs, and I would like to convert it's description, which is in simple HTML, so a plain string, where the 'layout' of the HTML is preserved. 我将一些数据从另一个测试/错误跟踪工具导入到tfs中,我想转换它的描述,它是简单的HTML,所以是一个普通的字符串,其中保留了HTML的“布局”。

For example: 例如:

<body>
  <ol>
    <li>Log on with user Acme &amp; Co.</li>
    <li>Navigate to the details tab</li>
    <li>Check the official name</li>
  </ol>
  <br>
  <br>
  Expected Result:<br>
  official name is filled in<br>
  <br>
  Actual Result:<br>
  The &amp;-sign is not shown correctly<br>
  See attachement.
</body>

Would become plain text with newlines inserted and HTML-entities translated like: 将插入换行符并将HTML实体翻译成纯文本:

1. Log on with user Acme & Co.
2. Navigate to the details tab
3. Check the official name

Expected Result:
official name is filled in

Actual Result:
The &-sign is not shown correctly
See attachment

I can currently replace some tags with newlines using a regex and strip the rest, but replacing the HTML-entities and stuff like <ol> and <ul> seemed like I'm re-inventing something (browser?). 我现在可以使用正则表达式替换一些带有换行符的标签并删除其余部分,但是替换HTML实体和诸如<ol><ul>类的东西似乎我正在重新发明一些东西(浏览器?)。 So I was wondering if someone has done this before me. 所以我想知道是否有人在我面前这样做了。 I can't find it using Google. 我用谷歌找不到它。

Rather than regex, you could try loading it into the HTML agility pack ? 您可以尝试将其加载到HTML敏捷包中而不是正则表达式吗? If it was xhtml, then an xslt transformation might be a good option. 如果它是xhtml,那么xslt转换可能是一个不错的选择。

In the end, once I got more comfortable with TFS, I customized the work item type to include a new HTML Field, and just copied the contents into that field. 最后,一旦我对TFS更加熟悉,我自定义了工作项类型以包含新的HTML字段,并将内容复制到该字段中。

This solution was so much better, because we could now see the intended formatting of the field. 这个解决方案要好得多,因为我们现在可以看到该字段的预期格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM