1. Shlomi Fish
  2. perl-begin

Commits

Shlomi Fish  committed 9f57915

Syntax highlighting using Text::VimColor.

  • Participants
  • Parent commits 331c800
  • Branches default

Comments (0)

Files changed (7)

File .hgignore

View file
  • Ignore whitespace
 rules.mak
 .sass-cache
 src/style.css
+src/vim_syntax_highlighting.css
 temp
 compile/

File Makefile

View file
  • Ignore whitespace
 
 run_compass: src/style.css
 
-src/style.css: config.rb lib/sass/style.sass lib/sass/print.sass
+src/style.css: config.rb lib/sass/style.sass lib/sass/print.sass lib/sass/vim_syntax_highlighting.sass
 	compass compile
 
 dest/humour/index.html: lib/retrieved-html-parts/Perl_Humour.html

File lib/VimIface.pm

View file
  • Ignore whitespace
+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;
+

File lib/sass/style.sass

View file
  • Ignore whitespace
 
 .study_group
     :margin-top 2em
+
+@import "vim_syntax_highlighting"

File lib/sass/vim_syntax_highlighting.sass

View file
  • Ignore whitespace
+/* Vim-HTML markup codes
+.Comment
+    color: #0000ff
+.Constant
+    color: #ff00ff
+.Identifier
+    color: #008b8b
+.Special
+    color: #6a5acd
+.Statement
+    color: #a52a2a
+    font-weight: bold
+.PreProc
+    color: #a020f0
+.Type
+    color: #2e8b57
+    font-weight: bold

File src/print.css

View file
  • Ignore whitespace
-/* line 24, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 24, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 body {
   line-height: 1.5;
   font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
   font-size: 10pt;
 }
 
-/* line 45, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 45, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 .container {
   background: none;
 }
 
-/* line 47, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 47, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 hr {
   background: #cccccc;
   color: #cccccc;
   padding: 0;
   border: none;
 }
-/* line 55, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 55, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 hr.space {
   background: white;
   color: white;
 }
 
-/* line 58, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 58, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 h1, h2, h3, h4, h5, h6 {
   font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
 }
 
-/* line 60, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 60, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 code {
   font-size: 0.9em;
   font-family: "andale mono", "lucida console", monospace;
 }
 
-/* line 65, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 65, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 a img {
   border: none;
 }
-/* line 68, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 68, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 a:link, a:visited {
   background: transparent;
   font-weight: 700;
   text-decoration: underline;
 }
 
-/* line 72, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 72, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 p img.top {
   margin-top: 0;
 }
 
-/* line 74, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 74, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 blockquote {
   margin: 1.5em;
   padding: 1em;
   font-size: 0.9em;
 }
 
-/* line 79, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 79, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 .small {
   font-size: 0.9em;
 }
 
-/* line 81, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 81, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 .large {
   font-size: 1.1em;
 }
 
-/* line 83, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 83, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 .quiet {
   color: #999999;
 }
 
-/* line 85, /usr/lib/ruby/gems/1.8/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
+/* line 85, ../../../../../../../../../usr/share/ruby/gems/gems/compass-0.12.2/frameworks/blueprint/stylesheets/blueprint/_print.scss */
 .hide {
   display: none;
 }

File src/topics/files-and-directories/index.html.wml

View file
  • Ignore whitespace
 
 <define-tag perl_code endtag="required">
 <pre class="perl">
-\#!/usr/bin/perl
+<:{
+    use Text::VimColor;
+
+    my $s = <<'EOF_BLAH_BLAH_YES_THIS_IS_PERL_CODE_TO_PASS_TO_VIM';
+#!/usr/bin/perl
 
 use strict;
 use warnings;
 %body
+EOF_BLAH_BLAH_YES_THIS_IS_PERL_CODE_TO_PASS_TO_VIM
+
+    my $tvc = Text::VimColor->new(
+        string => \$s,
+        filetype => 'perl',
+    );
+    print $tvc->html() =~ s{(class=")syn}{$1}gr;
 </pre>
+}:>
 </define-tag>
 
 <script type="text/javascript">
 
 <div id="processing_lines_of_a_file_cmd_line">
 <pre>
-\$ perl -i.bak -lp -e 's/\bFrom\b/To/g' *.txt
+$ perl -i.bak -lp -e 's/\bFrom\b/To/g' *.txt
 </pre>
 </div>