Skip to content

Commit 3f5bb28

Browse files
dwursteisenclaude
andcommitted
Keep toolbar visible on Try it and highlight static code examples
Only hide the code body (.fn-card__code) when clicking Try it, keeping the toolbar visible. Add a highlightLua() JS function that reuses the same regex logic as the tiny-web-editor highlight() to syntax-highlight all static code examples on page load. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 34e0f40 commit 3f5bb28

File tree

1 file changed

+18
-4
lines changed
  • tiny-doc/src/docs/templates/pages

1 file changed

+18
-4
lines changed

tiny-doc/src/docs/templates/pages/api.peb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,30 @@
293293
filterCards();
294294
});
295295

296-
// -- Try it: replace code block with inline tiny-editor
296+
// -- Lua syntax highlighting (same logic as tiny-web-editor highlight())
297+
function highlightLua(text) {
298+
return text
299+
.replace(/(".*?")/g, '<strong class="code_string">$1</strong>')
300+
.replace(/--(.*)/g, '<em class="code_comment">--$1</em>')
301+
.replace(/\b(if|else|elif|end|while|for|in|of|continue|break|return|function|local|do)\b/g, '<strong class="code_keyword">$1</strong>')
302+
.replace(/\b(\d+)/g, '<em class="code_number">$1</em>');
303+
}
304+
305+
// -- Highlight all static code blocks on load
306+
grid.querySelectorAll('.fn-card__code pre').forEach(function (pre) {
307+
pre.innerHTML = highlightLua(pre.textContent);
308+
});
309+
310+
// -- Try it: hide code body, keep toolbar, start editor
297311
grid.addEventListener('click', function (e) {
298312
var btn = e.target.closest('.fn-card__try-btn');
299313
if (!btn) return;
300314
var wrapper = btn.closest('.fn-card__example');
301315
if (!wrapper) return;
302-
var codeBlock = wrapper.querySelector('.fn-card__code-block');
316+
var codeBody = wrapper.querySelector('.fn-card__code');
303317
var editor = wrapper.querySelector('tiny-editor');
304-
if (codeBlock && editor) {
305-
codeBlock.style.display = 'none';
318+
if (codeBody && editor) {
319+
codeBody.style.display = 'none';
306320
editor.dispatchEvent(new Event('play'));
307321
}
308322
});

0 commit comments

Comments
 (0)