App-PDoc

 view release on metacpan or  search on metacpan

lib/App/PDoc.pm  view on Meta::CPAN

package App::PDoc;

#  PODNAME: pdoc
# ABSTRACT: typeset pandoc documents with document-specific, default options

# pdoc
#
# What this script does:
# 1. Get the first argument passed to it
# 2. Slurp that file and leave @ARGV intact
# 3. Grep all lines "<!--+ (--some-pandoc-option) +-->" from that file
# 4. Grep all lines "<!--& (some post processing action) &-->" from that file
# 5. join them into a command to be executed:
#    a) if there are commands to be executed, attach them with &&'s
#    b) else, don't.
# 6. Send that command off to the shell


# What to do with your pandoc files
# ---------------------------------
# Sprinkle <!--+ --pandoc-option1 --pandoc--option2 +--> all over your file
# as your would use them on the shell
#
# If you want your file to be typeset using those options, run
#     pdoc file.pandoc
#
# If you want standard processing of that file, run pandoc as usual:
#     pandoc file.pandoc

# Daniel Bruder <daniel.bruder[@]gmail.com>
# WTFPL License <http://sam.zoy.org/wtfpl/>

sub main {
    $_    = do{ local(@ARGV => $/) = $ARGV[0]; <> };            # Slurp the file
    @opts = join " "        => m/<!--\+\s*(.*?)\s*\+-->/g;      # Get <!--+X+-->
    @exec = join " && \\\n" => m/<!--&\s*(.*?)\s*&-->/g;        # Get <!--&X&-->
    @cmd  = join " && \\\n" => "pandoc @opts @ARGV", @exec;     # Construct cmd
    exec @cmd                                                   # exec cmd
}


1;
__END__
=pod

=encoding utf-8

=head1 NAME

pdoc - typeset pandoc documents with document-specific, default options

=head1 VERSION

version 0.10.0

=head1 SYNOPSIS

This is just a small executable and a hack to pandoc:
you can use it to set document-specific, default options for pandoc
in the typesetting process.
Of course, you can safely ignore these settings and return to the standard way of doing things at all times.

=head1 USAGE

Usage is absolutely straight-forward:

=head2 Usage on the commandline

If you want your file to be typeset using the document-specific default options, run

     pdoc file.pandoc

If you want standard processing of that file, simply run pandoc as usual:

     pandoc file.pandoc

=head2 Setting document-specific options

=head3 Setting options

Sprinkle C<<< <!--+ --pandoc-option1 --pandoc--option2 +--> >>> all over your pandoc file -- just as your would use them on the shell.
C<<< pdoc >>> will read these and add them to the commandline that is passed to a standard pandoc typesetting.

=head3 Defining post-processing behavior

Use C<<< <!--& (some post processing action) &--> >>> as the special markup to C<<< pdoc >>> for post-processing options. These will be concatenated to the pandoc-commandline that is generated via C<<< && >>>, just like so:

     % pandoc --option1 --option2 && your-command-1 && your-command2

=head1 INTERNAL WORKINGS

This is just a simple hack reading out specially marked comments in your pandoc source. Everything will stay usable as always. When typesetting in the standard manner, these comments are simply ignored.

See the executable for the details.

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.394 second using v1.00-cache-2.02-grep-82fe00e-cpan-9e6bc14194b )