[fix](trx-frontend-http): robust ft8 grid highlighting
Co-authored-by: Codex <codex@openai.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -31,12 +31,13 @@ function addFt8Message(msg) {
|
||||
function renderFt8Message(message) {
|
||||
const parts = message.split(/(\\s+)/);
|
||||
return parts.map((part) => {
|
||||
const token = part.trim();
|
||||
if (!token) return escapeHtml(part);
|
||||
const stripped = token.replace(/[^A-Za-z0-9]/g, "");
|
||||
const grid = stripped.toUpperCase();
|
||||
if (/^\\s+$/.test(part)) return part;
|
||||
const m = part.match(/^([^A-Za-z0-9]*)([A-Za-z0-9]+)([^A-Za-z0-9]*)$/);
|
||||
if (!m) return escapeHtml(part);
|
||||
const [, lead, core, tail] = m;
|
||||
const grid = core.toUpperCase();
|
||||
if (/^[A-R]{2}\\d{2}(?:[A-X]{2})?$/.test(grid)) {
|
||||
return part.replace(token, `<span class="ft8-locator">[${grid}]</span>`);
|
||||
return `${escapeHtml(lead)}<span class="ft8-locator">[${grid}]</span>${escapeHtml(tail)}`;
|
||||
}
|
||||
return escapeHtml(part);
|
||||
}).join("");
|
||||
@@ -45,7 +46,9 @@ function renderFt8Message(message) {
|
||||
function extractFirstGrid(message) {
|
||||
const parts = message.split(/\\s+/);
|
||||
for (const part of parts) {
|
||||
const grid = part.replace(/[^A-Za-z0-9]/g, "").toUpperCase();
|
||||
const m = part.match(/[A-Za-z0-9]+/);
|
||||
if (!m) continue;
|
||||
const grid = m[0].toUpperCase();
|
||||
if (/^[A-R]{2}\\d{2}(?:[A-X]{2})?$/.test(grid)) {
|
||||
return grid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user