2

I use Pandoc to create Reveal.js presentations from Markdown documents, having switched to it from Google Slides. From the beginning I decided that presentations for different events and lectures are to be combined automatically from multiple files - thus it's easier to maintain separate slides without need to update content constantly in several places.

The solution for now combines Codekit (using its Kit language) and pandoc. So individual parts of presentations are prepared in an editor, then are referred in a single .kit file with @import statements and then the resulting Markdown file goes processed by pandoc which creates an HTML presentation (the last part being done by Sublime Text build system).

I'd like to simplify this process somehow with some kind of script that would pre-process a combined Markdown file automatically every time pandoc eats it. There are posts on StackExchange that refer to Haskell filters, but Haskell install is way too big for my tiny system (800Mb at minimum).

Is there a way to include files with some other kind of programming language or trick? I know for example, that it's possible to join several files by concatenating their names in pandoc command, but that doesn't make workflow smoother or faster.

1

In principle, you can write pandoc filters in any language, though Haskell is particularly well suited. The pandocfilters library makes it easy to write them in python.

Here's a tutorial on pandoc filters. It contains a sample Haskell filter for include files, which should be pretty easy to translate to a python filter using pandocfilters.

See also the directory of examples in the pandocfilters repository.

1

I finally figured out some ways to do the task.

The first is to use a pandoc filter written in Python that does includes (it works the same way as the Haskell filter described in pandoc docs). However, now it's adapted for using only with included code blocks, not with general content pieces.

The second way is to use inline Perl script which may be prepended to the build command (first seen here). This path has proved useful and I'll stick to it for some time, because

  1. I'm not really good at Python and
  2. it allows for some handy search-and-replace tasks to be done, such as on-the-go replacing parts of paths of the images and included files.

Below is the command I use to produce a slideshow in Reveal.js format (though this one meant to be uploaded to some web hosting, there are other build variants for building a self-contained slideshow file using --self-contained option of pandoc or, for example, "collect" all the files related to slideshow to a folder on Desktop):

perl -ne 's/^#\\((.+)\\).*/`cat \"${project_path/\\//\\\\\\//g}\\$1\"`/e;s/\\((\\/_common\\/img)/(\\/presentations\\$1/g;print' ${file_base_name}.md > result.md && pandoc -s -t revealjs --variable revealjs-url=http://www.site.com/presentations/_common/resources/revealjs --css=http://www.site.com/presentations/_common/resources/customcss_sky.css -H ${project_path}/_common/resources/customhtml.html --highlight-style haddock result.md -o index.html && trash result.md

This command:

  1. Replaces all #(path/to/include) expressions (paths must be relative to project folder) with includes' contents;
  2. Replaces paths in images (relative to project folder) with server path to images directory;
  3. Outputs the resulting Markdown to a temporary file;
  4. Creates HTML slideshow with pandoc;
  5. Trashes temporary file with Ali Rantakari's trash utility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.