You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.1 KiB
Lua
87 lines
2.1 KiB
Lua
|
|
function len(x)
|
|
return string.len(x)
|
|
end
|
|
function at(s,p)
|
|
return string.sub(s,p,p)
|
|
end
|
|
function find(s,n)
|
|
string.find()
|
|
end
|
|
|
|
function rhtml(pageTitle)
|
|
print("Enter page's title:")
|
|
pageTitle=io.read("*a")
|
|
return "<!DOCTYPE html>\n<html>\n<head>\n<title>"..pageTitle.."</title>\n</head>\n<body>\n"
|
|
end
|
|
|
|
function parse(s)
|
|
newstr={}
|
|
for i = 1,len(s),1 do
|
|
cc = at(s,i)
|
|
if cc=="*" then
|
|
if star==true then
|
|
table.insert(newstr,starpos,"<em>")
|
|
table.insert(newstr,"</em>")
|
|
star = false
|
|
starpos=nil
|
|
elseif star==false or star==nil then
|
|
star = true
|
|
starpos=i
|
|
end
|
|
elseif cc=="_" then
|
|
if undscr==true then
|
|
table.insert(newstr,undscrpos,"<u>")
|
|
table.insert(newstr,"</u>")
|
|
undscr = false
|
|
undscrpos = nil
|
|
elseif undscr==false or undscr==nil then
|
|
undscr = true
|
|
undscrpos = i
|
|
end
|
|
-- headers conditions ============== headers
|
|
elseif cc=="#" and i<=3 then
|
|
if i==1 and string.find(s,"###") == 1 then
|
|
table.insert(newstr,"<h1>")
|
|
pendcloseh="</h1>"
|
|
elseif string.find(s,"###") == nil then
|
|
table.insert(newstr,cc)
|
|
end
|
|
-- end header cond ~~~~~~~~~~~~~~~~~~~~
|
|
-- (Experimemtal Color test) here
|
|
--:-)=========== < ----
|
|
else
|
|
table.insert(newstr,cc)
|
|
end
|
|
end
|
|
if pendcloseh ~= nil then
|
|
table.insert(newstr,pendcloseh)
|
|
pendcloseh=nil
|
|
end
|
|
return table.concat(newstr)
|
|
end
|
|
|
|
function getln(fn)
|
|
lnlist={}
|
|
fp = io.open(fn,"r")
|
|
for l in fp:lines("l") do
|
|
table.insert(lnlist,parse(l))
|
|
end
|
|
fp:close()
|
|
return table.concat(lnlist,"<br />\n")
|
|
end
|
|
|
|
function writeln(fn,lines)
|
|
fp = io.open(fn,"w")
|
|
fp:write(rhtml())
|
|
if fp:write(lines) ~= false then
|
|
print("\nWrote file with sucess.")
|
|
end
|
|
fp:write("</body>\n</html>")
|
|
fp:close()
|
|
end
|
|
|
|
fname = droid.primaryvolume().."/Comet/test.txt"
|
|
wfname = droid.primaryvolume().."/Comet/parsed.html"
|
|
print(getln(fname))
|
|
writeln(wfname,getln(fname)) |