RakuDoc revision open to comment
Tags: rakulang, documentation, rakudoc
Published: 2023-07-31 23:00:00

The second stage in the process to update RakuDoc is now over and the third (GAMMA review) stage is starting. In order not to repeat some history, please take a look at [Revising Rakudoc](https://dev.to/finanalyst/revising-rakudoc-29d4).

An online version is available of [the proposed RakuDoc language](https://new-raku.finanalyst.org/language/rakudoc).

The whole of [the Raku documentation suite](docs.raku.org) is written in RakuDoc.

## Improving on a good design

About half of the original design ideas outlined in [S26](https://design.raku.org/S26.html) were documented in [current POD6](https://docs.raku.org/language/pod). Some of the ideas were available, but not documented. Some instructions were not realised at all. 

It should be remembered that RakuDoc is parsed by the compiler (eg. Rakudo) as part of a Raku program, and is then rendered by the renderer (eg. `Raku::Pod::Render`) into (for example) HTML. When I use the word 'implemented', I mean that a RakuDoc instruction is properly parsed and rendered. Some of the instructions defined in S26 were parsed by Rakudo, but ***not rendered***, and some were ***not parsed*** properly or at all, so could not be rendered. 

The revision process has therefore identified and rectified the parsing deficiencies, and identified the rendering flaws. RakuDoc is correctly parsed only on the most recent versions of Rakudo, which at the time of writing has yet to be released. `Raku::Pod::Render` still does not handle RakuDoc in its entirety.  

## Two use cases
It became clear that the RakuDoc serves two inter-related use cases:
1. Documenting code for developing and maintaining software. 
  - explanations about variables, methods, etc.
  - another program that uses the software as a dependency should be able to access these explanations
  - data which should be included with the software but not be hard coded into it, for example, a unit test needs to populate a data structure with test data.
2. Documenting the software for use by another user.
  - Good documentation should have tutorials, code snippets, headings, Tables of content, etc

## Tables
RakuDoc had a simple table markup, which is very similar to the Markdown syntax. It worked, but the simplicity of the syntax was at the cost of flexibility. 

Looking around at other ways of specifying a table, we identified two paradigms (there may be more), namely the one used by HTML and the one used by the GTK grid widget. Both of them allow for cells that span more than one column or row, and both allow for embedding (eg. a table inside a cell of a table).

After several iterations, a new *procedural* model was created and rendered. The design allows for spanning and embedding, but it also allows an author to specify a table row by row, or column by column, or even using a mixture of both.

An example showing a markup using both rows and columns can be seen in [the online draft](https://new-raku.finanalyst.org/language/rakudoc#Procedural_description_of_tables).

## Semantic blocks

A semantic block is a section of text that should be easily available to another software tool, or can be moved around the final document. 

For example, a section on the authors of a document (including contact or affiliations) is most easily written at the top of the document, but often it is better to place the information towards the bottom of the text. 

This is done by creating a semantic block (simply by making the calling the block in uppercase letters). The block can be hidden from view by adding the metadata option `:hidden`. All the data is placed in a special structure.

The rendered text can be placed in the document later using the `P<>` instruction, or it can be accessed by another tool that may only be wanting the VERSION or LICENSE. 

## More metadata options

One of the strengths of RakuDoc is the ability to add optional metadata to blocks of text.

The new version of the defining document explains this concept in more detail. Metadata options are optional, with reasonable defaults being assumed. This means that a short form of the block is sufficient in most cases.

In the description above, the option `:hidden` was mentioned. Another example, is `:caption`. Suppose you want to write a semantic block called `=AUTHORS` at the start of the document, but you want for it to appear later in the document as `Article authors`, then you could specify it as follows:
```
=for AUTHORS :caption<Article authors> :hidden
A. N. Writer, socMedia nic @psuedonym
M. Z. Orator, socMedia nic @politician

Article text continues

Pages later

P<semantic: AUTHORS>
```
It is possible to include a link `L<for reference see | #A very long title somewhere in the text>` where the text on the right-hand side of the `|` is a heading. However, this can become tiresome if you want to include several links to the same place. 

So, a metadata option `:id` can be included in a heading. This allows you to do the following:
```
=for head3 :id<lnk>
How to correctly link to other places in a manual

Pages of text

Properly linking is important, L<see for example|#lnk>
```

## Doing things in line

RakuDoc has instructions for block level text, such as headings, paragraphs, code. 

Typically blocks will be included in the Table of Contents. 
It also has ***markup*** instructions that work in line, and which do not (typically) affect the ToC. 

For example, a simple markup instruction is `C< text >`, which renders like `text`. I have used the Markdown equivalent here. In RakuDoc, everything between the `C<` and `>` is verbatim and styled differently to normal text, just like the Markdown code quotes. However, RakuDoc also has `V< text >` which treats everything inside the angle brackets as verbatim but does not style it differently.

A new markup instruction in RakuDoc is `M< text | metadata>`. A renderer will place the *text* in the rendered text, but will also provide a mechanism for the user to take the metadata and provide new functionality. For instance, `M< fa-copy | font awesome v5 >` could be interpreted to insert the `font-awesome` icon called `fa-copy` into the text. Or `M< Buy now | PayPal, database-id >` could expose the API for the PayPal payment platform.

## How not to be confusing

RakuDoc is inherently customisable. It is also designed to be output neutral (although at the moment HTML is the most common output form). Semantic blocks can be invented within a document, and a renderer can allow for other user-defined blocks and markup instructions to be created. 

However, RakuDoc is specific about naming rules. A built-in block must be all lower case, and renderers should not allow user-defined blocks to use all lower case. A semantic block is all upper case. And a user-defined block must have at least one upper-case letter and one lower-case letter.

All markup instructions, which are inline instructions, must be a single Unicode character with the property UPPER. Built-in markup instructions are the ASCII characters and `Δ`. All other codes can be used.

The naming rules have been created to ensure that even if a user-defined block or markup becomes popular, it is not a part of the RakuDoc standard. Renderers are only required to implement the RakuDoc standard, and may render other blocks, or not.

## Wrapping up

These are some of the interesting additions to RakuDoc that are being proposed. There are more.

Since the Gamma review stage is now underway, it is almost certain that there may be more changes because the revision is now open to the Raku community for comment and requests. Discussion is open both for the language design and for the explanation of the design. 

As might be admitted, community requests for changes to the overall design will face significant resistance from the main authors in order to maintain backwards compatibility with the previous version of RakuDoc, and the integrity of the underlying paradigms. New block or inline instructions will be more readily considered, but requests for examples, explanation, and greater clarity will be very much appreciated.