DEV Community

Lidong Wang
Lidong Wang

Posted on AI-assisted

I built a source-to-clipboard test for documentation code blocks

A documentation code block can render correctly while its Copy code button silently changes the
text. A trailing newline, a tab converted to spaces, a zero-width character, or Unicode
normalization may be invisible on screen but still matter to a shell command, configuration file,
or source example.

I built Snippet Fidelity to test that narrow boundary:

canonical snippet -> rendered page -> copy handler -> browser clipboard
Enter fullscreen mode Exit fullscreen mode

It drives Chromium, activates the intended copy control, records the
navigator.clipboard.writeText payload when available, reads the browser clipboard, and compares
both observations at Unicode code-point precision.

The repository includes a synthetic adversarial fixture with one valid control and five intentional
regressions. A local run currently produces:

Snippet Fidelity: 1/6 passed, 5 failed, 0 errors.
Enter fullscreen mode Exit fullscreen mode

The failures cover:

  • terminal newline changes;
  • indentation loss;
  • tab/space substitution;
  • zero-width character injection;
  • Unicode normalization.

Reports contain fingerprints, lengths, categorized findings, and bounded escaped context around the
first difference. They do not print the complete expected or copied snippet by default.

This is deliberately not a Markdown linter, a generic clipboard manager, or a replacement for broad
documentation test frameworks. A linter checks source; Snippet Fidelity checks what a real rendered
page actually copies. Source-aware configuration can use literal canonical text or an exact UTF-8
file, while discovery mode is useful for reconnaissance.

Quick start:

npm install --save-dev snippet-fidelity
npx playwright install chromium
npx snippet-fidelity audit https://docs.example.com/
Enter fullscreen mode Exit fullscreen mode

There is also a GitHub Action
for source-aware release gates.

I have used the tool to validate copy-button work in two open upstream pull requests:
obsidian-webpage-export #751 and
Nexus #681. Those reviews are ongoing; they are evidence
of real integration work, not claims of upstream adoption.

The project is an early public release (v0.2.0) and Chromium-only today. I would especially value a
minimal public documentation page where the visual code and copied payload disagree—or a report
showing that the tool classified a difference incorrectly. Reproducible counterexamples will shape
the conformance contract more usefully than feature requests in the abstract.

Top comments (0)