=begin rakudoc :kind("Language") :subkind("Language") :category("reference") =TITLE RakuDoc =SUBTITLE A Raku slang for documenting Raku software to aid development and use. =VERSION 2.10.2 RakuDoc is a markup language with simple instructions for simple tasks and more complex structures to suit larger projects. There is a clear distinction between documenting intended to help maintain and develop the software, and the visually presentations needed by a newcomer to understand how to use software. =begin AUTHORS :hidden =item Damian Conway (@thoughtstream) =item Richard Hainsworth (@finanalyst) =item Elizabeth Mattijen (@lizmat) =item Aliaksandr Zahatski (@zag) =end AUTHORS =head1 SYNOPSIS =comment should be a semantic block C<=SYNOPSIS> Consider the two ways in which documentation is used. =head2 Case 1: You are writing internal documentation to aid software design =begin code :allow :lang unit class Beginners; B<#| a variable to hold number of people> has $.participants; B<#| data that is initially provided by default, but will be overwritten> has $.new-participant = $=finish; ... # code B<=finish> default data string for a new participant =end code A RakuDoc compliant editor or Integrated Design Environment will pick up the text following C<#|> and put it into a pop-up menu whenever you select (e.g. by hovering over) a use of C<$.participants>. The C<=finish> statement is the last piece of code. Everything after it is treated as a string and placed in the C<$=finish> variable. There are other possibilities described below. =head2 Case2: You are writing external documentation to accompany some software Consider the following short description: =begin code :lang =begin rakudoc =TITLE Tutorial about Flavorizing =SUBTITLE A short tutorial on Flavorizing your quarks =head1 Starting out In the section you will learn about how to add flavors to quarks produced by the I. It goes without saying that these techniques should B be carried out without a precocious child nearby; they will strain the imagination of an ossified adult. =head2 What is a flavour It is well-known (see the L that quarks N come in six flavors, for example: =item Up =item Bottom =item Charm Z< Lots more text > =end rakudoc =end code To indicate that all of the markup above is not Raku code, it is enclosed in a block labelled I. This is an example of the B form of the B block (so named because it is specified between C<=begin> and C<=end> directives). The C<=TITLE>, C<=SUBTITLE>, and C<=SYNOPSIS> are I containing standard information that can be searched by other tools. For all other purposes, they can be considered to the same as C<=head1> I. A C<=head1> block begins a top-level heading. The C<=head2> is a second level heading. These are examples of the B form of RakuDoc blocks. Any non-empty text lines following a heading specifier are collectively treated as the text of the heading. The C<=item> components are abbreviated blocks with text entries for a list. There is no need to start or stop a list explicitly; the renderer will place each consecutive C<=item> in a list. The first non-C<=item> paragraph or block will end the list. Within the text there are several examples of inline markup instructions, which have the form R B<< < >> B<< > >>. In the example above, we used: C. These are for Important, Basis, Note (a footnote), Link, and Zero (a comment) markup. =head1 Introduction RakuDoc has a variety of B that allow for rich structured documents, provide markup hints to renderers without assuming an output format, extract information from compiled programs, provide information to programs, and enable custom developer extensions. This document describes a revision of RakuDoc modifying the original speculation L that was implemented as Raku was developed. RakuDoc is intended to be backwards compatible with the POD6 markup language based on S26. RakuDoc is extensible and renderers are free to provide extra functionality beyond the minimum set of instructions described here. The markup language is called B with the I spelling in order to highlight both the I and I parts for a newcomer. Some authors may prefer B with I spelling, which is considered a possible but non-canonical variant. The file extension for a file containing RakuDoc source is B<.rakudoc>. =begin nested As it will become apparent, whitespace and indentation plays an important role in RakuDoc. There are L; no equivalence is made between them by Rakudo. For example, tabs and spaces are treated as two separate horizontal whitespace characters, with no assumption that a tab is equivalents, say to four (or 2, 8, etc as per style manual) spaces. Consequently, mixing spaces and tabs may B to create the same visual margin in some editor, but they may be B as different margins when parsing RakuDoc. It is recommended that RakuDoc authors choose a single whitespace character (eg, tab or space) for margin alignment. =end nested =head1 Two use cases for RakuDoc RakuDoc can be thought of as having components that are closely connected to a program or module that is being documented (D), and components that can be used for text-oriented documents, such as the source for a webpage or a book (D). Code-oriented RakuDoc is expected to be "consumed" by users in an editor or Integrated Design Environment (IDE), while text-oriented RakuDoc is consumed in some rendered version, such as an HTML web page, a command-line manpage, or a chapter in an e-book. When RakuDoc components are viewed in an editor or IDE to provide information about variables, methods, roles, classes and the like, the information could be made available in a pop-up whenever a documented term is selected in some way (e.g. hovering a mouse over it). In the editor context, RakuDoc blocks and markup should then be treated as a comment to the code. Editors are not expected to render the RakuDoc other than to show the RakuDoc components verbatim, but may do so if it seems expedient. When RakuDoc components are viewed in a rendered version (for example, as HTML), components related to a running program should be ignored. Within the body of a program there may be several sections of code, which is called the D, interleaved between sections of RakuDoc. Sections of code that are intended to be examples within the documentation (i.e. code that is not actual interleaved executable code) can be specified in C<=code> blocks, which are treated as integral parts of the RakuDoc, not as source code in ambient context. Consider a source file containing the definition of a class. When the file is edited in an IDE (e.g. the class is being developed or maintained) the code-oriented RakuDoc is useful to help the developer understand the internal structure and function of specific elements within the code. Furthermore, when the class is imported into another Raku program the IDE will be able to access the information in declarator blocks attached to specific terms, without needing the source code to be available. However, by including text-oriented RakuDoc in the same file, end-user documentation can be provided for the class within the same source file. By passing the source through a renderer, a documentation file (e.g. a README.md file for a github repo) can be generated. This document describes the minimum version of RakuDoc that a renderer or editor must recognise along with some expected rendering behaviors for text-oriented renderers. I<"Expected behaviors"> means that a renderer should approximate the behavior as far as possible given the limitations of the output format, and that the approximation should be a reasonable interpretation of the standard described here. The RakuDoc design assumes certain types of customisability, such as the ability to define new blocks or markup instructions. In order to access blocks or functionality not described in this document, the file containing such RakuDoc instructions should contain a C statement that loads a module that provides the information needed to render the extensions. The information provided by this module may be renderer-specific. =head1 Components RakuDoc has four main types of components, which are distinguished by their scope and by effect they have on other components. =defn Directives Directives define how blocks work. Directives have a similar syntax to regular blocks, but they actually operate on other blocks. New directives cannot be defined. Directives specify B rather than content. =defn Blocks Blocks define complete text components, such as a new paragraph or a code sample or a table. New kinds of blocks can be defined. Blocks contain B which is to be directly rendered in some way. =defn Markup instructions Markup instructions typically define inline items embedded within a block. Some markup instructions only affect the visual rendering of their contents. Others may have side-effects (such as including items into an index or glossary). New markup instructions can be defined. =defn Metadata options Options provide information to a block. They may produce side-effects or alter the way a block should be rendered. A document writer can associate any metadata option with any block or directive. A renderer is only required to comply with those listed in this document. =head2 Directive syntax These are the syntax forms for each directive. The C<=> of each directive must be the first non-whitespace character on a given line. =item B<=begin> specifies the start of a delimited block =item B<=end> specifies the end of a delimited block =item B<=for> specifies the start of an extended block =item B<=finish> ends ambient code and is followed by text =begin item B<=alias> specifies a text substitution available in subsequent C> markup instructions. The general syntax for an alias directive is: =begin code :lang =alias ALIAS_NAME Text for substitution = Optional extra text =end code =end item =begin item B<=config> specifies default options to be applied to specific types of blocks or markup instructions within the remainder of the current block-scope. These default options apply from immediately after the C<=config> directive up to the end of the innermost surrounding block. The general syntax for configuration directives is: =begin code :allow< R > :lang =config R R = R =end code If the block-type is single uppercase character R, the C<=config> directive applies the specified configuration options to the R markup instruction. For example: =for code :allow :lang V<=>config B :allow This configures the C> markup instruction to recognize nested C> and C> markup instructions (both of which would otherwise be treated as verbatim within a C> instruction). To avoid ambiguities L are applied to blocks and markup instructions. =end item =begin item B<=place> specifies a source of information that is to be placed in the current block. The general syntax of B<=place> is =begin code :lang :allow =place R R = R =end code =end item =head2 Block syntax Even though visually similar in some contexts, a block is not a directive...nor vice versa. Blocks may be specified in three ways: =begin item B A D starts with the directive C<=begin> as the first non-whitespace on a line, followed by a valid Raku identifier indicating the name of the block, followed optionally by metadata (see "Metadata" below), followed by content lines. A delimited block is only terminated by an C<=end> directive followed by the same block name. A delimited block that is not terminated by an C<=end same-block-name> instruction throws an error. For example, to specify a C block in delimited form: =begin code :lang =begin para :meta This text is the content of the block. The preceding blank line is also a part of the block, as are these two non-blank lines. =end para =end code The general syntax is: =begin code :lang :allow =begin R R = R R =end R =end code =end item =begin item B An D begins with the directive C<=for> as the first non-whitespace on a line, followed by the name of the block, followed by optional metadata. The next non-blank lines after the metadata specify the content of the block, which is terminated either by the first entirely blank line after the content or by the first line that begins with a RakuDoc directive. For example, to specify a C block in extended format: =begin code :lang =for para :meta This text is the content of the block. This text is NOT content of the block. After a blank line, a new block is started. =end code The general syntax is: =begin code :lang :allow =for R R = R R =end code =end item =begin item B In an D, the name of the block immediately follows an C<=> sign, which must be the first non-whitespace character on the line. Everything after the block name (up to the first blank line or directive line) is considered the content of the block. For example, to specify a C block in abbreviated form: =begin code :lang =para This text is the content of the block. This text is NOT content of the block. After a blank line, a new block is started. =end code Note that abbreviated blocks cannot be specified with metadata. Any apparent metadata elements placed after an abbreviated block name are instead considered to be part of the block contents. Where an extended or abbreviated block uses a blank line as the block terminator, the blank line is not included as part of the content of the block. All subsequent whitespace, whether horizontal or vertical (spaces, tabs, new lines), is ignored. Note that horizontal and vertical whitespace can be included inside a delimited block, and may be significant (eg, Verbatim blocks). =end item =head2 Markup instruction syntax The general syntax of a markup instruction is =for code :lang | =begin item B«» This is a single uppercase letter, or a unicode entity with the UPPER property =end item =begin item B«» This is either one-or-more C«<» characters or a single C<«> character (i.e. The Unicode entity C«E<0x00AB>») =end item =begin item B«» This is a string that does not contain the C<|> character (i.e. Unicode entity C«E<0x007C>»), unless that character is inside a nested markup instruction. =end item =begin item B«» Is a list of strings separated by C<,> or C<;>, depending on the semantics imposed by the =end item =begin item B«» Is one-or-more C«>» or a single C<»> (i.e. Unicode entity C«E<0x00BB>»). The closing marker must be symmetrical with the markup instruction's opening marker. That is, it must consist of the same number of C«>» or C<»> as there were C«<» or C<«> in the opening marker. =end item For example: =begin code :allow :lang This is B> text, and this is B>. And this is a B>. =end code Which would be rendered as: =begin nested For example: This is U text, and this is I. And this is a L. =end nested =head2 Metadata syntax Metadata is specified using a Raku option pair, where the value portion is always parsed using Raku semantics. The following table contains some typical examples. =begin table :!toc :caption('') Value is... Specify with... =============== =================== True :key False :!key Literal :key List :key("foo", 42) Hash :key{ :note('Rosebud, they said'), :emphasize } =end table Numerical values can be specified in any Raku-compatible format (42, 42.0, 42e0, 0x2a, 0d42, 0o52, 0b101010). Strings can either be specified using single or double quotes, or angle brackets (C<'foo'>, C<"bar">, C< >). Note that if a string with whitespace is specified in angle brackets, it is in fact a list of strings: C<< >> is the same as C< ('foo','bar','baz') >. Within the context of the parser of the Raku Programming Language, it is also possible to refer to any compile-time value inside the meta-data. Requiring Raku semantics for the value component of a metadata option means that for compliance to this specification, RakuDoc markup is prohibited within a metadata option. For example, C< :bullet( E ) > is prohibited. However, Raku has a syntax for Unicode characters, so C< :bullet«\c[BALLOT BOX WITH CHECK]» > is possible. Note the C< «...» > syntax which stringifies the contents with interpolation. A renderer may provide a mechanism for allowing RakuDoc within a metadata option but the value part must still conform to Raku semantics, for example, :caption('This is a heading with I in it') The outer single quotes ensures that the parser passes a plain string to the renderer, which may then post-process the string. The metadata of an extended block or abbreviated block may extend beyond the first line declaring the block. Each subsequent line must start with an C<=> in the first virtual column, meaning that it must vertically align with the C<=> of the RakuDoc block declaration, and it must be followed by at least one horizontal whitespace character. For example: =begin code :lang =for head1 :a-first-line-key :another-first-line-key = :a-second-line-key(42) = :a-third-line-key Content for the header block =end code =head1 Directives Directives are similar in form to I instructions, but they do not have the extended or delimited forms. If a directive name is preceded by a C<=begin>, C<=for> or C<=end>, then an error will be thrown. =head2 Aliases The C<=alias> directive provides a way to define block-scoped synonyms for longer RakuDoc sequences, (meta)object declarators from the code, or even entire chunks of ambient source. These synonyms can then be inserted into subsequent RakuDoc using the L formatting code>|#Alias placements>. An C<=alias> is scoped from immediately after its declaration up to the end of the innermost surrounding RakuDoc block. The alias directive takes two arguments. The first is an identifier (which is usually specified in uppercase, though this is not mandatory). The second argument consists of one or more lines of replacement text. Each C<=alias> directive creates a block-scoped RakuDoc macro that can be invoked during document generation by placing the identifier (i.e. the first argument of the alias) in an C> formatting code. This formatting code is then replaced by the text returned by the new macro. The replacement text returned by the alias macro begins at the first non-whitespace character after the alias's identifier, and continues to the end of the line. You can extend the replacement text over multiple lines by starting the following line(s) with an C<=> (at the same level of indentation as the C<=alias> directive itself) followed by at least one whitespace. Each additional line of replacement text uses the original line's (virtual) left margin, as specified by the indentation of the replacement text on the C<=alias> line. For example: =begin code :lang =alias PROGNAME Earl Irradiatem Evermore =alias VENDOR 4D Kingdoms =alias TERMS_URLS =item L = =item L = =item L The use of A is subject to the terms and conditions laid out by A, as specified at: A =end code This would produce: =begin nested =alias PROGNAME Earl Irradiatem Evermore =alias VENDOR 4D Kingdoms =alias TERMS_URLS =item L = =item L = =item L The use of A is subject to the terms and conditions laid out by A, as specified at: A =end nested The advantage of using aliases is, obviously, that the same alias can be reused in multiple places in the documentation. Then, if the replacement text ever has to be changed, it need only be modified in a single place: =begin code :lang =alias PROGNAME Count Krunchem Constantly =alias VENDOR Last Chance Receivers Intl =alias TERMS_URLS L =end code Alias placement codes may also specify a default display text, before the alias name and separated from it by a C<|>. When a display is specified, it will be used if the requested alias cannot be found (and an I<"unknown alias"> warning will be issued in that case): =begin code :lang :allow The use of A SOFTWARE> is subject to the terms and conditions laid out by A COMPANY>, as specified at: A OURTERMS> =end code produces ... =begin nested The use of A is subject to the terms and conditions laid out by A, as specified at: A<(Please visit our website) | OURTERMS> =end nested Furthermore, since none of the aliases were specified in this document, error messages will be produced by the renderer (perhaps at the end of the rendered page). =head2 Block specifiers The C<=begin>, C<=end>, and C<=for> directives all specify types of blocks. They have already been illustrated in multiple examples and will not be described further here. =head2 Config All block forms can be associated with metadata options. Typically the metadata are specified for a block using the B or B forms. If the same option needs to be added to multiple blocks, this can be done using a C directive, and then the B block form can be used in the L. For example, suppose we want all C<=code> blocks to be labeled with a `:delta` within some section of a document (L). Rather than add a C<:delta> modifier to every individual C<=code>, we could configure every V<=code> block to be automatically given the same developer note, like so: =begin code :allow< B V > :lang B<config code :delta(v2.3.2+, 'oFun enhancements') >> =code method droll { say 'what a cool operator' } =code method drool { say 'what a slob' } =code method drill { say 'keep up' } =end code Within the same block scope, eg., between C<=begin section> and C<=end section> instructions, one or more C<=config> directives can be specified to define the default behaviour of specific block types. Successive C<=config> directives within the same scope are cumulative in effect. Because C<=config> directives specify I behaviours, whenever a particular kind of metadata is explicitly specified for an instance of that block type, that option overrides the defaults set by any active C<=config> blocks. For example: =begin code :allow B<=config item1 :bullet« \c[Earth Globe Europe-Africa] » > B<=config item2 :bullet« \c[Hand with Index and Middle Fingers Crossed] » > =comment In the following list, =item1 and =item2 will now have non-standard bullets The major sources of sustainable energy are: =item1 geothermal =item1 fusion =item2 (eventually) =begin section B<=config item1 :toc :headerlevel(2)> =comment The following items still have non-standard bullets but now they will also be added to the table of contents as if they were =head2 blocks Important items are: =item1 small scale fusion =item1 room temperature superconductors =end section =comment The following list items will NOT be added to the Table of Contents because the section containing that particular =config has now ended. They will still have the non-standard Earth bullets though, because those two =config directives are still in scope. =item1 matter-antimatter annihilation =item1 zero-point energy =end code When an option needs to be associated with all blocks, the config statement may take a whatever C<*> instead of a specific block name, like so: =begin code :lang =config * :!error =end code This particular example signals to the renderer that no warning messages should be issued if errors are encountered by I block type in the current block scope. The general principle is that more block-specific configurations of metadata take precedence over more generic configurations. For example, suppose in the same block scope, we have: =begin code :lang =config * :!error =config item :error =for item :!error Item 1 =for item Item 2 =for numitem Item 3 =end code Then the configuration would applied in the following order: =numitem V<=>for item V<:!error> (specific metadata applied to a specific block) =numitem V<=config item :error> (default metadata applied to a specific kind of block) =numitem V<=config * :!error> (default metadata applied to any kind of block) Which means that I would never generate a warning (because its C block is specifically configured not to do so), while I could generate warnings (because C blocks are generically configured to do so), and I would never never generate a warning (because generic blocks are generically configured not to do so). There is more discussion of C<=config> in the context of L. =head2 Document termination The C<=finish> directive indicates the end of all ambient contexts within the document. This means that the parser will treat all the remaining text in the file as a string. Any text after the C<=finish> block can be accessed as a string within the program (i.e. the ambient code) via the C<$=finish> variable. This can be used to provide data to a program, such as a test. =begin code :allow< V B > :lang use JSON::Fast; my %h = from-json( B<$=finish> ); say %h.raku; # more lines of code Bfinish { "key1": "a string value", "key2": "another value" }> =end code This will generate the following output: =begin code :lang {:key1("a string value"), :key2("another value")} =end code =head2 Table constructors The C<=row> and C<=column> instructions are directives, not blocks, and they are described in more detail in the section on the L block|#Procedural description of tables>. =head2 Placement from external sources The C<=place> instruction is a directive that tells the renderer to obtain text, information, or an object from another source. The rendered version of the data placed in the text is considered to form its own block scope. An in-line version of C<=place> is C>, which is described in more detail in the section on markup codes. The schema of the URL specified in a C<=place> directive specifies where to look for the external content: =begin table :!toc :caption('') | Schema | Where to look for the resource | |=============|=================================================| | C | Look on the web | | C | Look on the local filesystem | | C | Look in the usual places for Raku documentation | | C | Look via a local man(1) | | C | Look in the current document | =end table Meanwhile, the kind of content being placed is inferred from the final extension of the URL. For example: =begin table :!toc :caption('') | Extension | How to treat the contents | |=============|==================================| | C<.txt> | Render the contents as plaintext | | C<.rakudoc> | Render the contents as RakuDoc | | C<.html> | Render the contents as XHTML | | C<.md> | Render the contents as Markdown | | C<.json> | Render the contents as JSON | | C<.jpg> | Render the contents as an image | | C<.mp4> | Render the contents as a video | =end table Renderers are not required to render anything other than plaintext and RakuDoc, but may also support other formats if they wish. In the case where a URL does not end in a recognized extension: =begin code :lang =place https://example.org/landingpage =place rakudoc:App::Rak =place file:/usr/share/legal/std_disclaimer =end code ...then the type of content (and hence rendering) may be inferred from the schema: =begin table :!toc :caption('') | Schema | Inferred content type if no final extension | |=============|=============================================| | C | XHTML | | C | plaintext | | C | RakuDoc | =end table A B<=place> directive may be accompanied by metadata options to ensure that a reference can be made in the Table of Contents, or to provide an ALT text. For example: =begin code :lang =place https://raku.org/camelia-logo.png :caption :alt =end code will produce ... =place https://raku.org/camelia-logo.png :caption :alt =head1 Code-oriented RakuDoc The following RakuDoc components are primarily intended for use when editing within an editor. Standalone renderers may ignore them. X<|Syntax,#|>X<|Syntax,#=> =head2 Declarator blocks Declarator blocks differ from other blocks in that they do not have a specific type. Instead, they are attached to a particular element of the ambient source code. Declarator blocks are introduced by a special comment: either C<#|> or C<#=>, which must be immediately followed by either a space or an opening bracket character, such as a curly brace C<{>, C<(> or C<«>. If followed by a space, the block is terminated by the end of line; if followed by one or more opening bracket character, the block may extend over multiple lines and is terminated by the matching sequence of closing bracket characters. RakuDoc markup instructions may be used inside declarator blocks. Blocks starting with C<#|> are attached to the code after them, and blocks starting with C<#=> are attached to the code before them. Since declarator blocks are attached to source code, they can be used to document classes, roles, subroutines and in general any statement or block. The C method can be used on these classes, roles, subroutines, etc. to return the attached RakuDoc value. For example: =begin code :lang #| Base class for magicians class Magician { has Int $.level; has Str @.spells; } #| Fight mechanics sub duel( #= Magicians only, no mortals. Magician $a, #= first magician Magician $b, #= second magician ) { } say Magician.WHY; # OUTPUT: «Base class for magicians␤» say &duel.WHY.leading; # OUTPUT: «Fight mechanics␤» say &duel.WHY.trailing; # OUTPUT: «Magicians only, no mortals.␤» say &duel.signature.params[0].WHY; # OUTPUT: «first magician␤» say &duel.signature.params[1].WHY; # OUTPUT: «second magician␤» =end code These declarations can extend to several lines. For example: =begin code :lang #|( This is an example of stringification: * Numbers turn into strings * Regexes operate on said strings * C topicalizes and places result into $_ ) sub search-in-seq #=« Uses * topic * decont operator » ( Int $end, Int $number ) { with (^$end).grep( /^$number/ ) { .say for $_<>; } } =end code A useful idiom is to place trailing declarator blocks on the parameters of the MAIN sub. These comments will be picked up automatically by USAGE. =begin code :lang sub MAIN( Str $first, #= the first CLI parameter Int :$verbose, #= an integer to indicate output, 0 = no output ) =end code =head2 Data blocks C<=data> blocks are used to specify named and/or ordered chunks of data for the ambient code. They may appear anywhere within a source file, and as many times as required. The corresponding variable, C<$=data> holds an object that does both the Associative and Positional roles. Each C<=data> block can be given a C<:key> option, to name it. The contents of any C<=data> block with a key are accessible (as a single string) via the Associative aspect of C<$=data> object. For example: =begin code =begin data :key Laziness Impatience Hubris =end data say 'The three virtues are:'; say $=data; =end code The contents of any C<=data> block that does not have a C<:key> are accessible (as a single string) via the Positional aspect of C<$=data>. Unkeyed C<=data> blocks are stored in the same order they appear in the file. For example: =begin code :lang say 'The second anti-virtue is: ', $=data[1]; =data Industry =data Patience =data Humility =end code Note that, as the preceding example illustrates, because RakuDoc is a compile-time phenomenon, it is possible to specify C<=data> blocks I the point in the source where their contents will be used (provided they're not being used in a C, of course). When C<$=data> itself is stringified, it returns the concatenation of all the unkeyed C<=data> blocks the parser has seen. C<=data> blocks are never rendered by the text-oriented RakuDoc renderers. =head1 Text-oriented RakuDoc The RakuDoc instructions in this section are primarily intended for text-oriented rendering. However, text-oriented and code-oriented RakuDoc can be freely intermixed with Raku code in a single file; this may help to create code that is well-documented. When a Raku compiler parses a file, line contents are expected to be Raku code (ambient text). When a RakuDoc block is finished, the next line is assumed to revert to ambient text. =begin code :lang #start of file my $text; # ambient code =head this is some text this line continues the header #this line is now ambient code and so must be specified as a comment =end code A C block reverses this assumption. =begin code :lang #start of file my $text; # ambient code =begin rakudoc =head this is some text this line continues the header this line is not ambient code and so it will be treated as an ordinary paragraph =end rakudoc # this line is now ambient code =end code Files that are intended to contain text-oriented documentation alone should be entirely enclosed in a C block. However, files whose filename ends in a C<.rakudoc> extension are always presumed to contain only text-oriented documentation, and any renderer must always treat the file's contents as being enclosed in an implicit C<=begin rakudoc>...C<=end rakudoc>, unless those contents are already explicitly enclosed in a C block. Historically the name C was used for this functionality. For compatibility it will still be possible to use the name C instead of C in the foreseeable future. Note however that the Raku Programming Language may assign slightly different semantics to C at some time in the future. =head2 Headings Headings can be defined using C<=headN>, where R is greater than zero (e.g. C<=head1>, C<=head2>, etc.). C<=head> is an alias for C<=head1>. =begin code :lang =head1 A top level heading =head2 A second level heading =head3 A third level heading =end code =head3 Numbered headings You can specify that a heading is numbered using the C<=numhead> block. For example: =begin code :lang =numhead1 The Problem =numhead1 The Solution =numhead2 Analysis =head3 Overview =head3 Details =numhead2 Design =numhead1 The Implementation =end code which would produce: =begin code :lang 1. The Problem 2. The Solution 2.1. Analysis Overview Details 2.2. Design 3. The Implementation =end code A document has an I for every heading, but only the C<=numheadN> block makes the numeration visible in the heading and in the Table of Contents. Note that, even though renderers are not required to distinctly render more than the first four levels of heading, they are required to correctly honour arbitrarily nested numberings. That is: =begin code :lang =numhead6 The Rescue of the Kobayashi Maru =end code should produce something like: =begin code :lang 2.3.8.6.1.9. The Rescue of the Kobayashi Maru =end code =head2 Block scope A block scope is important for the C<=config> and C<=alias> directives. In addition, some renderers may generate secondary pages from primary source files, for example, gathering together the same method names in multiple classes. It is desirable for all the relevant blocks to be gathered together. =head3 Sections The C
block will typically only be used in the delimited form so that the document writer can define an explicit block scope. The C<=begin section> declaration starts a new block scope, and the C<=end section> returns the scope to the previous one. Unlike an C<=end rakudoc>, an C<=end section> does not always change the scope back to ambient code. It only does so when its corresponding C<=begin section> changed the scope I ambient code. In contrast, an C<=end rakudoc> always reverts to ambient code. Sections may be embedded within other sections. When a C<=begin section> is not present, a renderer may apply the following heuristic to determine the block scope (assuming X, Y, and Z are digits such that C«0 < X < Y < Z »): =item A C<=headY> declaration starts a new block scope. =item The next C<=headY> declaration ends the block scope of the previous C<=headY> =item A C<=headZ> declaration following a C<=headY> is within the block scope of the preceding C<=headY> declaration, and does not end it. =item A C<=headX> declaration ends the scope of any preceding C<=headY> and C<=headZ> declarations. Note that a C<=begin section> declaration overrides the heuristic, meaning that multiple C<=headX> declarations can be placed within the same block scope. A renderer is not expected to render blocks differently when they are embedded in a C
block. Providing metadata to a C<=begin section> block definition is B the same as declaring metadata using a C<=config> directive. Metadata in a config is provided to all matching blocks in the current block scope. Metadata in the C<=begin section> declaration is only applied to the section itself, not to the blocks it contains. For example, suppose the following RakuDoc text was included in a source file =begin code :lang =begin section :delta(v2.3.2-, 'removed due to conflict with chancellors') =head2 role fool This role is especially important in authoritarian kingdoms to remind kings of their humanity. =end section =end code which might render as: =begin nested =begin section :delta(v2.3.2-, 'removed due to conflict with chancellors') =for head2 :!toc role fool This role is especially important in authoritarian kingdoms to remind kings of their humanity. =end section =end nested If a user indicates to a renderer that they wish to view documentation valid today, which corresponds (for example) to C then, because C is after C, the section above – including the nested C<=head2> block and the following plain paragraph – would not be rendered. If however, a user indicates they wish to view documentation for C, the renderer would render the section above, including an indication the section will be removed in C. =head3 Document scope A C<=begin rakudoc> declaration (or equivalently a C<=begin pod>) also defines a new scope, and also has the effect that code following it is not considered Raku code. An C<=end rakudoc> will return scope to the ambient code. This also means that C blocks cannot be nested, while C
blocks may be nested. The first C<=begin rakudoc> declaration in a document starts the RakuDoc scope of the document. Metadata following the first such declaration are made available to all blocks in the document. =head2 Ordinary paragraphs An ordinary paragraph consists of text that is to be formatted into a document at the current level of nesting, with whitespace squeezed, lines filled, and any special inline mark-up applied. Ordinary paragraphs consist of one or more consecutive lines of text, each of which starts with a non-whitespace character. The paragraph is terminated by the first blank line or directive. For example: =begin code :lang =head1 This is a heading block This is an ordinary paragraph. Its text will be squeezed and short lines filled. It is terminated by the first blank line. This is another ordinary paragraph. Its text will also be squeezed and short lines filled. It is terminated by the trailing directive on the next line. =head2 This is another heading block This is yet another ordinary paragraph, at the first virtual column set by the previous directive =end code Ordinary paragraphs do not require an explicit marker or delimiters (within a C block). Alternatively, there is also an explicit C<=para> marker that can be used to explicitly mark a paragraph, which would be necessary outside a C block. =begin code :lang =para This is an ordinary paragraph. Its text will be squeezed and short lines filled. =end code This is rendered as: =para This is an ordinary paragraph. Its text will be squeezed and short lines filled. In addition, the longer C<=begin para> and C<=end para> form can be used. For example: =begin code :lang =begin para This is an ordinary paragraph. Its text will be squeezed and short lines filled. This is still part of the same paragraph, which continues until an... =end para =end code As demonstrated by the previous example, within a delimited C<=begin para> and C<=end para> block, any blank lines are preserved. =head2 Nesting or indenting a block RakuDoc provides a C<=nested> block that marks all its contents as being nested: =begin code :lang =begin nested We are all of us in the gutter, but some of us are looking at the stars! =begin nested -- Oscar Wilde =end nested =end nested =end code ...which would produce: =begin nested We are all of us in the gutter, but some of us are looking at the stars! =begin nested -- Oscar Wilde =end nested =end nested Nesting blocks can contain any other kind of block, including implicit paragraph and code blocks. Note that the relative physical indentation of the nested blocks plays no role in determining their ultimate indentation in the final rendering. The preceding example could equally have been specified: =begin code :lang =begin nested We are all of us in the gutter, but some of us are looking at the stars! =begin nested -- Oscar Wilde =end nested =end nested =end code =head2 Verbatim blocks Normally a writer does not want to consider the way text flows on a page. They want the end of each line to be treated the same as a space, and for extra spaces to be eliminated. However, the exact placing of whitespace sometimes I important, especially for code. =head3 Code blocks Code blocks are used to specify pre-formatted text (typically source code), which should be rendered without rejustification, without whitespace squeezing, and by default B recognizing any inline markup instructions. Code blocks also have an implicit nesting associated with them. Typically these blocks are used to show examples of code, mark-up, data formats, or other textual specifications. They are usually rendered using a fixed-width font. A code block may be implicitly specified as one or more lines of text, each of which starts with a whitespace character at the block's virtual left margin. The implicit code block is then terminated by a blank line or an explicit directive. For example: =begin code :lang This ordinary paragraph introduces a code block: $this = 1 * code('block'); $which.is_specified(:by); =end code Implicit code blocks may be used L. There is also an explicit C<=code> block (which can be specified within any block type, not just C<=rakudoc>, C<=item>, etc.): =begin code :lang The C subroutine adds feedback: =begin code sub loud_update ($who, $status) { say "$who -> $status"; silent_update($who, $status); } =end code =end code As the previous example demonstrates, within an explicit C<=code> block the code does not have to be indented; it can start at the (virtual) left margin. Furthermore, lines that start with whitespace characters after that margin have subsequent whitespace preserved exactly (in addition to the implicit nesting of the code). Explicit C<=code> blocks may also contain empty lines. =head5 Preprocessing and postprocessing of code The code in a document is almost always related to a specific programming language, by default Raku. But examples of Ruby, C, RakuDoc, or other languages may also appear in the Raku documentation sources. A renderer may apply language specific syntax highlighting to the contents of a code block according to the following rules: =item C<=code> blocks with no explicit or preconfigured C<:lang> option default to C<:lang>. =item C<=code> blocks can be marked as not being in any specific language by using C<:!lang>. =item Renderers must not syntax-highlight any code block whose C<:lang> value is C, that is C<:!lang>. =item Renderers must not syntax-highlight any code block whose C<:syntax-highlighting> value is C; by default C<:syntax-highlighting> is True. =item Renderers may syntax-highlight any other code block (including C<:lang>), but are not required to do so. By default, a renderer will not change the contents of a code block, but see the caveat when L is used|#Markup within verbatim blocks>. =head3 I/O blocks RakuDoc provides blocks for specifying the input and output of programs. These are similar to C blocks in that they preserve whitespace and are rendered distinctly from regular text paragraphs. The C<=input> block is used to specify pre-formatted keyboard input, which should be rendered without re-justification or squeezing of whitespace. The C<=output> block is used to specify pre-formatted terminal or file output, which should also be rendered without re-justification or whitespace-squeezing. Although they are rendered with verbatim whitespace, like a code block, input and output blocks differ from code blocks in that they do recognize any inline mark-up instructions within their text. For example: =begin code :lang =begin output Name: Baracus, B.A. Rank: Sgt Serial: 1PTDF007 Do you want additional personnel details? K Height: 180cm/5'11" Weight: 104kg/230lb Age: 49 Print? K =end output =end code In this example, the two embedded C> sequences would be recognized as inline mark-up and rendered appropriately (i.e. as keyboard input). =head3 Markup within verbatim blocks Although C<=code> blocks automatically disregard all markup instructions, occasionally you may still need to specify some markup within a code block. For example, you may wish to emphasize a particular keyword in an example (using a C> code). Or you may want to indicate that part of the example is metasyntactic (using the C> code). Or you might need to insert a non-ASCII character (using the C> code). You can specify a list of L markup instructions (B C H I J K N O R S T U V) that should still be recognized within a code block using the C<:allow> option. The value of the C<:allow> option must be a list of the (single-letter) names of one or more markup instructions. Those codes will then remain active inside the code block. For example: =begin code :allow< B V > :lang =begin code B<:allow< B R >> :lang sub demo { V 'Hello R'; I 'The I format is not recognised'; } =end code =end code This would be rendered: =begin code :allow< B R > :lang sub demo { B 'Hello R'; I 'The I format is not recognised'; } =end code It should be noted that both C<:allow> and C<:lang> (if C<:syntax-highlighting> is True) will affect the rendering of the content of the block. This is likely to cause conflicts in some cases. The renderer is free to choose how to resolve such conflicts, e.g. by disregarding the C<:allow> metadata. =head2 Lists Lists in RakuDoc are specified as a series of contiguous C<=item> blocks. No special "container" directives or other list delimiters are required to enclose the entire list. Note that C<=item> is just an abbreviation for C<=item1>. =head3 Unordered lists Lists in RakuDoc are by default unordered. For example: =begin code :lang The three suspects are: =item Happy =item Sleepy =item Grumpy =end code This produces: =begin nested The three suspects are: =item Happy =item Sleepy =item Grumpy =end nested By default, a compliant renderer will provide a bullet for each item. RakuDoc also allows for custom bullets as L. =head3 Multi-level lists Lists may be multi-level, with items at each level specified using the C<=item1>, C<=item2>, C<=item3>, etc. blocks. (The indentation depends on the rendering engine and does not need to be included in the RakuDoc markup.) Up to four levels are normally differentiated. For example: =begin code :lang =item1 Animal =item2 Vertebrate =item3 Mammals =item4 Primates =item2 Invertebrate =item1 Phase =item2 Solid =item3 Crystalline =item3 Amorphous =item2 Liquid =item2 Gas =end code This would produce: =item1 Animal =item2 Vertebrate =item3 Mammals =item4 Primates =item2 Invertebrate =item1 Phase =item2 Solid =item3 Crystalline =item3 Amorphous =item2 Liquid =item2 Gas Note, however, that C blocks within the same list are not I nested. That is, lower-level items should not be specified inside higher-level items: =begin code :lang =comment THE WRONG WAY... =begin item1 ───────────────┐ The choices are: | =item2 Liberty ─── Level 2 ├─── Level 1 =item2 Death ─── Level 2 | =item2 Beer ─── Level 2 | =end item1 ───────────────┘ =comment THE CORRECT WAY... =begin item1 ───────────────┐ The choices are: ├─── Level 1 =end item1 ───────────────┘ =item2 Liberty ─────────────────── Level 2 =item2 Death ─────────────────── Level 2 =item2 Beer ─────────────────── Level 2 =end code =head3 Multi-paragraph lists Using the delimited form of the C<=item> block (C<=begin item> and C<=end item>), we can specify items that contain multiple paragraphs. For example: =begin code :lang Let's consider two common proverbs: =begin item I This is a common myth and an unconscionable slur on the Spanish people, the majority of whom are extremely attractive. =end item =begin item I In deciding whether to become an early riser, it is worth considering whether you would actually enjoy annelids for breakfast. =end item As you can see, folk wisdom is often of dubious value. =end code This renders as: =begin nested Let's consider two common proverbs: =begin item I This is a common myth and an unconscionable slur on the Spanish people, the majority of whom are extremely attractive. =end item =begin item I In deciding whether to become an early riser, it is worth considering whether you would actually enjoy annelids for breakfast. =end item As you can see, folk wisdom is often of dubious value. =end nested =head3 Bullets and bullet strategy When rendered, each C<=item>R will be preceded by a bullet and each level may have a different bullet. A compliant renderer will define a I bullet for at least the first four levels within a nested list, with the bulleting strategy for other levels being up to the renderer. The default bullet can be overridden with a custom bullet for any C<=item>R, for example =begin code :lang :allow The project originally consisted of five phases, of which two are already complete and two have been abandoned: =for item B<:bullet« \c[BALLOT BOX WITH CHECK] »> Investigate existing solutions =for item B<:bullet« \c[BALLOT BOX WITH CHECK] »> Define a minimal initial feature set =for item B<:bullet« \c[BALLOT BOX] »> Implement this minimal set of features =for item B<:bullet« \c[BALLOT BOX WITH X] »> Secure 100 million in venture capital =for item B<:bullet« \c[BALLOT BOX WITH X] »> Abscond to the Bahamas with the cash =end code ... would produce something like a list with checkboxes, thus: =begin nested The project originally consisted of five phases, of which two are already complete and two have been abandoned: =for item :bullet« \c[BALLOT BOX WITH CHECK] » Investigate existing solutions =for item :bullet« \c[BALLOT BOX WITH CHECK] » Define a minimal initial feature set =for item :bullet« \c[BALLOT BOX] » Implement this minimal set of features =for item :bullet« \c[BALLOT BOX WITH X] » Secure 100 million in venture capital =for item :bullet« \c[BALLOT BOX WITH X] » Abscond to the Bahamas with the cash =end nested However, more interesting bullets are possible, including multiple characters. For example: =begin code :lang :allow =for item B<:bullet« \c[Heavy Check Mark] »> Investigate existing solutions =for item B<:bullet« \c[Heavy Check Mark] »> Define a minimal initial feature set =for item B<:bullet« \c[Anticlockwise Downwards And Upwards Open Circle Arrows] »> Implement this minimal set of features =for item B<:bullet« \c[prohibited sign] »> Secure 100 million in venture capital =for item B<:bullet« \c[prohibited sign, palm tree] »> Abscond to the Bahamas with the cash =end code ... to produce =begin nested =for item :bullet« \c[Heavy Check Mark] » Investigate existing solutions =for item :bullet« \c[Heavy Check Mark] » Define a minimal initial feature set =for item :bullet« \c[Anticlockwise Downwards And Upwards Open Circle Arrows] » Implement this minimal set of features =for item :bullet« \c[prohibited sign] » Secure 100 million in venture capital =for item :bullet« \c[prohibited sign, palm tree] » Abscond to the Bahamas with the cash =end nested By using the C<=config> directive, it is also possible to change the default bullets for the duration of a section. For example, =begin code :lang :allow =begin section B<=config item1 :bullet« \c[Earth Globe Europe-Africa] » > B<=config item2 :bullet« \c[Hand with Index and Middle Fingers Crossed] » > The major sources of sustainable energy are: =item1 wind =item1 hydroelectric =item1 solar =item1 geothermal =item1 fusion =item2 (eventually) =end section =end code ...which would produce: =begin nested =begin section =config item1 :bullet« \c[Earth Globe Europe-Africa] » =config item2 :bullet« \c[Hand with Index and Middle Fingers Crossed] » The major sources of sustainable energy are: =item1 wind =item1 hydroelectric =item1 solar =item1 geothermal =item1 fusion =item2 (eventually) =end section =end nested In the event that a custom bullet cannot be rendered (e.g. a specified Unicode glyph is unrecognised or unrenderable in the target format), a compliant renderer will fall back to its default bullet and generate an error message. =head3 Ordered lists A C<=numitemN> expresses the I of a list: =begin code :lang =numitem1 Visito =numitem2 Veni =numitem2 Vidi =numitem2 Vici =end code This would produce something like: =begin nested 1. Visito 1.1. Veni 1.2. Vidi 1.3. Vici =end nested The numbering scheme is at the discretion of the renderer. A renderer might, for example, provide a scheme similar to the examples here, and also provide an enhancement, such as C<:html-ordered> that leverages the C«