Pandoc-0.6.1000755001750001750 013171447552 11512 5ustar00vojvoj000000000000README100644001750001750 2144213171447552 12476 0ustar00vojvoj000000000000Pandoc-0.6.1NAME Pandoc - wrapper for the mighty Pandoc document converter SYNOPSIS use Pandoc; # check at first use use Pandoc 1.12; # check at compile time Pandoc->require(1.12); # check at run time # execute pandoc pandoc 'input.md', -o => 'output.html'; pandoc -f => 'html', -t => 'markdown', { in => \$html, out => \$md }; # alternative syntaxes pandoc->run('input.md', -o => 'output.html'); pandoc [ -f => 'html', -t => 'markdown' ], in => \$html, out => \$md; pandoc [ -f => 'html', -t => 'markdown' ], { in => \$html, out => \$md }; # check executable pandoc or die "pandoc executable not found"; # check minimum version pandoc->version > 1.12 or die "pandoc >= 1.12 required"; # access properties say pandoc->bin." ".pandoc->version; say "Default user data directory: ".pandoc->data_dir; say "Compiled with: ".join(", ", keys %{ pandoc->libs }); say pandoc->libs->{'highlighting-kate'}; # create a new instance with default arguments my $md2latex = Pandoc->new(qw(-f markdown -t latex --smart)); $md2latex->run({ in => \$markdown, out => \$latex }); # set default arguments on compile time use Pandoc qw(-t latex); use Pandoc qw(/usr/bin/pandoc --smart); use Pandoc qw(1.16 --smart); # utility method to convert from string $latex = pandoc->convert( 'markdown' => 'latex', '*hello*' ); # utility methods to parse abstract syntax tree (requires Pandoc::Elements) $doc = pandoc->parse( markdown => '*hello* **world!**' ); $doc = pandoc->file( 'example.md' ); $doc = pandoc->file; # read Markdown from STDIN DESCRIPTION This module provides a Perl wrapper for John MacFarlane's Pandoc document converter. IMPORTING The utility function pandoc is exported, unless the module is imported with an empty list (use Pandoc ();). Importing this module with a version number or a more complex version requirenment (e.g. use Pandoc 1.13; or use Pandoc '>= 1.6, !=1.7) will check version number of pandoc executable instead of version number of this module (see $Pandoc::VERSION for the latter). Additional import arguments can be passed to set the executable location and default arguments of the global Pandoc instance used by function pandoc. FUNCTIONS pandoc If called without parameters, this function returns a global instance of class Pandoc to execute methods, or undef if no pandoc executable was found. The location and/or name of pandoc executable can be set with environment variable PANDOC_PATH (set to the string pandoc by default). pandoc( ... ) If called with parameters, this functions runs the pandoc executable configured at the global instance of class Pandoc (pandoc->bin). Arguments are passed as command line arguments and options control input, output, and error stream as described below. Returns 0 on success. Otherwise returns the the exit code of pandoc executable or -1 if execution failed. Arguments and options can be passed as plain array/hash or as (possibly empty) reference in the following ways: pandoc @arguments, \%options; # ok pandoc \@arguments, %options; # ok pandoc \@arguments, \%options; # ok pandoc @arguments; # ok, if first of @arguments starts with '-' pandoc %options; # ok, if %options is not empty pandoc @arguments, %options; # not ok! Options in / out / err These options correspond to arguments $stdin, $stdout, and $stderr of IPC::Run3, see there for details. binmode_stdin / binmode_stdout / binmode_stderr These options correspond to the like-named options to IPC::Run3, see there for details. binmode If defined any binmode_stdin/binmode_stdout/binmode_stderr option which is undefined will be set to this value. return_if_system_error Set to true by default to return the exit code of pandoc executable. For convenience the pandoc function (after checking the binmode option) checks the contents of any scalar references passed to the in/out/err options with utf8::is_utf8() and sets the binmode_stdin/binmode_stdout/binmode_stderr options to :encoding(UTF-8) if the corresponding scalar is marked as UTF-8 and the respective option is undefined. Since all pandoc executable input/output must be UTF-8 encoded this is convenient if you run with use utf8, as you then don't need to set the binmode options at all (encode nor decode) when passing input/output scalar references. METHODS new( [ $executable ] [, @arguments ] ) Create a new instance of class Pandoc or throw an exception if no pandoc executable was found. The first argument, if given and not starting with -, can be used to set the pandoc executable (pandoc by default). Additional arguments are passed to the executable on each run. Repeated use of this constructor with same arguments is not recommended because pandoc --version is called for every new instance. run( ... ) Execute the pandoc executable with default arguments and optional additional arguments and options. See function pandoc for usage. convert( $from => $to, $input [, @arguments ] ) Convert a string in format $from to format $to. Additional pandoc options such as --smart and --standalone can be passed. The result is returned in same utf8 mode (utf8::is_unicode) as the input. To convert from file to string use method pandoc/run like this and set input/output format via standard pandoc arguments -f and -t: pandoc->run( $filename, @arguments, { out => \$string } ); parse( $from => $input [, @arguments ] ) Parse a string in format $from to a Pandoc::Document object. Additional pandoc options such as --smart and --normalize can be passed. This method requires at least pandoc version 1.12.1 and the Perl module Pandoc::Elements. The reverse action is possible with method to_pandoc of Pandoc::Document. Additional shortcut methods such as to_html are available: $html = pandoc->parse( 'markdown' => '# A *section*' )->to_html; Method convert should be preferred for simple conversions unless you want to modify or inspect the parsed document in between. file( [ $filename [, @arguments ] ] ) Parse from a file (or STDIN) to a Pandoc::Document object. Additional pandoc options can be passed, for instance use HTML input format (@arguments = qw(-f html)) instead of default markdown. This method requires at least pandoc version 1.12.1 and the Perl module Pandoc::Elements. require( $version_requirement ) Return the Pandoc instance if its version number fulfills a given version requirement. Throw an error otherwise. Can also be called as constructor: Pandoc->require(...) is equivalent to pandoc->require but throws a more meaningful error message if no pandoc executable was found. version( [ $version_requirement ] ) Return the pandoc version as Pandoc::Version object. If a version requirement is given, the method returns undef if the pandoc version does not fulfill this requirement. To check whether pandoc is available with a given minimal version use one of: Pandoc->require( $minimum_version) # true or die pandoc and pandoc->version( $minimum_version ) # true or false bin( [ $executable ] ) Return or set the pandoc executable. Setting an new executable also updates version and data_dir by calling pandoc --version. arguments( [ @arguments | \@arguments ) Return or set a list of default arguments. data_dir Return the default data directory (only available since Pandoc 1.11). input_formats Return a list of supported input formats. output_formats Return a list of supported output formats. highlight_languages Return a list of programming languages which syntax highlighting is supported for (via Haskell library highlighting-kate). libs Return a hash mapping the names of Haskell libraries compiled into the pandoc executable to Pandoc::Version objects. SEE ALSO See Pandoc::Elements for a Perl interface to the abstract syntax tree of Pandoc documents for more elaborate document processing. See Pandoc wrappers and interfaces in the Pandoc GitHub Wiki for a list of wrappers in other programming languages. Other Pandoc related but outdated modules at CPAN include Orze::Sources::Pandoc and App::PDoc. AUTHOR Jakob Voß CONTRIBUTORS Benct Philip Jonsson LICENSE GNU General Public License, Version 2 Changes100644001750001750 303613171447552 13070 0ustar00vojvoj000000000000Pandoc-0.6.1Revision history for Pandoc Perl module 0.6.1 2017-10-17 20:43:51 CEST - make sure to override existing options and output destination (#16) 0.6.0 2017-01-27 10:51:10 CET - support more expressive version requirements 0.5.0 2016-11-24 14:14:34 CET - add method Pandoc::Version::match 0.4.3 2016-11-09 21:11:53 CET - fix bug with executable not named 'pandoc' 0.4.2 2016-11-09 19:39:45 CET - fix test for pandoc 1.9 0.4.1 2016-11-03 21:14:26 CET - add method highlight_languages - support calling run( $filename, ... ) - strip '*' from input/output format names 0.4.0 2016-11-01 20:44:15 CET - add Pandoc::Version module for version numbers - allow setting executable via PANDOC_PATH environment variable - add method file to parse from file - add method libs to access libraries used by pandoc - prepare to adjust Pandoc::Elements for pandoc 1.18 0.3.1 2016-10-26 20:37:24 CEST - add parse method - fix version number comparison - extend documentation 0.3.0 2016-10-21 20:10:30 CEST - support setting default arguments on import - make bin and arguments setters - use File::Which to find executable 0.2.2 2016-10-20 11:20:36 CEST - support default arguments 0.2.1 2016-10-20 10:34:31 CEST - add method input_format and output_format - let version return a version object 0.2.0 2016-10-18 21:58:19 CEST - add alternative calling conventions for pandoc/run - add utility method convert 0.1.0 2016-10-10 10:37:02 CEST - create initial release t000755001750001750 013171447552 11676 5ustar00vojvoj000000000000Pandoc-0.6.1run.t100644001750001750 450513171447552 13033 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More 0.96; # for subtests use Test::Exception; use Pandoc; plan skip_all => 'pandoc executable required' unless pandoc; # XXX: does Test::More/IPC::Run3 lack write permissions? my $args = ['-t' => 'markdown']; subtest 'pandoc( ... )' => sub { my ($html, $md); is pandoc({ in => \'*.*', out => \$html }), 0, 'pandoc({in =>..., out=>...}'; is $html, "

.

\n", 'markdown => html'; ## no critic pandoc -f => 'html', -t => 'markdown', { in => \$html, out => \$md }; like $md, qr/^\*\.\*/, 'html => markdown'; }; subtest 'run(@args, \%opts)' => sub { my $in = 'foo'; my %opts = ( in => \$in, out => \my($out), err => \my($err) ); lives_ok { pandoc->run( @$args, \%opts ) }, 'run'; like $out, qr!^\s*foo\s*$!, 'stdout'; note $out; is $err //= "", "", 'stderr'; lives_ok { pandoc->run( 'README.md', \%opts ) }, 'run with filename'; }; subtest '->run(\@args, \%opts)' => sub { my $in = 'foo'; my %opts = ( in => \$in, out => \my($out), err => \my($err) ); lives_ok { pandoc->run( $args, \%opts ) }, 'run'; like $out, qr!^\s*foo\s*$!, 'stdout'; is $err //= "", "", 'stderr'; }; subtest '->run(\@args, %opts)' => sub { my $in = 'foo'; my %opts = ( in => \$in, out => \my($out), err => \my($err) ); lives_ok { pandoc->run( $args, %opts ) }, 'run'; like $out, qr!^\s*foo\s*$!, 'stdout'; is $err //= "", "", 'stderr'; }; subtest '->run([], %opts)' => sub { my $in = 'foo'; my %opts = ( in => \$in, out => \my($out), err => \my($err) ); lives_ok { pandoc->run( [], %opts ) }, 'run'; like $out, qr!

foo

!, 'stdout'; is $err //= "", "", 'stderr'; }; subtest 'run(%opts)' => sub { my $out; lives_ok { pandoc in => \"# hi", out => \$out }; is $out, "

hi

\n", 'run( %opts )'; }; subtest '->run(\@args, qw[odd length list])' => sub { my $in = 'foo'; my %opts = ( in => \$in, out => \my($out), err => \my($err) ); throws_ok { pandoc->run( $args, %opts, 'foo' ) } qr!^\QToo many or ambiguous arguments!, 'run'; }; subtest '->run(\@args, ..., \%opts)' => sub { my $in = 'foo'; my %opts = ( in => \$in, out => \my($out), err => \my($err) ); throws_ok { pandoc->run( $args, qw[foo, bar], \%opts ) } qr!^\QToo many or ambiguous arguments!, 'run'; }; done_testing; LICENSE100644001750001750 4350013171447552 12622 0ustar00vojvoj000000000000Pandoc-0.6.1This software is Copyright (c) 2017 by Jakob Voß. This is free software, licensed under: The GNU General Public License, Version 2, June 1991 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. cpanfile100644001750001750 25113171447552 13255 0ustar00vojvoj000000000000Pandoc-0.6.1requires 'perl', '5.010'; requires 'IPC::Run3'; requires 'File::Which', '1.11'; on test => sub { requires 'Test::More', '0.96'; requires 'Test::Exception'; }; dist.ini100644001750001750 4713171447552 13200 0ustar00vojvoj000000000000Pandoc-0.6.1author=Jakob Voß name=Pandoc [@Milla] Build.PL100644001750001750 25113171447552 13045 0ustar00vojvoj000000000000Pandoc-0.6.1# This Build.PL for Pandoc was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.010. use strict; use warnings; use 5.010; use Module::Build::Tiny 0.039; Build_PL(); META.yml100644001750001750 166113171447552 13050 0ustar00vojvoj000000000000Pandoc-0.6.1--- abstract: 'wrapper for the mighty Pandoc document converter' author: - 'Jakob Voß' build_requires: Test::Exception: '0' Test::More: '0.96' configure_requires: Module::Build::Tiny: '0.039' dynamic_config: 0 generated_by: 'Dist::Zilla version 5.036, Dist::Milla version v1.0.15, CPAN::Meta::Converter version 2.150001' license: gpl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Pandoc no_index: directory: - t - xt - inc - share - eg - examples requires: File::Which: '1.11' IPC::Run3: '0' perl: '5.010' resources: bugtracker: https://github.com/nichtich/Pandoc-Wrapper/issues homepage: https://github.com/nichtich/Pandoc-Wrapper repository: https://github.com/nichtich/Pandoc-Wrapper.git version: 0.6.1 x_contributors: - 'Benct Philip Jonsson ' - 'Edward Betts ' - 'Jakob Voß ' MANIFEST100644001750001750 53713171447552 12711 0ustar00vojvoj000000000000Pandoc-0.6.1# This file was automatically generated by Dist::Zilla::Plugin::Manifest v5.036. Build.PL Changes LICENSE MANIFEST META.json META.yml README cpanfile dist.ini lib/Pandoc.pm lib/Pandoc/Version.pm t/binmode.t t/convert.t t/example.md t/executables.t t/file-objects.t t/import.t t/lists.t t/methods.t t/parse.t t/release-pod-syntax.t t/run.t t/version.t lists.t100644001750001750 44313171447552 13342 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More; use Test::Exception; use Pandoc; plan skip_all => 'pandoc executable required' unless pandoc; my @list; @list = pandoc->input_formats; ok scalar @list > 5, 'input_formats'; @list = pandoc->output_formats; ok scalar @list > 5, 'output_formats'; done_testing; parse.t100644001750001750 232113171447552 13333 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More; use Test::Exception; use Pandoc; plan skip_all => 'pandoc executable >= 1.12.1 required' unless pandoc and pandoc->version('1.12.1'); plan skip_all => 'pandoc executable < 1.18 required' # FIXME in Pandoc::Elements if pandoc->version('1.18'); plan skip_all => 'Pandoc::Elements required' unless eval { require Pandoc::Elements; 1 }; my $expect = '{"c":[{"c":[{"c":"--ä","t":"Str"}],"t":"Emph"}],"t":"Para"}'; my $doc = pandoc->parse( markdown => "*--ä*" ); isa_ok $doc, 'Pandoc::Document', 'parse markdown'; is $doc->content->[0]->to_json, $expect, 'parse markdown'; $doc = pandoc->parse( html => '

--ä

', '--normalize' ); is $doc->content->[0]->to_json, $expect, 'parse html'; $doc = pandoc->parse( markdown => "*--ä*", '--smart' ); is $doc->string, "\x{2013}\x{00E4}", 'parse with addition arguments'; is_deeply $doc, pandoc->parse( json => $doc->to_json ), 'parse json'; my $ex = pandoc->file('t/example.md', '--smart'); is_deeply $ex, $doc, 'parse_file'; if ($Pandoc::Elements::VERSION >= 0.29) { my $html = pandoc->parse( 'markdown' => '# A *section*' )->to_html; ok $html =~ qr{]*>A section}, 'parse->to_html'; } done_testing; META.json100644001750001750 330413171447552 13214 0ustar00vojvoj000000000000Pandoc-0.6.1{ "abstract" : "wrapper for the mighty Pandoc document converter", "author" : [ "Jakob Voß" ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 5.036, Dist::Milla version v1.0.15, CPAN::Meta::Converter version 2.150001", "license" : [ "gpl_2" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Pandoc", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples" ] }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.039" } }, "develop" : { "requires" : { "Dist::Milla" : "v1.0.15", "Test::Pod" : "1.41" } }, "runtime" : { "requires" : { "File::Which" : "1.11", "IPC::Run3" : "0", "perl" : "5.010" } }, "test" : { "requires" : { "Test::Exception" : "0", "Test::More" : "0.96" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/nichtich/Pandoc-Wrapper/issues" }, "homepage" : "https://github.com/nichtich/Pandoc-Wrapper", "repository" : { "type" : "git", "url" : "https://github.com/nichtich/Pandoc-Wrapper.git", "web" : "https://github.com/nichtich/Pandoc-Wrapper" } }, "version" : "0.6.1", "x_contributors" : [ "Benct Philip Jonsson ", "Edward Betts ", "Jakob Voß " ] } import.t100644001750001750 125213171447552 13535 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More; use Test::Exception; BEGIN { require Pandoc; if ($ENV{RELEASE_TESTING}) { Pandoc->import(qw(-t latex)); } else { plan skip_all => 'these tests are for release candidate testing'; } } is_deeply [ pandoc->arguments ], [qw(-t latex)], 'import with arguments'; throws_ok { Pandoc->VERSION(99) } qr/^pandoc 99 required/, '!use Pandoc 99'; throws_ok { Pandoc->import(99) } qr/^pandoc 99 required/, '!use Pandoc qw(99 ...)'; lives_ok { Pandoc->VERSION(pandoc->version) } "use Pandoc ".pandoc->version; lives_ok { Pandoc->VERSION('1.9') } "use Pandoc 1.9"; lives_ok { Pandoc->VERSION('v1') } "use Pandoc 'v1'"; done_testing; binmode.t100644001750001750 135413171447552 13643 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More; use Pandoc; use utf8; # essential! sub capture_stderr(&;@); plan skip_all => 'pandoc executable required' unless pandoc; plan skip_all => 'Capture::Tiny required' unless eval 'use Capture::Tiny qw(capture_stderr); 1;'; my $input = <<'DUMMY_TEXT'; ## Ëïüs Üt Qüï äüt völüptätë mïnïmä. DUMMY_TEXT my( $output, $stderr ); $stderr = capture_stderr { pandoc->run( +{ in => \$input, out => \$output } ) }; unlike $stderr, qr{Wide character in print}, 'no wide character warning'; $stderr = capture_stderr { pandoc->run( +{ in => \$input, out => \$output, binmode => ':encoding(UTF-8)' } ) }; unlike $stderr, qr{Wide character in print}, 'one binmode for all handles'; done_testing; convert.t100644001750001750 137613171447552 13712 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More; use Test::Exception; use Pandoc; plan skip_all => 'pandoc executable required' unless pandoc; my $latex = pandoc->convert('html' => 'latex', 'hällo'); is $latex, '\emph{hällo}', 'html => latex'; my $html = pandoc->convert('markdown' => 'html', '...', '--smart'); is $html, '

', 'markdown => html'; is $html, "

\xE2\x80\xA6

", 'convert returns bytes'; utf8::decode($html); my $markdown = pandoc->convert('html' => 'markdown', $html); like $markdown, qr{^\x{2026}}, 'convert returns Unicode to Unicode'; throws_ok { pandoc->convert('latex' => 'html', '', '--template' => '') } qr/^pandoc: /, 'croak on error'; like pandoc->convert('latex' => 'html', '$\rightarrow$'), qr/→/, 'unicode'; done_testing; methods.t100644001750001750 722313171447552 13672 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More; use Test::Exception; use File::Which; use Pandoc; use Scalar::Util 'reftype'; plan skip_all => 'pandoc executable required' unless pandoc; # import { throws_ok { Pandoc->import('999.9.9') } qr/^pandoc 999\.9\.9 required, only found \d+(\.\d)+/, 'import'; } # require { my $pandoc; lives_ok { $pandoc = Pandoc->require('0.1.0.1') } 'Pandoc->require'; is_deeply $pandoc, pandoc, 'require returns singleton'; lives_ok { pandoc->require('0.1.0.1') } 'pandoc->require'; throws_ok { pandoc->require('x') } qr{ at t/methods.t}m, 'require throws)'; throws_ok { pandoc->require('12345.67') } qr/^pandoc 12345\.67 required, only found \d+(\.\d)+/, 'require throws'; } # new { my $pandoc = Pandoc->new; is_deeply $pandoc, pandoc(), 'Pandoc->new'; ok $pandoc != pandoc, 'Pandoc->new creates new instance'; throws_ok { Pandoc->new('/dev/null/notexist') } qr{pandoc executable not found}; } # bin { is pandoc->bin, which($ENV{PANDOC_PATH} || 'pandoc'), 'default executable'; # not an full test but part of it lives_ok { pandoc->bin( pandoc->bin ) } 'set executable'; throws_ok { pandoc->bin('/dev/null/notexist') } qr{pandoc executable not found}; } # version { my $version = pandoc->version; like( $version, qr/^\d+(.\d+)+$/, 'pandoc->version' ); isa_ok $version, 'Pandoc::Version', 'pandoc->version is a version object'; ok pandoc->version >= $version, 'compare same versions'; is pandoc->version($version), $version, 'expect same version'; ok pandoc->version > '0.1.2', 'compare lower versions'; is pandoc->version('0.1.2'), $version, 'expect lower version'; $version =~ s/(\d+)$/$1+1/e; ok pandoc->version < $version, 'compare higher versions'; ok !pandoc->version($version), 'expect higher version'; throws_ok { pandoc->version('abc') } qr{at t/methods\.t}m, 'invalid version'; } # arguments { my $pandoc = Pandoc->new(qw(--smart -t html)); is_deeply [$pandoc->arguments], [qw(--smart -t html)], 'arguments'; $pandoc = Pandoc->new(qw(pandoc --smart -t html)); is $pandoc->bin, which('pandoc'), 'executable and arguments'; is_deeply [$pandoc->arguments], [qw(--smart -t html)], 'arguments'; my ($in, $out) = ('*...*'); is $pandoc->run([], in => \$in, out => \$out), 0, 'run'; is $out, "

\n", 'use default arguments'; is $pandoc->run( '-t' => 'latex', { in => \$in, out => \$out }), 0, 'run'; is $out, "\\emph{\\ldots{}}\n", 'override default arguments'; throws_ok { $pandoc->arguments(1) } qr/^first default argument must be an -option/; pandoc->arguments('--smart'); is_deeply [ pandoc->arguments ], ['--smart'], 'set arguments'; pandoc->arguments([]); is_deeply [ pandoc->arguments ], [], 'set arguments with array ref'; } # data_dir { if (-d $ENV{HOME}.'/.pandoc' and pandoc->version('1.11')) { ok( pandoc->data_dir, 'pandoc->data_dir' ); } } # libs { is reftype(pandoc->libs), 'HASH', 'pandoc->libs'; if ($ENV{RELEASE_TESTING}) { # don't assume any libraries isa_ok pandoc->libs->{'highlighting-kate'}, 'Pandoc::Version'; } } # input_formats / output_formats { my $want = qr/^(markdown|latex|html|json)$/; is scalar (grep { $_ =~ $want} pandoc->input_formats), 4, 'input_formats'; is scalar (grep { $_ =~ $want} pandoc->output_formats), 4, 'output_formats'; } # highlight_languages { # we cannot assume that highlighting is enabled but it should not die if (pandoc->libs->{'highlighting-kate'}) { ok scalar( pandoc->highlight_languages ) > 10, 'highlight_languages'; } } done_testing; version.t100644001750001750 465413171447552 13721 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More; use Test::Exception; use Pandoc::Version; { my %same = ( array => [ [ 1, 17, 0, 4 ] ], list => [ ( 1, 17, 0, 4 ) ], string => ['1.17.0.4'], vstring => ['v1.17.0.4'], ); foreach ( sort keys %same ) { my $version = new_ok 'Pandoc::Version', $same{$_}, "new from $_"; is_deeply $version->TO_JSON, [qw(1 17 0 4)], "from $_"; } my @invalid = ( [{}], ['1..2'], ['abc'], ['1.9a'], ['0.-1'], [], [''], [undef] ); foreach ( @invalid ) { throws_ok { Pandoc::Version->new(@{$_}) } qr{^invalid version number}, 'invalid version number'; } } { my $version = bless [ 1, 17, 0, 4 ], 'Pandoc::Version'; new_ok 'Pandoc::Version', [ $version ], 'copy constructor'; is "$version", '1.17.0.4', 'stringify'; is $version->number, 1.017000004, 'number'; my %tests = ( '1.9' => { eq => '1.9', gt => '1.10', }, '1' => { eq => '1.0', gt => '1.0.1', }, '1.17.0.4' => { eq => '1.17.0.4', gt => '1.18', } ); foreach ( sort keys %tests ) { my $version = Pandoc::Version->new($_); my $eq = $tests{$_}{eq}; my $gt = $tests{$_}{gt}; ok $version == $eq, "$version == ".$eq; ok $version >= $eq, "$version >= ".$eq; ok $version <= $eq, "$version <= ".$eq; ok $version eq $eq, "$version eq ".$eq; ok $version ge $eq, "$version ge ".$eq; ok $version le $eq, "$version le ".$eq; if ( defined $gt ) { ok $version < $gt, "$version < $gt"; ok $version lt $gt, "$version lt $gt"; } } } { my $version = Pandoc::Version->new('1.7.3'); ok($version->match($_), "1.7.3 match $_") for qw(1 1.7 1.7.3 1.7.3.1); ok(!$version->match($_), "1.7.3 no match $_") for qw(1.6 1.8 2); } { my $version = Pandoc::Version->new('1.7'); my @yes = qw(1.7 !=1.7.1 >1.6 >=1.7 <1.7.1 <=1.7.1 ==1.7); for (@yes, join ', ', @yes) { ok $version->fulfills($_), "fulfills $_"; } my @no = qw(1.7,!=1.7 1.7.1 >1.7 >=1.7.1 <1.7 <=1.6 ==1.7.1); for (@no, join(', ', @yes, @no)) { ok !$version->fulfills($_), "!fulfills $_"; } throws_ok { $version->fulfills('foo') } qr/^invalid version requirement: foo/, 'invalid version requirement'; } done_testing; example.md100644001750001750 713171447552 13730 0ustar00vojvoj000000000000Pandoc-0.6.1/t*--ä* lib000755001750001750 013171447552 12201 5ustar00vojvoj000000000000Pandoc-0.6.1Pandoc.pm100644001750001750 3673113171447552 14135 0ustar00vojvoj000000000000Pandoc-0.6.1/libpackage Pandoc; use strict; use warnings; use 5.010; use utf8; =head1 NAME Pandoc - wrapper for the mighty Pandoc document converter =cut our $VERSION = '0.6.1'; use Pandoc::Version; use Carp 'croak'; use File::Which; use IPC::Run3; use parent 'Exporter'; our @EXPORT = qw(pandoc); our $PANDOC; our $PANDOC_PATH ||= $ENV{PANDOC_PATH} || 'pandoc'; sub import { shift; if (@_ and $_[0] =~ /^[v0-9.<>=!, ]+$/) { $PANDOC //= Pandoc->new; $PANDOC->require(shift); } $PANDOC //= Pandoc->new(@_) if @_; Pandoc->export_to_level(1, 'pandoc'); } sub VERSION { shift; $PANDOC //= Pandoc->new; $PANDOC->require(shift) if @_; $PANDOC->version; } sub new { my $pandoc = bless { }, shift; my $bin = (@_ and $_[0] !~ /^-./) ? shift : $PANDOC_PATH; $pandoc->{bin} = which($bin); $pandoc->{arguments} = []; $pandoc->arguments(@_) if @_; my ($in, $out); if ($pandoc->{bin}) { run3 [ $pandoc->{bin},'-v'], \$in, \$out, \undef, { return_if_system_error => 1 }; } croak "pandoc executable not found\n" unless $out and $out =~ /^[^ ]+ (\d+(\.\d+)+)/; $pandoc->{version} = Pandoc::Version->new($1); $pandoc->{data_dir} = $1 if $out =~ /^Default user data directory: (.+)$/m; # before pandoc supported --list-highlight-languages if ( $out =~ /^Syntax highlighting is supported/m ) { $pandoc->{highlight_languages} = [ map { split /\s*,\s*/, $_ } ($out =~ /^ (.+)$/mg) ]; } my %libs; my $LIBRARY_VERSION = qr/\s+(\pL\w*(?:-\pL\w*)*)\s+(\d+(?:\.\d+)*),?/; if ( $out =~ /^Compiled with($LIBRARY_VERSION+)/m ) { %libs = $1 =~ /$LIBRARY_VERSION/g; for my $name ( keys %libs ) { $libs{$name} = Pandoc::Version->new( $libs{$name} ); } } $pandoc->{libs} = \%libs; return $pandoc; } sub pandoc(@) { ## no critic $PANDOC //= eval { Pandoc->new } // 0; if (@_) { return $PANDOC ? $PANDOC->run(@_) : -1; } else { return $PANDOC; } } sub run { my $pandoc = shift; my $args = 'ARRAY' eq ref $_[0] ? \@{shift @_} : undef; # \@args [ ... ] my $opts = 'HASH' eq ref $_[-1] ? \%{pop @_} : undef; # [ ... ] \%opts if ( @_ ) { if ( !$args ) { # @args if ($_[0] =~ /^-/ or $opts) { $args = \@_; } else { # %opts $opts = { @_ }; } } elsif ( $args and !$opts and (@_ % 2 == 0) ) { # \@args [, %opts ] $opts = { @_ }; } else { # passed both the args and opts by ref, # so other arguments don't make sense; # or passed args by ref and an odd-length list croak 'Too many or ambiguous arguments'; } } $args //= []; $opts //= {}; for my $io ( qw(in out err) ) { $opts->{"binmode_std$io"} //= $opts->{binmode} if $opts->{binmode}; if ( 'SCALAR' eq ref $opts->{$io} ) { next unless utf8::is_utf8(${$opts->{$io}}); $opts->{"binmode_std$io"} //= ':encoding(UTF-8)'; } } $opts->{return_if_system_error} //= 1; $args = [ $pandoc->{bin}, @{$pandoc->{arguments}}, @$args ]; run3 $args, $opts->{in}, $opts->{out}, $opts->{err}, $opts; return $? == -1 ? -1 : $? >> 8; } sub convert { my $pandoc = shift; my $from = shift; my $to = shift; my $in = shift; my $out = ""; my $err = ""; my $utf8 = utf8::is_utf8($in); my %opts = (in => \$in, out => \$out, err => \$err); my @args = (@_, '-f' => $from, '-t' => $to, '-o' => '-'); my $status = $pandoc->run( \@args, \%opts ); croak($err || "pandoc failed with exit code $status") if $status; utf8::decode($out) if $utf8; chomp $out; return $out; } sub parse { my $pandoc = shift; my $format = shift; my $json = ""; if ($format eq 'json') { $json = shift; } else { $pandoc->require('1.12.1'); $json = $pandoc->convert( $format => 'json', @_ ); } require Pandoc::Elements; Pandoc::Elements::pandoc_json($json); } sub file { my $pandoc = shift; $pandoc->require('1.12.1'); my ($json, $err); my @args = (@_, '-t' => 'json', '-o' => '-'); my $status = $pandoc->run( \@args, out => \$json, err => \$err ); croak($err || "pandoc failed with exit code $status") if $status; #utf8::decode($out) if $utf8; require Pandoc::Elements; Pandoc::Elements::pandoc_json($json); } sub require { my $pandoc = shift; $pandoc = do { $PANDOC //= Pandoc->new } if $pandoc eq 'Pandoc'; unless ($pandoc->version(@_)) { croak "pandoc $_[0] required, only found ".$pandoc->{version}."\n" } return $pandoc; } sub version { my $pandoc = shift or return; my $version = $pandoc->{version} or return; # compare against given version return if @_ and not $version->fulfills(@_); return $version; } sub data_dir { $_[0]->{data_dir}; } sub bin { my $pandoc = shift; if (@_) { my $new = Pandoc->new(shift); $pandoc->{$_} = $new->{$_} for (qw(version bin data_dir)); } $pandoc->{bin}; } sub arguments { my $pandoc = shift; if (@_) { my $args = 'ARRAY' eq ref $_[0] ? shift : \@_; croak "first default argument must be an -option" if @$args and $args->[0] !~ /^-./; $pandoc->{arguments} = $args; } @{$pandoc->{arguments}}; } sub _list { my ($pandoc, $which) = @_; if (!$pandoc->{$which}) { if ($pandoc->version('1.18')) { my $list = ""; my $command = $which; $command =~ s/_/-/g; $pandoc->run("--list-$command", { out => \$list }); $pandoc->{$which} = [ split /\n/, $list ]; } elsif (!defined $pandoc->{help}) { my $help; $pandoc->run('--help', { out => \$help }); for my $inout (qw(Input Output)) { $help =~ /^$inout formats:\s+([a-z_0-9,\+\s*]+)/m or next; $pandoc->{lc($inout).'_formats'} = [ split /\*?,\s+|\*?\s+/, $1 ]; } $pandoc->{help} = $help; } } @{$pandoc->{$which} // []}; } sub input_formats { $_[0]->_list('input_formats'); } sub output_formats { $_[0]->_list('output_formats'); } sub highlight_languages { $_[0]->_list('highlight_languages'); } sub libs { $_[0]->{libs}; } 1; __END__ =encoding utf-8 =begin markdown # STATUS [![Build Status](https://travis-ci.org/nichtich/Pandoc-Wrapper.svg)](https://travis-ci.org/nichtich/Pandoc-Wrapper) [![Coverage Status](https://coveralls.io/repos/nichtich/Pandoc-Wrapper/badge.svg)](https://coveralls.io/r/nichtich/Pandoc-Wrapper) [![Kwalitee Score](http://cpants.cpanauthors.org/dist/Pandoc.png)](http://cpants.cpanauthors.org/dist/Pandoc) =end markdown =head1 SYNOPSIS use Pandoc; # check at first use use Pandoc 1.12; # check at compile time Pandoc->require(1.12); # check at run time # execute pandoc pandoc 'input.md', -o => 'output.html'; pandoc -f => 'html', -t => 'markdown', { in => \$html, out => \$md }; # alternative syntaxes pandoc->run('input.md', -o => 'output.html'); pandoc [ -f => 'html', -t => 'markdown' ], in => \$html, out => \$md; pandoc [ -f => 'html', -t => 'markdown' ], { in => \$html, out => \$md }; # check executable pandoc or die "pandoc executable not found"; # check minimum version pandoc->version > 1.12 or die "pandoc >= 1.12 required"; # access properties say pandoc->bin." ".pandoc->version; say "Default user data directory: ".pandoc->data_dir; say "Compiled with: ".join(", ", keys %{ pandoc->libs }); say pandoc->libs->{'highlighting-kate'}; # create a new instance with default arguments my $md2latex = Pandoc->new(qw(-f markdown -t latex --smart)); $md2latex->run({ in => \$markdown, out => \$latex }); # set default arguments on compile time use Pandoc qw(-t latex); use Pandoc qw(/usr/bin/pandoc --smart); use Pandoc qw(1.16 --smart); # utility method to convert from string $latex = pandoc->convert( 'markdown' => 'latex', '*hello*' ); # utility methods to parse abstract syntax tree (requires Pandoc::Elements) $doc = pandoc->parse( markdown => '*hello* **world!**' ); $doc = pandoc->file( 'example.md' ); $doc = pandoc->file; # read Markdown from STDIN =head1 DESCRIPTION This module provides a Perl wrapper for John MacFarlane's L document converter. =head2 IMPORTING The utility function L is exported, unless the module is imported with an empty list (C). Importing this module with a version number or a more complex version requirenment (e.g. C or C<< use Pandoc '>= 1.6, !=1.7 >>) will check version number of pandoc executable instead of version number of this module (see C<$Pandoc::VERSION> for the latter). Additional import arguments can be passed to set the executable location and default arguments of the global Pandoc instance used by function pandoc. =head1 FUNCTIONS =head2 pandoc If called without parameters, this function returns a global instance of class Pandoc to execute L, or C if no pandoc executable was found. The location and/or name of pandoc executable can be set with environment variable C (set to the string C by default). =head2 pandoc( ... ) If called with parameters, this functions runs the pandoc executable configured at the global instance of class Pandoc (C<< pandoc->bin >>). Arguments are passed as command line arguments and options control input, output, and error stream as described below. Returns C<0> on success. Otherwise returns the the exit code of pandoc executable or C<-1> if execution failed. Arguments and options can be passed as plain array/hash or as (possibly empty) reference in the following ways: pandoc @arguments, \%options; # ok pandoc \@arguments, %options; # ok pandoc \@arguments, \%options; # ok pandoc @arguments; # ok, if first of @arguments starts with '-' pandoc %options; # ok, if %options is not empty pandoc @arguments, %options; # not ok! =head3 Options =over =item in / out / err These options correspond to arguments C<$stdin>, C<$stdout>, and C<$stderr> of L, see there for details. =item binmode_stdin / binmode_stdout / binmode_stderr These options correspond to the like-named options to L, see there for details. =item binmode If defined any binmode_stdin/binmode_stdout/binmode_stderr option which is undefined will be set to this value. =item return_if_system_error Set to true by default to return the exit code of pandoc executable. =back For convenience the C function (I checking the C option) checks the contents of any scalar references passed to the in/out/err options with L<< utf8::is_utf8()|utf8/"* C<$flag = utf8::is_utf8($string)>" >> and sets the binmode_stdin/binmode_stdout/binmode_stderr options to C<:encoding(UTF-8)> if the corresponding scalar is marked as UTF-8 and the respective option is undefined. Since all pandoc executable input/output must be UTF-8 encoded this is convenient if you run with L, as you then don't need to set the binmode options at all (L) when passing input/output scalar references. =head1 METHODS =head2 new( [ $executable ] [, @arguments ] ) Create a new instance of class Pandoc or throw an exception if no pandoc executable was found. The first argument, if given and not starting with C<->, can be used to set the pandoc executable (C by default). Additional arguments are passed to the executable on each run. Repeated use of this constructor with same arguments is not recommended because C is called for every new instance. =head2 run( ... ) Execute the pandoc executable with default arguments and optional additional arguments and options. See L for usage. =head2 convert( $from => $to, $input [, @arguments ] ) Convert a string in format C<$from> to format C<$to>. Additional pandoc options such as C<--smart> and C<--standalone> can be passed. The result is returned in same utf8 mode (C) as the input. To convert from file to string use method C/C like this and set input/output format via standard pandoc arguments C<-f> and C<-t>: pandoc->run( $filename, @arguments, { out => \$string } ); =head2 parse( $from => $input [, @arguments ] ) Parse a string in format C<$from> to a L object. Additional pandoc options such as C<--smart> and C<--normalize> can be passed. This method requires at least pandoc version 1.12.1 and the Perl module L. The reverse action is possible with method C of L. Additional shortcut methods such as C are available: $html = pandoc->parse( 'markdown' => '# A *section*' )->to_html; Method C should be preferred for simple conversions unless you want to modify or inspect the parsed document in between. =head2 file( [ $filename [, @arguments ] ] ) Parse from a file (or STDIN) to a L object. Additional pandoc options can be passed, for instance use HTML input format (C<@arguments = qw(-f html)>) instead of default markdown. This method requires at least pandoc version 1.12.1 and the Perl module L. =head2 require( $version_requirement ) Return the Pandoc instance if its version number fulfills a given version requirement. Throw an error otherwise. Can also be called as constructor: C<< Pandoc->require(...) >> is equivalent to C<< pandoc->require >> but throws a more meaningful error message if no pandoc executable was found. =head2 version( [ $version_requirement ] ) Return the pandoc version as L object. If a version requirement is given, the method returns undef if the pandoc version does not fulfill this requirement. To check whether pandoc is available with a given minimal version use one of: Pandoc->require( $minimum_version) # true or die pandoc and pandoc->version( $minimum_version ) # true or false =head2 bin( [ $executable ] ) Return or set the pandoc executable. Setting an new executable also updates version and data_dir by calling C. =head2 arguments( [ @arguments | \@arguments ) Return or set a list of default arguments. =head2 data_dir Return the default data directory (only available since Pandoc 1.11). =head2 input_formats Return a list of supported input formats. =head2 output_formats Return a list of supported output formats. =head2 highlight_languages Return a list of programming languages which syntax highlighting is supported for (via Haskell library highlighting-kate). =head2 libs Return a hash mapping the names of Haskell libraries compiled into the pandoc executable to L objects. =head1 SEE ALSO See L for a Perl interface to the abstract syntax tree of Pandoc documents for more elaborate document processing. See L in the Pandoc GitHub Wiki for a list of wrappers in other programming languages. Other Pandoc related but outdated modules at CPAN include L and L. =head1 AUTHOR Jakob Voß =head1 CONTRIBUTORS Benct Philip Jonsson =head1 LICENSE GNU General Public License, Version 2 =cut executables.t100644001750001750 60113171447552 14504 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More; use File::Temp; use Pandoc; plan skip_all => 'pandoc executable required' unless pandoc; plan skip_all => 'these tests are for release candidate testing' unless $ENV{RELEASE_TESTING}; my $dir = File::Temp->newdir; ok symlink(pandoc->bin, "$dir/foo"), 'create symlink'; new_ok 'Pandoc', [ "$dir/foo" ], 'executable not named "pandoc"'; done_testing; file-objects.t100644001750001750 113013171447552 14564 0ustar00vojvoj000000000000Pandoc-0.6.1/tuse strict; use Test::More; use Test::Exception; use Pandoc; use subs qw(path tempdir); plan skip_all => 'pandoc executable required' unless pandoc; plan skip_all => 'Path::Tiny required' unless eval 'use Path::Tiny qw(path tempdir); 1;'; my $dir = tempdir( CLEANUP => 1 ); (my $input = $dir->child('input.md'))->spew_utf8(<<'DUMMY_TEXT'); ## Eius Ut Qui aut voluptate minima. DUMMY_TEXT note $input->slurp_utf8; my $output = $dir->child('output.html'); lives_ok { pandoc->run(-o => $output, $input) } 'call pandoc with file objects as arguments'; note $output->slurp_utf8; done_testing; Pandoc000755001750001750 013171447552 13405 5ustar00vojvoj000000000000Pandoc-0.6.1/libVersion.pm100644001750001750 1034213171447552 15550 0ustar00vojvoj000000000000Pandoc-0.6.1/lib/Pandocpackage Pandoc::Version; use strict; use warnings; use 5.010; use utf8; =head1 NAME Pandoc::Version - version number of pandoc and its libraries =cut our $VERSION = '0.6.1'; use overload '""' => 'string', '0+' => 'number', cmp => 'cmp', '<=>' => 'cmp', fallback => 1; use Carp qw(croak); use Scalar::Util qw(reftype blessed); our @CARP_NOT = ('Pandoc'); sub new { my $class = shift; # We accept array or string input # (or mixed but let's not document that!) my @nums = map { my $num = $_; $num =~ /^\d+$/ or croak 'invalid version number'; $num =~ s/^0+(?=\d)//; # ensure decimal interpretation $num = 0+ $num; $num } map { s/^v//i; split /\./ } ## no critic map { 'ARRAY' CORE::eq (reftype $_ // "") ? @$_ : $_ } map { $_ // '' } @_; croak 'invalid version number' unless @nums; return bless \@nums => $class; } sub string { join '.', @{ $_[0] } } sub number { my ($major, @minors) = @{ $_[0] }; no warnings qw(uninitialized numeric); if ( @minors ) { my $minor = join '', map { sprintf '%03d', $_ } @minors; return 0+ "$major.$minor"; # return a true number } return 0+ $major; } sub cmp { my ($a, $b) = map { (blessed $_ and $_->isa('Pandoc::Version')) ? $_ : Pandoc::Version->new($_ // ()) } ($_[0], $_[1]); return $a->number <=> $b->number; } sub match { my ($a, $b) = map { Pandoc::Version->new($_) } @_; pop @$a while @$a > @$b; pop @$b while @$b > @$a; return $a->number == $b->number; } my %cmp_truth_table = ( '==' => [0,1,0], '!=' => [1,0,1], '>=' => [0,1,1], '<=' => [1,1,0], '<' => [1,0,0], '>' => [0,0,1] ); sub fulfills { my ($self, $req) = @_; return 1 unless $req; my @parts = split qr{\s*,\s*}, $req; for my $part (@parts) { my ($op, $ver) = $part =~ m{^\s*(==|>=|>|<=|<|!=)?\s*v?(\d+(\.\d+)*)$}; croak "invalid version requirement: $req" unless defined $ver; my $cmp = $self->cmp($ver) + 1; # will be 0 for <, 1 for ==, 2 for > return unless $cmp_truth_table{$op || '>='}->[$cmp]; } 1; } sub TO_JSON { my ($self) = @_; return [ map { 0+ $_ } @$self ]; } 1; __END__ =head1 SYNOPSIS $version = Pandoc::Version->new("1.17.2"); # create version $version = bless [1,17,2], 'Pandoc::Version'; # equivalent "$version"; # stringify to "1.17.2" $version > 1.9; # compare $version->[0]; # major $version->[1]; # minor $version->match('1.17'); # true for 1.17, 1.17.x, 1.17.x.y... =head1 DESCRIPTION This module is used to store and compare version numbers of pandoc executable and Haskell libraries compiled into pandoc. A Pandoc::Version object is an array reference of one or more non-negative integer values. In most cases there is no need to create Pandoc::Version objects by hand. Just use the instances returned by methods C and C of module L and trust in overloading. =head1 METHODS =head2 string Return a string representation of a version, for instance C<"1.17.0.4">. This method is automatically called by overloading in string context. =head2 number Return a number representation of a version, for instance C<1.017000004>. This method is automatically called by overloading in number context. =head2 cmp( $version ) Compare two version numbers. This is method is used automatically by overloading to compare version objects with strings or numbers (operators C, C, C, C, C<==>, C<< < >>, C<< > >>, C<< <= >>, and C<< >= >>). =head2 match( $version ) Return whether a version number matches another version number if cut to the same number of parts. For instance C<1.2.3> matches C<1>, C<1.2>, and C<1.2.3>. =head2 fulfills( $version_requirement ) Return whether a version number fullfills a version requirement, such as C<=1.16, !=1.17>'. See L for possible values. =head2 TO_JSON Return an array reference of the version number to serialize in JSON format. =head1 SEE ALSO L is a similar module for Perl version numbers. L extends versions to Semantic Versioning as described at L. =cut release-pod-syntax.t100644001750001750 45613171447552 15734 0ustar00vojvoj000000000000Pandoc-0.6.1/t#!perl BEGIN { unless ($ENV{RELEASE_TESTING}) { require Test::More; Test::More::plan(skip_all => 'these tests are for release candidate testing'); } } # This file was automatically generated by Dist::Zilla::Plugin::PodSyntaxTests. use Test::More; use Test::Pod 1.41; all_pod_files_ok();