Next in thread → Next in month →

Re: [docbook-apps] aligning code to the right

From
Bob Stayton <>
Date
2012-05-10T16:33:22+00:00
ID
028301cd2eca$956491c0$6600a8c0@pazu
Thread
Re: [docbook-apps] aligning code to the right
This is actually difficult to do inside a 
programlisting. The problem is that a programlisting is handled as a single 
string containing white space and line breaks that are preserved by the 
formatter.  But neither XSL-FO or CSS provide a way to change the alignment 
of an inline string, even when it is bounded by line feeds on both sides.  

 

To effect a change of alignment, the long string 
would need to be broken and "text to the right" would need to be placed inside 
an fo:block (or div for HTML) so that the text-align="right" formatting property 
could be applied.  But when you put that text in its own fo:block, that 
breaks the line before and after.  Those line breaks add to the line breaks 
already existing in the text string, so you get a blank line before and after 
from the double line breaks. 

 

The only solution I can see is to remove the line 
breaks in the source file programlisting before and after such text, and wrap 
the text in <phrase role="right-align"> like this:

 

<programlisting>First line<phrase 
role="right-align">text to the right</phrase>Third line

And more lines.

</programlisting>

 

and add this template to your customization 
layer:

 

<xsl:template 
match="phrase[@role='right-align']">
  <fo:block 
text-align="end">
    
<xsl:apply-templates/>
  
</fo:block>
</xsl:template>

 

And something similar using <div> for HTML 
output.  This should result in:

 

-------------------------------------------------------------------

First line

                                                  text 
to the right

Third line

And more 
lines
--------------------------------------------------------------------

 

Removing the line breaks in the programlisting 
makes it difficult to read, but it does work.

 

Bob Stayton
Sagehill Enterprises


 

 

----- Original Message ----- 

From: "Lorenzo Caminiti" <>

To: <>

Sent: Tuesday, May 08, 2012 5:34 AM

Subject: [docbook-apps] aligning code to the 
right

> Hello all,
> 
> How can I align code to the 
right?
> 
> +-------------------------------------------+
> 
test to the 
left
>                        
text to the right
> text to the left again
> 
> Ideally, I'd 
do this not within a table but in normal text I'd start a
> few lines that 
are aligned to the right and then go back to left
> alignment.
> 

> Thanks a lot.
> --Lorenzo
> 
> 
---------------------------------------------------------------------
> To 
unsubscribe, e-mail: 
> For additional commands, e-mail: 
> 
> 
>
Next in thread → Next in month →