add code blocks + copy

This commit is contained in:
2025-05-24 05:12:46 +03:00
parent 66318698e5
commit 69bfaa8db0
5 changed files with 90 additions and 3 deletions

View File

@ -44,7 +44,9 @@ function babycode.to_html(s, escape_html)
-- replace code block placeholders back with their original contents
text = text:gsub("\1CODE:(%d+)\1", function(n)
return "<pre><code>"..code_blocks[tonumber(n)].."</code></pre>"
local code = code_blocks[tonumber(n)]
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>"
end)
return text