Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Turning HtmlDoc into Book

by holli (Abbot)
on Jul 08, 2005 at 14:53 UTC ( [id://473432]=CUFP: print w/replies, xml ) Need Help??

Today I decided to learn more about the Template-Toolkit. I am the kind of person that can learn the first steps better when I read things on paper. Reading from screen is fine for me for looking up a reference, but reading long texts is a pain. Regardless if it is a CRT or a TFT display.

The docs of Template Toolkit are, as of many Perl modules, splitted in many small chunks, which is also fine for reference, but a pain to print out.

So I decided to put the stuff together in a Word (/me ducks) file and make a pdf out of it, so i can share it with people. I planned to make it in three parts.
  • The Manual
  • The Tutorial
  • The Reference
The manual and the tutorial consist of a few documents so i did them by hand. I copied the relevant parts from the HTML-doc and inserted them into Word, changed headings, inserted pagebreaks, did some pageformatting and printed it to a pdf.

So far so good. But when I came to the reference I realized that there are far too many files to do it conviniently by hand. Solution: script it.

Here is the script I used for the issue. It uses regexes to deal with the html, but since Active States HTML-Docs are computer generated I think that is ok in this case :-D
my @f = ( "c:/perl/html/site/lib/Template.html", "c:/perl/html/site/lib/Template/Base.html", #... "c:/perl/html/site/lib/Template/Plugin/XML/Style.html", "c:/perl/html/site/lib/Template/Plugin/XML/XPath.html", ); open OUT, ">ref.html"; print OUT <<"HTML"; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w +3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Template::Config - Factory module for instantiating other TT2 m +odules</title> <link rel="stylesheet" href="Active.css" type="text/css" /> <link rev="made" href="mailto:" /> </head> <body> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td class="block" valign="middle"> <big><strong><span class="block">&nbsp;Template::Config - Factory modu +le for instantiating other TT2 modules</span></strong></big> </td></tr> </table> <p> HTML for my $f ( @f ) { #trigger $i=0; open IN, $f or die "$f: $!"; while ( <IN> ) { $i=1 if /<!-- INDEX END -->/; $i=0 if /<h1><a name="authors?">/; #tweak the NAME heading my $ff = $f; $ff =~ s/^.+Template/Template/; $ff =~ s/\.html//; $ff =~ s/\//::/g; s/<h1><a name="name">NAME<\/a><\/h1>/[[[PB!]]]<h0><a name="nam +e">$ff<\/h0>/; s/<hr \/>//g; #tweak headings one step smaller s/(<\/?h)([0-9])(>)/$1.($2+1).$3/eg; print OUT $_ if $i; } } print OUT "</body></html>";
That worked fine. All I had to do manually was replacing the [[[PB!]]] parts with pagebreaks using the "search and replace" functionality of Word, formatting the pages and adding a autogenerated Table of Contents. Et voila, a full fledged book. :-)

As you may have noticed, the html relies on a external stylesheet, so you can even tweak the formatting to you your liking.

I will put the six Files (TT-Manual-Single, TT-Manual-Double, TT-Tutorial-Single, TT-Tutorial-Double, TT-Reference-Single and TT-Reference-Double) on my webspace at holli.perlmonk.org as soon as I get home, since I cannot ssh from work.

The difference between "Double" and "Single" here is that one is optimized for double paged print, the other for single page print.

Update:
The files are now available at http://holli.perlmonk.org/TTdocs. There is a 20MB transfer limit per day on jcwren's server, so please be kind if it does not work for you. Just try the other day.


holli, /regexed monk/

Replies are listed 'Best First'.
Re: Turning HtmlDoc into Book
by chanio (Priest) on Jul 09, 2005 at 05:59 UTC
    It looks great! Thanks for the pdfs! If you want a tool to interface between you and your scripts, you should try Total Commander. It helps to make listings, searchings (just like the old Norton Comander), and call scripts. It has a lot of very useful pluggins. For me it is what I miss from the old Windows and my daily swiss-knife.

    Your pdfs will help me find some time to learn to use TT.- Whats bizarre is that the TT's manual installation was expected to generate postscript files just by calling ttree -f /../ttree.conf. Those would be easily transformed into pdf with the help of ghostscript. But the autogenerated config files seem not to be working.

    { \ ( ' v ' ) / }
    ( \ _ / ) _ _ _ _ ` ( ) ' _ _ _ _
    ( = ( ^ Y ^ ) = ( _ _ ^ ^ ^ ^
    _ _ _ _ \ _ ( m _ _ _ m ) _ _ _ _ _ _ _ _ _ ) c h i a n o , a l b e r t o
    Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://473432]
Approved by Tanalis
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-03-28 17:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found