larsgw / citation.js

Citation.js converts formats like BibTeX, Wikidata JSON and ContentMine JSON to CSL-JSON to convert to other formats like APA, Vancouver and back to BibTeX.
https://citation.js.org/
MIT License
222 stars 30 forks source link

Is there a way to customize the structure of the output? #179

Closed niudong1001 closed 5 years ago

niudong1001 commented 5 years ago

Hello, I have some questions about Citation.js. First one: I find that if I input a BibTeX structure text like this:

let BibTeX = "@article{}"
let cite = new Cite(BibTeX)

It will get the HTML output using the following code:

let bibHtmled = bibParsed.format(
  'bibliography',
  {
      format: 'html',
      template: 'apa',
      lang: 'en-US'
  }
);

The output is like:

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

Now I want to ask If there is a way to customize the structure of the output? For example I want output this:

"<div class="csl-bib-body">
  <div data-csl-entry-id="tang2007neural" class="csl-entry">
    // Add 'div' block
    <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>"

Second one: And also I want to ask If there is a way to import modules optionally? For example, I just want to import bibtex module and do not need modules like doi or wikidata. This may narrow the package size.

Thanks for your excellent work, Hope to get some advice!

larsgw commented 5 years ago

Now I want to ask If there is a way to customize the structure of the output?

Citation.js uses CSL and citeproc-js to create formatted bibliographies, and I don't know of a way to make it there but I can ask.

And also I want to ask If there is a way to import modules optionally?

Yep, check out the packages and for browsers the bundle tool (also available at juniper-coat.glitch.me). Example usage:

const {Cite} = require('@citation-js/core')
require('@citation-js/plugin-bibtex') // load BibTeX functionality

// new Cite(...)
niudong1001 commented 5 years ago

@larsgw Thanks!

larsgw commented 5 years ago

So there is an (experimental) option to do this in citeproc apparently, I'll see what I can do to implement it.