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