summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2018-12-06 17:19:02 +0100
committerGuilhem Moulin <guilhem@fripost.org>2018-12-06 17:23:53 +0100
commitdb38048fe11edb0464cb3ab45221660d9c329f04 (patch)
tree2b666c9184c1ae9d1546b7e6cf87b70dd6335cf1 /roles
parentfc0ae167c7db24bcec6d3b3125fa610c8384ac1e (diff)
Upgrade 'ikiwiki-pandoc' to v0.5.1.
https://raw.githubusercontent.com/sciunto-org/ikiwiki-pandoc/v0.5.1/pandoc.pm Currently at commit 9292e45cea1be120adb3babd5b835b547f4c825a .
Diffstat (limited to 'roles')
-rw-r--r--roles/wiki/files/var/lib/ikiwiki/IkiWiki/Plugin/pandoc.pm38
1 files changed, 31 insertions, 7 deletions
diff --git a/roles/wiki/files/var/lib/ikiwiki/IkiWiki/Plugin/pandoc.pm b/roles/wiki/files/var/lib/ikiwiki/IkiWiki/Plugin/pandoc.pm
index a3b803a..25081ef 100644
--- a/roles/wiki/files/var/lib/ikiwiki/IkiWiki/Plugin/pandoc.pm
+++ b/roles/wiki/files/var/lib/ikiwiki/IkiWiki/Plugin/pandoc.pm
@@ -149,40 +149,47 @@ sub getsetup () {
type => "boolean",
example => 1,
description => "Obfuscate emails",
safe => 1,
rebuild => 1,
},
pandoc_html5 => {
type => "boolean",
example => 0,
description => "Generate HTML5",
safe => 1,
rebuild => 1,
},
pandoc_ascii => {
type => "boolean",
example => 0,
description => "Generate ASCII instead of UTF8",
safe => 1,
rebuild => 1,
},
+ pandoc_html_extra_options => {
+ type => "internal",
+ default => [],
+ description => "List of extra pandoc options for html",
+ safe => 0,
+ rebuild => 0,
+ },
pandoc_numsect => {
type => "boolean",
example => 0,
description => "Number sections",
safe => 1,
rebuild => 1,
},
pandoc_sectdiv => {
type => "boolean",
example => 0,
description => "Attach IDs to section DIVs instead of Headers",
safe => 1,
rebuild => 1,
},
pandoc_codeclasses => {
type => "string",
example => "",
description => "Classes to use for indented code blocks",
safe => 1,
rebuild => 1,
@@ -408,46 +415,49 @@ sub htmlize ($@) {
@args, '--normalize');
error("Unable to open $command") unless $to_json_pid;
# Workaround for perl bug (#376329)
require Encode;
my $content = Encode::encode_utf8($params{content});
# Protect inline plugin placeholders from being mangled by pandoc:
$content =~ s{<div class="inline" id="(\d+)"></div>}
{::INLINE::PLACEHOLDER::$1::}g;
print PANDOC_OUT $content;
close PANDOC_OUT;
my $json_content = <JSON_OUT>;
close JSON_OUT;
waitpid $to_json_pid, 0;
# Parse the title block out of the JSON and set the meta values
- my @json_content = @{decode_json($json_content)};
- my $meta = {};
- if (ref $json_content[0] eq 'HASH') {
- $meta = $json_content[0]->{'unMeta'};
- }
- else {
+ my $meta = undef;
+ my $decoded_json = decode_json($json_content);
+ # The representation of the meta block changed in pandoc version 1.18
+ if (ref $decoded_json eq 'HASH' && $decoded_json->{'Meta'}) {
+ $meta = $decoded_json->{'Meta'} || {}; # post-1.18 version
+ } elsif (ref $decoded_json eq 'ARRAY') {
+ $meta = $decoded_json->[0]->{'unMeta'} || {}; # pre-1.18 version
+ }
+ unless ($meta) {
warn "WARNING: Unexpected format for meta block. Incompatible version of Pandoc?\n";
}
# Get some selected meta attributes, more specifically:
# (title date bibliography csl subtitle abstract summary description
# version lang locale references author [+ num_authors primary_author]),
# as well as some configuration options (generate_*, *_extra_options, *_template).
my @format_keys = grep { $_ ne 'pdf' } keys %extra_formats;
my %scalar_meta = map { ($_=>undef) } qw(
title date bibliography csl subtitle abstract summary
description version lang locale);
$scalar_meta{$_.'_template'} = undef for @format_keys;
my %bool_meta = map { ("generate_$_"=>0) } keys %extra_formats;
my %list_meta = map { ($_=>[]) } qw/author references/;
$list_meta{$_.'_extra_options'} = [] for @format_keys;
my $have_bibl = 0;
foreach my $k (keys %scalar_meta) {
next unless $meta->{$k};
$scalar_meta{$k} = compile_string($meta->{$k}->{c});
@@ -517,44 +527,58 @@ sub htmlize ($@) {
push @args, "--metadata=lang:".$config{pandoc_csl_default_lang};
}
}
# Turn on the pandoc-citeproc filter if either global bibliography,
# local bibliography or a 'references' key in Meta is present.
if ($have_bibl) {
my $citeproc = $config{pandoc_citeproc} || 'pandoc-citeproc';
push @args, "--filter=$citeproc";
}
# Other pandoc filters. Note that currently there is no way to
# configure a filter to run before pandoc-citeproc has done its work.
if ($config{pandoc_filters}) {
my @filters = split /\s*,\s*/, $config{pandoc_filters};
s/^["']//g for @filters; # get rid of enclosing quotes
foreach my $filter (@filters) {
push @args, "--filter=$filter";
}
}
+ # html_extra_options my be set in Meta block in the page or in the .setup
+ # file. If both are present, the Meta block has precedence, even if it is
+ # an empty list
+ my @html_args = @args;
+ if (ref $meta->{html_extra_options}{c} eq 'ARRAY') {
+ if (ref unwrap_c($meta->{html_extra_options}{c}) eq 'ARRAY') {
+ push @html_args, @{unwrap_c($meta->{html_extra_options}{c})};
+ } else {
+ push @html_args, unwrap_c($meta->{html_extra_options}{c});
+ }
+ } elsif (ref $config{'pandoc_html_extra_options'} eq 'ARRAY') {
+ push @html_args, @{$config{'pandoc_html_extra_options'}};
+ }
+
my $to_html_pid = open2(*PANDOC_IN, *JSON_IN, $command,
'-f', 'json',
'-t', $htmlformat,
- @args);
+ @html_args);
error("Unable to open $command") unless $to_html_pid;
$pagestate{$page}{pandoc_extra_formats} = {};
foreach my $ext (keys %extra_formats) {
if ($bool_meta{"generate_$ext"}) {
export_file($page, $ext, $json_content, $command, @args);
} else {
remove_exported_file($page, $ext);
}
}
print JSON_IN $json_content;
close JSON_IN;
my @html = <PANDOC_IN>;
close PANDOC_IN;
waitpid $to_html_pid, 0;
$content = Encode::decode_utf8(join('', @html));