This commit is contained in:
2025-11-19 21:45:36 -05:00
parent 5cfaddf479
commit aab31daa2e
9 changed files with 103 additions and 27 deletions

View File

@@ -121,39 +121,62 @@ function M:custom(str)
return self
end
function M:g(str)
self:custom(str)
return self
end
function M:h1(str)
str = str or ""
table.insert(self.parts, "<h1>" .. str .. "</h1>")
self:custom("<h1>" .. str .. "</h1>")
return self
end
function M:h2(str)
str = str or ""
table.insert(self.parts, "<h2>" .. str .. "</h2>")
self:custom("<h2>" .. str .. "</h2>")
return self
end
function M:h3(str)
str = str or ""
table.insert(self.parts, "<h3>" .. str .. "</h3>")
self:custom("<h3>" .. str .. "</h3>")
return self
end
function M:h4(str)
str = str or ""
table.insert(self.parts, "<h4>" .. str .. "</h4>")
self:custom("<h4>" .. str .. "</h4>")
return self
end
function M:h5(str)
str = str or ""
table.insert(self.parts, "<h5>" .. str .. "</h5>")
self:custom("<h5>" .. str .. "</h5>")
return self
end
function M:h6(str)
str = str or ""
table.insert(self.parts, "<h6>" .. str .. "</h6>")
self:custom("<h6>" .. str .. "</h6>")
return self
end
function M:p(str)
str = str or ""
table.insert(self.parts, "<p>" .. str .. "</p>")
return self
end
function M:note(content)
content = content or ""
self:custom('<div class="note">' .. content .. '</div>')
return self
end
function M:a(link, str)
str = str or ""
table.insert(self.parts, "<a href=\"" .. link .. "\">" .. str .. "</a>")
return self
end

19
core/markdown.lua Normal file
View File

@@ -0,0 +1,19 @@
local M = {}
-- Markdown to HTML conversion function
-- Uses the Go backend markdown parser
function M.to_html(markdown_text)
markdown_text = markdown_text or ""
-- Get the fes module
local fes_mod = package.loaded.fes
if fes_mod and fes_mod.markdown_to_html then
return fes_mod.markdown_to_html(markdown_text)
end
-- Fallback: return error message if Go function not available
return "<p>Error: markdown_to_html function not available</p>"
end
return M

2
go.mod
View File

@@ -3,7 +3,7 @@ module fes
go 1.25.4
require (
github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386 // indirect
github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a // indirect
github.com/gomarkdown/mdtohtml v0.0.0-20240124153210-d773061d1585 // indirect
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/yuin/gopher-lua v1.1.1 // indirect

2
go.sum
View File

@@ -1,4 +1,6 @@
github.com/gomarkdown/markdown v0.0.0-20230922112808-5421fefb8386/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a h1:l7A0loSszR5zHd/qK53ZIHMO8b3bBSmENnQ6eKnUT0A=
github.com/gomarkdown/markdown v0.0.0-20250810172220-2e2c11897d1a/go.mod h1:JDGcbDT52eL4fju3sZ4TeHGsQwhG9nbDV21aMyhwPoA=
github.com/gomarkdown/mdtohtml v0.0.0-20240124153210-d773061d1585/go.mod h1:6grYm5/uY15CwgBBqwA3+o/cAzaxssckznJ0B35ouBY=
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=

52
main.go
View File

@@ -1,6 +1,7 @@
package main
import (
_ "embed"
"flag"
"fmt"
"net/http"
@@ -11,10 +12,22 @@ import (
"regexp"
"strings"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
"github.com/pelletier/go-toml/v2"
lua "github.com/yuin/gopher-lua"
)
//go:embed core/builtin.lua
var builtinLua string
//go:embed core/markdown.lua
var markdownLua string
//go:embed core/std.lua
var stdLua string
const version = "1.0.0"
type MyConfig struct {
@@ -31,22 +44,36 @@ type MyConfig struct {
var port = flag.Int("p", 3000, "set the server port")
// markdownToHTML converts markdown text to HTML
func markdownToHTML(mdText string) string {
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
p := parser.NewWithExtensions(extensions)
doc := p.Parse([]byte(mdText))
htmlFlags := html.CommonFlags | html.HrefTargetBlank
opts := html.RendererOptions{Flags: htmlFlags}
renderer := html.NewRenderer(opts)
return string(markdown.Render(doc, renderer))
}
func loadLua(luaDir string, entry string, cfg *MyConfig) (string, error) {
L := lua.NewState()
defer L.Close()
L.PreloadModule("fes", func(L *lua.LState) int {
mod := L.NewTable()
wd, _ := os.Getwd()
corePath := filepath.Join(wd, "core")
files, _ := os.ReadDir(corePath)
for _, f := range files {
if f.IsDir() || filepath.Ext(f.Name()) != ".lua" {
continue
// Load core modules from embedded files
coreModules := map[string]string{
"builtin": builtinLua,
"markdown": markdownLua,
"std": stdLua,
}
modName := f.Name()[:len(f.Name())-len(".lua")]
if err := L.DoFile(filepath.Join(corePath, f.Name())); err != nil {
fmt.Println("error loading", f.Name(), ":", err)
for modName, luaCode := range coreModules {
if err := L.DoString(luaCode); err != nil {
fmt.Println("error loading", modName, ":", err)
continue
}
val := L.Get(-1)
@@ -82,6 +109,13 @@ func loadLua(luaDir string, entry string, cfg *MyConfig) (string, error) {
configTable.RawSetString("fes", fesTable)
mod.RawSetString("config", configTable)
}
// Register markdown_to_html function
mod.RawSetString("markdown_to_html", L.NewFunction(func(L *lua.LState) int {
mdText := L.ToString(1)
html := markdownToHTML(mdText)
L.Push(lua.LString(html))
return 1
}))
L.Push(mod)
return 1
})

View File

@@ -1,6 +1,6 @@
[site]
name = "test"
name = "sam-fan-page"
version = "0.0.1"
authors = ["vx-clutch"]

View File

@@ -0,0 +1,6 @@
local fes = require("fes")
local site = fes.site_builder()
site:h1("Hello, World!")
return site

View File

@@ -1,8 +0,0 @@
local fes = require("fes")
local site = fes.site_builder()
site:h1("Hello, Sam!")
site:h2(fes.std.fes_version())
site:h2(fes.std.site_version())
return site