Plaintext Paragraphs
Wraps plaintext paragraphs with HTML paragraph elements
Description
Pimped the nl2br utility to wrap plaintext paragraphs with HTML paragraph elements before inserting HTML line breaks in a string.
Credits to nl2br, only changed and added a few lines.
XSLT
View Raw
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- Example: <xsl:call-template name="plaintext-paragraphs"> <xsl:with-param name="string" select="body"/> </xsl:call-template> --> <xsl:template name="plaintext-paragraphs"> <xsl:param name="string"/> <xsl:choose> <xsl:when test="contains($string,' ')"> <p> <xsl:call-template name="nl2br"> <xsl:with-param name="string" select="substring-before($string,' ')"/> </xsl:call-template> </p> <xsl:call-template name="plaintext-paragraphs"> <xsl:with-param name="string" select="substring-after($string,' ')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <p> <xsl:call-template name="nl2br"> <xsl:with-param name="string" select="$string"/> </xsl:call-template> </p> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="nl2br"> <xsl:param name="string"/> <xsl:value-of select="normalize-space(substring-before($string,' '))"/> <xsl:choose> <xsl:when test="contains($string,' ')"> <br /> <xsl:call-template name="nl2br"> <xsl:with-param name="string" select="substring-after($string,' ')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$string"/> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>