Skip to content
This repository was archived by the owner on Mar 14, 2024. It is now read-only.

Add support for in-document linking (e.g. #my-id). #50

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

isaksavo
Copy link

@isaksavo isaksavo commented Jun 8, 2021

Add support for navigating to headers inside a document.

  • Enables the AutoIdentifiers markdig extension to give each header a unique anchor name. This anchor name is exposed on the header blocks as an attached dependency property.
  • The LinkInlineRenderer calls Uri.TryCreate to determine if the URL is valid or not (fixes issue with links being replaced with # as described in Intra-document links not created correctly #49
    • If the link is to a header inside the same document, the command used is Navigate instead of Link
  • The MarkdownViewer adds a command handler to the Navigate command which it sets to handled if the header was successfully navigated to. Otherwise the command will bubble up to whoever else is listening.
  • Updated sample md file with a TOC to test this functionality

This is my first shot at this. I'm open to suggestion if you want it done in a different way.

@Kryptos-FR
Copy link
Owner

Thanks, I had a quick look and I will probably make some changes (or make suggestions) when I have time to properly review it.

It looks promising.

@Kryptos-FR Kryptos-FR self-requested a review June 8, 2021 14:09
@ComtelJeremy
Copy link

Hello, is this something that will be added in the future? This would be very helpful for our project.

return false;
}

private bool ScrollIntoView(Block block)
Copy link

@JD-Howard JD-Howard Jan 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled this concept into my own customizations. This scroll into view method is fine in theory, but not always. The document start location literally shifts around; probably based on scroll state. The following is normalizing the problem I am having:

var objTop = block.ContentStart.GetCharacterRect(LogicalDirection.Forward).Top;
var docTop = _viewer.Document.ContentStart.GetCharacterRect(LogicalDirection.Forward).Top;
scrollViewer.ScrollToVerticalOffset(Math.Abs(docTop) + objTop);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants