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

Desktop: Improved resource hover title #1965

Merged
merged 3 commits into from
Oct 8, 2019

Conversation

CalebJohn
Copy link
Collaborator

This pull does 2 things.

  1. Actually allows the user to set a markdown link title for resource URLs and internal links
    e.g
    [internal link](:/51bee0f048994f81a7cbca4e7627ad13 "title")

  2. Display the stored resource title for resources on hover.
    From what I can tell, this field is always the original filename, is that correct @laurent22 ? This will be useful because it will allow users to hover over a resource to get some additional info.
    My other motivation for adding that is it will allow for joplin to display the filetype instead of the resource icon when filetypes are known. Users can do this manually using css, or if you're open to it, I can make a pull request that will make it a feature in Joplin.

@laurent22
Copy link
Owner

That looks good I think, but please could you show an example of how the HTML would look before, and how it would look now? Just to get a better sense of what's changed. I guess we should have test units for this, but currently we don't unfortunately.

This change seems good in itself, however it's not required to get custom icons working. This can be derived from the resource mime type. I'm not sure the title is always the filename - it might depend on how the resource was imported. One might even build a custom importer using the API and forget to set the title. On the other hand, the mime type is automatically set by the app when a resource is imported (via the API or anywhere) so it's more likely to be set and accurate.

@CalebJohn
Copy link
Collaborator Author

Here's an example of an attached word document
image

The old html has a title, but it isn't equal to anything
image

The new html includes a title with the original (uploaded filename)
image

The above images show off change #2, for #1 the only difference is that I've enabled the title attribute of markdown for regular http(s) links. It was a bug in joplin that it didn't work before.
e.g.
[test](http://google.ca "Googles Homepage!")

Would become
image

And it will now correctly pick up the title
image

And in the new version if you use the same link as above without the title attribute, it will correctly render as [test](http://google.ca")
image

@CalebJohn
Copy link
Collaborator Author

CalebJohn commented Oct 8, 2019

That's a good point about the mimeType, I pushed another commit that adds mimetype to resource links because I figured it would be valuable to add as much info as possible. If it's out of scope for this pull (or you just don't like it) I can pull the commit, no problem.

Here is an example of what a resource link will look now
image

edit: it seems like mimetype is always completely specific, for example when a .docx is attached
image
We get a mimetype of application/octet-stream

@@ -37,7 +43,7 @@ function installRule(markdownIt, mdOptions, ruleOptions) {

let js = `${ruleOptions.postMessageSyntax}(${JSON.stringify(href)}); return false;`;
if (hrefAttr.indexOf('#') === 0 && href.indexOf('#') === 0) js = ''; // If it's an internal anchor, don't add any JS since the webview is going to handle navigating to the right place
return `<a data-from-md ${resourceIdAttr} title='${htmlentities(title)}' href='${hrefAttr}' onclick='${js}'>${icon}`;
return `<a data-from-md ${resourceIdAttr} title='${htmlentities(title)}' href='${hrefAttr}' onclick='${js}' type='${mime}'>${icon}`;
Copy link
Owner

Choose a reason for hiding this comment

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

Like the title, the mime type should be escaped with htmlentities()

@laurent22
Copy link
Owner

Good idea to add the mime type there. I didn't know it was a valid attribute so indeed we may as well put it there.

Regarding docx, acccording to mime-utils.js, it should have been detected as application/vnd.openxmlformats-officedocument.wordprocessingml.document so looks like there's a bug there. Did you attach it from the desktop or mobile app?

Otherwise if you could just fix the mime type escaping, it's good to merge.

@CalebJohn
Copy link
Collaborator Author

CalebJohn commented Oct 8, 2019

Thanks @laurent22 I've escaped the mime.

I attached from the desktop app, I've added the file below in case you want to try and reproduce it.

thesis-chapter_2016.docx

@laurent22
Copy link
Owner

Perfect, thanks @CalebJohn. I've also fixed the mime type issue (turns out I was using the simplified version of a package that didn't the vendor types (vnd-*)).

@laurent22 laurent22 merged commit f2c82b0 into laurent22:master Oct 8, 2019
@CalebJohn CalebJohn deleted the link-title branch October 8, 2019 21:33
@CalebJohn
Copy link
Collaborator Author

Thanks for fixing it so quickly!

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.

2 participants