Pod-Pandoc-0.5.0000755001750001750 013275405016 12222 5ustar00vojvoj000000000000README100644001750001750 657713275405016 13202 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0NAME Pod::Pandoc - process Plain Old Documentation format with Pandoc DESCRIPTION The Plain Old Documentation format (Pod) is a markup language used to document Perl code (see perlpod for reference). Several Perl modules exist to process and convert Pod into other formats. Pod::Pandoc is an attempt to unify and extend Pod converting based on the Pandoc document converter. Pandoc supports more document formats in a more detailled and uniform way than any set of Perl modules will ever do. For this reason Pod::Pandoc provides methods to convert Pod to the Pandoc document model for further processing with Pandoc. OUTLINE * pod2pandoc is a command line script to convert Pod to any format supported by Pandoc. * App::pod2pandoc provides functionality of pod2pandoc to be used in Perl code. * Pod::Simple::Pandoc converts Pod to the abstract document model of Pandoc. * Pod::Pandoc::Modules manages a set of Pod documents of Perl modules. REQUIREMENTS Installation of this module does not require Pandoc but it is needed to make actual use of it. See http://pandoc.org/installing.html for installation. USAGE EXAMPLES Replace pod2html # pod2html --infile=input.pm --css=style.css --title=TITLE > output.html pod2pandoc input.pm --css=style.css --toc --name -o output.html Pandoc option --toc corresponds to pod2html option --index and is disabled by default. pod2pandoc adds title and subtitle from NAME section. Replace pod2markdown # pod2markdown input.pod pod2pandoc input.pod -t markdown # pod2markdown input.pod output.md pod2pandoc input.pod -o output.md GitHub wiki The GitHub wiki of this project is automatically populated with its module documentation. Wiki pages are created with pod2pandoc as following (see script update-wiki.sh): pod2pandoc lib/ script/ wiki/ --ext md --index Home --wiki -t markdown_github Sphinx and Read The Docs The Sphinx documentation generator recommends documents in reStructureText format. It further requires a configuration file conf.py and some links need to be adjusted because Pandoc does not support wikilinks in rst output format (see script update-docs.sh: pod2pandoc lib/ script/ docs/ --ext rst --wiki -t rst --standalone perl -pi -e 's!`([^`]+) <([^>]+)>`__!-e "docs/$2.rst" ? ":doc:`$1 <$2>`" : "`$1 <$2>`__"!e' docs/*.rst make -C docs html The result is published automatically at http://pod-pandoc.rtfd.io/en/latest/Pod-Pandoc.html. SEE ALSO This module is based on the wrapper module Pandoc to execute pandoc from Perl and on the module Pandoc::Elements for pandoc document processing. This module makes obsolete several specialized Pod::Simple::... modules such as Pod::Simple::HTML, Pod::Simple::XHTML, Pod::Simple::LaTeX, Pod::Simple::RTF Pod::Simple::Text, Pod::Simple::Wiki, Pod::WordML, Pod::Perldoc::ToToc etc. It also covers batch conversion such as Pod::Simple::HTMLBatch, Pod::ProjectDocs, Pod::POM::Web, and Pod::HtmlTree. AUTHOR Jakob Voß CONTRIBUTORS Benct Philip Jonsson COPYRIGHT AND LICENSE Copyright 2017- Jakob Voß GNU General Public License, Version 2 Changes100644001750001750 206513275405016 13601 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0Revision history for Pod-Pandoc 0.5.0 2018-05-11 23:24:05 CEST - Remove NAME section by default, include with option --name - Allow to disable module linking with --podurl 0 0.4.1 2018-05-10 22:01:34 CEST - Fix running on Windows - Fix running with Pandoc >= 2.0 - Add option --version 0.4.0 2017-02-06 11:31:17 CET - Guess NAME in parse_modules if missing - Let .pod override .pm in module sets (#4) - Rename option data-sections to parse - Add option (default-)meta (#6) - Make flat output directory the default (#8) 0.3.2 2017-02-03 13:44:42 CET - Fix converting with pod2pandoc to STDOUT - Extend module index with module descriptions - Include all data sections as RawBlock - Automatically publish documentation via travis-ci 0.3.1 2017-02-01 15:45:45 CET - Add method parse_module - Implement option update - Include Perl scripts in parse_dir - Add GitHub wiki and Read the Docs as examples 0.3.0 2017-02-01 07:44:58 CET - Split from Pandoc-Elements. See there for previous changes. LICENSE100644001750001750 4352513275405016 13341 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0This 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 54413275405016 13772 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0requires 'perl', '5.014'; # core modules requires 'Pod::Simple', '3.08'; requires 'Pod::Usage'; requires 'Getopt::Long'; # additional modules requires 'Pandoc', '0.6.0'; requires 'Pandoc::Elements', '0.33'; on test => sub { requires 'Test::More', '0.96'; requires 'Test::Output'; requires 'Capture::Tiny'; requires 'Test::Exception'; }; dist.ini100644001750001750 13713275405016 13730 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0author=Jakob Voß [@Milla] [PruneFiles] match=^wiki match=^docs match=^.+\.sh$ match=^.+\.enc$ Build.PL100644001750001750 25513275405016 13561 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0# This Build.PL for Pod-Pandoc was generated by Dist::Zilla::Plugin::ModuleBuildTiny 0.010. use strict; use warnings; use 5.014; use Module::Build::Tiny 0.039; Build_PL(); META.yml100644001750001750 175613275405016 13565 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0--- abstract: 'process Plain Old Documentation format with Pandoc' author: - 'Jakob Voß' build_requires: Capture::Tiny: '0' Test::Exception: '0' Test::More: '0.96' Test::Output: '0' 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: Pod-Pandoc no_index: directory: - t - xt - inc - share - eg - examples requires: Getopt::Long: '0' Pandoc: v0.6.0 Pandoc::Elements: '0.33' Pod::Simple: '3.08' Pod::Usage: '0' perl: '5.014' resources: bugtracker: https://github.com/nichtich/Pod-Pandoc/issues homepage: https://github.com/nichtich/Pod-Pandoc repository: https://github.com/nichtich/Pod-Pandoc.git version: 0.5.0 x_contributors: - 'Benct Philip Jonsson ' - 'Jakob Voß ' MANIFEST100644001750001750 114313275405016 13433 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0# 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/App/pod2pandoc.pm lib/Pod/Pandoc.pm lib/Pod/Pandoc/Modules.pm lib/Pod/Simple/Pandoc.pm script/pod2pandoc t/app-pod2pandoc-arguments.t t/app-pod2pandoc-meta.t t/app-pod2pandoc.t t/examples/Foo.pm t/examples/Pandoc t/examples/Pandoc.pod t/examples/metadata.json t/examples/metadata.yaml t/perltidy.t t/pod-pandoc-modules.t t/pod-pandoc.t t/pod-simple-pandoc-parse-modules.t t/pod-simple-pandoc.t t/pod2pandoc.t t/release-pod-syntax.t t/template.html META.json100644001750001750 350213275405016 13724 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0{ "abstract" : "process Plain Old Documentation format with Pandoc", "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" : "Pod-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" : { "Getopt::Long" : "0", "Pandoc" : "v0.6.0", "Pandoc::Elements" : "0.33", "Pod::Simple" : "3.08", "Pod::Usage" : "0", "perl" : "5.014" } }, "test" : { "requires" : { "Capture::Tiny" : "0", "Test::Exception" : "0", "Test::More" : "0.96", "Test::Output" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/nichtich/Pod-Pandoc/issues" }, "homepage" : "https://github.com/nichtich/Pod-Pandoc", "repository" : { "type" : "git", "url" : "https://github.com/nichtich/Pod-Pandoc.git", "web" : "https://github.com/nichtich/Pod-Pandoc" } }, "version" : "0.5.0", "x_contributors" : [ "Benct Philip Jonsson ", "Jakob Voß " ] } t000755001750001750 013275405016 12406 5ustar00vojvoj000000000000Pod-Pandoc-0.5.0perltidy.t100644001750001750 44013275405016 14545 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/tuse strict; use Test::More; use File::Find; plan skip_all => 'these tests are for author testing' unless $ENV{AUTHOR_TESTING}; use_ok 'Test::PerlTidy'; foreach ( Test::PerlTidy::list_files('lib'), 'script/pod2pandoc' ) { ok Test::PerlTidy::is_file_tidy($_), $_; } done_testing; pod-pandoc.t100644001750001750 14413275405016 14736 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/tuse strict; use Test::More; # just loads all included modules use_ok 'Pod::Pandoc'; done_testing; pod2pandoc.t100644001750001750 32513275405016 14744 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/tuse strict; use Test::More; use Capture::Tiny qw(capture); my ( $out, $err ) = capture { system( $^X, '-Ilib', 'script/pod2pandoc', '--version' ); }; like $out, qr{\d+\.\d+\.\d+}, '--version'; done_testing; template.html100644001750001750 7513275405016 15211 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/t$title$: $subtitle$ $base$: $for(file)$$file$$sep$, $endfor$ Pod000755001750001750 013275405016 13433 5ustar00vojvoj000000000000Pod-Pandoc-0.5.0/libPandoc.pm100644001750001750 1066413275405016 15364 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/lib/Podpackage Pod::Pandoc; use strict; use warnings; require 5.010; our $VERSION = '0.5.0'; use Pod::Simple::Pandoc; use Pod::Pandoc::Modules; use App::pod2pandoc; 1; __END__ =head1 NAME Pod::Pandoc - process Plain Old Documentation format with Pandoc =begin markdown # STATUS [![Unix Build Status](https://travis-ci.org/nichtich/Pod-Pandoc.svg)](https://travis-ci.org/nichtich/Pod-Pandoc) [![Windows Build status](https://ci.appveyor.com/api/projects/status/lfskwt20v0ofj5ix?svg=true)](https://ci.appveyor.com/project/nichtich/pod-pandoc) [![Coverage Status](https://coveralls.io/repos/nichtich/Pod-Pandoc/badge.svg)](https://coveralls.io/r/nichtich/Pod-Pandoc) [![Kwalitee Score](http://cpants.cpanauthors.org/dist/Pod-Pandoc.png)](http://cpants.cpanauthors.org/dist/Pod-Pandoc) [![Code Climate Issue Count](https://codeclimate.com/github/nichtich/Pod-Pandoc/badges/issue_count.svg)](https://codeclimate.com/github/nichtich/Pod-Pandoc) [![Documentation Status](https://readthedocs.org/projects/pod-pandoc/badge/?version=latest)](http://pod-pandoc.readthedocs.io/?badge=latest) =end markdown =head1 DESCRIPTION The Plain Old Documentation format (Pod) is a markup language used to document Perl code (see L for reference). Several Perl modules exist to process and convert Pod into other formats. Pod::Pandoc is an attempt to unify and extend Pod converting based on the L document converter. Pandoc supports more document formats in a more detailled and uniform way than any set of Perl modules will ever do. For this reason Pod::Pandoc provides methods to convert Pod to the Pandoc document model for further processing with Pandoc. =head1 OUTLINE =over =item L is a command line script to convert Pod to any format supported by Pandoc. =item L provides functionality of L to be used in Perl code. =item L converts Pod to the abstract document model of Pandoc. =item L manages a set of Pod documents of Perl modules. =back =head1 REQUIREMENTS Installation of this module does not require Pandoc but it is needed to make actual use of it. See L for installation. =head1 USAGE EXAMPLES =head2 Replace L # pod2html --infile=input.pm --css=style.css --title=TITLE > 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. =head2 Replace L # pod2markdown input.pod pod2pandoc input.pod -t markdown # pod2markdown input.pod output.md pod2pandoc input.pod -o output.md =head2 GitHub wiki The L is automatically populated with its module documentation. Wiki pages are created with L as following (see script C): pod2pandoc lib/ script/ wiki/ --ext md --index Home --wiki -t markdown_github =head2 Sphinx and Read The Docs The L recommends documents in reStructureText format. It further requires a configuration file C and some links need to be adjusted because Pandoc does not support wikilinks in rst output format (see script C: pod2pandoc lib/ script/ docs/ --ext rst --wiki -t rst --standalone perl -pi -e 's!`([^`]+) <([^>]+)>`__!-e "docs/$2.rst" ? ":doc:`$1 <$2>`" : "`$1 <$2>`__"!e' docs/*.rst make -C docs html The result is published automatically at L. =head1 SEE ALSO This module is based on the wrapper module L to execute pandoc from Perl and on the module L for pandoc document processing. This module makes obsolete several specialized C modules such as L, L, L, L L, L, L, L etc. It also covers batch conversion such as L, L, L, and L. =encoding utf8 =head1 AUTHOR Jakob Voß Ejakob.voss@gbv.deE =head1 CONTRIBUTORS Benct Philip Jonsson =head1 COPYRIGHT AND LICENSE Copyright 2017- Jakob Voß GNU General Public License, Version 2 =cut =begin rst .. toctree:: :hidden: :glob: * =end rst script000755001750001750 013275405016 13447 5ustar00vojvoj000000000000Pod-Pandoc-0.5.0pod2pandoc100755001750001750 467613275405016 15603 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/script#!/usr/bin/env perl use strict; require 5.010; my $VERSION = '0.345.0'; use App::pod2pandoc; pod2pandoc( App::pod2pandoc::parse_arguments(@ARGV) ); =head1 NAME pod2pandoc - convert Pod to Pandoc document model =head1 SYNOPSIS pod2pandoc [OPTIONS] {INPUT} [ [ -- ] PANDOC_ARGUMENTS ] pod2pandoc Module.pm -o Module.pdf pod2pandoc script.pl -t markdown pod2pandoc Module::Name -o Module-Name.html pod2pandoc lib/ wiki/ --ext .md --wiki --index Home -t markdown_github pod2pandoc lib/ docs/ --standalone =head1 DESCRIPTION pod2pandoc converts "Plain Old Documentation" format (aka Pod, see L) to the L document model for further processing to other document formats (HTML, Markdown, LaTeX, PDF, EPUB, docx, ODT, man...). By default or with input C<-> a document is read from STDIN. Multiple input files are combined to one document and listed in document metadata field C. The result is printed in JSON format or passed to Pandoc if additional options such as C<-t> or C<-o> are given. To process a whole directory of C<.pm> and/or C<.pod> files, specify an input directory as first input and an optional output directory as second. =head1 OPTIONS =over =item --help|-h|-? Print out usage information and exit. =item --parse FORMATS Parse and include data sections. Use C<*> for all. =item --podurl URL Base URL to Perl modules. Default: C. A false value such as C<0> or C<""> will disable linking to external modules. =item --ext EXT Output file extension when processing a directory. Default: C. =item --index NAME Index file (e.g. C) name when processing a directory. Can be disabled with C<0>. =item --name Include C section which is removed by default. =item --wiki Create wikilinks when processing a directory. =item --update Only process when input file is newer then output file. =item --default-meta FILE Read default metadata from given file. =item --quiet Don't emit warnings and status information. =item ... Additional options are passed through to pandoc executable. =back =head1 SEE ALSO This script is part of L and implemented in L. Together with Pandoc document converter it can be used as customizable replacement for specialized Pod converter scripts such as L, L, L, L, L, L, L, L, and L. =cut examples000755001750001750 013275405016 14224 5ustar00vojvoj000000000000Pod-Pandoc-0.5.0/tFoo.pm100644001750001750 4113275405016 15400 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/t/examples=head1 NAME Bar - not Foo =cut Pandoc100755001750001750 4013275405016 15450 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/t/examples#!/usr/bin/env perl use strict; app-pod2pandoc.t100644001750001750 361613275405016 15550 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/tuse strict; use Test::More; use App::pod2pandoc; use File::Temp qw(tempdir); use File::Spec::Functions; use Test::Output qw(:functions); use JSON; plan skip_all => 'these tests are for release candidate testing' unless $ENV{RELEASE_TESTING}; my $dir = tempdir( CLEANUP => 1 ); sub slurp { local ( @ARGV, $/ ) = @_; <> } # convert a single file { my @source = 'lib/Pod/Pandoc.pm'; my $target = catfile( $dir, 'Pandoc-Elements.html' ); my @args = ('--template' => 't/template.html'); is stdout_from { pod2pandoc( \@source, -o => $target, @args ) }, ''; is slurp($target), "Pod::Pandoc: process Plain Old Documentation format with Pandoc\n" . ": lib/Pod/Pandoc.pm\n", "pod2pandoc single file"; # convert file to json my $stdout = stdout_from { pod2pandoc( \@source ) }; ok decode_json($stdout), 'JSON by default'; # convert and emit to STDOUT $stdout = stdout_from { pod2pandoc( \@source, '-t', 'rst' ) }; like $stdout, qr/^DESCRIPTION/m, 'convert to STDOUT'; } # convert multiple files { my @source = ( 'lib/App/pod2pandoc.pm', 'lib/Pod/Pandoc.pm' ); my $target = catfile( $dir, 'Pod-Pandoc.md' ); pod2pandoc( \@source, { ext => 'md' }, '-o', $target, '--template', 't/template.html' ); is slurp($target), "App::pod2pandoc: implements pod2pandoc command line script\n" . ": lib/App/pod2pandoc.pm, lib/Pod/Pandoc.pm\n", "pod2pandoc multiple files"; } # convert directory my ( $stdout, $stderr ) = output_from { pod2pandoc( [ 'lib/', 'script', 't/empty', $dir ], { 'ext' => 'md', wiki => 1, update => 1, index => 'Home' } ); }; is( ( scalar split "\n", $stdout ), 5, 'pod2pandoc directory, option update' ); is $stderr, "no .pm, .pod or Perl script found in t/empty\n", 'warning'; ok -e catfile( $dir, 'Pod-Simple-Pandoc.md' ), 'option wiki'; ok -e catfile( $dir, 'Home.md' ), 'option index'; done_testing; App000755001750001750 013275405016 13431 5ustar00vojvoj000000000000Pod-Pandoc-0.5.0/libpod2pandoc.pm100644001750001750 1116513275405016 16204 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/lib/Apppackage App::pod2pandoc; use strict; use warnings; use 5.010; our $VERSION = '0.3.2'; use Getopt::Long qw(:config pass_through); use Pod::Usage; use Pod::Simple::Pandoc; use Pandoc; use Pandoc::Elements; use Scalar::Util qw(reftype blessed); use JSON; use Carp; use parent 'Exporter'; our @EXPORT = qw(pod2pandoc); our @EXPORT_OK = qw(pod2pandoc parse_arguments); sub parse_arguments { my %opt; Getopt::Long::GetOptionsFromArray( \@_, \%opt, 'help|h|?', 'version', 'parse=s', 'podurl=s', 'ext=s', 'index=s', 'wiki', 'default-meta=s', 'update', 'quiet', 'name', ) or exit 1; pod2usage(1) if $opt{help}; if ( $opt{version} ) { say "$0 $VERSION"; exit 0; } my @input = @_ ? () : '-'; my ($index) = grep { $_[$_] eq '--' } ( 0 .. @_ - 1 ); if ( defined $index ) { push @input, shift @_ for 0 .. $index - 1; shift @_; # -- } else { push( @input, shift @_ ) while @_ and $_[0] !~ /^-./; } if ( $opt{parse} and $opt{parse} ne '*' ) { $opt{parse} = [ split /[, ]+/, $opt{parse} ]; } return ( \@input, \%opt, @_ ); } # TODO: move to Pandoc::Elements sub _add_default_meta { my ( $doc, $meta ) = @_; return unless $meta; $doc->meta->{$_} //= $meta->{$_} for keys %$meta; } sub _default_meta { my $meta = shift || {}; return $meta if ref $meta; # read default metadata from file if ( $meta =~ /\.json$/ ) { open( my $fh, "<:encoding(UTF-8)", $meta ) or croak "failed to open $meta"; local $/; $meta = decode_json(<$fh>); for ( keys %$meta ) { $meta->{$_} = metadata( $meta->{$_} ); } return $meta; } else { pandoc->require('1.12.1'); return pandoc->file($meta)->meta; } } sub pod2pandoc { my $input = shift; my $opt = ref $_[0] ? shift : {}; my @args = @_; $opt->{meta} = _default_meta( $opt->{meta} // delete $opt->{'default-meta'} ); # directories if ( @$input > 0 and -d $input->[0] ) { my $target = @$input > 1 ? pop @$input : $input->[0]; my $modules = Pod::Pandoc::Modules->new; foreach my $dir (@$input) { my $found = Pod::Simple::Pandoc->new->parse_modules($dir); warn "no .pm, .pod or Perl script found in $dir\n" unless %$found or $opt->{quiet}; $modules->add( $_ => $found->{$_} ) for keys %$found; } _add_default_meta( $modules->{$_}, $opt->{meta} ) for %$modules; $modules->serialize( $target, $opt, @args ); } # files and/or module names else { my $parser = Pod::Simple::Pandoc->new(%$opt); my $doc = $parser->parse_and_merge( @$input ? @$input : '-' ); _add_default_meta( $doc, $opt->{meta} ); if (@args) { pandoc->require('1.12.1'); $doc->pandoc_version( pandoc->version ); print $doc->to_pandoc(@args); } else { print $doc->to_json, "\n"; } } } 1; __END__ =head1 NAME App::pod2pandoc - implements pod2pandoc command line script =head1 SYNOPSIS use App::pod2pandoc; # pod2pandoc command line script my ($input, $opt, @args) = parse_arguments(@ARGV); pod2pandoc($input, $opt, @args); # parse a Perl/Pod file and print its JSON serialization pod2pandoc( ['example.pl'], {} ); # parse a Perl/Pod file and convert to HTML with a template pod2pandoc( ['example.pl'], {}, '--template', 'template.html' ); # process directory of Perl modules pod2pandoc( [ lib => 'doc'], { ext => 'html' }, '--standalone' ); =head1 DESCRIPTION This module implements the command line script L. =head1 FUNCTIONS =head2 pod2pandoc( \@input, [ \%options, ] \@arguments ) Processed input files with given L options (C, C, C, C, C, C, and C) . Additional arguments are passed to C executable via module L. Input can be either files and/or module names or directories to recursively search for C<.pm> and C<.pod> files. If no input is specified, Pod is read from STDIN. When processing directories, the last input directory is used as output directory. This function is exported by default. =head2 parse_arguments( @argv ) Parses options and input arguments from given command line arguments. May terminate the program with message, for instance with argument C<--help>. =head1 SEE ALSO This module is part of L and based on the modules L, L, L and L. =cut Pandoc.pod100644001750001750 013275405016 16202 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/t/examplespod-simple-pandoc.t100644001750001750 516713275405016 16257 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/tuse strict; use Test::More; use Pandoc::Elements; use Pandoc; use Pod::Simple::Pandoc; use Test::Exception; plan skip_all => 'pandoc not available' unless pandoc; my $parser = Pod::Simple::Pandoc->new(); my $file = 'lib/Pod/Simple/Pandoc.pm'; # parse_file { my $doc = $parser->parse_file($file); is_deeply $doc->query( Header => sub { $_->level == 1 ? $_->string : () } ), [ qw(SYNOPSIS DESCRIPTION OPTIONS METHODS MAPPING), 'SEE ALSO' ], 'headers'; is_deeply $doc->metavalue, { title => 'Pod::Simple::Pandoc', subtitle => 'convert Pod to Pandoc document model', file => $file, }, 'metadata'; is_deeply $doc->query( RawBlock => sub { $_->format } ), [qw(markdown html html tex tex)], 'data sections as RawBlock'; foreach ( '', 'Pandoc::Elements' ) { dies_ok { $parser->parse_file($_) } 'parse_file not found'; } } # 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'; if ( $ENV{RELEASE_TESTING} ) { my $files = $parser->parse_dir('lib'); is scalar( keys %$files ), 4, 'parse_dir'; my $doc = $files->{'lib/Pod/Pandoc.pm'}; isa_ok $doc, 'Pandoc::Document'; is_deeply $doc->metavalue, { file => 'lib/Pod/Pandoc.pm', title => 'Pod::Pandoc', subtitle => 'process Plain Old Documentation format with Pandoc', base => '../', }, 'parse_dir document metadata'; $files = $parser->parse_dir('script'); my @keys = keys %$files; like $keys[0], qr{^(script/)?pod2pandoc}, 'parse_dir with script'; } # parse_string { my $doc = $parser->parse_string(< =back POD is_deeply $doc, Document( {}, [ BlockQuote [ Para [ Emph [ Str 'hello' ] ] ] ] ), 'parse_string'; is $doc->metavalue('title'), undef, 'no title'; } # podurl { my %opt = ( podurl => 'http://example.org/' ); my $doc = Pod::Simple::Pandoc->new(%opt)->parse_file($file); my $urls = $doc->query( Link => sub { $_->url } ); is $urls->[0], 'http://example.org/perlpod', 'podurl'; } # parse data sections if ( pandoc and pandoc->version >= '1.12' ) { my %opt = ( 'parse' => '*' ); my $doc = Pod::Simple::Pandoc->new(%opt)->parse_file($file); is_deeply $doc->query( Header => sub { $_->level == 3 ? $_->string : () } ), ['Examples'], 'data-sections'; is_deeply [], $doc->query( RawBlock => sub { $_->format } ), 'no RawBlock'; } done_testing; pod-pandoc-modules.t100644001750001750 331113275405016 16423 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/tuse strict; use Test::More; use Pandoc::Elements; use Pandoc; use Pod::Simple::Pandoc; use Pod::Pandoc::Modules; use Test::Exception; plan skip_all => 'pandoc not available' unless pandoc; my $parser = Pod::Simple::Pandoc->new; # add { my $modules = Pod::Pandoc::Modules->new; my $name = 'Pod::Simple::Pandoc'; my $file = 'lib/Pod/Simple/Pandoc.pm'; my $doc = $parser->parse_file($file); ok $modules->add( $name => $doc ), 'add'; is $modules->{$name}, $doc, 'added'; ok !$modules->add( $name => $parser->parse_file('script/pod2pandoc') ); is $modules->{$name}, $doc, 'add doesn\'t override'; $file = 't/examples/Pandoc.pod'; ok $modules->add( $name => $parser->parse_file($file) ), 'add'; is $modules->{$name}->metavalue('file'), $file, '.pod overrides .pm'; is $modules->{$name}->metavalue('title'), $name, 'title without NAME'; } # constructor my $modules = Pod::Pandoc::Modules->new({ 'Pod::Simple::Pandoc' => $parser->parse_file('lib/Pod/Simple/Pandoc.pm') }); # index sub is_index { my ( $name, $opt, $meta, $url, $title ) = @_; is_deeply $modules->index(%$opt), Document( $meta, [ DefinitionList [ [ [ Link attributes {}, [ Str 'Pod::Simple::Pandoc' ], [ $url, $title ] ], [ [ Plain [ Str 'convert Pod to Pandoc document model' ] ] ] ] ] ]), $name; } is_index( 'index (default)', {}, {}, 'Pod-Simple-Pandoc.html', 'Pod::Simple::Pandoc' ); is_index( 'index (wiki & title)', { wiki => 1, title => 'test' }, { title => MetaString 'test' }, 'Pod-Simple-Pandoc', 'wikilink' ); done_testing; release-pod-syntax.t100644001750001750 45613275405016 16444 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/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(); app-pod2pandoc-meta.t100644001750001750 203213275405016 16463 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/tuse strict; use Test::More; use Test::Exception; use File::Temp qw(tempfile); use App::pod2pandoc; use Pandoc::Elements; plan skip_all => 'these tests are for release candidate testing' unless $ENV{RELEASE_TESTING}; sub pod2meta { my ( $fh, $file ) = tempfile; pod2pandoc ['script/pod2pandoc'], {@_}, '-t' => 'json', '-o', $file; my $json = do { local ( @ARGV, $/ ) = $file; <> }; pandoc_json($json)->metavalue; } my $expect = { file => 'script/pod2pandoc', subtitle => 'convert Pod to Pandoc document model', title => 'pod2pandoc' }; is_deeply pod2meta(), $expect, 'no meta'; throws_ok { pod2meta( meta => 't/examples/missing.json' ) } qr{^failed to open t/examples/missing\.json}, 'invalid meta'; $expect->{bool} = 0; $expect->{map} = { list => [ 1, 2 ] }; is_deeply pod2meta( meta => 't/examples/metadata.json' ), $expect, 'meta from json'; $expect->{bool} = 1; $expect->{map}{list} = ['a string']; is_deeply pod2meta( meta => 't/examples/metadata.yaml' ), $expect, 'meta from YAML'; done_testing; Simple000755001750001750 013275405016 14664 5ustar00vojvoj000000000000Pod-Pandoc-0.5.0/lib/PodPandoc.pm100644001750001750 4063113275405016 16612 0ustar00vojvoj000000000000Pod-Pandoc-0.5.0/lib/Pod/Simplepackage Pod::Simple::Pandoc; use strict; use warnings; use 5.010; our $VERSION = '0.346.0'; use Pod::Simple::SimpleTree; use Pod::Perldoc; use Pandoc::Elements; use Pandoc::Filter::HeaderIdentifiers; use Pod::Pandoc::Modules; use Pandoc; use File::Find (); use File::Spec; use Carp; use utf8; sub new { my ( $class, %opt ) = @_; $opt{parse} ||= []; if ( $opt{parse} eq '*' ) { $opt{parse} = [ pandoc->require('1.12')->input_formats ]; } $opt{podurl} //= 'https://metacpan.org/pod/'; bless \%opt, $class; } sub _parser { my $self = shift; my $parser = Pod::Simple::SimpleTree->new; $parser->nix_X_codes(1); # ignore X<...> codes $parser->nbsp_for_S(1); # map S<...> to U+00A0 (non-breaking space) $parser->merge_text(1); # emit text nodes combined $parser->no_errata_section(1); # omit errata section $parser->complain_stderr(1); # TODO: configure $parser->accept_target('*'); # include all data sections # remove shortest leading whitespace string from verbatim sections $parser->strip_verbatim_indent( sub { my $indent = length $_[0][1]; for ( @{ $_[0] } ) { $_ =~ /^(\s*)/; $indent = length($1) if length($1) < $indent; } ' ' x $indent; } ); return $parser; } sub parse_file { my ( $self, $file ) = @_; # Pod::Simple::parse_file does not detect this croak "Can't use directory as a source for parse_file" if -d $file; my $doc = $self->parse_tree( $self->_parser->parse_file($file)->root ); if ( !ref $file and $file ne '-' ) { $doc->meta->{file} = MetaString($file); } $doc; } sub parse_module { my ( $self, $name ) = @_; my ($file) = Pod::Perldoc->new->grand_search_init( [$name] ); $self->parse_file($file); } sub parse_string { my ( $self, $string ) = @_; $self->parse_tree( $self->_parser->parse_string_document($string)->root ); } sub parse_tree { my $doc = Pandoc::Filter::HeaderIdentifiers->new->apply( _pod_element(@_) ); my $sections = $doc->outline(1)->{sections}; if ( my ($name) = grep { $_->{header}->string eq 'NAME' } @$sections ) { # TODO: support formatting my $text = $name->{blocks}->[0]->string; my ( $title, $subtitle ) = $text =~ m{^\s*([^ ]+)\s*[:-]*\s*(.+)}; $doc->meta->{title} = MetaString($title) if $title; $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; } sub parse_and_merge { my ( $self, @input ) = @_; my $doc; foreach my $file (@input) { my $cur = ( $file ne '-' and not -e $file ) ? $self->parse_module($file) : $self->parse_file($file); if ($doc) { push @{ $doc->content }, @{ $cur->content }; } else { $doc = $cur; } } return unless $doc; if ( @input > 1 ) { $doc->meta->{file} = MetaList [ map { MetaString $_ } @input ]; } return $doc; } sub is_perl_file { my $file = shift; return 1 if $file =~ /\.(pm|pod)$/; if ( -f $file ) { open( my $fh, '<', $file ) or return; return 1 if $fh and ( <$fh> // '' ) =~ /^#!.*perl/; } 0; } sub parse_dir { my ( $parser, $directory ) = @_; my $files = {}; File::Find::find( { no_chdir => 1, wanted => sub { my $file = $_; return unless is_perl_file($file); my $doc = $parser->parse_file($file); my $base = File::Spec->abs2rel( $directory, $file ); $base =~ s/\.\.$//; $doc->meta->{base} = MetaString $base; $files->{$file} = $doc; } }, $directory ); $files; } sub parse_modules { my ( $parser, $dir, %opt ) = @_; my $modules = Pod::Pandoc::Modules->new; return $modules unless -d $dir; my $files = $parser->parse_dir($dir); foreach my $file ( sort keys %$files ) { my $doc = $files->{$file}; my $module = File::Spec->abs2rel( $file, $dir ); $module =~ s{\.(pm|pod)$}{}g; $module =~ s{/}{::}g; if ( ( $doc->metavalue('title') // $module ) eq $module ) { my $old = $modules->{$module}; my $skipped = $modules->add( $module => $doc ) ? $old : $doc; if ( $skipped and not $opt{quiet} ) { warn $skipped->metavalue('file') . " skipped for " . $modules->{$module}->metavalue('file') . "\n"; } } else { warn "$file NAME does not match module\n" unless $opt{quiet}; } } $modules; } my %POD_ELEMENT_TYPES = ( Document => sub { Document {}, [ _pod_content(@_) ]; }, Para => sub { Para [ _pod_content(@_) ]; }, I => sub { Emph [ _pod_content(@_) ]; }, B => sub { Strong [ _pod_content(@_) ]; }, L => \&_pod_link, C => sub { Code attributes {}, _pod_flatten(@_); }, F => sub { Code attributes { classes => ['filename'] }, _pod_flatten(@_); }, head1 => sub { Header 1, attributes {}, [ _pod_content(@_) ]; }, head2 => sub { Header 2, attributes {}, [ _pod_content(@_) ]; }, head3 => sub { Header 3, attributes {}, [ _pod_content(@_) ]; }, head4 => sub { Header 4, attributes {}, [ _pod_content(@_) ]; }, Verbatim => sub { CodeBlock attributes {}, _pod_flatten(@_); }, 'over-bullet' => sub { BulletList [ _pod_list(@_) ]; }, 'over-number' => sub { OrderedList [ 1, DefaultStyle, DefaultDelim ], [ _pod_list(@_) ]; }, 'over-text' => sub { DefinitionList [ _pod_list(@_) ]; }, 'over-block' => sub { BlockQuote [ _pod_content(@_) ]; }, 'for' => \&_pod_data, ); # option --smart sub _str { my $s = shift; $s =~ s/\.\.\./…/g; Str $s; } # map a single element or text to a list of Pandoc elements sub _pod_element { my ( $self, $element ) = @_; if ( ref $element ) { my $type = $POD_ELEMENT_TYPES{ $element->[0] } or return; $type->( $self, $element ); } else { my $n = 0; map { $n++ ? ( Space, _str($_) ) : _str($_) } split( /\s+/, $element, -1 ); } } # map the content of a Pod element to a list of Pandoc elements sub _pod_content { my ( $self, $element ) = @_; my $length = scalar @$element; map { _pod_element( $self, $_ ) } @$element[ 2 .. ( $length - 1 ) ]; } # stringify the content of an element sub _pod_flatten { my $string = ''; my $walk; $walk = sub { my ($element) = @_; my $n = scalar @$element; for ( @$element[ 2 .. $n - 1 ] ) { if ( ref $_ ) { $walk->($_); } else { $string .= $_; } } }; $walk->( $_[1] ); return $string; } # map link sub _pod_link { my ( $self, $link ) = @_; my $type = $link->[1]{type}; my $to = $link->[1]{to}; my $section = $link->[1]{section}; my $url = ''; if ( $type eq 'url' ) { $url = "$to"; } elsif ( $type eq 'man' ) { if ( $to =~ /^([^(]+)(?:[(](\d+)[)])?$/ ) { # TODO: configure MAN_URL, e.g. # http://man7.org/linux/man-pages/man{section}/{name}.{section}.html $url = "http://linux.die.net/man/$2/$1"; # TODO: add section to URL if given } } elsif ( $type eq 'pod' ) { if ( $to && $self->{podurl} ) { $url = $self->{podurl} . $to; } if ($section) { $section = header_identifier("$section") unless $to; # internal link $url .= "#" . $section; } } my $content = [ _pod_content( $self, $link ) ]; if ($url) { Link attributes { class => 'perl-module' }, $content, [ $url, '' ]; } else { Span attributes { class => 'perl-module' }, $content; } } # map data section sub _pod_data { my ( $self, $element ) = @_; my $target = lc( $element->[1]{target} ); my $length = scalar @$element; my $content = join "\n\n", map { $_->[2] } grep { $_->[0] eq 'Data' } @$element[ 2 .. $length - 1 ]; # cleanup HTML and Tex blocks if ( $target eq 'html' ) { $content = "
$content
" if $content !~ /^<.+>$/s; } elsif ( $target =~ /^(la)?tex$/ ) { # TODO: more intelligent check & grouping, especiall at the end $content = "\\begingroup $content \\endgroup" if $content !~ /^[\\{]/; $target = 'tex'; } # parse and insert known formats if requested my $format_arg = my $format = $target eq 'tex' ? 'latex' : $target; if ( pandoc->version ge 2 ) { $format_arg .= '+smart'; } if ( grep { $format eq $_ } @{ $self->{parse} } ) { utf8::decode($content); my $doc = ( pandoc->version ge 2 ) ? pandoc->parse( $format_arg => $content ) : pandoc->parse( $format => $content, '--smart' ); return @{ $doc->content }; } RawBlock( $target, "$content\n" ); # TODO: add Null element to not merge with following content } # map a list (any kind) sub _pod_list { my ( $self, $element ) = @_; my $length = scalar @$element; my $deflist = $element->[2][0] eq 'item-text'; my @list; my $item = []; my $push_item = sub { return unless @$item; if ($deflist) { my $term = shift @$item; push @list, [ $term->content, [$item] ]; } else { push @list, $item; } }; foreach my $e ( @$element[ 2 .. $length - 1 ] ) { my $type = $e->[0]; if ( $type =~ /^item-(number|bullet|text)$/ ) { $push_item->(); $item = [ Plain [ _pod_content( $self, $e ) ] ]; } else { if ( @$item == 1 and $item->[0]->name eq 'Plain' ) { # first block element in item should better be Paragraph $item->[0] = Para $item->[0]->content; } push @$item, _pod_element( $self, $e ); } } $push_item->(); # BulletList/OrderedList: [ @blocks ], ... # DefinitionList: [ [ @inlines ], [ @blocks ] ], ... return @list; } 1; __END__ =encoding utf-8 =head1 NAME Pod::Simple::Pandoc - convert Pod to Pandoc document model =head1 SYNOPSIS use Pod::Simple::Pandoc; my $parser = Pod::Simple::Pandoc->new( %options ); my $doc = $parser->parse_file( $filename ); # result is a Pandoc::Document object my $json = $doc->to_json; my $markdown = $doc->to_pandoc( -t => 'markdown' ); $doc->to_pandoc(qw( -o doc.html --standalone )); =head1 DESCRIPTION This module converts Pod format (L) to the document model used by L. The result can be accessed with methods of L and further processed with Pandoc to convert it to other document formats (HTML, Markdown, LaTeX, PDF, EPUB, docx, ODT, man...). See L and L for a command line script and a simplified API to this module. =head1 OPTIONS =over =item parse Parse Pod L with L and merge them into the document instead of passing them as C. Use C<*> to parse all formats supported by pandoc as input format. Expects an array reference otherwise. =item podurl Base URL to link Perl module names to. Set to L by default. A false value disables linking external modules and wraps module names in C elements instead. All module names are marked up with class C. =back =head1 METHODS =head2 parse_file( $filename | *INPUT ) Reads Pod from file or filehandle and convert it to a L. The filename is put into document metadata field C and the module name. The NAME section, if given, is additionally split into metadata fields C and C<subtitle>. =head2 parse_module( $module ) Reads Pod from a module given by name such as C<"Pod::Pandoc"> or by URL. =head2 parse_string( $string ) Reads Pod from string and convert it to a L<Pandoc::Document>. Also sets metadata fields C<title> and C<subtitle>. =head2 parse_dir( $directory ) Recursively looks for C<.pm> and C<.pod> files in a given directory and parses them. Returns a hash reference with filenames mapped to L<Pandoc::Document> objects. Each document is enriched with metadata fields C<base> (relative path from each file to the base directory) in addition to C<file>, C<title>, and C<subtitle>. =head2 parse_modules( $directory, [ quiet => 0|1 ] ) Same as method C<parse_dir> but returns a L<Pod::Simple::Pandoc::Modules> instance that maps module names to L<Pandoc::Document> instances. The source directory can also be specified with option C<source>. Option C<quiet> disables warnings for skipped files. =head2 parse_and_merge( @files_or_modules ) Reads Pod from files or modules given by name and merges them into one L<Pandoc::Document> by concatenation. =head1 MAPPING Pod elements are mapped to Pandoc elements as following: =head2 Formatting codes L<Formatting codes|perlpod/Formatting Codes> for I<italic text> (C<IE<lt>...E<gt>>), B<bold text> (C<BE<lt>...E<gt>>), and C<code> (C<CE<lt>...E<gt>>) are mapped to Emphasized text (C<Emph>), strongly emphasized text (C<Strong>), and inline code (C<Code>). Formatting code for F<filenames> (C<FE<lt>...E<gt>>) are mapped to inline code with class C<filename> (C<`...`{.filename}> in Pandoc Markdown). Formatting codes inside code and filenames (e.g. C<code with B<bold>> or F<L<http://example.org/>> as filename) are stripped to unformatted code. Character escapes (C<EE<lt>...E<gt>>) and C<SE<lt>...E<gt>> are directly mapped to Unicode characters. The special formatting code C<XE<lt>...E<gt>> is ignored. =head2 Links Some examples of links of different kinds: L<http://example.org/> L<pod2pandoc> L<pod2pandoc/"OPTIONS"> L<perl(1)> L<crontab(5)/"ENVIRONMENT"> L<hell itself!|crontab(5)> Link text can contain formatting codes: L<the C<pod2pandoc> script|pod2pandoc> L</"MAPPING"> L<mapping from PoD to Pandoc|/"MAPPING"> =head2 Titles I<may contain formatting C<codes>>! =head2 Lists =over =item 1 Numbered lists are =item 2 converted to C<NumberedList> and =over =item * Bulleted lists are =item * converted to C<BulletList> =back =back =over =item Definition =item Lists =item are I<also> supported. =back =head2 =over/=back =over An C<=over>...C<=back> region containing no C<=item> is mapped to C<BlockQuote>. =back =head2 Verbatim sections verbatim sections are mapped to code blocks =head2 Data sections Data sections are passed as C<RawBlock>. C<HTML>, C<LaTeX>, C<TeX>, and C<tex> are recognized as alias for C<html> and C<tex>. Option C<parse> can be used to parse data sections with pandoc executable and merge them into the result document. =begin markdown ### Examples =end markdown =begin html <p> HTML is passed through as <i>you can see here</i>. </p> =end html =for html HTML is automatically enclosed in <code><div>...</div></code> 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<Pod::Simple> (L<Pod::Simple::SimpleTree>). It makes obsolete several specialized C<Pod::Simple::...> modules such as L<Pod::Simple::HTML>, L<Pod::Simple::XHTML>, L<Pod::Simple::LaTeX>, L<Pod::Simple::RTF> L<Pod::Simple::Text>, L<Pod::Simple::Wiki>, L<Pod::WordML>, L<Pod::Perldoc::ToToc> 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<Pod::Simple::Pandoc> for how to create instances of this module. =head1 METHODS =head2 add( $name => $doc ) Add a module given as L<Pandoc::Document> 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<format> by default. =item index Index filename (with or without extension). Set to C<index> 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<Pandoc::Document>. =head1 SEE ALSO This module is part of L<Pod::Pandoc>. =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; ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������