Skip to content

feat: follow links between notes in the reader - #94

Merged
bencode merged 1 commit into
mainfrom
feat/links-render
Oct 4, 2026
Merged

bencode merged 1 commit into
mainfrom
feat/links-render

Conversation

@bencode

@bencode bencode commented Oct 4, 2026

Copy link
Copy Markdown
Owner

What

Iteration 5 of bidirectional links: rendering and navigation. In the reader, [[ ]] links can now be clicked and each one lands on the place it names. Embeds and the backlinks section come in iteration 6.

Written Shown as Click
[[X]], [[X|label]] A link in the text (dotted underline) One note named X: open it. No note: greyed out, title "No note named X yet.", nothing happens. Several notes: a list of paths to choose from
[[X#^b]], [[X#Heading]] Same Open the note and scroll the block or heading to the top
[[x.pdf#page=12]] Same Open the PDF at page 12
#[[X]] #X, no underline Same as [[X]]
![[X]] An ordinary link for now Embedding is iteration 6
^name, ^name on its own line Hidden —

How it works

  • remarkLinks (links package):

    • turns links into <button>s that carry what was written. They are buttons rather than <a> so they can be reached by keyboard, have no href to inject into, and need no change to the shared components/markdown.tsx;
    • writes data-block and data-heading onto named blocks and headings, and hides ^name.

    The naming rule is extracted into namingsAmong and shared by parseNote and the plugin, so there is still a single rule. The real-vault snapshot is identical before and after, and a test checks that the set of data-blocks equals parseNote().blocks.

  • Locating by name, not by line number. Before rendering, the reader rewrites display math into extra lines, so rendered line numbers stop matching the source.

  • reveal in the workspace store. A link records "show this place in this file" and then opens the file. The file's reader consumes the request once and clears it. Only that request is cleared, never a newer one.

  • Markdown reveal goes through use-flow-position. The place shown is recorded as the reading position and held the way a restored position is. As a result:

    • images that finish loading afterwards don't push it away;
    • the reading position from the last visit doesn't pull it back.
  • Link resolution comes from the link graph (resolve / node). While indexing is still running, links are not yet clickable and their title explains why.

Testing

  • remark.test.ts:

    • each case in the table above;
    • code, inline code, Markdown links and same-page [[#…]] are left alone;
    • names are hidden and attached to the right element;
    • data-block agrees with the index.
  • markdown-reader.test.tsx:

    • clicking opens the note and passes the anchor;
    • a link to a missing note does nothing;
    • a name shared by several notes shows the chooser;
    • a reveal is consumed.
  • links-navigation.integration.test.tsx: from one note, click [[Retrieval#^first|why]]. It opens the target note, the named element is there, ^name is not shown, and Back returns to the first note.

  • pnpm check passes: unit 306, integration 68, links 36.

  • Real browser (agent-browser on a copy of bcd-new), checked with real layout:

    Case Result
    我的技能图谱.md (55 links) 7 open notes (Python matches pages/python.md regardless of case; tags work), 48 are greyed out, ^name is not shown
    Block link, with a reading position of 1500 recorded beforehand The block lands at the top (offset 0, scrollTop 5394); the old position does not override it
    Heading link #Section 33 Lands at the top (offset 0)
    The same link again while the target is already open and scrolled elsewhere Lands correctly
    Six images above the target that load afterwards The block stays at the top after they all load (offset 0)
    [[noticing.pdf#page=3]], including after turning the open PDF back to page 1 Opens at page 3
    A name shared by two notes The chooser lists both paths
    A heading that doesn't exist The note opens at its current reading position

Differences from the plan

  • use-flow-position.ts changed, adding show and folding the hold into a hold function. This came out of reading the code: without it, a later image load or position restore would pull the reveal back.
  • csv-reader.test.tsx and docx-reader.test.tsx only gain useReveal in their context mocks.
  • The links package adds mdast-util-to-hast (types for data.hProperties; web already pulls it in through react-markdown, so it adds nothing to the bundle) and dev-only @types/hast.
  • A heading that doesn't exist keeps the current reading position instead of returning to the top. That seems more natural, since the reader isn't interrupted.

[[Page]], [[Page#^name]], [[Page#Heading]], [[paper.pdf#page=12]] and
#[[tag]] now read as links. A link opens the note its page names and
shows the place it names: the named block or heading scrolled to the
top, or the PDF page. A page shared by several notes offers them to
choose from; a page no note has yet stays greyed out. ^name is hidden.

remarkLinks, in the links package, turns links into buttons that carry
what was written and marks each named block and heading with the name a
link uses, following the same naming rule as the index, now shared as
namingsAmong. Places are found by name rather than line, since the
reader rewrites display math before it renders.

A link asks the workspace to reveal a place in a file and opens it; the
file's reader shows the place once and clears the request. In Markdown
the place is held as the reading position, so images that load later
do not carry it away and a restored position does not take it back.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant