{rss:text:maxlen}

Description

Prepares text for output inside an RSS or other XML feed. It strips all HTML tags, turns each non-breaking space (the nbsp entity) into a normal space, escapes a bare ampersand that is followed by a space (so the feed stays well-formed XML), and trims leading and trailing whitespace. Give the optional second parameter to cut the cleaned result to that many characters. The classic use is wrapping a headline or abstract inside the title and description elements of a feed item.

Parameters

text required default (empty)

The text to clean for a feed. All HTML tags are removed, each non-breaking space (nbsp entity) becomes a normal space, a bare ampersand followed by a space is escaped to amp-semicolon, and surrounding whitespace is trimmed. In practice this is a field-getter such as the headline or abstract of the current item.

maxlen optional default (no limit)

Optional maximum length, in characters, of the cleaned result. When present and made up only of digits, the output is cut to this many characters (counted with multibyte awareness, so accented letters count as one). Any non-digit value, or an omitted value, leaves the text at full length.

Examples

test{rss:<b>Annual report</b> is out}
ExpectedAnnual report is out
ActualAnnual report is out
rss removes every HTML tag, leaving plain feed-safe text.
test{rss: Spaced headline }
ExpectedSpaced headline
ActualSpaced headline
Leading and trailing whitespace is trimmed away.
test{rss:Prague&nbsp;Open&nbsp;Day}
ExpectedPrague Open Day
ActualPrague Open Day
Each nbsp entity is turned into an ordinary space, so feed readers wrap the text normally.
test{rss:R & D team}
ExpectedR & D team
ActualR & D team
A stray ampersand-plus-space is escaped to amp-semicolon in the stored feed source, keeping the XML well-formed. On this page the browser shows it decoded again as a single ampersand.
test{rss:The quick brown fox jumps:9}
ExpectedThe quick
ActualThe quick
With a digit-only second parameter the cleaned text is cut to that many characters.
test{rss:Full headline stays:all}
ExpectedFull headline stays
ActualFull headline stays
Only an all-digits maxlen truncates; any other value (or none) leaves the text at full length.
test{rss:Volunteers <b>needed</b> for spring cleanup}
ExpectedVolunteers needed for spring cleanup
ActualVolunteers needed for spring cleanup
rss strips HTML tags from text so it is safe inside an RSS title or description element; the bold tags are removed.