Compare commits
3 Commits
f125640ace
...
565d4add81
| Author | SHA1 | Date | |
|---|---|---|---|
| 565d4add81 | |||
| 49467fee22 | |||
| e5f4026a68 |
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user