Skip to content

Commit

Permalink
Item14323: convert unbulleted lists to a list type instead of a div. …
Browse files Browse the repository at this point in the history
…This uses some new classes which require a core change, so the fix won't be complete until that core change is made. However it should work even without the core change (it's a display problem only)
  • Loading branch information
cdot committed Mar 10, 2017
1 parent 9a88996 commit 05fd015
Show file tree
Hide file tree
Showing 3 changed files with 302 additions and 187 deletions.
87 changes: 36 additions & 51 deletions WysiwygPlugin/lib/Foswiki/Plugins/WysiwygPlugin/HTML2TML/Node.pm
Original file line number Diff line number Diff line change
Expand Up @@ -754,30 +754,6 @@ sub _isProtectedByAttrs {
return 0;
}

sub _convertIndent {
my ( $this, $options ) = @_;
my $indent = $WC::TAB;

my ( $f, $t ) = $this->_handleP($options);
return $t unless Foswiki::Func::getContext->{SUPPORTS_PARA_INDENT};

if ( $t =~ /^$WC::WS_NOTAB*($WC::TAB+):(.*)$/ ) {
return "$WC::CHECKn$1:$2";
}

# Zoom up through the tree and see how many layers of indent we have
my $p = $this;
while ( $p = $p->{parent} ) {
if ( $p->{tag} eq 'div' && $p->hasClass('foswikiIndent') ) {
$indent .= $WC::TAB;
}
}
$t =~ s/^$WC::WS*//s;
$t =~ s/$WC::WS*$//s;
$t = "$WC::CHECKn$indent: " . $t;
return $t;
}

# perform conversion on a list type
sub _convertList {
my ( $this, $indent ) = @_;
Expand All @@ -788,10 +764,29 @@ sub _convertList {
$basebullet = '';
}
elsif ( $this->{tag} eq 'ol' ) {
$basebullet = '1';
if ( $this->hasClass('foswikiListStyleA') ) {
$basebullet = 'A.';
}
elsif ( $this->hasClass('foswikiListStylea') ) {
$basebullet = 'a.';
}
elsif ( $this->hasClass('foswikiListStyleI') ) {
$basebullet = 'I.';
}
elsif ( $this->hasClass('foswikiListStylei') ) {
$basebullet = 'i.';
}
else {
$basebullet = '1.';
}
}
else {
$basebullet = '*';
else { # ul
if ( $this->hasClass('foswikiListStyleNone') ) {
$basebullet = ':';
}
else {
$basebullet = '*';
}
}

my $f;
Expand Down Expand Up @@ -824,10 +819,7 @@ sub _convertList {
next;
}
my $bullet = $basebullet;
if ( $basebullet eq '1' && $kid->{attrs}->{type} ) {
$bullet = $kid->{attrs}->{type} . '.';
}
my $spawn = '';
my $spawn = '';
my $t;
my $grandkid = $kid->{head};
if ($grandkid) {
Expand Down Expand Up @@ -880,16 +872,6 @@ sub _convertList {
return $text;
}

sub _isConvertableIndent {
my ( $this, $options ) = @_;

return 0 unless Foswiki::Func::getContext->{SUPPORTS_PARA_INDENT};

return 0 if ( $this->_isProtectedByAttrs() );

return $this->{tag} eq 'div' && $this->hasClass('foswikiIndent');
}

# probe down into a list type to determine if it
# can be converted to TML.
sub _isConvertableList {
Expand Down Expand Up @@ -1572,13 +1554,22 @@ sub _handleB {
|| $this->{parent}->{tag} eq 'th' )
)
{
# Item9651: Don't convert bold in a table cell into stars
# if the TML would be interpreted as a heading
my $left = $this->{prev} ? $this->{prev}->stringify() : '';
my $right = $this->{next} ? $this->{next}->stringify() : '';
if ( "$left$right" =~ /^\s*$/ ) {

# Item9651: Don't convert bold in a table cell into stars
# if the TML would be interpreted as a heading
return ( 0, undef );
# Have to exclude ==this case== and __that case__ as
# they look awfully similar but don't generate table
# headings
my ( $foo, $t ) = _emphasis( @_, '*' );
if ( $t !~ /.*?$WC::CHECK1(==|__).*\1$WC::CHECK2/ ) {
return ( 0, undef );
}
else {
return ( $foo, $t );
}
}
}
}
Expand Down Expand Up @@ -1640,13 +1631,7 @@ sub _handleDFN { return _flatten(@_); }

sub _handleDIV {
my ( $this, $options ) = @_;

if ( ( $options & WC::NO_BLOCK_TML )
|| !$this->_isConvertableIndent( $options | WC::NO_BLOCK_TML ) )
{
return $this->_handleP($options);
}
return ( WC::BLOCK_TML, $this->_convertIndent($options) );
return $this->_handleP($options);
}

sub _handleDL { return _LIST(@_); }
Expand Down
Loading

0 comments on commit 05fd015

Please sign in to comment.