From 0bc1a2c0548967878890b93859f697f6629855df Mon Sep 17 00:00:00 2001 From: Vance Ingalls Date: Sun, 7 Jun 2026 20:06:22 -0700 Subject: [PATCH 1/5] feat(core): ensureHfIds node-id pass + shared hf- mint helper (R1) --- packages/core/src/parsers/hfIds.test.ts | 72 ++++++++++++++++++++++ packages/core/src/parsers/hfIds.ts | 80 +++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 packages/core/src/parsers/hfIds.test.ts create mode 100644 packages/core/src/parsers/hfIds.ts diff --git a/packages/core/src/parsers/hfIds.test.ts b/packages/core/src/parsers/hfIds.test.ts new file mode 100644 index 000000000..803cceedc --- /dev/null +++ b/packages/core/src/parsers/hfIds.test.ts @@ -0,0 +1,72 @@ +import { describe, it, expect } from "vitest"; +import { ensureHfIds, mintHfId } from "./hfIds.js"; +import { parseHTML } from "linkedom"; + +function ids(html: string): string[] { + const { document } = parseHTML(html); + return Array.from(document.querySelectorAll("[data-hf-id]")).map( + (e) => e.getAttribute("data-hf-id") as string, + ); +} + +describe("ensureHfIds", () => { + it("mints a hf- id on every editable element node in body", () => { + const html = ` +

Hi

x
+ `; + const out = ensureHfIds(html); + for (const id of ids(out)) expect(id).toMatch(/^hf-[a-z0-9]{4}$/); + // div, h1, img, span = 4 ids + expect(ids(out)).toHaveLength(4); + }); + + it("skips script/style/template/meta and head", () => { + const html = ` +

keep

`; + const out = ensureHfIds(html); + // only the

gets an id + expect(ids(out)).toHaveLength(1); + expect(out).not.toContain("