decorators

3 views
Skip to first unread message

Phillip Lord

unread,
Mar 31, 2011, 3:59:29 PM3/31/11
to citep...@googlegroups.com

I'm struggling a little with the code base of citeproc at the moment,
and would be grateful for any pointers people could give me.

I've got as far as running citeproc to produce a (reasonably) nice
bibliography in HTML. My intext-citations look like....

<span id="kcite-citation-5" kcite-id="ITEM-4">
<span style="text-decoration: underline;">(D&#8217;Arcus 2005)
</span>
</span>

This is from the DOM post citeproc processing. One entry from the
bibliography looks like this...

<div class="csl-entry">D&#8217;Arcus, Bruce. 2005.
<i>Boundaries of Dissent: Protest and State Power
in the Media Age</i>. Routledge, November 22.</div>


Now I know that I can modify the output format using the output
prototype in formats.js. I've been trying to hunt down where this
substitution happens in code, but my javascript is just not good enough.
So, my question is, can I parameterise this in someway. The basic
problem is that, I want to hyperlink the in-text citation to the
bibliography. The in-text citation gives me enough information to do
this, but in the generated bibliography there is not.

For example, if I have defined the retrieveItem function like so:

var sys = {
retrieveItem: function(id){
return citation_data[id];
},

retrieveLocale: function(lang){
return locale[lang];
}
};

I would like to generate

<a name="ITEM-4">
<div class="csl-entry">D&#8217;Arcus, Bruce. 2005.
<i>Boundaries of Dissent: Protest and State Power
in the Media Age</i>. Routledge, November 22.</div>
</a>

where ITEM-4 is the id that would have been passed to retrieveItem.

I'm also trying to hyperlink DOIs in the bibliography, and want to
include outgoing links as well. But one thing at a time.

Phil


Bruce D'Arcus

unread,
Mar 31, 2011, 4:21:32 PM3/31/11
to citep...@googlegroups.com
I can't help with the js or citeproc-js details, but on the HTML ...

Wouldn't it be more appropriate to use an id anchor on the div, and
leave room to expand? E.g. start with:

<div class="csl-entry" id="citeref:d-arcus-2005">D&#8217;Arcus, Bruce. 2005.


       <i>Boundaries of Dissent: Protest and State Power
       in the Media Age</i>. Routledge, November 22.</div>

... then add basic links:

<div class="csl-entry" id="cite:d-arcus-2005">D&#8217;Arcus, Bruce. 2005.
       <i><a href="[some uri]">Boundaries of Dissent: Protest and State Power
       in the Media Age</a></i>. Routledge, November 22.</div>

... and maybe at some point layer in basic RDFa (details unchecked;
just for illlustration):

<div class="csl-entry" id="cite:d-arcus-2005"
property="dc:references" about="[some uri]"
typeOf="bibo:Book">D&#8217;Arcus, Bruce. 2005.
       <i><a href="[some uri]"><span property="dc:title">Boundaries


of Dissent: Protest and State Power

       in the Media Age</span></a></i>. Routledge, November 22.</div>

...?

Bruce

Frank Bennett

unread,
Mar 31, 2011, 5:31:27 PM3/31/11
to citeproc-js
On Apr 1, 12:59 am, phillip.l...@newcastle.ac.uk (Phillip Lord) wrote:
> I'm struggling a little with the code base of citeproc at the moment,
> and would be grateful for any pointers people could give me.

Don't jump!

:) Just kidding.
This is a common need, and should be built into the processor as a
standard option. The simplest thing would probably be to add a couple
of functions to the code blocks in formats.js, with names like
citeLink() and bibAnchor() or so (as free-standing functions like
text_esc()), and invoke them at the appropriate locations in
api_cite.js and api_bibliography.js. If you're getting comfortable
with the code, it would be great to have that as a contribution, but
otherwise I'll get to it eventually, after things settle down with the
Zotero 2.1 deployment.

Phillip Lord

unread,
Apr 1, 2011, 9:22:09 AM4/1/11
to citep...@googlegroups.com

The short answer is probably.

The longer answer is once I have got the basic metadata that I need out
of citeproc and I can do any processing I like in independent
javascript. In terms of reducing dependencies between my code and
citeproc, it seemed to me that the best solution was to get the basic
info out of citeproc then do the rest externally.

For my money, I would do

<div class="csl-entry" citeproc-id="CITE-4">Blah</div>

This gives me the key information that I need. I can anchor this however
I choose then. More over, I have the key to the bib JSON, so if I want
to add more stuff (which I probably will do) then I get that data
structure also.

But at the moment, I have to guess the bibliography entry from the in
text citation. Not somewhere I want to go.

Phil

Phillip Lord

unread,
Apr 1, 2011, 9:24:23 AM4/1/11
to citep...@googlegroups.com


I'm reasonably far from "getting comfortable" (is it really true that to
build citeproc-js I have to run a file called "test"?). But there is
nothing like having a need to enable this.

I will try and have another pick through api_bibliography.js and see if
I can work it out!

Phil

Phillip Lord

unread,
Apr 1, 2011, 2:26:58 PM4/1/11
to citep...@googlegroups.com
Frank Bennett <bierc...@gmail.com> writes:
>> I would like to generate
>>
>> <a name="ITEM-4">
>> <div class="csl-entry">D&#8217;Arcus, Bruce. 2005.
>>         <i>Boundaries of Dissent: Protest and State Power
>>         in the Media Age</i>. Routledge, November 22.</div>
>> </a>
>>
>> where ITEM-4 is the id that would have been passed to retrieveItem.
>
> This is a common need, and should be built into the processor as a
> standard option. The simplest thing would probably be to add a couple
> of functions to the code blocks in formats.js, with names like
> citeLink() and bibAnchor() or so (as free-standing functions like
> text_esc()), and invoke them at the appropriate locations in
> api_cite.js and api_bibliography.js. If you're getting comfortable
> with the code, it would be great to have that as a contribution, but
> otherwise I'll get to it eventually, after things settle down with the
> Zotero 2.1 deployment.


Frank

I'm sort of getting my head around this, but I am a bit stuck.

If I understand things correctly, CSL.getBibliographyEntries does adds
tokens to an output queue, at a point when we don't know what the output
format is. So, this code adds a new token representing the bib entry (or
the start of one.

bib_entry = new CSL.Token("group", CSL.START);
bib_entry.decorations = [["@bibliography", "entry"]].concat(this[this.build.area].opt.layout_decorations);
this.output.startTag("bib_entry", bib_entry);

At this point, I have easy access to the bibliographic item being
processed.

Later on, the queue gets run. At this CSL.Output.Queue.prototype.string
takes over. At this point, we know the output format, but we no longer
know the item.

If my understanding is correct, I could stuff any object I like (including
the item) into the CSL.Token object; but this doesn't get passed to the
decorator function -- only "state" and "str" get passed in.

So I'm not really sure how to put these two parts together.

Tips welcome!

Phil

Frank Bennett

unread,
Apr 1, 2011, 4:43:47 PM4/1/11
to citeproc-js
On Apr 1, 11:26 pm, phillip.l...@newcastle.ac.uk (Phillip Lord) wrote:
Yep.

>
> Later on, the queue gets run. At this CSL.Output.Queue.prototype.string
> takes over. At this point, we know the output format, but we no longer
> know the item.

Yep.

>
> If my understanding is correct, I could stuff any object I like (including
> the item) into the CSL.Token object; but this doesn't get passed to the
> decorator function -- only "state" and "str" get passed in.
>
> So I'm not really sure how to put these two parts together.

It's late here, but I'll give some thought to this tomorrow. It's
a bit tricky because the text escape function gets applied
text on its way through the output queue machinery.

Frank

>
> Tips welcome!
>
> Phil

Philli...@newcastle.ac.uk

unread,
Apr 1, 2011, 10:03:10 PM4/1/11
to citep...@googlegroups.com
>> If I understand things correctly, CSL.getBibliographyEntries does adds
>> tokens to an output queue, at a point when we don't know what the output
>> format is. So, this code adds a new token representing the bib entry (or
>> the start of one.
>>
>> � � bib_entry = new CSL.Token("group", CSL.START);
>> � � bib_entry.decorations = [["@bibliography",
>> "entry"]].concat(this[this.build.area].opt.layout_decorations);
>> � � this.output.startTag("bib_entry", bib_entry);
>>
>> At this point, I have easy access to the bibliographic item being
>> processed.
>
> Yep.
>
>>
>> Later on, the queue gets run. At this CSL.Output.Queue.prototype.string
>> takes over. At this point, we know the output format, but we no longer
>> know the item.
>
> Yep.
>
>>
>> If my understanding is correct, I could stuff any object I like
>> (including
>> the item) into the CSL.Token object; but this doesn't get passed to the
>> decorator function -- only "state" and "str" get passed in.
>>
>> So I'm not really sure how to put these two parts together.
>
> It's late here, but I'll give some thought to this tomorrow. It's
> a bit tricky because the text escape function gets applied
> text on its way through the output queue machinery.


Okay, thanks!

If it is any help, I think my inclination would be to allow the addition
of a standard "what am I" object to CSL.Token, and then the CSL.Token into
the decorator function. I *think* that this only requires a small
modification to the Output functionality.

This would allow output formats to do fairly generic things while still
using a standard style; for example, for HTML, I could DIV tag journal
names (as well as entire bibliography references).

It shouldn't affect existing decorator functions as the additional
parameters will just get ignored.

Phil

Frank Bennett

unread,
Apr 2, 2011, 1:10:40 AM4/2/11
to citeproc-js
Thanks for pushing on this. I've just pushed a fresh processor release
(1.0.142) that provides what you're after. The bib entry wrapper
function now has access to the itemID. You can access the processor
registry via the state object, which gives you the full item content
(as well as the item's disambiguation state and a lot of other obscure
details). You can basically anything you like inside the function,
which opens up a bunch of interesting possibilities.

Philli...@newcastle.ac.uk

unread,
Apr 2, 2011, 10:22:51 AM4/2/11
to citep...@googlegroups.com


Frank

This is excellent -- I shall test it out as soon as I can. This should
allow me to do everything that I need.

Many thanks!

Phil

Reply all
Reply to author
Forward
0 new messages