-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathopencode-prompt.lua
More file actions
79 lines (70 loc) · 2.42 KB
/
opencode-prompt.lua
File metadata and controls
79 lines (70 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- Lua filter: 将自定义代码块渲染为带标签和复制按钮的样式框
-- 支持: ```opencode ```agent ```skill ```bash
local block_types = {
opencode = { label = "▶ Claude Code", css = "opencode-block" },
agent = { label = "▶ Agent", css = "agent-block" },
skill = { label = "▶ Skill", css = "skill-block" },
}
local terminal_types = {
bash = true,
}
local function escape_html(s)
return s
:gsub("&", "&")
:gsub("<", "<")
:gsub(">", ">")
:gsub('"', """)
end
function CodeBlock(el)
-- 终端窗口样式(bash)
for lang, _ in pairs(terminal_types) do
if el.classes:includes(lang) then
local code = escape_html(el.text)
local html = string.format([[
<div class="terminal-block">
<div class="terminal-header">
<span class="terminal-dots">
<span class="terminal-dot red"></span>
<span class="terminal-dot yellow"></span>
<span class="terminal-dot green"></span>
</span>
<button class="terminal-copy" onclick="
var code = this.closest('.terminal-block').querySelector('code').textContent;
navigator.clipboard.writeText(code).then(function() {
var btn = event.target;
btn.textContent = '已复制 ✓';
btn.classList.add('copied');
setTimeout(function() { btn.textContent = '复制'; btn.classList.remove('copied'); }, 2000);
});
">复制</button>
</div>
<pre><code>%s</code></pre>
</div>]], code)
return pandoc.RawBlock("html", html)
end
end
-- 语义化代码块样式(opencode / agent / skill)
for lang, cfg in pairs(block_types) do
if el.classes:includes(lang) then
local code = escape_html(el.text)
local css = cfg.css
local html = string.format([[
<div class="custom-code-block %s">
<div class="custom-code-header">
<span class="custom-code-label">%s</span>
<button class="custom-code-copy" onclick="
var code = this.closest('.custom-code-block').querySelector('code').textContent;
navigator.clipboard.writeText(code).then(function() {
var btn = event.target;
btn.textContent = '已复制 ✓';
btn.classList.add('copied');
setTimeout(function() { btn.textContent = '复制'; btn.classList.remove('copied'); }, 2000);
});
">复制</button>
</div>
<pre><code>%s</code></pre>
</div>]], css, cfg.label, code)
return pandoc.RawBlock("html", html)
end
end
end