Upload files to ''
upload
This commit is contained in:
parent
22790532ae
commit
45079e8143
87
parse.lua
Normal file
87
parse.lua
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
|
||||||
|
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))
|
Loading…
Reference in New Issue
Block a user