- Timestamp:
- 05/30/09 15:46:14 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm
r3947 r3992 246 246 $text = $this->_takeOutSets($text); 247 247 248 $text = $this->_takeOutCustomTags($text); 249 248 250 $text =~ s/\\\n/ /g; 249 251 $text =~ s/\t/ /g; … … 595 597 } 596 598 599 sub _takeOutCustomTags { 600 my ( $this, $text ) = @_; 601 602 # Take out custom XML tags 603 sub _takeOutCustomXmlProcess { 604 my ( $this, $state, $scoop ) = @_; 605 return $this->_liftOut( $scoop, 'PROTECTED' ); 606 } 607 my $xmltags = $this->{opts}->{xmltag}; 608 for my $tag ( sort keys %$xmltags ) { 609 $text = _takeOutXml( $this, $text, $tag, \&_takeOutCustomXmlProcess ); 610 } 611 612 # Take out other custom tags here 613 614 return $text; 615 } 616 597 617 sub _takeOutBlocks { 598 my ( $this, $intext, $tag ) = @_; 599 die unless $tag; 618 # my ( $this, $intext, $tag ) = @_; 619 620 sub _takeOutBlocksProcess { 621 my ( $this, $state, $scoop ) = @_; 622 my $placeholder = $state->{tag} . $state->{n}; 623 $this->{removed}->{$placeholder} = { 624 params => _parseParams( $state->{tagParams} ), 625 text => $scoop, 626 }; 627 return $TT0 . $placeholder . $TT0; 628 } 629 630 return _takeOutXml( @_, \&_takeOutBlocksProcess ); 631 } 632 633 sub _takeOutXml { 634 my ( $this, $intext, $tag, $fn ) = @_; 635 die unless $tag; 636 die unless $fn; 600 637 return '' unless $intext; 601 638 return $intext unless ( $intext =~ m/<$tag\b/ ); 602 639 603 my $open = qr/<$tag\b[^>]*>/i; 604 my $close = qr/<\/$tag>/i; 605 my $out = ''; 606 my $depth = 0; 640 my $openNoCapture = qr/<$tag\b[^>]*>/i; 641 my $openCaptureAttrs = qr/<$tag\b([^>]*)>/i; 642 my $close = qr/<\/$tag>/i; 643 my $out = ''; 644 my $depth = 0; 607 645 my $scoop; 608 my $tagParams; 609 my $n = 0; 610 611 foreach my $chunk ( split /($open|$close)/, $intext ) { 646 647 # &$fn may rely on the existence of these fields, 648 # and may add more fields, if needed 649 my %state = ( tag => $tag, n => 0, tagParams => undef ); 650 651 foreach my $chunk ( split /($openNoCapture|$close)/, $intext ) { 612 652 next unless defined($chunk); 613 if ( $chunk =~ m/ <$tag\b([^>]*)>/ ) {653 if ( $chunk =~ m/$openCaptureAttrs/ ) { 614 654 unless ( $depth++ ) { 615 $ tagParams= $1;616 $scoop = '';655 $state{tagParams} = $1; 656 $scoop = ''; 617 657 next; 618 658 } … … 620 660 elsif ( $depth && $chunk =~ m/$close/ ) { 621 661 unless ( --$depth ) { 622 my $placeholder = $tag . $n; 623 $this->{removed}->{$placeholder} = { 624 params => _parseParams($tagParams), 625 text => $scoop, 626 }; 627 $chunk = $TT0 . $placeholder . $TT0; 628 $n++; 662 $chunk = $fn->( $this, \%state, $scoop ); 663 $state{n}++; 629 664 } 630 665 } … … 643 678 # $scoop .= "</$tag>\n"; 644 679 # } 645 my $placeholder = $tag . $n; 646 $this->{removed}->{$placeholder} = { 647 params => _parseParams($tagParams), 648 text => $scoop, 649 }; 650 $out .= $TT0 . $placeholder . $TT0; 680 $out .= $fn->( $this, \%state, $scoop ); 651 681 } 652 682 653 683 # Filter spurious tags without matching open/close 654 $out =~ s/$open /<$tag$1>/g;684 $out =~ s/$openCaptureAttrs/<$tag$1>/g; 655 685 $out =~ s/$close/<\/$tag>/g; 656 686 $out =~ s/<($tag\s+\/)>/<$1>/g;
Note: See TracChangeset
for help on using the changeset viewer.
