Looking good voyager. Here's a small patch that will
convert any UTF-8 extended ascii from XML::Parser
to latin1 so odd nodetitles or usernames look right.
Example nodetitle from today's new nodes:
Before: Reactionary Coding—One-Shot Programs
After : Reactionary Coding—One-Shot Programs
Add this conversion subroutine:
sub UTF8_latin1
{ # UTF-8 to latin1 regex from XML::TiePYX (thanks to mirod)
my($text) = @_;
$text =~ s{([\xc0-\xc3])(.)}{
my $hi = ord($1);
my $lo = ord($2);
chr((($hi & 0x03) <<6) | ($lo & 0x3F))
}ge;
return $text;
}
Add two lines to the foreach loop in sub html_by_type:
foreach my $node (@$nodes) {
$node->{cdata} = UTF8_latin1($node->{cdata}); # ADDED
my $link = $q->a({-href => "$url_base$node->{node_id}"}, $node
+->{cdata});
my $node_text = $q->li($link);
my $author = $authors->{$node->{author_user}};
$author = UTF8_latin1($author); # ADDED
$node_text .= (' ' x 2) . $q->small(" by $author") if $SH
+OW_AUTHOR;
print $node_text;
}
Enjoy.
--
Check out my Perlmonks Related Scripts like framechat,
reputer, and xNN.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|