App-sdview
view release on metacpan or search on metacpan
lib/App/sdview/Parser/Pod.pm view on Meta::CPAN
);
$self->reset_tags;
}
method start_code { $self->_start_highlighter( \%_next_verbatim_options ); }
method end_code { undef $_redirect_text; }
method start_for ( $attrs )
{
my $target = $attrs->{target};
my $code = $self->can( "start_for_$target" ) or return;
return $self->$code( $attrs );
}
method end_for { undef $_redirect_text; }
method start_for_highlighter { $self->_start_highlighter( \%_verbatim_options ) }
method start_for_table ( $attrs )
{
my @spec = split m/\s+/, $attrs->{title} // "";
$spec[0] = "style=$spec[0]" if @spec and $spec[0] !~ m/=/;
my %spec = map { m/^(.*?)=(.*)$/ ? ( $1, $2 ) : () } @spec;
my $style = $spec{style} // "md";
$style eq "md" and
$_redirect_text = \&_handle_text_table_md, return;
$style eq "mediawiki" and
$_redirect_text = \&_handle_text_table_mediawiki, return;
warn "TODO unrecognised table style $style\n";
}
method _start_highlighter ( $options )
{
$_redirect_text = method ( $text ) {
my @args = split m/\s+/, $text;
$args[0] = "language=$args[0]" if @args and $args[0] !~ m/=/;
%$options = ();
foreach ( @args ) {
my ( $key, $val ) = m/^(.*?)=(.*)$/ or next;
$options->{$key} = $val;
}
};
}
method start_S { $_conv_nbsp = 1; }
method end_S { undef $_conv_nbsp; }
role App::sdview::Parser::Pod::_TagHandler {
ADJUST {
$self->nix_X_codes( 1 );
$self->accept_codes(qw( U ));
}
field %_curtags :reader;
method reset_tags { %_curtags = (); }
method start_B { $_curtags{bold}++ }
method end_B { delete $_curtags{bold} }
method start_I { $_curtags{italic}++ }
method end_I { delete $_curtags{italic} }
method start_U { $_curtags{underline}++ }
method end_U { delete $_curtags{underline} }
method start_C { $_curtags{monospace}++ }
method end_C { delete $_curtags{monospace} }
method start_F { $_curtags{file}++ }
method end_F { delete $_curtags{file} }
method start_L ( $attrs )
{
my $uri = $attrs->{to};
# TODO: more customizable
if( defined $uri and $uri !~ m(^\w+://) ) {
$uri = "https://metacpan.org/pod/$uri";
}
$_curtags{link} = { uri => $uri };
}
method end_L { delete $_curtags{link} }
}
apply App::sdview::Parser::Pod::_TagHandler;
method start_over_block ( $attrs )
{
push @_indentstack, $_indentstack[-1] + $attrs->{indent};
}
method end_over_block
{
pop @_indentstack;
}
method start_over_number ( $attrs ) { $self->_start_over( number => $attrs ); }
method start_over_bullet ( $attrs ) { $self->_start_over( bullet => $attrs ); }
method start_over_text ( $attrs ) { $self->_start_over( text => $attrs ); }
method _start_over ( $type, $attrs )
{
push $_parastack[-1]->@*, App::sdview::Para::List->new(
listtype => $type,
indent => $_indentstack[-1] + $attrs->{indent},
);
push @_parastack, [];
undef $_curpara;
}
method end_over_number { $self->_end_list( number => ); }
method end_over_bullet { $self->_end_list( bullet => ); }
method end_over_text { $self->_end_list( text => ); }
method _end_list ( $type )
{
my @items = ( pop @_parastack )->@*;
$_parastack[-1][-1]->push_item( $_ ) for @items;
}
method start_item_number { $self->_start_item( number => ); }
method start_item_bullet { $self->_start_item( bullet => ); }
method _start_item ( $type )
{
push $_parastack[-1]->@*, $_curpara = App::sdview::Para::ListItem->new(
listtype => $type,
text => String::Tagged->new,
( run in 0.665 second using v1.01-cache-2.11-cpan-39bf76dae61 )