File: outline.t

package info (click to toggle)
libpandoc-elements-perl 0.38-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 732 kB
  • sloc: perl: 1,630; makefile: 15; sh: 1
file content (72 lines) | stat: -rw-r--r-- 1,583 bytes parent folder | download | duplicates (3)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use strict;
use 5.010;
use Test::More;
use Pandoc::Elements;
use Pandoc;

plan skip_all => 'pandoc >= 1.12.1 not available'
    unless (pandoc and pandoc->version > '1.12.1');

my $doc = pandoc->file('t/documents/outline.md');

my $outline = $doc->outline;

sub simplify {
    my $o = shift;
    $o->{header} //= Header 0, {}, [ Str '' ];
    [
        ('#' x $o->{header}->level . ' ' . $o->{header}->string),
        join(' / ', map { $_->string } @{$o->{blocks}}),
        [ map { simplify($_) } @{$o->{sections}} ]
    ]
}

is_deeply simplify($doc->outline),
[
  ' ', 'test document',
  [
    [
      '## section 0.1', '', [
        [ '### section 0.1.1', '', [] ]
      ]
    ],
    [ '# chapter 1', 'with / content', [] ],
    [
      '# chapter 2', '',
      [
        [ '## section 2.1', '', [] ],
        [
          '## section 2.2', 'text',
          [
            [ '#### subsubsection 2.2.1.1.1', '', [] ],
            [ '### subsubsection 2.2.2', '', [] ]
          ]
        ]
      ]
    ],
    [ '# chapter 3', 'header in table', [] ],
    [ '# chapter 4', '', [] ]
  ]
], 'outline()';

is_deeply simplify($doc->outline(2)),
[
  ' ', 'test document', [
    [ '## section 0.1', 'section 0.1.1', [] ],
    [ '# chapter 1', 'with / content', [] ],
    [
      '# chapter 2', '',
      [
        [ '## section 2.1', '', [] ],
        [
          '## section 2.2',
          'text / subsubsection 2.2.1.1.1 / subsubsection 2.2.2', []
        ]
      ]
    ],
    [ '# chapter 3', 'header in table', [] ],
    [ '# chapter 4', '', [] ]
  ]
], 'outline(2)';

done_testing;