Skip to content

Commit

Permalink
Add raw option where possible [#2]
Browse files Browse the repository at this point in the history
This adds a `raw` option that can be passed to `parse()` that causes the
parser to return the raw output of the underlying layer, without
wrapping in the minimal HTML skeleton.

This is only possible for a subset of the existing parsers; this patch
makes no attempt to remove the HTML wrappers in the cases where that
wrapper is being added by the underlying parser.

Note also that this patch does not add any tests for this new behavior,
because there don't appear to be any cases where input/output
transformations are actually being currently tested.
  • Loading branch information
genehack authored and theory committed May 10, 2016
1 parent 5566c5c commit 2d3352c
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Text/Markup/Asciidoc.pm
Expand Up @@ -77,6 +77,7 @@ sub parser {
# Make sure we have something.
return unless $html =~ /\S/;
utf8::encode $html;
return $html if $opts->{raw};
return qq{<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand Down Expand Up @@ -121,6 +122,7 @@ Text::Markup::Asciidoc - Asciidoc parser for Text::Markup
use Text::Markup;
my $html = Text::Markup->new->parse(file => 'hello.adoc');
my $raw_asciidoc = Text::Markup->new->parse(file => 'hello.adoc', raw => 1 );
=head1 Description
Expand All @@ -140,6 +142,10 @@ recognizes files with the following extensions as Asciidoc:
=back
Normally this parser returns the output of C<asciidoc> wrapped in a minimal
HTML page skeleton. If you would prefer to just get the exact output returned
by C<asciidoc>, you can pass in a true value for the C<raw> option.
=head1 Author
David E. Wheeler <david@justatheory.com>
Expand Down
6 changes: 6 additions & 0 deletions lib/Text/Markup/Bbcode.pm
Expand Up @@ -16,6 +16,7 @@ sub parser {
my $html = $parse->render(<$fh>);
return unless $html =~ /\S/;
utf8::encode($html);
return $html if $opts->{raw};
return qq{<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand All @@ -38,6 +39,7 @@ Text::Markup::Bbcode - BBcode parser for Text::Markup
=head1 Synopsis
my $html = Text::Markup->new->parse(file => 'file.bbcode');
my $raw = Text::Markup->new->parse(file => 'file.bbcode', raw => 1);
=head1 Description
Expand All @@ -58,6 +60,10 @@ It recognizes files with the following extensions as Markdown:
=back
Normally this module returns the output wrapped in a minimal HTML document
skeleton. If you would like the raw output with the raw skeleton, you can pass
the C<raw> option to C<parse>.
=head1 Author
Lucas Kanashiro <kanashiro.duarte@gmail.com>
Expand Down
6 changes: 6 additions & 0 deletions lib/Text/Markup/Creole.pm
Expand Up @@ -15,6 +15,7 @@ sub parser {
my $html = creole_parse(<$fh>);
return unless $html =~ /\S/;
utf8::encode($html);
return $html if $opts->{raw};
return qq{<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand All @@ -37,6 +38,7 @@ Text::Markup::Creole - Creole parser for Text::Markup
=head1 Synopsis
my $html = Text::Markup->new->parse(file => 'file.creole');
my $raw = Text::Markup->new->parse(file => 'file.creole', raw => 1);
=head1 Description
Expand All @@ -55,6 +57,10 @@ It recognizes files with the following extensions as Markdown:
=back
Normally this module returns the output wrapped in a minimal HTML document
skeleton. If you would like the raw output without the skeleton, you can pass
the C<raw> option to C<parse>.
=head1 Author
Lucas Kanashiro <kanashiro.duarte@gmail.com>
Expand Down
6 changes: 6 additions & 0 deletions lib/Text/Markup/Markdown.pm
Expand Up @@ -16,6 +16,7 @@ sub parser {
my $html = $md->markdown(<$fh>);
return unless $html =~ /\S/;
utf8::encode($html);
return $html if $opts->{raw};
return qq{<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand All @@ -38,6 +39,7 @@ Text::Markup::Markdown - Markdown parser for Text::Markup
=head1 Synopsis
my $html = Text::Markup->new->parse(file => 'README.md');
my $raw = Text::Markup->new->parse(file => 'README.md', raw => 1);
=head1 Description
Expand All @@ -64,6 +66,10 @@ It recognizes files with the following extensions as Markdown:
=back
Normally this module returns the output wrapped in a minimal HTML document
skeleton. If you would like the raw output without the skeleton, you can pass
the C<raw> option to C<parse>.
=head1 See Also
L<National Funk Congress Deadlocked On Get Up/Get Down
Expand Down
6 changes: 6 additions & 0 deletions lib/Text/Markup/Mediawiki.pm
Expand Up @@ -15,6 +15,7 @@ sub parser {
my $html = Text::MediawikiFormat::format(<$fh>, @{ $opts || [] });
return unless $html =~ /\S/;
utf8::encode($html);
return $html if $opts->{raw};
return qq{<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand All @@ -37,6 +38,7 @@ Text::Markup::Mediawiki - MediaWiki syntax parser for Text::Markup
=head1 Synopsis
my $html = Text::Markup->new->parse(file => 'README.mediawiki');
my $raw = Text::Markup->new->parse(file => 'README.mediawiki', raw => 1);
=head1 Description
Expand All @@ -58,6 +60,10 @@ It recognizes files with the following extensions as MediaWiki:
=item F<.wiki>
Normally this module returns the output wrapped in a minimal HTML document
skeleton. If you would like the raw output without the skeleton, you can pass
the C<raw> option to C<parse>.
=back
=head1 Author
Expand Down
6 changes: 6 additions & 0 deletions lib/Text/Markup/Multimarkdown.pm
Expand Up @@ -16,6 +16,7 @@ sub parser {
my $html = $md->markdown(<$fh>);
return unless $html =~ /\S/;
utf8::encode($html);
return $html if $opts->{raw};
return qq{<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand All @@ -38,6 +39,7 @@ Text::Markup::Multimarkdown - MultiMarkdown parser for Text::Markup
=head1 Synopsis
my $html = Text::Markup->new->parse(file => 'README.md');
my $raw = Text::Markup->new->parse(file => 'README.md', raw => 1);
=head1 Description
Expand All @@ -64,6 +66,10 @@ It recognizes files with the following extensions as MultiMarkdown:
=back
Normally this module returns the output wrapped in a minimal HTML document
skeleton. If you would like the raw output without the skeleton, you can pass
the C<raw> option to C<parse>.
=head1 Author
David E. Wheeler <david@justatheory.com>
Expand Down
6 changes: 6 additions & 0 deletions lib/Text/Markup/None.pm
Expand Up @@ -14,6 +14,7 @@ sub parser {
local $/;
my $html = encode_entities(<$fh>, '<>&"');
utf8::encode($html);
return $html if $opts->{raw};
return qq{<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand All @@ -36,6 +37,7 @@ Text::Markup::None - Turn a file with no known markup into HTML
use Text::Markup;
my $html = Text::Markup->new->parse(file => 'README');
my $raw = Text::Markup->new->parse(file => 'README', raw => 1);
=head1 Description
Expand All @@ -46,6 +48,10 @@ entities, and then returns an HTML string with the file in a C<< <pre> >>
element. This will be handy for files that really are nothing but plain text,
like F<README> files.
Normally this module returns the output wrapped in a minimal HTML document
skeleton. If you would like the raw output without the skeleton, you can pass
the C<raw> option to C<parse>.
=head1 Author
David E. Wheeler <david@justatheory.com>
Expand Down
6 changes: 6 additions & 0 deletions lib/Text/Markup/Textile.pm
Expand Up @@ -21,6 +21,7 @@ sub parser {
my $html = $textile->process(<$fh>);
return unless $html =~ /\S/;
utf8::encode($html);
return $html if $opts->{raw};
return qq{<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand All @@ -43,6 +44,7 @@ Text::Markup::Textile - Textile parser for Text::Markup
=head1 Synopsis
my $html = Text::Markup->new->parse(file => 'README.textile');
my $raw = Text::Markup->new->parse(file => 'README.textile', raw => 1);
=head1 Description
Expand All @@ -61,6 +63,10 @@ It recognizes files with the following extension as Textile:
=back
Normally this module returns the output wrapped in a minimal HTML document
skeleton. If you would like the raw output without the skeleton, you can pass
the C<raw> option to C<parse>.
=head1 Author
David E. Wheeler <david@justatheory.com>
Expand Down
6 changes: 6 additions & 0 deletions lib/Text/Markup/Trac.pm
Expand Up @@ -16,6 +16,7 @@ sub parser {
my $html = $trac->parse(<$fh>);
return unless $html =~ /\S/;
utf8::encode($html);
return $html if $opts->{raw};
return qq{<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Expand All @@ -38,6 +39,7 @@ Text::Markup::Trac - Trac wiki syntax parser for Text::Markup
=head1 Synopsis
my $html = Text::Markup->new->parse(file => 'README.trac');
my $raw = Text::Markup->new->parse(file => 'README.trac', raw => 1);
=head1 Description
Expand All @@ -59,6 +61,10 @@ It recognizes files with the following extensions as Trac:
=back
Normally this module returns the output wrapped in a minimal HTML document
skeleton. If you would like the raw output without the skeleton, you can pass
the C<raw> option to C<parse>.
=head1 Author
David E. Wheeler <david@justatheory.com>
Expand Down

0 comments on commit 2d3352c

Please sign in to comment.