Text::InHTML - Display plain text in HTML


Text-InHTML documentation  | view source Contained in the Text-InHTML distribution.

Index


NAME

Top

Text::InHTML - Display plain text in HTML

SYNOPSIS

Top

  use Text::InHTML;
  my $html = Text::InHTML::encode_plain($plain_text_text);
  my $syntax_higlighted_diff = Text::InHTML::encode_diff($plain_text_diff);

DESCRIPTION

Top

In its simplest form it turns a plain text string into HTML that when rendered retains its whitespace without pre tags or pre-like css. Also HTML is encoded so no HTML is rendered like it would be with pre tags. Useful for displaying source code or a text file on a web page exactly as-is.

More advanced useage includes syntax highlighting.

EXPORT

None by default.

Any encode_* is exportable

The tag :common does: encode_plain encode_whitespace encode_perl encode_diff encode_html encode_css encode_sql encode_mysql encode_xml encode_dtd encode_xslt encode_xmlschema

Functions

Top

encode_plain

Returns an HTML and whitespace encoded version of $plain_text_string

    encode_plain($plain_text_string);

$tabs is the number of spaces a tab should be considered to be, default is 4

    encode_plain($plain_text_string, $tabs);

encode_whitespace

Mostly a utility function, returns whitespace encoded version of $string

    encode_whitespace($tring);

$tabs is the number of spaces a tab should be considered to be, default is 4

    encode_whitespace($plain_text_string, $tabs);

encode_perl, encode_diff, encode_*

You can call Text::InHTML::encode_whatever(), where "whatever" is a "format" as listed under "Processing text" at Syntax::Highlight::Universal

Note: if the format has a dash, like "html-css" then you need to call it with an underscore in place of each - like so:

    Text::InHTML::encode_html_css()

and it will return HTML that is syntax highlighted (what Syntax::Highlight::Universal does) *and* retains whitespace (what Syntax::Highlight::Universal does not do)

    my $syntax_highlighted_source_code = Text::InHTML::encode_perl($string); 

    my $syntax_highlighted_source_code = Text::InHTML::encode_perl($string, $syntax);

    my $syntax_highlighted_source_code = Text::InHTML::encode_perl($string, $syntax, $tabs);    

    my $syntax_highlighted_source_code = Text::InHTML::encode_perl($string, undef, $tabs);

    my $syntax_highlighted_source_code = Text::InHTML::encode_perl($string, {}, $tabs);

$tabs is the number of spaces a tab should be considered to be, default is 4

If Syntax::Highlight::Universal is installed, it calls Syntax::Highlight::Universal's highlight method with the given format, othersise it simply does encode_plain()

Additionally $syntax can be a hashref which gives you fine grained control over the Syntax::Highlight::Universal object.

Its keys and values are as follows:

* callbacks

Value is the same as Syntax::Highlight::Universal's highlight() method's 3rd argument.

* pre_proc

Value is a code ref whose only argument if the Syntax::Highlight::Universal object that will next be used to process the $string

SEE ALSO

Top

HTML::Entities, Syntax::Highlight::Universal

TIPS

Top

* Wrap the whole thing in a div that's monospace styled and source code will look real nice!
* You'll need to use CSS to color in the highlighted syntax. The Syntax::Highlight::Universal bundle has some samples and info on how to generate that CSS.

TODO

Top

Function(s) to facilitate javascript highlighters like google's syntax highlighter framework.

AUTHOR

Top

Daniel Muey, http://drmuey.com/cpan_contact.pl

COPYRIGHT AND LICENSE

Top


Text-InHTML documentation  | view source Contained in the Text-InHTML distribution.