Skip to content

Instantly share code, notes, and snippets.

@tyru
Created December 30, 2012 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tyru/4414639 to your computer and use it in GitHub Desktop.
Save tyru/4414639 to your computer and use it in GitHub Desktop.
--- vim2html.pl.bak 2013-01-27 19:33:42.945919677 +0900
+++ vim2html.pl 2013-01-27 19:33:41.797918006 +0900
@@ -19,7 +19,7 @@
return $url{ $tag };
} else {
#warn "Unknown hyperlink target: $tag\n";
- $tag =~ s/\.txt//;
+ $tag =~ s/\.(?:txt|..x)//;
$tag =~ s/</&lt;/g;
$tag =~ s/>/&gt;/g;
return "<code class=\"badlink\">$tag</code>";
@@ -38,8 +38,8 @@
$tag = $1;
my $label = $tag;
- ($file= $2) =~ s/.txt$/.html/g;
- $label =~ s/\.txt//;
+ ($file= $2) =~ s/.(?:txt|..x)$/.html/g;
+ $label =~ s/\.(?:txt|..x)//;
$url{ $tag } = "<a href=\"$file#".escurl($tag)."\">".esctext($label)."</a>";
}
@@ -75,9 +75,12 @@
my( $outfile );
open(IN, "$infile" ) || die "Couldn't read from $infile: $!.\n";
+ # Help files must use latin1 or utf-8 encoding. (:help help-translated)
+ my $encoding = scalar(<IN>) =~ /[^\x00-\x7F]/ ? 'utf-8' : 'latin1';
+ seek IN, 0, 0;
($outfile = $infile) =~ s:.*/::g;
- $outfile =~ s/\.txt$//g;
+ $outfile =~ s/\.(?:txt|..x)$//g;
open( OUT, ">$outfile.html" )
|| die "Couldn't write to $outfile.html: $!.\n";
@@ -88,6 +91,7 @@
<html>
<head>
<title>VIM: $outfile</title>
+<meta http-equiv="Content-Type" content="text/html; charset=$encoding">
<link rel="stylesheet" href="vim-stylesheet.css" type="text/css">
</head>
<body>
@tyru
Copy link
Author

tyru commented Dec 30, 2012

This patch does:

  • Process *.??x files (non-English vim help files) not only *.txt files
  • Add charset tag <meta http-equiv="Content-Type" content="text/html; charset=$encoding">
    • $encoding = "latin1" by default
  • Detect !_TAG_FILE_ENCODING line in tags file
    • If vim2html.pl found this line, set the encoding value to $encoding

@tyru
Copy link
Author

tyru commented Jan 27, 2013

in revision 2(69c2bdd), I have changed like the followings:

  • Process *.??x files (non-English vim help files) not only *.txt files
  • Add charset tag
    • $encoding = "latin1" by default
  • If the firstline of help file contains non-ASCII character, set "utf-8" to $encoding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment