From db38048fe11edb0464cb3ab45221660d9c329f04 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Thu, 6 Dec 2018 17:19:02 +0100 Subject: Upgrade 'ikiwiki-pandoc' to v0.5.1. https://raw.githubusercontent.com/sciunto-org/ikiwiki-pandoc/v0.5.1/pandoc.pm Currently at commit 9292e45cea1be120adb3babd5b835b547f4c825a . --- .../files/var/lib/ikiwiki/IkiWiki/Plugin/pandoc.pm | 38 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'roles/wiki/files/var') 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 @@ -166,6 +166,13 @@ sub getsetup () { 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, @@ -425,12 +432,15 @@ sub htmlize ($@) { 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"; } @@ -534,10 +544,24 @@ sub htmlize ($@) { } } + # 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} = {}; -- cgit v1.2.3