Search by

ramir1 / mtxt

Ramir1

Parser for the MTXT (Multi-Text Frontmatter) format

v0.1.0 2026-09-16 09:33 UTC

This package is auto-updated.

Last update: 2026-09-16 13:13:03 UTC


README

Читать на русском

MTXT (Multi-Text Frontmatter) is a minimal, human-writable text format for describing one or more records with typed-ish fields, dot-notation nesting, multilingual values, and multiline text blocks — no YAML/JSON escaping headaches, easy to hand-edit in any plain text editor.

@company.id: 15
@location: Kyiv
code: it101
title.ru: Смартфон Google Pixel 8
title.en: Google Pixel 8 Smartphone
price: 700
tags: pre-order, sale
content.ru: |||
Описание товара. Может быть **многострочным** и с Markdown.
|||
content.en: |||
Product description. Can be **multiline** and contain Markdown.
|||
+++
code: it102
title: Second item
price: 900

Read the full specification: SPEC.md (по-русски).

See examples/reader-profiles.md for illustrative field profiles (listings, events, articles) built on top of the format.

Installation

composer require ramir1/mtxt

Requires PHP 8.3+.

Usage

use Mtxt\Parser;

$parser = new Parser;
$records = $parser->parse(file_get_contents('data.mtxt'));

foreach ($records as $record) {
    echo $record['title'], "\n";
}

Parser::parse() returns a list of records, each an associative array of the record's fields merged with any @-prefixed global fields, with dot-notation keys expanded into nested arrays and repeated keys collapsed into lists.

Writer is the inverse: it serializes a list of records (in that same shape) back into .mtxt text. Global fields aren't inferred from the records — pass them explicitly as the second argument, and they're written as an @-preamble shared by every record:

use Mtxt\Writer;

$writer = new Writer;

echo $writer->write(
    records: [
        ['code' => 'it101', 'title' => 'First item'],
        ['code' => 'it102', 'title' => 'Second item'],
    ],
    globalFields: ['company' => ['id' => '15']],
);

Testing

composer install
vendor/bin/pest

Development

A Dockerfile is provided for a dependency-free dev environment (PHP + Composer, no local install needed):

docker build -t mtxt-spec .
docker run --rm -v $(pwd):/app mtxt-spec composer install
docker run --rm -v $(pwd):/app mtxt-spec vendor/bin/pest

License

MIT