(no commit message)
[ikiwiki] / t / toc.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More;
5 use Encode;
6
7 BEGIN { use_ok("IkiWiki"); }
8 BEGIN { use_ok("IkiWiki::Render"); }
9
10 %config=IkiWiki::defaultconfig();
11 $config{srcdir}=$config{destdir}="/dev/null";
12 $config{add_plugins}=[qw(toc)];
13
14 my $installed = $ENV{INSTALLED_TESTS};
15
16 unless ($installed) {
17         $config{templatedir} = "templates";
18         $config{underlaydir} = "underlays/basewiki";
19         $config{underlaydirbase} = "underlays";
20 }
21
22 IkiWiki::loadplugins();
23 IkiWiki::checkconfig();
24
25 sub render {
26         my $content = shift;
27         $IkiWiki::pagesources{foo} = "foo.mdwn";
28         $IkiWiki::pagemtime{foo} = 42;
29         $IkiWiki::pagectime{foo} = 42;
30         $content = IkiWiki::filter("foo", "foo", $content);
31         $content = IkiWiki::preprocess("foo", "foo", $content);
32         $content = IkiWiki::linkify("foo", "foo", $content);
33         $content = IkiWiki::htmlize("foo", "foo", "mdwn", $content);
34         $content = IkiWiki::genpage("foo", $content);
35         return $content;
36 }
37
38 # https://ikiwiki.info/todo/toc-with-human-readable-anchors/
39 # (toc-recycle-id part)
40 like(render('[[!toc ]]
41 ## Weasels
42
43 These mustelids are weasilly recognised
44
45 <h2 id="the-chapter-on-stoats">Stoats</h2>
46
47 These are stoatally different
48 '),
49         qr{(?s)<a href="\#index1h2">.*<a href="\#the-chapter-on-stoats">});
50
51 done_testing();