| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

「Perl JavaコードをHTMLに」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
(ページの作成:「==Perl JavaコードをHTMLに== open IN, "<c:\\test.java"; open OUT, ">c:\\test.html"; print OUT "<style>"; print OUT ".kwd{ color:blue;font-weight:bold; }"…」)
 
1行目: 1行目:
 
==Perl JavaコードをHTMLに==
 
==Perl JavaコードをHTMLに==
  
  open IN, "<c:\\test.java";
+
  open IN, "&lt;c:\\test.java";
  open OUT, ">c:\\test.html";
+
  open OUT, "&gt;c:\\test.html";
 
   
 
   
  print OUT "<style>";
+
  print OUT "&lt;style&gt;";
 
  print OUT ".kwd{ color:blue;font-weight:bold; }";
 
  print OUT ".kwd{ color:blue;font-weight:bold; }";
 
  print OUT ".cmt{ color:green; }";
 
  print OUT ".cmt{ color:green; }";
10行目: 10行目:
 
  print OUT ".lit{ color:#00ffff; }";
 
  print OUT ".lit{ color:#00ffff; }";
 
  print OUT ".code{ background-color:#efefff;border:1px solid lightgrey;font-family:monospace; }";
 
  print OUT ".code{ background-color:#efefff;border:1px solid lightgrey;font-family:monospace; }";
  print OUT "</style>";
+
  print OUT "&lt;/style&gt;";
 
   
 
   
  print OUT "<div class='code'>";
+
  print OUT "&lt;div class='code'&gt;";
 
  $c = 1;
 
  $c = 1;
 
  $isCmt = 0;
 
  $isCmt = 0;
  while ( $line = <IN> ) {
+
  while ( $line = &lt;IN&gt; ) {
 
      
 
      
 
     $line =~ s/\s*$//;
 
     $line =~ s/\s*$//;
 
      
 
      
 
     $line =~ s/(&)/&amp;/g;
 
     $line =~ s/(&)/&amp;/g;
     $line =~ s/(<)/&lt;/g;
+
     $line =~ s/(&lt;)/&lt;/g;
     $line =~ s/(>)/&gt;/g;
+
     $line =~ s/(&gt;)/&gt;/g;
 
     $line =~ s/([ ])/&nbsp;/g;
 
     $line =~ s/([ ])/&nbsp;/g;
 
     $line =~ s/(\t)/&nbsp;&nbsp;&nbsp;&nbsp;/g;
 
     $line =~ s/(\t)/&nbsp;&nbsp;&nbsp;&nbsp;/g;
 
   
 
   
 
     if ($line =~ /(\/\*)/) {
 
     if ($line =~ /(\/\*)/) {
         $line =~ s/(\/\*)/<span class='cmt'>\1/;
+
         $line =~ s/(\/\*)/&lt;span class='cmt'&gt;\1/;
 
         $isCmt = 1;
 
         $isCmt = 1;
 
     }
 
     }
32行目: 32行目:
 
     if ($isCmt) {
 
     if ($isCmt) {
 
         if ($line =~ /(\*\/)/) {
 
         if ($line =~ /(\*\/)/) {
             $line =~ s/(\*\/)/\1<\/span>/;
+
             $line =~ s/(\*\/)/\1&lt;\/span&gt;/;
 
             $isCmt = 0;
 
             $isCmt = 0;
 
         }
 
         }
 
     } else {
 
     } else {
         $line =~ s/(\bString\b|\babstract\b|\bcontinue\b|\bfor\b|\bnew\b|\bswitch\b|\bassert\b|\bdefault\b|\bif\b|\bpackage\b|\bsynchronized\b|\bboolean\b|\bdo\b|\bgoto\b|\bprivate\b|\bthis\b|\bbreak\b|\bdouble\b|\bimplements\b|\bprotected\b|\bthrow\b|\bbyte\b|\belse\b|\bimport\b|\bpublic\b|\bthrows\b|\bcase\b|\benum\b|\binstanceof\b|\breturn\b|\btransient\b|\bcatch\b|\bextends\b|\bint\b|\bshort\b|\btry\b|\bchar\b|\bfinal\b|\binterface\b|\bstatic\b|\bvoid\b|\bclass\b|\bfinally\b|\blong\b|\bstrictfp\b|\bvolatile\b|\bconst\b|\bfloat\b|\bnative\b|\bsuper\b|\bwhile\b)/<span class='kwd'>\1<\/span>/g;
+
         $line =~ s/(\bString\b|\babstract\b|\bcontinue\b|\bfor\b|\bnew\b|\bswitch\b|\bassert\b|\bdefault\b|\bif\b|\bpackage\b|\bsynchronized\b|\bboolean\b|\bdo\b|\bgoto\b|\bprivate\b|\bthis\b|\bbreak\b|\bdouble\b|\bimplements\b|\bprotected\b|\bthrow\b|\bbyte\b|\belse\b|\bimport\b|\bpublic\b|\bthrows\b|\bcase\b|\benum\b|\binstanceof\b|\breturn\b|\btransient\b|\bcatch\b|\bextends\b|\bint\b|\bshort\b|\btry\b|\bchar\b|\bfinal\b|\binterface\b|\bstatic\b|\bvoid\b|\bclass\b|\bfinally\b|\blong\b|\bstrictfp\b|\bvolatile\b|\bconst\b|\bfloat\b|\bnative\b|\bsuper\b|\bwhile\b)/&lt;span class='kwd'&gt;\1&lt;\/span&gt;/g;
         $line =~ s/(\/\/.*)/<span class='cmt'>\1<\/span>/g;
+
         $line =~ s/(\/\/.*)/&lt;span class='cmt'&gt;\1&lt;\/span&gt;/g;
 
     }
 
     }
     printf(OUT "<span class='lin'>%04d:</span> $line<br/>\n", $c);
+
     printf(OUT "&lt;span class='lin'&gt;%04d:&lt;/span&gt; $line&lt;br/&gt;\n", $c);
 
   
 
   
 
     $c++;
 
     $c++;
 
  }
 
  }
  print OUT "</div>";
+
  print OUT "&lt;/div&gt;";
 
  close IN;
 
  close IN;
 
  close OUT;
 
  close OUT;
  
 
{{ref j2html.pl}}
 
{{ref j2html.pl}}

2020年2月15日 (土) 08:05時点における版

Perl JavaコードをHTMLに

open IN, "<c:\\test.java";
open OUT, ">c:\\test.html";

print OUT "<style>";
print OUT ".kwd{ color:blue;font-weight:bold; }";
print OUT ".cmt{ color:green; }";
print OUT ".lin{ color:#808080; }";
print OUT ".lit{ color:#00ffff; }";
print OUT ".code{ background-color:#efefff;border:1px solid lightgrey;font-family:monospace; }";
print OUT "</style>";

print OUT "<div class='code'>";
$c = 1;
$isCmt = 0;
while ( $line = <IN> ) {
    
    $line =~ s/\s*$//;
    
    $line =~ s/(&)/&/g;
    $line =~ s/(<)/</g;
    $line =~ s/(>)/>/g;
    $line =~ s/([ ])/ /g;
    $line =~ s/(\t)/    /g;

    if ($line =~ /(\/\*)/) {
        $line =~ s/(\/\*)/<span class='cmt'>\1/;
        $isCmt = 1;
    }
    
    if ($isCmt) {
        if ($line =~ /(\*\/)/) {
            $line =~ s/(\*\/)/\1<\/span>/;
            $isCmt = 0;
        }
    } else {
        $line =~ s/(\bString\b|\babstract\b|\bcontinue\b|\bfor\b|\bnew\b|\bswitch\b|\bassert\b|\bdefault\b|\bif\b|\bpackage\b|\bsynchronized\b|\bboolean\b|\bdo\b|\bgoto\b|\bprivate\b|\bthis\b|\bbreak\b|\bdouble\b|\bimplements\b|\bprotected\b|\bthrow\b|\bbyte\b|\belse\b|\bimport\b|\bpublic\b|\bthrows\b|\bcase\b|\benum\b|\binstanceof\b|\breturn\b|\btransient\b|\bcatch\b|\bextends\b|\bint\b|\bshort\b|\btry\b|\bchar\b|\bfinal\b|\binterface\b|\bstatic\b|\bvoid\b|\bclass\b|\bfinally\b|\blong\b|\bstrictfp\b|\bvolatile\b|\bconst\b|\bfloat\b|\bnative\b|\bsuper\b|\bwhile\b)/<span class='kwd'>\1<\/span>/g;
        $line =~ s/(\/\/.*)/<span class='cmt'>\1<\/span>/g;
    }
    printf(OUT "<span class='lin'>%04d:</span> $line<br/>\n", $c);

    $c++;
}
print OUT "</div>";
close IN;
close OUT;

テンプレート:Ref j2html.pl