OK, I see HTMLText->Summary preserver HTML tags. So, here's my path:
--- HTMLText.php.orig 2007-05-25 13:00:18.000000000 +1200
+++ HTMLText.php 2007-05-25 13:09:17.000000000 +1200
@@ -33,13 +33,12 @@
}
elseif( preg_match( '/<\/(\w+)>/', $parts[$pIndex], $endTag ) && $endTag[1] == substr( $tagStack[count($tagStack) - 1], 1, strlen( $endTag[1] ) ) ) {
array_pop( $tagStack );
- $words++;
$summary .= $parts[$pIndex++];
} elseif( preg_match( '/^<\w+/', $parts[$pIndex] ) ) {
array_push( $tagStack, $parts[$pIndex] );
- $words++;
$summary .= $parts[$pIndex++];
} else {
+ $words++;
$summary .= $parts[$pIndex++] . ' ';
}
}
@@ -52,7 +51,11 @@
if(sizeof($tagName) > 0)
$summary .= "</{$tagName[1]}>";
}
-
+ // add triple dot and close the paragraph, if the paragraph has been trimmed
+ if ( $words > $maxWords || $pIndex >= count( $parts ) ) {
+ $summary .= '...</p>';
+ }
+
return $summary;
}
Now, it seems to work well. Anyway, it would be nice to have other similar text manipulation methods from Text class also in HTMLText class.