smr/src/lua/parser_plain.lua

29 lines
597 B
Lua
Raw Permalink Normal View History

2020-12-23 07:02:02 +01:00
--[[
A plain parser that dosen't do much
]]
2020-05-16 01:10:11 +02:00
--Characters to escape in the body text
local escapes = {
["&"] = "&",
["<"] = "&lt;",
[">"] = "&gt;",
['"'] = "&quot;",
["'"] = "&#39;",
2020-12-24 19:43:19 +01:00
["\t"] = "&emsp;",
2020-05-16 01:10:11 +02:00
--Kinda hacky
2021-01-04 04:48:36 +01:00
["\n"] = "<br/><p>",
2020-05-16 01:10:11 +02:00
}
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
2020-05-16 01:10:11 +02:00
end