| 1 | package App::PDoc; | ||
| 2 | |||
| 3 | # PODNAME: pdoc | ||
| 4 | # ABSTRACT: typeset pandoc documents with document-specific, default options | ||
| 5 | |||
| 6 | # pdoc | ||
| 7 | # | ||
| 8 | # What this script does: | ||
| 9 | # 1. Get the first argument passed to it | ||
| 10 | # 2. Slurp that file and leave @ARGV intact | ||
| 11 | # 3. Grep all lines "<!--+ (--some-pandoc-option) +-->" from that file | ||
| 12 | # 4. Grep all lines "<!--& (some post processing action) &-->" from that file | ||
| 13 | # 5. join them into a command to be executed: | ||
| 14 | # a) if there are commands to be executed, attach them with &&'s | ||
| 15 | # b) else, don't. | ||
| 16 | # 6. Send that command off to the shell | ||
| 17 | |||
| 18 | |||
| 19 | # What to do with your pandoc files | ||
| 20 | # --------------------------------- | ||
| 21 | # Sprinkle <!--+ --pandoc-option1 --pandoc--option2 +--> all over your file | ||
| 22 | # as your would use them on the shell | ||
| 23 | # | ||
| 24 | # If you want your file to be typeset using those options, run | ||
| 25 | # pdoc file.pandoc | ||
| 26 | # | ||
| 27 | # If you want standard processing of that file, run pandoc as usual: | ||
| 28 | # pandoc file.pandoc | ||
| 29 | |||
| 30 | # Daniel Bruder <daniel.bruder[@]gmail.com> | ||
| 31 | # WTFPL License <http://sam.zoy.org/wtfpl/> | ||
| 32 | |||
| 33 | sub main { | ||
| 34 | $_ = do{ local(@ARGV => $/) = $ARGV[0]; <> }; # Slurp the file | ||
| 35 | @opts = join " " => m/<!--\+\s*(.*?)\s*\+-->/g; # Get <!--+X+--> | ||
| 36 | @exec = join " && \\\n" => m/<!--&\s*(.*?)\s*&-->/g; # Get <!--&X&--> | ||
| 37 | @cmd = join " && \\\n" => "pandoc @opts @ARGV", @exec; # Construct cmd | ||
| 38 | exec @cmd # exec cmd | ||
| 39 | } | ||
| 40 | |||
| 41 | |||
| 42 | 1; | ||
| 43 | __END__ |