~subsetpark/mago

a minimal frontmatter library
51a147f9 — Zach Smith 3 years ago
Add LICENSE
d9821e12 — Zach Smith 3 years ago
add README
cb660ed6 — Zach Smith 3 years ago
Some changes after testing with subsetpark

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~subsetpark/mago
read/write
git@git.sr.ht:~subsetpark/mago

You can also use your local clone with git send-email.

{:title "Mago" :description "A minimal frontmatter library for Janet"}

%%%

#Mago

mago is an extremely simple format and library for writing text documents with arbitrary metadata and parsing them in pure Janet.

This file is a Mago document; a Markdown text file with a Janet struct at the beginning and a separator string, followed by the rest of the body.

#Demo

Here's an example of how to use it:

Janet 1.13.1-e9f6c4f linux/x64 - '(doc)' for help
repl:1:> (import mago)
@{mago/parse @{:private true} mago/peg @{:private true} _ @{:value <cycle 0>} mago/default-peg @{:private true} mago/default-separator @{:private true}}
repl:2:> (mago/parse (slurp "README.md"))
{:body "\n\n# Mago\n\n`mago` is an extremely simple format and library for writing text\ndocuments with arbitrary metadata and parsing them in pure Janet.\n\nThis file is a Mago document; a Markdown text file with a Janet struct\nat the beginning and a separator string, followed by the rest of the\nbody.\n" :front {:description "A minimal frontmatter library for Janet" :title "Mago"}}
repl:3:> 

In other words, mago/parse will take a string, split it on the separator string, and then parse the frontmatter as a Janet data structure.

It produces a simple struct where :front contains the parsed data structure and :body contains the rest of the document.

#Usage

This allows us to encode text file metadata similarly to Jekyll or Multimarkdown. However, it has the advantage, within the Janet ecosystem, of not requiring any shelling out to an external program.