Download the PHP package ancarda/gemtext-parser without Composer
On this page you can find all versions of the php package ancarda/gemtext-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ancarda/gemtext-parser
More information about ancarda/gemtext-parser
Files in ancarda/gemtext-parser
Package gemtext-parser
Short Description Gemtext (text/gemini) parser with conversion to HTML
License MIT
Informations about the package gemtext-parser
ancarda/gemtext-parser
Gemtext (text/gemini) parser and HTML encoder
This package implements a PHP parser for Gemtext (text/gemini
) as specified
here: https://gemini.circumlunar.space/docs/gemtext.gmi
Useful Links
- Source Code: https://git.sr.ht/~ancarda/gemtext-parser/
- Issue Tracker: https://todo.sr.ht/~ancarda/gemtext-parser/
- Mailing List: https://lists.sr.ht/~ancarda/gemtext-parser/
Usage
All the low level classes are built around Generator
, which makes plugging in
middleware easy while keeping memory usage low.
Unfortunately, Generators can be a bit of work to actually use. As such, a
utility class, SimpleTransformer
is available which abstracts this away if
you just want a Gemtext to HTML conversion quickly and easily.
Here's how to convert Gemtext to HTML with the low level (Generator
) API:
And here's the higher level utility class, which abstracts this away:
Pipelining
You can create lightweight middleware by creating a function that accepts and
returns Generator<Node>
. This function would be inserted between encode
and
parse
, like so:
Here, middleware's __invoke
method accepts and returns Generator<Node>
.
Middleware could make modifications, inject new nodes, drop some nodes, and so
on. For instance: