diff --git a/parse.lua b/parse.lua new file mode 100644 index 0000000..d83fd74 --- /dev/null +++ b/parse.lua @@ -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 "\n\n\n"..pageTitle.."\n\n\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,"") + table.insert(newstr,"") + 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,"") + table.insert(newstr,"") + 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,"

") + pendcloseh="

" + 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,"
\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("\n") + fp:close() +end + +fname = droid.primaryvolume().."/Comet/test.txt" +wfname = droid.primaryvolume().."/Comet/parsed.html" +print(getln(fname)) +writeln(wfname,getln(fname)) \ No newline at end of file