YAML::Yaml2Html - Builds an HTML page from a YAML-based document.
use YAML::Yaml2Html; my $y2h = new YAML::Yaml2Html( $my_document ); print $y2h->toString(); OR my $y2h = new YAML::Yaml2Html(); $y2h->loadFile( $y2h ); print $y2h->toString(); OR my $y2h = new YAML::Yaml2Html(); $y2h->loadText( "---\ntitle: This is just a test\n..." ); $y2h->toFile( "myfile" ); # module will auto-append '.html' if it's not already there.
This uses the YAML parser to convert a specialized YAML document into an HTML page.
I recently learned POD. Immediately, I was taken by its simplicity. It's so much easier to use than HTML, I even began writing simple HTML documents -- which had nothing to do with Perl -- with POD, then using pod2html to convert to a webbable format.
After doing this for awhile, I started to realize that POD was simply shorthand for heirarchical text... just the kind of thing that YAML is good for. Well, being rather lazy when it comes to using two tools where a single tool will work fine, I decided to write a proof-of-concept Perl structure parser that could output HTML... a back-end to YAML, in a way.
This script builds a table of contents and a body.
Sections are titled using < h1 >, < h2 >...< hn >, according to their subordinate level. They're also indented: the table of contents is indented using an Ordered (Numbered) List, and the body is indented using < div id="d##"> tags, where ## is the division number within that level. Paragraphs within text bodies are divided with < p class="p##"> tags, where ## is the paragraph number within that text.
< br > tags are added before newline characters in the body text, except when the text is inside < pre >...< /pre > tags, in which case it's left alone.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The latest version of this library is likely to be available from CPAN.