# Markdown customizations and external Lua programs

**URL:** https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443
**Category:** Lua
**Created:** [October 12, 2026, 9:25pm UTC](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443 "2026-10-12T21:25:42Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Offray](https://community.silverbullet.md/user_avatar/community.silverbullet.md/offray/32/3900_2.png) [@Offray](https://community.silverbullet.md/u/Offray)
#### Post date: [October 12, 2026, 9:25pm UTC](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443/1 "2026-10-12T21:25:42Z")

</div>

Hi again,

TL;DR:

Authors using SB are asking for a [short syntax to include metadata in the page](https://community.silverbullet.md/t/reference-frontmatter-attribute-on-the-same-page/4419) or a [custom Markdown syntax](https://community.silverbullet.md/t/custom-markdown-parsing-question/1985), which are requirements that I and others have found many times before while authoring in Markdown. And given that I have already approached such problems previously in Lua (and I don't know TS to go into the [current markdown\_parser](https://github.com/silverbulletmd/silverbullet/tree/main/client/markdown_parser)) I wonder:

How can I reuse Lua Parser Expression Grammars (LPEG) and pure Lua libraries like [Lustache](https://github.com/Olivine-Labs/lustache) and [Lunamark](https://jgm.github.io/lunamark/doc/) to reuse Markdown syntax customizations, like page metadata tranclusions, Pandoc/Djot's div syntax for admonitions and others, without reimplementing them? In general, How can Space Lua reuse Lua scripts and libraries that are used in Markdown/document processing elsewhere so SB can integrate better to existing rich documentation workflows and ecosystems?

TIA

* * *

(The long version)

This inquiry concerns how to to integrate SB with [Cardumem](https://mutabit.com/repos.fossil/cardumem/doc/tip/tekne/wiki/en/), a Lua based Static Site Generator (SSG) (still in alpha), that I have made to suit our documentation/publishing workflows in grassroots communities (like [HackBo](https://hackbo.org/), our local Hackerspace) and at the [university department](https://comunicacionylenguaje.javeriana.edu.co/departamento-de-ciencia-de-la-informacion), in the classes, workshops and research/prototyping projects across academic and non academic spaces/contexts. I'll explain how our documentation workflow looks like and where I would like to integrate SB. I will try to be pretty detailed as this particular concern could document how SB can be integrated into rich pre-existing documentation workflows and ecosystems.

Currently our publications workflow looks like this:

 ![image](https://community.silverbullet.md/uploads/default/original/2X/9/96915efc5f76a59e387ecdf44405a040c7e3cd16.png)

So, we write Markdown content in our workshops/classes using the real time collaborative editor [HedgeDoc](https://hedgedoc.org/), Cardumem downloads/renames that information to the hard disk and parses (Markdown) content, (YAML) metadatada and [Mustache](https://mustache.github.io/) (HTML + CSS) logicless templates to produce a HTML output that we store in a [Fossil](https://fossil-scm.org/) repository, kind of a GitHub/Gitea/Forgejo in a box (3 Mb), providing us collaboration, versioning, web server, ticketing/issues and forum. We use also [Codium](https://vscodium.com/), the non-panoptic and telemetry disabled variant of VSCode, for wiki refactoring (more on that and the role of SB for our audiences later).

As many other SSGs, we need to parse, separate and process YAML metadata from Markdown content, while dealing with the popularity and insufficiency of the Markdown (sub)"standard" (despite of important efforts like [CommonMark](https://commonmark.org/)) by providing custom syntax for everything that plain Markdown doesn't allow, including transclusions, an important hypertext feature about how to make content modular and "assemblable", that has been historically overshadowed by linking...

Anyway, part of my thinking has been related with how to reuse the libraries and functionality we already have for Markdown processing to deal with this format's (many) limitations, making its syntax extensible, while offering a gentle curve to the authors, so they can traverse from content to functionality creation and viceversa, as they need.

For example, given that I already have Lua's [Lustache](https://github.com/Olivine-Labs/lustache) to process logicless templates, Cardumem provides [page metadata transclusions](https://mutabit.com/repos.fossil/cardumem/doc/tip/tekne/wiki/en/features.html#page-fields-transclusion-13) using the same Mustache syntax. So, given this page metadata:

```yaml
---
# This is part of this page YAML metadata.
example: " **I'm just a brief text**."
mutabit: >
  ===== <br>
  [mutabiT](https://mutabit.com/) is the small family enterprise that funds and sustains most of this long research and agile prototyping efforts, since 2003.
musketeers: ["Athos", "Aramis", "Porthos", "D'Artagnan"]
---

```

I can call those fields in Cardumem's Markdown with `{{example}}` , `{{mutabit}}` or `{{#musketeers}} {{.}} {{/musketeers}}`, to get them properly rendered inside the page.

Syntax extension reuse YAML + Mustache processing, so authors/collectives can create their own [customized portable macros](https://mutabit.com/repos.fossil/cardumem/doc/trunk/tekne/wiki/en/features.html#macros-for-adding-11) by defining them in a simple [macros.yaml file](https://mutabit.com/repos.fossil/cardumem/file?udc=1&ci=tip&name=tekne%2Fmakina%2Fmacros.yaml), with nested keys containing the name of the macro, its input and how it is used in its output, again as a Mustache template. Similarly, global transclusion keys are defined in a [transclusions.lua file](https://mutabit.com/repos.fossil/cardumem/file?name=tekne/makina/transclusions.lua&ci=tip), which allows, for example, to call `{{_date}}` in any page and get the current date when such page is exported as HTML.

Another example is the usage of [Lunamark](https://jgm.github.io/lunamark/doc/) to process not only standard Markdown, but also its customizations, using Lua PEG, like in our [admonitions](https://mutabit.com/repos.fossil/cardumem/doc/trunk/tekne/wiki/en/features.html#admonitions-9), that follow [Djot's div syntax](https://github.com/jgm/djot/blob/master/doc/syntax.html#div), which is also used by Pandoc and HedgeDoc, as my policy regarding Markdown syntax extension is: "when in doubt, look at Pandoc/Djot as it's the variant that deals with most export/import scenarios.

Given the static/dynamic nature of Cardumem/SilverBullet, respectively, and that both have a Lua extension story, I would like to make each one the complement of the other: SB can be used for live coding and wiki refactoring of our documentation, instead of Codium, which suits better our general non-developers audience and Cardumem can work on the static site generation.

Finally, what I would like is to make SB to reuse Cardumem's syntax and hopefully some of its scripts. And make the bridge between both using Lua, not TypeScript. That's why I asked the short question at the beginning of this post.

Cheers,

Ps: While writing this, I remembered the [Pascal quote](https://en.wikiquote.org/wiki/Blaise_Pascal): _I made this one [letter] longer only because I have not had the leisure to make it shorter_.

---

<div class="post-metadata">

### Author: ![duaerteam](https://community.silverbullet.md/letter_avatar_proxy/v4/letter/d/df705f/32.png) [@duaerteam](https://community.silverbullet.md/u/duaerteam)
#### Post date: [October 15, 2026, 8:43am UTC](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443/2 "2026-10-15T08:43:22Z")

</div>

This answer is AI-generated.

I can't give a definitive answer, but here is what the Space Lua docs say and where I'd expect the limits to be:

1. Space Lua is SilverBullet's own Lua implementation. Its scripts live in space-lua blocks in your pages, are loaded when the client boots (or on "System: Reload"), and their load order is controlled with a `-- priority: <number>` comment. I couldn't find documentation saying Space Lua can `require` arbitrary external Lua files or libraries from disk, so I'd treat that as unsupported unless the maintainers say otherwise.
2. LPeg is a C library, so I wouldn't expect it to run inside Space Lua. Pure-Lua libraries such as Lustache might work if you paste their source into a space-lua block, but that depends on which standard-library functions they use. I'm not sure which ones Space Lua implements, so test it on a copy of your space and check the browser console, which is where the docs say load-time errors show up.
3. For metadata transclusion, the docs describe the `${lua expression}` syntax, which renders the result of a Lua expression in Live Preview. That might cover your `{{field}}` use case without a separate template engine.
4. Since your site generator already works on the Markdown files on disk, another option is to leave the custom syntax in the files and let your generator handle it at build time, using SilverBullet only for editing. It's probably worth asking the maintainers whether a custom syntax hook is planned.

---

<div class="post-metadata">

### Author: ![Offray](https://community.silverbullet.md/user_avatar/community.silverbullet.md/offray/32/3900_2.png) [@Offray](https://community.silverbullet.md/u/Offray)
#### Post date: [October 15, 2026, 7:11pm UTC](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443/3 "2026-10-15T19:11:11Z")

</div>

Thanks. But answers like this are precisely why I try to avoid AI (or Apparent Intelligence as I like to call it) as much as I can and used it "surgically" pointing to code bases I know or over questions with few lines of code as an answer that I can verify quickly. I would wait for a human answer made in context and less generic.

Cheers,

---

<div class="post-metadata">

### Author: ![duaerteam](https://community.silverbullet.md/letter_avatar_proxy/v4/letter/d/df705f/32.png) [@duaerteam](https://community.silverbullet.md/u/duaerteam)
#### Post date: [October 15, 2026, 7:54pm UTC](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443/4 "2026-10-15T19:54:07Z")

</div>

Fair point — the last reply was too generic.

On the specific question (reuse LPeg / Lustache / Lunamark from Space Lua):

1. Space Lua is SilverBullet’s own Lua implementation (not Lua/LuaJIT/WASM). C libraries like LPeg are not available inside it.
2. Definitions live in `space-lua` fenced blocks in pages and load on boot / `System: Reload`. I still don’t see a documented way to `require` arbitrary Lua files from disk the way Cardumem does.
3. Pure-Lua code can be pasted into a `space-lua` block and tested, but anything that depends on C bindings or a full standard library will fail — check the browser console after Reload.
4. Practical split that matches your setup: keep Cardumem’s custom Markdown/Mustache/Lunamark pipeline on the files for static export; use SilverBullet for editing/live refactoring; use `${…}` only for live preview inside SB. For a real syntax bridge (custom admonitions, Mustache-style macros in SB itself), that needs a maintainer answer — I’m not going to invent one.

If that still isn’t useful, ignore this and wait for a human who works on SB day to day.

---

<div class="post-metadata">

### Author: ![Offray](https://community.silverbullet.md/user_avatar/community.silverbullet.md/offray/32/3900_2.png) [@Offray](https://community.silverbullet.md/u/Offray)
#### Post date: [October 15, 2026, 8:08pm UTC](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443/5 "2026-10-15T20:08:31Z")

</div>

Yep, I'll wait for the human. Thanks again.

---

<div class="post-metadata">

### Author: ![zef](https://community.silverbullet.md/user_avatar/community.silverbullet.md/zef/32/7_2.png) [@zef](https://community.silverbullet.md/u/zef)
#### Post date: [October 16, 2026, 6:14am UTC](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443/6 "2026-10-16T06:14:51Z")

</div>

This is a lot of information to process, and I don't have the capacity to dig into each of these links and projects. Let me just give a few pointers that may or may not answer your question:

1. Space Lua is a reimplementation of Lua and it's "hard wired" in, so you can not just swap out Lua dialects.
2. There's a _very_ simple extension point to extend the syntax right now: [syntax](https://docs.silverbullet.md/API/syntax)
3. Space Lua is deeply wired into SilverBullet itself, so cannot easily be pulled out and mixed and matched with other tools.

---

<div class="post-metadata">

### Author: ![Offray](https://community.silverbullet.md/user_avatar/community.silverbullet.md/offray/32/3900_2.png) [@Offray](https://community.silverbullet.md/u/Offray)
#### Post date: [October 16, 2026, 12:46pm UTC](https://community.silverbullet.md/t/markdown-customizations-and-external-lua-programs/4443/7 "2026-10-16T12:46:36Z")

</div>

Thanks Zef for pointing me to the syntax extension point. I'll look at it.

And yes I tend to overwrite... it is some academician increased decease and also my way to raise awareness of local/Spanish projects that would be little to not known except for our participation in forums like this. Instead, to share the way SB will be part of our "ecosystems of memory", I'm planing to write some blog post and sharing some workshops that I will give to colleagues and undergrad /post grad students, using SB inside such ecosystems.

Coming back to my question, my idea is not to replace/swap Lua dialects. Instead what I want to do it to use the fact that Space Lua _is_ a Lua to use external Lua programs I have used before to deal with inherited Markdown customizations, like those coming from HedgeDoc and Pandoc, and also the ones we have devised our selves to attend particular writing needs.

For example, I use [TinyYAML](https://github.com/peposso/lua-tinyyaml) combined with [Lustache](https://github.com/Olivine-Labs/lustache) to support Mustache templating syntax exemplified in this very thread when calling page metadata inside Markdown. This allow us to take advantage of the logicless nature of Mustache, so authors can make document/template customizations and call metadata without even knowing any programming and instead using the Mustache concepts: presence, absence, plain, nested, unique, multiple, partial and complement. Given that both, TinyYAML and Lustache, are pure Lua packages, how can I use them in Space Lua?

Ultimately, given that _Growing with you_ implies also _Meeting where you are_, I wonder how SB and Space Lua can benefit of the huge amount of pure Lua packages and/or those provided by Luarocks, to create a better synergy with the wider Lua community and its use cases around the globe. I believe this may increase SB awareness and utility, given the use Lua has in places like academic writing (with Pandoc), programming education for different ages/platforms, and so on.
