# Plugin for TWiki Collaboration Platform, http://TWiki.org/ # # Copyright (C) 2005-2018 TWiki Contributor. # Copyright (C) 2005 ILOG http://www.ilog.fr # Copyright (C) 2008-2010 Foswiki Contributors. # All Rights Reserved. TWiki Contributors are listed in the # AUTHORS file in the root of this distribution. # NOTE: Please extend that file, not this notice. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 3 # of the License, or (at your option) any later version. For # more details read LICENSE in the root of the TWiki distribution. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # As per the GPL, removal of this notice is prohibited. =pod ---+ package TWiki::Plugins::WysiwygPlugin::TML2HTML Convertor class for translating TML (TWiki Markup Language) into HTML The convertor does _not_ use the TWiki rendering, as that is a lossy conversion, and would make symmetric translation back to TML an impossibility. The design goal was to support round-trip conversion from well-formed TML to XHTML1.0 and back to identical TML. Notes that some deprecated TML syntax is not supported. =cut package TWiki::Plugins::WysiwygPlugin::TML2HTML; use CGI qw( -any ); use Error qw( :try ); use TWiki; use TWiki::Plugins::WysiwygPlugin::Constants; use TWiki::Plugins::WysiwygPlugin::Handlers; use strict; use warnings; # Used by _takeOutBlocks/_putBackBlocks our $BLOCKID = 0; our $OC = ""; # SMELL: If special characters are added here, they must also be accounted # for in the sub _protectVerbatimChars my $TT0 = chr(0); my $TT1 = chr(1); my $TT2 = chr(2); my $TT3 = chr(3); # Temporarily hides noautolink %macros at various points # HTML elements that are palatable to editors. Other HTML tags will be # rendered in 'protected' regions to prevent the WYSIWYG editor mussing # them up. Note that A is specifically excluded from this list because it # is common for href attributes to contain variables. Users should # be encouraged to use square bracket formulations for links instead. my @PALATABLE_TAGS = qw( ABBR ACRONYM ADDRESS B BDO BIG BLOCKQUOTE BR CAPTION CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FONT H1 H2 H3 H4 H5 H6 HR HTML I IMG INS ISINDEX KBD LABEL LEGEND LI OL P PRE Q S SAMP SMALL SPAN STRONG SUB SUP TABLE TBODY TD TFOOT TH THEAD TITLE TR TT U UL STICKY ); my $PALATABLE_HTML = '(' . join( '|', @PALATABLE_TAGS ) . ')'; # There are several tags that could come before a table tag my @tagsBeforeTable = ( '
\s*
', # from HTML tables not in sticky or literal blocks ); my $tagsBeforeFirstTablePattern = '^\\s*(?:' . join( '|', map { $_ . '\\s*' } @tagsBeforeTable ) . ')?