holyandrew (holyandrew) wrote in changelog,
holyandrew
holyandrew
changelog

[livejournal] r22660: LJSUP-12915: Don't clean <s> tag from pr...

Committer: akanashin
LJSUP-12915: Don't clean <s> tag from preview at top entries
U   trunk/cgi-bin/LJ/Text.pm
U   trunk/cgi-bin/ljtextutil.pl
Modified: trunk/cgi-bin/LJ/Text.pm
===================================================================
--- trunk/cgi-bin/LJ/Text.pm	2012-08-15 13:47:28 UTC (rev 22659)
+++ trunk/cgi-bin/LJ/Text.pm	2012-08-15 13:54:10 UTC (rev 22660)
@@ -253,6 +253,8 @@
     my $fill_empty = delete $opts{'fill_empty'} ? 1 : 0;
     my $punct_space = delete $opts{'punct_space'} ? 1 : 0;
     my $strip_html = delete $opts{'strip_html'} ? 1 : 0;
+    my $noparse_tags = delete $opts{'noparse_tags'} || [];
+
     my $force_ellipsis;
 
     cluck "unknown options: " . Dumper(\%opts)
@@ -260,10 +262,10 @@
 
     cluck "not actually truncating"
         unless $bytes || $chars;
-        
+
     if($strip_html) {
         $force_ellipsis = ($str =~ /<(img|embed|object|iframe|lj\-embed)/i) ? 1 : 0;
-        $str = LJ::strip_html($str, { use_space => 1 });
+        $str = LJ::strip_html($str, { use_space => 1, noparse_tags => $noparse_tags });
     }
 
     my $remove_last_word = sub {

Modified: trunk/cgi-bin/ljtextutil.pl
===================================================================
--- trunk/cgi-bin/ljtextutil.pl	2012-08-15 13:47:28 UTC (rev 22659)
+++ trunk/cgi-bin/ljtextutil.pl	2012-08-15 13:54:10 UTC (rev 22660)
@@ -239,16 +239,30 @@
                     text  => [sub { $_[0]->{res} .= $_[1] }, 'self, text'], # concat plain text
                     # handle tags
                     start => [sub { 
-                                    my ($self, $tag, $attrs) = @_;
+                                    my ($self, $tag, $attrs, $origtext) = @_;
                                     if ($tag =~ /lj/i){
                                         $self->{res} .= $attrs->{user} || $attrs->{comm};  # <lj user="username" title=".."> -> username
                                     } else {
                                         $self->{res} .= ' ' if $opts->{use_space}; # for other tags add spaces if needed.
                                     }
+                                    if ($opts->{noparse_tags}) {
+                                        for (@{$opts->{noparse_tags}}) {
+                                            $self->{res} .= $origtext if $tag eq $_;
+                                        }
+                                    }
                                    },
-                                   'self, tagname, attr, text'
+                                  'self, tagname, attr, text'
                                ],
-                },
+                    end => [sub {
+                                 my ($self, $tag, $origtext) = @_;
+                                 if ($opts->{noparse_tags}) {
+                                     for (@{$opts->{noparse_tags}}) {
+                                        $self->{res} .= $origtext if $tag eq $_;
+                                     }
+                                 }
+                            }, 'self, tagname, text'
+                           ]   
+                 },
             );
     $p->parse($str);
     $p->eof; 

Tags: akanashin, holyandrew, livejournal, pl, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments