<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lidong Wang</title>
    <description>The latest articles on DEV Community by Lidong Wang (@wldkk).</description>
    <link>https://dev.to/wldkk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4101032%2F7957f082-9bb4-4cf5-96ce-f3640a28536b.jpg</url>
      <title>DEV Community: Lidong Wang</title>
      <link>https://dev.to/wldkk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wldkk"/>
    <language>en</language>
    <item>
      <title>Your docs can look right and still copy wrong</title>
      <dc:creator>Lidong Wang</dc:creator>
      <pubDate>Tue, 01 Sep 2026 10:54:23 +0000</pubDate>
      <link>https://dev.to/wldkk/your-docs-can-look-right-and-still-copy-wrong-265p</link>
      <guid>https://dev.to/wldkk/your-docs-can-look-right-and-still-copy-wrong-265p</guid>
      <description>&lt;p&gt;A code block can look perfectly correct while its &lt;strong&gt;Copy&lt;/strong&gt; button silently changes what reaches the clipboard.&lt;/p&gt;

&lt;p&gt;The failures are usually small enough to escape screenshots and ordinary DOM assertions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a final newline disappears;&lt;/li&gt;
&lt;li&gt;tabs become spaces;&lt;/li&gt;
&lt;li&gt;indentation is trimmed;&lt;/li&gt;
&lt;li&gt;a shell prompt is removed;&lt;/li&gt;
&lt;li&gt;ASCII punctuation becomes a Unicode look-alike;&lt;/li&gt;
&lt;li&gt;composed and decomposed Unicode compare differently.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a command that will be pasted into a terminal, “almost the same” is not a useful contract.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a DOM assertion is not enough
&lt;/h2&gt;

&lt;p&gt;Most documentation tests stop at the rendered &lt;code&gt;&amp;lt;code&amp;gt;&lt;/code&gt; element. Copy behavior introduces at least two more boundaries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;canonical source -&amp;gt; rendered DOM -&amp;gt; copy handler -&amp;gt; browser clipboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A page can render the right text but send a different string to &lt;code&gt;navigator.clipboard.writeText&lt;/code&gt;. The handler can also send the right string while the browser or operating system exposes a transformed result. Without observing the stages separately, a failure is easy to misattribute.&lt;/p&gt;

&lt;p&gt;That is the narrow problem I built &lt;strong&gt;Snippet Fidelity&lt;/strong&gt; to test.&lt;/p&gt;

&lt;h2&gt;
  
  
  A one-step reconnaissance check
&lt;/h2&gt;

&lt;p&gt;The fastest way to try it is a GitHub Actions workflow against a public documentation page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;snippet-fidelity&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;audit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;WLDKK/snippet-fidelity@v0&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://docs.example.com/getting-started/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This mode discovers visible copy controls near code blocks, activates them in real Chromium, and compares copied text with the rendered code. It is useful reconnaissance, but it cannot prove that the rendered page matches a maintainer's source of truth.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turn it into a release gate
&lt;/h2&gt;

&lt;p&gt;For a dependable contract, point a check at a checked-in UTF-8 source file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"$schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://raw.githubusercontent.com/WLDKK/snippet-fidelity/v0/schema/config.schema.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"baseUrl"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://docs.example.com/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"pages"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"getting-started/"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"checks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"install-command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"button"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"#install-command button[aria-label='Copy code']"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"expected"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"file"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"./snippets/install.sh"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"probe"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"both"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the result can distinguish a source-to-render mismatch from a handler or clipboard mismatch. Reports use SHA-256 fingerprints, lengths, categorized findings, and a bounded escaped context around the first different Unicode code point. Full snippets are not printed by default.&lt;/p&gt;

&lt;h2&gt;
  
  
  What real-site testing taught me
&lt;/h2&gt;

&lt;p&gt;I ran the discovery mode against three maintained documentation sites. Three Starlight checks matched. Material for MkDocs consistently omitted a rendered terminal newline, while Doc Detective omitted a displayed shell prompt marker.&lt;/p&gt;

&lt;p&gt;Those differences may be deliberate paste-friendly behavior. I do &lt;strong&gt;not&lt;/strong&gt; label them bugs, because rendered-page discovery does not know the maintainers' canonical intent. That result led to an important reporting rule: a mismatch is an observation; a release-blocking claim requires a maintainer-owned source contract.&lt;/p&gt;

&lt;p&gt;The pilot also found a bug in the tool itself. Tabbed documentation often keeps inactive code blocks mounted, so the first implementation tried to activate hidden duplicate controls. The fix excluded non-rendered blocks while retaining hover-revealed controls, then added an end-to-end regression fixture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reproduce the failure classes locally
&lt;/h2&gt;

&lt;p&gt;The repository includes an adversarial fixture with one passing control and five intentional failures:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pnpm &lt;span class="nb"&gt;install
&lt;/span&gt;pnpm build
pnpm fixture

&lt;span class="c"&gt;# In another terminal:&lt;/span&gt;
node dist/cli.js audit &lt;span class="nt"&gt;--config&lt;/span&gt; examples/adversarial-fixture.config.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The expected outcome is one pass and five failures. A zero exit code would mean the fixture stopped exercising the intended regressions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scope and limits
&lt;/h2&gt;

&lt;p&gt;Snippet Fidelity is deliberately not a generic documentation testing framework or clipboard manager. It does not execute copied commands, rewrite clipboard content, or claim source fidelity when the baseline came from the rendered DOM. Version 0.4 currently drives Chromium, and automatic discovery remains heuristic; explicit selectors and canonical source are required for a serious release gate.&lt;/p&gt;

&lt;p&gt;The project is MIT licensed and available as a GitHub Action and npm package:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Repository: &lt;a href="https://github.com/WLDKK/snippet-fidelity?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=v0_4_launch" rel="noopener noreferrer"&gt;https://github.com/WLDKK/snippet-fidelity?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=v0_4_launch&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;GitHub Marketplace: &lt;a href="https://github.com/marketplace/actions/snippet-fidelity" rel="noopener noreferrer"&gt;https://github.com/marketplace/actions/snippet-fidelity&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you maintain public developer documentation, you can open a public audit request with one page. I am especially interested in examples where whitespace, generated snippets, tabs, or Unicode matter.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I used AI assistance to review wording and test coverage. I verified the implementation, commands, limitations, and reported evidence before publication.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>documentation</category>
      <category>githubactions</category>
    </item>
    <item>
      <title>I built a source-to-clipboard test for documentation code blocks</title>
      <dc:creator>Lidong Wang</dc:creator>
      <pubDate>Sun, 30 Aug 2026 06:26:12 +0000</pubDate>
      <link>https://dev.to/wldkk/i-built-a-source-to-clipboard-test-for-documentation-code-blocks-43gb</link>
      <guid>https://dev.to/wldkk/i-built-a-source-to-clipboard-test-for-documentation-code-blocks-43gb</guid>
      <description>&lt;p&gt;A documentation code block can render correctly while its &lt;strong&gt;Copy code&lt;/strong&gt; button silently changes the&lt;br&gt;
text. A trailing newline, a tab converted to spaces, a zero-width character, or Unicode&lt;br&gt;
normalization may be invisible on screen but still matter to a shell command, configuration file,&lt;br&gt;
or source example.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://github.com/WLDKK/snippet-fidelity" rel="noopener noreferrer"&gt;Snippet Fidelity&lt;/a&gt; to test that narrow boundary:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;canonical snippet -&amp;gt; rendered page -&amp;gt; copy handler -&amp;gt; browser clipboard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;The repository includes a synthetic adversarial fixture with one valid control and five intentional&lt;br&gt;
regressions. A local run currently produces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Snippet Fidelity: 1/6 passed, 5 failed, 0 errors.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The failures cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;terminal newline changes;&lt;/li&gt;
&lt;li&gt;indentation loss;&lt;/li&gt;
&lt;li&gt;tab/space substitution;&lt;/li&gt;
&lt;li&gt;zero-width character injection;&lt;/li&gt;
&lt;li&gt;Unicode normalization.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Reports contain fingerprints, lengths, categorized findings, and bounded escaped context around the&lt;br&gt;
first difference. They do not print the complete expected or copied snippet by default.&lt;/p&gt;

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

&lt;p&gt;Quick start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; snippet-fidelity
npx playwright &lt;span class="nb"&gt;install &lt;/span&gt;chromium
npx snippet-fidelity audit https://docs.example.com/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is also a &lt;a href="https://github.com/WLDKK/snippet-fidelity/blob/main/docs/github-action.md" rel="noopener noreferrer"&gt;GitHub Action&lt;/a&gt;&lt;br&gt;
for source-aware release gates.&lt;/p&gt;

&lt;p&gt;I have used the tool to validate copy-button work in two open upstream pull requests:&lt;br&gt;
&lt;a href="https://github.com/KosmosisDire/obsidian-webpage-export/pull/751" rel="noopener noreferrer"&gt;obsidian-webpage-export #751&lt;/a&gt; and&lt;br&gt;
&lt;a href="https://github.com/nexuslabs-ai/nexus/pull/681" rel="noopener noreferrer"&gt;Nexus #681&lt;/a&gt;. Those reviews are ongoing; they are evidence&lt;br&gt;
of real integration work, not claims of upstream adoption.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Repository: &lt;a href="https://github.com/WLDKK/snippet-fidelity" rel="noopener noreferrer"&gt;https://github.com/WLDKK/snippet-fidelity&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;npm: &lt;a href="https://www.npmjs.com/package/snippet-fidelity" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/snippet-fidelity&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Release: &lt;a href="https://github.com/WLDKK/snippet-fidelity/releases/tag/v0.2.0" rel="noopener noreferrer"&gt;https://github.com/WLDKK/snippet-fidelity/releases/tag/v0.2.0&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>testing</category>
      <category>documentation</category>
      <category>playwright</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
