From 0ca9a45f4eaf434c27e0065580808555a8813eb8 Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Mon, 20 Jan 2020 18:30:31 +0100 Subject: [PATCH] Feature. Support of complex meta structures MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add support in *unwrap_c* for support of the structure: *MetaList* with 2 x *MetaMap* with keys pointing to *MetaInlines*: --- references: - id: refone title: Ref-MetaInlines-in-MetaList - id: reftwo title: Ref-MetaInlines-in-MetaList ... Actually it sounds complex but this fix should also be needed for the simpler example of *MetaMap* with keys pointing at *MetaInlines*: --- experiment: key_first: Värde key_second: värde ... --- pandoc.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandoc.pm b/pandoc.pm index 7c4d731..be44a06 100755 --- a/pandoc.pm +++ b/pandoc.pm @@ -773,6 +773,11 @@ sub unwrap_c { # Finds the deepest-level scalar value for 'c' in the data structure. # Lists with one element are replaced with the scalar, lists with more # than one element are returned as an arrayref containing scalars. + # + # Elements containing hash as keys are unwrapped. That is to + # support *MetaList* containing *MetaMap* with keys pointing to + # *MetaInlines*. Reference are examples of that structure. (hash unwrap) + # my $container = shift; if (ref $container eq 'ARRAY' && @$container > 1) { if (ref $container->[0] eq 'HASH' && $container->[0]->{t} =~ /^(?:Str|Space)$/) { @@ -787,6 +792,8 @@ sub unwrap_c { return; } elsif (ref $container eq 'HASH' && $container->{c}) { return unwrap_c($container->{c}); + } elsif (ref $container eq 'HASH' && keys $container->%*) { # (hash unwrap) + return {map { $_ => unwrap_c($container->{$_}) } keys $container->%*}; } elsif (ref $container) { return; } else { -- 2.39.5