Insert COinS in index.html generated by bookdown

Hello RStudio community,

I've published a book/manual with bookdown and hosted it on Github-pages.
My browser has the Zotero-connector which scans for bibliographic metadata and allows to directly ingest the bibliographic reference into my Zotero database.

However, when I visit my bookdwon-website it is currently recognized as a book and the authors (as listed in the yaml) are mixed up when using the Zotero connector. On this site it is explained how to integrate ContextObjects in Spans (COinS) in the index.html of a website. So when I create a correct bibliographic reference in Zotero, export it as COinS and paste the generated COinS-html into the index.html, the Zotero-connector detects this meta-data and ingests it correctly into Zotero.

Is it possible to embed bibliographic metadata (COinS) directly in the Rmarkdown files when building the book in Bookdown, so there would be no need to copy/paste this after every build and update?

That would, for instance, require to include the following html in the html-output generated by Bookdown:

<span class='Z3988' title='url_ver=Z39.88-2004&amp;ctx_ver=Z39.88-2004&amp;;rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Adc&amp;rft.type=webpage&amp;rft.title=A%20manual%20published%20with%20bookdown&amp;rft.description=Brief%20content%20of%20the%20website%20or%20book&amp;rft.identifier=urlOfTheWebsite&amp;rft.aufirst=first&amp;rft.aulast=Author&amp;;'></span>

Thanks for your time!
Best wishes,

I don't see any HTML.

Make sure you put it between two lines of triple backticks like this, but without the quotes:

html here

Sorry for that. I've updated my question.

Where should this be inserted ?

And you should be able to put it already in your Rmd file and as it is already html string, it will be kept in the output. Did you try that already ?

This line of html with the bibliographic meta data should be inserted anywhere in the body of the index.html.

When I copy this line of html directly in index.Rmd (<span class= ...), for instance right under the YAML and before the first heading, is doesn't become part of index.html when I build the book. with bookdown


Two options:

  1. If you want it to show up using this method you have to set an option in index.Rmd in the YAML at the top:
always_allow_html: yes
  1. There's an even better solution, though, I suspect. You want this to appear on every page of the book that somebody browses to, probably. Which means the best way to accomplish this is by placing it in a separate HTML file and then including that in your book on every page. You do that by saving a file (let's call it COinS.html) into your project with just that span code inside it. Then you include it like so in the bookdown::gitbook section of your YAML, either in index.Rmd or _output.yml:
    before_body: COinS.html

Hope that helps!


I am not sure this is required. This need to be set mainly for htmlwidget or other HTML only content, that would need to appear in a non-HTML format.

Using before_body is indeed the solution to have this inserted on each page.

Anything before One level headings won't be included in a gitbook output because of the splitting that happens in gitbook format. You need to put it after the first header or use the before_body insertion

1 Like

Pretty sure it is. The first thing I did was try inserting her span code into the demo book, and it didn't show up in the page source until I added the always_allow_html option.

Edit: After reading about that option, perhaps this is just a bug?

I did the same thing and this option does seem to change anything on my end. If I put the span before the first level header in the index.Rmd file, I don't get the span in the output, no matter that option.

Anyway, it is indeed not made for this use as you saw in the documentation


My apologies. I cannot reproduce my claim above. I know I didn't have it before the header, so I must have simply fumbled my initial search in the source code.

No worries! :slight_smile: Thanks for having looked into it though ! It is nice to have Rmarkdown helpers around here!

1 Like

Wow! Thanks a lot, both of you. I'm going to use the

workaround. Then the COinS is indeed on every page of the book/website.
Another step forward in my (still limited) Rmarkdown/bookdown skills.

Best wishes,


If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.