aboutsummaryrefslogtreecommitdiff
path: root/src/templates
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-10-17 14:22:29 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2006-10-17 14:22:29 +0000
commitdf7b68225101966051f8b592a27127bf789eb81e (patch)
treea063e97ed58d0bdb2cbb5a95c3e8c1bcce54aa00 /src/templates
parente7dbfef4d8aa528d9245424e9c372e900a774c90 (diff)
downloadpandoc-df7b68225101966051f8b592a27127bf789eb81e.tar.gz
initial import
git-svn-id: https://pandoc.googlecode.com/svn/trunk@2 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/templates')
-rw-r--r--src/templates/ASCIIMathML.hs7
-rw-r--r--src/templates/DefaultHeaders.hs20
-rw-r--r--src/templates/Makefile16
-rw-r--r--src/templates/S5.hs88
-rw-r--r--src/templates/fillTemplates.pl138
5 files changed, 269 insertions, 0 deletions
diff --git a/src/templates/ASCIIMathML.hs b/src/templates/ASCIIMathML.hs
new file mode 100644
index 000000000..fabc7fba2
--- /dev/null
+++ b/src/templates/ASCIIMathML.hs
@@ -0,0 +1,7 @@
+-- | Definitions for use of Pandoc.ASCIIMathML in HTML.
+-- (See <http://www1.chapman.edu/~jipsen/mathml/asciimath.html>.)
+module Text.Pandoc.ASCIIMathML ( asciiMathMLScript ) where
+
+-- | String containing Pandoc.ASCIIMathML javascript.
+asciiMathMLScript :: String
+asciiMathMLScript = "<script type=\"text/javascript\">\n<ASCIIMathML.js></script>\n"
diff --git a/src/templates/DefaultHeaders.hs b/src/templates/DefaultHeaders.hs
new file mode 100644
index 000000000..22d17d6a7
--- /dev/null
+++ b/src/templates/DefaultHeaders.hs
@@ -0,0 +1,20 @@
+-- | Default headers for Pandoc writers.
+module Text.Pandoc.Writers.DefaultHeaders (
+ defaultLaTeXHeader,
+ defaultHtmlHeader,
+ defaultS5Header,
+ defaultRTFHeader
+ ) where
+import Text.Pandoc.Writers.S5
+
+defaultLaTeXHeader :: String
+defaultLaTeXHeader = "<LaTeXHeader>"
+
+defaultHtmlHeader :: String
+defaultHtmlHeader = "<HtmlHeader>"
+
+defaultS5Header :: String
+defaultS5Header = "<S5Header>" ++ s5CSS ++ s5Javascript
+
+defaultRTFHeader :: String
+defaultRTFHeader = "<RTFHeader>"
diff --git a/src/templates/Makefile b/src/templates/Makefile
new file mode 100644
index 000000000..ccd7b7076
--- /dev/null
+++ b/src/templates/Makefile
@@ -0,0 +1,16 @@
+VPATH := ..
+PROCESSOR := ./fillTemplates.pl
+TARGETS := Text/Pandoc/ASCIIMathML.hs \
+ Text/Pandoc/Writers/S5.hs \
+ Text/Pandoc/Writers/DefaultHeaders.hs
+
+all: $(TARGETS)
+
+Text/Pandoc/ASCIIMathML.hs: ASCIIMathML.hs $(PROCESSOR) $(VPATH)/ASCIIMathML.js
+ perl $(PROCESSOR) $@ $(VPATH)
+
+Text/Pandoc/Writers/S5.hs: S5.hs $(PROCESSOR) $(VPATH)/headers/*
+ perl $(PROCESSOR) $@ $(VPATH)
+
+Text/Pandoc/Writers/DefaultHeaders.hs: DefaultHeaders.hs $(PROCESSOR) $(VPATH)/ui/default/*
+ perl $(PROCESSOR) $@ $(VPATH)
diff --git a/src/templates/S5.hs b/src/templates/S5.hs
new file mode 100644
index 000000000..1417e7d7d
--- /dev/null
+++ b/src/templates/S5.hs
@@ -0,0 +1,88 @@
+-- | Definitions for creation of S5 powerpoint-like HTML.
+-- (See <http://meyerweb.com/eric/tools/s5/>.)
+module Text.Pandoc.Writers.S5 (
+ -- * Strings
+ s5Javascript,
+ s5CSS,
+ s5Links,
+ -- * Functions
+ writeS5,
+ insertS5Structure
+ ) where
+import Text.Pandoc.Shared ( joinWithSep, WriterOptions )
+import Text.Pandoc.Writers.HTML ( writeHtml )
+import Text.Pandoc.Definition
+
+s5Javascript :: String
+s5Javascript = "<script type=\"text/javascript\">\n<slides.js></script>\n"
+
+s5CoreCSS :: String
+s5CoreCSS = "<s5-core.css>"
+
+s5FramingCSS :: String
+s5FramingCSS = "<framing.css>"
+
+s5PrettyCSS :: String
+s5PrettyCSS = "<pretty.css>"
+
+s5OperaCSS :: String
+s5OperaCSS = "<opera.css>"
+
+s5OutlineCSS :: String
+s5OutlineCSS = "<outline.css>"
+
+s5PrintCSS :: String
+s5PrintCSS = "<print.css>"
+
+s5CSS :: String
+s5CSS = "<style type=\"text/css\" media=\"projection\" id=\"slideProj\">\n" ++ s5CoreCSS ++ "\n" ++ s5FramingCSS ++ "\n" ++ s5PrettyCSS ++ "\n</style>\n<style type=\"text/css\" media=\"projection\" id=\"operaFix\">\n" ++ s5OperaCSS ++ "\n</style>\n<style type=\"text/css\" media=\"screen\" id=\"outlineStyle\">\n" ++ s5OutlineCSS ++ "\n</style>\n<style type=\"text/css\" media=\"print\" id=\"slidePrint\">\n" ++ s5PrintCSS ++ "\n</style>\n"
+
+s5Links :: String
+s5Links = "<!-- style sheet links -->\n<link rel=\"stylesheet\" href=\"ui/default/slides.css\" type=\"text/css\" media=\"projection\" id=\"slideProj\" />\n<link rel=\"stylesheet\" href=\"ui/default/outline.css\" type=\"text/css\" media=\"screen\" id=\"outlineStyle\" />\n<link rel=\"stylesheet\" href=\"ui/default/print.css\" type=\"text/css\" media=\"print\" id=\"slidePrint\" />\n<link rel=\"stylesheet\" href=\"ui/default/opera.css\" type=\"text/css\" media=\"projection\" id=\"operaFix\" />\n<!-- S5 JS -->\n<script src=\"ui/default/slides.js\" type=\"text/javascript\"></script>\n"
+
+-- | Converts 'Pandoc' to an S5 HTML presentation.
+writeS5 :: WriterOptions -> Pandoc -> String
+writeS5 options = writeHtml options . insertS5Structure
+
+-- | Inserts HTML needed for an S5 presentation (e.g. around slides).
+layoutDiv :: [Inline] -- ^ Title of document (for header or footer)
+ -> String -- ^ Date of document (for header or footer)
+ -> [Block] -- ^ List of block elements returned
+layoutDiv title date = [(RawHtml "<div class=\"layout\">\n<div id=\"controls\"></div>\n<div id=\"currentSlide\"></div>\n<div id=\"header\"></div>\n<div id=\"footer\">\n"), (Header 1 [Str date]), (Header 2 title), (RawHtml "</div>\n</div>\n")]
+
+presentationStart = (RawHtml "<div class=\"presentation\">\n\n")
+
+presentationEnd = (RawHtml "</div>\n")
+
+slideStart = (RawHtml "<div class=\"slide\">\n")
+
+slideEnd = (RawHtml "</div>\n")
+
+-- | Returns 'True' if block is a Header 1.
+isH1 :: Block -> Bool
+isH1 (Header 1 _) = True
+isH1 _ = False
+
+-- | Insert HTML around sections to make individual slides.
+insertSlides :: Bool -> [Block] -> [Block]
+insertSlides beginning blocks =
+ let (beforeHead, rest) = break isH1 blocks in
+ if (null rest) then
+ if beginning then
+ beforeHead
+ else
+ beforeHead ++ [slideEnd]
+ else
+ if beginning then
+ beforeHead ++ slideStart:(head rest):(insertSlides False (tail rest))
+ else
+ beforeHead ++ slideEnd:slideStart:(head rest):(insertSlides False (tail rest))
+
+-- | Insert blocks into 'Pandoc' for slide structure.
+insertS5Structure :: Pandoc -> Pandoc
+insertS5Structure (Pandoc meta []) = Pandoc meta []
+insertS5Structure (Pandoc (Meta title authors date) blocks) =
+ let slides = insertSlides True blocks
+ firstSlide = if (not (null title)) then [slideStart, (Header 1 title), (Header 3 [Str (joinWithSep ", " authors)]), (Header 4 [Str date]), slideEnd] else [] in
+ let newBlocks = (layoutDiv title date) ++ presentationStart:firstSlide ++ slides ++ [presentationEnd] in
+ Pandoc (Meta title authors date) newBlocks
diff --git a/src/templates/fillTemplates.pl b/src/templates/fillTemplates.pl
new file mode 100644
index 000000000..381db13d5
--- /dev/null
+++ b/src/templates/fillTemplates.pl
@@ -0,0 +1,138 @@
+#!/usr/bin/env perl
+# fills templates in templates directory with haskell-escaped strings
+# slurped from input files
+
+use strict;
+use warnings;
+
+# Utility routines:
+
+sub slurp {
+ open FILE, $_[0] or die "couldn't open file '$_[0]': $!";
+ my $contents = do { local $/; <FILE>;};
+ close FILE;
+ return $contents;
+}
+
+sub escape_for_haskell {
+ my ($contents) = @_;
+
+ $contents =~ s/\\/\\\\/g;
+ $contents =~ s/\t/\\t/g;
+ $contents =~ s/"/\\"/g;
+ $contents =~ s/\n/\\n/g;
+ return $contents;
+}
+
+# Template processors.
+
+my %processor = (
+ # --------------------------------------------------------------------------
+ 'Text/Pandoc/Writers/S5.hs' => {
+ # --------------------------------------------------------------------------
+ proc => sub {
+ my ($template) = @_;
+
+ my $slides = escape_for_haskell(slurp "ui/default/slides.js");
+ my $s5core = escape_for_haskell(slurp "ui/default/s5-core.css");
+ my $framing = escape_for_haskell(slurp "ui/default/framing.css");
+ my $pretty = escape_for_haskell(slurp "ui/default/pretty.css");
+ my $opera = escape_for_haskell(slurp "ui/default/opera.css");
+ my $outline = escape_for_haskell(slurp "ui/default/outline.css");
+ my $print = escape_for_haskell(slurp "ui/default/print.css");
+
+ $template =~ s/<slides\.js>/$slides/;
+ $template =~ s/<s5-core\.css>/$s5core/;
+ $template =~ s/<framing\.css>/$framing/;
+ $template =~ s/<pretty\.css>/$pretty/;
+ $template =~ s/<opera\.css>/$opera/;
+ $template =~ s/<outline\.css>/$outline/;
+ $template =~ s/<print\.css>/$print/;
+
+ return $template;
+ },
+ },
+ # --------------------------------------------------------------------------
+ 'Text/Pandoc/ASCIIMathML.hs' => {
+ # --------------------------------------------------------------------------
+ proc => sub {
+ my ($template) = @_;
+
+ my $script = escape_for_haskell(slurp "ASCIIMathML.js");
+ my $acknowledgements =
+ " ASCIIMathML.js - copyright Peter Jipsen,".
+ " released under the GPL\\nSee ".
+ "http://www1.chapman.edu/~jipsen/mathml/asciimath.html/ ";
+ $script =~ s/\/\*.*?\*\//\/\*$acknowledgements\*\//g; # strip comments
+ $template =~ s/<ASCIIMathML\.js>/$script/;
+
+ return $template;
+ },
+ },
+ # --------------------------------------------------------------------------
+ 'Text/Pandoc/Writers/DefaultHeaders.hs' => {
+ # --------------------------------------------------------------------------
+ proc => sub {
+ my ($template) = @_;
+
+ my $html = escape_for_haskell(slurp "headers/HtmlHeader");
+ my $latex = escape_for_haskell(slurp "headers/LaTeXHeader");
+ my $rtf = escape_for_haskell(slurp "headers/RTFHeader");
+ my $s5 = escape_for_haskell(slurp "headers/S5Header");
+
+ $template =~ s/<HtmlHeader>/$html/;
+ $template =~ s/<LaTeXHeader>/$latex/;
+ $template =~ s/<RTFHeader>/$rtf/;
+ $template =~ s/<S5Header>/$s5/;
+
+ return $template;
+ },
+ },
+ # --------------------------------------------------------------------------
+ # 'foo/bar/baz' => {
+ # --------------------------------------------------------------------------
+ # template => 'optional-template-filename-defaults-to-baz'
+ # proc => sub {
+ # my ($template) = @_;
+ # # Process.
+ # return $template;
+ # },
+ #},
+);
+
+# Main.
+
+my $target = shift @ARGV;
+if (!defined $target || !length $target) {
+ print STDERR "Available targets:\n\n" . join "\n", keys %processor;
+ die "\n\nYou must supply a target!\n";
+}
+
+die "No processor exists for '$target'!\n" if ! exists $processor{$target};
+
+my $rootdir = shift @ARGV || '..';
+chdir $rootdir or die "Couldn't chdir to '$rootdir': $!";
+
+my $template;
+if (exists $processor{$target}->{template}) {
+ $template = $processor{$target}->{template};
+}
+else {
+ ($template = $target) =~ s!.*/+!!;
+}
+$template = "templates/$template";
+die "No template exists for '$target'!\n" if ! -f "$template";
+
+open OUTFILE, ">$target" or die "couldn't open file '$target': $!";
+print OUTFILE <<END;
+----------------------------------------------------
+-- Do not edit this file by hand. Edit
+-- '$template'
+-- and run $0 $target
+----------------------------------------------------
+
+END
+
+print OUTFILE $processor{$target}->{proc}->(slurp($template));
+print OUTFILE "\n";
+close OUTFILE;