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

喜夏-厌秋 提交于 2019-11-29 12:51:09

问题


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.

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:

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?). So I was wondering if someone has done this before me. I can't find it using Google.


回答1:


Rather than regex, you could try loading it into the HTML agility pack? If it was xhtml, then an xslt transformation might be a good option.




回答2:


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.

This solution was so much better, because we could now see the intended formatting of the field.



来源:https://stackoverflow.com/questions/356597/render-or-convert-html-to-formatted-text-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!