Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clicking a PDF annotation link now causes an immediate jump to the annotation in markdown-source-view #257

Closed
wants to merge 1 commit into from

Conversation

HardwayLinka
Copy link
Contributor

@HardwayLinka HardwayLinka commented Nov 11, 2022

Hi @aladmit , I have added a new feature to the project which is to jump directly to the PDF by clicking on the PDF annotation link in markdown-source-view. And fixed #251.

Click:
0003

Click while holding ctrl:
0002

PS. Ignore the modifications other than src/main.tsx, because I don't know why so many files were added, maybe because I developed it with windows11?

Implementation

Add a file-open listener in Obsidian, add a click event to the PDF annotation link and let MutationObserver observe the PDF annotation link in that listener

Test Objects

All the following tests passed

  1. A PDF annotation link in one line
    image

  2. A PDF annotation link with multi-line aliases in one line
    0001

  3. A PDF annotation link with multi-line aliases and two normal PDF annotation links in one line
    image

  4. A PDF annotation link with multi-line aliases and a normal link in one line
    image

  5. PDF annotation link in list
    image

  6. PDF annotation links in other formats
    image


public pdfAnnotatorFileModes: { [file: string]: string } = {};
private _loaded = false;
private eventRefs: EventRef[] = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use an array to store the events of Obsidian, which is convenient for closing events when closing the software

@@ -356,25 +389,188 @@ export default class AnnotatorPlugin extends Plugin implements IHasAnnotatorSett
private addMarkdownPostProcessor() {
const markdownPostProcessor = async (el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
for (const link of el.getElementsByClassName('internal-link') as HTMLCollectionOf<HTMLAnchorElement>) {
const parsedLink = parseLinktext(link.href);
Copy link
Contributor Author

@HardwayLinka HardwayLinka Nov 11, 2022

Choose a reason for hiding this comment

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

The form of link.href does not work on Windows, and link.getAttribute("href") works.

}
}

linkOnFocus(element: Element) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

when the cursor is focused on the link

image

this.tmpLinkInfos.push({linkText: linkText, count: count});
}

linkOnBlur(node: Element, rawLinkText: string, filePath: string, className: string) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the link loses the cursor

0004

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.

Link to annotation does not scroll to the highlight in the PDF
1 participant