1

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?

SOS
  • 6,430
  • 2
  • 11
  • 29
lambypie
  • 471
  • 1
  • 12
  • 35

1 Answers1

4

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?

SOS
  • 6,430
  • 2
  • 11
  • 29
Adam Cameron
  • 29,677
  • 4
  • 37
  • 78
  • I have added this for an example("wrapping" this mark-up at 10 characters). Thanks for your information. I got it – lambypie Jan 07 '14 at 11:23
  • But word wrapping using css will not work while rendering html to pdf. You can check the same in the issue [http://stackoverflow.com/questions/18483073/cfdocument-pdf-rendering-issue-with-japanese](http://stackoverflow.com/questions/18483073/cfdocument-pdf-rendering-issue-with-japanese) – lambypie Jan 07 '14 at 11:44
  • 2
    `` ain't that good at doing PDFs, unfortunately. Odd, given who owns both ColdFusion and Acrobat. – Adam Cameron Jan 07 '14 at 11:51
  • You might need to raise another question relating to getting text-wrapping in both HTML and PDF working, perhaps? I cannot help you with that though, sorry. I know know anything about generating PDFs (other than stuff I taught myself when helping you with the Japanese stuff earlier) – Adam Cameron Jan 07 '14 at 11:53