3D engine that AI agents drive
Colour code and commands on the site
Nguyen Xuan Anaa5653e3ef41
diff --git a/changes/site-syntax-colors.md b/changes/site-syntax-colors.mdnew file mode 100644index 00000000..4c46740f--- /dev/null+++ b/changes/site-syntax-colors.md@@ -0,0 +1 @@+- Colour the code on the site: the home page example, the MCP command and the install command now use the same syntax colours as the docs, and shell commands colour the program, subcommand, flags, numbers and package specifiers.diff --git a/index.html b/index.htmlindex 549efd24..ee93769b 100644--- a/index.html+++ b/index.html@@ -62,7 +62,7 @@<div class="code-copy"><h2 id="code-title">A scene in a few lines</h2><div class="code-block">- <pre><code id="home-code">import { Renderer67 } from '67js';+ <pre><code id="home-code" data-language="javascript">import { Renderer67 } from '67js';import { loadGltf } from '67js/addons/gltf';import { loadHdri } from '67js/addons/hdri';@@ -98,7 +98,7 @@ renderer.render({ eye: [58, 31, 84], target: [-8, 3, -18] });</code></pre><h2 id="agents-title">Built for agents</h2><p>An agent gets a live scene to edit, render and review.</p><div class="code-block">- <pre><code id="home-mcp">npx 67js-mcp --backend gpu --memory 192</code></pre>+ <pre><code id="home-mcp" data-language="shell">npx 67js-mcp --backend gpu --memory 192</code></pre><button data-copy-code="home-mcp" aria-label="Copy the MCP server command">Copy</button></div></div>diff --git a/src/code-highlight.js b/src/code-highlight.jsnew file mode 100644index 00000000..01637280--- /dev/null+++ b/src/code-highlight.js@@ -0,0 +1,38 @@+import highlight from 'highlight.js/lib/core';+import javascript from 'highlight.js/lib/languages/javascript';+import xml from 'highlight.js/lib/languages/xml';++// highlight.js's bash grammar leaves a plain command such as `npm install pkg` uncoloured, so the site's commands get a+// small grammar of their own: the program, its subcommand, flags, numbers and package specifiers.+function shell() {+ return {+ name: 'Shell',+ contains: [+ { className: 'comment', begin: /#/, end: /$/ },+ { className: 'built_in', begin: /^\s*[\w.-]+/, starts: { end: /$/, returnEnd: true, contains: [+ { className: 'keyword', begin: /(?<=^\s*[\w.-]+\s+)\w[\w-]*/ },+ { className: 'attr', begin: /\s--?[\w-]+/ },+ { className: 'string', begin: /'/, end: /'/ },+ { className: 'string', begin: /"/, end: /"/ },+ { className: 'string', begin: /[\w.-]*@[\w@/.:^~-]+/ },+ { className: 'number', begin: /\b\d+(\.\d+)*\b/ },+ ] } },+ ],+ };+}++highlight.registerLanguage('javascript', javascript);+highlight.registerLanguage('xml', xml);+highlight.registerLanguage('shell', shell);+highlight.registerAliases(['bash', 'sh'], { languageName: 'shell' });++/** Return highlighted HTML for source in a registered language. */+export function highlightCode(source, language) {+ return highlight.highlight(source, { language }).value;+}++/** Colour a code element's own text in place. */+export function highlightElement(element, language) {+ element.innerHTML = highlightCode(element.textContent, language);+ element.classList.add('hljs', `language-${language}`);+}diff --git a/src/documentation.css b/src/documentation.cssindex fcc7438a..7cdf5ed0 100644--- a/src/documentation.css+++ b/src/documentation.css@@ -1,4 +1,3 @@-.documentation { --syntax-string:#9dd1b6; --syntax-keyword:#c8b1ed; --syntax-number:#e8bd88; --syntax-comment:#a0a0a0; --syntax-name:#acc7ed; }.doc-install-link { display:inline-flex; align-items:center; gap:8px; }.documentation .docs-page { display:grid; grid-template-columns:244px minmax(0,780px); justify-content:center; gap:52px; max-width:1440px; margin-inline:auto; padding:36px 40px 64px; }.docs-sidebar { position:sticky; top:calc(var(--navigation-height,80px) + 24px); align-self:start; max-height:calc(100vh - var(--navigation-height,80px) - 48px); overflow-y:auto; padding:0 5px 12px; }@@ -39,11 +38,6 @@.copy-code .icon { width:14px; height:14px; margin:0; }.documentation .docs pre { display:block; padding:17px 20px 22px; margin:0; background:transparent; border:0; border-radius:0; overflow:auto; font-size:13px; line-height:1.75; }.documentation .docs pre code { display:block; overflow:visible; padding:0; color:var(--text); }-.hljs-keyword, .hljs-selector-tag, .hljs-literal { color:var(--syntax-keyword); }-.hljs-string, .hljs-attr, .hljs-template-tag { color:var(--syntax-string); }-.hljs-number, .hljs-symbol { color:var(--syntax-number); }-.hljs-comment { color:var(--syntax-comment); }-.hljs-title, .hljs-built_in, .hljs-tag, .hljs-name { color:var(--syntax-name); }.documentation table { font-size:13px; margin:4px 0 28px; border-collapse:separate; border-spacing:0 5px; }.documentation td, .documentation th { border:0; padding:12px 14px; }.documentation th { font-weight:600; }diff --git a/src/documentation.js b/src/documentation.jsindex 7bc895c3..8c06b622 100644--- a/src/documentation.js+++ b/src/documentation.js@@ -1,14 +1,7 @@import './home.js';import './documentation.css';import guide from '../docs/guide.md?raw';-import highlight from 'highlight.js/lib/core';-import javascript from 'highlight.js/lib/languages/javascript';-import xml from 'highlight.js/lib/languages/xml';-import bash from 'highlight.js/lib/languages/bash';--highlight.registerLanguage('javascript', javascript);-highlight.registerLanguage('xml', xml);-highlight.registerLanguage('bash', bash);+import { highlightCode } from './code-highlight.js';const article = document.querySelector('#doc-article');const topicNavigation = document.querySelector('#doc-toc');@@ -113,7 +106,7 @@ function codeBlock(block, title) {const pre = document.createElement('pre');const code = document.createElement('code');code.className = language ? `hljs language-${language}` : 'hljs';- code.innerHTML = language ? highlight.highlight(source, { language }).value : escapeHtml(source);+ code.innerHTML = language ? highlightCode(source, language) : escapeHtml(source);button.addEventListener('click', () => copyText(button, source, code));header.append(languageLabel, button);pre.append(code);diff --git a/src/home.js b/src/home.jsindex 01bc4c4b..8400542c 100644--- a/src/home.js+++ b/src/home.js@@ -1,6 +1,7 @@import './site.css';import './brand.js';import './site-motion.js';+import { highlightElement } from './code-highlight.js';const copyControls = [];const packageControls = [];@@ -58,6 +59,7 @@ function renderRelease() {document.querySelectorAll('[data-release-status]').forEach(element => { element.dataset.status = state.status; });setText('[data-release-version]', release ? `v${release.version}` : state.status === 'error' ? 'Release unavailable' : 'Loading release');setText('[data-install-command]', release ? installCommand() : state.status === 'error' ? 'Release information is unavailable' : 'Loading the release command…');+ if (release) document.querySelectorAll('[data-install-command]').forEach(element => highlightElement(element, 'shell'));packageControls.forEach(({ name, control }) => control.update({ 'aria-pressed':String(name === state.packageManager) }));document.querySelectorAll('.release-feedback').forEach(element => { element.hidden = state.status !== 'error'; });setText('[data-release-status]', state.status === 'error' ? 'Release information could not load. Retry to get the current files.' : '');@@ -135,6 +137,7 @@ function mountCodeCopyButton(button) {}document.querySelectorAll('[data-copy-code]').forEach(mountCodeCopyButton);+document.querySelectorAll('code[data-language]').forEach(element => highlightElement(element, element.dataset.language));document.querySelectorAll('.example img').forEach(image => {image.addEventListener('error', () => {diff --git a/src/site.css b/src/site.cssindex 3b011611..9735fd5d 100644--- a/src/site.css+++ b/src/site.css@@ -22,6 +22,12 @@--error: #ffb4ab;--invert-border: #ffffff26;--dither-ink: #ff9a62;+ --syntax-keyword: #c9a8ff;+ --syntax-string: #8fe3c0;+ --syntax-number: #ffb877;+ --syntax-flag: #ffc98f;+ --syntax-name: #8cc8ff;+ --syntax-comment: #8a83a3;--dither-strength: 2.2;transition: --glow .9s ease-out;}@@ -63,6 +69,12 @@ body.site h1 { font-size: clamp(40px, 6.2vw, 74px); font-weight: 600; letter-spabody.site h2 { font-size: clamp(26px, 3vw, 36px); font-weight: 600; letter-spacing: -.8px; line-height: 1.2; }body.site h3 { font-size: 16px; font-weight: 600; letter-spacing: -.2px; }body.site code, body.site pre { font-family: var(--mono); }+.hljs-keyword, .hljs-selector-tag, .hljs-literal { color: var(--syntax-keyword); }+.hljs-string, .hljs-template-tag, .hljs-regexp { color: var(--syntax-string); }+.hljs-number, .hljs-symbol { color: var(--syntax-number); }+.hljs-attr { color: var(--syntax-flag); }+.hljs-title, .hljs-built_in, .hljs-tag, .hljs-name { color: var(--syntax-name); }+.hljs-comment { color: var(--syntax-comment); font-style: italic; }body.site :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }body.site ::selection { background: color-mix(in srgb, var(--focus) 24%, transparent); }body.site .icon { width: 18px; height: 18px; margin: 0; }