IkiWiki-Plugin-syntax

 view release on metacpan or  search on metacpan

lib/IkiWiki/Plugin/syntax/base.pm  view on Meta::CPAN

    my  $fail       =   shift;
    my  $error_msg  =   undef;

    if (not $fail) {
        $error_msg = gettext(q(unknown exception));
    }
    elsif (ref($fail)) {
        $error_msg = $fail->full_message();
    }
    else {
        $error_msg = $fail;
    }

    return sprintf 'syntax (%s) on page %s: %s', 
                    $self->engine() || 'undef', 
                    $self->page() || 'none',                        
                    $error_msg;
}

sub engine {
    my  $self   =   shift;

    if (ref $self) {
        return ref $self;
    }
    else {
        return '';
    }
}


sub plugin_info {
    my  ($self,@params)   =   @_;
    my  %info = (
        name        =>  undef,      # shorten plugin name 
        version     =>  undef,      # version number
        description =>  undef,      # human readable description
        special     =>  undef,      # special features
        bugs        =>  undef,      # bugs or missing features
        external    =>  undef,      # external modules 
        linenumbers =>  0,
        bars        =>  0,
        supported   =>  [],
    );

    if ($self->can('build_plugin_info')) {
        %info = $self->build_plugin_info(@params);
    }
    else {
        # fill with harmless values
        $info{name}         = q(None);
        $info{description}  = gettext(q(No external plugin available));
    }

    return %info;        
}

sub _split_htmlized {
    my  $self   =   shift;

    return split m{\n}xms, $self->htmlized();
}

sub _join_html_lines {
    my  ($self,@lines)   =   @_;

    return join "\n", @lines;
}

sub syntax_highlight {
    my  ($self, %params)    =  @_;

    ## configure engine
    $self->configure( %params );

    ## is the language missing ? 
    if (not $self->language()) {
        Syntax::X::Parameters::Wrong->throw( 
            message => gettext('missing language for source highlight'),
            );
    }

    ## do we have a source text ? 
    if (not $self->source()) {
        Syntax::X::Parameters::Source->throw();
    }

    ## is the language supported ? 
    if (not $self->can_syntax_from( proposed => $self->language() )) {
        Syntax::X::Engine::Language->throw( language => $self->language() );
    }

    ## parse the source and add html tags
    $self->parse_and_html( );

    ## normalize the css tags 
    $self->normalize_tags( );

    ## are the lines numered ?
    if ($self->linenumbers()) {
        $self->to_number_lines( );
    }

    ## is the output barred ? 
    if ($self->bars()) {
        $self->to_bar_lines();
    }

    ## future updates: format comments ? 

    ## save the htmlized to the final target
    return $self->output( $self->htmlized() );
}

sub normalize_tags {
    my  $self   =   shift;

    return $self;
}

sub parse_and_html {



( run in 2.242 seconds using v1.01-cache-2.11-cpan-71847e10f99 )