Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Should support opening relative links to markdown #85

Open
dwlf opened this issue May 21, 2014 · 46 comments
Open

Should support opening relative links to markdown #85

dwlf opened this issue May 21, 2014 · 46 comments

Comments

@dwlf
Copy link

dwlf commented May 21, 2014

On January 30, 2013 relative links in markup files was added to github, https://github.com/blog/1395-relative-links-in-markup-files

Clicking on [a relative link](other_file.md) does not work.

Env
markdown-preview 0.71.0 in Atom 0.96.0 on Mac OS X 10.9.2.

Actual Result
No action.

Expected Result
A new preview tab with the linked md file.

Additional Details
Github Pages now supports relative links, as documented December 5, 2016 https://github.com/blog/2290-relative-links-for-github-pages

@IjzerenHein
Copy link

Yes, support for working links would be awesome. Especially when testing your markdown-file, so see whether internal and external document links work correctly. +1

@FunTimeCoding
Copy link

+1

1 similar comment
@davidhesselbom
Copy link

+1

@Jcamilorada
Copy link

+1

2 similar comments
@phairow
Copy link

phairow commented Jun 24, 2015

+1

@dlip
Copy link

dlip commented Jul 2, 2015

+1

@bojidar-bg
Copy link

+1!

@pkeir
Copy link

pkeir commented Sep 24, 2015

+1

2 similar comments
@medfreeman
Copy link

+1

@forthright48
Copy link

+1

@tkent
Copy link

tkent commented Oct 15, 2015

+1

@chris2fr
Copy link

chris2fr commented Nov 8, 2015

+1

1 similar comment
@Morriz
Copy link

Morriz commented Nov 9, 2015

+1

@graehu
Copy link

graehu commented Nov 17, 2015

+1 feels like this should be relatively easy, pun intended. Might have a look into it.

@rtremmel
Copy link

rtremmel commented Dec 4, 2015

+1

1 similar comment
@niermeyer
Copy link

+1

@bradley-fastorientation
  • 1

@JulianStier
Copy link

+1

1 similar comment
@ChristopherKing42
Copy link

👍

@rscottfree
Copy link

I poked around in this some, and got it working by adding the following snippet to the attached() method in markdown-preview-view.coffee.

document.getElementsByClassName('markdown-preview')[0].addEventListener 'click', (event) =>
    if event.target.tagName == 'A' && event.target.protocol == 'file:'
      atom.workspace.open event.target.getAttribute('href'), { split: 'left' }

Seeing as this is my first attempt at coffeescript and editing Atom plugins, I'm probably doing all sorts of things wrong.

  1. There must be a better way to attach this event, maybe to the editor dom itself, or maybe the Atom API provides a click event already
  2. Opening the file in the left-most pane worked for my use case, but a more generic implementation is probably available.

If someone with more knowledge of coffeescript and plugin API would like to clean this up into a proper pull request, or if you just want to test it out yourself, my fork is here: https://github.com/rscottfree/markdown-preview

@stevemoser
Copy link

It would be great if the path was checked and if the file doesn't exist then Atom would offer to create a new file. Otherwise the file would open as normal if it does exist. For an example of this check out MacDown.

@ChristopherKing42
Copy link

@stevemoser 👍

@rahul-pande
Copy link

+1

1 similar comment
@ghost
Copy link

ghost commented Jun 27, 2016

+1

@daniellavoie
Copy link

+1 👍

@tvld
Copy link

tvld commented Aug 23, 2016

+1

@tucknology
Copy link

+10000

@brandoncurtis
Copy link

brandoncurtis commented Oct 17, 2016

@rscottfree, thanks for the lead! Your modification works well for me except when I have multiple project folders open—in that case, clicking on the relative link attempts to open the file in the path of the project folder I opened first (which may or may not be the folder that the relative link is supposed to point at!)

I modified ~/.atom/packages/markdown-preview-plus/lib/markdown-preview-view.coffee, reloaded Atom with ctrl-alt-r, and added the following to attached. This seems to work well for me:

    # attempting to get relative links in markdown preview to open when clicked!
    document.getElementsByClassName('markdown-preview')[0].addEventListener 'click', (event) =>
      if event.target.tagName == 'A' && event.target.protocol == 'file:'
        activeFile = @getPath()
        activeFileDir = path.dirname(activeFile)
        clickedFile = event.target.getAttribute('href')
        clickedPath = path.join(activeFileDir, clickedFile)
        atom.workspace.open clickedPath, { split: 'left' }

Thanks again!

@bojidar-bg
Copy link

What about a PR? 😺

@brandoncurtis
Copy link

@bojidar-bg, fair point. I don't actually know Javascript, but I'll prepare a patch for testing and submit a PR if it looks good :)

tlnagy added a commit to tlnagy/markdown-preview that referenced this issue Oct 18, 2016
tlnagy added a commit to tlnagy/markdown-preview that referenced this issue Oct 18, 2016
@tlnagy
Copy link

tlnagy commented Oct 18, 2016

I submitted a PR for this feature here: #442

@coffeegist
Copy link

+1

@ghost
Copy link

ghost commented Oct 19, 2016

Reminder that you can now +1 on the topic itself so that it doesn't send
out an email to everyone subscribed.

On Tue, Oct 18, 2016 at 5:51 PM, Adam Brown [email protected]
wrote:

+1


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#85 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AKN8wc0NA9hDYiQzcCloWajIkw4abmEBks5q1WmEgaJpZM4B9Fv_
.

@stevemoser
Copy link

Now that Github Pages supports relative links, Atom is the last hold out. https://github.com/blog/2289-publishing-with-github-pages-now-as-easy-as-1-2-3

@MikiGrit
Copy link

Also it would be great if the clicked link would not open in new tab but in the same tab as current page. Sort of static web pages...

@bojidar-bg
Copy link

Not sure, I think it would be better if the last one is configurable (I don't want it navigating around if I misclick).

@MikiGrit
Copy link

Well, the option for user to choose the behaviour is definitely the best variant :).

@Michael-Jing
Copy link

+1

@rlam3
Copy link

rlam3 commented Feb 24, 2017

Still no update on this? I'm really frustrated now that I can't even test the links...

@ghost
Copy link

ghost commented Feb 24, 2017 via email

@tucknology
Copy link

tucknology commented Feb 24, 2017 via email

@rlam3
Copy link

rlam3 commented Feb 24, 2017

@braderhart @tucknology No need anymore. Somebody else already did it.
Just need to install this package...

https://atom.io/packages/markdown-preview-enhanced

I'm uninstalling markdown-preview-plus to get it to work smoothly. It has much more functionality as well.

@ghost
Copy link

ghost commented Feb 24, 2017 via email

@superzw
Copy link

superzw commented Mar 3, 2017

+1

@alexmorosmarco
Copy link

Hi, this development is still stuck? Last comment is from March 2017.
I would also love to have this feature, otherwise we cannot test our mds like we do in GitHub...

Thanks!

@Asday
Copy link

Asday commented Jul 12, 2019

@alexmorosmarco (and future intrepid googlers), check out https://github.com/shd101wyy/markdown-preview-enhanced

It's alright.

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

Successfully merging a pull request may close this issue.