Tk-Markdown
view release on metacpan or search on metacpan
lib/Tk/Markdown.pm view on Meta::CPAN
package Tk::Markdown;
use 5.006;
use strict;
use warnings FATAL => 'all';
=head1 NAME
Tk::Markdown - display Markdown in a Text
=cut
our $VERSION = '0.08';
use base qw(Tk::Derived Tk::Text);
use Tk::Font;
#use Tk::Carp qw/fatalsToDialog warningsToDialog tkDeathsNonFatal/;
## commented out Tk::carp because it is not available in ppm.
Construct Tk::Widget 'Markdown';
=head1 SYNOPSIS
use Tk;
use Tk::Markdown;
my $mw = Tk::MainWindow->new();
my $mdt = $mw->Markdown();
my $markdown = q~# Heading 1
## Heading 2
### Heading 3
#### Heading 4
##### Heading 5
###### Heading 6
* list 1
** list 2
*** list 3
**** list 4
***** list 5
****** list 6
Source shown in monofont
another line of source code here
~;
$mdt->insert('0.0', $markdown);
=head1 DESCRIPTION
Tk::Markdown is a widget to render L<Markdown|https://en.wikipedia.org/wiki/Markdown> in a L<Tk::Text> widget.
=head1 METHODS
=head2 insert
Whenever insert is called on the Markdown widget, some translation is done on the text in order to display it nicely as Markdown.
Tables are reformatted (if the line starts with a bar) and headers are tagged with different fonts.
This module has very basic support for Markdown and there is still plenty to do, e.g. links, images, etc.
=cut
### add the processing functionality to the insert method
sub insert {
my ($self,$index,$content) = @_;
my $res = $self->SUPER::insert($index,FormatMarkdown($content));
if(! $self->{inserting}) { ### don't allow recursion...
$self->{inserting} = 1;
$self->PaintMarkdown();
# $self->TransformTk();
( run in 0.482 second using v1.01-cache-2.11-cpan-a1f116cd669 )