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

Open item in Zotero from vim buffer #79

Open
artkpv opened this issue Jul 9, 2024 · 10 comments
Open

Open item in Zotero from vim buffer #79

artkpv opened this issue Jul 9, 2024 · 10 comments

Comments

@artkpv
Copy link

artkpv commented Jul 9, 2024

Hi @jalvesaq! Thank you for the tool. How to open an item (book, article, etc.) in Zotero from a zotero link in my vim buffer? I place my cursor at the @<somelinkhere> and press Enter. It opens Zotero but doesn't focus on the item I expect. While other features are working like open attachment, get biblio info etc.

:Zinfo:

Information from the Python module:
  time to load data : 1e-05 (check) + 0.00954 (read) + 0.03217 (write) + 0.01726 (sql)
  zotero.sqlite     : /home/**/mydir/ref/Zotero/zotero.sqlite
  tmpdir            : /home/***/.cache/zotcite
  data dir          : /home/***/mydir/ref/Zotero
  references found  : 392
  citation template : {Authors}_{Year}
  excluded fields   : []
  attachments dir   : /home/***/mydir/books
  docs              : {}
  zotero.py         : /home/****/mydir/ref/dotfiles/nvim/pack/minpac/start/zotcite/python3/zotero.py
  banned words      : a an the some from on in to of do with
~/.config/nvim/pack/minpac/start/zotcite master
❯ g log -1
commit 9753c2629cefa3bc388e3bac4ac65dfb9d5a3610 (grafted, HEAD -> master, origin/master, origin/HEAD)
Author: Jakson Alves de Aquino <[email protected]>
Date:   Sat Mar 16 12:20:47 2024 -0300

    Make :Zinfo show the time to update the database

@jalvesaq
Copy link
Owner

jalvesaq commented Jul 9, 2024

It doesn't work on my side either. Please, update the plugin and put let zotcite_wait_attachment = 1 in your vimrc.

After that, I can see the following error message:

Error running `xdg-open "zotero://open-pdf/library/items/GWCTFLHS"`: $(realpath: -c: line 2: unexpected EOF while looking for matching `)'

I installed Zotero manually. This should be the reason why xdg-open doesn't know what to do with zotero://.

@jalvesaq
Copy link
Owner

jalvesaq commented Jul 9, 2024

I edited my zotero.desktop file and replaced

Exec=bash -c "$(dirname $(realpath $(echo %k | sed -e 's/^file:\/\///')))/zotero -url %U"

with

Exec=/path_to/zotero -url %U"

and now I can replicate the issue as you reported. Maybe the ZotFile extension is required (see https://forums.zotero.org/discussion/73776/create-external-link-to-open-pdf-within-zotero), but it's installed here...

This feature was introduced by @jasonccox

@artkpv
Copy link
Author

artkpv commented Jul 10, 2024

@jalvesaq I can open attachments by pressing <leader>zo for pdfs, htmls. The issue is about openning an item inside the Zotero program which means a record there that contains biblio info, links to PDFs, or PDFs themselves, etc. When I place a cursor inside my vim buffer on a @some_id_author_year and press Enter key then the zotero window appears but it does not focus the item inside Zotero. Hope it is clear now what's the issue.

I've tried let zotcite_wait_attachment = 1 it doesn't show anything

@jalvesaq
Copy link
Owner

Same bug here. I don't know how to fix it.

@jasonccox
Copy link
Contributor

Chiming in as the original author of this feature. I don't have Zotero installed anymore, so I can't do much debugging right now, but I'd guess that the issue is related to the logic to build the zotero:// URL:

if a:zotero_uri && a:strg =~? '\.pdf$'
. I don't recall how I figured out how to construct that URL, and I'm not finding any documentation on those URLs from a quick search either.

@jalvesaq
Copy link
Owner

Thanks, @jasonccox!

When we can't find anything on the web, we have to look at the source code. I downloaded Zotero from Git Hub and used grep to search the string "open.*pdf". Part of the output was:

chrome/content/zotero/ZoteroProtocolHandler.jsm:         * zotero://open-pdf/library/items/[itemKey]?page=[page]
chrome/content/zotero/ZoteroProtocolHandler.jsm:         * zotero://open-pdf/groups/[groupID]/items/[itemKey]?page=[page]
chrome/content/zotero/ZoteroProtocolHandler.jsm:         * zotero://open-pdf/[libraryID]_[key]/[page]

The first line has the command that we are already using, but it doesn't work.

Looking at the code, I found:

image

whose part of the diff is:

-			uriPath = uriPath.substr('//open-pdf/'.length);
-			var mimeType, content = '';
+			uriPath = uriPath.replace(/^\/\/open(-pdf)?\//, '');

And in Zotero, clicking on "Help / Debug Output Logging / View Output", I find:

[JavaScript Error: "URIError: malformed URI sequence" {file: "resource://gre/modules/osfile/ospath_unix.jsm" line: 188}]

This is the end of my research, and I still don't know how to fix the bug.

Perhaps, someone will find a solution. I will wait a few days before removing the option zotcite_open_in_zotero.

@adam-coates
Copy link
Contributor

adam-coates commented Jul 27, 2024

I also experience the issues pointed out here. I notice though that the @ZoteroKey# 's are different for a parent and child Item. Using the ZotFile plugin to get the keys for each (ie directly in zotero itself right clicking and selecting "copy select item links" https://forums.zotero.org/discussion/comment/317284/#Comment_317284, I notice that I get two different ones for the citation and the pdf itself.

So when I do: xdg-open "zotero://open-pdf/library/items/NMPZXK65" generated from the original @ZoteroKey# zotero opens but no pdf opens but when I do xdg-open "zotero://open-pdf/library/items/C892Q6IM" generated from the pdf itself then the pdf opens.

How are the URI's made? Based on the original @ZoteroKey# or by the key associated with the pdf.

Here's a snippet from the sqlite database

{"key":"MSNST3S9","version":1571,"parentItem":"C892Q6IM","itemType"

In the above snippet both MSNST3S9 and C892Q6IM work to open the pdf.

@jalvesaq
Copy link
Owner

Would you be able to make a pull request fixing this issue?

@adam-coates
Copy link
Contributor

I can, I just noticed though that if I set in config open_in_zotero = true and then press <leader>zo I can get it to work and the ID used for the URI is correct, this is referring to the lines here:

if config.open_in_zotero and string.lower(strg):find("%.pdf$") then
local id = fpath:gsub(":.*", "")
return "zotero://open-pdf/library/items/" .. id
end

Here's an example:

@9IQRHJF2#Remedios_Logothetis_Kayser-2014
IP2MW2MU

Then I'm a bit confused about where the logic is failing in this, since enter for me is not doing anything anymore since moving the merge from lua to master.

@jalvesaq
Copy link
Owner

My guess is that this commit caused the problem:

zotero/zotero@a7d59a9

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

No branches or pull requests

4 participants