Skip to content

Fix off-by-one in <File> line-range extraction and add regression test#2971

Open
afurm wants to merge 1 commit intonear:masterfrom
afurm:fix/copy-md-range-off-by-one
Open

Fix off-by-one in <File> line-range extraction and add regression test#2971
afurm wants to merge 1 commit intonear:masterfrom
afurm:fix/copy-md-range-off-by-one

Conversation

@afurm
Copy link

@afurm afurm commented Feb 17, 2026

Summary

<File ... start="x" end="y" /> snippet extraction had an off-by-one bug that included one extra line after end.

This PR:

  • fixes the line-range slicing so end does not include the next line
  • adds a regression test for start="2" end="3" to ensure only lines 2–3 are returned
  • adds a small require.main guard/export so the helper can be tested directly without changing normal script execution

Before / After

  • Before: start=2, end=3 returned lines 2, 3, 4
  • After: start=2, end=3 returns lines 2, 3

Testing

node --test website/scripts/copy-md-to-static.test.js

@gagdiez
Copy link
Collaborator

gagdiez commented Feb 21, 2026

hi @afurm , thanks for the PR! could you point which .md is showing problems that this PR fixes? I'm trying to figure out if this is a real issue, or the +1 is actually not affecting the results

@afurm
Copy link
Author

afurm commented Feb 21, 2026

hi @afurm , thanks for the PR! could you point which .md is showing problems that this PR fixes? I'm trying to figure out if this is a real issue, or the +1 is actually not affecting the results

This is a real issue, but specifically in the markdown generated by yarn process-markdown (website/scripts/copy-md-to-static.js), not in the runtime <Github> component used on rendered docs pages.

Concrete examples where end gets one extra line before this fix:

  • docs/web3-apps/quickstart.md (line 118)
    <Github ... start="11" end="11" />
    Source file is hello-near/index.tsx, where line 11 is:
    const { signedAccountId, viewFunction, callFunction } = useNearWallet();
    With the old +1, line 12 is also included.

  • docs/web3-apps/tutorials/wallet-login.md (line 118)
    <Github ... start="3" end="3" />
    This should include only line 3, but old logic includes the next line too.

So the fix aligns copy-md-to-static.js behavior with the existing frontend GitHub component behavior (slice(start-1, end)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: NEW❗

Development

Successfully merging this pull request may close these issues.

2 participants