
package Text::Wigwam::Directives::html;

    use strict;
    use warnings;
    no warnings 'uninitialized';
    our $VERSION = '0.01';

    use Text::Wigwam::Const qw(:all);


=head1 Name

Text::Wigwam::Modules::Core::Html - A Wigwam module.

=head1 Description

This module contains directives useful for managing data in HTML documents.

=head1 Directives

=cut

sub _proto_escape { [ STRING ] }
sub _escape {
    my $text = $_[0]->get_arg;
    for( $text ){
        s/&/&amp;/g;
        s/</&lt;/g;
        s/>/&gt;/g;
        s/"/&quot;/g;
    }
    return $text;
}

=head2 #html::escape I<string>

Converts specific characters in I<string> to their respective character entity
references.

 [!!
  #html::escape "less than: <"    /* output: less than: &lt; */
  #html::escape "greater than: >" /* output: greater than: &gt; */
  #html::escape "quote: \""       /* output: quote: &quot; */
  #html::escape "ampersand: &"    /* output: ampersand: &amp; */
 !!]

 <Textarea rows=12 cols=80 name="blah">
 [!~ #html::escape !!>
 <html>
 <head><title>Sample HTML page</title></head>
 <body>
 content
 </body>
 </html>
 <!! ~!]
 </Textarea>
 [!!
  /* output:
   <Textarea rows=12 cols=80 name="blah">
   &lt;html&gt;
   &lt;head&gt;&lt;title&gt;Sample HTML page&lt;/title&gt;&lt;/head&gt;
   &lt;body&gt;
   content
   &lt;/body&gt;
   &lt;/html&gt;
   </Textarea>
  */
 !!]

=cut

sub _proto_unquote { [ STRING ] }
sub _unquote {
    my $html = $_[0]->get_arg;
    $html =~ s/\"/&quot;/gs;
    return $html;
}

=head2 #html::unquote I<string>

Similar to C<#html::escape>, but works only on the quotation character. It's
used frequently in form widget value fields.

 [!! #define quote 'Bush Sr. "Read my lips"' !!]
 <Input type="text" name="quote" value="[!! #html::unquote quote !!]">
 [!!
  /* output:
   <Input type="text" name="quote" value="Bush Sr. &quot;Read my lips&quot;">
  */
 !!]

=cut

1;

__END__

