| 1 | #!/usr/bin/env perl |
|---|
| 2 | # Copyright (c) 2009, Sébastien Bocahu <zecrazytux@zecrazytux.net> |
|---|
| 3 | # All rights reserved. |
|---|
| 4 | # |
|---|
| 5 | # Redistribution and use in source and binary forms, with or without |
|---|
| 6 | # modification, are permitted provided that the following conditions are met: |
|---|
| 7 | # |
|---|
| 8 | # * Redistributions of source code must retain the above copyright notice, |
|---|
| 9 | # this list of conditions and the following disclaimer. |
|---|
| 10 | # * Redistributions in binary form must reproduce the above copyright |
|---|
| 11 | # notice, this list of conditions and the following disclaimer in the |
|---|
| 12 | # documentation and/or other materials provided with the distribution. |
|---|
| 13 | # * Neither the name of Bearstech nor the names of its contributors |
|---|
| 14 | # may be used to endorse or promote products derived from this software without |
|---|
| 15 | # specific prior written permission. |
|---|
| 16 | # |
|---|
| 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|---|
| 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|---|
| 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|---|
| 20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|---|
| 21 | # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
|---|
| 22 | # OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|---|
| 23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|---|
| 24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|---|
| 25 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|---|
| 26 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
|---|
| 27 | # THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | # mkd2s5 - markdown to s5 slideshow converter |
|---|
| 31 | # Homepage: http://dev.zecrazytux.net/trac/wiki/markdown-tools#mkd2s5 |
|---|
| 32 | |
|---|
| 33 | # 2009-11-08: Splitted code into a module to be required and smaller scripts |
|---|
| 34 | # 2009-10-26: rewritten this small hack in perl to replace my sh implementation |
|---|
| 35 | # * added syntax highlighting thanks to vim (optional) |
|---|
| 36 | |
|---|
| 37 | use strict; |
|---|
| 38 | use warnings; |
|---|
| 39 | use Template; |
|---|
| 40 | use Getopt::Long; |
|---|
| 41 | |
|---|
| 42 | push(@INC, '/usr/lib/markdown-tools', |
|---|
| 43 | '/usr/pkg/lib/markdown-tools', |
|---|
| 44 | '/usr/lib/markdown-tools', '.'); |
|---|
| 45 | require('mkdtools-functions.pl'); |
|---|
| 46 | |
|---|
| 47 | my $tool_name = 'mkd2s5'; |
|---|
| 48 | my $tool_version = 0.1.1; |
|---|
| 49 | my $tool_license = 'BSD'; |
|---|
| 50 | |
|---|
| 51 | my $markdowncmd; |
|---|
| 52 | my $help; |
|---|
| 53 | my $version; |
|---|
| 54 | my $tpl = 's5'; |
|---|
| 55 | my $in; |
|---|
| 56 | my $author = 'lolguy'; |
|---|
| 57 | my $email = 'root@localhost'; |
|---|
| 58 | my $company = 'Lonesome Cowboy'; |
|---|
| 59 | my $title = 'Untitled'; |
|---|
| 60 | my $date = `date +%x`; |
|---|
| 61 | my $synthaxhighlighting; |
|---|
| 62 | |
|---|
| 63 | GetOptions( |
|---|
| 64 | 'i|in=s' => \$in, |
|---|
| 65 | 't|template=s' => \$tpl, |
|---|
| 66 | 'm|markdown=s' => \$markdowncmd, |
|---|
| 67 | 'a|author=s' => \$author, |
|---|
| 68 | 'e|email=s' => \$email, |
|---|
| 69 | 'c|company=s' => \$company, |
|---|
| 70 | 'T|title=s' => \$title, |
|---|
| 71 | 'h|help' => \$help, |
|---|
| 72 | 'v|version' => \$version, |
|---|
| 73 | 'd|date=s' => \$date, |
|---|
| 74 | 's|syntax-highlighting' => \$synthaxhighlighting, |
|---|
| 75 | ); |
|---|
| 76 | |
|---|
| 77 | usage() if ($help or !$in); |
|---|
| 78 | version($tool_name, $tool_version, $tool_license) if $version; |
|---|
| 79 | |
|---|
| 80 | # looks like fuckage eh ?§?1 |
|---|
| 81 | # <h2> tags delimit the slides |
|---|
| 82 | my $output = join("", mkdandvimthis($in, $markdowncmd, $synthaxhighlighting)); |
|---|
| 83 | $output =~ s/<h2>/-SLIDE+<h2>/gi; |
|---|
| 84 | my @slides = split(/-SLIDE\+/, $output); |
|---|
| 85 | |
|---|
| 86 | my $data = { |
|---|
| 87 | main => \@slides, |
|---|
| 88 | author => $author, |
|---|
| 89 | email => $email, |
|---|
| 90 | company => $company, |
|---|
| 91 | title => $title, |
|---|
| 92 | date => $date, |
|---|
| 93 | }; |
|---|
| 94 | |
|---|
| 95 | # template toolkit permit us to create custom s5 templates |
|---|
| 96 | # (themes, standalone/or not, blalah) |
|---|
| 97 | my $template = Template->new( { INCLUDE_PATH => [ |
|---|
| 98 | '/usr/local/share/markdown-tools', |
|---|
| 99 | '/usr/share/markdown-tools', |
|---|
| 100 | '/usr/pkg/share/markdown-tools', |
|---|
| 101 | '.', $ENV{'HOME'}."/.markdown-tools", ] } ); |
|---|
| 102 | |
|---|
| 103 | $template->process($tpl, $data) || |
|---|
| 104 | die "Error while openning template $tpl"; |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | # -h, --help |
|---|
| 108 | sub usage { |
|---|
| 109 | print <<EOF; |
|---|
| 110 | $0 -i inputfile [options] |
|---|
| 111 | |
|---|
| 112 | Options: |
|---|
| 113 | |
|---|
| 114 | -t, --template Template to use (default s5) |
|---|
| 115 | -m, --markdown Markdown command (default markdown-discount) |
|---|
| 116 | -a, --author Author name |
|---|
| 117 | -e, --email Author email |
|---|
| 118 | -c, --company Author's company, event name, organization... |
|---|
| 119 | -T, --title Presentation title (default is first <h1>) |
|---|
| 120 | -d, --date Date (default is current date) |
|---|
| 121 | -s, --syntax-highlighting Enable syntax highlighting (require vim) |
|---|
| 122 | EOF |
|---|
| 123 | exit 2; |
|---|
| 124 | } |
|---|