smr/src/lua/parser_plain.lua

29 lines
597 B
Lua

--[[
A plain parser that dosen't do much
]]
--Characters to escape in the body text
local escapes = {
["&"] = "&",
["<"] = "&lt;",
[">"] = "&gt;",
['"'] = "&quot;",
["'"] = "&#39;",
["\t"] = "&emsp;",
--Kinda hacky
["\n"] = "<br/><p>",
}
local esctbl = {}
for char,_ in pairs(escapes) do
table.insert(esctbl,char)
end
local escapematch = string.format("([%s])",table.concat(esctbl))
local function sanitize(capture)
return escapes[capture] or capture
end
return function(text)
text = string.gsub(text,escapematch,sanitize)
--text = string.gsub(text,"\n\n","<p>")
return text
end