- Go 99.3%
- Makefile 0.7%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
An image gallery drew <img> with src and a size and nothing else, so a reader who cannot see the picture was told only that a picture was there. The description the author already wrote is the text for it, flattened: an attribute holds text, so a caption's bold arrives as bold rather than as asterisks, a link as what it displays, and several lines as one line. An entry with no description gets alt="", which says the picture is decorative. A page name is a name for a file and a URL is worse, so neither is dressed up as a description; the caption is where such a reader is told anything at all. Both renderers share the attribute builder, so the block tree and the streaming path cannot disagree about it. |
||
| blocks | ||
| cmd/mojomarkup | ||
| genhtml | ||
| links | ||
| mycocontext | ||
| objects | ||
| options | ||
| parser | ||
| temporary_workaround | ||
| testdata | ||
| tools | ||
| util | ||
| .gitignore | ||
| A New Kind of Mojomarkup.md | ||
| alt_test.go | ||
| code_span_test.go | ||
| colouring_test.go | ||
| data_test.go | ||
| escape_test.go | ||
| go.mod | ||
| go.sum | ||
| img_description_test.go | ||
| injection_test.go | ||
| inline_object_test.go | ||
| LICENSE | ||
| Makefile | ||
| mojomarkup.go | ||
| race_off_test.go | ||
| race_on_test.go | ||
| README.md | ||
| render.go | ||
| render_test.go | ||
| scheme_test.go | ||
| stream_test.go | ||
| tag_string_test.go | ||
| Versioning.md | ||
Mojomarkup
Mojomarkup is a markup language designed to be used in Mojowiki, a fork of Mycorrhiza Wiki, and in Betula. This project is both a library for these projects and a command-line tool for processing Mojomarkup files in other projects.
See the Mojowiki help page on the markup language itself. The rest of the document provides documentation on the library and the command only.
We track tickets on our Forgejo.
Running
Usage of mojomarkup:
-file-name string
File with mojomarkup. (default "/dev/stdin")
-page-name string
Set page name. Relative links depend on it.
Set the parameters and run the program. The output will be written to stdout. The output is HTML code.
Embedding
Mojomarkup provides an API for Go projects. Consult the docs and Mycorrhiza Wiki source code for inspiration.
When possible, integrate with the library rather than with CLI. Some features such as transclusion are not supported in CLI.
Document data
A document may begin with a data block: a line that is exactly #DATA#, the
text, and another #DATA# line.
#DATA#
{"type": "person", "categories": ["Persons"]}
#DATA#
The page body.
The library does not know what the text says. blocks.Data.Contents returns it
exactly as written, delimiters excluded, and it renders to nothing at all — data
is not part of the page a reader sees.
visitor, result := tools.DataVisitor(ctx)
mojomarkup.BlockTree(ctx, visitor)
if data, ok := result(); ok {
// your format, your parser
var v MyData
json.Unmarshal([]byte(data.Contents()), &v)
}
Four rules, all of them structural:
- The opening delimiter must be the first line of the document. A
#DATA#line anywhere else is text. - The block ends at the next line that is exactly
#DATA#. If there is none, the document has no data and the text stays in the page, where its author can see what went wrong. - There is at most one data block per document.
- A quote, a list item or a table cell is parsed as part of the page, not as a document of its own, so a delimiter there is text — a page may document the feature without a code fence.
Carriage returns are trimmed when comparing lines, so a page checked out with
core.autocrlf still has data.
Inline objects
A document may contain objects like <<color #ffffff | White>>. The library
does not know what any of them means: it finds where the object ends, takes the
name, and hands the rest over untouched through
options.Options.InlineObjectHTML.
An object opens only at << immediately followed by a letter. Anything else
after << — a space, a digit, a bracket — is ordinary text, so a << b >> c,
cat <<EOF and <<<<<<< HEAD need no rule of their own. The name runs to the
next space; the rest is everything after it, as written.
InlineObjectHTML: func(name, rest string) (string, bool) {
if name != "color" {
return "", false // leave it as the author wrote it
}
head, text, _ := objects.Split(rest) // first unescaped '|'
fields := strings.Fields(head)
if len(fields) != 1 {
return "", false
}
label := text
if label == "" {
label = fields[0]
}
return `<span class="swatch" data-color="` + html.EscapeString(fields[0]) + `">` +
html.EscapeString(label) + `</span>`, true
},
Returning false puts the source back into the document, escaped, so an object
this host does not implement is visible rather than dropped. The returned HTML
is inserted as it is, so escape anything that came from the document.
Rest is everything after the name, as written: spaces, bars and backslashes
all survive, so an object that needs its own grammar reads it directly. The
objects package has the parts most objects share — Split for the first
unescaped |, Unescape for a rest read whole — because splitting and
unescaping have to happen in that order: once \| has become |, the parser
can no longer tell an escaped bar from a separator. Neither helper trims, so an
object that wants a padded label can keep it.
How the value reaches the browser is the host's problem. A site with a
restrictive Content-Security-Policy cannot use a style attribute, so the
colour has to travel in a data attribute, an SVG presentation attribute, or a
generated class name rather than in an inline style.
An object lives on one line: an opening << with no closing >> before the
line ends is ordinary text, which is what keeps cat <<EOF and <<<<<<< HEAD
as prose. A backslash escapes the character after it.
Contributing
We accept patches. Please run go fmt.