[dokuwiki] Re: FCKW wysiwyg plugin published

  • From: Spring Pierre <pierre.spring@xxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Wed, 9 Jan 2008 09:41:01 +0100

dear myron,

i added s.th. to your DokuWikiFCK.pm solution ( thanks or that ;) in order to get rid of any html within headers. taken the fact that

    <h1><i>Myron</i> Turner</h1>

was rendered to

    ====== //Myron// Turner ======

you just need to add the following lines in the rules definition:

*********************************

  # overwrite rules for h1 to h5
  for( 1..5 ) {
    $rules->{"h$_"} = { replace => \&_header };
  }
  # there is no h6 in dokuwiki syntax!!!
  # remove the rule from the super class
  $rules->{h6} = { start => '', end => ''};

*********************************

and define the following 3 subroutines:

*********************************

# dokuwiki does not allow any syntax within
# headers, so here we clean those
sub _header {
    my($self, $node, $rules ) = @_;

    # remove html nodes from content
    my $text = $self->_as_text($node);

    # get header level
    $node->tag =~ /(\d)/;

    # get pre and postfix for dokuwiki syntax
    # and pre/append those
    my $pre_and_post_fix = "=" x (7 - $1);
    my $str = $pre_and_post_fix . $text . $pre_and_post_fix;
    return $str;
}

# this helper is used for the header subroutine, in
# order to return the text without any html tags.
# ( we can not use the $node->as_text() methode, as the
#   WikiConverter parsed it into a <~text text="content">
#   tag... )
sub _as_text {
    my($self, $node) = @_;
my $text = join '', map { $self->__get_text($_) } $node- >content_list;
    return defined $text ? $text : '';
}

# this helper is used for the header subroutine, in
# order to return the text without any html tags.
# ( we can not use the $node->as_text() methode, as the
#   WikiConverter parsed it into a <~text text="content">
#   tag... )
sub __get_text {
    my($self, $node) = @_;
    $node->normalize_content();
    if( $node->tag eq '~text' ) {
        # we return text nodes
        return $node->attr('text');
    } elsif( $node->tag eq '~comment' ) {
        # we keep comments
        return '<!--' . $node->attr('text') . '-->';
    } else {
        # recurse
        my $output = $self->_as_text($node)||'';
        return $output;
    }
}

*********************************

this is my first atempt in coding perl. it's not easy to get into it. if you see s.th. really ugly, please let me know. i hope you can use this.

greetings.
pierre.
--
Liip AG // Rte de la Fonderie 7 // CH-1700 Fribourg
Fon 026 4222511 // Key id 0x5BF5F8FA // www.liip.ch




--
DokuWiki mailing list - more info at
http://wiki.splitbrain.org/wiki:mailinglist

Other related posts: