MarkAPL for Programmers

1. Overview

This document is relevant for APL programmers using MarkAPL within an APL application. If you're using it implicitly, such as editing a Markdown file with Meddy[1], the cheat sheet and MarkAPL reference document should be sufficient.

2. How to

One approach to learn about MarkAPL is to trace through the method MarkAPL.Help.

The MarkAPL project

Alternatively you can explore the test cases named Test_Examples_01 etc. To do that you need to take a copy of the MarkAPL project on GitHub and open it with the project manager Cider which is available as a Tatin package.

]Cider.OpenProject /path/2/MarkAPL-clone
)CS #.MarkAPL.TestCases
Prepare 1
1 T.RunThese 'Examples'

The left argument makes sure that the test suite stops just before a particular test case is executed, allowing you to trace through the test cases.

3. Methods

Note that helpers are discussed separately.

3.1. CompressCSS

Takes CSS — either a text vector or a vector of text vectors — and compresses it to a single line: comments and spaces around ;:{} are removed, TAB characters become spaces, and multiple spaces are reduced to a single one.

Note that this can have disastrous results when performed on invalid CSS. An error is thrown in case the comment markers do not match.

3.2. ConvertMarkdownFile

This method takes a filename as right argument. It expects the file to contain Markdown content.

By default a fully-fledged HTML page is created from that Markdown file with exactly the same filename except that the file extension is .html rather than .md.

However, instead of accepting the default parameters one can create a parameter namespace with:

parms←MarkAPL.CreateParms

and then amend parameters within parms. That parameter space parms then needs to be passed as left argument to the ConvertMarkdownFile method.

Note that when the right argument is not empty then inputFilename must either be empty or identical with it, otherwise an error is signalled. This is because the input file is already defined by the right argument. With an empty right argument the file inputFilename points to is converted.

The shy result is ns.report: a possibly empty list of warnings and error messages.

3.3. CreateParms

This niladic function returns a namespace populated with parameters and their default values.

CreateParms tries to find for every parameter a value from the command line. If it cannot find them it will establish a default value.

The namespace returned by the CreateParms method has a built-in method ∆List which is niladic and will return a matrix with two columns, the parameter name in the first column and the default value in the second column.

Note that a value of ¯1 means that there is not really a default available, but a reasonable value will be determined at a later stage, usually depending on the context.

3.4. CreateHelpParms

This niladic function returns a namespace with parameters with default values. Internally it calls CreateParms and then adds some parameters that are required by the Help and Reference methods.

3.5. Execute

This function is used exclusively by test cases.

3.6. Help

The function lists all HTML files in the folder holding the documentation — that includes “MarkAPL_CheatSheet.html” — and asks you to select one.

It takes a Boolean right argument:

You might specify an optional left argument: a parameter space, typically created by calling the CreateHelpParms method. This allows creating a document with non-default parameters. Of course this has only an effect when the right argument is a 1.

Note that the Markdown files carry several embedded parameters — those cannot be overridden by a parameter namespace unless you assign a 1 to ignoreEmbeddedParms.

In order to enable Help to find the files (in case the defaults don't work) you must create a parameter space and then set homeFolder accordingly.

If you specify a 1 as right argument but Help can only find the HTML file but not the Markdown file it will ignore the right argument and just put the file on display with your default browser.

The shy result is either ⍬ or the ns namespace created by Init and modified by Process.

3.7. History

A variable that holds the version history of MarkAPL: a vector of text vectors in Markdown format.

3.8. Init

Takes a two-item-vector as right argument:

  1. A parameter namespace, typically created by calling CreateParms.
  2. A vector of character vectors: the Markdown.

Returns the “ns” namespace.

Init works on a copy of the parameter namespace: the namespace you pass is left untouched, so you can use it again for another document. The parameters actually used — including any embedded parameters found in the Markdown — are available as ns.parms. Pass ns.parms on to MakeHTML_Doc. (Before version 16.0 Init changed the namespace passed to it.)

Note that after executing Init ns.report might well carry warnings that are misleading. An example for this are links inside a LeanPub block: because the LeanPub stuff is already converted in Init, MarkAPL cannot (yet) judge whether the links are okay or not.

Therefore at the end of converting the full document the warnings are investigated again, and any warnings that are now obsolete are removed.

3.9. MakeHTML_Doc

Takes HTML, typically created by calling Process, and makes it a fully fledged HTML document by adding <body>, <head> — with <title> — and <html> with the DocType.

The left argument is a parameter namespace. If the HTML was created by Init and Process, pass ns.parms, otherwise any embedded parameters (like a title) are not taken into account:

ns←MarkAPL.Init parms markdown
ns←MarkAPL.Process ns
html←ns.parms MarkAPL.MakeHTML_Doc ns.html

Like Init, MakeHTML_Doc leaves the namespace passed to it untouched.

3.10. Markdown2HTML

This ambivalent function requires some Markdown as right argument.

It returns (since version 1.7.0) a two-item vector (shy):

Without an — optional — left argument it creates just the HTML from the Markdown.

However, you can also create a parameter space by calling CreateParms and set outputFilename. In that case it will create a fully-fledged HTML page from the Markdown and write it to that file. The generated page is also returned as result.

Finally one can also set the inputFilename parameter. This is taken into account only when the right argument is empty: it reads the input file, expecting it to be Markdown, creates HTML5 from it and writes it to the output file if there is one. Again the HTML is also returned as result.

Internally it calls Init & Process & MakeHTML_Doc.

Note that in case the parameter createFullHtmlPage is ¯1 (the default value which means “undefined”) the default behaviour of Markdown2HTML is defined by the setting of the parameter outputFilename: if outputFilename is not empty then createFullHtmlPage will default to 1, otherwise to 0, and that's what Markdown2HTML will take into account.

3.11. Process

This function takes — and returns — an ns namespace which was typically created by calling Init.

3.12. Reference

The function takes a Boolean right argument:

You might specify an optional left argument: a parameter space, typically created by calling the CreateHelpParms method. This allows creating a help file with non-default parameters. Of course this has only an effect when the right argument is a 1.

Note that the file “MarkAPL.md” carries several embedded parameters — those cannot be overridden by a parameter namespace unless you assign a 1 to ignoreEmbeddedParms.

In order to enable Reference to find the file “MarkAPL.html” (in case the defaults don't work) you must create a parameter space and then set homeFolder.

If you specify a 1 as right argument but Reference can only find the HTML file but not the Markdown file it will ignore the right argument and just put the file on display with your default browser.

The shy result is either ⍬ or the ns namespace created by Init and modified by Process.

3.13. Version

Returns the version number of MarkAPL including the build-ID, for example 16.0.0+376, or an empty vector in case MarkAPL was not loaded by Tatin.

4. Parameters

In order to specify parameters execute this:

      parms←MarkAPL.CreateParms

parms is a namespace that contains all variables that can be used.

You can list them with their default values:

      parms.∆List
 bookmarkLink                                                     6
 bookmarkMayStartWithDigit                                        1
 charset                                                      utf-8
 checkFootnotes                               ⍝ defaults to "debug"
 checkLinks                                   ⍝ defaults to "debug"
 compressCSS                                                      1
 copiedCaption                                                    ✓
 copy2ClipboardBtn                                                1
 copyCaption                                              <svg ...>
 createFullHtmlPage                                              ¯1
 cssURL                                                      [Null]
 debug                                  ⍝ 0 in Runtime, 1 otherwise
 div_h_tag                                                        1
 enforceEdge                                                      1
 footnotesCaption                                         Footnotes
 head
 homeFolder                                  ⍝ '' or TatinVars.HOME
 ignoreEmbeddedParms                                              0
 imageURL
 inputFilename
 javaScript                                                       1
 lang                                                            en
 leanpubExtensions                                                0
 lineNumberOffset                                                 0
 linkToCSS                                                        0
 lowercaseID                                                      1
 markdownStrict                                                   0
 noCSS                                                            0
 numberHeaders                                                    0
 outputFilename
 printCSS                                         Classic_print.css
 reportLinks                                                      0
 reportLinksCaption                                     Link report
 saveHTML                                                        ¯1
 screenCSS                                       Classic_screen.css
 smoothScrolling                                                  1
 startHeaderNoWith                                                1
 subTocs                                                          1
 syntaxSugar                                                      1
 title                                                       [Null]
 toc                                                              0
 tocCaption                                       Table of contents
 tocHideCaption                                                Hide
 tocShowCaption                                                Show
 verbose                                      ⍝ defaults to "debug"
 width                                                          900

The function ∆List lists all the variables in the parameter space with their corresponding values.

After making amendments the parameter space can be passed as the first argument to the MarkAPL.Init function. See How-to for details.

The parameters themselves are discussed in the MarkAPL reference.

5. Function calls

It is possible to embed APL function calls in your Markdown document. The simplest way to call a function #.foo is:

This: ⍎⍎#.foo⍎⍎ is the result.

Given a function #.foo←{'FOO'} this will be the result:

This: FOO is the result.

The purpose of this feature is to either inject simple text or one or more HTML blocks.

Notes:

You may specify something to the right as in this example:

This: ⍎⍎#.foo 1 2 'hello'⍎⍎ is the result.

The array 1 2 'hello' is however passed as left argument since ns is always passed as the right argument. The function must therefore accept a left argument: a monadic tradfn called that way is reported as “did crash”.

Notes:

The result of such an embedded function must be one of:

Note that mixing Markdown and HTML blocks is not permitted.

In case the function returns an HTML block the function call must stand on its own on a line.

If an HTML block is returned then the function is responsible for the correct formatting. In particular a <pre> block must look like this otherwise you might not get the desired result:

<pre><code>Line 1
Line 2
Last line
</code></pre>

Notes:

6. The ns namespace

6.1. Overview

The ns namespace is returned (created) by the Init method and modified by the Process method. It contains both input and output variables.

Before Process is run the variables emptyLines, leadingChars, markdown, markdownLC and withoutBlanks hold data that is extracted from the Markdown.

Process then splits the Markdown into appropriate blocks, and processes them one after the other, and removes stuff accordingly from these variables.

At the same time the variable ns.html is collecting the resulting html. Other variables (abbreviations, data, footnoteDefs, headers, linkRefs, parms, subToc and toc) may or may not collect data in the process as well.

The two variables report and lineNumbers are special, see there.

6.2. The ns namespace in detail

The namespace contains the following variables:

6.2.1. abbreviations

A (possibly empty) matrix with two columns: the first one holds the abbreviation, the second one the explanation or comment.

6.2.2. data

A (possibly empty) vector of two-item vectors, one for each name defined with [data]:. The first item holds the name, the second item the value.

6.2.3. embeddedParms

A matrix with two columns and as many rows as there are embedded parameters.

This document for example carries these embedded parameters:

      ns.embeddedParms
 toc                                    2 3
 numberHeaders                    2 3 4 5 6
 bookmarkLink                             6
 title              MarkAPL for programmers
 width                                 1000
 reportLinks                              1
 smoothScrolling                          1
 saveHTML                                 1
 leanpubExtensions                        1

6.2.4. emptyLines

A vector of Booleans indicating which lines in markdown are empty. Lines consisting of white-space characters only are considered empty.

6.2.5. footnoteDefs

A matrix that carries all footnote definitions found in markdown. The matrix has these columns:

  1. The identifier of the footnote.
  2. The text of the footnote.

6.2.6. headerLineNos

An integer vector that carries the line numbers of headers.

6.2.7. headers

A matrix that carries all headers defined in markdown.

The matrix has four columns:

  1. The level of the header, starting with 1.
  2. The anchor-ready version of the caption.
  3. The caption.
  4. The tiered number of the header.

Naturally the last column is empty for all headers that are not numbered.

6.2.8. html

After having created the ns namespace by calling Init this variable is empty. By running the Process method this variable will be filled up.

6.2.9. leadingChars

After having created the ns namespace by calling Init this variable contains a limited number of characters from markdown. Leading white-space is removed. This increases performance for many of the checks to be carried out by Process.

6.2.10. lineNumbers

After having created the ns namespace by calling Init this variable contains a vector of integers representing line numbers in markdown. This allows the current line number to be reported in case there is a problem like odd number of double quotes, invalid internal links etc.

Notes:

6.2.11. linkRefs

A vector of vectors holding information regarding all link references (see the MarkAPL reference for details regarding link references):

  1. id
  2. url
  3. alt text or empty
  4. special attributes or empty

6.2.12. markdown

This variable holds the Markdown to be processed by Process.

6.2.13. markdownLC

Same as markdown but all in lower case. That speeds things up at the expense of memory.

6.2.14. noOf

The number of lines processed in the next (or current) step.

6.2.15. parms

A copy of the parameters passed to Init, with any embedded parameters applied and adjustments made. Pass this to MakeHTML_Doc.

6.2.16. report

After having created the ns namespace by calling Init this variable is either empty or carries remarks from Init. Both the Init and the Process method might add remarks to this variable in case it finds something to complain about or comment on. However, you are advised to ignore warnings after having executed just Init.

Some methods print what they assign to report also to the session in case the parameter verbose is 1.

6.2.17. subToc

This is a vector of four-item vectors, one for every <<SubTOC>> directive:

  1. The level of the header the directive belongs to.
  2. The row of that header in headers.
  3. The depth requested with <<SubTOC-n>>; 0 means “no limit”.
  4. Any special attributes.

6.2.18. toc

This is a vector of four-item vectors:

  1. The level of the header, starting with 1.
  2. The caption of the header as displayed.
  3. The internal link name.
  4. The line number of the header.

6.2.19. topOfDocument

Used internally.

6.2.20. withoutBlanks

Same as markdown but without any blanks. This speeds things up at the expense of memory.

7. Helpers

This chapter discusses all methods that help converting APL arrays into Markdown.

7.1. Matrix2MarkdownList

This helper method takes an APL matrix and converts it to a list definition in Markdown.

Note that the table must have three columns:

  1. List type. A 0 defines a bulleted list. Any positive integer starts an ordered list, and defines at the same time the starting point.
  2. Nesting level. The first row must start with nesting level 0 or 1.
  3. Either a text vector or a vector of text vectors.

Example:

 m←''
 m,←⊂0 1 'Level 1 a bullet point'
 m,←⊂2 2 'Level 2 a num'
 m,←⊂2 2('Level 2 b num' '' 'Another para' '' '~~~' '{+⌿⍵}' '~~~')
 m,←⊂2 2 'Level 2 c num'
 md←MarkAPL.Matrix2MarkdownList↑m
 ns←MarkAPL.Init''md
 ns←MarkAPL.Process ns

leads to this list:

7.2. Matrix2MarkdownTable

Takes an APL matrix and converts it to a table definition in Markdown.

Without a left argument there are no column headers, and alignment is ruled by data type: strictly numeric columns are right-aligned, everything else is left-aligned:

      M←↑('APL' 99 'Really great')('Python' 70 'Nice')('Cobol' 1 'Oh dear')
      ⍪MarkAPL.Matrix2MarkdownTable M
 :-|-:|:-
 APL|99|Really great
 Python|70|Nice
 Cobol|1|Oh dear

This results in this:

APL 99 Really great
Python 70 Nice
Cobol 1 Oh dear

You can specify column headers via the left argument. Naturally the length of the left argument must match the number of columns in the matrix. You can use leading and trailing colons (:) in order to define column alignment.

Note that any | in the matrix is automatically escaped except when it appears in code:

      ch←'Lang' 'Prod:Rank' ':Comment:'
      M←↑('APL' 99 'Really great')('Python' 70 'Nice')('Cobol' 1 'Oh|dear')
      ⍪ch MarkAPL.Matrix2MarkdownTable M
 Lang|Prod:Rank|Comment
 :-|-:|:-:
 APL|99|Really great
 Python|70|Nice
 Cobol|1|Oh\|dear

This results in this:

Lang Prod:Rank Comment
APL 99 Really great
Python 70 Nice
Cobol 1 Oh|dear

Notes:

8. Problems

8.1. Bugs

Please report any bugs to kai@aplteam.com. I appreciate:

8.2. Unexpected results

Before reporting a bug please check carefully your Markdown. More often than not mistakes in the Markdown are causing the problem.

If you cannot work out why it goes wrong report it to me – see the previous topic for how to report a problem.

This document refers to version 16.0 of MarkAPL.

Kai Jaeger ⋄ Last update 2026-10-31


Footnotes

  1. The Markdown editor Meddy on GitHub:
    https://github.com/aplteam/Meddy