A lightweight template-driven markup language
Project description
Mau v5
Mau is a lightweight markup language heavily inspired by AsciiDoc, Asciidoctor and Markdown.
It is built on Jinja and designed for authors who want the simplicity of Markdown with the expressive power of templating. You can use Mau to create blog posts, books, documentation.
Why Mau?
Mau combines:
- Readable plain text similar to Markdown.
- Jinja templating that allows you to easily affect the rendering of Mau syntax.
- Flexible output via pluggable visitors (HTML, TeX, YAML, etc.)
Installation
Mau requires Python 3.10 or later.
pip install mau
Mau parses the source into an abstract syntax tree and then transforms it into the final output using a visitor. The core package includes a YAML visitor and a Jinja base visitor. To render into a specific format you need an additional visitor plugin.
To render Mau into HTML:
pip install mau-html-visitor
To render Mau into TeX:
pip install mau-tex-visitor
Quick start
-
Create a file
example.mauwith some Mau content:= My first document This is a paragraph with *bold text* and _underlined text_. * Item one * Item two * Item three -
Render it to YAML (built-in, no extra plugin needed):
mau -i example.mau -t core:YamlVisitor -o example.yaml
-
If you installed
mau-html-visitor, render it to HTML:mau -i example.mau -t core:HtmlVisitor -o example.html
CLI usage
mau -i INPUT_FILE -t VISITOR [-o OUTPUT_FILE] [OPTIONS]
Required arguments
| Flag | Description |
|---|---|
-i, --input-file |
The Mau source file |
-t, --visitor |
The output format visitor (e.g. core:YamlVisitor, core:HtmlVisitor) |
Optional arguments
| Flag | Description |
|---|---|
-o, --output-file |
Output file path. Use - for standard output. Defaults to the input file name with the visitor's extension |
-c, --config-file |
A YAML configuration file |
-e, --environment-file |
A YAML file loaded into the environment. Can be repeated. Format: key=path or just path |
--environment-files-namespace |
Namespace for environment files (default: envfiles) |
-v, --environment-variable |
An environment variable as key=value. Can be repeated. The key can be dotted to add namespaces |
--environment-variables-namespace |
Namespace for environment variables (default: envvars) |
--verbose |
Set log level to INFO |
--debug |
Set log level to DEBUG |
--lexer-print-output |
Print the tokens produced by the lexer |
--lexer-only |
Stop after the lexing step |
--version |
Print the Mau version and exit |
Examples
# Render to YAML and print to stdout
mau -i document.mau -t core:YamlVisitor -o -
# Render to HTML with an environment variable
mau -i document.mau -t core:HtmlVisitor -v title="My Doc"
# Render with a config file and debug output
mau -i document.mau -t core:YamlVisitor -c config.yaml --debug
# Load an environment file
mau -i document.mau -t core:HtmlVisitor -e metadata=data.yaml
Library usage
You can use Mau as a Python library:
import logging
from mau import Mau, load_visitors
from mau.environment.environment import Environment
from mau.message import LogMessageHandler
logger = logging.getLogger(__name__)
message_handler = LogMessageHandler(logger)
# Build the environment from a dictionary.
environment = Environment.from_dict(
{"some_variable": "some_value"},
)
# Create the Mau processor.
mau = Mau(message_handler=message_handler, environment=environment)
# Load available visitors.
visitors = load_visitors()
# Select a visitor class.
visitor_class = visitors["core:YamlVisitor"]
# Process the text.
text = "= Hello\n\nThis is *bold*."
result = mau.process(visitor_class, text, source_filename="example.mau")
print(result)
For finer control, you can run each stage individually:
# Initialise the text buffer.
text_buffer = mau.init_text_buffer(text, "example.mau")
# Run the lexer.
lexer = mau.run_lexer(text_buffer)
# Run the parser.
parser = mau.run_parser(lexer.tokens)
# Run the visitor on the document node.
rendered = mau.run_visitor(visitor_class, parser.output.document)
Backward compatibility
Mau v5 changed some parts of the syntax in a non-backward compatible way. The file MAJOR_CHANGES.md contains a list of the major changes between v4 and v5.
Pelican plugin
There is a Pelican plugin to use Mau directly in your blog:
https://github.com/pelican-plugins/mau-reader
Make sure to read the instructions in that repository to configure the plugin correctly.
Full documentation
The full documentation is available at https://project-mau.github.io/.
LLM instructions
If you want to quickly teach an LLM to use Mau you can use the file MAU_SYNTAX_REFERENCE.md.
Development
Setup
-
Clone the repository.
-
Create a virtual environment with Python 3.10+.
-
Install the development and testing dependencies:
pip install -e ".[development,testing]"
Running tests
pytest
Linting
ruff check .
mypy .
pylint mau
Support
Bug reports and feature requests: https://github.com/Project-Mau/mau/issues
Discussions and Q&A: https://github.com/Project-Mau/mau/discussions
License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mau-5.0.0.tar.gz.
File metadata
- Download URL: mau-5.0.0.tar.gz
- Upload date:
- Size: 136.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
884fa6a6a329c17fc7a13a667f9a8a56d93c28e55a363c8a8383adfd2a15add9
|
|
| MD5 |
2b448ea8b395c403681e9636152cb314
|
|
| BLAKE2b-256 |
84a4323755f62daff8a4fa8c8bc0c2f8d65e43169c0fedf09f3c304e879c3af1
|
File details
Details for the file mau-5.0.0-py3-none-any.whl.
File metadata
- Download URL: mau-5.0.0-py3-none-any.whl
- Upload date:
- Size: 100.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
103a9c7cf436bd5fdb5ad50c020e3ef440cadbddf9925670f21e77108ae3241a
|
|
| MD5 |
e1f9eeabb47f67b0ea711ba959b54f1e
|
|
| BLAKE2b-256 |
1c7de4e4f09a89c0031b1d73aee200ca2fedc75b92344e14dd0988f718b76674
|