3 Commits

Author SHA1 Message Date
murat 565d4add81 feat(styling): ul and ol lists 2026-06-16 19:26:14 +03:00
murat 49467fee22 fix(blockquote): force \n 2026-06-16 19:00:52 +03:00
murat e5f4026a68 blockquote line by line checking 2026-06-16 18:48:19 +03:00
+45 -1
View File
@@ -124,9 +124,52 @@ for index, value in ipairs(markdownFiles) do
local content = indexFile
-- STYLING
local function styleLists(s)
local lines = {}
for line in (s .. "\n"):gmatch("([^\n]*)\n") do
table.insert(lines, line)
end
local result = {}
local inUl = false
local inOl = false
for _, line in ipairs(lines) do
local ulItem = line:match("^[%-%*%+]%s+(.*)")
local olItem = line:match("^%d+%.%s+(.*)")
if ulItem then
if inOl then table.insert(result, "</ol>"); inOl = false end
if not inUl then table.insert(result, "<ul>"); inUl = true end
table.insert(result, "<li>" .. ulItem .. "</li>") -- ulItem!
elseif olItem then
if inUl then table.insert(result, "</ul>"); inUl = false end
if not inOl then table.insert(result, "<ol>"); inOl = true end
table.insert(result, "<li>" .. olItem .. "</li>")
else
if inUl then table.insert(result, "</ul>"); inUl = false end
if inOl then table.insert(result, "</ol>"); inOl = false end
table.insert(result, line)
end
end
if inUl then table.insert(result, "</ul>") end
if inOl then table.insert(result, "</ol>") end
return table.concat(result, "\n")
end
local function styling(s)
-- blockquote
s = s:gsub(">%s*(.-)%s*\r?\n", "<blockquote>%1</blockquote>")
local lines = {}
for line in (s .. "\n"):gmatch("([^\n]*)\n?") do
local nline = line:gsub("^>%s*(.*)", "<blockquote>%1</blockquote>")
table.insert(lines, nline)
end
s = table.concat(lines, "\n")
-- lists
s = styleLists(s)
-- line breaks
s = s:gsub("\r?\n", "<br>")
-- headers
@@ -150,6 +193,7 @@ for index, value in ipairs(markdownFiles) do
s = s:gsub("`(.-)`", "<code>%1</code>")
-- horizontal rule
s = s:gsub("%-%-%-", "<hr>")
-- TODO: p for normal text
return s
end