Styling Open-Ended Text Inputs [closed]

眉间皱痕 提交于 2019-12-11 02:29:56

问题


What's the best / recommended practice to treat a text input that contains HTML tags? The idea is to properly display the input e.g. on a different page.

As expected, people can be very creative with their HTML. For example:

<p>...</p>
<ul><li>...</li></ul>

Another example:

<h1>...</h1>

A more challenging case will be an input without a properly structured HTML e.g. <h1>Hello</p></h1>. Without proper care, this has the potential to break the whole page layout.

One thing I could think of is to completely strip down the tags. However, there might be a much better way. To the very least, I'd like to be able to place a proper spacing / margin between the paragraphs; instead of just collapsing them together.


回答1:


As rlb.usa noted in the comments, most people rely on a mature, well-tested HTML renderer to display HTML. WebKit, Qt, and Microsoft's Trident control are popular choices depending on the platform.

If you've got a renderer that has problems with nonstandard code, you could run it through something like tidy first.



来源:https://stackoverflow.com/questions/7434629/styling-open-ended-text-inputs

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