Wrap fails for HTML content

寵の児 提交于 2019-12-11 13:33:16

问题


I have tried to wrap HTML CMS content, but it fails.

Here the code I have tried:

<h3>Wrap Example</h3>
<cfset test='<h4><span>This is failure wrap function</span></h4><span><h5>This is failure wrap function</h5></span>'>
<cfoutput>#Wrap(test, 10)#</cfoutput>

The result is given below:

 Wrap Example

 This is failure wrap function< /span>

 This is failure wrap function< /h5>

How can fix this issue?


回答1:


As per its docs, wrap() operates on a string, not a fragment of HTML. Whilst the latter is the former, the former does not imply any understanding of the latter. All wrap() sees is string data... it does not know that some of the string you are passing it is HTML, and accordingly one cannot simply interrupt an HTML tag with a line break character.

So basically there's nothing to "fix" here, as you're just using the inappropriate tool for the job.

I suspect what you should be looking at doing is putting the text within a span or a div or some other container tag, and then style that containing tag to have the width that you want. Chopping the string up into numbers-of-characters is not really how to approach the task you're wanting to accomplish, I think?

Why is it you're trying to do, in "wrapping" this mark-up at 10 characters?



来源:https://stackoverflow.com/questions/20969118/wrap-fails-for-html-content

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