Fork of mycomarkup with Mojosa extensions
  • Go 99.3%
  • Makefile 0.7%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
surdeus 4f13c6886c fix: a picture carries its description as alt text
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.
2026-11-12 19:28:26 +05:00
blocks feat: carry a document's data block without reading it 2026-11-12 03:46:09 +05:00
cmd/mojomarkup style: gofmt the two files gofmt disagreed with 2026-11-11 20:47:28 +05:00
genhtml fix: a picture carries its description as alt text 2026-11-12 19:28:26 +05:00
links fix: a link is only a URL when its scheme may be linked 2026-11-12 19:13:21 +05:00
mycocontext feat: carry a document's data block without reading it 2026-11-12 03:46:09 +05:00
objects refactor!: hand an object's rest to the object 2026-11-11 22:25:25 +05:00
options refactor!: hand an object's rest to the object 2026-11-11 22:25:25 +05:00
parser feat: carry a document's data block without reading it 2026-11-12 03:46:09 +05:00
temporary_workaround refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
testdata refactor!: rename mycomarkup to mojomarkup 2026-10-26 21:24:35 +05:00
tools feat: carry a document's data block without reading it 2026-11-12 03:46:09 +05:00
util fix: a link is only a URL when its scheme may be linked 2026-11-12 19:13:21 +05:00
.gitignore refactor!: rename mycomarkup to mojomarkup 2026-10-26 21:24:35 +05:00
A New Kind of Mojomarkup.md refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
alt_test.go fix: a picture carries its description as alt text 2026-11-12 19:28:26 +05:00
code_span_test.go feat: draw inline objects, and make code spans literal 2026-11-11 20:47:37 +05:00
colouring_test.go refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
data_test.go feat: carry a document's data block without reading it 2026-11-12 03:46:09 +05:00
escape_test.go fix: open an inline object only at "<<letter", and escape at line start 2026-11-12 01:52:15 +05:00
go.mod refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
go.sum Move some stuff, fix the id attr, show an error when transcluding from CLI 2021-05-13 22:57:41 +05:00
img_description_test.go fix: keep nested braces in an image description 2026-11-11 20:47:31 +05:00
injection_test.go refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
inline_object_test.go refactor!: hand an object's rest to the object 2026-11-11 22:25:25 +05:00
LICENSE Create LICENSE 2021-05-11 14:40:16 +05:00
Makefile refactor!: rename mycomarkup to mojomarkup 2026-10-26 21:24:35 +05:00
mojomarkup.go refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
race_off_test.go perf: cut allocations in rendering 2026-10-26 21:53:47 +05:00
race_on_test.go perf: cut allocations in rendering 2026-10-26 21:53:47 +05:00
README.md feat: carry a document's data block without reading it 2026-11-12 03:46:09 +05:00
render.go refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
render_test.go refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
scheme_test.go fix: a link is only a URL when its scheme may be linked 2026-11-12 19:13:21 +05:00
stream_test.go refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
tag_string_test.go refactor: move to the go.mojosa.su/lib/mojomarkup module path 2026-10-31 14:20:55 +05:00
Versioning.md refactor!: rename mycomarkup to mojomarkup 2026-10-26 21:24:35 +05:00

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.