root/markdown-tools/mkd2s5

Revision 66, 4.3 KB (checked in by zecrazytux, 6 months ago)

Added a tiny script that convert <img/> external source into embedded data source. Added a bearstech s5 template

  • Property svn:executable set to *
Line 
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
37use strict;
38use warnings;
39use Template;
40use Getopt::Long;
41
42push(@INC, '/usr/lib/markdown-tools',
43           '/usr/pkg/lib/markdown-tools',
44           '/usr/lib/markdown-tools', '.');
45require('mkdtools-functions.pl');
46
47my $tool_name = 'mkd2s5';
48my $tool_version = 0.1.1;
49my $tool_license = 'BSD';
50
51my $markdowncmd;
52my $help;
53my $version;
54my $tpl = 's5';
55my $in;
56my $author = 'lolguy';
57my $email = 'root@localhost';
58my $company = 'Lonesome Cowboy';
59my $title = 'Untitled';
60my $date = `date +%x`;
61my $synthaxhighlighting;
62
63GetOptions(
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
77usage() if ($help or !$in);
78version($tool_name, $tool_version, $tool_license) if $version;
79
80# looks like fuckage eh ?§?1
81# <h2> tags delimit the slides
82my $output = join("", mkdandvimthis($in, $markdowncmd, $synthaxhighlighting));
83$output =~ s/<h2>/-SLIDE+<h2>/gi;
84my @slides = split(/-SLIDE\+/, $output);
85
86my $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)
97my $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
108sub usage {
109  print <<EOF;
110$0 -i inputfile [options]
111
112Options:
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)
122EOF
123  exit 2;
124}
Note: See TracBrowser for help on using the browser.