Notations of your own

Every notation in MyMark is a definition, so an author can add one, or change one, the same way the standard sheet makes its own. There are three ways to do it, each a step further than the last:

  1. a definition that uses a function the standard sheet already has, with arguments to say how;
  2. a macro: a notation written in terms of other notations, in MyMark itself;
  3. a function of your own, in Python.

Most needs stop at the first or the second. This guide is a MyMark document, and its examples are live: each shows its text, then what it becomes.

Definitions with arguments

A definition names a function, and anything after the name is its arguments. The standard sheet's functions take arguments that make one function do many jobs:

.hot(...) -> span red
~(+-) -> glyph ±
!idea ... => callout idea 🌱

A .hot(span) with a class, a ~(+-) glyph, and
!idea a callout of a new kind.

A span with a class, a ± glyph, and

🌱

a callout of a new kind.

std.mym, the standard sheet, says what arguments each of its functions takes.

Macros

A macro is a notation made of others. Its definition names the function mym, and the arguments are MyMark, with ... where the content goes:

Press .key(Ctrl-C) to copy, and .warn(never) delete.

.key(...) -> mym `(...)
.warn(...) -> mym **red(...)

Press Ctrl-C to copy, and never delete.

A block macro is the same idea for a block: mymblock, with ... for the text after the label. The block's own lines follow, so its | lines are still | lines:

Todo:  ... => mymblock !warning To do: ...

Todo:  check the figures
| - in chapter one
| - and in chapter two
⚠️

To do: check the figures

  • in chapter one
  • and in chapter two

A macro needs no code, and it is not tied to HTML: whatever the notations it uses become, it becomes.

Functions

For anything more, a function. A notation sheet, such as my.mym, brings its functions with it, in a Python module beside it, my_html.py: html is the target, the kind of output. A document does the same: this guide is notations.mym, and its functions are in notations_html.py. Each function shown below is its source, read from that file.

An inline function

An inline function takes one element, e, and returns its translation. This one wraps the content in a kbd element, with wrap, a helper from std_html.py that also translates the content:

def kbd(e):
    """A key on the keyboard, as in .kbd(Ctrl-C)."""
    return wrap("kbd", e)
Press .kbd(Ctrl-C), or .kbd(*any* key).

.kbd(...) -> kbd

Press Ctrl-C, or any key.

Declining

A function may decline an element by returning None. The element is then undefined: it is left as written, and its content is read again. So a notation can take only what it knows. GitHub names emoji between colons, and a pattern can say that much, but not which names there are; the function knows, and declines the rest:

def emoji(e):
    """An emoji by its name, as GitHub writes :tada:. A name that is not
    in the table is declined, so 10:30:45 and 1:2:3 are left as written."""
    names = {"tada": "🎉", "rocket": "🚀", "smile": "🙂", "bug": "🐛"}
    found = names.get(e.content)
    return text(found) if found else None
Shipped :rocket: at 10:30:45, a :bug: fixed, in the ratio 1:2:3, and :nosuch: as written.

:...: -> emoji

Shipped 🚀 at 10:30:45, a 🐛 fixed, in the ratio 1:2:3, and :nosuch: as written.

A block function

A block function takes a run, r: the blocks in a row with the same definition, such as the items of a list. Each block b has its label and the text after it, b.body, and its lines, b.lines. lines_of, another helper, translates a block's text with its line breaks:

def verse(r):
    """Verse: each block a stanza, its lines kept, in italics."""
    return "".join(f"<p class='verse'><em>{lines_of(b)}</em></p>\n" for b in r)
Verse:  ... => verse

Verse:  The bar is a guide line,
it shows where you are;
Verse:  a stanza a block,
and the run is the poem.

The bar is a guide line,
it shows where you are;

a stanza a block,
and the run is the poem.

What a function is given

An element e has its sigil, its tag, its content and all its parts, e.args from the definition, and e.inline() to translate its content, or e.inline(s) for any MyMark text. A block b has its label, b.body, b.lines, b.args, b.inline(s), b.translate(s) for a MyMark document of its own, as a callout reads its | lines, and b.nested, whether it is inside another block. mym.py lists them all at its head.

A function can also carry an attribute. verbatim says an element's content is taken as it is, as code's is, with no notations inside. A block function can say how its label gathers lines and how its content is read, with gathers (alone, lines, nested, closer, run) and reads (inline, mym, verbatim, or a grammar's name); content(b), a helper, gives it its content read that way. The standard sheet uses three more for its own work: continues, sheets and shows.

The helpers in std_html.py are there to be used: text for plain text, wrap for an element, lines_of for a block's lines, nested for a block's content as a document, fenced for the lines of a fence. A module imports what it needs, as notations_html.py does.

A sheet of your own

To use notations in more than one document, put their definitions in a sheet, my.mym, and their functions, if any, in my_html.py beside it. A document names the sheet with sheets: my.mym. A sheet is found beside the document, or else beside mym.py, where std.mym and abc.mym are.

A sheet is a MyMark file, and only its definition lines count, so it can be a document too: the definitions, with their manual and examples around them. A line definitions: shown makes its definitions show when it is read as a document, as std.mym does.

Later: one function for every format

A function writes HTML, so a notation needs a function for each kind of output. The plan is to follow Pandoc: functions that build a document tree in Pandoc's own form, from which Pandoc can write HTML, LaTeX, Word and many more. Then one function would serve every format.

Work in progress...