From b334a5cd721e57077eadc8636801d0bffd3f734d Mon Sep 17 00:00:00 2001 From: Manoj Srivastava Date: Tue, 5 Oct 2010 19:26:43 -0400 Subject: [PATCH] Added Manoj Srivastava's org.pm plugin. From http://www.golden-gryphon.com/blog/manoj/blog/2008/06/08/Using_org-mode_with_Ikiwiki/ on which page it lists the license as "GPL". --- IkiWiki/Plugin/org.pm | 68 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 IkiWiki/Plugin/org.pm diff --git a/IkiWiki/Plugin/org.pm b/IkiWiki/Plugin/org.pm new file mode 100644 index 000000000..36e269280 --- /dev/null +++ b/IkiWiki/Plugin/org.pm @@ -0,0 +1,68 @@ +#!/usr/bin/perl +# File: org.pm +# Time-stamp: <2008-06-08 23:12:20 srivasta> +# +# Copyright (C) 2008 by Manoj Srivastava +# +# Author: Manoj Srivastava +# +# Description: +# This allows people to write Ikiwiki content using Emacs and org-mode +# (requires Emacs 23), and uses the html export facility of org-mode to +# create the output. Some bits based on otl.pm. +# Here is the code: org.pm + +package IkiWiki::Plugin::org; +use warnings; +use strict; +use Carp; +use IkiWiki 2.00; + +use File::Temp qw/ tempfile tempdir /; + +# ------------------------------------------------------------ + +sub import { + hook(type => "htmlize", id => "org", call => \&htmlize); +} # + +sub htmlize (@) { + my %params = @_; + my $dir = File::Temp->newdir(); + + + + my $ret = open(INPUT, ">$dir/contents.org"); + unless (defined $ret) { + debug("failed to open $dir/contents.org: $@"); + return $params{content}; + } + + print INPUT $params{content}; + close INPUT; + my $args = '/usr/local/bin/emacs --batch -l org ' . + "--eval '(setq org-export-headline-levels 3 org-export-with-toc nil org-export-author-info nil )' " . + "--visit=$dir/contents.org " . + '--funcall org-export-as-html-batch >/dev/null 2>&1'; + if (system($args)) { + debug("failed to convert $params{page}: $@"); + return $params{content}; + } + $ret = open(OUTPUT, "$dir/contents.html"); + unless (defined $ret) { + debug("failed find html output for $params{page}: $@"); + return $params{content}; + } + local $/ = undef; + $ret = ; + close OUTPUT; + $ret=~s/(.*

){1}?//s; + $ret=~s/^(.*<\/h1>){1}?//s; + $ret=~s/
.*//s; + $ret=~s/(<\/div>\s*$)//s; + + return $ret; +} + +# ------------------------------------------------------------ +1; # modules have to return a true value -- 2.26.2