Sie sind in Kategorie Blosxom

Brotkrumennavigation


Dienstag, 01. Juli 2008

Blosxom patch: using HTML content with RSS

Schlagworte: , , ,
01.07.2008 · 15:38
Some months ago i was asked if i would like to share my patches to the community. The standard RSS in blosxom.cgi is not very useful for making correct RSS. Especially using HTML for RSS is resulting in a desaster. Sorry to say this, Blosxom is a fine Perl webapp. But, no problem, with a little patch it will work fine.

Deutsche Version dieses Blogeintrags.

I, beeing a real geeky lazybone, use much HTML in my blog. The internal RSS encoding the XML entities does not work fine all, because that implementation does destroy HTML, changes it to plain text.

My flavour templates adds HTML to element description with a CDATA section. In a CDATA section you can insert HTML without special recoding, because CDATA means to the XML parser: Do not parse, use as is!

OK, my approach for a better RSS-HTML in Blosxom with filtering only the allowed and really useful HTML.

As prerequisites you need HTML::TagFilter; sorry for the inconvenience. Please fetch it from CPAN.

My patch refers to the CVS Rev. 1.69 of blosxom.

Instead of using (line 663–675):

if ( $encode_xml_entities && $content_type =~ m{\bxml\b} ) {

     # Escape <, >, and &, and to produce valid RSS
     my %escape = (
       '<' => '&lt;',
       '>' => '&gt;',
       '&' => '&amp;',
       '"' => '&quot;'
     );
     my $escape_re = join '|' => keys %escape;
     $title =~ s/($escape_re)/$escape{$1}/g;
     $body  =~ s/($escape_re)/$escape{$1}/g;
 }

use this part:

## --- 07-2008 Patch by GwenDragon for HTML and RSS ---
##     (c)2008 Lilo von Hanffstengel "GwenDragon"
##     see http://www.gwendragon.de/blog/Web/Webapplikationen/Blosxom/RSS-Patch-for-HTML.html
## --------------
if ( $content_type =~ m{\bxml\b} ) {
    my $t = $title;
    my $b = $body;
    eval {
       require HTML::Entities;
       $t = HTML::Entities::decode( $t );
       #$b = HTML::Entities::decode( $b );
                        
       require HTML::TagFilter;
       # and strip off HTML
       my $tf = new HTML::TagFilter;
       $t = $tf->filter( $t );
       $b = $tf->filter( $b );
    };
    if ( not $@ ) { 
       $title = $t;
       $body = $b;
    }
    #
                
    if ( $@ and $encode_xml_entities ) {
       # decode HTML
       $title = HTML::Entities::decode($title);
       $body = HTML::Entities::decode($body);
       #
                        
       # Escape <, >, and &, and to produce valid RSS
       my %escape = (
          '<' => '&lt;',
          '>' => '&gt;',
          '&' => '&amp;',
          '"' => '&quot;'
       );
       my $escape_re = join '|' => keys %escape;
       $title =~ s/($escape_re)/$escape{$1}/g;
       $body  =~ s/($escape_re)/$escape{$1}/g;
    }
                                
}
# -------------

Use and enjoy. But add a short author information about me for this patch in Blosxom's code. Thanks.

In case of problems with the patch please contact me.

Autor: GwenDragon · Kategorie Blosxom · Permalink · Kommentare (0) · Kommentar schreiben

Kommentar für Blogeintrag

Vorschau des Kommentars

Kommentar

Mit * gekennzeichnete Felder müssen angegeben werden.



(Textformatierung in Markdown möglich)

Hinweis zum Datenschutz

Falls es Probleme mit Kommentaren/Trackbacks gibt, bitte ich um eine Beschreibung per E-Mail.

TrackBack-URL: http://gwendragon.de/blog/Web/Webapplikationen/Blosxom/RSS-Patch-for-HTML.html/trackback

↑Artikel