inukshuk / citeproc-ruby

A Citation Style Language (CSL) Cite Processor
101 stars 22 forks source link

Implement Cite Collapsing #46

Open inukshuk opened 7 years ago

inukshuk commented 7 years ago

https://github.com/citation-style-language/documentation/blob/master/specification.txt#L1655

Also see https://github.com/inukshuk/jekyll-scholar/issues/196

krafczyk commented 7 years ago

@inukshuk Where would be the right place to implement this? I might be able to do it if I know where to start and have a bit of extra time.

inukshuk commented 7 years ago

Citation nodes are currently rendered by the render_citation method (and render_single_citation directly below that). As you can see, there is a map and join using the layout's delimiter -- if collapse is set, we'd have to reduce the citations differently there. After a quick glance at the spec I'm a bit concerned about prefixes and suffixes, like brackets, because, if I'm not mistaken they would be rendered by the layout node. So render_single_citation and maybe even render_layout will have to be hoisted into the loop or passed some information that collapsing is taking place.

If it gets a little complicated, I'd move the relevant methods to renderer/citation.rb -- if you take a look at all these renderer files, you'll see that they all just open the Renderer class and add they're own private methods (so some additional care must be taken with regard to naming).

Generally, these features work really well with a TDD approach. Take a look at the renderer unit tests or renderer.feature for more high-level tests where you can pass in CSL snippets.

Finally, I don't know if it's relevant, but we're collapsing page numbers already -- perhaps some parts of that could be reused.

If you have any questions, just ask. The dev dependencies may be a bit dusty, because the gem has been in maintenance-only mode for some time, but the CI builds have been running fine recently so I'd hope it's easy to get set up!

inukshuk commented 7 years ago

Oh, if you do decide that render_layout will have to be aware of whether or not collapsing is taking place, let's discuss it in more detail. We have some state that is kept separately (and not passed down through all renderer methods) already (e.g. for suppression of author names or stuff like 'ibid' etc.).