merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi
About | Files | Commits | Refs | License
feat: add markdown to HTML conversion for plugins
Author: pi66
Date: 2026-10-05 01:08
commit: d7b8fc55
- Add `merodi.compile.convert` for Jinja + Markdown conversion - Add `merodi.compile.mdtohtml` for Markdown to HTML conversion - Add an example plugin using both functions
Stat
| A | examples/plugins/compile.lua | 7 | +7 | -0 |
| A | src/core/lua/compile.go | 34 | +34 | -0 |
| A | src/core/lua/lua.go | 1 | +1 | -0 |
Diff
diff --git a/examples/plugins/compile.lua b/examples/plugins/compile.lua
new file mode 100644
index 0000000..9599eb5
--- /dev/null
+++ b/examples/plugins/compile.lua
@@ -0,0 +1,7 @@
+-- merodi.compile lets you convert Markdown to HTML without writing files.
+
+merodi.compile.convert("# Hello\nSome **markdown** content")
+-- Runs Jinja and Markdown, then returns the HTML.
+
+merodi.compile.mdtohtml("# Hello\nSome **markdown** content")
+-- Converts Markdown to HTML without running Jinja.
diff --git a/src/core/lua/compile.go b/src/core/lua/compile.go
new file mode 100644
index 0000000..d025e7f
--- /dev/null
+++ b/src/core/lua/compile.go
@@ -0,0 +1,34 @@
+package lua
...
Show all
Show less
diff --git a/examples/plugins/compile.lua b/examples/plugins/compile.lua
new file mode 100644
index 0000000..9599eb5
--- /dev/null
+++ b/examples/plugins/compile.lua
@@ -0,0 +1,7 @@
+-- merodi.compile lets you convert Markdown to HTML without writing files.
+
+merodi.compile.convert("# Hello\nSome **markdown** content")
+-- Runs Jinja and Markdown, then returns the HTML.
+
+merodi.compile.mdtohtml("# Hello\nSome **markdown** content")
+-- Converts Markdown to HTML without running Jinja.
diff --git a/src/core/lua/compile.go b/src/core/lua/compile.go
new file mode 100644
index 0000000..d025e7f
--- /dev/null
+++ b/src/core/lua/compile.go
@@ -0,0 +1,34 @@
+package lua
...
diff --git a/examples/plugins/compile.lua b/examples/plugins/compile.lua
new file mode 100644
index 0000000..9599eb5
--- /dev/null
+++ b/examples/plugins/compile.lua
@@ -0,0 +1,7 @@
+-- merodi.compile lets you convert Markdown to HTML without writing files.
+
+merodi.compile.convert("# Hello\nSome **markdown** content")
+-- Runs Jinja and Markdown, then returns the HTML.
+
+merodi.compile.mdtohtml("# Hello\nSome **markdown** content")
+-- Converts Markdown to HTML without running Jinja.
diff --git a/src/core/lua/compile.go b/src/core/lua/compile.go
new file mode 100644
index 0000000..d025e7f
--- /dev/null
+++ b/src/core/lua/compile.go
@@ -0,0 +1,34 @@
+package lua
+
+import (
+ "merodi/src/core/build/compile"
+ "merodi/src/core/state"
+ . "merodi/src/utils/errs"
+ "strings"
+
+ glua "github.com/yuin/gopher-lua"
+)
+
+func (self *Lua) registerCompile() {
+ c := &compile.Compile{State: self.State}
+ build := state.Build{}
+ CheckE(c.Init())
+ c.Build = &build
+
+ compileTable := self.Context.NewTable()
+
+ compileTable.RawSetString("convert", self.Context.NewFunction(func(L *glua.LState) int {
+ c.Build.Content = L.ToString(1)
+ L.Push(glua.LString(strings.TrimRight(c.Convert(), "\n")))
+ return 1
+ }))
+
+ compileTable.RawSetString("mdtohtml", self.Context.NewFunction(func(L *glua.LState) int {
+ md := L.ToString(1)
+ html := CheckV(c.MD.MdToDoc(md))
+ L.Push(glua.LString(strings.TrimRight(html, "\n")))
+ return 1
+ }))
+
+ self.Merodi.RawSetString("compile", compileTable)
+}
diff --git a/src/core/lua/lua.go b/src/core/lua/lua.go
index 8361deb..e5ad6bb 100644
--- a/src/core/lua/lua.go
+++ b/src/core/lua/lua.go
@@ -58,5 +58,6 @@ func (self *Lua) registerMerodi() {
self.registerEnable()
self.registerDisable()
self.registerLog()
+ self.registerCompile()
self.State.Lua.Context.SetGlobal("merodi", self.Merodi)
}