This is the mail archive of the docbook-apps@lists.oasis-open.org mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [docbook-apps] accentuate or indent wrapped lines


I know of one way to solve this problem.  There may be others.

The method I have used is to put each line of the programlisting
into its own fo:block. When you do that, you can control how the
line is formatted. In your case, you could indent the left margin
a bit, then set the text-indent to a negative number to outdent
the first line to counteract the left margin.  This means the first
line of a wrapped line is not indented, but any subsequent
wrapped lines are indented.

In order to put each line in its own fo:block, you have to create
a template for programlisting that parses the text of the
programlisting.  Whenever it finds a line feed, it uses that
as the boundary to form a fo:block.

Below is an example of an oversimplified template
for programlisting that parses its content.  You should put
this into the larger template for programlisting, which
handles any id and other such matters.

<xsl:template match="programlisting">

  <xsl:variable name="text" select="."/>

  <xsl:call-template name="lineblock">
    <xsl:with-param name="text" select="$text"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="lineblock">
  <xsl:param name="text" select="''"/>

  <xsl:choose>
    <xsl:when test="contains($text, '&#10;')">
      <fo:block wrap-option='wrap'
                text-indent="-0.5in"
                margin-left='0.5in'
                white-space-collapse='false'
                linefeed-treatment="preserve"
                xsl:use-attribute-sets="monospace.properties">
        <xsl:value-of select="substring-before($text, '&#10;')"/>
      </fo:block>
      <xsl:variable name="after" select="substring-after($text, '&#10;')"/>

      <xsl:choose>
        <xsl:when test="contains($after, '&#10;')">
          <xsl:call-template name="lineblock">
            <xsl:with-param name="text" select="$after"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <fo:block wrap-option='wrap'
                text-indent="-0.5in"
                margin-left='0.5in'
                white-space-collapse='false'
                linefeed-treatment="preserve"
                xsl:use-attribute-sets="monospace.properties">
            <xsl:value-of select="$after"/>
          </fo:block>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:when>
    <xsl:otherwise>
      <fo:block wrap-option='wrap'
                text-indent="-0.5in"
                margin-left='0.5in'
                white-space-collapse='false'
                linefeed-treatment="preserve"
                xsl:use-attribute-sets="monospace.properties">
        <xsl:value-of select="$text"/>
      </fo:block>
    </xsl:otherwise>
  </xsl:choose>

</xsl:template>

The programlisting template calls the lineblock template.
The lineblock template recursively parses the string value
of the programlisting, looking for line ending characters "&#10;".
It then puts the substring-before into an fo:block and recurses
on the remaining text.

If your programlistings have elements and not just text, then
it will have to do more work to handle the elements.
Of course, using a recursive template to parse the lines
of a programlisting is going to slow down processing.
How much it slows down depends on how long the
listing is and how many you have.  It may not matter much.

So this is one method for handling text displays where you
want to preserve the line endings if a line is short, but if the
line is too long it has to be broken so it doesn't bleed off the
edge of the page.  With real programlistings with nested
indents on the text, it may not work very well.  But at least
the text won't go off the page!

Bob Stayton
Sagehill Enterprises
DocBook Consulting
bobs@sagehill.net


----- Original Message ----- 
From: "Sebastian Fey" <fey@parsytec.de>
To: <docbook-apps@lists.oasis-open.org>
Sent: Friday, February 06, 2004 4:59 AM
Subject: [docbook-apps] accentuate or indent wrapped lines


>
>
> hi,
>
> in docbook-xsl it is standard that programlistings are NOT wrapped, but
this results in an overflow of the text over the page.
>
> i set the attribute  wrap-option="wrap".
> well the programlistings are wrapped now, but i need to marks these
linebreaks, either by an indent or a spezial character.
>
>
>
> it is not possible to add sth to the xml, such as line numbers.
>
> thx in advance,
>
> Sebastian
>
>
>
>



To unsubscribe from this list, send a post to docbook-apps-unsubscribe@lists.oasis-open.org, or visit http://www.oasis-open.org/mlmanage/.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]