@praxisflux/gates 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -110,15 +110,18 @@ function openTagsWithClass(html, classToken) {
110
110
  return out;
111
111
  }
112
112
 
113
- /** Each .translation-block open tag, its attrs, and its chunk extent (to the
114
- * next block or end of input blocks never nest, and the tracked classes
115
- * only occur inside blocks, so chunk counting is exact). */
113
+ /** Each .translation-block element with its REAL extent from its open tag
114
+ * to its own nesting-aware closing </div> (via findElements), not to the
115
+ * next block's open tag. Content between blocks therefore belongs to no
116
+ * chunk; the orphan scan in checkTranslationBlocks owns that territory.
117
+ * A block whose close tag is missing is not returned here (findElements
118
+ * can't bound it) — checkTranslationBlocks flags the unmatched open. */
116
119
  function findBlocks(html) {
117
- const opens = [];
118
- const re = /<div([^>]*)>/g;
119
- let m;
120
- while ((m = re.exec(html))) if (hasClassToken(m[1], "translation-block")) opens.push({ start: m.index, attrs: m[1] });
121
- return opens.map((o, i) => ({ ...o, end: i + 1 < opens.length ? opens[i + 1].start : html.length, n: i + 1 }));
120
+ return findElements(html, "div", "translation-block").map((el, i) => ({
121
+ ...el,
122
+ attrs: (/^<div([^>]*)>/.exec(html.slice(el.start, el.innerStart)) || [, ""])[1],
123
+ n: i + 1,
124
+ }));
122
125
  }
123
126
 
124
127
  /* ── bracket balance over code text ───────────────────────────── */
@@ -177,6 +180,28 @@ export function checkTranslationBlocks(html, source = "html") {
177
180
  const fails = [];
178
181
  const details = [];
179
182
  const blocks = findBlocks(html);
183
+
184
+ // A translation-block open tag findElements couldn't close never reaches
185
+ // `blocks` — without this check it (and its contents) would silently skip
186
+ // validation entirely.
187
+ const bounded = new Set(blocks.map((b) => b.start));
188
+ const openRe = /<div([^>]*)>/g;
189
+ let om;
190
+ while ((om = openRe.exec(html)))
191
+ if (hasClassToken(om[1], "translation-block") && !bounded.has(om.index))
192
+ fails.push(`${source}: .translation-block opened on line ${lineOf(html, om.index)} has no matching closing </div> — nothing inside it can be validated. Close the block.`);
193
+
194
+ // Tracked content outside every block extent is unattributable: the old
195
+ // next-open-tag chunks blamed it on a neighboring block (or missed it
196
+ // before the first block); now it fails by name.
197
+ const inBlock = (i) => blocks.some((b) => i >= b.start && i < b.end);
198
+ for (const [cls, label] of [["translation-code", ".translation-code panel"], ["code-line", ".code-line span"], ["tl", ".tl note"]]) {
199
+ for (const t of openTagsWithClass(html, cls)) {
200
+ if (!inBlock(t.start))
201
+ fails.push(`${source}: orphan ${label} on line ${lineOf(html, t.start)} sits outside every .translation-block — the validator cannot attribute it and the renderer will misplace it. Wrap it in a .translation-block or delete it.`);
202
+ }
203
+ }
204
+
180
205
  for (const b of blocks) {
181
206
  const id = `${source}: translation block ${b.n} (line ${lineOf(html, b.start)})`;
182
207
  if (/data-validate\s*=\s*["']off["']/.test(b.attrs)) { details.push({ ...b, skipped: true }); continue; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@praxisflux/gates",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "praxisflux gate checks as a zero-dependency CLI (spec-bridge, wiki-freshness, course) — status can't exceed proven artifacts",
5
5
  "license": "MIT",
6
6
  "repository": {