Skip to content

Commit

Permalink
Remove NAME section by default (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed May 11, 2018
1 parent d3df0c1 commit 2914bfd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 13 deletions.
5 changes: 3 additions & 2 deletions lib/App/pod2pandoc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ sub parse_arguments {
Getopt::Long::GetOptionsFromArray(
\@_, \%opt, 'help|h|?', 'version',
'parse=s', 'podurl=s', 'ext=s', 'index=s',
'wiki', 'default-meta=s', 'update', 'quiet'
'wiki', 'default-meta=s', 'update', 'quiet',
'name',
) or exit 1;
pod2usage(1) if $opt{help};
if ( $opt{version} ) {
Expand Down Expand Up @@ -133,7 +134,7 @@ App::pod2pandoc - implements pod2pandoc command line script
use App::pod2pandoc;
# pod2pandoc command line script
my ($input, $opt, @args) = parse_arguments(@ARGV);
my ($input, $opt, @args) = parse_arguments(@ARGV);
pod2pandoc($input, $opt, @args);
# parse a Perl/Pod file and print its JSON serialization
Expand Down
2 changes: 1 addition & 1 deletion lib/Pod/Pandoc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ actual use of it. See L<http://pandoc.org/installing.html> for installation.
=head2 Replace L<pod2html>
# pod2html --infile=input.pm --css=style.css --title=TITLE > output.html
pod2pandoc input.pm -C style.css --toc -M title=TITLE -M subtitle= -o output.html
pod2pandoc input.pm --css=style.css --toc --name -o output.html
Pandoc option C<--toc> corresponds to pod2html option C<--index> and is
disabled by default. pod2pandoc adds title and subtitle from NAME section.
Expand Down
2 changes: 1 addition & 1 deletion lib/Pod/Pandoc/Modules.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sub index {
my @definitions = map {
[
[ module_link( $_, \%opt ) ],
[ [ Plain [ Str $modules->{$_}->metavalue('subtitle') // '' ] ] ]
[ [ Plain [ Str ($modules->{$_}->metavalue('subtitle') // '') ] ] ]
]
} sort keys %$modules;

Expand Down
26 changes: 26 additions & 0 deletions lib/Pod/Simple/Pandoc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,32 @@ sub parse_tree {
$doc->meta->{subtitle} = MetaString($subtitle) if $subtitle;
}

# remove header sections (TODO: move into Pandoc::Elements range filter)
unless ( ref $_[0] and $_[0]->{name} ) {
my $skip;
$doc->content(
[
map {
if ( defined $skip ) {
if ( $_->name eq 'Header' && $_->level <= $skip ) {
$skip = 0;
}
$skip ? () : $_;
}
else {
if ( $_->name eq 'Header' && $_->string eq 'NAME' ) {
$skip = $_->level;
();
}
else {
$_;
}
}
} @{ $doc->content }
]
);
}

$doc;
}

Expand Down
19 changes: 12 additions & 7 deletions script/pod2pandoc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ directory as first input and an optional output directory as second.

=item --help|-h|-?

Print out usage information and exit
Print out usage information and exit.

=item --parse FORMATS

Expand All @@ -55,27 +55,32 @@ such as C<0> or C<""> will disable linking to external modules.

=item --ext EXT

Output file extension when processing a directory. Default: C<html>
Output file extension when processing a directory. Default: C<html>.

=item --index NAME

Index file name when processing a directory. Disable with C<0>
Index file (e.g. C<index.html>) name when processing a directory. Can be
disabled with C<0>.

=item --name

Include C<NAME> section which is removed by default.

=item --wiki

Create wikilinks when processing a directory
Create wikilinks when processing a directory.

=item --update

Only process when input file is newer then output file
Only process when input file is newer then output file.

=item --default-meta FILE

Read default metadata from given file
Read default metadata from given file.

=item --quiet

Don't emit warnings and status information
Don't emit warnings and status information.

=item ...

Expand Down
10 changes: 8 additions & 2 deletions t/pod-simple-pandoc.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ my $file = 'lib/Pod/Simple/Pandoc.pm';
my $doc = $parser->parse_file($file);

is_deeply $doc->query( Header => sub { $_->level == 1 ? $_->string : () } ),
[ qw(NAME SYNOPSIS DESCRIPTION OPTIONS METHODS MAPPING), 'SEE ALSO' ],
[ qw(SYNOPSIS DESCRIPTION OPTIONS METHODS MAPPING), 'SEE ALSO' ],
'headers';

is_deeply $doc->metavalue,
Expand All @@ -34,6 +34,12 @@ my $file = 'lib/Pod/Simple/Pandoc.pm';
}
}

# parse_file with name
{
my $doc = Pod::Simple::Pandoc->new( name => 1 )->parse_file($file);
is $doc->content->[0]->string, 'NAME', 'keep NAME section';
}

# parse module
isa_ok $parser->parse_module('Pandoc::Elements'), 'Pandoc::Document';

Expand All @@ -60,7 +66,7 @@ if ( $ENV{RELEASE_TESTING} ) {
{
my $doc = $parser->parse_string(<<POD);
=over
I<hello>
=back
Expand Down

0 comments on commit 2914bfd

Please sign in to comment.