rhysd / Shiba

Rich markdown live preview app with linter
774 stars 55 forks source link

Allow to link to local `.md` files #3

Closed ghost closed 9 years ago

ghost commented 9 years ago

Allow user to link markdown file to markdown file. Given a link in file1.md to file2.md when user clicks this link [file2.md](file2.md), auto-load and display file2.md in Shiba.

Again, here is how Markn handle this: https://github.com/minodisk/markn/commit/bf3112936a8e6dd5a0f437e7bae9a36813148114

rhysd commented 9 years ago

Nice catch!

I must implement to prevent default file loading and opening the markdown file with <markdown-preview>.

rhysd commented 9 years ago

@xHN35RQ

I updated Shiba to 0.3.8 with fixing links to markdown documents. Could you try it?

ghost commented 9 years ago

I'm not able to get it to work using 0.3.8. When I click the link, all I get is the error Can't open: file.md on the command line.

rhysd commented 9 years ago

@xHN35RQ

I tested with Shiba directory.

$ cd ./Shiba
$ shiba README.md

Then the README.md was shown in window. Next, I clicked Easy to install link. The clicked document was shown though watching file was stll README.md so when README.md was updated, it showed README.md preview again.

So I tested Shiba again in my environment in some situations but I could not reproduce the error... Could you tell me the detail?

ghost commented 9 years ago

Hello! Here is updates on what is working and what is not. Assume we have file1.md file2.md and file three.md

Starting in file1.md there is link to file2.md [file2.md](file2.md) When I click on the link file2.md is loaded by Shiba and it works fine!!

But with file2.md loaded when I edit file2.md Shiba will not see any of the changes. Then if I click on "Reload" Shiba will reload file1.md and if I click the link again it will load the new changes. So Shiba cannot see any changes in files that have been loaded via clicking on links.

Also, if a file has spaces in the name it will not be loaded. In file1.md this link will do nothing if I click it: file three.md

Thanks!!

rhysd commented 9 years ago

@xHN35RQ

Thank you for your detailed description! I'll check it later.

ghost commented 9 years ago

Thank you for making such an awesome app :yum:

rhysd commented 9 years ago

@xHN35RQ

I checked your sequence. I think there are a point to fix and another point not to fix.

1. file1.md -> file2.md works well, but file2.md -> file3.md doesn't work

I think this behavior should be fixed. When we click the link to file3.md in file2.md, it should work as the link to file2.md in file1.md. file3.md -> file4.md, ... are the same. Thank you for the nice pointing out.

2. Watching directory does not change

I think this is an expected behavior. This is a problem of concept of this app.

The main purpose of clicking link would be the check which ensures the link to be correct. I'm writing something (e.g. file1.md), and click a link (e.g. to file2.md) in the document. But I'll want to continue the original document (file1.md). I mean clicking link is temporary and I want to go back to the original document. But I may overlook some use cases. Is there any use case to move watching directory on clicking links in document?

ghost commented 9 years ago

Ah ok, I see what you mean. Shiba thinks that clicking a link is temporary.

Is there any use case to move watching directory on clicking links in document?

Is it really moving the watching directory? I thought it was just changing the currently watched file?

Sometimes I create networks of linked Markdown documents as a personal wiki-of-sorts.

If I'm clicking the links between each document, I'd expect Shiba to load each document as needed, and not treat the first document as any different than any other document. Because I often enter and exit the network of interlinked documents from any different direction. And I might want to edit a file in response to seeing it loaded into Shiba, and I'd expect that file to be updated whenever I make a change.

However I can see the benefits of the current behavior. I guess it comes down to how many documents you tend to edit at once.

Maybe there is a way to make "Reload" into a back button? As in, reload last known document, but always watch the currently loaded document for changes.


Also, did you see that if a file has spaces in the name it will not be loaded?

In file1.md this link will do nothing if I click it: [this is file two.md](this is file two.md)

rhysd commented 9 years ago

@xHN35RQ

I thought it was just changing the currently watched file?

Yes. Sorry for confusing you.

I understood your use case and I think it is reasonable. So I added a workaround. Clicking with modifier key now changes the watching path.

Though it is possible to watch multiple files which we visited, it requires a lot of code changes because it is necessary to make multiple watchers to watch multiple paths with chokidar.

Also, did you see that if a file has spaces in the name it will not be loaded?

Ah, I don't care about the file name containing spaces because I don't use them for file name. I'll check it later.

ghost commented 9 years ago

Clicking with modifier key now changes the watching path.

:+1: good changes. Now I understand about the difficulty with chokidar. So thank you for making the necessary changes, this is very helpful. :smile:

Ah, I don't care about the file name containing spaces because I don't use them for file name. I'll check it later.

Yes, there are several reasons why spaces will occur in file names, but perhaps it can be solved by running filenames through an URL-escaping step before working with them? This will ensure converting spaces to %20 before working with them? Just an idea for you.

Thanks again :cake: :dog:

rhysd commented 9 years ago

I created space test.md and checked Shiba with the file. It seems to work well. If you encountered some problems with files containing white spaces, could you tell me your environment? I tested it in Ubuntu 12.04. I'm worried that error may occur in other OS environment.

ghost commented 9 years ago

I'm using Ubuntu 14.04 so it should be the same. I'll update to latest Shiba and test.

rhysd commented 9 years ago

@xHN35RQ

Thanks!

ghost commented 9 years ago

When I click on link with spaces in name, nothing happens. When I control-click nothing changes except window title changes to full path of link, with escaped spaces. Given this link: [space test.md](space test.md) when control-clicked the window title changes to Shiba (/home/nic/Desktop/space%20.md)

However I can drag and drop files with spaces, and they open just fine.

rhysd commented 9 years ago

Ah, I see. I'll check again. Thanks!

I think marked doesn't consider about the file whose name contains spaces when it converts markdown document to html document.

ghost commented 9 years ago

thanks!

rhysd commented 9 years ago

I fixed the bug in the latest version! I forgot to unescape the path on watching it.

ghost commented 9 years ago

Brilliant!! This works fantastic now. :trophy::trophy::trophy: Best markdown reader I've used so far. It's starting to remind me of Marked app for Mac OS X which I used to use before moving to Linux.

rhysd commented 9 years ago

@xHN35RQ

Thank you for so much cooperation! It was very helpful.