Structured HTML output

In an issue report for Citation.js someone asks whether it’s possible to create output like this (with citeproc):

<div class="csl-bib-body">
  <div data-csl-entry-id="tang2007neural" class="csl-entry">
    <div class='csl-author'> Tang, H., Tan, K. C., &#38; Yi, Z. (2007). </div>
    <i class="csl-title">Neural networks: computational models and applications</i> (Vol. 53). 
    <div class="csl-publisher">Springer Science &#38; Business Media.</div>
  </div>
</div>

Basically wrapping every variable (not the year in their example, but whatever) in a div. Is it possible to extend the formatter to do that? I haven’t had any luck so far.

Try setting csl_reverse_lookup_support to true in the source of the processor. That should give you something to work with. (It’s the mode used in the WYSIWYG-ish CSL editor to enable source-output highlighting.)

1 Like

Cool, thanks! I’ll take a look. (Seems like it’s a sys option too?)

I tried setting it on the fly in a test fixture, and the setting was ignored. But if it picks it up on sys, it might work without modifying the source itself.

Followed your link and thought, “Oh! I did that, did I?” Just tried setting it on sys (before instantiating the processor), and yes indeed, it does work there! The code for it was done on impulse, on the day that the dev who built the CSL editor (Steve Ridout) outlined his plan in a mail message. That was the last time I touched it – I don’t even remember where it is in the code base – and it would be good to see it get further use.

Would you mind if I opened a PR with some changes for HTML? Particularly, I was thinking of:

  • renaming cslid to data-csl(-node)-id (since the data- prefix should be used for custom attrs AFAIK)
  • changing the class to csl-entry-part (or similar) to preserve the scoped style of the other classes
  • moving the node name to data-csl-node
  • adding the rendered variable, if applicable, as data-csl-variable

Seems like the @showid/true formatter function.

Happy to take a PR - but we should step carefully, since the CSL editor depends on it too. We could either parameterize the changes to output in some way, or adapt the editor to use common modern conventions. I think @Sebastian_Karcher is keeping it going, maybe he has a view.

1 Like

I don’t want the editor to stand in the way of what seem like smart changes to me, but I’m not deeply familiar with the editor code (I essentially just run the standard update and deploy process) and have limited time, so would tremendously appreciate some help in adapting it to any relevant citeproc-js changes. Code is here: https://github.com/citation-style-language/csl-editor

If someone wants to spend some more serious time updating this, we may also be able to pay something – probably below market rate, but also more than just a tip.

1 Like

Sounds fun (in theory, I haven’t seen the code yet :slight_smile:). I’ll have plenty of time beginning this June.

In the meantime, I could just wrap the @showid/true formatting function like I did for @bibliography/entry (which was to allow prepending and appending stuff like badges). Actually setting the option is a bit more difficult because of the (dumb) way I set up my code; caching the engine may be clever for performance but given all the side effects I don’t think it’s worth it anymore. I’m getting a bunch of new ideas though, so it’s all fine.