Compare commits
No commits in common. "2a22f6d2ceacf9712e1f785c68c5169b17bebd5e" and "69bfaa8db0d7cf925d3d64930216ddad248d0136" have entirely different histories.
2a22f6d2ce
...
69bfaa8db0
2
app.lua
2
app.lua
@ -13,8 +13,6 @@ app.layout = require "views.base"
|
|||||||
|
|
||||||
local function inject_constants(req)
|
local function inject_constants(req)
|
||||||
req.constants = constants
|
req.constants = constants
|
||||||
math.randomseed(os.time())
|
|
||||||
req.__cachebust = math.random(99999)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function inject_methods(req)
|
local function inject_methods(req)
|
||||||
|
15
apps/mod.lua
15
apps/mod.lua
@ -1,5 +1,4 @@
|
|||||||
local app = require("lapis").Application()
|
local app = require("lapis").Application()
|
||||||
local babycode = require("lib.babycode")
|
|
||||||
|
|
||||||
local db = require("lapis.db")
|
local db = require("lapis.db")
|
||||||
|
|
||||||
@ -44,18 +43,4 @@ app:post("sort_topics", "/sort-topics", function(self)
|
|||||||
return {redirect_to = self:url_for("sort_topics")}
|
return {redirect_to = self:url_for("sort_topics")}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
app:get("reparse_posts", "/reparse-posts", function(self)
|
|
||||||
db.query("BEGIN")
|
|
||||||
local hist = db.select("* FROM post_history")
|
|
||||||
for _, history in ipairs(hist) do
|
|
||||||
db.query(
|
|
||||||
"UPDATE post_history SET content = ? WHERE post_history.id = ?",
|
|
||||||
babycode.to_html(history.original_markup, require("lapis.html").escape),
|
|
||||||
history.id
|
|
||||||
)
|
|
||||||
end
|
|
||||||
db.query("COMMIT")
|
|
||||||
return "ok"
|
|
||||||
end)
|
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
@ -120,16 +120,6 @@ pre code {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.inline-code {
|
|
||||||
background-color: rgb(38.5714173228, 40.9237007874, 35.6762992126);
|
|
||||||
color: white;
|
|
||||||
padding: 5px 10px;
|
|
||||||
display: inline-block;
|
|
||||||
margin: 4px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-code-container {
|
.copy-code-container {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
width: calc(100% - 4px);
|
width: calc(100% - 4px);
|
||||||
|
@ -8,29 +8,22 @@ function babycode.to_html(s, escape_html)
|
|||||||
-- extract code blocks first and store them as placeholders
|
-- extract code blocks first and store them as placeholders
|
||||||
-- don't want to process bbcode embedded into a code block
|
-- don't want to process bbcode embedded into a code block
|
||||||
local code_blocks = {}
|
local code_blocks = {}
|
||||||
local inline_codes = {}
|
local code_count = 0
|
||||||
s = escape_html(s)
|
|
||||||
local text = s:gsub("%[code%](.-)%[/code%]", function(code)
|
local text = s:gsub("%[code%](.-)%[/code%]", function(code)
|
||||||
local is_inline = code:match("\n") == nil
|
code_count = code_count + 1
|
||||||
if is_inline then
|
-- strip leading and trailing newlines, preserve others
|
||||||
table.insert(inline_codes, code)
|
code_blocks[code_count] = code:gsub("^%s*(.-)%s*$", "%1")
|
||||||
return "\1ICODE:"..#inline_codes.."\1"
|
return "\1CODE:"..code_count.."\1"
|
||||||
else
|
|
||||||
-- strip leading and trailing newlines, preserve others
|
|
||||||
local m, _ = code:gsub("^%s*(.-)%s*$", "%1")
|
|
||||||
table.insert(code_blocks, m)
|
|
||||||
return "\1CODE:"..#code_blocks.."\1"
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- replace `[url=https://example.com]Example[/url] tags
|
-- replace `[url=https://example.com]Example[/url] tags
|
||||||
text = text:gsub("%[url=([^%]]+)%](.-)%[/url%]", function(url, label)
|
text = text:gsub("%[url=([^%]]+)%](.-)%[/url%]", function(url, label)
|
||||||
return '<a href="'..url..'">'..label..'</a>'
|
return '<a href="'..escape_html(url)..'">'..escape_html(label)..'</a>'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- replace `[url]https://example.com[/url] tags
|
-- replace `[url]https://example.com[/url] tags
|
||||||
text = text:gsub("%[url%]([^%]]+)%[/url%]", function(url)
|
text = text:gsub("%[url%]([^%]]+)%[/url%]", function(url)
|
||||||
return '<a href="'..url..'">'..url..'</a>'
|
return '<a href="'..escape_html(url)..'">'..escape_html(url)..'</a>'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- bold, italics, strikethrough
|
-- bold, italics, strikethrough
|
||||||
@ -41,16 +34,13 @@ function babycode.to_html(s, escape_html)
|
|||||||
-- replace loose links
|
-- replace loose links
|
||||||
text = text:gsub("(https?://[%w-_%.%?%.:/%+=&~%@#%%]+[%w-/])", function(url)
|
text = text:gsub("(https?://[%w-_%.%?%.:/%+=&~%@#%%]+[%w-/])", function(url)
|
||||||
if not text:find('<a[^>]*>'..url..'</a>') then
|
if not text:find('<a[^>]*>'..url..'</a>') then
|
||||||
return '<a href="'..url..'">'..url..'</a>'
|
return '<a href="'..escape_html(url)..'">'..escape_html(url)..'</a>'
|
||||||
end
|
end
|
||||||
return url
|
return url
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- rule
|
|
||||||
text = text:gsub("\n+%-%-%-", "<hr>")
|
|
||||||
|
|
||||||
-- normalize newlines, replace them with <br>
|
-- normalize newlines, replace them with <br>
|
||||||
text = text:gsub("\r?\n\r?\n+", "<br>")--:gsub("\r?\n", "<br>")
|
text = text:gsub("\r?\n\r?\n+", "<br>"):gsub("\r?\n", "<br>")
|
||||||
|
|
||||||
-- replace code block placeholders back with their original contents
|
-- replace code block placeholders back with their original contents
|
||||||
text = text:gsub("\1CODE:(%d+)\1", function(n)
|
text = text:gsub("\1CODE:(%d+)\1", function(n)
|
||||||
@ -58,11 +48,6 @@ function babycode.to_html(s, escape_html)
|
|||||||
local button = ("<button type=button class=\"copy-code\" value=\"%s\">Copy</button>"):format(code)
|
local button = ("<button type=button class=\"copy-code\" value=\"%s\">Copy</button>"):format(code)
|
||||||
return "<pre><span class=\"copy-code-container\">" .. button .. "</span><code>"..code.."</code></pre>"
|
return "<pre><span class=\"copy-code-container\">" .. button .. "</span><code>"..code.."</code></pre>"
|
||||||
end)
|
end)
|
||||||
|
|
||||||
text = text:gsub("\1ICODE:(%d+)\1", function (n)
|
|
||||||
local code = inline_codes[tonumber(n)]
|
|
||||||
return "<code class=\"inline-code\">" .. code .. "</code>"
|
|
||||||
end)
|
|
||||||
|
|
||||||
return text
|
return text
|
||||||
end
|
end
|
||||||
|
@ -156,16 +156,6 @@ pre code {
|
|||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.inline-code {
|
|
||||||
background-color: $verydark;
|
|
||||||
color: white;
|
|
||||||
padding: 5px 10px;
|
|
||||||
display: inline-block;
|
|
||||||
margin: 4px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-code-container {
|
.copy-code-container {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
// width: 100%;
|
// width: 100%;
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
<% else %>
|
<% else %>
|
||||||
<title>Porom</title>
|
<title>Porom</title>
|
||||||
<% end %>
|
<% end %>
|
||||||
<link rel="stylesheet" href="<%= "/static/style.css?v=" .. __cachebust %>">
|
<% math.randomseed(os.time()) %>
|
||||||
|
<link rel="stylesheet" href="<%= "/static/style.css?v=" .. math.random(1, 100) %>">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<% render("views.common.topnav") -%>
|
<% render("views.common.topnav") -%>
|
||||||
|
@ -6,16 +6,6 @@
|
|||||||
<li>[s]<del>strikethrough</del>[/s]</li>
|
<li>[s]<del>strikethrough</del>[/s]</li>
|
||||||
<li>[url=https://example.com]<a href="https://example.com">labeled URL</a>[/url]</li>
|
<li>[url=https://example.com]<a href="https://example.com">labeled URL</a>[/url]</li>
|
||||||
<li>[url]<a href="https://unlabeled-url.example.com">https://unlabeled-url.example.com</a>[/url]</li>
|
<li>[url]<a href="https://unlabeled-url.example.com">https://unlabeled-url.example.com</a>[/url]</li>
|
||||||
<li>
|
<li>[code]<code>code block</code>[/code]</li>
|
||||||
[code]with<br>line breaks[/code] will produce a code block:
|
|
||||||
<details>
|
|
||||||
<summary>Show code block example</summary>
|
|
||||||
<pre><span class="copy-code-container"><button type=button class="copy-code" value="with
|
|
||||||
line breaks">Copy</button></span><code>with
|
|
||||||
line breaks</code></pre>
|
|
||||||
</details>
|
|
||||||
</li>
|
|
||||||
<li>[code]<code class="inline-code">with no line breaks</code>[/code]</li>
|
|
||||||
<li><code class="inline-code">---</code> will create a horizontal rule for separating content</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</details>
|
</details>
|
||||||
|
Loading…
Reference in New Issue
Block a user