51 linhas
1.1 KiB
Lua
51 linhas
1.1 KiB
Lua
local md = {}
|
|
function md.parse(md)
|
|
local it = {}
|
|
it.l = {}
|
|
it[#it+1] = {["content"]="",["bold"]=false,["italic"]=false}
|
|
local lc,llc = "",""
|
|
local function newpart()
|
|
it[#it+1] = {["content"]="",["bold"]=it[#it].bold,["italic"]=it[#it].italic}
|
|
end
|
|
newpart()
|
|
local lm = false
|
|
for c in md:gmatch(".") do
|
|
if c == "*" then
|
|
if lc == "*" then
|
|
it[#it].italic = false
|
|
it[#it].italic = it[#it-1].italic
|
|
it[#it].bold = not it[#it].bold
|
|
else
|
|
newpart()
|
|
it[#it].italic = not it[#it].italic
|
|
end
|
|
elseif c == "[" then
|
|
newpart()
|
|
elseif c == "(" and lc == "]" then
|
|
lm = true
|
|
it[#it].content = it[#it].content:sub(1,-2)
|
|
it[#it].address = ""
|
|
elseif c == ")" and lm then
|
|
lm = false
|
|
it.l[#it.l+1] = it[#it].address
|
|
it[#it].addrid = #it.l
|
|
newpart()
|
|
else
|
|
if not lm then
|
|
it[#it].content = it[#it].content .. c
|
|
else
|
|
it[#it].address = it[#it].address .. c
|
|
end
|
|
end
|
|
llc = lc
|
|
lc = c
|
|
end
|
|
for k,v in pairs(it) do
|
|
if v.content then
|
|
v.content = v.content:gsub("\n","\r\n")
|
|
end
|
|
end
|
|
return it
|
|
end
|
|
return md
|