App-sdview

 view release on metacpan or  search on metacpan

lib/App/sdview.pm  view on Meta::CPAN

      $_->can( "format" ) and say "  " . $_->format . "  (provided by $_)"
         for @OUTPUT_CLASSES;
      exit 0;
   }

   if( -f( my $configpath = "$ENV{HOME}/.sdviewrc" ) ) {
      App::sdview::Style->load_config( $configpath );
   }

   my %output_options = map {
      map { m/^(.*?)=(.*)$/ ? ( $1 => $2 ) : ( $_ => !!1 ) } split m/,/, $_;
   } $output_options->@*;

   my $parser_class;

   if( defined $format ) {
      $parser_class = first { $_->can( "format" ) and $_->format eq $format } @PARSER_CLASSES or
         die "Unrecognised format name $format\n";
   }

   if( !defined $file ) {

lib/App/sdview/Output/Man.pm  view on Meta::CPAN

   $self->say( ".PP" ) unless $_current_mode eq "PP";
   $_current_mode = "";

   $self->say( $self->_convert_str( $para->text ) );
}

method output_verbatim ( $para )
{
   $self->say( ".EX" );

   $self->say( $_ ) for split m/\n/, $para->text;

   $self->say( ".EE" );
}

method output_list_bullet ( $para ) { $self->_output_list( $para ); }
method output_list_text   ( $para ) { $self->_output_list( $para ); }

method _output_list ( $para )
{
   foreach my $item ( $para->items ) {

lib/App/sdview/Output/Pod.pm  view on Meta::CPAN

   $self->maybe_blank;

   $self->say( $self->_convert_str( $para->text ) );
}

method output_verbatim ( $para )
{
   $self->say( "=pod" ), $_printed_pod = 1 unless $_printed_pod;
   $self->maybe_blank;

   $self->say( "    ", $_ ) for split m/\n/, $para->text;
}

method output_list_bullet ( $para ) { $self->_output_list( $para ); }
method output_list_number ( $para ) { $self->_output_list( $para ); }
method output_list_text   ( $para ) { $self->_output_list( $para ); }

method _output_list ( $para )
{
   $self->maybe_blank;

lib/App/sdview/Parser/Markdown.pm  view on Meta::CPAN

   return $self->parse_string( read_text $fh );
}

field @_paragraphs;

sub _split_table_row ( $str )
{
   $str =~ m/^\s*\|/ or return undef;
   $str =~ m/\|\s*$/ or return undef;

   my @cols = split m/\|/, $str, -1;
   shift @cols; pop @cols;

   s/^\s+//, s/\s+$// for @cols;

   return \@cols;
}

method parse_string ( $str )
{
   my $in_verb;

lib/App/sdview/Parser/Pod.pm  view on Meta::CPAN

   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;
      }
   };
}

lib/App/sdview/Parser/Pod.pm  view on Meta::CPAN

      return $self->$_redirect_text( $text );
   }

   $text =~ s/ /\xA0/g if $_conv_nbsp;

   $_curpara->append_text( $text, $self->curtags );
}

method _handle_text_table_md ( $text )
{
   my @lines = split m/\n/, $text
      or return;

   my @rows;
   push @rows, _split_table_row( shift @lines );

   my $heading = !!0;
   my @align;
   my $alignspec = _split_table_row( shift @lines );
   if( all { $_ =~ m/^(:?)-{3,}(:?)$/ } @$alignspec ) {
      $heading = !!1;

lib/App/sdview/Parser/Pod.pm  view on Meta::CPAN

      rows => \@rows
   );
}

sub _split_table_row ( $str )
{
   # Leading/trailing pipes are optional
   $str =~ s/^\s*\|//;
   $str =~ s/\|\s*$//;

   my @cols = split m/\|/, $str;
   s/^\s+//, s/\s+$// for @cols;

   # TODO: Find out why these parsers aren't reusable
   $_ = App::sdview::Parser::Pod::_TableCellParser->new->parse_string( $_ ) for @cols;

   return \@cols;
}

method _handle_text_table_mediawiki ( $text )
{
   my @lines = split m/\n/, $text
      or return;

   my @rows;
   foreach my $line ( @lines ) {
      $line =~ m/^\|-/ and
         push @rows, [] and next;

      $line =~ s/^([!|])\s*// or
         warn "Unsure what to do with line $line" and next;
      my $chr = $1;
      my $heading = ( $chr eq "!" );

      foreach my $cell ( split m/\s*\Q$chr$chr\E\s*/, $line ) {
         @rows or push @rows, [];
         push $rows[-1]->@*, App::sdview::Para::TableCell->new(
            align => "left", # TODO
            heading => $heading,
            text => App::sdview::Parser::Pod::_TableCellParser->new->parse_string( $cell ),
         );
      }
   }

   push $_parastack[-1]->@*, App::sdview::Para::Table->new(

lib/App/sdview/Style.pm  view on Meta::CPAN


   'string.special' => { fg => "vga:red" },
   'function.builtin' => { fg => "xterm:147", bold => 1 },
);
$HIGHLIGHTSTYLES{$_} = { fallback => "keyword"  } for qw( include repeat conditional exception );
$HIGHLIGHTSTYLES{$_} = { fallback => "function" } for qw( method );
_fixup_colour_keys $_ for values %HIGHLIGHTSTYLES;

sub highlight_style ( $pkg, $key )
{
   my @nameparts = split m/\./, $key;
   while( @nameparts ) {
      my $style = $HIGHLIGHTSTYLES{ join ".", @nameparts } or
         pop( @nameparts ), next;

      if( keys( $style->%* ) == 1 and defined( my $fbkey = $style->{fallback} ) ) {
         return $pkg->highlight_style( $fbkey );
      }

      return $style;
   }



( run in 0.922 second using v1.01-cache-2.11-cpan-62a16548d74 )