[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: 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, ' ')"> <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, ' ')"/> </fo:block> <xsl:variable name="after" select="substring-after($text, ' ')"/> <xsl:choose> <xsl:when test="contains($after, ' ')"> <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 " ". 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 > > > >
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]