(function (hirad) { // // hirad - Radiance Syntax Highlighter // // Copyright (c) 2020-2025 Alexis Sellier // const selector = hirad || '.language-radiance'; const keywords = [ 'fn', 'pub', 'if', 'else', 'for', 'while', 'break', 'switch', 'match', 'record', 'union', 'const', 'align', 'let', 'use', 'mod', 'case', 'continue', 'return', 'true', 'false', 'loop', 'extern', 'panic', 'device', 'register', 'catch', 'throw', 'throws', 'at', 'mut', 'nil', 'undefined', 'static', 'in', 'is', 'where', 'as', 'and', 'or', 'xor', 'not', 'try', 'atomic', 'select', 'trait', 'instance', 'assert' ]; const types = ['bool', 'u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'f32', 'void', 'opaque']; // Syntax definition. // // The key becomes the class name of the span around the matched block of code. const syntax = [ ['comment', /(\/\/[^\n]*)/g], ['string' , /("(?:(?!").|\\.)*"|'[^']{1,2}')/g], ['number' , /\b(0x[0-9a-fA-F]+|0b[01]+|[0-9]+(?:\.[0-9]+)?)\b/g], ['ref' , /(&|&'|\*)\b/g], ['delim' , /(->|=>|\(|\)|\{|\}|\[|\])/g], ['builtin', /(@[a-zA-Z]+)/g], ['access' , /(\.|::)/g], ['op' , /(=|!=|\.\.|\+|-|\*|\/|%|\?{1,2}|!{1,2}|>=?|<=?)/g], ['keyword', new RegExp('\\b(' + keywords.join('|') + ')\\b', 'g')], ['type' , new RegExp('\\b(' + types.join('|') + ')\\b', 'g')], ]; const table = {}; // Encode ASCII characters to Braille to avoid conflicts between patterns. const encode = (str) => { const encoded = [...str].map(c => c.charCodeAt(0) <= 127 ? String.fromCharCode(c.charCodeAt(0) + 0x2800) : c ).join(''); table[encoded] = str; return encoded; }; // Decode Braille back to ASCII. const decode = (str) => table[str] || [...str].map(c => { const code = c.charCodeAt(0) - 0x2800; return code >= 0 && code <= 127 ? String.fromCharCode(code) : c; }).join(''); // Escape HTML special characters. const escape = (str) => str.replace(//g, '>'); // Highlight all matching elements. for (const node of document.querySelectorAll(selector)) { for (const child of node.childNodes) { if (child.nodeType !== Node.TEXT_NODE) continue; if (/^\$\s/.test(child.nodeValue.trim())) continue; // Skip shell snippets. for (const [cls, re] of syntax) { child.nodeValue = child.nodeValue.replace(re, (_, m) => '\u00ab' + encode(cls) + '\u00b7' + encode(m) + '\u00b7' + encode(cls) + '\u00bb' ); } } node.innerHTML = node.innerHTML.replace( /\u00ab(.+?)\u00b7(.+?)\u00b7\1\u00bb/g, (_, name, value) => { value = value.replace(/\u00ab[^\u00b7]+\u00b7|\u00b7[^\u00bb]+\u00bb/g, ''); return '' + escape(decode(value)) + ''; } ); } })(window.hirad);