Closed jansensan closed 3 years ago
Sorry, I have not updated the demo in a while. It shows both outdated code and is not very clear. The JSON format there is CSL-JSON, described here. In that format, it would look like this:
const toFormat = [
{
type: 'book',
title: 'Aesthetics of Interaction in Digital Art',
author: [
{
given: 'Katja',
family: 'Kwastek',
}
],
// Note for 'issued': the order of the outer two brackets changed, from
// [ { date-parts: [] } ] to { date-parts: [ [] ] }
issued: {
'date-parts': [['2013']]
},
// The publisher would be split into 'publisher' and 'publisher-place'. Unfortunately,
// CSL-JSON has no way of specifying whether the place is a city etc
publisher: 'MIT Press',
'publisher-place': 'Cambridge, MA, USA'
}
]
Are APA (
citation-apa
), Vancouver (citation-vancouver
), and Harvard (citation-harvard1
) the only styles accepted? I tried with MLA (citation-mla
) and Chicago (citation-chicago
) and got nothing different than what is shown above. How would one know what are the accepted values?
The accepted values are listed in the documentation, on this page. To add different styles, you can use the following:
const Cite = require('citation-js')
const styleName = 'mla'
const styleConfig = Cite.plugins.config.get('@csl')
const styleData = Cite.util.fetchFile('https://zotero.org/styles/' + styleName)
styleConfig.templates.add(styleName, styleData)
Then you could format like so:
const cite = new Cite(toFormat)
cite.get({
type: 'html',
style: 'citation-mla'
})
Or, with the recent API:
const cite = new Cite(toFormat)
cite.format('bibliography', {
format: 'html',
template: 'mla'
})
Thanks @larsgw that was extremely helpful!
Current situation Attempting to follow the instructions of the demo provides no guidance as of what is the expected JSON data structure for a book.
Attempted This data was used (JSON object is inline in a JS file, which explains its quotes):
Then, parsing the data was done like this:
This provides this response:
Expected results
citation-apa
), Vancouver (citation-vancouver
), and Harvard (citation-harvard1
) the only styles accepted? I tried with MLA (citation-mla
) and Chicago (citation-chicago
) and got nothing different than what is shown above.How would one know what are the accepted values?