summaryrefslogtreecommitdiff
path: root/perllib/sdf/podmacs.pl
blob: 71c75f4989129fad0becae891dde93cbfefa9557 (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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# $Id$
$VERSION{''.__FILE__} = '$Revision$';
#
# >>Title::     POD Macros Library
#
# >>Copyright::
# Copyright (c) 1992-1997, Ian Clatworthy (ianc@mincom.com).
# You may distribute under the terms specified in the LICENSE file.
#
# >>History::
# -----------------------------------------------------------------------
# Date      Who     Change
# 17-Jun-97 ianc    SDF 2.000
# -----------------------------------------------------------------------
#
# >>Purpose::
# This library provides the built-in macros (implemented in [[Perl]]) for
# compatibility with POD.
#
# >>Description::
#
# >>Limitations::
#


# Switch to the user package
package SDF_USER;

##### Constants #####

##### Variables #####

# This contains the first item in each list
@_pod_item = ();

# This contains the indent (i.e. N within "over N") of each list
@_pod_over = ();

# This contains the style for each list
@_pod_style = ();

##### Initialisation #####

#
# >>Description::
# {{Y:InitPodMacros}} initialises the global variables in this module.
#
sub InitPodMacros {
#   local() = @_;
#   local();

    @_pod_item = ();
    @_pod_over = ();
    @_pod_style = ();
}

##### Support Routines #####


##### General Macros #####

# head1 - level 1 heading
@_head1_MacroArgs = (
    'Name       Type        Default     Rule',
    'text       rest        _NULL_',
);
sub head1_Macro {
    local(%arg) = @_;
    local(@text);

    # Return result
    return ("H1:$arg{'text'}");
}

# head2 - level 2 heading
@_head2_MacroArgs = (
    'Name       Type        Default     Rule',
    'text       rest        _NULL_',
);
sub head2_Macro {
    local(%arg) = @_;
    local(@text);

    # Return result
    return ("H2:$arg{'text'}");
}

# head3 - level 3 heading
@_head3_MacroArgs = (
    'Name       Type        Default     Rule',
    'text       rest        _NULL_',
);
sub head3_Macro {
    local(%arg) = @_;
    local(@text);

    # Return result
    return ("H3:$arg{'text'}");
}

# head4 - level 4 heading
@_head4_MacroArgs = (
    'Name       Type        Default     Rule',
    'text       rest        _NULL_',
);
sub head4_Macro {
    local(%arg) = @_;
    local(@text);

    # Return result
    return ("H4:$arg{'text'}");
}

# head5 - level 5 heading
@_head5_MacroArgs = (
    'Name       Type        Default     Rule',
    'text       rest        _NULL_',
);
sub head5_Macro {
    local(%arg) = @_;
    local(@text);

    # Return result
    return ("H5:$arg{'text'}");
}

# head6 - level 6 heading
@_head6_MacroArgs = (
    'Name       Type        Default     Rule',
    'text       rest        _NULL_',
);
sub head6_Macro {
    local(%arg) = @_;
    local(@text);

    # Return result
    return ("H6:$arg{'text'}");
}


# over - begin a list
@_over_MacroArgs = (
    'Name       Type        Default     Rule',
    'N          integer     4',
);
sub over_Macro {
    local(%arg) = @_;
    local(@text);

    # If this is the first level, switch on some special processing
    @text = ();
    if (scalar(@_pod_style) == 0) {
        # Indent examples using the level information
        push(@text, '!on paragraph \'E\'; POD_LIST_E; $attr{"in"} = scalar(@_pod_style)');

        # Set up the rule for paragraphs within a list
        push(@text, '!on paragraph \'N\'; POD_LIST_N; ' .
          '$style = $_pod_style[$#_pod_style]; ' .
          '$_pod_style[$#_pod_style] = "L" . scalar(@_pod_style)');
    }

    # Update the state
    push(@_pod_item, '');
    push(@_pod_over, $arg{'N'});
    push(@_pod_style, '');

    # Return result
    return @text;
}

# item - list item
@_item_MacroArgs = (
    'Name       Type        Default     Rule',
    'text       rest        _NULL_',
);
sub item_Macro {
    local(%arg) = @_;
    local(@text);

    # If an over hasn't been found, assume one
    @text = &over_Macro('N', 4) if scalar(@_pod_over) == 0;

    # Get the level
    my $level = scalar(@_pod_style);

    # If this is the first item, decide how to format the list
    unless ($_pod_item[$#_pod_item]) {
        $_pod_item[$#_pod_item] = $arg{'text'};
    }

    # Handle bulleted lists
    if ($_pod_item[$#_pod_item] eq '*') {
        $_pod_style[$#_pod_style] = "LU$level";
    }

    # Handle ordered lists
    elsif ($_pod_item[$#_pod_item] eq '1.') {
        $_pod_style[$#_pod_style] = $arg{'text'} eq '1.' ? "LF$level" : "LN$level";
    }

    # Handle enumerated lists
    else {
        $_pod_style[$#_pod_style] = "L$level";
        push(@text, "LI$level:$arg{'text'}");
    }

    # Return result
    return @text;
}

# back - end a list
@_back_MacroArgs = ();
sub back_Macro {
    local(%arg) = @_;
    local(@result);

    # Update the state
    pop(@_pod_item);
    pop(@_pod_over);
    pop(@_pod_style);

    # If this terminates the first level, switch off the special processing
    @result = ();
    if (scalar @_pod_style == 0) {
        @result = (
            '!off paragraph POD_LIST_N',
            '!off paragraph POD_LIST_E');
    }

    # Return result
    return @result;
}

# cut - ignore file until next = at start of line
@_cut_MacroArgs = ();
sub cut_Macro {
    local(%arg) = @_;
    local(@text);

    # Update the parser state
    $'sdf_cutting = 1;

    # Return result
    return ();
}

# pod - begin some POD
@_pod_MacroArgs = ();
sub pod_Macro {
    local(%arg) = @_;

    # Return result - nothing
    return ();
}

# for - paragraph is for format X only
@_for_MacroArgs = (
    'Name       Type        Default     Rule',
    'format     symbol',
    'text       rest        _NULL_',
);
sub for_Macro {
    local(%arg) = @_;
    local(@text);

    # Return result
    #return (&SdfJoin("__inline", $arg{'text'}, 'target', $arg{'format'}));
    return (
        "!block inline; target='$arg{'format'}'",
        $arg{'text'},
        '!endblock');
}

# begin - begin paragraphs for format X only
@_begin_MacroArgs = (
    'Name       Type        Default     Rule',
    'format     symbol',
);
sub begin_Macro {
    local(%arg) = @_;
    local(@text);

    # Return result
    return ();
}

# end - end paragraphs for format X
@_end_MacroArgs = (
    'Name       Type        Default     Rule',
    'format     symbol',
);
sub end_Macro {
    local(%arg) = @_;
    local(@text);

    # Return result
    return ();
}

# package return value
1;