aboutsummaryrefslogtreecommitdiffstats
path: root/org.pm
blob: 0d191771019e20373f897fc4173bedf06a9e313f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl
# org-mode markup
# based on the WikiCreole plugin.
package IkiWiki::Plugin::org;

use warnings;
use strict;
use IkiWiki 3.00;

sub import {
    hook(type => "getsetup", id => "org", call => \&getsetup);
    hook(type => "htmlize",  id => "org", call => \&htmlize);
}

sub getsetup {
    return plugin => {
        safe => 0,
        rebuild => 1,           # format plugin
        section => "format",
    },
}

sub htmlize (@) {
    my %params=@_;
    my $content = $params{content};

    print($params{page});

    open(my $file, ">test.org") || die("Couldn't open test.org: $!");
    print $file $content;
    close($file);
    `emacs -batch -L ~/.emacs.d/vendor-lisp/org/lisp -L ~/.emacs.d/vendor-lisp/org/contrib/lisp -visit test.org -eval "(setq org-html-htmlize-output-type 'css)" -eval "(org-html-export-to-html nil nil nil t)"`;
    open($file, "test.html") || die("Couldn't open test.html: $!");
    my @lines=<$file>;
    close($file);

    unlink "test.org";
    unlink "test.html";

    return join('', @lines);
}

1