diff --git a/conf/smr.conf b/conf/smr.conf index 9c960a8..4394059 100644 --- a/conf/smr.conf +++ b/conf/smr.conf @@ -42,6 +42,7 @@ domain * { route /_login login route /_claim claim route /_download download + route /_preview preview # Leading ^ is needed for dynamic routes, kore says the route is dynamic if it does not start with '/' route ^/[^_].* read_story @@ -64,6 +65,12 @@ domain * { validate pasteas v_subdomain validate markup v_markup } + params post /_preview { + validate title v_any + validate text v_any + validate pasteas v_subdomain + validate markup v_markup + } params get ^/[^_].* { validate comments v_bool #validate story v_storyid diff --git a/src/lua/init.lua b/src/lua/init.lua index 84ea981..5c9b87a 100644 --- a/src/lua/init.lua +++ b/src/lua/init.lua @@ -1022,4 +1022,24 @@ function download(req) http_response(req,200,text) end +function preview(req) + print("We want to preview a paste!") + local host = http_request_get_host(req) + local path = http_request_get_path(req) + http_request_populate_post(req) + local title = assert(http_argument_get_string(req,"title")) + local text = assert(http_argument_get_string(req,"text")) + local markup = assert(http_argument_get_string(req,"markup")) + print("title:",title,"text:",text,"markup:",markup) + local parsed = parsers[markup](text) + local ret = pages.read{ + domain = domain, + title = title, + author = "preview", + idp = "preview", + text = parsed, + } + http_response(req,200,ret) +end + print("Done with init.lua") diff --git a/src/lua/parser_imageboard.lua b/src/lua/parser_imageboard.lua index d1797a7..77809dd 100644 --- a/src/lua/parser_imageboard.lua +++ b/src/lua/parser_imageboard.lua @@ -1,4 +1,3 @@ - local lpeg = require("lpeg") lpeg.locale(lpeg) local V,P,C,S,B,Cs = lpeg.V,lpeg.P,lpeg.C,lpeg.S,lpeg.B,lpeg.Cs @@ -35,8 +34,8 @@ local word = Cs((1 - special)^1) * space / sanitize --ex wrap("^^",[[%s]]) --will wrap text "5^^3^^" as "53" local function wrap(seq,format) - return P(seq) * Cs(((1 - P(seq)) * space)^1) * P(seq) * space / function(a) - return string.format(format,sanitize(a)) + return P(seq) * Cs(((V"marked" + word + P"\n"))^1) * P(seq) / function(a) + return string.format(format,a) end end @@ -45,7 +44,8 @@ end local function tag(name,format) local start_tag = P(string.format("[%s]",name)) local end_tag = P(string.format("[/%s]",name)) - return start_tag * Cs(((1 - end_tag) * space)^1) * end_tag * space / function(a) + return start_tag * Cs(((1 - end_tag))^1) * end_tag / function(a) + print("sanatizing tag:",name,"data:",a) return string.format(format,sanitize(a)) end end @@ -70,45 +70,13 @@ local grammar = P{ marked = V"spoiler" + V"bold" + V"italic" + V"underline" + V"heading" + V"strike" + V"spoiler2" + V"code", plainline = (V"marked" + word)^0, line = Cs(V"greentext" + V"pinktext" + V"plainline" + P"") * P"\n" / function(a) + print("matched line:",a) return string.format("

%s",a) end, - ending = C(P(1)^0) / sanitize, + ending = C(P(1)^0) / function(a) print("failed with ending:", a) return sanitize(a) end, chunk = V"line"^0 * V"plainline" * V"ending" } ---[=[ -local text = [[ - sanitize < things that could be tags -like really badly -words can include any'single item without=penalty -Can you use '''one tag ==within== another tag'''? -let's see if [spoiler]spoiler tags work[/spoiler] -things might even __go over -multiple lines__ blah -Let's test out those [code] -code tag,s and see how well -they work - here's ome - preformated - text -[/code] ->Or have blank lines - -one important thing is that greentext > should not start in the middle of a line ->this next line is a green text, what if I include **markup** inside it? -because of some of these restrictions **bold text -cannot go over multiple lines** in a green text ->greentext on the last line -
+