From 55d78e2528de772f263dd14be3665915a6c3b6c9 Mon Sep 17 00:00:00 2001 From: Baldur Kristinsson Date: Sun, 6 Nov 2016 14:24:14 +0000 Subject: [PATCH] Compatibility with pandoc 1.18+ --- pandoc.pm | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pandoc.pm b/pandoc.pm index 5fe2d0a..25081ef 100755 --- a/pandoc.pm +++ b/pandoc.pm @@ -432,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"; } -- 2.39.5