From c352987645294838b7ea1eaa3cbcaf0994bf9dd0 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 22 Jan 2024 10:18:35 +0100 Subject: Sync from main --- server-katex/filter.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 server-katex/filter.lua (limited to 'server-katex/filter.lua') diff --git a/server-katex/filter.lua b/server-katex/filter.lua new file mode 100644 index 0000000..1010217 --- /dev/null +++ b/server-katex/filter.lua @@ -0,0 +1,23 @@ +function Pandoc(doc) + local tmp_name = os.tmpname() + local math = assert(io.popen("deno run server-katex/math.ts > " .. tmp_name, "w")) + doc:walk({ + Math = function(el) + if el.mathtype == 'DisplayMath' then + assert(math:write("d" .. el.text:gsub("\n", " ") .. "\n")) + else + assert(math:write("i" .. el.text:gsub("\n", " ") .. "\n")) + end + end + }) + math:close() + local tmp = assert(io.open(tmp_name, "r")) + doc = doc:walk({ + Math = function(el) + return pandoc.RawInline(FORMAT, tmp:read()) + end + }) + tmp:close() + os.remove(tmp_name) + return doc +end -- cgit v1.2.3