From 6b7db793a76edb9e22da59048e5518ccf7337c85 Mon Sep 17 00:00:00 2001 From: AriaEdo Date: Thu, 5 Nov 2026 16:29:05 +0700 Subject: [PATCH] feat: fill $PROJECT references with the reader's project ID Treat $PROJECT as an alias of your-project-id so commands like --project $PROJECT show the reader's value. Assignments ($PROJECT = "your-project-id") are left as written, checking text past Shiki's span split. Update the README rules to match. --- README.md | 4 ++-- docs-vars.js | 27 ++++++++++++++++++++------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index af1c882..fb7fee6 100644 --- a/README.md +++ b/README.md @@ -72,9 +72,9 @@ NAMESPACE="default" Rules: - Write the token exactly, in lowercase. Variants such as `my-project`, `my-project-id`, ``, `` or `ORG_ID` are not replaced. -- `PROJECT_ID` and `$PROJECT_ID` are aliases of `your-project-id` and get the same value (the MetricsQL queries in the observability pages use `PROJECT_ID`). `${PROJECT_ID}`, `MY_PROJECT_ID` and `PROJECT_ID_2` are not replaced. +- `PROJECT_ID`, `$PROJECT_ID` and `$PROJECT` are aliases of `your-project-id` and get the same value (the MetricsQL queries in the observability pages use `PROJECT_ID`). `${PROJECT_ID}`, `${PROJECT}`, `MY_PROJECT_ID`, `PROJECT_ID_2` and a bare `PROJECT` are not replaced, nor is `$PROJECT` on the left of an assignment (`$PROJECT = "your-project-id"`). - Don't wrap a token in `<…>`. Shiki reads `<` as a shell redirect and splits the token across several spans, so it can't be replaced. -- Replace values only, never variable references: `PROJECT="your-project-id"` uses the token, `--project $PROJECT` stays. +- Put the token in values, not in variable references: write `PROJECT="your-project-id"` and `--project $PROJECT`, never `--project your-project-id`. The reader's value still shows in `--project $PROJECT`, because `$PROJECT` is an alias. - Use `your-email` only for the reader's own account. Someone else's identity (an audit filter, an allowed-users list) keeps an example address like `alice@example.com`. - Other placeholders (`ALB_NAME`, `INSTANCE_NAME`, `my-zone`, `example.com`) are fine. They are never replaced, so readers still swap them by hand. - Prose that explains flag syntax, like ``--project ``, can keep the angle brackets. It isn't a value to copy. diff --git a/docs-vars.js b/docs-vars.js index 7f9c7e0..3ce9686 100644 --- a/docs-vars.js +++ b/docs-vars.js @@ -14,12 +14,17 @@ var VAR_CLASS = 'datum-var'; // A whole token only: `your-project-id-2` is someone's own name, not a token. // `$` and `{` before it are excluded so `${PROJECT_ID}` stays as written. + // `$PROJECT` being assigned (PowerShell `$PROJECT = "your-project-id"`) stays + // too, or the copied code would read `my-project = "my-project"`. var TOKEN_PATTERN = - /(? text.length) break; if (values[match[1]]) matches.push(match); } if (!matches.length) return; @@ -140,7 +148,7 @@ // The hover card names the token in a too; that one stays plain. var text = code.textContent; if ( - (text.indexOf('your-') === -1 && text.indexOf('PROJECT_ID') === -1) || + (text.indexOf('your-') === -1 && text.indexOf('PROJECT') === -1) || code.closest('#' + TIP_ID) ) { return; @@ -148,8 +156,13 @@ var walker = document.createTreeWalker(code, NodeFilter.SHOW_TEXT); var nodes = []; while (walker.nextNode()) nodes.push(walker.currentNode); - nodes.forEach(function (node) { - if (!node.parentElement.closest('.' + VAR_CLASS)) fillTextNode(node, values); + nodes.forEach(function (node, i) { + if (node.parentElement.closest('.' + VAR_CLASS)) return; + var following = ''; + for (var j = i + 1; j < nodes.length && following.length < LOOKAHEAD_CHARS; j++) { + following += nodes[j].nodeValue; + } + fillTextNode(node, values, following); }); }); };