summaryrefslogtreecommitdiffhomepage
path: root/raku-pod.html.markdown
blob: b008beab8fb27157d3ffa70fdef247c06dda9081 (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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
---
language: Pod
contributors:
    - ["Luis F. Uceta", "https://uzluisf.gitlab.io/"]
filename: learnpod.pod6
---

Pod is an easy-to-use and purely descriptive mark-up language,
with no presentational components. Besides its use for documenting
Raku programs and modules, Pod can be utilized to write language
documentation, blogs, and other types of document composition as well.

Pod documents can be easily converted to HTML and many other formats
(e.g., Markdown, Latex, plain text, etc.) by using the corresponding
variant of the `Pod::To` modules (e.g. `Pod::To::HTML` for HTML conversion).

- [General Info](#general-info)
- [Pod Basics](#pod-basics)
	- [Basic Text Formatting](#basic-text-formatting)
	- [Headings](#headings)
	- [Ordinary Paragraphs](#ordinary-paragraphs)
	- [Lists](#lists)
	- [Code Blocks](#code-blocks)
	- [Comments](#comments)
	- [Links](#links)
	- [Tables](#tables)
- [Block Structures](#block-structures)
	- [Abbreviated Blocks](#abbreviated-blocks)
	- [Delimited Blocks](#delimited-blocks)
	- [Paragraph Blocks](#paragraph-blocks)
- [Configuration Data](#configuration-data)
	- [Standard Configuration Options](#standard-configuration-options)
	- [Block Pre-configuration](#block-pre-configuration)
- [Semantic Blocks](#semantic-blocks)
- [Miscellaneous](#miscellaneous)
	- [Notes](#notes)
	- [Keyboard Input](#keyboard-input)
	- [Terminal Output](#terminal-output)
	- [Unicode](#unicode)
- [Rendering Pod](#rendering-pod)
- [Accessing Pod](#accessing-pod)

## General Info

Every Pod document has to begin with `=begin pod` and end with `=end pod`.
Everything between these two delimiters will be processed and used to
generate documentation.

```
=begin pod

A very simple Raku Pod document. All the other directives go here!

=end pod
```

Pod documents usually coexist with Raku code. If by themselves,
Pod files often have the `.pod6` suffix. Moving forward, it's assumed that
the constructs being discussed are surrounded by the `=begin pod ... =end pod`
directives.

## Pod Basics

### Basic Text Formatting

Text can be easily styled as bold, italic, underlined or verbatim (for code
formatting) using the following formatting codes: `B<>`, `I<>`, `U<>`
and `C<>`.

```
B<This text is in Bold.>

I<This text is in Italics.>

U<This text is Underlined.>

The function C<sub sum { $^x + $^y}> is treated as verbatim.
```

There are more formatting codes (e.g., `L<>`, `T<>`, etc.) but they'll be
discussed later throughout the document. You'll recognize them because they're
just a single capital letter followed immediately by a set of single or double
angle brackets. The Unicode variant («») of the angle brackets can also be
used.

### Headings

Headings are created by using the `=headN` directive where `N` is the
heading level.

```
=head1 This is level 1
=head2 This is level 2
=head3 This is level 3
=head4 This is level 4
=head5 This is level 5
=head6 This is level 6
```

### Ordinary Paragraphs

Ordinary paragraphs consist of one or more adjacent lines of text, each of
which starts with a non-whitespace character. Any paragraph is terminated
by the first blank line or block directive.

```
=head1 First level heading block

=head2 Paragraph 1

This is an ordinary paragraph. Its text will be squeezed and
short lines filled. It is terminated by the first blank line.

=head2 Paragraph 2

This is another ordinary paragraph albeit shorter.
```

Alternatively, the `=para` directive can be used to explicitly mark adjacent
lines of text as a paragraph.

```
=head1 First level heading block

=head2 Paragraph 1

=para
This is an ordinary paragraph. Its text will be squeezed and
short lines filled. It is terminated by the first blank line.

=head2 Paragraph 2

=para
This is another ordinary paragraph albeit shorter.
```

### Lists

Unordered lists can be created using the `=item` directive.

```
=item Item
=item Item
=item Another item
```

Sublists are achieved with items at each level specified using the `=item1`,
`=item2`, `=item3`, `...`, `=itemN` etc. directives. The `=item` directive
defaults to `=item1`.

```
=item1 Item one
=item1 Item two
=item1 Item three
    =item2 Sub-item
    =item2 Sub-item
=item1 Item four
```

Definition lists that define terms or commands use the `=defn` directive.
This is equivalent to the `<dl>` element in HTML.

```
=defn Beast of Bodmin
A large feline inhabiting Bodmin Moor.

=defn Morgawr
A sea serpent.

=defn Owlman
A giant owl-like creature.
```

### Code Blocks

A code block is created (which uses the HTML `<code>` element) by starting each
line with one or more whitespace characters.

```
    #`( this is comment )
    my $sum = -> $x, $y { $x + $y }
    say $sum(12, 5);
```

As shown in the [Basic Text Formatting](#basic-text-formatting) section,
inline code can be created using the `C<>` code.

```
In Raku, there are several functions/methods to output text. Some of them
are C<print>, C<put> and C<say>.
```

### Comments

Although Pod blocks are ignored by the Rakudo Raku compiler, everything
identified as a Pod block will be read and interpreted by Pod renderers. In
order to prevent Pod blocks from being rendered by any renderer, use the
`=comment` directive.

```
=comment Add more here about the algorithm.

=comment Pod comments are great for documenting the documentation.
```

To create inline comments, use the `Z<>` code.

```
Pod is awesome Z<Of course it is!>. And Raku too!
```

Given that the Raku interpreter never executes embedded Pod blocks,
comment blocks can also be used as an alternative form of nestable block
comments.

### Links

Creating links in Pod is quite easy and is done by enclosing them in
a `L<>` code. The general format is `L<Label|Url>` with `Label`
being optional.

```
Raku homepage is L<https://raku.org>.
L<Click me!|http://link.org/>.
```

Relative paths work too.

```
L<Go to music|/music/>.
```

Linking to a section in the same document works as well.

```
L<Link to Headings|#Headings>
```

### Tables

The Pod specifications are not completely handled properly yet and this
includes the handling of table. For simplicity's sake, only one way of
constructing tables is shown here. To learn about good practices and see
examples of both good and bad tables, please visit
<https://docs.raku.org/language/tables>.

```
=begin table
Option      | Description     
============|================  
data        | path to data files.
engine      | engine to be used for processing templates.
ext         | extension to be used for dest files.
=end table
```

## Block Structures

As mentioned earlier, Pod documents are specified using directives, which are
used to delimit blocks of textual content and declare optional
[configuration information](#configuration-data). Every directive starts with
an equals sign (`=`) in the first column. The content of a document is
specified within one or more blocks. Every Pod block may be declared in any of
three equivalent forms: delimited style, paragraph style, or abbreviated style.

Up to this point, we have only used the abbreviated style for the block
types (e.g., `=head1`, `=para`, `=comment`, `=item`, etc).

### Abbreviated Blocks

Abbreviated blocks are introduced by an `=` sign in the first column, which
is followed immediately by the `typename` of the block and then the content.
The rest of the line is treated as block data, rather than as configuration.
The content terminates at the next Pod directive or the first blank line
(which is not part of the block data). The general syntax is

```
=BLOCK_TYPE  BLOCK_DATA
```
For example:

```
=head1 Top level heading
```

### Delimited Blocks

Delimited blocks are bounded by `=begin` and `=end` markers, both of which are
followed by a valid Pod identifier, which is the `typename` of the block.
The general syntax is

```
=begin BLOCK_TYPE
BLOCK_DATA
=end BLOCK_TYPE
```

For example:

```
=begin head1
Top level heading
=end head1
```

This type of blocks is useful for creating headings, list items, code blocks,
etc. with multiple paragraphs. For example,

* a multiline item of a list

```
=begin item
This is a paragraph in list item.

This is another paragraph in the same list item.
=end item
```

* a code block

```
=begin code
#`(
A non-efficient recursive implementation of a power function using multi subs.
)

multi pow( Real $base, 0 ) { 1 }

multi pow( Real $base, Int $exp where * ≥ 0) {
	$base * pow($base, $exp - 1)
}

multi pow( Real $base ) {
     pow($base, 2)
}

say pow(3, 0);   #=> 1
say pow(4.2, 2); #=> 17.64
say pow(6);      #=> 36
=end code
```

### Paragraph Blocks

Paragraph blocks are introduced by a `=for` marker and terminated by
the next Pod directive or the first blank line (which is not considered to
be part of the block's contents). The `=for` marker is followed by the
`typename` of the block. The general syntax is

```
=for BLOCK_TYPE
BLOCK DATA
```

For example:

```
=for head1
Top level heading
```

## Configuration Data

Except for abbreviated blocks, both delimited blocks and paragraph
blocks can be supplied with configuration information about their
contents right after the `typename` of the block. Thus the following
are more general syntaxes for these blocks:

* Delimited blocks

```
=begin BLOCK_TYPE OPTIONAL_CONFIG_INFO
=                 ADDITIONAL_CONFIG_INFO
BLOCK_DATA
=end BLOCK_TYPE
```

* Paragraph blocks

```
=for BLOCK_TYPE OPTIONAL_CONFIG_INFO
=               ADDITIONAL_CONFIG_INFO
BLOCK DATA
```

The configuration information is provided in a format akin to the
["colon pair"](https://docs.raku.org/language/glossary#index-entry-Colon_Pair)
syntax in Raku. The following table is a simplified version of the
different ways in which configuration info can be supplied. Please go to
<https://docs.raku.org/language/pod#Configuration_information> for a more
thorough treatment of the subject.

| Value     | Specify with...             | Example                        |
| :-------- | :------                     | :------                        |
| List      | :key($elem1, $elem2, ...)   | :tags('Pod', 'Raku')          |
| Hash      | :key{$key1 => $value1, ...} | :feeds{url => 'raku.org'}     |
| Boolean   | :key/:key(True)             | :skip-test(True)               |
| Boolean   | :!key/:key(False)           | :!skip-test                    |
| String    | :key('string')              | :nonexec-reason('SyntaxError') |
| Int       | :key(2)                     | :post-number(6)                |


### Standard Configuration Options

Pod provides a small number of standard configuration options that can
be applied uniformly to built-in block types. Some of them are:

* `:numbered`

This option specifies that the block is to be numbered. The most common
use of this option is to create numbered headings and ordered lists, but it
can be applied to any block.

For example:

```
=for head1 :numbered
The Problem
=for head1 :numbered
The Solution
=for head2 :numbered
Analysis
=for head3 :numbered
Overview
```

* `:allow`

The value of the `:allow` option must be a list of the (single-letter) names
of one or more formatting codes. Those codes will then remain active inside
the code block. The option is most often used on `=code` blocks to allow
mark-up within those otherwise verbatim blocks, though it can be used in any
block that contains verbatim text.

Given the following snippet:

```
=begin code :allow('B', 'I')
B<sub> greet( $name ) {
    B<say> "Hello, $nameI<!>";
}
=end code
```

we get the following output:

<pre><strong>sub</strong> greet( $name ) {
    <strong>say</strong> &quot;Hello, $name<em>!</em>&quot;;
}
</pre>

This is highly dependent on the format output. For example, while this works
when Pod is converted to HTML, it might not be preserved when converted
to Markdown.

### Block Pre-configuration

The `=config` directive allows you to prespecify standard configuration
information that is applied to every block of a particular type.
The general syntax for configuration directives is:

```
=config BLOCK_TYPE  CONFIG OPTIONS
=                  ADDITIONAL_CONFIG_INFO
```

For example, to specify that every heading level 1 be numbered, bold
and underlined, you preconfigure the `=head1` as follows:

```
=config head1 :formatted('B', 'U') :numbered
```

## Semantic Blocks

All uppercase block typenames are reserved for specifying standard
documentation, publishing, source components, or meta-information.
Some of them are:

```
=NAME
=AUTHOR
=VERSION
=CREATED
=SYNOPSIS
=DESCRIPTION
=USAGE
```

Most of these blocks would typically be used in their full
delimited forms. For example,

```
=NAME B<Doc::Magic>

=begin DESCRIPTION
This module helps you generate documentation automagically.
Not source code needed! Most of it is outsourced from a black hole.
=end DESCRIPTION

=begin SYNOPSIS
=begin code
	use Doc::Magic;

 	my Doc::Magic $doc .= new();

    my $result = $doc.create-documentation($fh);
=end code
=end SYNOPSIS

=AUTHOR Authorius Docus
=VERSION 42
```

## Miscellaneous

### Notes

Notes are rendered as footnotes and created by enclosing a note in a
`N<>` code.

```
In addition, the language is also multi-paradigmatic N<According to Wikipedia,
this means that it supports procedural, object-oriented, and functional
programming.>
```

### Keyboard Input

To flag text as keyboard input enclose it in a `K<>` code.

```
Enter your name K<John Doe>
```

### Terminal Output

To flag text as terminal output enclose it in `T<>` code.

```
Hello, T<John Doe>
```

### Unicode

To include Unicode code points or HTML5 character references in
a Pod document, enclose them in a `E<>` code.

For example:

```
Raku makes considerable use of the E<171> and E<187> characters.
Raku makes considerable use of the E<laquo> and E<raquo> characters.
```

is rendered as:

Raku makes considerable use of the « and » characters.
Raku makes considerable use of the « and » characters.

## Rendering Pod

To generate any output (i.e., Markdown, HTML, Text, etc.), you need to
have the Rakudo Raku compiler installed. In addition, you must install
a module (e.g., `Pod::To::Markdown`, `Pod::To::HTML`, `Pod::To::Text`, etc.)
that generates your desired output from Pod.

For instructions about installing Rakudo for running raku programs,
[look here](https://raku.org/downloads/).

Run the following command to generate a certain output:

```
raku --doc=TARGET input.pod6 > output.html
```

with `TARGET` being `Markdown`, `HTML`, `Text`, etc. Thus to generate
Markdown from Pod, run this:

```
raku --doc=Markdown input.pod6 > output.html
```

## Accessing Pod

In order to access Pod documentation from within a Raku program,
it is required to use the special `=` twigil (e.g., `$=pod`, `$=SYNOPSIS`,etc).

The `$=` construct provides the introspection over the Pod structure,
producing a `Pod::Block` tree root from which it is possible to access
the whole structure of the Pod document.

If we place the following piece of Raku code and the Pod documentation
in the section [Semantic blocks](#semantic-blocks) in the same file:

```
my %used-directives;
for $=pod -> $pod-item {
    for $pod-item.contents -> $pod-block {
        next unless $pod-block ~~ Pod::Block::Named;
        %used-directives{$pod-block.name} = True;
    }
}

say %used-directives.keys.join("\n");
```

we get the following output:

```
SYNOPSIS
NAME
VERSION
AUTHOR
DESCRIPTION
```

## Additional Information

* <https://docs.raku.org/language/pod> for the Pod documentation.
* <https://docs.raku.org/language/tables> for advices about Pod tables.
* <https://design.raku.org/S26.html> for the Pod specification.