-
Notifications
You must be signed in to change notification settings - Fork 1
/
WikiDoc.pm
46 lines (35 loc) · 1.22 KB
/
WikiDoc.pm
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
package Pod::Elemental::Transformer::WikiDoc;
use Moose;
with 'Pod::Elemental::Transformer';
use namespace::autoclean;
use Moose::Autobox;
use Pod::Elemental::Types qw(FormatName);
use Pod::WikiDoc;
has format_name => (
is => 'ro',
isa => FormatName,
default => 'wikidoc',
);
sub transform_node {
my ($self, $node) = @_;
my $children = $node->children;
PASS: for my $i (0 .. $children->length - 1) {
my $para = $children->[$i];
next unless $para->isa('Pod::Elemental::Element::Pod5::Region')
and $para->format_name eq $self->format_name;
confess "wikidoc transformer expects wikidoc region to contain 1 Data para"
unless $para->children->length == 1
and $para->children->[0]->isa('Pod::Elemental::Element::Pod5::Data');
my $text = $para->children->[0]->content;
my $parser = Pod::WikiDoc->new;
my $new_pod = $parser->format($para->as_pod_string);
my $new_doc = Pod::Elemental->read_string($new_pod);
Pod::Elemental::Transformer::Pod5->transform_node($new_doc);
$new_doc->children->shift
while
$new_doc->children->[0]->isa('Pod::Elemental::Element::Pod5::Nonpod');
splice @$children, $i, 1, $new_doc->children->flatten;
}
return $node;
}
1;