Changeset 3875
- Timestamp:
- 05/10/09 16:02:03 (3 years ago)
- Location:
- trunk/WysiwygPlugin
- Files:
-
- 4 edited
-
lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML.pm (modified) (2 diffs)
-
lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm (modified) (5 diffs)
-
lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm (modified) (1 diff)
-
test/unit/WysiwygPlugin/TranslatorTests.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML.pm
r2957 r3875 66 66 67 67 my $this = new HTML::Parser( 68 start_h => [ \&_openTag, 'self,tagname,attr' ], 69 end_h => [ \&_closeTag, 'self,tagname' ], 70 declaration_h => [ \&_ignore, 'self' ], 71 default_h => [ \&_text, 'self,text' ], 72 comment_h => [ \&_comment, 'self,text' ] 68 start_h => [ \&_openTag, 'self,tagname,attr' ], 69 end_h => [ \&_closeTag, 'self,tagname' ], 70 text_h => [ \&_text, 'self,text' ], 71 comment_h => [ \&_comment, 'self,text' ], 72 declaration_h => [ \&_ignore, 'self' ], 73 start_document_h => [ \&_ignore, 'self' ], 74 end_document_h => [ \&_ignore, 'self' ], 75 default_h => [ \&_default, 'self,event,text' ] 73 76 ); 74 77 … … 220 223 } 221 224 225 sub _default { 226 my ( $this, $event, $text ) = @_; 227 # Unexpected $event event from HTML::Parser; text contains '$text' 228 ASSERT(0); 229 } 230 222 231 sub _apply { 223 232 my ( $this, $tag ) = @_; -
trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm
r3396 r3875 363 363 364 364 # Collapse adjacent VERBATIM nodes together 365 # Collapse a <p> tha ncontains only a protected span into a protected P365 # Collapse a <p> that contains only a protected span into a protected P 366 366 # Collapse em in em 367 367 # Collapse adjacent text nodes … … 444 444 } 445 445 446 # If this node has the specified class, insert a new "span" node with that 447 # class between this node and all of this node's children. 448 sub _moveClassToSpan 449 { 450 my $this = shift; 451 my $class = shift; 452 453 if ( $this->{tag} and 454 lc($this->{tag}) ne 'span' and 455 $this->_removeClass($class) ) { 456 457 my $newspan = new Foswiki::Plugins::WysiwygPlugin::HTML2TML::Node( $this->{context}, 'span', { class => $class } ); 458 my $kid = $this->{head}; 459 while ($kid) { 460 $newspan->addChild($kid); 461 $kid = $kid->{next}; 462 } 463 $this->{head} = $this->{tail} = $newspan; 464 } 465 } 466 446 467 # the actual generate function. rootGenerate is only applied to the root node. 447 468 sub generate { … … 487 508 $tag =~ s/!//; # DOCTYPE 488 509 my $tmlFn = '_handle' . uc($tag); 510 511 $this->_moveClassToSpan('WYSIWYG_TT'); 489 512 490 513 # See if we have a TML translation function for this tag … … 839 862 while ($kid) { 840 863 if ( $kid->{tag} eq 'th' ) { 864 $kid->_moveClassToSpan('WYSIWYG_TT'); 841 865 ( $flags, $text ) = $kid->_flatten($options); 842 866 $text = _TDtrim($text); … … 844 868 } 845 869 elsif ( $kid->{tag} eq 'td' ) { 870 $kid->_moveClassToSpan('WYSIWYG_TT'); 846 871 ( $flags, $text ) = $kid->_flatten($options); 847 872 $text = _TDtrim($text); -
trunk/WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/TML2HTML.pm
r3396 r3875 470 470 (CGI::span({class => 'WYSIWYG_TT'}, $1))gem; 471 471 472 # Handle [[][] and [[]] links472 # Handle [[][]] and [[]] links 473 473 474 474 # We _not_ support [[http://link text]] syntax -
trunk/WysiwygPlugin/test/unit/WysiwygPlugin/TranslatorTests.pm
r3396 r3875 39 39 my $HTML2TML = 1 << 1; # test html => finaltml (default tml) 40 40 my $ROUNDTRIP = 1 << 2; # test tml => => finaltml 41 # Note: ROUNDTRIP is *not* the same as the combination of 42 # HTML2TML and TML2HTML. The HTML and TML comparisons are both 43 # somewhat "flexible". This is necessry because, for example, 44 # the nature of whitespace in the TML may change. 45 # ROUNDTRIP tests are intended to isolate gradual degradation 46 # of the TML, where TML -> HTML -> not quite TML -> HTML 47 # -> even worse TML, ad nauseum 41 48 42 49 # Bit mask for selected test types … … 55 62 56 63 # Each testcase is a subhash with fields as follows: 57 # exec => 1 to test TML -> HTML, 2 to test HTML -> TML, 3 to 58 # test both, anything else to skin the test. 64 # exec => $TML2HTML to test TML -> HTML, $HTML2TML to test HTML -> TML, 65 # $ROUNDTRIP to test TML-> ->TML, all other bits are ignored. 66 # They may be OR'd togoether to perform multiple tests. 67 # For example: $TML2HTML | $HTML2TML to test both 68 # TML -> HTML and HTML -> TML 59 69 # name => identifier (used to compose the testcase function name) 60 70 # tml => source topic meta-language 61 # html => expected html from expanding tml 71 # html => expected html from expanding tml (not used in roundtrip tests) 62 72 # finaltml => optional expected tml from translating html. If not there, 63 73 # will use tml. Only use where round-trip can't be closed because … … 152 162 }, 153 163 { 164 exec => $TML2HTML | $HTML2TML, 165 name => 'codeToFromHtml', 166 html => <<'BLAH', 167 <p> 168 <span class="WYSIWYG_TT">Code</span> 169 </p> 170 BLAH 171 tml => '=Code=' 172 }, 173 { 154 174 exec => $ROUNDTRIP, 155 175 name => 'strongCode', 156 176 html => '<b><code>Bold Code</code></b>', 157 177 tml => '==Bold Code==' 178 }, 179 { 180 exec => $TML2HTML | $HTML2TML, 181 name => 'bToFromHtml', 182 html => '<p><b>Bold</b></p>', 183 tml => '*Bold*' 184 }, 185 { 186 exec => $TML2HTML | $HTML2TML, 187 name => 'strongCodeToFromHtml', 188 html => <<'BLAH', 189 <p> 190 <b><span class="WYSIWYG_TT">Code</span></b> 191 </p> 192 BLAH 193 tml => '==Code==' 194 }, 195 { 196 exec => $HTML2TML, 197 name => 'spanWithTtClassWithStrong', 198 html => <<'BLAH', 199 <p> 200 <span class="WYSIWYG_TT"><strong>Code</strong></span> 201 </p> 202 BLAH 203 tml => '==Code==' 204 }, 205 { 206 exec => $HTML2TML, 207 name => 'strongWithSpanWithTtClass', 208 html => <<'BLAH', 209 <p> 210 <strong><span class="WYSIWYG_TT">Code</span></strong> 211 </p> 212 BLAH 213 tml => '==Code==' 214 }, 215 { 216 exec => $HTML2TML, 217 name => 'strongWithTtClass', 218 html => <<'BLAH', 219 <p> 220 <strong class="WYSIWYG_TT">Code</strong> 221 </p> 222 BLAH 223 tml => '==Code==' 224 }, 225 { 226 exec => $HTML2TML, 227 name => 'bWithTtClass', 228 html => "<p>\n<b class=\"WYSIWYG_TT\">Code</b>\n</p>", 229 tml => '==Code==' 230 }, 231 { 232 exec => $HTML2TML | $ROUNDTRIP, 233 name => 'ttClassInTable', 234 html => '<table><tr><td class="WYSIWYG_TT">Code</td></tr></table>', 235 tml => '| =Code= |' 158 236 }, 159 237 {
Note: See TracChangeset
for help on using the changeset viewer.
