(C...E>) are mapped to Emphasized text (C), strongly
emphasized text (C), and inline code (C). Formatting code for
F (C...E>) are mapped to inline code with class
C (C<`...`{.filename}> in Pandoc Markdown). Formatting codes inside
code and filenames (e.g. C> or F > as
filename) are stripped to unformatted code. Character escapes
(C...E>) and C...E> are directly mapped to Unicode
characters. The special formatting code C...E> is ignored.
=head2 Links
Some examples of links of different kinds:
L
L
L
L
L
L
Link text can contain formatting codes:
L script|pod2pandoc>
L"MAPPING">
L
=head2 Titles I>!
=head2 Lists
=over
=item 1
Numbered lists are
=item 2
converted to C and
=over
=item *
Bulleted lists are
=item *
converted to
C
=back
=back
=over
=item Definition
=item Lists
=item are
I supported.
=back
=head2 =over/=back
=over
An C<=over>...C<=back> region containing no C<=item> is mapped to C.
=back
=head2 Verbatim sections
verbatim sections are mapped
to code blocks
=head2 Data sections
Data sections are passed as C. C, C, C, and C
are recognized as alias for C and C.
Option C can be used to parse data sections with pandoc executable and
merge them into the result document.
=begin markdown
### Examples
=end markdown
=begin html
HTML is passed through
as you can see here.
=end html
=for html HTML is automatically enclosed in
<div>...</div>
if needed.
=for latex \LaTeX\ is passed through as you can see here.
=begin tex
\LaTeX\ sections should start and end so Pandoc can recognize them.
=end tex
=head1 SEE ALSO
This module is based on L (L). It makes
obsolete several specialized C modules such as
L, L, L,
L L, L, L,
L etc.
=cut
metadata.json 100644 001750 001750 126 13275405016 17016 0 ustar 00voj voj 000000 000000 Pod-Pandoc-0.5.0/t/examples {
"title": "title from json",
"bool": false,
"map": {
"list": [1,2]
}
}
metadata.yaml 100644 001750 001750 113 13275405016 17003 0 ustar 00voj voj 000000 000000 Pod-Pandoc-0.5.0/t/examples ---
title: a *title*
map:
list:
- 'a *string*'
bool: true
...
Pandoc 000755 001750 001750 0 13275405016 14637 5 ustar 00voj voj 000000 000000 Pod-Pandoc-0.5.0/lib/Pod Modules.pm 100644 001750 001750 12476 13275405016 16777 0 ustar 00voj voj 000000 000000 Pod-Pandoc-0.5.0/lib/Pod/Pandoc package Pod::Pandoc::Modules;
use strict;
use warnings;
use 5.010;
our $VERSION = '0.30';
use File::Path qw(make_path);
use File::Find;
use File::Spec;
use File::stat;
use File::Basename qw(dirname);
use Pandoc::Elements;
use Carp qw(croak);
sub new {
bless( ( $_[1] // {} ), $_[0] );
}
sub add {
my ( $self, $name, $doc ) = @_;
if ( my $given = $self->{$name} ) {
return if $doc->metavalue('file') !~ /\.pod/;
}
$doc->meta->{title} //= MetaString $name;
$self->{$name} = $doc;
}
sub module_link {
my ( $module, $opt ) = @_;
my $target = $module;
if ( $opt->{subdirectories} ) { # TODO: document and test
$target =~ s{::}{/}g;
}
else {
$target =~ s{::}{-}g;
}
if ( $opt->{wiki} ) {
return Link attributes {}, [ Str $module ], [ $target, 'wikilink' ];
}
else {
$target .= '.' . ( $opt->{ext} // 'html' );
return Link attributes {}, [ Str $module ], [ $target, $module ];
}
}
sub index {
my ( $modules, %opt ) = @_;
# TODO: extend, document, and test metadata
my %meta = map { $_ => MetaString "" . $opt{$_} }
grep { defined $opt{$_} } qw{title};
my @definitions = map {
[
[ module_link( $_, \%opt ) ],
[
[
Plain [ Str( $modules->{$_}->metavalue('subtitle') // '' ) ]
]
]
]
} sort keys %$modules;
Document \%meta, [ DefinitionList \@definitions ];
}
sub serialize {
my ( $modules, $dir, $opt, @args ) = _parse_arguments(@_);
# adjust links
# TODO: create copy instead of transforming, so
# this can be called multiple times!
foreach my $doc ( values %$modules ) {
$doc->transform(
Link => sub {
# TODO: use configured prefix instead of hard-coded URL base
my ( $module, $hash ) =
$_->url =~ qr{^https://metacpan\.org/pod/([^#]+)(#.*)?$};
return unless ( $module and $modules->{$module} );
# TODO: check whether hash link target exists
my $link = module_link( $module, $opt );
if ( defined $hash ) {
$link->url( $link->url . $hash );
}
return $link;
}
);
}
# serialize
foreach my $doc ( values %$modules ) {
my $file = $doc->metavalue('file');
my $module = $doc->metavalue('title');
my $name = $module;
if ( $opt->{subdirectories} ) {
$name =~ s{::}{/}g;
}
else {
$name =~ s{::}{-}g;
}
$name .= '.' . ( $opt->{ext} // 'html' );
my $target = File::Spec->catfile( $dir, $name );
if ( $opt->{update} and -e $target ) {
next if stat($file)->[9] <= stat($target)->[9];
}
make_path( dirname($target) );
$doc->to_pandoc( -o => $target, @args );
say "$file => $target" unless $opt->{quiet};
}
# create index file
if ( $opt->{index} ) {
my $index = $modules->index(%$opt);
my $target =
File::Spec->catfile( $dir, $opt->{index} . '.' . $opt->{ext} );
$index->to_pandoc( @args, -o => $target );
say $target unless $opt->{quiet};
}
}
sub _parse_arguments {
my $modules = shift;
my $dir = ref $_[0] ? undef : shift;
my %opt = ref $_[0] ? %{ shift() } : ();
$dir //= $opt{dir} // croak "output directory must be specified!";
$opt{index} = 'index' unless exists $opt{index};
$opt{ext} //= 'html';
$opt{ext} =~ s/^\.//;
croak "ext must not be .pm or .pod" if $opt{ext} =~ /^(pod|pm)$/;
( $modules, $dir, \%opt, @_ );
}
1;
__END__
=head1 NAME
Pod::Pandoc::Modules - set of parsed documentation of Perl modules
=head1 SYNOPSIS
use Pod::Simple::Pandoc;
my $modules = Pod::Simple::Pandoc->new->parse_modules('lib');
$modules->serialize( { target => 'doc' }, '--template' => '...' ] ); # TODO
=head1 DESCRIPTION
Module to serialize Pod from a set of parsed Perl or Pod files. Can be
configured via templates, document rewriting etc. and used with many output
formats (html, markdown, and rst to be embedded in static site generators such
as Jekyll).
See L for how to create instances of this module.
=head1 METHODS
=head2 add( $name => $doc )
Add a module given as L unless a module of same C<$name>
already exists. As an exception a parsed L<.pod> file will override existing
entries. The document title is set to the module name if missing.
=head2 serialize ( [ $dir ] [, \%options ] [, @args ] )
Serialize a set of modules into a given directory.
This method is experimental and may change!
=over
=item dir
Output directory.
=item ext
Output file extension. Set to the value of C by default.
=item index
Index filename (with or without extension). Set to C by default. Use a
false value to disable index generation.
=item wiki
Don't create subdirectories and use wiki links for references between files.
instead.
=item update
Generate target files even if source files have not been updated.
=item quiet
Don't emit warnings and status information.
=back
=head2 index ( %options )
Create and return an index document as L.
=head1 SEE ALSO
This module is part of L.
=cut
app-pod2pandoc-arguments.t 100644 001750 001750 527 13275405016 17531 0 ustar 00voj voj 000000 000000 Pod-Pandoc-0.5.0/t use strict;
use Test::More;
use App::pod2pandoc qw(parse_arguments);
is_deeply
[ parse_arguments(qw(foo --bar doz --baz --wiki)) ],
[ ['foo'], { wiki => 1 }, qw(--bar doz --baz) ], 'parse_arguments';
is_deeply
[ parse_arguments(qw(foo -- doz --baz --wiki)) ],
[ ['foo'], {}, qw(doz --baz --wiki) ], 'parse_arguments';
done_testing;
pod-simple-pandoc-parse-modules.t 100644 001750 001750 674 13275405016 21013 0 ustar 00voj voj 000000 000000 Pod-Pandoc-0.5.0/t use strict;
use Test::More;
use Pod::Simple::Pandoc;
use Pandoc;
use Test::Output;
plan skip_all => 'pandoc not available' unless pandoc;
my $modules;
stderr_is {
$modules = Pod::Simple::Pandoc->parse_modules('t/examples');
} "t/examples/Foo.pm NAME does not match module\n".
"t/examples/Pandoc skipped for t/examples/Pandoc.pod\n",
"parse_modules";
is_deeply [ keys %$modules ], ['Pandoc'], 'module name from file';
done_testing;