Commit c7e90422 by PLN (Algolia)

404: le code des pièces hydra passe en highlight monochrome — une couleur, la…

404: le code des pièces hydra passe en highlight monochrome — une couleur, la syntaxe portée par les graisses (commentaires légers, keywords 700, strings/numbers/appels 600), rien ne tear dans le blend difference ; landing: URLs de sync canoniques /les-femmes/
parent 5a376c1c
...@@ -83,6 +83,34 @@ function bag(sketches, n) { ...@@ -83,6 +83,34 @@ function bag(sketches, n) {
return picked; return picked;
} }
/**
* Monochrome syntax tinting for the code panel: one color, no hues — the
* syntax lives in the font weight alone (light comments, bold keywords,
* semibold strings/numbers/calls over a regular base). The panel sits in a
* difference blend, so any hue would risk tearing; weight never does.
*/
const MONO_TOKEN =
/(\/\/[^\n]*|\/\*[\s\S]*?\*\/)|('(?:\\.|[^'\\])*'|"(?:\\.|[^"\\])*"|`(?:\\.|[^`\\])*`)|\b(const|let|var|function|return|if|else|for|while|new|class|of|in|typeof|import|export|from|default|true|false|null|undefined|await|async)\b|\b(\d+\.?\d*)\b|([A-Za-z_$][\w$]*)(?=\s*\()/g;
function monoSpans(source) {
const out = [];
let last = 0;
let m;
MONO_TOKEN.lastIndex = 0;
while ((m = MONO_TOKEN.exec(source)) !== null) {
if (m.index > last) out.push([source.slice(last, m.index), 400, 1]);
if (m[1]) out.push([m[1], 300, 0.5]); // commentaire : léger, discret
else if (m[2]) out.push([m[2], 600, 1]); // string
else if (m[3]) out.push([m[3], 700, 1]); // keyword : le plus gras
else if (m[4]) out.push([m[4], 600, 1]); // number
else if (m[5]) out.push([m[5], 600, 1]); // appel de fonction
last = m.index + m[0].length;
}
if (last < source.length) out.push([source.slice(last), 400, 1]);
return out;
}
export default function NotFoundHydra({ sketches }) { export default function NotFoundHydra({ sketches }) {
const canvasRef = useRef(null); const canvasRef = useRef(null);
const wrapRef = useRef(null); const wrapRef = useRef(null);
...@@ -270,7 +298,11 @@ export default function NotFoundHydra({ sketches }) { ...@@ -270,7 +298,11 @@ export default function NotFoundHydra({ sketches }) {
fontFamily: 'var(--font-mono, monospace)', fontFamily: 'var(--font-mono, monospace)',
}} }}
> >
{current.source} {monoSpans(current.source).map(([text, weight, opacity], i) => (
<span key={i} style={{ fontWeight: weight, opacity }}>
{text}
</span>
))}
</pre> </pre>
</div> </div>
)} )}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment