diff options
| author | tv <tv@krebsco.de> | 2026-11-12 18:06:06 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-12 19:18:41 +0100 |
| commit | e0b7c0f52ceaf0fac514cecbe1b14a20c8eb9e8a (patch) | |
| tree | d387f4dd4c7f94b89e7efe039a1a68a0200950f6 | |
| parent | 4f3bc08757f73e9a282ea41c72816610d7e1d7d4 (diff) | |
cgit-about-filter: write through html()
| -rw-r--r-- | pkgs/simple/cgit-about-filter/cgit-about-filter.lua | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua index 6e1ccdd..86468f5 100644 --- a/pkgs/simple/cgit-about-filter/cgit-about-filter.lua +++ b/pkgs/simple/cgit-about-filter/cgit-about-filter.lua @@ -46,6 +46,26 @@ local function url_escape(s) end)) end +-- cgit provides html() to Lua filters. It writes in order with cgit's own +-- output, which io.write's buffered stdout doesn't. io.write is for running +-- the filter outside of cgit. +local emit = html or io.write + +-- Run md2html and return its output. +local function md2html(markdown) + local input = os.tmpname() + local file = assert(io.open(input, "w")) + file:write(markdown) + file:close() + local handle = io.popen("@md2html@ --github < " .. input, "r") + local output = handle and handle:read("*a") + if handle then + handle:close() + end + os.remove(input) + return output +end + local buffer = "" local should_render = true local current_dir = "" -- Stores the directory prefix of the file being processed @@ -85,7 +105,7 @@ end function filter_close() if not should_render then - io.write("<p><em>Error: Access Denied. Only README.md and documentation markdown files are viewable here.</em></p>") + emit("<p><em>Error: Access Denied. Only README.md and documentation markdown files are viewable here.</em></p>") return end @@ -115,12 +135,10 @@ function filter_close() end end) - -- Pipe everything into md2html - local handle = io.popen("@md2html@ --github", "w") - if handle then - handle:write(processed) - handle:close() + local output = md2html(processed) + if output then + emit(output) else - io.write("<p>Error: Could not execute md2html.</p>") + emit("<p>Error: Could not execute md2html.</p>") end end |
