[WM] SDF conversion support (first-cut)

Carlos Ramirez cramirez at gte.net
Fri Mar 5 08:39:22 GMT 2004


I downloaded the latest CVS WebMake from sourceforge. I added the 
"text/sdf" format type to FormatConvert.pm. I used pod_to_html to walk 
me through, which is evident in the code ;)
So, would this be worthy of being added to WebMake formatters?

Example usage:
<content name="my_sdf_doc" format="text/sdf">
H1: Introduction

blah.....

H1: Installation

^ Step one
. C<root# my command>
+ Step Two

H1: Post Installation

H2: Configuration
</content>

Notable features:
* POD-like commands
* Automatic generation of Table of contents, based on H1,H2,H3,.. sections
* Include directives
* Variable declarations
* Based on sdf-2.001beta

More: http://search.cpan.org/~ianc/sdf-2.001/

I can supply more documentation if needed.

Thanks,

-Carlos


Diff:

Index: FormatConvert.pm
===================================================================
RCS file: /cvsroot/webmake/webmake/lib/HTML/WebMake/FormatConvert.pm,v
retrieving revision 1.18
diff -c -r1.18 FormatConvert.pm
*** FormatConvert.pm	20 Nov 2003 19:47:09 -0000	1.18
--- FormatConvert.pm	5 Mar 2004 07:45:21 -0000
***************
*** 23,28 ****
--- 23,31 ----
  sub set_converters {
    my $self = shift;
  
+   $self->add_converter ('text/sdf', 'text/html',
+                         undef, \&sdf_to_html);
+ 
    $self->add_converter ('text/tt', 'text/html',
                         'Text::Textile', \&tt_to_html);
  
***************
*** 212,217 ****
--- 215,255 ----
    return $self;
  }
  
+ # -------------------------------------------------------------------------
+ # SDF stuff
+ 
+ sub sdf_to_html {
+   my ($self,$contobj,$txt) = @_;
+   local($_);
+ 
+   my $tmpin   = $self->{main}->tmpdir().'tmp_wm_sdf.'.$$;
+   my $sdf_out = "";
+                                                                                 
+   ## SDF requires a .sdf file, does not accept input from STDIN
+   open (SDF_IN, "+>$tmpin") or die "Cannot write to $tmpin";
+   print SDF_IN $txt; undef $txt;
+   close SDF_IN;
+                                                                                 
+   ## Call sdf and direct output to STDOUT via '-o-' option
+   open(SDF,"sdf -2html -o- $tmpin |") or die "sdf -2html error : $!";
+   
+   ## Remove everything between [<html>....<body>]
+   ## and </body></html>
+   my $inside_body = 0;
+   while (<SDF>) {
+      if ($inside_body) {
+          last if /<\/body>/i;
+ 
+          $_ =~ s/<(H|B)R>/<$1R \/>/ig; ## Convert <br>,<hr> to <br />,<hr />
+          $sdf_out .= $_;
+      }
+      elsif (/<body>/i) {
+          $inside_body = 1;
+      }
+   }
+                                                                                 
+   $sdf_out;
+ }
  
  # -------------------------------------------------------------------------
  





More information about the Webmake-talk mailing list