lib/TWiki/Plugins/WysiwygPlugin/HTML2TML/Leaf.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
child 1 e2915a7cbdfa
permissions -rw-r--r--
RELEASE 4.2.0 freetown
     1 # Copyright (C) 2005 ILOG http://www.ilog.fr
     2 # and TWiki Contributors. All Rights Reserved. TWiki Contributors
     3 # are listed in the AUTHORS file in the root of this distribution.
     4 # NOTE: Please extend that file, not this notice.
     5 #
     6 # This program is free software; you can redistribute it and/or
     7 # modify it under the terms of the GNU General Public License
     8 # as published by the Free Software Foundation; either version 2
     9 # of the License, or (at your option) any later version. For
    10 # more details read LICENSE in the root of the TWiki distribution.
    11 #
    12 # This program is distributed in the hope that it will be useful,
    13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    15 #
    16 # As per the GPL, removal of this notice is prohibited.
    17 
    18 =pod
    19 
    20 ---+ package TWiki::Plugins::WysiwygPlugin::TML2HTML::Leaf
    21 
    22 Object for a leaf node in an HTML parse tree
    23 
    24 A leaf node is text in the document.
    25 
    26 See also TWiki::Plugins::WysiwygPlugin::TML2HTML::Node
    27 
    28 =cut
    29 
    30 package TWiki::Plugins::WysiwygPlugin::HTML2TML::Leaf;
    31 use base 'TWiki::Plugins::WysiwygPlugin::HTML2TML::Base';
    32 
    33 use strict;
    34 
    35 sub new {
    36     my( $class, $text ) = @_;
    37 
    38     my $this = {};
    39 
    40     $this->{tag} = '';
    41     $this->{text} = $text;
    42     return bless( $this, $class );
    43 }
    44 
    45 # Entities that we want to decoded in plain text
    46 my %text_entities = (
    47     quot => 34, amp => 38, lt => 60, gt => 62
    48    );
    49 my $text_entities_re = join('|', keys %text_entities);
    50 
    51 sub generate {
    52     my( $this, $options ) = @_;
    53     my $t = $this->{text};
    54 
    55     if (!($options & $WC::KEEP_WS)) {
    56         $t =~ s/\t/   /g;
    57         $t =~ s/\n/$WC::CHECKw/g;
    58         $t =~ s/  +/ /g;
    59     }
    60     if( $options & $WC::NOP_ALL ) {
    61         # escape all embedded wikiwords
    62         $t =~ s/$WC::STARTWW($TWiki::regex{wikiWordRegex})/<nop>$1/go;
    63         $t =~ s/$WC::STARTWW($TWiki::regex{abbrevRegex})/<nop>$1/go;
    64         $t =~ s/\[/<nop>[/g;
    65     }
    66     unless ($options & $WC::KEEP_ENTITIES) {
    67         $t =~ s/&($text_entities_re);/chr($text_entities{$1})/ego;
    68         $t =~ s/&nbsp;/$WC::NBSP/g;
    69     }
    70     return (0, $t);
    71 }
    72 
    73 sub stringify {
    74     my $this = shift;
    75     return $this->{text};
    76 }
    77 
    78 sub isInline {
    79     return 1;
    80 }
    81 
    82 1;