zotero / citeproc-rs

CSL processor in Rust.
https://cormacrelf.github.io/citeproc-wasm-demo/
Other
71 stars 12 forks source link

Stdio mode #13

Open cormacrelf opened 4 years ago

cormacrelf commented 4 years ago

It might turn out to be useful to have a command-line program that runs a citeproc server over stdin/stout with JSON messages. This might be easier to integrate in some applications than a WebAssembly runtime. citeproc-java, for instance, could do this, but so could a Vim plugin. It could also be a neat solution to running inside a Pandoc Lua script.

Stdio has proved a fitting transport for the Language Server Protocol, partly because of this ease of integration. You also wouldn't need to worry about ensuring downstream WebAssembly runtimes actually have the features you need; just build for x86 with rayon parallelism, set up filesystem watchers when requested, etc.

iandol commented 2 years ago

Hi Cormac, what is the current availability of this method? There is a writing app called Scrivener (written in objective-c for macOS) for which I asked to add support for CSL, but the developer was not convinced of the best way to integrate. Pandoc's newer citeproc has a binary that can communicate via JSON: https://github.com/jgm/citeproc/blob/master/man/citeproc.1.md — I'm not sure as a non-developer of the relative merits of each system.

cormacrelf commented 2 years ago

@iandol citeproc-rs now has bindings for Swift. Swift code can't be used 100% directly in Objective-C, but you can write that part of your app in Swift and expose @objc APIs to the rest of your program. It's available at https://github.com/cormacrelf/CiteprocRsKit, with documentation viewable on the web at https://citeprocrskit.cormacrelf.net/documentation/CiteprocRsKit

On the relative merits, whatever works works. But I would note that:

There's nothing stopping you from implementing either scheme (batch vs incremental) in terms of the other. For citeproc-rs, it's about 20 lines of straightforward code (like this test case) to batch all your cites together for e.g. previewing a full document, or exporting it.

iandol commented 2 years ago

Thank you, I'll relay this information back to the Scrivener developer. Batch mode will be more useful in this case, so thank you for the sample code for that!