fix nested quotes and alter linebreak parsing
This commit is contained in:
parent
6eee661b58
commit
94f58fef73
@ -23,6 +23,10 @@ function babycode.to_html(s, escape_html)
|
||||
end
|
||||
end)
|
||||
|
||||
text = text:gsub(" %s?\r?\n", "<br>")
|
||||
-- normalize newlines
|
||||
text = text:gsub("\r?\n\r?\n+", "<br>")
|
||||
|
||||
local url_tags = {}
|
||||
-- replace `[url=https://example.com]Example[/url] tags
|
||||
text = text:gsub("%[url=([^%]]+)%](.-)%[/url%]", function(url, label)
|
||||
@ -30,17 +34,15 @@ function babycode.to_html(s, escape_html)
|
||||
return "\1URL:"..#url_tags.."\1"
|
||||
end)
|
||||
|
||||
-- replace `[url]https://example.com[/url] tags
|
||||
-- text = text:gsub("%[url%]([^%]]+)%[/url%]", function(url)
|
||||
-- return '<a href="'..url..'">'..url..'</a>'
|
||||
-- end)
|
||||
|
||||
-- bold, italics, strikethrough
|
||||
text = text:gsub("%[b%](.-)%[/b%]", "<strong>%1</strong>")
|
||||
text = text:gsub("%[i%](.-)%[/i%]", "<em>%1</em>")
|
||||
text = text:gsub("%[s%](.-)%[/s%]", "<del>%1</del>")
|
||||
|
||||
text = text:gsub("%[quote%](.-)%[/quote%]", "<blockquote>%1</blockquote>")
|
||||
-- these can be nested, so replace open and closed separately
|
||||
-- text = text:gsub("%[quote%]", "<blockquote>")
|
||||
-- text = text:gsub("%[/quote%]", "</blockquote>")
|
||||
text = text:gsub("%[(/?)quote%]", "<%1blockquote>")
|
||||
|
||||
-- replace loose links
|
||||
text = text:gsub("(https?://[%w-_%.%?%.:/%+=&~%@#%%]+[%w-/])", function(url)
|
||||
@ -58,9 +60,6 @@ function babycode.to_html(s, escape_html)
|
||||
-- rule
|
||||
text = text:gsub("\n+%-%-%-", "<hr>")
|
||||
|
||||
-- normalize newlines, replace them with <br>
|
||||
text = text:gsub("\r?\n\r?\n+", "<br>")--:gsub("\r?\n", "<br>")
|
||||
|
||||
-- replace code block placeholders back with their original contents
|
||||
text = text:gsub("\1CODE:(%d+)\1", function(n)
|
||||
local code = code_blocks[tonumber(n)]
|
||||
|
@ -73,4 +73,22 @@ return {
|
||||
schema.add_column("users", "signature_original_markup", types.text{default = ""})
|
||||
schema.add_column("users", "signature_rendered", types.text{default = ""})
|
||||
end,
|
||||
|
||||
[11] = function ()
|
||||
local render = require("lib.babycode").to_html
|
||||
local html_escape = require("lapis.html").escape
|
||||
local phs = db.query("SELECT * from post_history")
|
||||
local users = db.query("SELECT * from users")
|
||||
db.query("BEGIN")
|
||||
|
||||
for _, post_history in ipairs(phs) do
|
||||
db.query("UPDATE post_history SET content = ? WHERE id = ?", render(post_history.original_markup, html_escape), post_history.id)
|
||||
end
|
||||
|
||||
for _, user in ipairs(users) do
|
||||
db.query("UPDATE users SET signature_rendered = ? WHERE id = ?", render(user.signature_original_markup, html_escape), user.id)
|
||||
end
|
||||
|
||||
db.query("COMMIT")
|
||||
end,
|
||||
}
|
||||
|
@ -64,14 +64,11 @@
|
||||
</div>
|
||||
<div class="post-content">
|
||||
<% if not edit then %>
|
||||
<div class="post-inner">
|
||||
<%- post.content %>
|
||||
</div>
|
||||
<div class="post-inner"><%- post.content %></div>
|
||||
<% if render_sig and #post.signature_rendered > 0 then %>
|
||||
<div class="signature-container">
|
||||
<hr>
|
||||
<%- post.signature_rendered %>
|
||||
</div>
|
||||
<%- post.signature_rendered %></div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<% render("views.common.babycode-editor", {
|
||||
|
Loading…
Reference in New Issue
Block a user