1 | package CFPlus::Pod; |
1 | package CFPlus::Pod; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
|
|
4 | use utf8; |
4 | |
5 | |
5 | use Storable; |
6 | use Storable; |
6 | |
7 | |
7 | our $VERSION = 1; |
8 | our $VERSION = 1; |
8 | |
9 | |
|
|
10 | our $on_link = sub { }; |
9 | our %wiki; |
11 | our %wiki; |
|
|
12 | |
|
|
13 | my $MA_BEG = "\x{fcd0}"; |
|
|
14 | my $MA_SEP = "\x{fcd1}"; |
|
|
15 | my $MA_END = "\x{fcd2}"; |
10 | |
16 | |
11 | *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; |
17 | *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; |
12 | |
18 | |
13 | sub is_prefix_of($@) { |
19 | sub is_prefix_of($@) { |
14 | my ($node, @path) = @_; |
20 | my ($node, @path) = @_; |
… | |
… | |
56 | my @res; |
62 | my @res; |
57 | |
63 | |
58 | do { |
64 | do { |
59 | my $p = $doc->[$par]; |
65 | my $p = $doc->[$par]; |
60 | |
66 | |
61 | if (exists $p->{markup}) { |
67 | if (length $p->{markup}) { |
62 | my %para = ( |
68 | push @res, { |
63 | markup => $p->{markup}, |
69 | markup => $p->{markup}, |
64 | indent => $p->{indent}, |
70 | indent => $p->{indent}, |
65 | ); |
|
|
66 | |
|
|
67 | for (@{ $p->{widget} || [] }) { |
|
|
68 | my ($class, @args) = @$_; |
|
|
69 | push @{ $para{widget} }, $class->new (@args); |
|
|
70 | } |
71 | }; |
71 | |
|
|
72 | push @res, \%para; |
|
|
73 | } |
72 | } |
74 | } while $doc->[++$par]{level} > $lvl; |
73 | } while $doc->[++$par]{level} > $lvl; |
75 | |
74 | |
76 | @res |
75 | @res |
77 | } |
76 | } |
78 | |
77 | |
79 | sub section(@) { |
78 | sub section(@) { |
80 | map section_of $_, &find |
79 | map section_of $_, &find |
81 | } |
80 | } |
82 | |
81 | |
|
|
82 | sub thaw_section(\@\%) { |
|
|
83 | for (@{$_[0]}) { |
|
|
84 | $_->{markup} =~ s{ |
|
|
85 | $MA_BEG |
|
|
86 | ([^$MA_END]+) |
|
|
87 | $MA_END |
|
|
88 | }{ |
|
|
89 | my ($type, @arg) = split /$MA_SEP/o, $1; |
|
|
90 | |
|
|
91 | $_[1]{$type}($_, @arg) |
|
|
92 | }ogex; |
|
|
93 | } |
|
|
94 | } |
|
|
95 | |
|
|
96 | my %as_label = ( |
|
|
97 | image => sub { |
|
|
98 | my ($par, $path) = @_; |
|
|
99 | |
|
|
100 | "<small>img</small>" |
|
|
101 | }, |
|
|
102 | link => sub { |
|
|
103 | my ($par, $text, $link) = @_; |
|
|
104 | |
|
|
105 | "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>" |
|
|
106 | }, |
|
|
107 | ); |
|
|
108 | |
83 | sub as_label(@) { |
109 | sub as_label(@) { |
|
|
110 | thaw_section @_, %as_label; |
|
|
111 | |
84 | my $text = |
112 | my $text = |
85 | join "\n", |
113 | join "\n", |
86 | map +("\xa0" x ($_->{indent} / 4)) . $_->{markup}, |
114 | map +("\xa0" x ($_->{indent} / 4)) . $_->{markup}, |
87 | @_; |
115 | @_; |
88 | |
116 | |
… | |
… | |
90 | $text =~ s/\s+$//; |
118 | $text =~ s/\s+$//; |
91 | |
119 | |
92 | $text |
120 | $text |
93 | } |
121 | } |
94 | |
122 | |
|
|
123 | my %as_paragraphs = ( |
|
|
124 | image => sub { |
|
|
125 | my ($par, $path) = @_; |
|
|
126 | |
|
|
127 | push @{ $par->{widget} }, new CFPlus::UI::Image path => $path; |
|
|
128 | |
|
|
129 | "\x{fffc}" |
|
|
130 | }, |
|
|
131 | link => sub { |
|
|
132 | my ($par, $text, $link) = @_; |
|
|
133 | |
|
|
134 | push @{ $par->{widget} }, new CFPlus::UI::Label |
|
|
135 | markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>", |
|
|
136 | size => 0.8, |
|
|
137 | can_hover => 1, |
|
|
138 | can_events => 1, |
|
|
139 | padding_x => 0, |
|
|
140 | padding_y => 0, |
|
|
141 | on_button_up => sub { |
|
|
142 | $on_link->(split /\//, $link); |
|
|
143 | }; |
|
|
144 | |
|
|
145 | "\x{fffc}" |
|
|
146 | }, |
|
|
147 | ); |
|
|
148 | |
|
|
149 | sub as_paragraphs(@) { |
|
|
150 | thaw_section @_, %as_paragraphs; |
|
|
151 | |
|
|
152 | @_ |
|
|
153 | } |
|
|
154 | |
|
|
155 | sub section_paragraphs(@) { |
|
|
156 | as_paragraphs §ion |
|
|
157 | } |
|
|
158 | |
95 | sub section_label(@) { |
159 | sub section_label(@) { |
96 | as_label §ion |
160 | as_label §ion |
97 | } |
161 | } |
98 | |
162 | |
99 | 1 |
163 | 1 |