Re: Simple guide to transformations using Jade

Subject: Re: Simple guide to transformations using Jade
From: Norman Walsh <ndw@xxxxxxxxxx>
Date: Fri, 5 Jun 1998 08:20:36 -0400
/ Robin Stephenson <robin.stephenson@xxxxxxxxxxxxxxx> was heard to say:
| >>>>> On Fri,  5 Jun 1998 12:04:06 +0100
| >>>>> "Sebastian" == Sebastian Rahtz <s.rahtz@xxxxxxxxxxxxxx> wrote:
| 
| Sebastian> post-process the output with an SGML/XML pretty-printer....

Fixing the output turns out to be necessary if you use <script>
(or is it <style>?) tags because if you split the tag over a
line, Lynx gets confused and displays a blank page.  (Grumble.)

Here's the Perl script I use to massage the output from Jade
before posting it on my website.  It doesn't do anything fancy,
but it fixes the formatting...

@rem = '--*-Perl-*--
@echo off
perl.exe %_batchname %$
goto endofperl
@rem ';

require 'n:/home/nwalsh/lib/jadefix.pl';

$loadfile = shift @ARGV || die;
$savefile = shift @ARGV || $loadfile;

&jadefix::sgmlfix($loadfile, $savefile);

__END__
:endofperl

and here's jadefix.pl:

package jadefix;

%PREFIX = (
	   '</HEAD' => "\n",
	   '</STYLE' => "\n",
	   '<BODY' => "\n",
	   '<DT' => "\n",
	   '<HEAD' => "\n",
	   '<HR' => "\n",
	   '<META' => "\n",
	   '<P' => "\n",
	   '<TABLE' => "\n",
	   '<TD' => "\n",
	   '<TITLE' => "\n",
	   '<TR' => "\n",
	  );

%PSTFIX = (
	   '</DD' => "\n",
	   '</DL' => "\n",
	   '</DT' => "\n",
	   '</P' => "\n",
	   '</STYLE' => "\n",
	   '</TITLE' => "\n",
	   '<BODY' => "\n",
	   '<HR' => "\n",
	   '<STYLE' => "\n",
	  );

sub sgmlfix {
    my($loadfile) = shift;
    my($savefile) = shift || $loadfile;
    local(*F, $_);

    open (F, $loadfile);
    read (F, $_, -s $loadfile);
    close (F);

    s/\n>/>/sg;

    $pre = "";
    while (/<[^>]+>/s) {
	$pre .= $`;
	$tag = $&;
	$_ = $';
	
	$tag =~ s/\n/ /g;
	$pre .= $tag;
    }
    $_ = $pre . $_;
    
    $out = "";
    while (/<[^>]+>/s) {
	$out .= $`;
	$tag = $&;
	$_ = $';
	
	$tag =~ /^([^\s>]+)/;
	$tagid = $1;
	
	$out .= $PREFIX{$tagid} . $tag . $PSTFIX{$tagid};
    }
    $_ = $out . $_;
    
    open (F, ">$savefile");
    print F "$_\n";
    close (F);
}

1;

    


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


Current Thread
  • Re: Simple guide to transformations using Jade, (continued)
      • Robin Stephenson - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id GAA07574Fri, 5 Jun 1998 06:54:57 -0400 (EDT)
        • Sebastian Rahtz - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id HAA08144Fri, 5 Jun 1998 07:30:31 -0400 (EDT)
        • Robin Stephenson - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id HAA08750Fri, 5 Jun 1998 07:56:17 -0400 (EDT)
        • Sebastian Rahtz - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id IAA09196Fri, 5 Jun 1998 08:16:52 -0400 (EDT)
        • Norman Walsh - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id IAA09460Fri, 5 Jun 1998 08:25:07 -0400 (EDT) <=
        • Jakob Fix - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id NAA01735Thu, 11 Jun 1998 13:44:01 -0400 (EDT)
    • Graydon Hoare - from mail1.ability.netby web4-1.ability.net (8.8.5/8.6.12) with ESMTP id LAA12708Fri, 5 Jun 1998 11:55:02 -0400 (EDT)