Code blocks in SilverBullet have a copy button, but inline code doesn't. This adds a small copy icon after inline code. Clicking it copies the code without the backticks.
The fix has two parts: a script that handles the click, and a style that draws the icon.
CONFIG page, or any page you keep code on.space-lua code block (three backticks followed by space-lua) and paste this code inside it:function inlineCopyInstall()
local win = js.window
if win.sbInlineCopyInstalled then return end
win.sbInlineCopyInstalled = true
win.document.addEventListener("pointerdown", function(e)
local target = e.target
if not target or not target.closest then return end
local el = target.closest(".sb-code")
if not el then return end
-- only inline code, not code blocks
if el.closest(".sb-line-fenced-code, .sb-line-code") then return end
-- the icon sits at the end of the code's last line: only clicks there copy
local rects = el.getClientRects()
if rects.length == 0 then return end
local last = rects.item(rects.length - 1)
local size = tonumber(string.match(tostring(win.getComputedStyle(el).fontSize), "[%d%.]+")) or 16
if e.clientX < last.right - size * 1.4 or e.clientY < last.top or e.clientY > last.bottom then return end
e.preventDefault()
e.stopPropagation()
local text = tostring(el.textContent)
text = string.gsub(text, "^`+", "")
text = string.gsub(text, "`+$", "")
win.navigator.clipboard.writeText(text)
editor.flashNotification("Copied")
end, true)
end
inlineCopyInstall()
STYLES page, or any page you keep styles on.space-style code block (three backticks followed by space-style) and paste this inside it:#sb-main .cm-editor .cm-line:not(.sb-line-fenced-code, .sb-line-code) .sb-code:not(.sb-code .sb-code)::after {
content: "";
display: inline-block;
width: 0.85em;
height: 0.85em;
margin-left: 0.4em;
vertical-align: -0.05em;
background-color: var(--subtle-color);
-webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E") center / contain no-repeat;
mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E") center / contain no-repeat;
opacity: 0.25;
cursor: pointer;
}
#sb-main .cm-editor .cm-line:not(.sb-line-fenced-code, .sb-line-code) .sb-code:not(.sb-code .sb-code):hover::after {
opacity: 0.8;
}
@media (hover: none) {
#sb-main .cm-editor .cm-line:not(.sb-line-fenced-code, .sb-line-code) .sb-code:not(.sb-code .sb-code)::after {
opacity: 0.6;
}
}
System: Reload is not enough here, because the script listens for clicks on the whole page.