Added preview

Added a preview button the the paste page that allows users to
preview their paste before submitting.

Various additions to the imageboard parser to make it more robust
and accept more inputs.
This commit is contained in:
Robin Malley 2020-08-24 21:38:24 +00:00
parent 496066e3aa
commit 55c56969ea
5 changed files with 41 additions and 38 deletions

View File

@ -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

View File

@ -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")

View File

@ -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("^^",[[<sup>%s</sup>]])
--will wrap text "5^^3^^" as "5<sup>3</sup>"
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("<p>%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 = [[
<pinktext on the first line
this is **a big** test with ''italics''!
we need to > sanitize < things that could be tags
like really <b> badly </b>
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 <with injection>
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?
<and after '''it is''' a pinktext
>because of some of these restrictions **bold text
cannot go over multiple lines** in a green text
>greentext on the last line
<pinktext on the last line
]]
]=]
return function(text)
return table.concat({grammar:match(text .. "\n")}," ")
end
--for k,v in pairs({grammar:match(text)}) do
-- print(k,":",v)
--end

View File

@ -25,6 +25,7 @@
<textarea name="text" cols=80 rows=24 class="column"></textarea><br/>
</div>
<input type="submit">
<input type="submit" formtarget="_blank" value="Preview" formaction="https://<%= domain %>/_preview">
</fieldset></form>
<footer class="footer">

View File

@ -21,6 +21,7 @@ int read_story(struct http_request *);
int login(struct http_request *);
int claim(struct http_request *);
int download(struct http_request *);
int preview(struct http_request *);
int style(struct http_request *);
int miligram(struct http_request *);
int do_lua(struct http_request *req, const char *name);
@ -114,6 +115,12 @@ download(struct http_request *req){
return do_lua(req,"download");
}
int
preview(struct http_request *req){
printf("We want to do preview!\n");
return do_lua(req,"preview");
}
int
home(struct http_request *req){
return do_lua(req,"home");