Compare commits
2 Commits
1e9809e4b2
...
07a65e9633
Author | SHA1 | Date | |
---|---|---|---|
07a65e9633 | |||
a2d3672fa8 |
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
let ta = document.getElementById("post_content");
|
let ta = document.getElementById("babycode-content");
|
||||||
const buttonBold = document.getElementById("post-editor-bold");
|
const buttonBold = document.getElementById("post-editor-bold");
|
||||||
const buttonItalics = document.getElementById("post-editor-italics");
|
const buttonItalics = document.getElementById("post-editor-italics");
|
||||||
const buttonStrike = document.getElementById("post-editor-strike");
|
const buttonStrike = document.getElementById("post-editor-strike");
|
@ -23,15 +23,17 @@ function babycode.to_html(s, escape_html)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
local url_tags = {}
|
||||||
-- 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>'
|
table.insert(url_tags, {url = url, label = label})
|
||||||
|
return "\1URL:"..#url_tags.."\1"
|
||||||
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="'..url..'">'..url..'</a>'
|
||||||
end)
|
-- end)
|
||||||
|
|
||||||
-- bold, italics, strikethrough
|
-- bold, italics, strikethrough
|
||||||
text = text:gsub("%[b%](.-)%[/b%]", "<strong>%1</strong>")
|
text = text:gsub("%[b%](.-)%[/b%]", "<strong>%1</strong>")
|
||||||
@ -48,6 +50,11 @@ function babycode.to_html(s, escape_html)
|
|||||||
return url
|
return url
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
text = text:gsub("\1URL:(%d+)\1", function(n)
|
||||||
|
local url = url_tags[tonumber(n)]
|
||||||
|
return ("<a href=%s>%s</a>"):format(url.url, url.label)
|
||||||
|
end)
|
||||||
|
|
||||||
-- rule
|
-- rule
|
||||||
text = text:gsub("\n+%-%-%-", "<hr>")
|
text = text:gsub("\n+%-%-%-", "<hr>")
|
||||||
|
|
||||||
|
@ -4,5 +4,5 @@
|
|||||||
<button type=button id="post-editor-strike" title="Insert Strikethrough">S</button>
|
<button type=button id="post-editor-strike" title="Insert Strikethrough">S</button>
|
||||||
<button type=button id="post-editor-code" title="Insert Code block">Code</button>
|
<button type=button id="post-editor-code" title="Insert Code block">Code</button>
|
||||||
</span>
|
</span>
|
||||||
<textarea class="babycode-editor" name="<%= ta_name %>" id="<%= ta_id or "post_content" %>" placeholder="<%= ta_placeholder or "Post body"%>" <%= not optional and "required" or "" %>><%- prefill or "" %></textarea>
|
<textarea class="babycode-editor" name="<%= ta_name %>" id="babycode-content" placeholder="<%= ta_placeholder or "Post body"%>" <%= not optional and "required" or "" %>><%- prefill or "" %></textarea>
|
||||||
<script src="/static/js/post-editor.js"></script>
|
<script src="/static/js/babycode-editor.js"></script>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<details>
|
<details>
|
||||||
<summary>babycode guide</summary>
|
<summary>babycode guide</summary>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>Loose links will be converted to clickable links automatically</li>
|
||||||
<li>[b]<b>bold</b>[/b]</li>
|
<li>[b]<b>bold</b>[/b]</li>
|
||||||
<li>[i]<i>italic</i>[/i]</li>
|
<li>[i]<i>italic</i>[/i]</li>
|
||||||
<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>
|
<li>
|
||||||
[code]with<br>line breaks[/code] will produce a code block:
|
[code]with<br>line breaks[/code] will produce a code block:
|
||||||
<details>
|
<details>
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
<form method="post" action="">
|
<form method="post" action="">
|
||||||
<label for="status">Status</label>
|
<label for="status">Status</label>
|
||||||
<input type="text" id="status" name="status" value="<%= me.status %>" maxlength="70" placeholder="Will be shown under your username. Max 70 characters">
|
<input type="text" id="status" name="status" value="<%= me.status %>" maxlength="70" placeholder="Will be shown under your username. Max 70 characters">
|
||||||
<label for="signature">Signature</label><br>
|
<label for="babycode-content">Signature</label><br>
|
||||||
<% render("views.common.babycode-editor-component", {ta_name = "signature", ta_id = "signature", prefill = me.signature_original_markup, ta_placeholder = "Will be shown under each of your posts", optional = true}) %>
|
<% render("views.common.babycode-editor-component", {ta_name = "signature", prefill = me.signature_original_markup, ta_placeholder = "Will be shown under each of your posts", optional = true}) %>
|
||||||
<input type="submit" value="Save settings">
|
<input type="submit" value="Save settings">
|
||||||
</form>
|
</form>
|
||||||
<div>
|
<div>
|
||||||
|
Loading…
Reference in New Issue
Block a user