aboutsummaryrefslogtreecommitdiff
path: root/lib/WebCoso/ReST.pm
blob: 5f7f922adcbbcae910d11eca74c9ed5dde4509e5 (plain)
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
package WebCoso::ReST; 
use strict;
use warnings;
use WebCoso::Common;
use Path::Class;
use Text::Restructured;
use Text::Restructured::Writer::LibXML;
use Log::Log4perl ':easy';
use Encode;
 
Text::Restructured::Directive::handle_directive( video => \&rst_video);
 
sub new {
    my ($class,%opts)=@_;
 
    my $self={%opts};
 
    $self->{rest}=Text::Restructured->new(
        {
            D=>{
                'file-insertion-enabled'=>1, # we use TT for insertion, but we need this for "raw" 
                generator=>0,
                date=>0,
                'time'=>0,
                'source-link'=>0,
                'section-subtitles'=>1,
                raw_enabled => 1,
            },
        },
        'WebCoso');
 
    $self->{fc}->add_parser(qr{\.rest\.txt$} =>
                                sub {
                                    my $dudom=$self->{rest}->Parse(decode('utf-8',$_[1]),$_[0]);
                                    return Text::Restructured::Writer::LibXML
                                        ->new->ProcessDOM($dudom);
                                });
 
    bless $self,$class;
}
 
sub rst_video {
    my($parser$name$parent$source$lineno$dtext$lit) = @_;
    my $dhash = Text::Restructured::Directive::parse_directive($parser$dtext$lit$source$lineno);
    my $options = $dhash->{options};
    my @extra_attrs = (qw(loop type));
    # a video is like an image 
    my $dom = Text::Restructured::Directive::image(@_,@extra_attrs);
    $dom->tag('video');
    for my $attr (@extra_attrs) {
        if ($options->{$attr}) {
            $dom->{attr}{$attr} = $options->{$attr};
        }
    }
    return $dom;
}
 
1;