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

File links does not work properly #55

Closed
Diafwl opened this issue Jan 30, 2023 · 8 comments
Closed

File links does not work properly #55

Diafwl opened this issue Jan 30, 2023 · 8 comments
Labels

Comments

@Diafwl
Copy link

Diafwl commented Jan 30, 2023

Describe the bug
links does not work properly for files, they are behaves like normal md links, not file links

To Reproduce
Steps to reproduce the behavior:
Link a file like: [[book.pdf]] does not work
Link a file like: [[book.pdf| Book Volume 1]] does not work
Link a file like: ![[book.pdf| Book Volume 1]] does not work

Expected behavior
3 of them needed to behave like: ![[book.df]]
[Book Volume](book.pdf) does work perfectly

Desktop (please complete the following information):

  • OS: Linux
  • Browser Firefox
  • Version 108.0.2
@Diafwl Diafwl added the bug report Something isn't working label Jan 30, 2023
@secure-77 secure-77 added enhancement New feature or request and removed bug report Something isn't working labels Jan 30, 2023
@secure-77
Copy link
Owner

secure-77 commented Jan 30, 2023

Hi @Diafwl,

yes currently file links need to start with an ! so the only working way àt the moment is ![[book.pdf]]. This is the default behavior if you drag & drop a file into a md document in obsidian.

I will take a look if I can implement the other formats as well.

@Diafwl
Copy link
Author

Diafwl commented Jan 30, 2023

but because of regex it does not capturing ![[book.pdf| Book Volume 1]] even if this one has ! renaming with | broking file links.

@Diafwl Diafwl closed this as completed Jan 30, 2023
@Diafwl Diafwl reopened this Jan 30, 2023
@secure-77
Copy link
Owner

yes, aliases for files are not supported / implemented at the moment

@Diafwl
Copy link
Author

Diafwl commented Jan 30, 2023

if we change pdf regex to \!?(\[\[)(.*?.pdf)(\]\]) it will work with ! or without !.
i tested i little bit it seems does not broke anything.

@secure-77
Copy link
Owner

secure-77 commented Jan 30, 2023

looks good 👍 then only the alias part is missing, ideally I should move the obsidian linking part into the PerliteParsdown.php but this is a little bit more work

@secure-77 secure-77 added the To Do on the to do list label Jan 30, 2023
@secure-77
Copy link
Owner

@Diafwl
This is a quick and dirty solution you can try. Just replace the pdf links section with these two:

	// pdf links with Alias
	$replaces = '<a class="internal-link" target="_blank" rel="noopener noreferrer" href="'.$path .'/'.'\\2">\\3</a>';
	$pattern = array('/(\!?\[\[)(.*?.pdf)\|(.*)(\]\])/');
	$content = preg_replace($pattern, $replaces ,$content);
	
	// pdf links without Alias
	$replaces = '<a class="internal-link" target="_blank" rel="noopener noreferrer" href="'.$path .'/'.'\\2">\\2</a>';
	$pattern = array('/(\!?\[\[)(.*?.pdf)(\]\])/');
	$content = preg_replace($pattern, $replaces ,$content);

I will check this again as soon I have some time and will make a new release

@Diafwl
Copy link
Author

Diafwl commented Jan 30, 2023

Yeah it works perfectly.

Thank you.

@secure-77 secure-77 added implemented / fixed and removed To Do on the to do list labels Feb 5, 2023
@secure-77
Copy link
Owner

This is fixed in version 1.5.3

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

No branches or pull requests

2 participants