Source

perl-begin / lib / VimIface.pm

package VimIface;

use strict;
use warnings;

use Text::VimColor;

sub is_newer
{
    my $file1 = shift;
    my $file2 = shift;
    my @stat1 = stat($file1);
    my @stat2 = stat($file2);
    if (! @stat2)
    {
        return 1;
    }
    return ($stat1[9] >= $stat2[9]);
}

sub get_syntax_highlighted_html_from_file
{
    my (%args) = (@_);

    my $filename = $args{'filename'};

    my $html_filename = "$filename.html-for-quad-pres";

    if (is_newer( $filename, $html_filename))
    {
        my $syntax = Text::VimColor->new(
            file => $filename,
            html_full_page => 1,
            ($args{'filetype'} ? (filetype => $args{'filetype'}) : ()),
        );

        open my $out, ">", $html_filename
            or die "Could not open HTML file '$html_filename' for output - $!";

        print {$out} $syntax->html();
        close($out);
    }

    open my $in, "<", $html_filename
        or die "Could not open HTML file '$html_filename' for input - $!";
    my $text = do { local $/; <$in> };
    close($in);

    $text =~ s{^.*<pre>[\s\n\r]*}{}s;
    $text =~ s{[\s\n\r]*</pre>.*$}{}s;
    $text =~ s{(class=")syn}{$1}g;

    return $text;
}

1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.