Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 87bbceb647 | |||
| 1aa5380836 |
@@ -51,7 +51,7 @@ for index, file in ipairs(markdownFiles) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- fill options table
|
-- fill options table
|
||||||
for i, value in ipairs(lines) do
|
for _, value in ipairs(lines) do
|
||||||
if value:sub(value:len(), value:len()) == "\n" then
|
if value:sub(value:len(), value:len()) == "\n" then
|
||||||
value = value:sub(1, value:find("\n")-1)
|
value = value:sub(1, value:find("\n")-1)
|
||||||
end
|
end
|
||||||
@@ -73,7 +73,7 @@ for index, file in ipairs(markdownFiles) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- replace markdownFiles.content with md file content
|
-- replace markdownFiles.content with md file content
|
||||||
for index, value in ipairs(markdownFiles) do
|
for index, _ in ipairs(markdownFiles) do
|
||||||
local f = io.open(markdownFiles[index].filePath)
|
local f = io.open(markdownFiles[index].filePath)
|
||||||
if f then
|
if f then
|
||||||
local content = f:read("*a")
|
local content = f:read("*a")
|
||||||
@@ -87,7 +87,7 @@ for index, value in ipairs(markdownFiles) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for index, value in ipairs(markdownFiles) do
|
for index, _ in ipairs(markdownFiles) do
|
||||||
print("---------------")
|
print("---------------")
|
||||||
-- print file path with index
|
-- print file path with index
|
||||||
print(index .. ': ' .. markdownFiles[index].filePath)
|
print(index .. ': ' .. markdownFiles[index].filePath)
|
||||||
@@ -116,7 +116,7 @@ local siteTitle
|
|||||||
lfs.rmdir("public")
|
lfs.rmdir("public")
|
||||||
lfs.mkdir("public")
|
lfs.mkdir("public")
|
||||||
|
|
||||||
for index, value in ipairs(markdownFiles) do
|
for index, _ in ipairs(markdownFiles) do
|
||||||
local workDir = lfs.currentdir()
|
local workDir = lfs.currentdir()
|
||||||
-- create html file for that md file
|
-- create html file for that md file
|
||||||
local htmlFile = io.open(workDir .. "/public/" .. markdownFiles[index].fileName .. ".html", 'w')
|
local htmlFile = io.open(workDir .. "/public/" .. markdownFiles[index].fileName .. ".html", 'w')
|
||||||
@@ -160,6 +160,37 @@ for index, value in ipairs(markdownFiles) do
|
|||||||
|
|
||||||
return table.concat(result, "\n")
|
return table.concat(result, "\n")
|
||||||
end
|
end
|
||||||
|
local function styleParagraph(s)
|
||||||
|
local lines = {}
|
||||||
|
for line in (s .. "\n"):gmatch("([^\n]*)\n") do
|
||||||
|
table.insert(lines, line)
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = {}
|
||||||
|
local pLines = {}
|
||||||
|
|
||||||
|
local function flushP()
|
||||||
|
if #pLines > 0 then
|
||||||
|
table.insert(result, "<p>" .. table.concat(pLines, "\n") .. "</p>")
|
||||||
|
pLines = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, line in ipairs(lines) do
|
||||||
|
local isBlock = line:match("^<") or line:match("^#")
|
||||||
|
local isEmpty = line:match("^%s*$")
|
||||||
|
|
||||||
|
if isBlock or isEmpty then
|
||||||
|
flushP()
|
||||||
|
table.insert(result, line)
|
||||||
|
else
|
||||||
|
table.insert(pLines, line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
flushP()
|
||||||
|
|
||||||
|
return table.concat(result, "\n")
|
||||||
|
end
|
||||||
local function styling(s)
|
local function styling(s)
|
||||||
-- blockquote
|
-- blockquote
|
||||||
local lines = {}
|
local lines = {}
|
||||||
@@ -170,15 +201,23 @@ for index, value in ipairs(markdownFiles) do
|
|||||||
s = table.concat(lines, "\n")
|
s = table.concat(lines, "\n")
|
||||||
-- lists
|
-- lists
|
||||||
s = styleLists(s)
|
s = styleLists(s)
|
||||||
|
-- paragraph
|
||||||
|
s = styleParagraph(s)
|
||||||
|
s = s:gsub("<p></p>", "")
|
||||||
-- line breaks
|
-- line breaks
|
||||||
s = s:gsub("\r?\n", "<br>")
|
s = s:gsub("\r?\n", "<br>")
|
||||||
-- remove <br> tags around block elements
|
-- remove <br> tags around block elements
|
||||||
s = s:gsub("(</?[uo]l>)<br>", "%1")
|
local blockTags = { "ul", "ol", "li", "blockquote", "p",
|
||||||
s = s:gsub("<br>(</?[uo]l>)", "%1")
|
"h1", "h2", "h3", "h4", "h5", "h6", "hr" }
|
||||||
s = s:gsub("(</?li>)<br>", "%1")
|
for _, tag in ipairs(blockTags) do
|
||||||
s = s:gsub("<br>(</?li>)", "%1")
|
s = s:gsub("(</" .. tag .. ">)<br>", "%1")
|
||||||
s = s:gsub("(</?blockquote>)<br>", "%1")
|
s = s:gsub("<br>(</" .. tag .. ">)", "%1")
|
||||||
s = s:gsub("<br>(</?blockquote>)", "%1")
|
s = s:gsub("(<" .. tag .. ">)<br>", "%1")
|
||||||
|
s = s:gsub("<br>(<" .. tag .. ">)", "%1")
|
||||||
|
end
|
||||||
|
-- self-closing hr
|
||||||
|
s = s:gsub("(<hr>)<br>", "%1")
|
||||||
|
s = s:gsub("<br>(<hr>)", "%1")
|
||||||
-- headers
|
-- headers
|
||||||
s = s:gsub("######%s*(.-)%s*<br>", "<h6>%1</h6>")
|
s = s:gsub("######%s*(.-)%s*<br>", "<h6>%1</h6>")
|
||||||
s = s:gsub("#####%s*(.-)%s*<br>", "<h5>%1</h5>")
|
s = s:gsub("#####%s*(.-)%s*<br>", "<h5>%1</h5>")
|
||||||
|
|||||||
Reference in New Issue
Block a user