Forum How do I...?

Force Line Breaks

scott_w
I have looked all over the forum and can't find something usable that works. I'm sure it is a simple answer but it is eluding me. I have something like this:

<p>Published by<br/>The Church of Jesus Christ of Latter-day Saints<br/>Salt Lake City, Utah</p>

I want to output this:

Published by
The Church of Jesus Christ of Latter-day Saints
Salt Lake City, Utah

The file is being processed as XML not HTML so the <br/> doesn't automatically do the right thing. I thought I could transform an entity in there and get it to behave, I have tried lots of different ones, &#13; &#10; &#x0D; &#x0A; &#x2028; &#x2029; and nothing seems to do what I would expect. What am I missing?
mikeday
The &#xA; entity is simply a newline that you can get by leaving a literal line break in the file. However, by default it will be treated as a space unless you apply some CSS: "white-space: pre" or "white-space: pre-line" to that element.
StoneCypher
Basically, you either want to put each individual line in its own display:block element, or you want to put them into an element with white-space:pre; set on it.

<p style="white-space:pre">Church of Jesus Christ
Latter Day Saints</p>


Or

<p>Church of Jesus Christ</p><p>Latter Day Saints</p>

John Haugeland is http://fullof.bs/

scott_w
Thanks, for the great feedback, everything works.
meowist
Hello,

I have the same question as the original poster, but since 3 years and many Prince upgrades have ensued, I'm wondering if there's a better solution for this now. Here's a sample of the markup I've got:

<div class="quote-text">
The strawberry grows underneath the nettle<br> 
And wholesome berries thrive and ripen best<br> 
Neighbored by furit of baser quality.<br>
</div>


The output needs to look like properly formatted lines of poetry, respecting the <br>s.

Are there any special Prince-specific properties like this one that might make this work automatically, or will I have to modify my markup (add p tags or divs)?

http://www.princexml.com/doc/9.0/properties/prince-linebreak-magic/

Thanks!

mikeday
Why won't it respect the br elements?
meowist
Hmmm I had assumed for the same reason as the OP's:

"The file is being processed as XML not HTML so the <br/> doesn't automatically do the right thing."

Right now if I process my HTML via Prince, lines like this:

<div class="quote-text">
The strawberry grows underneath the nettle<br> 
And wholesome berries thrive and ripen best<br> 
Neighbored by furit of baser quality.<br>
</div>


output like this in the PDF

The strawberry grows underneath the nettleAnd wholesome berries thrive and ripen bestNeighbored by fruit of baser quality.


mikeday
So this is not an HTML document, even though it uses <div> and <br>? Our default CSS style sheet for HTML includes this rule:
br {
    content: '\A';
    white-space: pre;
    background: none
}

Adding something like this in your own style sheet should do the trick.
meowist
Sorry for the confusion. It *is* an HTML document, which is why it surprised me that the <br> tags wouldn't just work normally. Should I try adding the br lines you suggested to my css? Seems that would be redundant. I'm using Prince 9.0 v4. Thanks for any help!
mikeday
Now I'm confused; if I run this document through Prince 9 it works fine:
<html>
<body>
<div class="quote-text">
The strawberry grows underneath the nettle<br>
And wholesome berries thrive and ripen best<br>
Neighbored by furit of baser quality.<br>
</div>
</body>
</html>

Perhaps you could attach your document here, or email me (mikeday@yeslogic.com) and I will take a look.
meowist
Turns out the problem was a method in my HTML generating script that stripped out <br>s. My fault! Thank you for the quick help.
Babelfish
The same problem by me. Inside a LI element prince will not break at a BR.

<ul>
  <li>break this line here<br>new line</li>
</ul>


In the PDF file it is rendered as:

• break this line here new line
mikeday
Works for me in attached document. Perhaps you have some other CSS style rules or markup issues?
  1. break.html0.1 kB
Babelfish
My mistake. In a imported stylesheet was a rule with br { display: none } :-(