in reply to Converting span tags.
Update: Probably a little less efficient, but clearer code:my $s = do {local $/=undef; <DATA>}; while( $s =~ s#<span style="(font-weight: bold;|font-style: italic;|te +xt-decoration: underline;)">(?!.*?<span)(.*?)</span>#span2tag($1,$2)# +sgei ){}; print $s; sub span2tag { my ($attr, $s) = @_; return "<b>$s</b>" if $attr =~ /bold/; return "<i>$s</i>" if $attr =~ /italic/; return "<u>$s</u>" if $attr =~ /underline/; return $s; } __DATA__ this <span style="font-weight: bold;">is</span> some <span style="font-weight: bold;">test <span style="font-style: italic;">text</span> <span style="text-decoration: underline;">for</span> bolding</span>, + underlining and italicizing text.<br />
my $s = do {local $/=undef; <DATA>}; while(1){ my $matched = 0; $matched ||= $s =~ s#<span style="font-weight: bold;">(?!.*?<span)(. +*?)</span>#<b>$1</b>#sgi; $matched ||= $s =~ s#<span style="font-style: italic;">(?!.*?<span)( +.*?)</span>#<i>$1</i>#sgi; $matched ||= $s =~ s#<span style="text-decoration: underline;">(?!.* +?<span)(.*?)</span>#<u>$1</u>#sgi; last unless $matched; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting span tags.
by the_0ne (Pilgrim) on Mar 27, 2006 at 20:05 UTC | |
|
Re^2: Converting span tags.
by the_0ne (Pilgrim) on Mar 27, 2006 at 17:28 UTC |