Tk-Markdown

 view release on metacpan or  search on metacpan

lib/Tk/Markdown.pm  view on Meta::CPAN

        ### HEADERS
        [qr/^#[^#].*$/m, 'h1', qr/^#\s*(?=[^#])/m ,''],
        [qr/^##[^#].*$/m, 'h2', qr/^##\s*(?=[^#])/m, ''],
        [qr/^###[^#].*$/m, 'h3', qr/^###\s*(?=[^#])/m, ''],
        [qr/^####[^#].*$/m, 'h4', qr/^####\s*(?=[^#])/m, ''],
        [qr/^#####[^#].*$/m, 'h5', qr/^#####\s*(?=[^#])/m, ''],
        [qr/^######[^#].*$/m, 'h6', qr/^######\s*(?=[^#])/m, ''],
        
        ### TABLES
        [qr/^\|.*\|$|^-+$|^\s\s\s\s/m, 'code', '', ''],
        
        ### LISTS
        [qr/^\*[^*].*$/m, 'list', qr/^\*(?=[^*])/, "   \x{2022} "],
        [qr/^\*\*[^*].*$/m, 'list', qr/^\*\*(?=[^*])/, "      \x{25E6} "],
        [qr/^\*\*\*[^*].*$/m, 'list', qr/^\*\*\*(?=[^*])/, "         \x{2022} "],
        [qr/^\*\*\*\*[^*].*$/m, 'list', qr/^\*\*\*\*(?=[^*])/, "            \x{25E6} "],
        [qr/^\*\*\*\*\*[^*].*$/m, 'list', qr/^\*\*\*\*\*(?=[^*])/, "               \x{2022} "],
        [qr/^\*\*\*\*\*\*[^*].*$/m, 'list', qr/^\*\*\*\*\*\*(?=[^*])/, "                  \x{25E6} "],
      
        ### CODE
        [qr/^\s\s\s\s.*$/m, 'code', '', ''],
    );
    
    foreach(@rules) {
        my ($re,$tag,$search,$replace) = @$_;
        $self->FindAll('-regexp','-case', $re );
        my @i = $self->tagRanges('sel');
        $self->tagAdd($tag,@i) if @i;
        if($search){
            #print "$search\n";
            $self->FindAndReplaceAll('-regexp','-case', $search, $replace);
        }
    }
}


=head2 clipEvents

This copied directly from L<Tk::ROText>.

=cut

sub clipEvents {
    return qw[Copy];
}


=head2 ClassInit

This is copied directly from L<Tk::ROText>.

=cut

sub ClassInit {
    my ($class,$mw) = @_;
    my $val = $class->bindRdOnly($mw);
    my $cb = $mw->bind($class,'<Next>');
    $mw->bind($class,'<space>',$cb) if (defined $cb);
    $cb = $mw->bind($class,'<Prior>');
    $mw->bind($class,'<BackSpace>', $cb) if (defined $cb);
    $class->clipboardOperations($mw,'Copy');
    return $val;
}


=head2 Populate

This is copied and modified from L<Tk::ROText>. The modification is the addition of a call to C<setDefaultStyles>. That's all.

=cut

sub Populate {
    my ($self,$args) = @_;
    $self->SUPER::Populate($args);
    my $m = $self->menu->entrycget($self->menu->index('Search'), '-menu');
    $m->delete($m->index('Replace'));
    $self->ConfigSpecs(-background=>['SELF'], -foreground=>['SELF'],);
    $self->defaultStyles(); ### Jimi added this line... does a bit more setup.
}


=head2 Tk::Widget::ScrlMarkdown

Copied and adapted from L<Tk::ROText>.

=cut

sub Tk::Widget::ScrlMarkdown { shift->Scrolled('Markdown' => @_) }


=head1 SEE ALSO

L<Tk::MarkdownTk>, L<Tk::Text>


=head1 AUTHOR

Jimi Wills.

Currently maintained by Alexander Becker.

=head1 BUGS

Known issue: Tables do not work.

Please report any bugs or feature requests via GitHub: L<https://github.com/asb-capfan/Tk-Markdown>




=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Tk::Markdown


You can also look for information at:

=over 4



( run in 3.988 seconds using v1.01-cache-2.11-cpan-84e82930d8c )