Repository navigation
feat: follow links between notes in the reader - #94
Merged
Merged
Conversation
[[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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.[[X]],[[X|label]][[X#^b]],[[X#Heading]][[x.pdf#page=12]]#[[X]]#X, no underline[[X]]![[X]]^name,^nameon its own lineHow it works
remarkLinks(links package):<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 sharedcomponents/markdown.tsx;data-blockanddata-headingonto named blocks and headings, and hides^name.The naming rule is extracted into
namingsAmongand shared byparseNoteand 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 ofdata-blocks equalsparseNote().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.
revealin 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: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:[[#…]]are left alone;data-blockagrees with the index.markdown-reader.test.tsx:links-navigation.integration.test.tsx: from one note, click[[Retrieval#^first|why]]. It opens the target note, the named element is there,^nameis not shown, and Back returns to the first note.pnpm checkpasses: unit 306, integration 68, links 36.Real browser (agent-browser on a copy of bcd-new), checked with real layout:
我的技能图谱.md(55 links)Pythonmatchespages/python.mdregardless of case; tags work), 48 are greyed out,^nameis not shown#Section 33[[noticing.pdf#page=3]], including after turning the open PDF back to page 1Differences from the plan
use-flow-position.tschanged, addingshowand folding the hold into aholdfunction. This came out of reading the code: without it, a later image load or position restore would pull the reveal back.csv-reader.test.tsxanddocx-reader.test.tsxonly gainuseRevealin their context mocks.mdast-util-to-hast(types fordata.hProperties; web already pulls it in through react-markdown, so it adds nothing to the bundle) and dev-only@types/hast.