From 87eee159d42b380458320ca2c9c9a093cab6a69f Mon Sep 17 00:00:00 2001 From: Moon Flower Date: Tue, 30 Dec 2025 22:24:17 +0330 Subject: changes --- index.html | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 99 insertions(+), 20 deletions(-) (limited to 'index.html') diff --git a/index.html b/index.html index aca73cb..73a47ab 100644 --- a/index.html +++ b/index.html @@ -12,6 +12,7 @@ tempo + @@ -28,7 +29,7 @@ } +
tempo is licensed under creative-commons. @@ -100,7 +102,7 @@ chunk = chunk.replace(/\*\*(.*?)\*\*/g, '$1') chunk = chunk.replace(/__(.*?)__/g, '$1') chunk = chunk.replace(/\*(.*?)\*/g, '$1') - chunk = chunk.replace(/\[\[(.*?)\]\]/g, '🔎 “$1”') + chunk = chunk.replace(/\[\[(.*?)\]\]/g, '🔎 "$1"') html += chunk } else { html += `${escapeHTML(parts[i])}` @@ -109,6 +111,46 @@ return html } + async function loadSymbols() { + try { + let response = await fetch('symbols.txt') + if (response.status !== 200) response = await fetch('symbols.txt.html') + if (response.status !== 200) { + console.log('symbols.txt not found, skipping symbol replacement') + return {} + } + + const text = await response.text() + const symbols = {} + + for (const line of text.split('\n')) { + const trimmed = line.trim() + if (!trimmed) continue + + const parts = trimmed.split(/\s+/) + if (parts.length >= 2) { + const symbol = parts[0] + const name = parts.slice(1).join(' ') + symbols[name] = symbol + } + } + + return symbols + } catch (err) { + console.warn('failed to load symbols.txt:', err) + return {} + } + } + + function applySymbols(text, symbols) { + let result = text + for (const [name, symbol] of Object.entries(symbols)) { + const pattern = new RegExp(`\\\\${name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\\\`, 'g') + result = result.replace(pattern, symbol) + } + return result + } + class TempoParser { constructor(rawText) { this.lines = rawText.replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n') @@ -266,25 +308,62 @@ const deftext = escapeHTML(code) return ` -
-
- def - ${escapeHTML(name)} - ${deftext.length === 0 ? `` : `${escapeHTML(code)}`} -
- ${eng ? `[${escapeHTML(eng)}]` : ''} -
- ${descHtml} -
` +
+
+ def + ${escapeHTML(name)} + ${deftext.length === 0 ? `` : `${escapeHTML(code)}`} +
+ ${eng ? `[${escapeHTML(eng)}]` : ''} +
+ ${descHtml} + ` + } + } + + function validateSymbols(text, symbols) { + const usagePattern = /\\([^\\\s]+)\\/g + const usedSymbols = new Set() + let match + + while ((match = usagePattern.exec(text)) !== null) { + usedSymbols.add(match[1]) + } + + const definedSymbols = new Set() + const defPattern = /^def\s+(\S+)/gm + + while ((match = defPattern.exec(text)) !== null) { + console.log('defined:', match[1]) + definedSymbols.add(match[1].replace(/^\\/g, '').replace(/\\$/g, '')) + } + + const missing = [] + for (const name of usedSymbols) { + if (definedSymbols.has(name)) continue + + const symbol = symbols[name] + if (symbol && definedSymbols.has(symbol)) continue + + missing.push(name) + } + + if (missing.length > 0) { + const msg = `undefined symbols detected:\n${missing.map(s => ` • (${symbols[s]}) ${s}`).join('\n')}` + warnings.innerHTML += msg.replace(/\n/g, '
') + console.warn('undefined symbols:', missing) } } async function loadMarkdown() { try { + const symbols = await loadSymbols() let response = await fetch('tempo.md') if (response.status !== 200) response = await fetch('tempo.md.html') - const text = await response.text() + let text = await response.text() + validateSymbols(text, symbols) + text = applySymbols(text, symbols) const parser = new TempoParser(text) parser.tokenize() @@ -356,4 +435,4 @@ - + \ No newline at end of file -- cgit v1.2.3