From 0046e45014101cae55443fe16a2a50cfa42418f1 Mon Sep 17 00:00:00 2001 From: Baldur Kristinsson Date: Tue, 2 Feb 2016 11:23:20 +0000 Subject: [PATCH] Added revealjs to export formats --- CHANGELOG | 2 +- README.md | 15 ++++++++++----- pandoc.pm | 29 +++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index eb2f957..c588e0d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,7 @@ 0.3 (2016-02-02) ================ -* Add support for on-demand page export in several formats: pdf, beamer, latex, docx, odt and epub. +* Add support for on-demand page export in several formats: pdf, beamer, revealjs, latex, docx, odt and epub. 0.2.1 (2016-01-31) ================== diff --git a/README.md b/README.md index 3afe52c..c3f05de 100644 --- a/README.md +++ b/README.md @@ -108,27 +108,32 @@ These settings have no effect unless you have activated the `page.tmpl` file whi ### Extra output formats -It is sometimes useful to use pandoc to export the content of a wiki page to non-html formats, e.g. pdf or docx. This can be triggered by setting certain attributes in the YAML meta block of the page. The currently supported formats are `pdf`, `docx`, `odt`, `latex`, `beamer`, and `epub`. The corresponding meta attributes are the boolean values `generate_pdf`, `generate_docx`, `generate_odt`, `generate_latex`, `generate_beamer`, and `generate_epub`. As a shortcut, `generate_all_formats` will turn on all the generation of all six formats. For instance, +It is sometimes useful to use pandoc to export the content of a wiki page to non-html formats, e.g. pdf or docx. This can be triggered by setting certain attributes in the YAML meta block of the page. The currently supported formats are `pdf`, `docx`, `odt`, `latex`, `beamer`, `revealjs` and `epub`. The corresponding meta attributes are the boolean values `generate_pdf`, `generate_docx`, `generate_odt`, `generate_latex`, `generate_beamer`, `generate_revealjs` and `generate_epub`. As a shortcut, `generate_all_formats` will turn on the generation of all seven formats; some of them may then be turned off individually. For instance, ```yaml generate_all_formats: true generate_beamer: false +generate_revealjs: false ``` -will export files of all formats except Beamer. +will export files of all formats except Beamer and reveal.js. -When such extra formats have been generated for a page, links to the exported files will be appended to the action links (e.g. "Edit"). These are at the top of the page in the default theme. +When such extra formats have been generated for a page, links to the exported files will be appended to the so-called action links ("Edit", "History", etc.). These links are at the top of the page in the default theme. There are several configuration options related to the export functionality: * `pandoc_latex_template`: Path to pandoc template for LaTeX and PDF output. Since PDF files are created by way of LaTeX, there is no separate PDF template. (Obviously, PDF generation requires a working LaTeX installation). -* `pandoc_latex_extra_options`: List of extra pandoc options of LaTeX and PDF generation. (Note that this, like other `*_extra_options`, is a *list*, not simply a string). +* `pandoc_latex_extra_options`: List of extra pandoc options for LaTeX and PDF generation. (Note that this, like other `*_extra_options`, is a *list*, not simply a string). * `pandoc_beamer_template`: Path to pandoc template for Beamer PDF output. (Beamer is a presentations package for LaTeX). * `pandoc_beamer_extra_options`: List of extra pandoc options for Beamer PDF generation. +* `pandoc_revealjs_template`: Path to pandoc template for Reveal.js slides output. + +* `pandoc_revealjs_extra_options`: List of extra pandoc options for Reveal.js slides generation. **Please note** that the option `--self-contained` is added automatically. In order for this to work, pandoc has to know where to find the reveal.js Javascript and CSS files. The easiest way of making sure of this is to keep them in pandoc's default user data directory. You can see the name of this folder by running `pandoc --version`; usually it is `~/.pandoc`, in which case the reveal.js files would be in the subdirectory `~/.pandoc/reveal.js/`. You can download the most recent reveal.js release [here](https://github.com/hakimel/reveal.js/releases). + * `pandoc_docx_template`: Path to pandoc template for MS Word (`docx`) output. * `pandoc_docx_extra_options`: List of extra pandoc options for `docx` generation. @@ -141,7 +146,7 @@ There are several configuration options related to the export functionality: * `pandoc_epub_extra_options`: List of extra pandoc options for epub generation. -Notable **limitations** with regard to the export suppport: +**Notable limitations** with regard to the export suppport: * There is currently no way of overriding template or option settings for a specific format on a per-page basis. diff --git a/pandoc.pm b/pandoc.pm index 2398325..3fb55b0 100755 --- a/pandoc.pm +++ b/pandoc.pm @@ -16,8 +16,9 @@ my %extra_formats = ( docx => { ext=>'docx', label=>'DOCX', format=>'docx', extra=>[], order=>2 }, odt => { ext=>'odt', label=>'ODT', format=>'odt', extra=>[], order=>3 }, beamer => { ext=>'beamer.pdf', label=>'Beamer', format=>'beamer', extra=>[], order=>4 }, - epub => { ext=>'epub', label=>'EPUB', format=>'epub3', extra=>[], order=>5 }, - latex => { ext=>'tex', label=>'LaTeX', format=>'latex', extra=>['--standalone'], order=>6 }, + revealjs => { ext=>'revealjs.html', label=>'RevealJS', format=>'revealjs', extra=>['--self-contained'], order=>5 }, + epub => { ext=>'epub', label=>'EPUB', format=>'epub3', extra=>[], order=>6 }, + latex => { ext=>'tex', label=>'LaTeX', format=>'latex', extra=>['--standalone'], order=>7 }, ); sub import { @@ -263,6 +264,20 @@ sub getsetup () { safe => 0, rebuild => 0, }, + pandoc_revealjs_template { + type => "string", + example => "", + description => "Path to pandoc template for Reveal.js slides output", + safe => 1, + rebuild => 0, + }, + pandoc_revealjs_extra_options { + type => "internal", + default => [], + description => "List of extra pandoc options for Reveal.js slides generation", + safe => 0, + rebuild => 0, + }, pandoc_docx_template { type => "string", example => "", @@ -357,6 +372,14 @@ sub htmlize ($@) { my %with_urls = qw/mimetex 1 webtex 1/; my $mathopt = $1 if $config{pandoc_math} && $config{pandoc_math} =~ /(\w+)/; my $custom_js = $config{pandoc_math_custom_js} || ''; + # cleanup pandoc-prefixed keys from persistent meta + if (ref $pagestate{$page}{meta} eq 'HASH') { + my @delkeys = (); + foreach my $k (%{ $pagestate{$page}{meta} }) { + push @delkeys, $k if $k =~ /^pandoc_/; + } + delete $pagestate{$page}{meta}{$_} for @delkeys; + } if ($mathopt && $mathconf{$mathopt}) { if ($with_urls{$mathopt} && $custom_js) { # In these cases, the 'custom js' is a misnomer: actually a server-side script @@ -436,6 +459,8 @@ sub htmlize ($@) { my $gen_all = $meta->{generate_all_formats} || {}; next unless $meta->{$k} || $gen_all->{c}; my $val = $meta->{$k} ? $meta->{$k}->{c} : $gen_all->{c}; + # simplifies matters with JSON::(PP::)Boolean objects + $val = 1 if $val == 1 || $val eq 'true'; if (ref $val || $val =~ /^\s*(?:off|no|false|0)\s*$/i) { $bool_meta{$k} = 0; } else { -- 2.39.2