egh / zotxt

zotxt: a Zotero extension for text
http://gitlab.com/egh/zotxt
GNU General Public License v3.0
327 stars 16 forks source link

Added pandoc-zotxt.lua #5

Closed odkr closed 5 years ago

odkr commented 6 years ago

This is a Lua filter for pandoc that does more or less the same pandoc-zotxt does. I had hoped for it to be faster than the original, but it isn't. (I wrongly assumed that I could retrieve multiple citation items concurrently in Lua; but Pandoc doesn't support that.) However, it ships with its only dependency, a JSON library, and doesn't require anything to run but Pandoc itself. So maybe it's useful for some people.

egh commented 6 years ago

@odkr This looks brilliant - I've long wanted to have something less hacky than a python script. I'll test it, but at first glance it looks great. Thank you!!

odkr commented 6 years ago

Thanks! I haven’t yet added support for BetterBibTex though.

egh commented 6 years ago

@odkr I'm trying to get the tests to run on this. Everything looks great to me and I really appreciate the work. I think the test problem is in zotxt but I'm not sure at the moment.

odkr commented 6 years ago

Are you referring to the tests in pandoc-zotxt/tests/test_zotxt.py? At a first glance, most of the code there appears to be machinery for the tests and there are, correct me if I'm wrong, four test cases:

  1. simple lookup
  2. lookup of an accented citation key
  3. lookup of a BetterBibTex key
  4. lookup of an non-existing key

My test suite covers all of these cases, save for the second one.

If that helps I can try to tidy up my test suite a bit and include a similar case. (It may take me some time though; I'm currently pre-occupied with other things.)

Lua is unicode-agnostic; and there's a very real chance things can go wrong here. (I’m thinking of non-ASCII characters that consist of multiple octets in non-normalised order; but given that Zotero doesn’t normalise strings either, at least it didn’t last time I checked, there is probably not much that can be done about this.)

odkr commented 5 years ago

Hey, I recently had a look at the code again. I've cleaned it up a bit and added the feature of letting pandoc-zotxt.lua 'manage' JSON bibliography files.

odkr commented 5 years ago

Sorry for the noise, but my Lua is rusty, it appears ;).

egh commented 5 years ago

I'm sorry this fell off my radar. I'm going to merge now. This is so much better than pandoc-zotxt (python). I'll try to update the README to mention it and deprecate the python code (which I haven't been keeping up-to-date). Thanks again!

odkr commented 5 years ago

No worries. (I just found out that there's a one year old PR on one of my repos. It happens.) I've improved the error handling of pandoc-zotxt.lua in the meantime. I'll open a new PR. But that should be it for the time being.